Package io.pebbletemplates.pebble.parser
Class ExpressionParser
- java.lang.Object
-
- io.pebbletemplates.pebble.parser.ExpressionParser
-
public class ExpressionParser extends java.lang.Object
Parses expressions.
-
-
Field Summary
Fields Modifier and Type Field Description private java.util.Map<java.lang.String,BinaryOperator>
binaryOperators
private Parser
parser
private ParserOptions
parserOptions
private static java.util.Set<java.lang.String>
RESERVED_KEYWORDS
private TokenStream
stream
private java.util.Map<java.lang.String,UnaryOperator>
unaryOperators
-
Constructor Summary
Constructors Constructor Description ExpressionParser(Parser parser, java.util.Map<java.lang.String,BinaryOperator> binaryOperators, java.util.Map<java.lang.String,UnaryOperator> unaryOperators, ParserOptions parserOptions)
Constructor
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description private boolean
isBinary(Token token)
Checks if a token is a binary operator.private boolean
isUnary(Token token)
Checks if a token is a unary operator.private ArgumentsNode
parseArguments()
ArgumentsNode
parseArguments(boolean isMacroDefinition)
private Expression<?>
parseArrayDefinitionExpression()
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<?>
parseExpression()
The public entry point for parsing an expression.private Expression<?>
parseExpression(int minPrecedence)
A private entry point for parsing an expression.FilterInvocationExpression
parseFilterInvocationExpression()
private Expression<?>
parseFunctionOrMacroInvocation(Expression<?> node)
private Expression<?>
parseMapDefinitionExpression()
java.lang.String
parseNewVariableName()
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<?>
parseStringExpression()
private Expression<?>
parseTernaryExpression(Expression<?> expression)
private Expression<?>
parseTestInvocationExpression()
private Expression<?>
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.
-
-
-
Field Detail
-
RESERVED_KEYWORDS
private static final java.util.Set<java.lang.String> RESERVED_KEYWORDS
-
parser
private final Parser parser
-
stream
private TokenStream stream
-
binaryOperators
private java.util.Map<java.lang.String,BinaryOperator> binaryOperators
-
unaryOperators
private java.util.Map<java.lang.String,UnaryOperator> unaryOperators
-
parserOptions
private ParserOptions parserOptions
-
-
Constructor Detail
-
ExpressionParser
public ExpressionParser(Parser parser, java.util.Map<java.lang.String,BinaryOperator> binaryOperators, java.util.Map<java.lang.String,UnaryOperator> unaryOperators, ParserOptions parserOptions)
Constructor- Parameters:
parser
- A reference to the main parserbinaryOperators
- All the binary operatorsunaryOperators
- All the unary operators
-
-
Method Detail
-
parseExpression
public Expression<?> parseExpression()
The public entry point for parsing an expression.- Returns:
- NodeExpression the expression that has been parsed.
-
parseExpression
private Expression<?> parseExpression(int minPrecedence)
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:
- "http://en.wikipedia.org/wiki/Operator-precedence_parser"
-
isUnary
private boolean isUnary(Token token)
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
private boolean isBinary(Token token)
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
private Expression<?> 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
private Expression<?> parseStringExpression() throws ParserException
- Throws:
ParserException
-
parseTernaryExpression
private Expression<?> parseTernaryExpression(Expression<?> expression)
-
parsePostfixExpression
private Expression<?> parsePostfixExpression(Expression<?> node)
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
private Expression<?> parseFunctionOrMacroInvocation(Expression<?> node)
-
parseFilterInvocationExpression
public FilterInvocationExpression parseFilterInvocationExpression()
-
parseTestInvocationExpression
private Expression<?> parseTestInvocationExpression()
-
parseBeanAttributeExpression
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. Ex. foo.bar or foo['bar'] or foo.bar('baz')- Parameters:
node
- The expression parsed so far- Returns:
- NodeExpression The parsed subscript expression
-
parseArguments
private ArgumentsNode parseArguments()
-
parseArguments
public ArgumentsNode parseArguments(boolean isMacroDefinition)
-
parseNewVariableName
public java.lang.String 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
private Expression<?> parseArrayDefinitionExpression()
-
parseMapDefinitionExpression
private Expression<?> parseMapDefinitionExpression()
-
-