[antlr-interest] Error Handling Advanced
Prados Valiente Enrique
Enrique.PradosValiente at reale.es
Fri Apr 29 02:06:53 PDT 2011
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();
}
More information about the antlr-interest
mailing list