[antlr-interest] Helpfulness of exception messages

Michael Sielemann michael.sielemann at asdl.gatech.edu
Mon Oct 17 08:31:47 PDT 2005


 

Hi list,

Now that I understand more and more about ANTLR I am getting really
impressed and would like to say a big "Thanks!" to everybody involved in
this.

 

I have one question though: Due to the nature of the input I am parsing I
have to distinguish various ways to define a construct. In the example
below, these alternatives are in the rule 'body'. If someone providing an
input file to the parser forgets a semicolon or makes a similar minor
mistake inside the rule 'composition' for example, ANTLR assumes that (
IDENT composition END ) is not the appropriate alternative to choose (but it
actually is the right alternative, some user just messed up a part of the
syntax). The other alternatives do not work in that case either.
Consequently, ANTLR raises a no viable alternative exception and says that
he could not match the token IDENT. It would be more helpful to get a
message like "Expected token SEMI" however. For me, it would thus be helpful
to have some sort of ANTLR directive at a point in the rule 'composition'
saying "If you're this far then assume that you chose the right alternative
and consume all the tokens until here". Is there such a feature in ANTLR? If
someone had some hints on how to get this done I would seriously appreciate
the help.

 

Thank you guys in any case MICHAEL

 

 

class ExampleParser extends parser;

 

start_rule

      : (

          ( WITHIN (name)? SEMI! )?

          ( ( CLASS | PACKAGE )

            body 

            SEMI!

          )*

        )

        ;

 

body  : (

          ( IDENT composition END )

          | ( IDENT EQ name (modification)? )

        )

        ;

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/antlr-interest/attachments/20051017/3eb43ddb/attachment.html


More information about the antlr-interest mailing list