Suppose that I have this simple and meaningless grammar:
propagate : what^ where*;
what : CHAR^;
where : NUMBER -> ^(PLUS NUMBER);
NUMBER : '0'..'9';
CHAR : 'a'..'z';
PLUS : '+';
If it parses a string like a123456789
, it generates an AST like:
What I would to do is to pass the token parsed by what
to where
and create an AST (for the same input) like:
I tried in the following way:
propagate : w=what^ where[$w.text]*;
what : CHAR^;
where[String s] : NUMBER -> ^(PLUS CHAR[s] NUMBER);
NUMBER : '0'..'9';
CHAR : 'a'..'z';
PLUS : '+';
it works if what
it's a single token, but what if it is a tree?
Is this the correct approach?