@mike-lischke/antlr-tgen
Version:
A generator for antlr-ng runtime test cases
37 lines (30 loc) • 1.25 kB
Plain Text
[notes]
This is a regression test for antlr/antlr4#433 "Not all context accessor
methods are generated when an alternative rule label is used for multiple
alternatives". https://github.com/antlr/antlr4/issues/433
[type]
Parser
[grammar]
grammar T;
s : e {<writeln("$e.v")>};
e returns [int v]
: e '*' e {$v = <Cast("BinaryContext","$ctx"):SubContextLocal({<Production("e")>(0)}, {<Result("v")>})> * <Cast("BinaryContext","$ctx"):SubContextLocal({<Production("e")>(1)}, {<Result("v")>})>;} # binary
| e '+' e {$v = <Cast("BinaryContext","$ctx"):SubContextLocal({<Production("e")>(0)}, {<Result("v")>})> + <Cast("BinaryContext","$ctx"):SubContextLocal({<Production("e")>(1)}, {<Result("v")>})>;} # binary
| INT{$v = $INT.int;} # anInt
| '(' e ')' {$v = $e.v;} # parens
| left=e INC {<ContextRuleFunction(Cast("UnaryContext","$ctx"), "INC()"):Concat(" != null"):Assert()>$v = $left.v + 1;} # unary
| left=e DEC {<ContextRuleFunction(Cast("UnaryContext","$ctx"), "DEC()"):Concat(" != null"):Assert()>$v = $left.v - 1;} # unary
| ID {<AssignLocal("$v","3")>} # anID
;
ID : 'a'..'z'+ ;
INT : '0'..'9'+ ;
INC : '++' ;
DEC : '--' ;
WS : (' '|'\n') -> skip;
[start]
s
[input]
1+2
[output]
"""3
"""