[antlr-interest] Template Rewrite Rule consumes one more Token than expected

Felix Dorner felix_do at web.de
Mon Apr 21 06:51:06 PDT 2008


Thomas Karcher wrote:
>> a * b; \n
>> returns "where's the semicolon?", i.e. the trailing semicolon is eaten 
>> up too...
>>     
>
> What do you expect?
>   
I expect "where's the semicolon?;"
> The "!" at the end prevents the construction of a ";" node in the
> resulting AST, so ...
>   
Right, but it does not delete the ";" from the corresponding Token stream.
>> tree grammar TestTree;
>> expression
>>     :    ^('*' ID ID)
>>             -> template(text={"where's the semicolon?"}) "<text>"
>>     
>
> ... doesn't expect any ";" node in the AST ... your example does exactly
> what I hope it should do :)
> Where do you see the problem?
>   
I expect the "a*b" to be replaced by "where's the semicolon?",  but the 
semicolon should remain
in the token stream.

The template rewrite rule for an "expression" should only replace the 
tokens that were matched
for that expression.

Felix





More information about the antlr-interest mailing list