Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Language.Nix.Identifier: Identifiers can never contain NUL bytes
The representation with Strings is tricky of course since identifiers in
Nix are technically byte strings (if you allow quoting). For our
purposes, it is practical to assume that all identifiers are ASCII or
UTF-8 encoded. With quoting, we can represent any Unicode character
except '\0'.
  • Loading branch information
sternenseemann committed Sep 12, 2025
commit 644be5e956c2123f44fa7c96c9731fa851127f09
5 changes: 4 additions & 1 deletion language-nix/src/Language/Nix/Identifier.hs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ import Text.PrettyPrint.HughesPJClass as PP
-- >>> pPrint (ident # "foo.bar")
-- "foo.bar"
--
-- __Warning__: Identifiers /may not/ contain @\'\\0\'@, but this is not
-- checked during construction!
--
-- prop> \str -> Just (ident # str) == parseM "Ident" (quote str)
-- prop> \i -> Just (i :: Identifier) == parseM "Ident" (prettyShow i)
declareLenses [d| newtype Identifier = Identifier { ident :: String }
Expand All @@ -49,7 +52,7 @@ instance NFData Identifier where
rnf (Identifier str) = rnf str

instance Arbitrary Identifier where
arbitrary = Identifier <$> listOf1 arbitraryUnicodeChar
arbitrary = Identifier <$> listOf1 (arbitraryUnicodeChar `suchThat` (/= '\0'))
shrink (Identifier i) = map Identifier (shrink i)

instance CoArbitrary Identifier
Expand Down