packages feed

json-autotype 0.2.5.4 → 0.2.5.6

raw patch · 5 files changed

+89/−3 lines, 5 filesdep +hintdep ~lens

Dependencies added: hint

Dependency ranges changed: lens

Files

+ Data/Aeson/AutoType/Plugin/Loader.hs view
@@ -0,0 +1,47 @@+{-# LANGUAGE ScopedTypeVariables #-}+-- | Module implementing loading generic plugins using Hint.+module Data.Aeson.AutoType.Plugin.Loader (+    importPlugins+  , main+  ) where++import           System.IO     ( hPutStrLn, stderr )+import           System.Exit   ( exitFailure )+import           Data.Typeable+import           Control.Arrow ((&&&))+import           Control.Monad+import qualified Language.Haskell.Interpreter as Hint++-- | Test script+main :: IO ()+main  = do result :: [[Int]] <- importPlugins "export" moduleNames+           forM_ (zip moduleNames result) $ \(moduleName, exportVal) ->+             putStrLn $ concat [moduleName, ": ", show exportVal, "\n"]+  where+    moduleNames = ["Plugin.hs"+                  ,"Plugin2.hs"]++-- | Fatal exit from the program+fatal :: String -> IO a+fatal msg = do+  hPutStrLn stderr msg+  exitFailure++-- | Imports a set of plugin modules with the same "interface" value,+-- and returns values exported as their interfaces.+importPlugins ::   Typeable a =>+                   String     -> -- ^ name exported from each module as an interface+                  [String]    -> -- ^ list of plugin modules (given as either module paths or file paths)+                   IO [a]        -- ^ Result is a list of exported objects in the order of module names+importPlugins interfaceName pluginModules = do+    result <- Hint.runInterpreter $ do+      Hint.loadModules pluginModules+      moduleNames <- Hint.getLoadedModules+      Hint.setImportsQ $ ("Prelude", Nothing):map (id &&& Just) moduleNames+      mapM getInterfaceVar moduleNames+    case result of+      Left  err   -> fatal $ "Cannot load plugins:\n" ++ show err+      Right value -> return value+  where+    getInterfaceVar moduleName = Hint.interpret (moduleName ++ "." ++ interfaceName) Hint.as+
+ Data/Aeson/AutoType/Plugin/Subtype.hs view
@@ -0,0 +1,25 @@+module Data.Aeson.AutoType.Plugin.Subtype (+    SubtypePlugin (..)+  , SubtypeDesc   (..)+  ) where++import Data.Aeson.AutoType.Type+import Data.Aeson+import Data.Dynamic++-- | Hmm... this should be existential type?+type TypeDesc = String++data SubtypePlugin = SubtypePlugin {+    detect :: [Value]  -> Maybe SubtypeDesc -- | Check whether a set of values belongs to this type family+  , unify  :: SubtypeDesc -> SubtypeDesc -> Either SubtypeDesc Type+  }++-- | Description of a subtype+data SubtypeDesc = SubtypeDesc {+    subtypeName  :: String           -- | Code that is different for different type families+  , subtypeClass :: Type+  , reference    :: String -> String -- | Show type reference with a given name prefix+  , declare      :: String           -- | Show type declaration+  , typeInfo     :: Dynamic+  }
GenerateJSONParser.hs view
@@ -74,6 +74,9 @@   -- Read type from each file   typeForEachFile  <- catMaybes <$> mapM extractTypeFromJSONFile inputFilenames   -- Unify all input types+  when (null typeForEachFile) $ do+    report "No valid JSON input file..."+    exitFailure   let finalType = foldr1 unifyTypes typeForEachFile   -- We split different dictionary labels to become different type trees (and thus different declarations.)   let splitted = splitTypeByLabel "TopLevel" finalType
changelog.md view
@@ -1,5 +1,13 @@ Changelog =========+    0.2.5.5  Mar 2015++        * Relaxed upper bounds for lens 4.8.+    +   0.2.5.5  Mar 2015++        * (Skipped this version number by mistake.)+     0.2.5.4  Dec 2014          * Relaxed upper bounds for new lens.
json-autotype.cabal view
@@ -1,6 +1,6 @@ -- Build information for the package. name:                json-autotype-version:             0.2.5.4+version:             0.2.5.6 synopsis:            Automatic type declaration for JSON input data description:         Generates datatype declarations with Aeson's "FromJSON" instances                      from a set of example ".json" files.@@ -26,7 +26,7 @@ stability:           beta author:              Michal J. Gajda maintainer:          mjgajda@gmail.com-copyright:           Copyright by Michal J. Gajda '2014+copyright:           Copyright by Michal J. Gajda '2014-'2015 category:            Web build-type:          Simple extra-source-files:  README.md changelog.md@@ -45,6 +45,8 @@                        Data.Aeson.AutoType.Pretty                        Data.Aeson.AutoType.CodeGen                        Data.Aeson.AutoType.Alternative+                       Data.Aeson.AutoType.Plugin.Subtype+                       Data.Aeson.AutoType.Plugin.Loader   other-extensions:    TemplateHaskell,                        ScopedTypeVariables,                        OverloadedStrings,@@ -63,8 +65,9 @@                        containers           >=0.3  && <0.6,                        filepath             >=1.3  && <1.4,                        hashable             >=1.2  && <1.3,+                       hint                 >=0.4  && <0.5,                        hflags               >=0.4  && <0.5,-                       lens                 >=4.1  && <4.8,+                       lens                 >=4.1  && <4.9,                        mtl                  >=2.1  && <2.3,                        pretty               >=1.1  && <1.3,                        process              >=1.2  && <1.4,