packages feed

bond-haskell-compiler 0.1.0.0 → 0.1.1.0

raw patch · 3 files changed

+37/−28 lines, 3 files

Files

app/Main.hs view
@@ -37,8 +37,11 @@     namespaceMapping <- parseNamespaceMappings $ namespace options     let mappingContext = MappingContext (error "can't create TypeMapping") aliasMapping namespaceMapping namespaces     forM_ templates $ \template -> do-        let MultiFile outputFiles = template mappingContext declarations-        forM_ outputFiles $ \(name, code) -> do-            let fileName = outputDir </> name+        let outputFiles = template mappingContext declarations+        forM_ outputFiles $ \ moduleInfo -> do+            let fileName = outputDir </> moduleFile moduleInfo             createDirectoryIfMissing True $ takeDirectory fileName-            writeFile fileName code+            writeFile fileName (moduleText moduleInfo)+            case moduleName moduleInfo of+                Nothing -> return ()+                Just name -> putStrLn name
bond-haskell-compiler.cabal view
@@ -1,5 +1,5 @@ name:                bond-haskell-compiler-version:             0.1.0.0+version:             0.1.1.0 synopsis:            Bond code generator for Haskell description:         Bond is a cross-platform framework for handling schematized                      data. It supports cross-language de/serialization and@@ -63,3 +63,4 @@ source-repository head   type:     git   location: https://github.com/rblaze/bond-haskell.git+  subdir:   compiler
src/Language/Bond/Codegen/Haskell/Decl.hs view
@@ -1,8 +1,9 @@-module Language.Bond.Codegen.Haskell.Decl (-        CodegenOpts(..),-        CodegenOutput(..),-        decl_hs,-        decl_hsboot+module Language.Bond.Codegen.Haskell.Decl+    ( CodegenOpts(..)+    , CodegenOutput+    , ModuleCode(..)+    , decl_hs+    , decl_hsboot     ) where  import Language.Bond.Syntax.Types@@ -11,45 +12,49 @@ import Language.Bond.Codegen.Haskell.StructDecl import Language.Bond.Codegen.Haskell.Util -import Control.Arrow import Data.Maybe import Language.Haskell.Exts import System.FilePath (joinPath) -data CodegenOutput-    = SingleFile FilePath String-    | MultiFile [(FilePath, String)]+data ModuleCode = ModuleCode+        { moduleFile :: FilePath+        , moduleName :: Maybe String+        , moduleText :: String+        } +type CodegenOutput = [ModuleCode]+ decl_hs :: CodegenOpts -> MappingContext -> [Declaration] -> CodegenOutput-decl_hs opts ctx declarations = MultiFile $ mapMaybe step declarations+decl_hs opts ctx declarations = mapMaybe step declarations     where-    step = fmap (second prettyPrint) . makeModule opts ctx+    step = fmap (\ (f, n, c) -> ModuleCode f n (prettyPrint c)) . makeModule opts ctx  decl_hsboot :: CodegenOpts -> MappingContext -> [Declaration] -> CodegenOutput-decl_hsboot opts ctx declarations = MultiFile $ mapMaybe step declarations+decl_hsboot opts ctx declarations = mapMaybe step declarations     where-    step = fmap (second prettyPrint) . makeHsBootModule opts ctx+    step = fmap (\ (f, n, c) -> ModuleCode f n (prettyPrint c)) . makeHsBootModule opts ctx -makeModule :: CodegenOpts -> MappingContext -> Declaration -> Maybe (FilePath, Module)-makeModule opts ctx decl = fmap ((,) sourceName) code+makeModule :: CodegenOpts -> MappingContext -> Declaration -> Maybe (FilePath, Maybe String, Module)+makeModule opts ctx decl = fmap (\ c -> (sourceName, Just printName, c)) code     where     code = case decl of-        Enum{} -> enumDecl opts ctx moduleName decl-        Struct{} -> structDecl opts ctx moduleName decl+        Enum{} -> enumDecl opts ctx modName decl+        Struct{} -> structDecl opts ctx modName decl         _ -> Nothing     hsModule = capitalize (makeDeclName decl)     hsNamespaces = map capitalize $ getNamespace ctx     sourceName = joinPath $ hsNamespaces ++ [hsModule ++ ".hs"]-    moduleName = mkModuleName hsNamespaces hsModule+    modName = mkModuleName hsNamespaces hsModule+    ModuleName printName = modName -makeHsBootModule :: CodegenOpts -> MappingContext -> Declaration -> Maybe (FilePath, Module)-makeHsBootModule opts ctx decl = fmap ((,) hsBootName) code+makeHsBootModule :: CodegenOpts -> MappingContext -> Declaration -> Maybe (FilePath, Maybe String, Module)+makeHsBootModule opts ctx decl = fmap (\ c -> (hsBootName, Nothing, c)) code     where     code = case decl of-        Enum{} -> enumHsBootDecl opts ctx moduleName decl-        Struct{} -> structHsBootDecl opts ctx moduleName decl+        Enum{} -> enumHsBootDecl opts ctx modName decl+        Struct{} -> structHsBootDecl opts ctx modName decl         _ -> Nothing     hsModule = capitalize (makeDeclName decl)     hsNamespaces = map capitalize $ getNamespace ctx     hsBootName = joinPath $ hsNamespaces ++ [hsModule ++ ".hs-boot"]-    moduleName = mkModuleName hsNamespaces hsModule+    modName = mkModuleName hsNamespaces hsModule