I have a simple grammar that will eventually parse YANG source. When I make when seem to be an arbitrary change the location of the MODULE token the IntelliJ ANTLR4 Plugin can/cannot parse my input.
The input string to be parsed:
module x { }
Here is the grammar that works without any error:
grammar Yang ;
yang: module_open module_close;
module_open : MODULE ID BRACKET_OPEN ;
module_close: BRACKET_CLOSE ;
MODULE: 'module' ;
ID: ([A-Za-z][A-Za-z0-9_-]*) ;
BRACKET_OPEN: '{' ;
BRACKET_CLOSE: '}' ;
WS: [
]+ -> skip ;
Here is the grammar that fails:
grammar Yang ;
yang: module_open module_close;
module_open : MODULE ID BRACKET_OPEN ;
module_close: BRACKET_CLOSE ;
ID: ([A-Za-z][A-Za-z0-9_-]*) ;
MODULE: 'module' ;
BRACKET_OPEN: '{' ;
BRACKET_CLOSE: '}' ;
WS: [
]+ -> skip ;
All I'm doing is cutting-pasting the MODULE token definition before/after the ID token, and it always fails if the MODULE definition is after the ID definition.
What am I missing? I see no discussion of order of tokens in the docs!
EDIT: @BartKiers Related Post... ANTLR4 lexer rules don't work as expected
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…