Class AntlrExpressionParser
java.lang.Object
dev.frostlake.executor.expressions.AntlrExpressionParser
Parses an expression string into an
Expression AST using the ANTLR grammar and
ExpressionAstBuilder. This is the replacement for the hand-rolled
ExpressionParser; callers fall back to that legacy parser when this throws (a
not-yet-ported construct, or input that is not a single complete expression).
Parsing is deliberately quiet: the default console error listeners are removed and a
BailErrorStrategy makes the parser throw on the first syntax error instead of
recovering and logging. A trailing-input check ensures the whole string was consumed, so a
partial parse falls back rather than silently truncating.
-
Method Summary
Modifier and TypeMethodDescriptionstatic org.antlr.v4.runtime.TokenfailurePoint(String expression) Whereparse(String)stops on an input it cannot turn into a single complete expression: the token the parser was looking at when it gave up, which is the offending token for a malformed expression and the first unconsumed token when the expression parsed but did not reach end of input (the EOF token when the input is simply exhausted).static ExpressionParses the expression string into anExpressionAST:parseTree(String)for the grammar's parse tree, thenExpressionAstBuilderto turn it into AST nodes.The PARSE TREEparse(String)builds itsExpressionfrom, for a caller that must inspect the expression's syntax rather than evaluate it (the CREATE-time SQL-UDF body check reads which functions a body calls).
-
Method Details
-
parse
Parses the expression string into anExpressionAST:parseTree(String)for the grammar's parse tree, thenExpressionAstBuilderto turn it into AST nodes. Throws when the input is not one complete expression — the cue for callers to fall back.- Parameters:
expression- the expression source text, exactly as it appears in the SQL- Returns:
- the expression AST, ready for
ExpressionEvaluatorVisitorevaluation
-
parseTree
The PARSE TREEparse(String)builds itsExpressionfrom, for a caller that must inspect the expression's syntax rather than evaluate it (the CREATE-time SQL-UDF body check reads which functions a body calls). Throws exactly asparsedoes on input that is not one complete expression.- Parameters:
expression- the expression source text, exactly as it appears in the SQL- Returns:
- the parse tree of the whole expression (the grammar's
booleanExprentry rule)
-
failurePoint
Whereparse(String)stops on an input it cannot turn into a single complete expression: the token the parser was looking at when it gave up, which is the offending token for a malformed expression and the first unconsumed token when the expression parsed but did not reach end of input (the EOF token when the input is simply exhausted).Diagnostics only — the routine-body compiler renders it as Snowflake's
syntax error line L at position P unexpected 'TOK'. Kept here so the knowledge of HOW an expression is parsed (grammar entry rule, bail strategy) stays in one place.- Parameters:
expression- the expression source text already known not to parse completely- Returns:
- the token the parser stopped at — its line and position locate the syntax error
-