[antlr-interest] Imaginary node construction question and some feature thoughts...

Patrick Niemeyer pat at pat.net
Fri Nov 12 13:25:47 PST 2010


1)  I know that there is a syntax for constructing an imaginary node based on a single real token, but I'm wondering if there is some convenient way for me to initialize my node such that it spans all of the tokens matched...

So, for example in the following:

primary_expression_start   primary_expression_part* ->^(AST_PRIMARY_EXPRESSION primary_expression_start primary_expression_part*)

I'd like my ASTPrimaryExpresion node to correspond to start and stop tokens and text for the whole matched expression.  Of course I can implement that with a custom node, or action, but I am wondering if there is some easy way that I'm missing (maybe using parenthesis?)

I am also wondering if that wouldn't be a reasonable default behavior for imaginary nodes, to represent the span of tokens that they contain by start and stop token and text value spanning all of them.

2) I am actually using heterogeneous node types and so my rule looks like this:

primary_expression_start   primary_expression_part* ->^(AST_PRIMARY_EXPRESSION<ASTPrimaryExpression> primary_expression_start primary_expression_part*)

I am wondering if in the future we could do away with having to declare a token type for the imaginary node as well as reference the heterogeneous node type... i.e. could we just implicitly create a node type for it...  I guess I could just use a single bogus "MYNODE" type or something everywhere, but it just seems wrong.


thanks,
Pat Niemeyer



More information about the antlr-interest mailing list