diff options
Diffstat (limited to 'ddl/Language.hs')
-rw-r--r-- | ddl/Language.hs | 13 |
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 | ||
64 | data Type | 64 | data 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 | ||
84 | filterInstances :: Target -> [(Target,Instance)] -> [Instance] | ||
85 | filterInstances target l = [inst | (t,inst) <- l, t == target] | ||
86 | |||
84 | hasEnumConstructor :: DataDef -> Bool | 87 | hasEnumConstructor :: DataDef -> Bool |
85 | hasEnumConstructor DataDef{..} = or [null fields | ConstructorDef{..} <- constructors] | 88 | hasEnumConstructor DataDef{..} = or [null fields | ConstructorDef{..} <- constructors] |
86 | hasEnumConstructor _ = False | 89 | hasEnumConstructor _ = False |
@@ -359,16 +362,18 @@ instance ToJSON DataDef | |||
359 | instance ToJSON Instance | 362 | instance ToJSON Instance |
360 | instance ToJSON Field | 363 | instance ToJSON Field |
361 | instance ToJSON Type | 364 | instance ToJSON Type |
365 | instance ToJSON Target | ||
362 | 366 | ||
363 | instance FromJSON ConstructorDef | 367 | instance FromJSON ConstructorDef |
364 | instance FromJSON DataDef | 368 | instance FromJSON DataDef |
365 | instance FromJSON Instance | 369 | instance FromJSON Instance |
366 | instance FromJSON Field | 370 | instance FromJSON Field |
367 | instance FromJSON Type | 371 | instance FromJSON Type |
372 | instance FromJSON Target | ||
368 | 373 | ||
369 | type MDef = Writer [ModuleDef] | 374 | type MDef = Writer [ModuleDef] |
370 | type DDef = Writer ([DataDef],[String]) | 375 | type DDef = Writer ([DataDef],[String]) |
371 | type CDef = Writer ([ConstructorDef],[Instance]) | 376 | type CDef = Writer ([ConstructorDef],[(Target,Instance)]) |
372 | 377 | ||
373 | module_ :: String -> DDef () -> MDef () | 378 | module_ :: String -> DDef () -> MDef () |
374 | module_ n m = tell [let (d,i) = execWriter m in ModuleDef n i d] | 379 | module_ 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 | ||
396 | deriving_ :: [Target] -> [Instance] -> CDef () | 401 | deriving_ :: [Target] -> [Instance] -> CDef () |
397 | deriving_ t l = tell (mempty,l) | 402 | deriving_ targets instances = tell (mempty,[(t,i) | i <- instances, t <- targets]) |
398 | 403 | ||
399 | const_ :: String -> [Type] -> CDef () | 404 | const_ :: String -> [Type] -> CDef () |
400 | const_ n t = tell ([ConstructorDef n [Field a b | Field a b <- map toField t]],mempty) | 405 | const_ n t = tell ([ConstructorDef n [Field a b | Field a b <- map toField t]],mempty) |