[antlr-interest] node construction proposed upgrade

Terence Parr parrt at cs.usfca.edu
Sat Feb 26 13:45:54 PST 2011


At moment you can set hetero node type with token option:

type : ID<TypeNode> ;

var : ID<VarNode> ;

Sometimes you want to set token type / text of node.  can use -> now

type : ID -> TYPENAME[$ID] ; // sets new token type for ID; copies text, line, col

a : lc='{' ... '}' -> BLOCK[$lc, "BLOCK"] ; // sets new token type and text

Inline i'm proposing two new token option names: text, ttype to join current options node and assoc.

type : ID<ttype=TYPENAME> ;

a : '{'<ttype=BLOCK, text="BLOCK"> ... '}' ;

My motivation is this

    |   e '?'^ e ':' e

following is gross but would work:

    |   e '?'<type=TERNARY, text="?:">^ e ':' e

we could also mimic rewrite stuff by allowing args on tokens in parser rules:

    |   e '?'[TERNARY, "?:"]^ e ':' e

what say ye? 2nd option is appealing but slightly diff fom how rewrite element args work.

Ter


More information about the antlr-interest mailing list