[antlr-interest] Error Handling Advanced

Kirby Bohling kirby.bohling at gmail.com
Fri Apr 29 13:31:26 PDT 2011


Maybe it is easier using C#, but it always annoys me that in Java if I
implement my own superclass, I have to implement two versions (and
duplicate a bunch of goop).   Hopefully addressing that is on the
ANTLRv4 list.  I thought Terrance said he had ideas for that in the
future when it was brought up in the past.

I'd recommending delegating to a helper class if possible and you're
doing this in Java.  At least if you ever want to use AntlrWorks.
Otherwise, you'll get errors about not having the Debug class not
existing.

Kirby


On Fri, Apr 29, 2011 at 11:41 AM, Jim Idle <jimi at temporal-wave.com> wrote:
> 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
>
> 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