summaryrefslogtreecommitdiff
path: root/lib/Paths.hs
diff options
context:
space:
mode:
authorstuebinm2021-09-23 03:11:28 +0200
committerstuebinm2021-09-23 03:11:28 +0200
commit04b98e4d62fe33b4fa357f2b52ffcc4f2c413302 (patch)
treee934d34f8f4d5ba99c617dc3e7b664ef20732e96 /lib/Paths.hs
parent7e77e6335bab772c4be1b3f0594113d09cd4a366 (diff)
some documentation
Diffstat (limited to '')
-rw-r--r--lib/Paths.hs12
1 files changed, 9 insertions, 3 deletions
diff --git a/lib/Paths.hs b/lib/Paths.hs
index 49c0295..5044673 100644
--- a/lib/Paths.hs
+++ b/lib/Paths.hs
@@ -1,7 +1,7 @@
{-# LANGUAGE OverloadedStrings #-}
--- |
-
+-- | Paths are horrible, so they have their own module now.
+-- I just hope you are running this on some kind of Unix
module Paths where
import Data.Text (Text)
@@ -12,7 +12,8 @@ import Text.Regex.TDFA
import Util (PrettyPrint (prettyprint))
-- | a normalised path: a number of "upwards" steps, and
--- a path without any . or .. in it
+-- a path without any . or .. in it. Also possibly a
+-- fragment, mostly for map links.
data RelPath = Path Int Text (Maybe Text)
deriving (Show, Eq, Ord)
@@ -37,6 +38,11 @@ instance PrettyPrint RelPath where
prettyprint (Path up rest _) = ups <> rest
where ups = T.concat $ replicate up "../"
+-- | Normalises a path.
+--
+-- It takes a `prefix`, and will "truncate" the .. operator
+-- at the end of the prefix, i.e. it will never return paths
+-- that lie (naïvely) outside of the prefix.
normalise :: FilePath -> RelPath -> FilePath
normalise prefix (Path 0 path _) = prefix </> T.unpack path
normalise prefix (Path i path _) =