1grammar t021hoist; 2options { 3 language=Cpp; 4} 5 6@lexer::includes 7{ 8#include "UserTestTraits.hpp" 9} 10@lexer::namespace 11{ Antlr3Test } 12 13@parser::includes { 14#include "UserTestTraits.hpp" 15} 16@parser::namespace 17{ Antlr3Test } 18 19/* With this true, enum is seen as a keyword. False, it's an identifier */ 20@parser::init { 21self.enableEnum = False 22} 23 24stat returns [enumIs] 25 : identifier {enumIs = "ID"} 26 | enumAsKeyword {enumIs = "keyword"} 27 ; 28 29identifier 30 : ID 31 | enumAsID 32 ; 33 34enumAsKeyword : {self.enableEnum}? 'enum' ; 35 36enumAsID : {not self.enableEnum}? 'enum' ; 37 38ID : ('a'..'z'|'A'..'Z'|'_') ('a'..'z'|'A'..'Z'|'0'..'9'|'_')* 39 ; 40 41INT : ('0'..'9')+ 42 ; 43 44WS : ( ' ' 45 | '\t' 46 | '\r' 47 | '\n' 48 )+ 49 {$channel=HIDDEN} 50 ; 51