How to Allow Double Angle Brackets as a String
Sometimes the '>>'
and/or '<<'
delimiters in a StringTemplate group file need to be used as regular strings. This can arise if a StringTemplate is writing out C-code that uses the C operators '<<'
or '>>'
. For example, consider the follwing StringTemplate in a StringTemplate group file:
group mygroup;
mycode(a,b,c) ::= <<
. . .
d = e >> 3;
f = g << 4;
. . .
>>
If one uses the above template, a run-time error will occur because the shift operators in the statements are being interpreted as the beginning or end of a multiline StringTemplate. Ths solution is to escape each of the angle brackets within the StringTemplate:
group mygroup;
mycode(a,b,c) ::= <<
. . .
d = e \>\> 3;
f = g \<\< 4;
. . .
>>