packages feed

pinch-gen 0.4.3.0 → 0.4.4.0

raw patch · 5 files changed

+27/−8 lines, 5 filesdep ~base

Dependency ranges changed: base

Files

CHANGELOG.md view
@@ -1,3 +1,8 @@+0.4.4 (2024-01-06)+==================++* Fix GHC 9.6 compatibility (thanks to @alexbiehl)+ 0.4.3 (2021-11-14) ================== 
README.md view
@@ -21,7 +21,7 @@  ``` Usage: pinch-gen --in IN_FILE --out OUT_DIR --hashable-vec-mod ARG-                 [--no-generate-arbitrary] [--extra-import IMPORT]+                 [--no-generate-arbitrary] [--no-generate-nfdata] [--extra-import IMPORT]   Generate Haskell files from a thrift input file. ``` @@ -75,7 +75,7 @@ To generate the corresponding Haskell code we can call pinch-gen:  ```-pinch-gen --no-generate-arbitrary --hashable-vec-mod Data.Vector.Instances --in trivial.thrift --out out/+pinch-gen --no-generate-arbitrary --no-generate-nfdata --hashable-vec-mod Data.Vector.Instances --in trivial.thrift --out out/ ```  This will create the appropriate datatypes for all struct, union and exception types:
pinch-gen.cabal view
@@ -1,7 +1,7 @@ cabal-version:       >=1.10  name:                pinch-gen-version:             0.4.3.0+version:             0.4.4.0 -- synopsis: synopsis:            A code generator for the pinch Thrift library. homepage:            https://github.com/phile314/pinch-gen@@ -20,7 +20,7 @@   hs-source-dirs:      src   other-modules:       Pinch.Generate                      , Pinch.Generate.Pretty-  build-depends:       base >=4.12 && < 4.17+  build-depends:       base >=4.12 && < 4.19                      , bytestring                      , directory                      , filepath
src/Main.hs view
@@ -25,6 +25,7 @@ pGenSettings = Settings   <$> strOption (long "hashable-vec-mod" <> help "Module containing hashable instances for vector")   <*> flag True False (long "no-generate-arbitrary")+  <*> flag True False (long "no-generate-nfdata")   <*> many (strOption (long "extra-import" <> metavar "IMPORT"))   <*> strOption         ( long "module-prefix"
src/Pinch/Generate.hs view
@@ -8,6 +8,7 @@ import           Control.Monad.Reader import qualified Data.ByteString                       as BS import           Data.Char+import           Data.Foldable                         (forM_) import qualified Data.HashMap.Strict                   as Map import           Data.List import           Data.Maybe@@ -38,6 +39,7 @@   = Settings   { sHashableVectorInstanceModule :: T.Text   , sGenerateArbitrary            :: Bool+  , sGenerateNFData               :: Bool   , sExtraImports                 :: [T.Text]   , sModulePrefix                 :: T.Text   } deriving (Show)@@ -107,7 +109,8 @@       mkMod ".Types"       (imports ++ defaultImports ++ map         (\n -> H.ImportDecl (H.ModuleName n) True H.IEverything)-        (sExtraImports s ++ if sGenerateArbitrary s then [ "Test.QuickCheck" ] else [])+        (sExtraImports s ++ (if sGenerateArbitrary s then [ "Test.QuickCheck" ] else [])+                         ++ (if sGenerateNFData s then [ "Control.DeepSeq" ] else []))       )       (concat typeDecls)     , -- client@@ -191,7 +194,7 @@   ConstFloat n _ -> pure (H.ELit (H.LFloat n))   ConstLiteral s _ -> pure (H.ELit (H.LString s))   ConstIdentifier ident _-    | xs @(_:_:_) <- T.splitOn "." ident -> do+    | xs@(_:_:_) <- T.splitOn "." ident -> do       moduleMap <- asks cModuleMap       case Map.lookup (mconcat $ init xs) moduleMap of         Nothing ->@@ -258,11 +261,14 @@       , H.FunBind (toEnum' ++ [toEnumDef])       ]     , H.InstDecl (H.InstHead [] clHashable (H.TyCon tyName)) []-    ] ++ if sGenerateArbitrary settings then [+    ] ++ (if sGenerateArbitrary settings then [       H.InstDecl (H.InstHead [] clArbitrary (H.TyCon tyName)) [         H.FunBind [ arbitrary ]       ]     ] else [])+    ++ (if sGenerateNFData settings then [+      H.InstDecl (H.InstHead [] clNFData (H.TyCon tyName)) []+    ] else []))   where     tyName = enumName e     (cons, fromEnum', toEnum', pinch', unpinchAlts') = unzip5 $ map gEnumDef $ zip [0..] $ enumValues e@@ -358,6 +364,9 @@     ] ++ (if sGenerateArbitrary settings then [       H.InstDecl (H.InstHead [] clArbitrary (H.TyCon nm)) [ arbitrary ]     ] else [])+      ++ (if sGenerateNFData settings then [+      H.InstDecl (H.InstHead [] clNFData (H.TyCon nm)) []+    ] else [])  data ServiceResultCon = SRCNone | SRCVoid H.Name @@ -419,6 +428,9 @@     ] ++ (if sGenerateArbitrary settings then [       H.InstDecl (H.InstHead [] clArbitrary (H.TyCon nm)) [ arbitrary ]     ] else [])+    ++ (if sGenerateNFData settings then [+      H.InstDecl (H.InstHead [] clNFData (H.TyCon nm)) []+    ] else [])  gField :: T.Text -> (Integer, Field SourcePos) -> GenerateM (Integer, H.Name, H.Type, Bool) gField prefix (i, f) = do@@ -539,11 +551,12 @@ tyUnit = H.TyCon $ "()" tyIO = H.TyCon $ "Prelude.IO" -clPinchable, clHashable, clException, clArbitrary :: H.ClassName+clPinchable, clHashable, clException, clArbitrary, clNFData :: H.ClassName clPinchable = "Pinch.Pinchable" clHashable = "Data.Hashable.Hashable" clException = "Control.Exception.Exception" clArbitrary = "Test.QuickCheck.Arbitrary"+clNFData = "Control.DeepSeq.NFData"  decapitalize :: T.Text -> T.Text decapitalize s = if T.null s then "" else T.singleton (toLower $ T.head s) <> T.tail s