[antlr-interest] Performing actions on a token

Tyler Distad tyler.distad at gmail.com
Mon Apr 12 20:48:57 PDT 2010


In my combined lexer/parser grammar, I have the following token rule:

FILE_DELIMITER : '|||||' (PRINTABLE ~ '|')+ '|||||' {$channel = HIDDEN;};

In a separate file, I have a tree parser grammar.

In one of these two files, I need to perform a specific action when this
token is found. I tried to add an action in my lexer/parser grammar, but it
wouldn't let me perform any actions on the token itself. (I need the text of
it.) Also, because the token can appear any number of times, at any point in
my grammar, it cannot easily be added to my tree grammar rules.

Is there any way for me to perform an action when this token appears in my
token stream? For various reasons, I wouldn't at all mind overriding some
part of the tokenization process if need be.

Tyler Distad


More information about the antlr-interest mailing list