[antlr-interest] @after in lexer rule

Gavin Lambert antlr at mirality.co.nz
Tue Sep 9 01:24:54 PDT 2008


At 15:32 9/09/2008, Hartmuth Gutsche wrote:
 >I.e. the state class doesn't get modified with the values 
assigned
 >by the @after action.
 >
 >Because I use ANTLR only occasionally my question here is if I 
have
 >to change the grammar ( I am aware of changes with respect to
 >$channel) or if that is a bug?

Not sure if it counts as a bug or not, but the @after block is 
designated as cleanup code that gets executed when the rule exits 
(and not just for successful exits), so it does seem like the 
wrong place to do it.

You should probably move it into an unadorned block at the end of 
your rule.  That way it'll only execute if the rule matches.  Just 
be careful about how you've structured your alternates -- if the 
block is at the same level as some | alts then it will only apply 
to the closest alt, not the whole set.



More information about the antlr-interest mailing list