From 08e10dec6b00cedf7aa6395d195a32860e35a690 Mon Sep 17 00:00:00 2001 From: Ben Sima Date: Tue, 19 Jul 2022 14:22:53 -0400 Subject: 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. --- Biz/Namespace.hs | 47 ++++++++++++++++++++++++++++++----------------- 1 file changed, 30 insertions(+), 17 deletions(-) (limited to 'Biz/Namespace.hs') 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 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. -- cgit v1.2.3