[antlr-interest] initializing a new node using a parser rule match

Devon devon.rueckner at temboo.com
Fri Jan 18 15:09:23 PST 2008


Hi -

NB:  My target is Python.

I'm having difficulty creating an imaginary node and initializing it
(with line/char number in particular) using information from a matched
rule.

In our expression language, two tokens next to each other (ignoring
whitespace) is an implicit concatenation (which we represent as a
FUNCTION type node with the text "concat").  I therefore need to
create an imaginary FUNCTION node.

My intuition was to do something like this:

concatExpr
    :   (addExpr -> addExpr)
        (a=addExpr -> ^(FUNCTION[$a, 'concat'] $concatExpr $a))*
    ;

However, this throws the error "missing attribute access on rule scope".
The following creates the expect tree, except FUNCTION contains
incorrect line/character information:

concatExpr
    :   (addExpr -> addExpr)
        (addExpr -> ^({self.adaptor.createFromType(FUNCTION,"concat")}
$concatExpr addExpr))*
    ;

Any ideas how to get the right info into the node?  In this case, the
best info to insert would actually be the character and line numbers
immediately following the first addExpr (since there could be a lot of
or no whitespace).

Thanks for your help
~ Devon


More information about the antlr-interest mailing list