Package io.pebbletemplates.pebble.parser
Class ExpressionParser
java.lang.Object
io.pebbletemplates.pebble.parser.ExpressionParser
Parses expressions.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate Map<String, BinaryOperator> private final Parserprivate ParserOptionsprivate TokenStreamprivate Map<String, UnaryOperator> -
Constructor Summary
ConstructorsConstructorDescriptionExpressionParser(Parser parser, Map<String, BinaryOperator> binaryOperators, Map<String, UnaryOperator> unaryOperators, ParserOptions parserOptions) Constructor -
Method Summary
Modifier and TypeMethodDescriptionprivate booleanChecks if a token is a binary operator.private booleanChecks if a token is a unary operator.private ArgumentsNodeparseArguments(boolean isMacroDefinition) private Expression<?> private Expression<?> parseBeanAttributeExpression(Expression<?> node) A bean attribute expression can either be an expression getting an attribute from a variable in the context, or calling a method from a variable.Expression<?> The public entry point for parsing an expression.private Expression<?> parseExpression(int minPrecedence) A private entry point for parsing an expression.private Expression<?> parseFunctionOrMacroInvocation(Expression<?> node) private Expression<?> Parses a new variable that will need to be initialized in the Java code.private Expression<?> parsePostfixExpression(Expression<?> node) Determines if there is more to the provided expression than we originally thought.private Expression<?> private Expression<?> parseTernaryExpression(Expression<?> expression) private Expression<?> private Expression<?> Finds and returns the next "simple" expression; an expression of which can be found on either side of a binary operator but does not contain a binary operator.
-
Field Details
-
RESERVED_KEYWORDS
-
parser
-
stream
-
binaryOperators
-
unaryOperators
-
parserOptions
-
-
Constructor Details
-
ExpressionParser
public ExpressionParser(Parser parser, Map<String, BinaryOperator> binaryOperators, Map<String, UnaryOperator> unaryOperators, ParserOptions parserOptions) Constructor- Parameters:
parser- A reference to the main parserbinaryOperators- All the binary operatorsunaryOperators- All the unary operators
-
-
Method Details
-
parseExpression
The public entry point for parsing an expression.- Returns:
- NodeExpression the expression that has been parsed.
-
parseExpression
A private entry point for parsing an expression. This method takes in the precedence required to operate a "precedence climbing" parsing algorithm. It is a recursive method.- Returns:
- The NodeExpression representing the parsed expression.
- See Also:
-
isUnary
Checks if a token is a unary operator.- Parameters:
token- The token that we are checking- Returns:
- boolean Whether the token is a unary operator or not
-
isBinary
Checks if a token is a binary operator.- Parameters:
token- The token that we are checking- Returns:
- boolean Whether the token is a binary operator or not
-
subparseExpression
Finds and returns the next "simple" expression; an expression of which can be found on either side of a binary operator but does not contain a binary operator. Ex. "var.field", "true", "12", etc.- Returns:
- NodeExpression The expression that it found.
-
parseStringExpression
- Throws:
ParserException
-
parseTernaryExpression
-
parsePostfixExpression
Determines if there is more to the provided expression than we originally thought. We will look for the filter operator or perhaps we are getting an attribute from a variable (ex. var.attribute or var['attribute'] or var.attribute(bar)).- Parameters:
node- The expression that we have already discovered- Returns:
- Either the original expression that was passed in or a slightly modified version of it, depending on what was discovered.
-
parseFunctionOrMacroInvocation
-
parseFilterInvocationExpression
-
parseTestInvocationExpression
-
parseBeanAttributeExpression
A bean attribute expression can either be an expression getting an attribute from a variable in the context, or calling a method from a variable. Ex. foo.bar or foo['bar'] or foo.bar('baz')- Parameters:
node- The expression parsed so far- Returns:
- NodeExpression The parsed subscript expression
-
parseArguments
-
parseArguments
-
parseNewVariableName
Parses a new variable that will need to be initialized in the Java code. This is used for the set tag, the for loop, and in named arguments.- Returns:
- A variable name
-
parseArrayDefinitionExpression
-
parseMapDefinitionExpression
-