Safe Haskell | Safe-Inferred |
---|---|
Language | Haskell2010 |
Unison.Codebase.Path
Contents
Synopsis
- data Path
- data Path'
- class Pathy path where
- class Pathy path => Namey path where
- newtype Absolute = Absolute {
- unabsolute :: Path
- absPath_ :: Lens' Absolute Path
- newtype Relative = Relative {
- unrelative :: Path
- relPath_ :: Lens' Relative Path
- class Resolve l r o where
- resolve :: l -> r -> o
- pattern Current :: Relative
- pattern Current' :: Path'
- pattern Root :: Absolute
- pattern Root' :: Path'
- singleton :: NameSegment -> Path
- isAbsolute :: Path' -> Bool
- isRelative :: Path' -> Bool
- parentOfName :: Name -> Split Path'
- maybePrefix :: Path' -> Path' -> Maybe Path'
- unprefix :: Relative -> Path' -> Path'
- maybePrefixName :: Path' -> Name -> Maybe Name
- prefixNameIfRel :: Path' -> Name -> Name
- unprefixName :: Relative -> Name -> Maybe Name
- type Split path = (path, NameSegment)
- ancestors :: Absolute -> Seq Absolute
- longestPathPrefix :: Absolute -> Absolute -> (Absolute, Relative, Relative)
- isRoot :: Absolute -> Bool
- absoluteToPath' :: Absolute -> Path'
- fromList :: [NameSegment] -> Path
- fromName :: Name -> Path
- fromName' :: Name -> Path'
- fromPath' :: Path' -> Path
- unsafeParseText :: Text -> Path
- unsafeParseText' :: Text -> Path'
- toAbsoluteSplit :: Absolute -> Split Path' -> Split Absolute
- toList :: Path -> [NameSegment]
- splitFromName :: Name -> Split Path
Documentation
A Path
is an internal structure representing some namespace in the codebase.
Foo.Bar.baz
becomes [Foo, Bar, "baz"]
.
NB: This shouldn’t be exposed outside of this module (preferPath'
, Absolute
, or Relative
), but it’s
currently used pretty widely. Such usage should be replaced when encountered.
Instances
Monoid Path Source # | |
Semigroup Path Source # | |
IsList Path Source # | Meant for use mostly in doc-tests where it's sometimes convenient to specify paths as lists. |
Show Path Source # | |
Eq Path Source # | |
Ord Path Source # | |
Namey Path Source # | |
Pathy Path Source # | |
Resolve Absolute Path Absolute Source # | |
Resolve Path Path Path Source # | |
Recursive Path (XNor NameSegment) Source # | |
Defined in Unison.Codebase.Path | |
Resolve Absolute (Split Path) (Split Absolute) Source # | |
type Item Path Source # | |
Defined in Unison.Codebase.Path |
A namespace that may be either absolute or relative, This is the most general type that should be used.
Constructors
AbsolutePath' Absolute | |
RelativePath' Relative |
class Pathy path where Source #
Methods
ascend :: path -> Maybe path Source #
descend :: path -> NameSegment -> path Source #
prefix :: path -> Relative -> path Source #
This always prefixes, since the second argument can never be absolute.
split :: path -> Maybe (Split path) Source #
Instances
Pathy Absolute Source # | |
Defined in Unison.Codebase.Path | |
Pathy Path Source # | |
Pathy Path' Source # | |
Pathy Relative Source # | |
Defined in Unison.Codebase.Path | |
Pathy ProjectPath Source # | |
Defined in Unison.Codebase.ProjectPath Methods ascend :: ProjectPath -> Maybe ProjectPath Source # descend :: ProjectPath -> NameSegment -> ProjectPath Source # prefix :: ProjectPath -> Relative -> ProjectPath Source # split :: ProjectPath -> Maybe (Split ProjectPath) Source # unsplit :: Split ProjectPath -> ProjectPath Source # toText :: ProjectPath -> Text Source # | |
Pathy ProjectPathNames Source # | |
Defined in Unison.Codebase.ProjectPath Methods ascend :: ProjectPathNames -> Maybe ProjectPathNames Source # descend :: ProjectPathNames -> NameSegment -> ProjectPathNames Source # prefix :: ProjectPathNames -> Relative -> ProjectPathNames Source # split :: ProjectPathNames -> Maybe (Split ProjectPathNames) Source # unsplit :: Split ProjectPathNames -> ProjectPathNames Source # toText :: ProjectPathNames -> Text Source # |
class Pathy path => Namey path where Source #
Minimal complete definition
Methods
nameFromSplit :: Split path -> Name Source #
toName :: path -> Maybe Name Source #
Convert a path' to a Name
An absolute from the current project root
Constructors
Absolute | |
Fields
|
Instances
Show Absolute Source # | |
Eq Absolute Source # | |
Ord Absolute Source # | |
Defined in Unison.Codebase.Path | |
Namey Absolute Source # | |
Pathy Absolute Source # | |
Defined in Unison.Codebase.Path | |
Resolve Absolute Path Absolute Source # | |
Resolve Absolute Path' Absolute Source # | |
Resolve Absolute Relative Absolute Source # | |
Resolve Absolute Relative Path' Source # | |
Recursive Absolute (XNor NameSegment) Source # | |
Defined in Unison.Codebase.Path | |
Resolve Absolute (Split Path) (Split Absolute) Source # | |
A namespace path that doesn’t necessarily start from the root. Typically refers to a path from the current namespace.
Constructors
Relative | |
Fields
|
Instances
class Resolve l r o where Source #
Instances
singleton :: NameSegment -> Path Source #
isAbsolute :: Path' -> Bool Source #
isRelative :: Path' -> Bool Source #
maybePrefix :: Path' -> Path' -> Maybe Path' Source #
Returns Nothing
if the second argument is absolute. A common pattern is
fromMaybe path $ maybePrefix prefix path
to use the unmodified path in that case.
unprefix :: Relative -> Path' -> Path' Source #
examples: unprefix foo.bar .blah == .blah (absolute paths left alone) unprefix foo.bar id == id (relative paths starting w/ nonmatching prefix left alone) unprefix foo.bar foo.bar.baz == baz (relative paths w/ common prefix get stripped)
maybePrefixName :: Path' -> Name -> Maybe Name Source #
Returns Nothing
if the second argument is absolute. A common pattern is
fromMaybe name $ maybePrefixName prefix name
to use the unmodified path in that case.
unprefixName :: Relative -> Name -> Maybe Name Source #
Remove a path prefix from a name.
Returns Nothing
if there are no remaining segments to construct the name from.
>>>
unprefixName (Relative $ fromList ["base", "List"]) (Name.unsafeFromText "base.List.map")
Just (Name Relative (NameSegment {toText = "map"} :| []))
type Split path = (path, NameSegment) Source #
utilities
longestPathPrefix :: Absolute -> Absolute -> (Absolute, Relative, Relative) Source #
Finds the longest shared path prefix of two paths. Returns (shared prefix, path to first location from shared prefix, path to second location from shared prefix)
>>>
longestPathPrefix ("a" :< "b" :< "x" :< Empty) ("a" :< "b" :< "c" :< Empty)
(a.b,x,c)
>>>
longestPathPrefix Empty ("a" :< "b" :< "c" :< Empty)
(,,a.b.c)
tests
conversions
absoluteToPath' :: Absolute -> Path' Source #
fromList :: [NameSegment] -> Path Source #
unsafeParseText :: Text -> Path Source #
unsafeParseText' :: Text -> Path' Source #
Construct a Path' from a text
>>>
fromText' "a.b.c"
a.b.c
>>>
fromText' ".a.b.c"
.a.b.c
>>>
show $ fromText' ""
""
toList :: Path -> [NameSegment] Source #