Search code examples
templatesantlrantlr3stringtemplate

Problem with parameter passing for stringtemplate


Given this rules :

 defServ: 'service' path bodyServ? SEP ->Serv(....);

 path: t+=ID ('/' t+=ID)* ->path(...);

I ask, as you can pass the token list "t" to the templete "Serv"?

The simplest solution would be to put the production of pathServ in defServ, that is :

   defServ: 'service'  t+=ID ('/' t+=ID)* bodyServ? SEP ->Serv(a={$t}, ...);

a better solution?

Thanks you


Solution

  • Tanuzzo88 wrote:

    I ask, as you can pass the token list "t" to the templete "Serv"?

    Sure, try this:

    defServ
      :  'service' path bodyServ? SEP -> Serv(a={$path.ids})
      ;
    
    path returns [List ids]
      :  t+=ID ('/' t+=ID)* {$ids = $t;}
      ;