mirror of
https://github.com/macocianradu/RosettaHaskellCompiler.git
synced 2026-03-18 21:10:07 +00:00
23 lines
936 B
Haskell
23 lines
936 B
Haskell
module Model.Enum where
|
|
import Model.Type
|
|
|
|
-- |The representation of a Rosetta enum data type
|
|
data EnumType = MakeEnum {
|
|
enumName :: String,
|
|
enumDescription :: Maybe String,
|
|
enumValues :: [EnumValue]
|
|
} deriving (Show, Eq)
|
|
|
|
-- |The representation of a Rosetta enum value type
|
|
data EnumValue = MakeEnumValue {
|
|
enumValueName :: String,
|
|
enumValueDescription :: Maybe String,
|
|
enumValueDisplayName :: Maybe String
|
|
} deriving (Show, Eq)
|
|
|
|
convertEnumToType :: EnumType -> Type
|
|
convertEnumToType (MakeEnum name desc val) = MakeType name (BasicType "Object") desc (map (convertValueToAttribute typ) val) [MakeCondition Nothing (Keyword "one-of")]
|
|
where typ = MakeType name (BasicType "Object") desc [] [MakeCondition Nothing (Keyword "one-of")]
|
|
|
|
convertValueToAttribute :: Type -> EnumValue -> TypeAttribute
|
|
convertValueToAttribute typ (MakeEnumValue name desc _) = MakeTypeAttribute name typ (Bounds (0, 1)) Nothing |