[antlr-interest] Non-Default Exception-Handling - Synching to the end of the rule

Ric Klaren ric.klaren at gmail.com
Mon Dec 13 16:42:51 PST 2004


On Sun, 12 Dec 2004 16:39:54 -0800 (PST), Colm McHugh
<colmmagoo at yahoo.com> wrote:
> > Just mimick the default errorhandlers. Inside the
> > errorhandling
> > section of a rule you can use the macros $FIRST
> > $FOLLOW
> > $FIRST(rulename) $FOLLOW(rulename) to get access to
> > the sets used for
> > error recovery. Just feed the right one to
> > consumeUntil and you should
> > have gone to the 'next-rule'.
> > 
> Thanks Ric, I wasn't aware of those macros, they seem
> really useful.

They're pretty recent additions. I noticed the docs are not that clear
on their existence :(

> However, consumeUntil doesn't work in the case of
> lexer exceptions;

consumeUntil does no exception handling (if this is required you need
to wrap it or provide a version that is exception resistant...)

By the way you mean MismatchedCharExceptions ? Or stream exceptions?

> I have an expr rule and if that gets
> something like 'x @ y' where @ is not a recognizable
> character, I still see the same '@ - bad character'
> error reported, even though my error handling code
> does consumeUntil on each rule.
> 
> [I think] this is because 'consumeUntil' calls LA(1),
> but if the current input is on a bad character, that's
> just going to result in the same bad character
> exception being thrown... I'd like something more
> low-level than LA(1) to advance past the character in
> this case, though I'm wary of dragging too much lexer
> detail into hand-written error managing code. Time to
> poke around the ANTLR header files a bit...

I think your analysis is pretty much dead on. Which makes me wonder
what kind of error handing is set up in the lexer? Doesn't it some
kind of consume() call to advance past such a character. My memory is
letting me down a bit on how this is handled. Anycase the actual act
of getting rid of such a character is done via the
LexerSharedInputState. Get from it the InputBuffer do a fill(1) on it
and consume() that should get rid of the char (I think)

Cheers,

Ric


 
Yahoo! Groups Links

<*> To visit your group on the web, go to:
    http://groups.yahoo.com/group/antlr-interest/

<*> To unsubscribe from this group, send an email to:
    antlr-interest-unsubscribe at yahoogroups.com

<*> Your use of Yahoo! Groups is subject to:
    http://docs.yahoo.com/info/terms/
 





More information about the antlr-interest mailing list