ANTLRMorph generates the rewritten text based on the output pattern. The output pattern are actually StringTemplate templates (an "unparser") using ANTLR v3's built-in support for constructing StringTemplate templates. Morph figures out which tokens, rules, and labels you reference in the template and then set those template attributes using an ANTLR v3 template rewrite rule. Here are some sample output patterns:
"1"
"<c>"
"<a; separator=\"\n\">"
"<a:{x|<x>}; separator=\"\n\">"
"<f(x=a)>"
"<if(a)><f(x=y)><endif>"
"<if(a)><f(x=y)><else><z><endif>"
"<a.prop>"
"<a.b.c:row()>"
"<[mine,yours]:{ v | <v><z>}>"
"<rest(numbers):{ n | sum += <n>;}>"
You can use <<...>> style templates too:
file: (p+=prop)+ ->
<<
\<properties>
<p; separator="\n">
\</properties>
>>
;
You can also specify arbitrary attributes yourself:
morph Sample;
labels { c,d=INT; }
...
expr : "... c+d ..." -> template(v={$c.int+$d.int}) "<v>" ;
Labels: