Class ExpressionParser


  • public class ExpressionParser
    extends java.lang.Object
    Parses expressions.
    • Field Detail

      • RESERVED_KEYWORDS

        private static final java.util.Set<java.lang.String> RESERVED_KEYWORDS
      • parser

        private final Parser parser
      • binaryOperators

        private java.util.Map<java.lang.String,​BinaryOperator> binaryOperators
      • unaryOperators

        private java.util.Map<java.lang.String,​UnaryOperator> unaryOperators
    • 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 parser
        binaryOperators - All the binary operators
        unaryOperators - 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.
      • 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)
      • 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

        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()