summaryrefslogtreecommitdiff
path: root/ddl/Language.hs
diff options
context:
space:
mode:
Diffstat (limited to 'ddl/Language.hs')
-rw-r--r--ddl/Language.hs13
1 files changed, 9 insertions, 4 deletions
diff --git a/ddl/Language.hs b/ddl/Language.hs
index be684db..9701023 100644
--- a/ddl/Language.hs
+++ b/ddl/Language.hs
@@ -26,7 +26,7 @@ data DataDef
26 = DataDef 26 = DataDef
27 { dataName :: String 27 { dataName :: String
28 , constructors :: [ConstructorDef] 28 , constructors :: [ConstructorDef]
29 , instances :: [Instance] 29 , instances :: [(Target,Instance)]
30 } 30 }
31 | TypeAlias 31 | TypeAlias
32 { aliasName :: String 32 { aliasName :: String
@@ -59,7 +59,7 @@ data Target
59 | PureScript 59 | PureScript
60 | Cpp 60 | Cpp
61 | CSharp 61 | CSharp
62 deriving (Show,Generic) 62 deriving (Show,Eq,Generic)
63 63
64data Type 64data Type
65 = Int 65 = Int
@@ -81,6 +81,9 @@ data Type
81 | Data { name_ :: String } 81 | Data { name_ :: String }
82 deriving (Show,Generic,Eq,Ord) 82 deriving (Show,Generic,Eq,Ord)
83 83
84filterInstances :: Target -> [(Target,Instance)] -> [Instance]
85filterInstances target l = [inst | (t,inst) <- l, t == target]
86
84hasEnumConstructor :: DataDef -> Bool 87hasEnumConstructor :: DataDef -> Bool
85hasEnumConstructor DataDef{..} = or [null fields | ConstructorDef{..} <- constructors] 88hasEnumConstructor DataDef{..} = or [null fields | ConstructorDef{..} <- constructors]
86hasEnumConstructor _ = False 89hasEnumConstructor _ = False
@@ -359,16 +362,18 @@ instance ToJSON DataDef
359instance ToJSON Instance 362instance ToJSON Instance
360instance ToJSON Field 363instance ToJSON Field
361instance ToJSON Type 364instance ToJSON Type
365instance ToJSON Target
362 366
363instance FromJSON ConstructorDef 367instance FromJSON ConstructorDef
364instance FromJSON DataDef 368instance FromJSON DataDef
365instance FromJSON Instance 369instance FromJSON Instance
366instance FromJSON Field 370instance FromJSON Field
367instance FromJSON Type 371instance FromJSON Type
372instance FromJSON Target
368 373
369type MDef = Writer [ModuleDef] 374type MDef = Writer [ModuleDef]
370type DDef = Writer ([DataDef],[String]) 375type DDef = Writer ([DataDef],[String])
371type CDef = Writer ([ConstructorDef],[Instance]) 376type CDef = Writer ([ConstructorDef],[(Target,Instance)])
372 377
373module_ :: String -> DDef () -> MDef () 378module_ :: String -> DDef () -> MDef ()
374module_ n m = tell [let (d,i) = execWriter m in ModuleDef n i d] 379module_ n m = tell [let (d,i) = execWriter m in ModuleDef n i d]
@@ -394,7 +399,7 @@ instance IsField Type where
394 toField a = Field "" a 399 toField a = Field "" a
395 400
396deriving_ :: [Target] -> [Instance] -> CDef () 401deriving_ :: [Target] -> [Instance] -> CDef ()
397deriving_ t l = tell (mempty,l) 402deriving_ targets instances = tell (mempty,[(t,i) | i <- instances, t <- targets])
398 403
399const_ :: String -> [Type] -> CDef () 404const_ :: String -> [Type] -> CDef ()
400const_ n t = tell ([ConstructorDef n [Field a b | Field a b <- map toField t]],mempty) 405const_ n t = tell ([ConstructorDef n [Field a b | Field a b <- map toField t]],mempty)