public class StatementParser
extends java.lang.Object
Tag in a TagNode, and has the following pseudo-EBNF grammar:
value =
variable
| number
| literal
| "(" expression ")"
| empty-term
unary-term = ["!"] unary-term
multiplicative-term = unnary-term [("*" | "/") multiplicative-term]
additive-term = multiplicative-term [("+" | "-") additive-term]
relational-term = additive-term [("<" | <=" | ">" | >=" | "in") relational-term]
equality-term = relational-term [("==" | "!=") equality-term]
and-term = equality-term ["&&" and-term]
or-term = and-term ["||" or-term]
ternary-term = or-term ["?" variable ":" variable]
emtpy-term =
expression = ternary-term ["," expression]
variable = identifier [func-call] ["[" expression "]"] ["." variable]
func-call = "." identifier "(" expression ")"
identifier = "any valid Java identifier"
number = "and valid Java number"
literal = """ anything """
The statement parser allows you to extract any sub-element from a string as well (for example, the ForTag wants to pull off it's arguments an identifier followed by the identifier "in" followed by a statement.
| Constructor and Description |
|---|
StatementParser(Tokenizer tokenizer) |
| Modifier and Type | Method and Description |
|---|---|
boolean |
isAssignment() |
Identifier |
maybeParseIdentifier()
Tries to parse an identifier from the stream and returns it if we parsed it, otherwise returns null.
|
java.util.List<Identifier> |
maybeParseIdentifierList()
Attempts to parse an identifier list.
|
void |
parseEnd()
Parses the "end" of the statement.
|
Identifier |
parseIdentifier() |
java.util.List<Identifier> |
parseIdentifierList() |
Term |
parseTerm() |
Term |
parseTermsIterable() |
Token |
parseToken(TokenType type) |
public StatementParser(Tokenizer tokenizer)
public void parseEnd()
throws CarrotException
CarrotException - if we're not actually at the end of the statement.@Nullable public Identifier maybeParseIdentifier() throws CarrotException
Identifier we parsed, or null if we couldn't parse an identifier.CarrotException - if there's some error parsing the identifer.@Nonnull public Identifier parseIdentifier() throws CarrotException
CarrotException@Nonnull public Token parseToken(@Nonnull TokenType type) throws CarrotException
CarrotExceptionpublic java.util.List<Identifier> maybeParseIdentifierList() throws CarrotException
Identifiers we parsed, or null if we couldn't parse an identifier.CarrotException - if there's some error parsing the identifiers.public java.util.List<Identifier> parseIdentifierList() throws CarrotException
CarrotExceptionpublic boolean isAssignment()
throws CarrotException
CarrotExceptionpublic Term parseTerm() throws CarrotException
CarrotExceptionpublic Term parseTermsIterable() throws CarrotException
CarrotException