Browse files

Extract module name from file

  • Loading branch information...
1 parent 8f09fdd commit 7b89f4a3f2c7eb5e060ad4801aa2394e2d8cbdcb @singpolyma committed Aug 20, 2012
Showing with 6 additions and 6 deletions.
  1. +3 −3 ParseRecords.hs
  2. +3 −3 mustache2hs.hs
View
6 ParseRecords.hs
@@ -62,9 +62,9 @@ extractFromTypeDecl :: HsDecl -> (String, HsType)
extractFromTypeDecl (HsTypeDecl _ name _ t) = (hsNameToString name, t)
extractFromTypeDecl _ = error "Programmer error, only call extractFromTypeDecl with TypeDecl"
-extractRecords :: String -> Records
+extractRecords :: String -> (String, Records)
extractRecords moduleSrc =
- map (extractFromDataDecl (map extractFromTypeDecl types)) datas
+ (mod, map (extractFromDataDecl (map extractFromTypeDecl types)) datas)
where
(types, datas) = partition (isTypeDecl) $ filter (\d -> isDataDecl d || isTypeDecl d) decls
- ParseOk (HsModule _ _ _ _ decls) = parseModule moduleSrc
+ ParseOk (HsModule _ (Module mod) _ _ decls) = parseModule moduleSrc
View
6 mustache2hs.hs
@@ -272,15 +272,15 @@ main = do
_ -> main' (getRecordModules flags) args
where
main' recordModules inputs = do
- recs <- concat <$> mapM (fmap extractRecords . readFile) recordModules
- builder <- codeGenFiles recs inputs
+ (ms, recs) <- unzip <$> mapM (fmap extractRecords . readFile) recordModules
+ builder <- codeGenFiles (concat recs) inputs
putStrLn "import Prelude hiding (foldr)"
putStrLn "import Data.Foldable (foldr)"
putStrLn "import Data.Maybe"
putStrLn "import Data.Monoid"
putStrLn "import Web.PathPieces" -- Maybe use a different typeclass?
putStrLn "import qualified Blaze.ByteString.Builder.Char.Utf8 as Builder"
- mapM_ (\m -> putStrLn $ "import " ++ takeBaseName m ++ "\n") recordModules
+ mapM_ (\m -> putStrLn $ "import " ++ m ++ "\n") ms
Builder.toByteStringIO BS.putStr builder
getRecordModules = foldr (\x ms -> case x of
RecordModule m -> m : ms

0 comments on commit 7b89f4a

Please sign in to comment.