How to use '[' and ']' in formatted strings?
During code generation it might become necessary to create
Asked by Sven Stork on 15 January 2013 at 23:02'['
and']'
and characters in the output file. Unfortunately those characters are part of the the Stratego grammar.
3 Answers
To generate those characters inside a formatted string (i.e.,
Answered by Sven Stork on 15 January 2013 at 23:04$[...]
) you first have to enclose them in double quotes and the enclose them in'['
and']'
to escape into the variable area. (e.g.,Subscript(e, index) -> $[ ([e']) ["["] [index'] ["]"] ]
)
You can also use the
Answered by Gabriƫl Konat on 16 January 2013 at 12:19${...}
or$<...>
string formatters if you want to easily use[
and]
.
Yet another way is to use escaping like this:
Answered by Lennart Kats on 16 January 2013 at 17:18$[ ...... $]$ ...... ]