tdlib-gen 0.3.0 → 0.4.0
raw patch · 4 files changed
+25/−15 lines, 4 files
Files
- src/Codegen.hs +14/−8
- src/Language/Haskell/Codegen.hs +7/−3
- src/Processing.hs +2/−2
- tdlib-gen.cabal +2/−2
src/Codegen.hs view
@@ -5,7 +5,7 @@ import Data.Map.Strict (Map) import qualified Data.Map.Strict as M import Data.Maybe (fromMaybe)-import Data.Text (Text, pack, unpack)+import Data.Text (Text, isInfixOf, pack, unpack) import qualified Data.Text as T import Language.Haskell.Codegen import Language.TL.AST hiding (ADT (..), Ann, App, Type (..))@@ -55,15 +55,21 @@ typeConv _ A.NatType = Type "Int" app :: Type -> [Type] -> Type-app t = foldl (\acc ty -> App acc ty) t+app t = foldr (\ty acc -> App acc ty) t convArg :: TyMap -> Arg -> Field convArg m Arg {..} =- Field- { name = argName,- ty = typeConv m argType,- ..- }+ let ty = typeConv m argType+ in Field+ { name = argName,+ ty = case ann of+ Nothing -> ty+ Just doc ->+ if "may be null" `isInfixOf` doc+ then warpM ty+ else ty,+ ..+ } combToConstr :: TyMap -> Combinator -> Constr combToConstr m Combinator {..} =@@ -74,7 +80,7 @@ } formArr :: [Field] -> Type -> Ann -> TypeSig-formArr fields resT resAnn = foldl (\res Field {..} -> Conn {..}) (Result {ty = resT, ann = resAnn}) fields+formArr fields resT resAnn = foldr (\Field {..} res -> Conn {..}) (Result {ty = resT, ann = resAnn}) fields combToFun :: TyMap -> Combinator -> FunDef combToFun m c@Combinator {..} =
src/Language/Haskell/Codegen.hs view
@@ -22,7 +22,7 @@ prettyDoc (Just d) = let ls = T.lines d ds = fmap unsafeTextWithoutNewlines ls- in "-- |" <+> foldl1 (<>) (intersperse (line <> "--" <> line <> "--") ds) <> line+ in "-- |" <+> foldl1' (<>) (intersperse (line <> "--" <> line <> "--") ds) <> line prettyDoc Nothing = mempty data ADT@@ -40,7 +40,7 @@ prettyConstrs [] = mempty prettyConstrs (x : xs) = vsep- [ foldl1 (<>) (intersperse (line <> "| ") (("=" <+> x) : xs)),+ [ foldl1' (<>) (intersperse (line <> "| ") (("=" <+> x) : xs)), "deriving (Show, Eq, Generic)" ] @@ -65,6 +65,10 @@ } deriving (Show, Eq, Generic) +warpM :: Type -> Type+warpM (App (Type "[]") t') = App (Type "[]") (warpM t')+warpM t = App (Type "Maybe") t+ instance Pretty Field where pretty Field {..} = prettyDoc ann@@ -85,7 +89,7 @@ pretty Constr {..} = let doc = prettyDoc ann n = unsafeTextWithoutNewlines name- fs = foldl (<>) mempty (intersperse ("," <> line) (fmap pretty fields))+ fs = foldl' (<>) mempty (intersperse ("," <> line) (fmap pretty fields)) in doc <> vsep [ n,
src/Processing.hs view
@@ -78,8 +78,8 @@ convProgram :: Program -> ([ADT], [Function]) convProgram prog =- foldl- ( \(c, f) blk -> case blk of+ foldr+ ( \blk (c, f) -> case blk of FunDeclBlk decls -> (c, (declBlockToFun $ filterAnnDecl decls) <> f) TypeDeclBlk decls -> ((declBlockToADT $ filterAnnDecl decls) <> c, f) )
tdlib-gen.cabal view
@@ -4,10 +4,10 @@ -- -- see: https://github.com/sol/hpack ----- hash: 87d8b332f3f3f40e3c87975b071928df3b431394f8d59a56968b8fcf9ffe65ed+-- hash: 37bce2cd570e13b47dd98eea43c2b8baad194f052f8ff9d05754dbef5b28851e name: tdlib-gen-version: 0.3.0+version: 0.4.0 synopsis: Codegen for TDLib description: Please see the README on GitHub at <https://github.com/poscat0x04/tdlib-gen#readme> category: Codegen