[antlr-interest] Error Handling Advanced
Jim Idle
jimi at temporal-wave.com
Fri Apr 29 09:41:36 PDT 2011
Download the source code for the JavaFX compiler. Though it is in Java,
the same techniques apply and you can easily adapt to both C# and Spanish.
Just do the same thing and use a superclass rather than trying to put
things in to the .g file.
http://kenai.com/projects/openjfx-compiler
Jim
> -----Original Message-----
> From: antlr-interest-bounces at antlr.org [mailto:antlr-interest-
> bounces at antlr.org] On Behalf Of Prados Valiente Enrique
> Sent: Friday, April 29, 2011 2:07 AM
> To: antlr-interest at antlr.org
> Subject: [antlr-interest] Error Handling Advanced
>
> Hi,
>
> I'm newbie using Antlr3.Runtime.dll C# , VS 2008, CSharp2 target
> (perhaps better use vs2010 and CSharp3 target)
>
> I need advanced error handling for use spanish in my error messages,
> and do more clearly the messages to show it to the users.
>
> I have been this page:
>
> http://www.antlr.org/wiki/pages/viewpage.action?pageId=23232568
>
>
> how is the code of getRuleInvocationStack ???
>
> please, any another advanced samples for error handling ??
>
> thanks.
>
>
> public String getErrorMessage(RecognitionException e,
> String[] tokenNames)
> {
> List stack = getRuleInvocationStack(e,
> this.getClass().getName());
> String msg = null;
> String inputContext =
> input.LT(-3) == null ? "" : ((Tree)input.LT(-
> 3)).getText()+"
> "+
> input.LT(-2) == null ? "" : ((Tree)input.LT(-
> 2)).getText()+"
> "+
> input.LT(-1) == null ? "" : ((Tree)input.LT(-
> 1)).getText()+"
> >>>"+
> ((Tree)input.LT(1)).getText()+"<<< "+
> ((Tree)input.LT(2)).getText()+" "+
> ((Tree)input.LT(3)).getText();
> if ( e instanceof NoViableAltException ) {
> NoViableAltException nvae = (NoViableAltException)e;
> msg = " no viable alt; token="+e.token+
> " (decision="+nvae.decisionNumber+
> " state "+nvae.stateNumber+")"+
> " decision=<<"+nvae.grammarDecisionDescription+">>";
> }
> else {
> msg = super.getErrorMessage(e, tokenNames);
> }
> return stack+" "+msg+" context=..."+inputContext+"...";
> }
> public String getTokenErrorDisplay(Token t) {
> return t.toString();
> }
>
> List: http://www.antlr.org/mailman/listinfo/antlr-interest
> Unsubscribe: http://www.antlr.org/mailman/options/antlr-interest/your-
> email-address
More information about the antlr-interest
mailing list