[antlr-interest] Continue parsing after an error
Luchesar Cekov
luchesar.cekov at ontology-partners.com
Wed Jun 30 07:10:02 PDT 2010
Dear ANTLR enthusiasts,
I am struggling with a problem. The parser jumps to the end of file from
the middle of the document.
The setup is as follow:
* I have two alternatives flowed by EOF
* during parse time in the middle of the document next token can not
match either alternatives start
This leads to parsing termination because the parser jumps to the EndOfFile.
A simple grammar the illustrates the problem is
===============
tokens {ROOT_TOKEN;}
root
: expressions EOF -> ^(ROOT_TOKEN expressions) ;
expressions : ('[' | ']')* ;
OTHER : . ;
===============
If then I try parsing "[[][]]sdsdf[]][]][" the parsing will stop and the
first "s" and will try to recover as if the EOF was the next token.
When looking at the generated Parser it looks like if there is no viable
alternative in the top rule in this case "root" the parser will behave
as if it reached the EOF and will skip the rest of the tokens.
The result AST will contain only children up until the first illegal
token "s".
I cannot see where my mistake is. It looks like the parser should not do
that. Can you suggest a workaround for the problem?
Thanks in advance,
Luchesar
--
Luchesar Cekov
Software Engineer
+44 (0) 207 239 4949
*Ontology Systems*
www.ontology.com <http://www.ontology.com/>
award list of icons
.
More information about the antlr-interest
mailing list