Consider my simple grammar, skipping the lexer here:
expr:
expr expr+ # CallFormExpr // ⬅ the question here!
| L_PAREN expr R_PAREN # ParensExpr
| L_BRACKET (expr COMMA?)* R_BRACKET # SquareBracketExpr
| L_CURLY (expr COMMA?)* R_CURLY # CurlyBracesExpr
| lit # LitExpr
| ident # IdentExpr
;
ident : IDENTIFIER | OPERATOR;
lit:
RUNE_LIT
| RAW_STRING_LIT
| INTERPRETED_STRING_LIT
| IMAGINARY_LIT
| FLOAT_LIT
| DECIMAL_LIT
| BINARY_LIT
| OCTAL_LIT
| HEX_LIT
;
Now, the very first expr
option expr expr+
is meant to capture foo bar baz
as an expr
with 3 ident
s but Antlr4 Lab gives me this parse tree which is kind of akin to foo (bar baz)
:
Due to recursion, the “flat list gets treeified”. Is it a matter of how the expr
options are ordered? Or is there some Antlr “hinting syntax” to “keep it flat”?