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