With ANTLR2, you could define something like this in grammar definition file:
options
{
language = "CSharp";
namespace = "Extended.Tokens";
}
tokens {
TOKEN<AST=Extended.Tokens.TokenNode>;
}
And then, you could create a class:
public class TokenNode: antlr.BaseAST
{
...
}
Any ideea if something like this can be used (delegate class creation to AST factory instead of me doing the tree replication manually)? It's not working just by simple grammar definition copy from old to new format, and I tried to search their site and samples for somthing similar. Any hints?
EDIT
I'm not trying to create custom tokens, but custom 'node parsers'.
In order to 'execute' a tree you have 2 choices (as far as I understood):
- create a 'tree visitor' and handle values, or
- create a tree parser by 'almost-duplicating' the grammar definition.
In v2 case, I could decorate the tree node to whateveer method I would have liked and then call them after the parser ran by just calling something like 'execute' from root node.