[antlr-interest] retrieving the length of a production match

Kay Roepke kroepke at classdump.org
Tue Aug 21 14:11:12 PDT 2007


On Aug 21, 2007, at 10:52 PM, Adrian Herscu wrote:

> I couldn't find a method that returns the stop token...
> But having an AST, it seems possible to iterate over its children  
> using getNextSibling() till the last child... then iterate over its  
> children till the last child... and so on, till the so called "stop  
> token"... awful! Is there something that I am missing?
>
> Thinking...
> Hmmm, that information is already available during the AST  
> construction...

Yes, it is.  But the tree only stores the indices into the token  
stream. So you can call tree.getTokenStartIndex() and  
getTokenStopIndex() to get that info.
Then ask the tree adaptor that built the tree for its tokenSource and  
get the tokens associated with the indices. That get's you the  
appropriate positions and stuff.

mmh. maybe this should be made easier...

HTH,
-k
-- 
Kay Röpke
http://classdump.org/






More information about the antlr-interest mailing list