[antlr-interest] newbie's question on writing template rewrite rule

woodzltc zhou woodzltc at gmail.com
Thu Jun 21 18:30:15 PDT 2012


Hello all,

I am a newbie to ANTLR, a great tool in my opinion! Here is a question
on how to write template rewrite rule for such kind of rule:

classTopLevelScope
   :   ^(CLASS_TOP_LEVEL_SCOPE classScopeDeclarations*)

I want to insert something fixed between CLASS_TOP_LEVEL_SCOPE and
classScopeDeclarations*, what should I do?

I wrote something as follows:

classTopLevelScope
   :   ^(CLASS_TOP_LEVEL_SCOPE classScopeDeclarations*) ->
embed(arg1={$CLASS_TOP_LEVEL_SCOPE.text},
arg2={$classScopeDeclarations.text})

embed(arg1, arg2) ::= <<
$arg1$
blabla
blabla
$arg2$
>>

It does insert what I want. But it also drop all the stuff at the two
sides. I guess I am wrong with what I gave as arg1 and arg2. Anyone
can give me some suggestions? Thanks a lot!

Best
- Wu


More information about the antlr-interest mailing list