0

How can I prevent new lines in StringTemplate? For example

myAssigns(isConst, myType, myName,exp1,exp2) ::=
<<
<if(isConst)>const <endif><myType> <myName> <if(exp2)> [<exp2>]<endif>= <exp1>;
>>

works and keeps the translation on one line, but it isn't easy to read. How can I escape my if statements to prevent them from printing on different lines. (In my sepcific case const type name would be on one line and exp2 and exp1 would be on the next line when printed to the screen.)

Pinsickle
  • 623
  • 2
  • 10
  • 20

2 Answers2

3

In v4 you can use t() ::= <%...%> syntax to have it ignore indentation and newlines.

Terence Parr
  • 5,912
  • 26
  • 32
  • Wow, an answer from the king of ANTLR himself! This will useful to know for a future project that I have in mind. Unfortunately, the work that I'm doing now is for a thesis. So time isn't on my side if I restarted with version 4. – Pinsickle Oct 12 '12 at 03:52
0

I found the answer to my question here (at the bottom of the page). It looks like the way I am doing it is how you have to do it (all on one line) to prevent unwanted newlines. If someone knows something that I don't, please let me know.

Pinsickle
  • 623
  • 2
  • 10
  • 20