my language to parse contains statements like
public var a, b = 42, c;
I.e. the .g file looks something like:
statements
: (introduction | expression ';'! | ... )+
;
introduction
: head single+ -> ^(head single)+
;
single
: Name ('='^ expression)?
;
head
: modifiers* v='var' -> ^(VARIABLE[$v] modifiers*)
;
Generating a tree like that would be easy, but mostly useless (for me):
----------statements----------
/ | \
variable variable variable
/ \ / \ / \
'public' 'a' 'public' '=' 'public' 'c'
/ \
'b' expr
I would like to have the the '='
on top of the middle node:
----------statements----------
/ | \
variable '=' variable
/ \ / \ / \
'public' 'a' variable expr 'public' 'c'
/ \
'public' 'b'
but I can't find the rewrite rule to do that.