...
In this case, whatever was matched for the type
rule would be replicated for each identifier match on the input stream. Input tokens int i,j
would become output token stream int i; int j;
.
where the output grammar is actually using StringTemplate as an "unparser"
...
This token stream could then be repeatedly processed by the rules until nothing had changed, signifying the end of translation. Naturally, one could design rewrite rules that flip back and forth between two patterns causing an infinite loop. This is a well-known problem and rewrite systems. I'm satisfied to send the call that a bug in your rewrite rules, though I'm sure I could come up with something nice to let you know precisely which rules were the problem.
You could also go to text instead of a token stream. In this case, the output grammar would actually be a StringTemplate (an "unparser"). For example, the following transformation would convert the token stream matched on the left hand push all of the elements into the attributes of the template on the right:
No Format |
---|
expr:
type ID (',' ID)* -> "<type> <ID; separator=\", \">"
|
Grammatical context
Arbitrary semantic content
No Format |
---|