Found another issue with string quotations :-/

The length of the placeholder itself (compile-time length) is used to calculate indent for any subsequent placeholders on the same line, instead of the length of the substituted text (run-time length). This means that it is not possible to neatly align the contents of a second placeholder on a line if that second placeholders contents contain line endings.

The following stratego-shell session demonstrates this:


stratego> import libstratego-lib
stratego> $[[“left”] [“right\nright\nright\nright”]]
left right
right
right
right
“left right\n right\n right\n right”
stratego> $[[“left” ] [“right\nright\nright\nright”]]
left right
right
right
right
“left right\n right\n right\n right”
stratego> $[[“left” ] [“right\nright\nright\nright”]]
left right
right
right
right
“left right\n right\n right\n right”

In practice I stumbled upon this when generating Stratego code with string quotations using string quotations, with the quotation type parameterized, i.e.:


template-to-prettyprint-strategy:
Template-Production(sort, Template(e*), attr*) ->
$[prettyprint-[sort]:
cons ->
$[open][parts*][close]]

where open and close are at runtime set to one of () [] or {}.

The output I expected would be something like this:


prettyprint-Statement:
IfThenStatement(condition, statement*) ->
$[if [condition] then
[statement*]
end]

But instead all except the first line of the template are indented an extra 5 spaces (the length of the string "[open]" minus the length of the string "("…)

Submitted by Tobi Vollebregt on 18 April 2011 at 23:32

Log in to post comments