I'm trying to match my grammar to an entire string, and have it error out if it cannot consume the entire input. Basically, this pseudo regex:
\whitespace* [a-zA-Z]+ [-]? [a-zA-Z]+ \whitespace* $
According to this, EOF should work. So, consider this grammar:
start : CHARS EOF
;
CHARS : ('a'..'z')+
;
If I set input to "hello"
in this code:
var ss = new Antlr.Runtime.ANTLRStringStream(input);
var lex = new autocompleteLexer(ss);
var tokens = new CommonTokenStream(lex);
var parser = new autocompleteParser(tokens);
return (BaseTree)(parser.start().Tree);
I get an AST with two children, HELLO
and EOF
, as expected. But if I set the input to say "hello#"
, it gives back the same tree, and doesn't complain about the hash at all. I'm not sure what I'm doing wrong.