[antlr-interest] Advanced questions and proposals
Alexey Demakov
demakov at ispras.ru
Mon Mar 14 02:09:36 PST 2005
> > 2. Text of EOF token
> >
> > When ANTLR (or generated parser) reports about unexpected end of file,
> > error message looks like:
> >
> > a.g:2:1: expecting ID, found 'null'
> >
> > I prefer to see something more informative instead of 'null'.
> > I've found workaround for that,
> > but propose to change default behaviour in future versions.
>
> Is this parser or lexer? I'm kindoff surprised at this at least the null
> doesn't ring a bell my parser/lexers usually say EOF. It might be
> something triggered by a specific construct rule though.
It is parser message about EOF_TOKEN from lexer.
Try to translate MyParser.g:
--- MyParser.g start ---
class MyParser
--- MyParser.g end ---
and you'll see:
ANTLR Parser Generator Version 2.7.4 1989-2004 jGuru.com
MyParser.g:1:16: expecting "extends", found 'null'
MyParser.g:1:16: rule classDef trapped:
MyParser.g:1:16: unexpected token: null
error: aborting grammar 'unknown grammar' due to errors
Exiting due to errors.
> > 3. Multiple error messages about unexpected EOF in parser.
> >
> > When EOF is found in some deep parser rule, ANTLR generates syntax error messages
> > for each exception handler (rule) on stack. I propose to process this case
> > separately and, for example, suppress all error messages after the first one
> > when EOF is reached.
>
> This again does not really ring a direct bell with me. But there's many
> ways to have error handlers and such.. A custom errorhandler that does
> something specific for an EOF could be a first workaround.
Yes, I know workaround, but it possible to improve ANTLR.
> > 4. Error handling - extend default error handler
> >
> > When I specify my own error handler, ANTLR doesn't generate default one.
> > But what if I process additional exception types and want use default handler
> > for RecognitionException? I propose that
> > options { defaultErrorHandler=true; }
> > turn on default error handler generation in this case.
>
> How about the ordering of the default one and your specific ones?
> Depending on the place and your custom exception hierarchy the one might
> eat the exception for the other.
When I write
exception
catch[MyExceptionType ex]
{ ... }
default exception handling is turned off and I have to write it explicitly
as
catch[RecognitionException ex]
{
reportError(ex);
consume();
consumeUntil($FOLLOW); // thanks, now I at least know how to write it :)
}
Or even with:
if (inputState.guessing==0) {
...
} else {
throw ex;
}
And I don't know when I should add this check.
And my question is - how to add custom error handlers but have default handler generated?
And if it is not possible - add this feature.
Regards,
Alexey
-----
Alexey Demakov
TreeDL: Tree Description Language: http://treedl.sourceforge.net
RedVerst Group: http://www.unitesk.com
More information about the antlr-interest
mailing list