[antlr-interest] Syntax confirmation
Kay Roepke
kroepke at classdump.org
Fri Aug 4 04:02:15 PDT 2006
Hi Phil!
On 4. Aug 2006, at 12:46 Uhr, Phil Ritchie wrote:
> Am I correct in my understanding:
>
> [snippet from grammar file]
> file
> : rec=record -> {%file(r={$rec.text})}
> ;
>
> %file corresponds to a StringTemplate template.
> r corresponds to the template parameter
Sort of, yes.
The '->' is already a rewrite operation. So the rule must be:
file
: rec=record -> file(r={$rec.text})
;
This would indeed use the template you mentioned.
The % notation is for use in actions that are not part of rewrites,
when you need to instantiate templates yourself:
file
: rec=record {StringTemplate recTmpl = %file(r={$rec.text});}
;
This amounts to the same thing, only it is not automatically set in
the rule's return value.
See the cminus example in the examples <http://www.antlr.org/download/
examples-v3.tar.gz> for a lot of template instantiations :)
Or for a real life example look at Ter's Mantra language (<http://
linguamantra.org/>).
HTH,
-k
--
Kay Röpke <kroepke at classdump.org>
classdump Software
More information about the antlr-interest
mailing list