[antlr-interest] HOW To catch error (no exception is thown)

Guntis Ozols guntiso at latnet.lv
Mon Apr 21 15:50:41 PDT 2008


> it's been 2 days, I try to catch error from the parser.

To catch error, you need to throw it first.
For some reason still unclear to me,
antlr lexer does not throw error by default.

The answer you are looking for is in FAQ.
For some reason, not error handling FAQ but lexing FAQ instead.

!The code there is version specific!

It suggests you to override nextToken() with lots of code.

I am just overriding reportError() with one line to throw
RuntimeException from there, but then I can not use syntactic
predicates for lexer rules.

Perhaps there are other options, too.

http://www.antlr.org/wiki/pages/viewpage.action?pageId=5341217.



More information about the antlr-interest mailing list