diff options
Diffstat (limited to 'Biz/Namespace.hs')
-rw-r--r-- | Biz/Namespace.hs | 47 |
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. |