language-nix-2.1.0.1: Data types and useful functions to represent and manipulate the Nix language.

Safe HaskellNone
LanguageHaskell2010

Language.Nix.Identifier

Synopsis

Documentation

data Identifier #

Identifiers in Nix are essentially strings. They can be constructed (and viewed) with the ident isomorphism. For the sake of convenience, Identifiers 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 Text class can be used to parse and pretty-print an identifier with proper quoting:

>>> disp (ident # "test")
test
>>> disp (ident # "foo.bar")
"foo.bar"
\str -> Just (ident # str) == simpleParse (quote str)
\i -> Just (i :: Identifier) == simpleParse (display i)
Instances
Eq Identifier # 
Instance details

Defined in Language.Nix.Identifier

Ord Identifier # 
Instance details

Defined in Language.Nix.Identifier

Show Identifier # 
Instance details

Defined in Language.Nix.Identifier

IsString Identifier # 
Instance details

Defined in Language.Nix.Identifier

Generic Identifier # 
Instance details

Defined in Language.Nix.Identifier

Associated Types

type Rep Identifier :: Type -> Type #

Text Identifier # 
Instance details

Defined in Language.Nix.Identifier

NFData Identifier # 
Instance details

Defined in Language.Nix.Identifier

Methods

rnf :: Identifier -> () #

Arbitrary Identifier # 
Instance details

Defined in Language.Nix.Identifier

type Rep Identifier # 
Instance details

Defined in Language.Nix.Identifier

type Rep Identifier = D1 (MetaData "Identifier" "Language.Nix.Identifier" "language-nix-2.1.0.1-BmSDMjriyUI13JPNa6s8Su" True) (C1 (MetaCons "Identifier" PrefixI False) (S1 (MetaSel (Nothing :: Maybe Symbol) NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 String)))

ident :: Iso' Identifier String #

An isomorphism that allows conversion of Identifier from/to the standard String type via review.

\str -> fromString str == ident # str
\str -> set ident str undefined == ident # str
\str -> view ident (review ident str) == str

quote :: String -> String #

Helper function to quote a given identifier string if necessary.

>>> putStrLn (quote "abc")
abc
>>> putStrLn (quote "abc.def")
"abc.def"

needsQuoting :: String -> Bool #

Checks whether a given string needs quoting when interpreted as an Identifier. Simple identifiers that don't need quoting match the regular expression ^[a-zA-Z_][a-zA-Z0-9_'-]*$.

parseSimpleIdentifier :: ReadP r Identifier #

ReadP parser for simple identifiers, i.e. those that don't need quoting.

parseQuotedIdentifier :: ReadP r Identifier #

ReadP parser for quoted identifiers, i.e. those that do need quoting.