[antlr-interest] String Template question

Behdad Forghani behdad.forghani at samsarasol.com
Wed Jul 8 13:16:14 PDT 2009


Hi,

I have a  question regarding templates. I have spent a lot of time to get the syntax right with no success. I cannot get the syntax of calling a template within a template to work.
I expected the syntax to be:
<template(<arg>)>
I.e.,
if the first template is:
template1(arg1) ::= "... <arg1> ..."

Then for the second template to call the first template, the syntax would be:
template2(arg) :: <<
...
<template1(<arg>)>
...
>>

This does not seem to work.


I want to declare a C structure. The typename may not be present. I.e., 
sometimes it is struct {} x; and sometimes it is struct y {} x;. So, in 
the string template I have:

struct(typename) ::="struct <typename>"

Now I want to define a template to call struct.  I expected the 
following to work, but it doesn't:

headerFileStruct(typename, fieldname) ::= <<
  <struct(<typename>)> {
   int length;
 } fieldname;
>>

I have tried <struct(typename)>, <struct<$typename$>> and any possiblity 
that I could think of with now luck.

Another question, jsut to doublecheck, is there a way to trace and debug 
stringtemplates? Not that this would have helped with not knowing the 
syntax.

Thanks for your help and providing Antlr.


Behdad



More information about the antlr-interest mailing list