Class AntlrExpressionParser

java.lang.Object
dev.frostlake.executor.expressions.AntlrExpressionParser

public final class AntlrExpressionParser extends Object
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 Details

    • parse

      public static Expression parse(String expression)
      Parses the expression string into an Expression AST: parseTree(String) for the grammar's parse tree, then ExpressionAstBuilder to 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 ExpressionEvaluatorVisitor evaluation
    • parseTree

      public static FrostlakeParser.BooleanExprContext parseTree(String expression)
      The PARSE TREE parse(String) builds its Expression from, 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 as parse does 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 booleanExpr entry rule)
    • failurePoint

      public static org.antlr.v4.runtime.Token failurePoint(String expression)
      Where parse(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