Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Decide how interpolating a multiline string preceded by an indent into a symbolic string should behave #1006

Open
matthew-healy opened this issue Dec 16, 2022 · 1 comment

Comments

@matthew-healy
Copy link
Contributor

On the symbolic strings PR (#994), @yannham pointed out that there's an inconsistency between how symbolic strings and multiline strings handle the interpolation of strings with multiple lines when preceded by an indent.

With multiline strings, the behaviour is as follows:

let s = "a\nb" in
m%"
begin
    %{s}
end"%

results in:

begin
    a
    b
end

i.e., the indentation preceding the first line of the interpolated string is also applied to the following lines.

However, currently with symbolic strings this does not happen. Which is to say that this:

let s = "a\nb" in
s%"
begin
    %{s}
end"%

evaluates to (with newlines written as escape characters for clarity):

[  "begin\n    ", "a\nb", "\nend" ]

The question essentially is whether it might be more natural to apply the same rule here. That is, to have the symbolic string above evaluate instead to:

[  "begin\n    ", "a\n    b", "\nend" ]
@vkleen
Copy link
Contributor

vkleen commented Dec 16, 2022

Having been educated about the (awesome!) behaviour of regular multiline strings with interpolation, I feel like we should have a way of implementing the same behaviour for symbolic strings. But I don't think selectively altering interpolated expressions, when they happen to be strings, would be the correct semantics. If we were to opt for a tagged representation of a symbolic string in Nickel these things could easily be implemented as library functions. E.g. if

let s = "a\nb" in
s%"
begin
    %{s}
end

evaluates to the array

[
  { type = `Literal, value = "begin\n    " },
  { type = `Interpolation, indent = 4, value = "a\nb" },
  { type = `Literal, value = "end\n" }
]

we could easily have a Nickel library function that turns { type = `Interpolation, indent = 4, value = "a\nb" } into "a\n b" if that is what's desired.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants