summaryrefslogtreecommitdiff
path: root/Biz/Namespace.hs
diff options
context:
space:
mode:
authorBen Sima <ben@bsima.me>2020-12-30 12:24:47 -0500
committerBen Sima <ben@bsima.me>2020-12-30 12:50:09 -0500
commit9da4feb106126940264dd27925ea3c19b04aac20 (patch)
tree23a8fe41eb6ef7ef51280e598bebfbf54f851ebc /Biz/Namespace.hs
parentf0895bfd73c53d9d5d9811c632d8e6f5e99dc0d4 (diff)
bild: build everyting
Now bild knows how to determine between modules that require ghcjs and ghc. It also knows what *not* to build, meaning it won't try to build non-buildable nix targets, for example (unfortunately this is just hardcoded for now), but it also won't build scm or py targets that I haven't implemented yet. It just silently fails, which is fine, because it means I can do `bild **/*` and everything just works. Of course, if I want to build scm code then I will have to implement that, but that's not a priority right now.
Diffstat (limited to 'Biz/Namespace.hs')
-rw-r--r--Biz/Namespace.hs21
1 files changed, 13 insertions, 8 deletions
diff --git a/Biz/Namespace.hs b/Biz/Namespace.hs
index 48ae1e6..574a2fc 100644
--- a/Biz/Namespace.hs
+++ b/Biz/Namespace.hs
@@ -1,6 +1,7 @@
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE NoImplicitPrelude #-}
+-- : dep regex-applicative
module Biz.Namespace
( Namespace (..),
Ext (..),
@@ -14,26 +15,31 @@ where
import Alpha
import qualified Data.Char as Char
import qualified Data.List as List
-import qualified Data.Text as Text
import qualified Text.Regex.Applicative as Regex
-data Ext = Hs | Scm | Nix
- deriving (Show)
+data Ext = Hs | Scm | Nix | Md | Css | Py | Sh | Key | Json | None
+ deriving (Eq, Show)
data Namespace = Namespace [String] Ext
- deriving (Show)
+ deriving (Eq, Show)
match :: String -> Maybe Namespace
match = Regex.match <| Namespace </ path <* Regex.sym '.' <*> ext
where
name =
Regex.many (Regex.psym Char.isUpper)
- <> Regex.many (Regex.psym Char.isLower)
+ <> Regex.many (Regex.psym Char.isAlphaNum)
path = Regex.many (name <* Regex.string "/" <|> name)
ext =
Nix <$ Regex.string "nix"
<|> Hs <$ Regex.string "hs"
<|> Scm <$ Regex.string "scm"
+ <|> Md <$ Regex.string "md"
+ <|> Css <$ Regex.string "css"
+ <|> Py <$ Regex.string "py"
+ <|> Sh <$ Regex.string "sh"
+ <|> Key <$ Regex.string "key"
+ <|> Json <$ Regex.string "json"
fromPath :: String -> String -> Maybe Namespace
fromPath bizRoot absPath =
@@ -46,9 +52,8 @@ toHaskellModule (Namespace parts Hs) = joinWith "." parts
toHaskellModule (Namespace _ ext) =
panic <| "can't convert " <> show ext <> " to a Haskell module"
-toPath :: Namespace -> Text
+toPath :: Namespace -> FilePath
toPath (Namespace parts ext) =
- Text.pack
- <| joinWith "/" parts
+ joinWith "/" parts
<> "."
<> lowercase (show ext)