44{-# LANGUAGE TemplateHaskell #-}
55
66module Language.Nix.Identifier
7- ( Identifier , ident , quote , needsQuoting , nixKeywords
7+ ( -- * Type-safe Identifiers
8+ Identifier , ident
89 , parseSimpleIdentifier , parseQuotedIdentifier
9- -- TODO: why do we expose quote?
10+ -- * String Predicates
11+ , needsQuoting
12+ -- * Internals
13+ -- TODO: only required by the language-nix test suite, unexport?
14+ , nixKeywords
15+ , quote
1016 )
1117 where
1218
@@ -24,10 +30,12 @@ import Text.PrettyPrint.HughesPJClass as PP
2430-- (and viewed) with the 'ident' isomorphism. For the sake of convenience,
2531-- @Identifier@s are an instance of the 'IsString' class.
2632--
27- -- Reasonable people restrict themselves to identifiers of the form
28- -- @[a-zA-Z_][a-zA-Z0-9_'-]*@, because these don't need quoting. The
29- -- methods of the 'Pretty' class can be used to print an identifier with proper
30- -- quoting:
33+ -- It is usually wise to only use identifiers of the form
34+ -- @[a-zA-Z_][a-zA-Z0-9_'-]*@, because these don't need quoting.
35+ -- Consequently, they can appear almost anywhere in a Nix expression
36+ -- (whereas quoted identifiers e.g. can't be used in function patterns).
37+ -- The methods of the 'Pretty' class can be used to print an identifier
38+ -- with proper quoting:
3139--
3240-- >>> pPrint (ident # "test")
3341-- test
@@ -128,6 +136,7 @@ nixKeywords =
128136 [ " assert" , " with" , " if" , " then" , " else" , " let" , " in" , " rec" , " inherit" , " or" ]
129137
130138-- | Helper function to quote a given identifier string if necessary.
139+ -- Usually, one should use the 'Pretty' instance of 'Identifier' instead.
131140--
132141-- >>> putStrLn (quote "abc")
133142-- abc
0 commit comments