I have the following grammar:
grammar tryout;
tryout : my_cmd
;
my_cmd
: 'start' '0'..'9'+ Name_string
;
Digit
: '0'..'9'
;
Name_string
: ('A'..'Z' | 'a'..'z') ('A'..'Z' | 'a'..'z' | '0'..'9' | '_')*
;
If I see the diagram in ANTLRworks, '0'..'9'+ shows as an empty element and so Java code compilation fails because the generated code has "if ()" statement; if I run at command line, compilation also fails.
The fix is to move '0'..'9'+ to a lexer rule.
grammar tryout;
tryout : my_cmd
;
my_cmd
: 'start' Digit+ Name_string
;
Digit
: '0'..'9'
;
Name_string
: ('A'..'Z' | 'a'..'z') ('A'..'Z' | 'a'..'z' | '0'..'9' | '_')*
;
But I wonder if this is a bug. Why the range element cannot be used in parser rule? This is on ANTLR v3.4.