1module Language.Nix.Path ( Path, path ) where
4import Distribution.Nixpkgs.Util.PrettyPrinting ( Pretty (..), char, hcat, punctuate )
5import Language.Nix.Identifier
7-- | Paths are non-empty lists of identifiers in Nix.
9-- >>> set path [set ident "yo" undefined] undefined
10-- Path {_segments = [Identifier "yo"]}
12-- Any attempt to construct the empty path throws an 'error':
14-- >>> set path [] undefined
15-- Path {_segments = *** Exception: Nix paths cannot be empty
17-- 'Identifier' is an instance of 'IsString':
19-- >>> :set -XOverloadedStrings
20-- >>> pPrint $ set path ["yo","bar"] undefined
23-- Freaky quoted identifiers are fine except in the first segment:
25-- >>> pPrint $ set path ["yo","b\"ar"] undefined
27-- >>> pPrint $ set path ["5ident"] undefined
28-- *** Exception: invalid Nix path: [Identifier "5ident"]
29-- >>> pPrint $ set path ["5ident","foo","bar"] undefined
30-- *** Exception: invalid Nix path: [Identifier "5ident",Identifier "foo",Identifier "bar"]
32newtype Path = Path { _segments :: [Identifier] }
33 deriving (Show, Eq, Ord)
35instance Default Path where def = Path (error "undefined Nix.Path")
37path :: Lens' Path [Identifier]
38path f (Path ids) = mkPath `fmap` f ids
40 mkPath :: [Identifier] -> Path
41 mkPath [] = error "Nix paths cannot be empty"
43 | s0^.ident.to needsQuoting = error ("invalid Nix path: " ++ show p)
46instance Pretty Path where
47 pPrint p = hcat $ punctuate (char '.') $ pPrint <$> p^.path
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list