git.iko.soy/haskell-generate
on master help sign in
.travis.yml+4−3
since splitsnapshots
unifiedsplit
@@ -2,7 +2,8 @@ env:
2 - GHCVER=7.4.2 CABALVER=1.16
2 - GHCVER=7.4.2 CABALVER=1.16
3 - GHCVER=7.6.3 CABALVER=1.18
3 - GHCVER=7.6.3 CABALVER=1.18
4 - GHCVER=7.8.3 CABALVER=1.20
4 - GHCVER=7.8.3 CABALVER=1.20
5+ - GHCVER=7.10.2 CABALVER=1.22
5− - GHCVER=head CABALVER=1.20
6+ - GHCVER=head CABALVER=1.22
6
7
7before_install:
8before_install:
8 - sudo add-apt-repository -y ppa:hvr/ghc
9 - sudo add-apt-repository -y ppa:hvr/ghc
@@ -21,5 +22,5 @@ script:
21
22
22matrix:
23matrix:
23 allow_failures:
24 allow_failures:
24− - env: GHCVER=head CABALVER=1.20
25+ - env: GHCVER=head CABALVER=1.22
25− fast_finish: true
26+ fast_finish: true
LICENSE+1−1
@@ -1,4 +1,4 @@
1−Copyright 2013-2014 Benno Fünfstück
1+Copyright 2013-2015 Benno Fünfstück
2
2
3All rights reserved.
3All rights reserved.
4
4
README.md−1
@@ -102,4 +102,3 @@ declareFunction 'permutations -- This generates the same code as above, but is m
102## Contributing
102## Contributing
103
103
104If you have an idea, a question or a bug report, open an issue on github. You can also find me on freenode in the #haskell channel, my nick is bennofs.
104If you have an idea, a question or a bug report, open an issue on github. You can also find me on freenode in the #haskell channel, my nick is bennofs.
105−
haskell-generate.cabal+8−6
@@ -1,5 +1,5 @@
1name: haskell-generate
1name: haskell-generate
2−version: 0.2.2
2+version: 0.2.4
3license: BSD3
3license: BSD3
4category: Code Generation, Language
4category: Code Generation, Language
5cabal-version: >= 1.10
5cabal-version: >= 1.10
@@ -9,9 +9,13 @@ maintainer: Benno Fünfstück <benno.fuenfstueck@gmail.com>
9stability: experimental
9stability: experimental
10homepage: http://github.com/bennofs/haskell-generate/
10homepage: http://github.com/bennofs/haskell-generate/
11bug-reports: http://github.com/bennofs/haskell-generate/issues
11bug-reports: http://github.com/bennofs/haskell-generate/issues
12−copyright: Copyright (C) 2013 Benno Fünfstück
12+copyright: Copyright (C) 2013-2015 Benno Fünfstück
13−synopsis: haskell-generate
13+synopsis: Typesafe generation of haskell source code
14−description: haskell-generate
14+description:
15+ This library provides an interface to generate haskell source code, verifying at compile time
16+ that the resulting code typechecks.
17+ See <https://github.com/bennofs/haskell-generate haskell-generate> for an
18+ introduction explaining how to use the library.
15build-type: Custom
19build-type: Custom
16
20
17extra-source-files:
21extra-source-files:
@@ -53,6 +57,4 @@ test-suite doctests
53 , doctest >= 0.9.1
57 , doctest >= 0.9.1
54 , filepath
58 , filepath
55 ghc-options: -Wall -threaded
59 ghc-options: -Wall -threaded
56− if impl(ghc<7.6.1)
57− ghc-options: -Werror
58 hs-source-dirs: tests
60 hs-source-dirs: tests
src/Language/Haskell/Generate/Monad.hs+11−3
@@ -36,6 +36,8 @@ import Language.Haskell.Exts.SrcLoc
36import Language.Haskell.Exts.Syntax
36import Language.Haskell.Exts.Syntax
37import Language.Haskell.Generate.Expression
37import Language.Haskell.Generate.Expression
38
38
39+import Prelude
40+
39--------------------------------------------------------------------------------
41--------------------------------------------------------------------------------
40-- Generate expressions
42-- Generate expressions
41
43
@@ -62,9 +64,11 @@ generateExp = prettyPrint . runExpression . fst . runGenerate
62caseE :: ExpG x -> [(Pat, ExpG t)] -> ExpG t
64caseE :: ExpG x -> [(Pat, ExpG t)] -> ExpG t
63caseE v alt = do
65caseE v alt = do
64 v' <- v
66 v' <- v
65−#if MIN_VERSION_haskell_src_exts(1,16,0)
67+#if MIN_VERSION_haskell_src_exts(1,17,0)
68+ alt' <- mapM (\(p,a) -> fmap (\a' -> Alt noLoc p (UnGuardedRhs $ runExpression a') Nothing) a) alt
69+#elif MIN_VERSION_haskell_src_exts(1,16,0)
66 alt' <- mapM (\(p,a) -> fmap (\a' -> Alt noLoc p (UnGuardedRhs $ runExpression a') (BDecls [])) a) alt
70 alt' <- mapM (\(p,a) -> fmap (\a' -> Alt noLoc p (UnGuardedRhs $ runExpression a') (BDecls [])) a) alt
67−#else
71+#else
68 alt' <- mapM (\(p,a) -> fmap (\a' -> Alt noLoc p (UnGuardedAlt $ runExpression a') (BDecls [])) a) alt
72 alt' <- mapM (\(p,a) -> fmap (\a' -> Alt noLoc p (UnGuardedAlt $ runExpression a') (BDecls [])) a) alt
69#endif
73#endif
70 return $ Expression $ Case (runExpression v') alt'
74 return $ Expression $ Case (runExpression v') alt'
@@ -210,7 +214,7 @@ instance GenExp (FunRef t) where
210
214
211-- | Generate a ExportSpec for a given function item.
215-- | Generate a ExportSpec for a given function item.
212exportFun :: FunRef t -> ExportSpec
216exportFun :: FunRef t -> ExportSpec
213−#if MIN_VERSION_haskell_src_exts(1,16,0)
217+#if MIN_VERSION_haskell_src_exts(1,16,0) && !MIN_VERSION_haskell_src_exts(1,17,0)
214exportFun (FunRef name) = EVar NoNamespace (UnQual name)
218exportFun (FunRef name) = EVar NoNamespace (UnQual name)
215#else
219#else
216exportFun (FunRef name) = EVar (UnQual name)
220exportFun (FunRef name) = EVar (UnQual name)
@@ -220,7 +224,11 @@ exportFun (FunRef name) = EVar (UnQual name)
220addDecl :: Name -> ExpG t -> ModuleM (FunRef t)
224addDecl :: Name -> ExpG t -> ModuleM (FunRef t)
221addDecl name e = ModuleM $ do
225addDecl name e = ModuleM $ do
222 let (body, mods) = runGenerate e
226 let (body, mods) = runGenerate e
227+#if MIN_VERSION_haskell_src_exts(1,17,0)
228+ tell (mods, [FunBind [Match noLoc name [] Nothing (UnGuardedRhs $ runExpression body) Nothing]])
229+#else
223 tell (mods, [FunBind [Match noLoc name [] Nothing (UnGuardedRhs $ runExpression body) $ BDecls []]])
230 tell (mods, [FunBind [Match noLoc name [] Nothing (UnGuardedRhs $ runExpression body) $ BDecls []]])
231+#endif
224 return $ FunRef name
232 return $ FunRef name
225
233
226-- | Extract the Module from a module generator.
234-- | Extract the Module from a module generator.
tests/doctests.hsc+1−2
@@ -20,18 +20,17 @@ import Data.List
20import System.Directory
20import System.Directory
21import System.FilePath
21import System.FilePath
22import Test.DocTest
22import Test.DocTest
23+import Prelude
23
24
24##ifdef mingw32_HOST_ARCH
25##ifdef mingw32_HOST_ARCH
25##ifdef i386_HOST_ARCH
26##ifdef i386_HOST_ARCH
26##define USE_CP
27##define USE_CP
27−import Control.Applicative
28import Control.Exception
28import Control.Exception
29import Foreign.C.Types
29import Foreign.C.Types
30foreign import stdcall "windows.h SetConsoleCP" c_SetConsoleCP :: CUInt -> IO Bool
30foreign import stdcall "windows.h SetConsoleCP" c_SetConsoleCP :: CUInt -> IO Bool
31foreign import stdcall "windows.h GetConsoleCP" c_GetConsoleCP :: IO CUInt
31foreign import stdcall "windows.h GetConsoleCP" c_GetConsoleCP :: IO CUInt
32##elif defined(x86_64_HOST_ARCH)
32##elif defined(x86_64_HOST_ARCH)
33##define USE_CP
33##define USE_CP
34−import Control.Applicative
35import Control.Exception
34import Control.Exception
36import Foreign.C.Types
35import Foreign.C.Types
37foreign import ccall "windows.h SetConsoleCP" c_SetConsoleCP :: CUInt -> IO Bool
36foreign import ccall "windows.h SetConsoleCP" c_SetConsoleCP :: CUInt -> IO Bool