purescript-bridge 0.3.0.5 → 0.3.0.6
raw patch · 3 files changed
+23/−8 lines, 3 files
Files
- purescript-bridge.cabal +1/−1
- src/Language/PureScript/Bridge/Primitives.hs +9/−0
- src/Language/PureScript/Bridge/Printer.hs +13/−7
purescript-bridge.cabal view
@@ -10,7 +10,7 @@ -- PVP summary: +-+------- breaking API changes -- | | +----- non-breaking API additions -- | | | +--- code changes with no API change-version: 0.3.0.5+version: 0.3.0.6 -- A short (one-line) description of the package. synopsis: Generate PureScript data types from Haskell data types
src/Language/PureScript/Bridge/Primitives.hs view
@@ -4,6 +4,15 @@ import Language.PureScript.Bridge.TypeInfo +unitBridge :: TypeBridge+unitBridge t+ | eqTypeName "()" t = Just $ t {+ typePackage = "purescript-prelude"+ , typeModule = "Prelude"+ , typeName = "Unit"+ }+ | otherwise = Nothing+ boolBridge :: TypeBridge boolBridge t | eqTypeName "Bool" t = Just $ t {
src/Language/PureScript/Bridge/Printer.hs view
@@ -68,11 +68,12 @@ sumTypeToText (SumType t cs) = T.unlines $ "data " <> typeName t <> " =" : [ " " <> T.intercalate "\n | " (map (constructorToText 4) cs) ]- ++ [ "\nderive instance generic" <> typeName t <> " :: Generic " <> typeName t <> "\n" ]+ ++ [ "derive instance generic" <> typeName t <> " :: Generic " <> typeName t ] constructorToText :: Int -> DataConstructor -> Text-constructorToText _ (DataConstructor n (Left ts)) = n <> " " <> T.intercalate " " (map typeInfoToText ts)+constructorToText _ (DataConstructor n (Left ts)) = n <> " " <> T.intercalate " " (map (typeInfoToText needParens) ts) <> "\n"+ where needParens = length ts > 1 constructorToText indentation (DataConstructor n (Right rs)) = T.unlines $ n <> " {" : [ spaces (indentation + 2) <> T.intercalate intercalation (map recordEntryToText rs) ]@@ -82,14 +83,19 @@ spaces c = T.replicate c " " recordEntryToText :: RecordEntry -> Text-recordEntryToText e = recLabel e <> " :: " <> typeInfoToText (recValue e)+recordEntryToText e = recLabel e <> " :: " <> typeInfoToText False (recValue e) -typeInfoToText :: TypeInfo -> Text-typeInfoToText t = if length textParameters > 1 then "(" <> inner <> ")" else inner+typeInfoToText :: Bool -> TypeInfo -> Text+typeInfoToText needParens t = if needParens && pLength > 0 then "(" <> inner <> ")" else inner where- inner = typeName t <> T.intercalate " " textParameters- textParameters = map typeInfoToText (typeParameters t)+ inner = typeName t <>+ if pLength > 0+ then " " <> T.intercalate " " textParameters+ else ""+ params = typeParameters t+ pLength = length params+ textParameters = map (typeInfoToText (pLength > 1)) params sumTypesToModules :: Modules -> [SumType] -> Modules sumTypesToModules = foldr sumTypeToModule