Hi,
I've been experimenting with a simple rewriter. The AST construction works
fine and does what I expect, but there must be something about the
interaction between Antlr and Stringtemplate that I don't understand despite
reading the Antlr book, because I can't get even simple things to do what I
want.
Here is an example I've simplified so much there's hardly anything left. I
just want to rewrite (1 2 3) into [1, 2, 3], but the elements disappear on
the way. I was under the impression that it was enough to specify the
rewrites I wanted to make and leave everything else alone with rewrite=true,
so why are the elements null?
Please help me out by explaining or pointing me to some passage in the book
or documentation. I'm very grateful for any help. Thank you.
The input:
(1 2 3)
The output:
tree=(List 1 2 3)
body=[null, null, null]
[]
-----------
grammar Example;
options { output=AST; }
tokens {
List;
}
cu:
expr+
;
expr:
INT
| ID
| list
;
list:
'(' expr* ')' -> ^(List expr*)
;
..
---------------------
tree grammar Gen;
options {
tokenVocab=Example;
ASTLabelType=CommonTree;
output=template;
rewrite=true;
}
cu:
expr+
;
expr:
INT
| ID
| list
;
list:
^(List body+=expr*)
{
System.out.println("body=" + $body.toString());
}
-> list(exprs={$body})
;
-----
list(exprs) ::=
<<
[<exprs; separator=", ">]
>>
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"il-antlr-interest" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/il-antlr-interest?hl=en
-~----------~----~----~----~------~----~------~--~---
List: http://www.antlr.org/mailman/listinfo/antlr-interest
Unsubscribe:
http://www.antlr.org/mailman/options/antlr-interest/your-email-address