[antlr-interest] how to call the getErrorMessage method

jabon elekis at gmail.com
Sat Apr 26 12:59:42 PDT 2008


hi all,
always try to get error from the parser, I overided the reporterror like 
that


     public void reportError (RecognitionException re){
              throw new RuntimeException("Bailing out!",re);
         }

    
other way, I have the follow catch

 catch(RuntimeException e){
            System.err.println("runtimeException ERROR:\n");
            System.exit(1);
        }

after a little research, I found that I have to override the followed méthod
but how to call this method , I havent the tokenName.

thanks

a++

         public String getErrorMessage(RecognitionException e,String[] 
tokenNames)
    {
        List stack = getRuleInvocationStack(e, this.getClass().getName());
        String msg = null;
        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;
    }
    
    public String getTokenErrorDisplay(Token t) {
        return t.toString();
    }


More information about the antlr-interest mailing list