You have to supply a function that takes the token as defined by the expecting element, perform a switch() on it and supply the text you really want. It is pretty easy but there is no automated way to do it and if we had the alias stuff that was in v2 it really doesn't save you any typing. Better to do it explicitly yourself.
Jim > -----Original Message----- > From: [email protected] [mailto:antlr-interest- > [email protected]] On Behalf Of Peterson, Joe > Sent: Tuesday, November 03, 2009 2:56 PM > To: [email protected] > Subject: [antlr-interest] C Target: Reverse look up of tokens for error > reporting > > Hello all, > > I am trying to generate more useful error messages when I get a file > that doesn't match the grammar. One of the complaints is that because I > named my tokens, the error messages look like this: > syntax error detected in file missing_semicolon.test at line number > 6, position 5; expecting SEMICOLON > > To me, this seems obvious, but my customers don't like the token names, > they'd rather see: > syntax error detected in file fail_missing_colon.ext at line number > 6, position 2; expecting ';' > > I prefer to have the names, though. Is there an easy way for me to > reverse the look up so the error can replace SEMICOLON with ';' (as > well as all my other tokens, of course)? > > I can get the NAME of the token with: > recognizer->state->tokenNames[recognizer->state->exception- > >expecting] > I can't seem to see how to get the text of that token, though. > > Thanks, > -JEEP > Joe Peterson > > List: http://www.antlr.org/mailman/listinfo/antlr-interest > Unsubscribe: http://www.antlr.org/mailman/options/antlr-interest/your- > email-address List: http://www.antlr.org/mailman/listinfo/antlr-interest Unsubscribe: http://www.antlr.org/mailman/options/antlr-interest/your-email-address --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "il-antlr-interest" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/il-antlr-interest?hl=en -~----------~----~----~----~------~----~------~--~---
