summaryrefslogtreecommitdiff
path: root/Biz/Namespace.hs
diff options
context:
space:
mode:
authorBen Sima <ben@bsima.me>2022-08-03 12:51:13 -0400
committerBen Sima <ben@bsima.me>2022-08-03 14:09:34 -0400
commit935d5dc1c8d4c60a70d79a3f47718f9dcf5684fd (patch)
tree0b51ea493ff026b35463400699a7320deae9f436 /Biz/Namespace.hs
parent82dd88a0f77ee9840a2b8f0e73ebfbc78b0ab8c5 (diff)
Key analyses on Namespace, not FilePath
Namespace is unique, whereas FilePath could be relative or absolute, or have a leading . or trailing / or not.
Diffstat (limited to 'Biz/Namespace.hs')
-rw-r--r--Biz/Namespace.hs26
1 files changed, 21 insertions, 5 deletions
diff --git a/Biz/Namespace.hs b/Biz/Namespace.hs
index 6fb40f7..cdc4464 100644
--- a/Biz/Namespace.hs
+++ b/Biz/Namespace.hs
@@ -1,4 +1,5 @@
{-# LANGUAGE DeriveAnyClass #-}
+{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE RecordWildCards #-}
{-# LANGUAGE NoImplicitPrelude #-}
@@ -37,10 +38,10 @@ data Ext
| Rs
| Scm
| Sh
- deriving (Eq, Show, Generic, Aeson.ToJSON)
+ deriving (Eq, Show, Generic, Aeson.ToJSON, Ord)
data Namespace = Namespace {path :: [String], ext :: Ext}
- deriving (Eq, Show, Generic, Aeson.ToJSON)
+ deriving (Eq, Show, Generic, Aeson.ToJSON, Ord)
fromPath :: String -> String -> Maybe Namespace
fromPath bizRoot absPath =
@@ -50,9 +51,24 @@ fromPath bizRoot absPath =
toPath :: Namespace -> FilePath
toPath (Namespace parts ext) =
- joinWith "/" parts
- <> "."
- <> lowercase (show ext)
+ joinWith "/" parts <> toExt ext
+
+toExt :: Ext -> String
+toExt =
+ ("." <>) <. \case
+ C -> "c"
+ Css -> "css"
+ Hs -> "hs"
+ Json -> "json"
+ Keys -> "pub"
+ Lisp -> "lisp"
+ Md -> "md"
+ Nix -> "nix"
+ None -> "none"
+ Py -> "py"
+ Rs -> "rs"
+ Scm -> "scm"
+ Sh -> "sh"
fromHaskellContent :: String -> Maybe Namespace
fromHaskellContent c = case Regex.findFirstInfix haskellModule c of