json-autotype 0.2.5.10 → 0.2.5.11
raw patch · 6 files changed
+33/−9 lines, 6 filesPVP ok
version bump matches the API change (PVP)
API changes (from Hackage documentation)
Files
- Data/Aeson/AutoType/CodeGen.hs +1/−1
- Data/Aeson/AutoType/Extract.hs +18/−0
- Data/Aeson/AutoType/Plugin/Subtype.hs +3/−1
- GenerateJSONParser.hs +6/−6
- changelog.md +4/−0
- json-autotype.cabal +1/−1
Data/Aeson/AutoType/CodeGen.hs view
@@ -70,7 +70,7 @@ ," exitSuccess" ,""] --- Write a Haskell module to an output file, or stdout if `-` filename is given.+-- | Write a Haskell module to an output file, or stdout if `-` filename is given. writeHaskellModule :: FilePath -> Map.HashMap Text Type -> IO () writeHaskellModule outputFilename types = withFileOrHandle outputFilename WriteMode stdout $ \hOut -> do
Data/Aeson/AutoType/Extract.hs view
@@ -15,6 +15,10 @@ import Data.Set (Set ) import Data.List (foldl1') +-- | Compute total number of nodes (and leaves) within the value tree.+-- Each simple JavaScript type (including String) is counted as of size 1,+-- whereas both Array or object types are counted as 1+sum of the sizes+-- of their member values. valueSize :: Value -> Int valueSize Null = 1 valueSize (Bool _) = 1@@ -23,6 +27,12 @@ valueSize (Array a) = V.foldl' (+) 1 $ V.map valueSize a valueSize (Object o) = (1+) . sum . map valueSize . Hash.elems $ o +-- | Compute total size of the type of the @Value@.+-- For:+-- * simple types it is always 1, +-- * for arrays it is just 1+_maximum_ size of the (single) element type,+-- * for objects it is _sum_ of the sizes of fields (since each field type+-- is assumed to be different.) valueTypeSize :: Value -> Int valueTypeSize Null = 1 valueTypeSize (Bool _) = 1@@ -31,6 +41,10 @@ valueTypeSize (Array a) = (1+) . V.foldl' max 0 $ V.map valueTypeSize a valueTypeSize (Object o) = (1+) . sum . map valueTypeSize . Hash.elems $ o +-- | Compute total depth of the value.+-- For:+-- * simple types it is 1+-- * for either Array or Object, it is 1 + maximum of depths of their members valueDepth :: Value -> Int valueDepth Null = 1 valueDepth (Bool _) = 1@@ -39,6 +53,8 @@ valueDepth (Array a) = (1+) . V.foldl' max 0 $ V.map valueDepth a valueDepth (Object o) = (1+) . maximum . (0:) . map valueDepth . Hash.elems $ o +-- | Extract @Type@ from the JSON @Value@.+-- Unifying types of array elements, if necessary. extractType :: Value -> Type extractType (Object o) = TObj $ Dict $ Hash.map extractType o extractType Null = TNull@@ -48,6 +64,8 @@ extractType (Array a) | V.null a = TArray emptyType extractType (Array a) = TArray $ V.foldl1' unifyTypes $ V.map extractType a +-- | Standard unification procedure on @Type@s,+-- with inclusion of @Type@ unions. unifyTypes :: Type -> Type -> Type unifyTypes TBool TBool = TBool unifyTypes TNum TNum = TNum
Data/Aeson/AutoType/Plugin/Subtype.hs view
@@ -1,3 +1,4 @@+-- | API to which @SubtypePlugin@s should conform. module Data.Aeson.AutoType.Plugin.Subtype ( SubtypePlugin (..) , SubtypeDesc (..)@@ -10,8 +11,9 @@ -- | Hmm... this should be existential type? type TypeDesc = String +-- | Operations that @SubtypPlugin@ must implement. data SubtypePlugin = SubtypePlugin {- detect :: [Value] -> Maybe SubtypeDesc -- | Check whether a set of values belongs to this type family+ detect :: [Value] -> Maybe SubtypeDesc -- | Check whether a set of values belongs to this type family , unify :: SubtypeDesc -> SubtypeDesc -> Either SubtypeDesc Type }
GenerateJSONParser.hs view
@@ -30,12 +30,12 @@ fst3 (a, _, _) = a -- * Command line flags-defineFlag "outputFilename" defaultOutputFilename "Write output to the given file"-defineFlag "suggest" True "Suggest candidates for unification"-defineFlag "autounify" True "Automatically unify suggested candidates"-defineFlag "test" False "Try to run generated parser after"-defineFlag "debug" False "Set this flag to see more debugging info"-defineFlag "fakeFlag" True "Ignore this flag - it doesn't exist!!!"+defineFlag "o:outputFilename" defaultOutputFilename "Write output to the given file"+defineFlag "suggest" True "Suggest candidates for unification"+defineFlag "autounify" True "Automatically unify suggested candidates"+defineFlag "t:test" False "Try to run generated parser after"+defineFlag "d:debug" False "Set this flag to see more debugging info"+defineFlag "fakeFlag" True "Ignore this flag - it doesn't exist!!! It is workaround to library problem." -- Tracing is switched off: myTrace :: String -> IO ()
changelog.md view
@@ -1,5 +1,9 @@ Changelog =========+ 0.2.5.11 Mar 2015++ * Add short versions of command line flags: -o, -d, and -t.+ 0.2.5.10 Mar 2015 * Bump up lens dependency.
json-autotype.cabal view
@@ -1,6 +1,6 @@ -- Build information for the package. name: json-autotype-version: 0.2.5.10+version: 0.2.5.11 synopsis: Automatic type declaration for JSON input data description: Generates datatype declarations with Aeson's "FromJSON" instances from a set of example ".json" files.