On Jan 26, 2010, at 6:00 PM, [email protected] wrote: > ROTFL! Thanks for calling it as you see it. I feel a little less naïve now, > knowing that you have "issues" with debugging. Thanks for the nice example > too!
:) Added a faq entry. yeah, it's tough for me right now because I'm debugging a tree grammar parsing an AST representing an ANTLR tree grammar. my brain hurts. Ter > > Kyle > > Sent from my Verizon Wireless BlackBerry > > -----Original Message----- > From: Terence Parr <[email protected]> > Date: Tue, 26 Jan 2010 14:57:40 > To: [email protected] interest<[email protected]> > Subject: [antlr-interest] better error messages in tree parsers > > Hi, a reminder that debugging tree grammars can be a bitch. I like to > override standard messaging to spew lots of stuff. E.g., i like this kind of > thing: > > ASTVerifier.g: node from after line 150:17 [grammarSpec, rules, rule, > altListAsBlock, altList, alternative, elements, element, ebnf, block, > altList, alternative] no viable alt; toke...@-1,0:0='ALT',<84>,0:-1] > (decision=24 state 3) decision=<<>> > context=...DOWN BLOCK DOWN >>>ALT<<< DOWN DOC_COMMENT... > > Here's my code: > > public String getErrorMessage(RecognitionException e, > String[] tokenNames) > { > List stack = getRuleInvocationStack(e, this.getClass().getName()); > String msg = null; > String inputContext = > ((Tree)input.LT(-3)).getText()+" "+ > ((Tree)input.LT(-2)).getText()+" "+ > ((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(); > } > > Ter > > 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 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.
