I am trying to write a manual tree walker in Java for an AST generated by ANTLR V3. The AST is built using island grammers as similar to the one specified in ANTLR: call a rule from a different grammar.
In the AST, I have a node for expression list with each expression as child node. Now I need to know the line numbers of the COMMAs which seperated the expressions. The COMMAs were present in parsing but removed during AST rewrite.
I see some resources(here and here) pointing to the usage of CommonTokenStream.getTokens but I am not sure how I can access the CommonTokenStream while processing the AST. Is there anyway I can get the CommonTokenStream used to build the AST?
COMMA
in your tree-walker, include it (or them). – Bart KiersgetTokenStartIndex()
andgetTokenStopIndex()
without cluttering the AST with theCOMMA
tokens. Or do I need to extend the CommonTree to include the source tokenStream? – Skar