[antlr-interest] Missing error when tokens are left to parse

Arne Schröder arne.schroeder at gmail.com
Fri Jan 15 00:57:24 PST 2010


I am trying to write a parser for an initialization-file. This file is
devided in sections which are not embraced but have a keyword to start them.

Unfortunately the parser stops when encountering a problem and just ends the
parsing-process, not even reporting an error.

For demostration of the problem I wrote the following example-grammar:

file    : section1 section2?

section1: 'Section1'

section2: 'Section2'

ID      : ('a'..'z'|'A'..'Z')+

SPACE   : ' ' {$channel = HIDDEN;}

Now using the input "Section1 bla Section2", I would expect the parser to
stop at "bla", throw an UnwantedTokenException, do a SingleTokenDeletion as
error-recovery and just continue parsing "Section2".
What happens is that it stops at "bla", does not recognize it as section2
and just terminates, leaving the two tokens unparsed and not reporting any

So my question is: How can I avoid my parser doing stuff like that without
changing my files' syntax?

Thanks in advance


More information about the antlr-interest mailing list