regex - ANTLR match to end of input -
i'm trying match grammar entire string, , have error out if cannot consume entire input. basically, pseudo regex:
\whitespace* [a-za-z]+ [-]? [a-za-z]+ \whitespace* $
according this, eof should work. so, consider grammar:
start : chars eof ; chars : ('a'..'z')+ ;
if set input "hello"
in 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 ast 2 children, hello
, eof
, expected. if set input "hello#"
, gives same tree, , doesn't complain hash @ all. i'm not sure i'm doing wrong.
i found problem, exceptions getting trapped lexer instead of propagating code. so, adding this:
class throwalllexer: querylexer { public throwalllexer(icharstream input): base(input) { } public override void reporterror(recognitionexception e) { throw e; }
i proper exceptions, instead of having them swallowed.
Comments
Post a Comment