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

Interpolation and files imported as Text #2078

Closed
mmhat opened this issue Oct 25, 2020 · 1 comment · Fixed by #2083
Closed

Interpolation and files imported as Text #2078

mmhat opened this issue Oct 25, 2020 · 1 comment · Fixed by #2083

Comments

@mmhat
Copy link
Collaborator

mmhat commented Oct 25, 2020

Consider this a Bash script called test.sh with the following content:

#!/usr/bin/bash

cat <<EOF
echo '${1}'
EOF

Now if we run dhall <<< "./test.sh as Text" we get

''
#!/usr/bin/bash

cat <<EOF
echo '''${1}'
EOF
''

Note that '${1}' is not escaped properly. In particular dhall <<< "./test.sh as Text" | dhall errors complaining that you can only interpolate Text.

I expected that as Text imports the test.sh as raw text, i.e. without interpolation.

@Gabriella439
Copy link
Collaborator

Gabriella439 commented Oct 25, 2020

@mmhat: The import is working fine (meaning that the import is being imported as raw text). If the import had not been treated as raw text then the import would have failed (because test.sh is not a valid Dhall expression).

The issue is that the '${1}' is not being escaped correctly by the pretty-printer. Normally the way to escape ${x} in a multi-line Text literal is to prefix it with two single quotes (i.e. ''${x}), but the issue is that there is already another single quote before that, leading to three single quotes in a row ('''), which is itself a separate escape sequence for two single quotes in a multi-line string literal.

Fortunately, this should be easy to fix by changing the pretty-printer to render the string to something like this:

''
#!/usr/bin/bash

cat <<EOF
echo ${"'"}''${1}'
EOF
''

mmhat pushed a commit to mmhat/dhall-haskell that referenced this issue Oct 26, 2020
@mmhat mmhat mentioned this issue Oct 26, 2020
Gabriella439 added a commit that referenced this issue Oct 29, 2020
Fixes #2078

Previously the pretty-printer would escape `'${` as `'''${` inside of
a multi-line string, but that escape sequence is incorrect because
`'''` is itself an escape sequence for `''`.  The solution is to
instead escape `'${` as `${"'"}${`
Gabriella439 added a commit that referenced this issue Nov 1, 2020
Fixes #2078

Previously the pretty-printer would escape `'${` as `'''${` inside of
a multi-line string, but that escape sequence is incorrect because
`'''` is itself an escape sequence for `''`.  The solution is to
instead escape `'${` as `${"'"}${`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants