Skip to content

Conversation

@sternenseemann
Copy link
Member

@sternenseemann sternenseemann commented Oct 24, 2025

Language.Nix.Identifier pretty much assumed that quoted identifiers could be rendered using show and parsed using read. This is not the case and resolved in this PR.

Additionally, I added some test cases that roundtrip identifiers through nix-instantiate --eval which should catch any remaining or re-introduced problems with the changed code. This cases are skipped if nix-instantiate can't be executed which is the case in Haskell-CI. I have some more tests in mind which I'll add in follow up PRs, I think.

Haven't tested whether it actually works in a derivation, but I don't see why not.

@sternenseemann sternenseemann force-pushed the sterni-wip-escaping branch 3 times, most recently from a3276df to ca6793c Compare November 8, 2025 11:20
This code previously assumed escape sequences in strings work like in
Haskell. This is not generally the case. This commit adds a custom
implementation of the relevant parsing and rendering logic which even
simplifies some things.

Escape sequences are a little weird in Nix since only very few things
_have_ to be escaped and some things not always, depending on
context (i.e. $). I've linked the best reference (the lexer) in the
code, but the manual is also helpful:
https://nix.dev/manual/nix/2.30/language/string-literals.html
We currently test two things marginally different things:

1. If we produce identifier syntax with quote, we verify that Nix will
   be able to parse and evaluate it and later produce the same quoted
   identifier as we do. (This makes sure we don't quote unnecessarily.)
2. If we prettyShow an Identifier, we verify that Nix will be able to
   parse and evaluate it and that we will be able to parse what Nix
   pretty prints.
@sternenseemann sternenseemann marked this pull request as ready for review November 8, 2025 11:25
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

Successfully merging this pull request may close these issues.

2 participants