language-nix-2.2.0: Data types and functions to represent the Nix language

Safe HaskellNone
LanguageHaskell2010

Language.Nix.Path

Synopsis

Documentation

data Path Source #

Paths are non-empty lists of identifiers in Nix.

>>> path # [ident # "yo"]
Path [Identifier "yo"]

Any attempt to construct the empty path throws an error:

>>> :set -XScopedTypeVariables
>>> either (\(_::SomeException) -> "empty paths are illegal") show <$> Excpt.try (evaluate (path # []))
"empty paths are illegal"

Paths can be pretty-printed and parsed with the Text class:

>>> parse "Path" "foo.\"foo.bar\".bar" :: Path
Path [Identifier "foo",Identifier "foo.bar",Identifier "bar"]
>>> pPrint (parse "Path" "foo.\"foo\".\"bar\".bar" :: Path)
foo.foo.bar.bar
\p -> Just (p :: Path) == parseM "Path" (prettyShow p)

Paths are instances of strings and can be implicitly converted:

>>> :set -XOverloadedStrings
>>> pPrint $ ("yo.bar" :: Path)
yo.bar
>>> pPrint $ ("  yo  .  bar" :: Path)
yo.bar

Freaky quoted identifiers are fine throughout:

>>> pPrint $ path # ["yo","b\"ar"]
yo."b\"ar"
>>> pPrint ("\"5ident\"" :: Path)
"5ident"
>>> pPrint $ path # ["5ident","foo.bar","foo\nbar"]
"5ident"."foo.bar"."foo\nbar"
Instances
Eq Path Source # 
Instance details

Defined in Language.Nix.Path

Methods

(==) :: Path -> Path -> Bool #

(/=) :: Path -> Path -> Bool #

Ord Path Source # 
Instance details

Defined in Language.Nix.Path

Methods

compare :: Path -> Path -> Ordering #

(<) :: Path -> Path -> Bool #

(<=) :: Path -> Path -> Bool #

(>) :: Path -> Path -> Bool #

(>=) :: Path -> Path -> Bool #

max :: Path -> Path -> Path #

min :: Path -> Path -> Path #

Show Path Source # 
Instance details

Defined in Language.Nix.Path

Methods

showsPrec :: Int -> Path -> ShowS #

show :: Path -> String #

showList :: [Path] -> ShowS #

IsString Path Source # 
Instance details

Defined in Language.Nix.Path

Methods

fromString :: String -> Path #

Generic Path Source # 
Instance details

Defined in Language.Nix.Path

Associated Types

type Rep Path :: Type -> Type #

Methods

from :: Path -> Rep Path x #

to :: Rep Path x -> Path #

Arbitrary Path Source # 
Instance details

Defined in Language.Nix.Path

Methods

arbitrary :: Gen Path #

shrink :: Path -> [Path] #

CoArbitrary Path Source # 
Instance details

Defined in Language.Nix.Path

Methods

coarbitrary :: Path -> Gen b -> Gen b #

NFData Path Source # 
Instance details

Defined in Language.Nix.Path

Methods

rnf :: Path -> () #

HasParser Path Source # 
Instance details

Defined in Language.Nix.Path

Methods

parser :: CharParser st input m Path #

Pretty Path Source # 
Instance details

Defined in Language.Nix.Path

type Rep Path Source # 
Instance details

Defined in Language.Nix.Path

type Rep Path = D1 (MetaData "Path" "Language.Nix.Path" "language-nix-2.2.0-4V8HiyuJODaH1hiGHTNPvO" True) (C1 (MetaCons "Path" PrefixI False) (S1 (MetaSel (Nothing :: Maybe Symbol) NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 [Identifier])))

path :: Iso' Path [Identifier] Source #

Use this isomorphism to construct a path from a list of identifiers, or to access that list for a given path.