rnix-parser icon indicating copy to clipboard operation
rnix-parser copied to clipboard

Fails to correctly parse `''\'''${` inside `''` string

Open tejing1 opened this issue 3 months ago • 0 comments

Describe the bug

rnix-parser (as used inside statix, in the case I noticed it), fails to correctly parse certain valid escape sequences inside nix '' strings. The specific case I noticed this with is ''\'''${, which nix treats as an escaped form of '${. Notably, nix itself does not start an antiquote with this, which I suspect rnix-parser is doing.

Code Snippet to reproduce

$ cat test.nix
''
''\'''${
''
$ nix eval -f test.nix --raw
'${
$ nix run pkgs\#statix -- check test.nix
[E00] Error: Syntax error
   ╭─[test.nix:1:1]
   │
 1 │ ''
   · │ 
   · ╰─ Unexpected end of file, wanted any of [TOKEN_STRING_END, TOKEN_STRING_CONTENT, TOKEN_INTERPOL_START]
───╯
[E00] Error: Syntax error
   ╭─[test.nix:1:1]
   │
 1 │ ''
   · │ 
   · ╰─ Unexpected end of file, wanted any of [TOKEN_STRING_END]
───╯
[E00] Error: Syntax error
   ╭─[test.nix:1:1]
   │
 1 │ ''
   · │ 
   · ╰─ Unexpected end of file, wanted any of [TOKEN_INTERPOL_END]
───╯
[E00] Error: Syntax error
   ╭─[test.nix:1:1]
   │
 1 │ ''
   · │ 
   · ╰─ Unexpected end of file, wanted any of [TOKEN_STRING_END, TOKEN_STRING_CONTENT, TOKEN_INTERPOL_START]
───╯
[E00] Error: Syntax error
   ╭─[test.nix:1:1]
   │
 1 │ ''
   · │ 
   · ╰─ Unexpected end of file, wanted any of [TOKEN_STRING_END]
───╯
[E00] Error: Syntax error
   ╭─[test.nix:3:3]
   │
 3 │ ''
   ·   ┬  
   ·   ╰── Error node at 14..15
───╯

Expected behavior

This should parse as an ordinary string without antiquotes, and without prematurely ending the '' string. Specifically, the ''\' should parse as an escaped ', then the following ''${ should parse as an escaped ${

Additional context

statix 0.5.8, which according to my reading of its Cargo.lock, uses rnix 0.10.2

tejing1 avatar Aug 31 '25 00:08 tejing1