src/pkg/path.bend checks
raw source on the hub · import ezx@1.6.0.0/src/pkg/path.bend as Path
pkg/path: the path arithmetic the import walk needs, lexical only. Base has
no readdir and no realpath, and a module's name in a package is the path it
was reached through, so . and .. are resolved by text rather than by
asking the file system.
1 import
import Base
Types
type Walk source · line 9 · raw
Data
where a normalisation has got to: abs is true for a path that began at the
root, out the components kept so far, reversed
Walk@abs:Bool -> @out:List<&2, String> -> Walk
type Comp source · line 13 · raw
Data
what one component of a path turned out to be
CSkipComp
CUpComp
CName@s:String -> Comp
Definitions
def comp_of source · line 19 · raw
@+part:String -> Comp
a component classified. +c because it is both asked about and kept.
def up.root source · line 25 · raw
@abs:Bool -> List<&2, String>
a climb with nothing left to climb off: at the root it goes nowhere, and in a relative path it is kept, since the package may still be re-rooted under it
def up.back source · line 33 · raw
@same:Bool -> @head:String -> @rest:List<&2, String> -> List<&2, String>
a climb past a component that is itself a climb keeps both
def up.go source · line 41 · raw
@+head:String -> @rest:List<&2, String> -> List<&2, String>
a climb against what has been kept: it cancels the last real component
def up source · line 45 · raw
@abs:Bool -> @out:List<&2, String> -> List<&2, String>
a climb against what has been kept
def up.step source · line 53 · raw
@+abs:Bool -> @out:List<&2, String> -> Walk
a climb, with the root flag carried through
def norm.go source · line 57 · raw
@st:Walk -> @comp:Comp -> Walk
the state once a component has been classified
def norm.step source · line 68 · raw
@st:Walk -> @part:String -> Walk
one component against the state
def norm.rel source · line 72 · raw
@+body:String -> String
a relative path with nothing left in it is the current directory
def norm.text source · line 76 · raw
@abs:Bool -> @body:String -> String
the components put back together, under the root or not
def norm.fin source · line 84 · raw
@st:Walk -> String
the components a normalisation kept, in order
def norm.walk source · line 92 · raw
@cs:List<&2, String> -> @st:Walk -> Walk
the walk one component at a time. Base's List.foldl applies an erased
function parameter, which Bend's termination check cannot see through, so
every def reaching it is reported as relying on unsafe code; a walk written
out is structural and costs nothing.
def norm source · line 102 · raw
@+path:String -> String
a path with . and an inner .. resolved by text. A leading .. survives,
because a module reached through one re-roots the package rather than
escaping it.
def base.go source · line 107 · raw
@ps:List<&2, String> -> @+last:String -> String
the component carried so far, kept when nothing follows it. The list is the first argument because that is the one the walk shrinks.
def base.last source · line 115 · raw
@ps:List<&2, String> -> String
the last component of a path
def base source · line 123 · raw
@path:String -> String
the last component of a path
def dir source · line 127 · raw
@+path:String -> String
the path with its last component climbed back off
def join.at source · line 134 · raw
@bare:Bool -> @left:String -> @right:String -> String
the path before it is normalised: the second alone when there is no
directory to take it relative to, the two spliced otherwise. Split out so
that norm runs once. Under a Bool.pick both arms were built, so every
join paid two full component walks and one concatenation it threw away.
def join source · line 143 · raw
@+left:String -> @+right:String -> String
a path taken relative to a directory. An empty directory means the path is already where it should be, and never that it starts at the root.
def tail source · line 147 · raw
@path:String -> @count:Nat -> String
the last n components of a path
def up.is source · line 152 · raw
@part:String -> Bool
whether a component is a climb
def ups.go source · line 158 · raw
@ps:List<&2, String> -> Nat
the climbs among components counted one at a time. Base's List.filter
applies an erased function parameter, so it falls outside the termination
check; this count is structural.
def ups source · line 166 · raw
@path:String -> Nat
how many components of a path are climbs
def unbend source · line 170 · raw
@+path:String -> String
a module path without its .bend, which is how bend names the module
def climb source · line 176 · raw
@count:Nat -> @path:String -> String
the path with n of its components climbed back off, which is where a
package re-roots when a module of it was reached through that many ..
def anchor.path source · line 185 · raw
@kept:Bool -> @+here:String -> @+path:String -> String
an absolute path, or a git@ URL, as it is, or a relative path taken from
here
def anchor.at source · line 193 · raw
@url:Bool -> @+here:String -> @+path:String -> String
a URL as it is, or a path
def anchor source · line 205 · raw
@+here:String -> @+path:String -> String
a source as the directory here reads it. The ledger keeps a local path
relative to the project, the way it was given, and git reads a relative path
from somewhere else, so every git command is handed this instead. A URL is
the same wherever it is read from.