summaryrefslogtreecommitdiff
path: root/Biz/Namespace.hs
diff options
context:
space:
mode:
authorBen Sima <ben@bsima.me>2022-07-19 14:22:53 -0400
committerBen Sima <ben@bsima.me>2022-07-19 14:25:23 -0400
commit08e10dec6b00cedf7aa6395d195a32860e35a690 (patch)
treec1e0c93de05f5fc5c1f4dcb0dce7bcbdaba815c1 /Biz/Namespace.hs
parentde3edfca6fd628494be5e04ff3dbe21a54441163 (diff)
Provision lisp repls with nix
asdf seems to always be necessary for any other packages to work, so I just include that in the call to nix-shell, and swank is included because it's just useful to start a repl server.
Diffstat (limited to 'Biz/Namespace.hs')
-rw-r--r--Biz/Namespace.hs47
1 files changed, 30 insertions, 17 deletions
diff --git a/Biz/Namespace.hs b/Biz/Namespace.hs
index 1365919..0fd861f 100644
--- a/Biz/Namespace.hs
+++ b/Biz/Namespace.hs
@@ -7,9 +7,9 @@ module Biz.Namespace
( Namespace (..),
Ext (..),
fromPath,
- fromContent,
- fromHaskellModule,
toPath,
+ fromHaskellContent,
+ fromHaskellModule,
toHaskellModule,
toSchemeModule,
isCab,
@@ -23,7 +23,19 @@ import qualified Data.List as List
import qualified Data.List.Split as List
import qualified Text.Regex.Applicative as Regex
-data Ext = Hs | Scm | Nix | Md | Css | Py | Sh | Keys | Json | None | Rs
+data Ext
+ = Css
+ | Hs
+ | Json
+ | Keys
+ | Lisp
+ | Md
+ | Nix
+ | None
+ | Py
+ | Rs
+ | Scm
+ | Sh
deriving (Eq, Show, Generic, Aeson.ToJSON)
data Namespace = Namespace {path :: [String], ext :: Ext}
@@ -35,8 +47,14 @@ fromPath bizRoot absPath =
+> List.stripPrefix "/"
+> Regex.match (Namespace </ rePath <* dot <*> reExt)
-fromContent :: String -> Maybe Namespace
-fromContent c = case Regex.findFirstInfix haskellModule c of
+toPath :: Namespace -> FilePath
+toPath (Namespace parts ext) =
+ joinWith "/" parts
+ <> "."
+ <> lowercase (show ext)
+
+fromHaskellContent :: String -> Maybe Namespace
+fromHaskellContent c = case Regex.findFirstInfix haskellModule c of
Nothing -> Nothing
Just (_, Namespace {..}, _) -> Just <| Namespace (filter (/= ".") path) ext
where
@@ -53,12 +71,6 @@ toHaskellModule (Namespace {..}) =
fromHaskellModule :: String -> Namespace
fromHaskellModule s = Namespace (List.splitOn "." s) Hs
-toPath :: Namespace -> FilePath
-toPath (Namespace parts ext) =
- joinWith "/" parts
- <> "."
- <> lowercase (show ext)
-
toSchemeModule :: Namespace -> String
toSchemeModule (Namespace parts Scm) = "(" ++ joinWith " " parts ++ ")"
toSchemeModule (Namespace {..}) =
@@ -77,16 +89,17 @@ rePath = Regex.many (name <* Regex.string "/" <|> name)
reExt :: Regex.RE Char Ext
reExt =
- Nix <$ Regex.string "nix"
+ Css <$ Regex.string "css"
<|> Hs <$ Regex.string "hs"
- <|> Scm <$ Regex.string "scm"
+ <|> Json <$ Regex.string "json"
+ <|> Keys <$ Regex.string "pub"
+ <|> Lisp <$ Regex.string "lisp"
<|> Md <$ Regex.string "md"
- <|> Css <$ Regex.string "css"
+ <|> Nix <$ Regex.string "nix"
<|> Py <$ Regex.string "py"
- <|> Sh <$ Regex.string "sh"
- <|> Keys <$ Regex.string "pub"
- <|> Json <$ Regex.string "json"
<|> Rs <$ Regex.string "rs"
+ <|> Scm <$ Regex.string "scm"
+ <|> Sh <$ Regex.string "sh"
-- | The cab dir is for temporary files and build outputs, not for source
-- inputs.