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

Adrian Herscu bmf1972 at fastmail.fm
Tue Aug 21 13:52:38 PDT 2007


Thanks for the suggestion, Kay.

Kay Roepke wrote:
> 
> On Aug 21, 2007, at 9:32 PM, Adrian Herscu wrote:
> 
>> I want to embed my parser in an IDE. One of the required features is 
>> to provide error markers. The markers framework API requires the 
>> length of the error besides of the line and column.
>>
>> I have looked into the AST API and couldn't find nothing to help with 
>> this task... Searched the group and google, but still nothing :-(
> 
> A tree node has the start and stop token index (in the sense that in a 
> tree like ^(+ 3 4) the + encompasses everything below). From that you 
> can get the tokens from the token stream and eventually figure out the 
> length of the matched string in the character stream :)

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...

> 
> HTH,
> -k



More information about the antlr-interest mailing list