summaryrefslogtreecommitdiff
path: root/lib/Paths.hs
diff options
context:
space:
mode:
authorstuebinm2021-09-23 00:23:03 +0200
committerstuebinm2021-09-23 00:23:03 +0200
commit7ad5e1cd504b1d57ff3660f9eb81d2e7072ea4bf (patch)
treea144113aa8defd68f7b88b1e9ef6ee0196384c55 /lib/Paths.hs
parentc6be6366d6411d7b0b53fd8879537a33fefd5a88 (diff)
very naïve handling of directories
Diffstat (limited to 'lib/Paths.hs')
-rw-r--r--lib/Paths.hs17
1 files changed, 13 insertions, 4 deletions
diff --git a/lib/Paths.hs b/lib/Paths.hs
index 7750723..4dcaa53 100644
--- a/lib/Paths.hs
+++ b/lib/Paths.hs
@@ -11,21 +11,30 @@ import Util (PrettyPrint (prettyprint))
-- | a normalised path: a number of "upwards" steps, and
-- a path without any . or .. in it
-data RelPath = Path Int Text
- deriving (Show, Eq)
+data RelPath = Path Int Text (Maybe Text)
+ deriving (Show, Eq, Ord)
-- | horrible regex parsing for filepaths that is hopefully kinda safe
parsePath :: Text -> Maybe RelPath
parsePath text =
if rest =~ ("^([^/]*[^\\./]/)*[^/]*[^\\./]$" :: Text) :: Bool
- then Just $ Path up rest
+ then Just $ Path up path fragment
else Nothing
where
(_, prefix, rest, _) =
text =~ ("^((\\.|\\.\\.)/)*" :: Text) :: (Text, Text, Text, [Text])
-- how many steps upwards in the tree?
up = length . filter (".." ==) . T.splitOn "/" $ prefix
+ parts = T.splitOn "#" rest
+ path = head parts
+ fragment = if length parts >= 2
+ then Just $ T.concat $ tail parts -- TODO!
+ else Nothing
instance PrettyPrint RelPath where
- prettyprint (Path up rest) = ups <> rest
+ prettyprint (Path up rest _) = ups <> rest
where ups = T.concat $ replicate up "../"
+
+normalise :: RelPath -> FilePath
+normalise (Path 0 path _) = T.unpack path
+normalize _ = error "not implemented yet"