Skip to content
Merged
Changes from all commits
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
21 changes: 15 additions & 6 deletions language-nix/src/Language/Nix/Identifier.hs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,15 @@
{-# LANGUAGE TemplateHaskell #-}

module Language.Nix.Identifier
( Identifier, ident, quote, needsQuoting, nixKeywords
( -- * Type-safe Identifiers
Identifier, ident
, parseSimpleIdentifier, parseQuotedIdentifier
-- TODO: why do we expose quote?
-- * String Predicates
, needsQuoting
-- * Internals
-- TODO: only required by the language-nix test suite, unexport?
, nixKeywords
, quote
)
where

Expand All @@ -24,10 +30,12 @@ import Text.PrettyPrint.HughesPJClass as PP
-- (and viewed) with the 'ident' isomorphism. For the sake of convenience,
-- @Identifier@s are an instance of the 'IsString' class.
--
-- Reasonable people restrict themselves to identifiers of the form
-- @[a-zA-Z_][a-zA-Z0-9_'-]*@, because these don't need quoting. The
-- methods of the 'Pretty' class can be used to print an identifier with proper
-- quoting:
-- It is usually wise to only use identifiers of the form
-- @[a-zA-Z_][a-zA-Z0-9_'-]*@, because these don't need quoting.
-- Consequently, they can appear almost anywhere in a Nix expression
-- (whereas quoted identifiers e.g. can't be used in function patterns).
-- The methods of the 'Pretty' class can be used to print an identifier
-- with proper quoting:
--
-- >>> pPrint (ident # "test")
-- test
Expand Down Expand Up @@ -128,6 +136,7 @@ nixKeywords =
[ "assert", "with", "if", "then", "else", "let", "in", "rec", "inherit", "or" ]

-- | Helper function to quote a given identifier string if necessary.
-- Usually, one should use the 'Pretty' instance of 'Identifier' instead.
--
-- >>> putStrLn (quote "abc")
-- abc
Expand Down
Loading