UNPKG

@mike-lischke/antlr-tgen

Version:

A generator for antlr-ng runtime test cases

45 lines (36 loc) 835 B
[notes] The lexer will create rules to match letters a, b, c. The associated token types A, B, C must have the same value and all import'd parsers. Since ANTLR regenerates all imports for use with the delegator M, it can generate the same token type mapping in each parser: public static final int C=6; public static final int EOF=-1; public static final int B=5; public static final int WS=7; public static final int A=4; [type] CompositeParser [grammar] grammar M; import S,T; s : x y ; // matches AA, which should be 'aa' B : 'b' ; // another order: B, A, C A : 'a' ; C : 'c' ; WS : (' '|'\n') -> skip ; [slaveGrammar] parser grammar T; tokens { C, B, A } // reverse order y : A {<writeln("\"T.y\"")>}; [slaveGrammar] parser grammar S; tokens { A, B, C } x : A {<writeln("\"S.x\"")>}; [start] s [input] aa [output] S.x T.y