kamadorueda / alejandra

The Uncompromising Nix Code Formatter
https://kamadorueda.github.io/alejandra/
The Unlicense
855 stars 41 forks source link

Valid escapes in `''` string are parsed as an error #417

Open me-and opened 4 months ago

me-and commented 4 months ago

The following is a valid Nix file:

{
  value = ''
    ''\'''${
  '';
}

This file produces an error with Alejandra:

$ alejandra test.nix
Checking style in 1 file using 9 threads.

Failed! 1 error found at:
- test.nix: unexpected end of file, wanted any of [TOKEN_STRING_END, TOKEN_STRING_CONTENT, TOKEN_INTERPOL_START]

But it's parsed as expected by nix:

$ nix --extra-experimental-features nix-command eval --read-only --file ./test.nix --raw value
'${

As a workaround, I can use ${"'"} to escape the single quote, rather than ''\', but this shouldn't be necessary as both are valid syntax.

me-and commented 4 months ago

This is possibly related to #194, although I'm not sure if it's fundamentally the same problem or a different problem in a related area.