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

Safe HaskellNone




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 <$> try (evaluate (path # []))
"empty paths are illegal"

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

>>> simpleParse "foo.\"\".bar" :: Maybe Path
Just (Path [Identifier "foo",Identifier "",Identifier "bar"])
>>> maybe empty disp (simpleParse "foo.\"foo\".\"bar\".bar" :: Maybe Path)
\p -> Just (p :: Path) == simpleParse (display p)

Paths are instances of strings and can be implicitly converted:

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

Freaky quoted identifiers are fine throughout:

>>> disp $ path # ["yo","b\"ar"]
>>> disp ("\"5ident\"" :: Path)
>>> disp $ path # ["5ident","","foo\nbar"]

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.