Class ExpressionParser
Builds a Riskscape Language Expression AST from a string. At the moment, the language is a mostly equivalent
version of ECQL that simplifies the language to make it more flexible for use throughout the riskscape engine.
Current plans are to extend its use to all uses of Expression
and
Filter
and possibly also taking in type expressions and pipeline expressions.
-
Field Summary
Modifier and TypeFieldDescriptionstatic final EnumSet<TokenTypes>
Used withConditionalParse
static final ExpressionParser
static final EnumSet<TokenTypes>
Used withConditionalParse
static final EnumSet<TokenTypes>
The list of tokens that typically start any expressionstatic final EnumSet<TokenTypes>
All of the things that can be inside aConstant
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
checkForParameters
(Expression parsed) protected Lexer<TokenTypes>
Lexes source with theTokenTypes.tokens()
.Parses the given string in to anExpression
.parseAllowParameters
(String source) A version ofparse(String)
that allows the expression to containParameterToken
s.parseExpression
(Lexer<TokenTypes> lexer) parseFunctionExpression
(Lexer<TokenTypes> lexer) Convenience method to catch any exceptions from parsing the expression and return them as aResultOrProblem
parsePropertyExpression
(Lexer<TokenTypes> lexer, Optional<Expression> receiver) static Expression
parseString
(String source) Convenience form ofnew ExpressionParser().parse(source)
toList
(Expression expr) Return a version of the given expression as aListDeclaration
.toStruct
(Expression expr) Return a version of the given expression as a struct.
-
Field Details
-
INSTANCE
-
IDENTIFIERS
Used with
ConditionalParse
-
KEY_IDENTIFIERS
Used with
ConditionalParse
-
LITERALS
All of the things that can be inside a
Constant
-
LEADING_TOKENS
The list of tokens that typically start any expression
NB this is 'derived', which kind of sucks, but it's just for debugging/error messages
-
-
Constructor Details
-
ExpressionParser
public ExpressionParser()
-
-
Method Details
-
parseString
Convenience form of
new ExpressionParser().parse(source)
-
parse
Parses the given string in to an
Expression
. SeeparseAllowParameters(String)
for a version that acceptsParameterToken
s- Returns:
- an Expression from the given string
- Throws:
ParseException
- if source couldn't be parsed or if the expression containsParameterToken
s.LexerException
- if source couldn't be lexed in to tokens
-
parseOr
Convenience method to catch any exceptions from parsing the expression and return them as a
ResultOrProblem
-
parseAllowParameters
A version of
parse(String)
that allows the expression to containParameterToken
s.- Parameters:
source
-- Returns:
- Expression
-
checkForParameters
- Throws:
ParseException
- if the given expression contains $foo style parameters
-
toStruct
Return a version of the given expression as a struct. If it's already a struct declaration it is returned as is, otherwise a simple anonymous struct declaration is put around it.
-
toList
Return a version of the given expression as a
ListDeclaration
. If expression is a ListDeclaration it is returned as is, otherwise a ListDeclaration is returned containing expression as the single item. -
lex
Lexes source with the
TokenTypes.tokens()
.- Parameters:
source
- to lex
-
parseExpression
-
parseFunctionExpression
-
parsePropertyExpression
public PropertyAccess parsePropertyExpression(Lexer<TokenTypes> lexer, Optional<Expression> receiver)
-