When I run the following grammer:
test : WORD+;
WORD : ('a'..'z')+;
WS : ' '+ {$channel = HIDDEN;};
and I give the input “?test” why does antlr accept this as valid input? I thought the (‘a’..’z’) would only match characters within the lowercase alphabet?
ANTLR does produce an error when parsing the input string
?testwith the grammar you posted. As is usually the case, the error lies with the tool being used around ANTLR (I see it happen a lot with ANTLRWorks as well, unfortunately!).To test it yourself (properly), create a file
Test.g:and a file
Main.java:and download a copy of the ANTLR 3.2 JAR in the same directory.
Now generate a lexer & parser:
compile all Java source files:
and run the Main class:
(replace the
:with;if you’re on Windows!)which will produce the following error message: