Hi Søren, You're right - it's not the most informative error message :)
Michael On 29 March 2011 01:35, Søren Boisen <[email protected]> wrote: > Hi Michael, > > Thanks for the reply. I agree that it was due to an error in my tree walker > grammar (that I've now found and fixed), but I think it is pretty bad that > ANTLR generates an internal error with no useful information, whenever I > make a mistake in my grammar. It certainly doesn't make it easy to learn > ANTLR and how to create tree parsers :-) > > I was therefore hoping for Ter or someone else with access, to create an > issue in the bug tracker, so it could be solved eventually. > > Regards > Søren > > 2011/3/28 Michael Bedward <[email protected]> >> >> Hi Søren, >> >> I see that error every so often and, so far al least, it has always >> been due to an error in my tree walker grammar - specifically an >> alternative that arises in the AST but that I forgot to consider in >> the grammar. >> >> Michael >> >> On 28 March 2011 23:29, Søren Boisen <[email protected]> wrote: >> > Greetings, >> > I have a encountered a problem while trying to write a tree parser for >> > my >> > grammar. Sometimes when trying to walk the AST and the tree parser fails >> > to >> > match some input, I get the following exception: >> > >> > can't look backwards more than one token in this stream >> > org.antlr.runtime.misc.LookaheadStream.LB(LookaheadStream.java:159) >> > org.antlr.runtime.misc.LookaheadStream.LT(LookaheadStream.java:120) >> > >> > >> > org.antlr.runtime.RecognitionException.extractInformationFromTreeNodeStream(RecognitionException.java:144) >> > >> > org.antlr.runtime.RecognitionException.(RecognitionException.java:111) >> > >> > >> > org.antlr.runtime.MismatchedTreeNodeException.(MismatchedTreeNodeException.java:42) >> > >> > >> > org.antlr.runtime.tree.TreeParser.recoverFromMismatchedToken(TreeParser.java:135) >> > org.antlr.runtime.BaseRecognizer.match(BaseRecognizer.java:115) >> > >> > >> > com.brunata.ws.rest.odata.query.NearestTelegramQueryWalker.queryOp(NearestTelegramQueryWalker.java:243) >> > >> > >> > com.brunata.ws.rest.odata.query.NearestTelegramQueryWalker.stmt(NearestTelegramQueryWalker.java:128) >> > >> > I have looked through the FAQ, the issue tracker and Google, but I >> > couldn't >> > find anything that looked related. >> > >> > From the stack trace it looks like an error in the >> > extractInformationFromTreeNodeStream, since I guess it shouldn't expect >> > to >> > always be able to look back more than one token in a stream. >> > Is there a workaround for this? This is the code I use for creating >> > parsers >> > and streams: >> > >> > String query = ...; // this is a parameter to the method >> > Map<String, String> propertyFilters = ...; // this is a field on >> > the >> > class >> > >> > ANTLRStringStream input = new ANTLRStringStream(query); >> > QueryParserLexer lexer = new QueryParserLexer(input); >> > >> > CommonTokenStream tokens = new CommonTokenStream(lexer); >> > QueryParserParser parser = new QueryParserParser(tokens); >> > >> > QueryParserParser.stmt_return result = tryParse(parser, query); >> > ast = (CommonTree) result.getTree(); >> > >> > CommonTreeNodeStream nodes = new CommonTreeNodeStream(ast); >> > nodes.setTokenStream(tokens); >> > >> > NearestTelegramQueryWalker walker = new >> > NearestTelegramQueryWalker(nodes); >> > propertyFilters = tryWalk(walker, query); >> > >> > Am I using the wrong kind of token/node streams or something? >> > >> > Regards, >> > Søren Boisen >> > >> > 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.
