on master help sign in
Custom types
commit295038206ef73524df681d4e956a498cba3f841d authoriko <ilyakooo0@gmail.com> dateWed 3 Aug 2022, 11:44 (4 years ago) parent659d213
1 file changed+11
src/Main.hs+11
src/Main.hs+11
@@ -30,6 +30,7 @@ data Datatype
3030 | IntType
3131 | FloatType
3232 | StringType
33+ | CustomType Text
3334 | List Datatype
3435 | MaybeType Datatype
3536 deriving stock (Show)
@@ -54,6 +55,7 @@ instance FromJSON Datatype where
5455 parseJSON (String "Int") = pure IntType
5556 parseJSON (String "Float") = pure FloatType
5657 parseJSON (String "String") = pure StringType
58+ parseJSON (String t) = pure $ CustomType t
5759 parseJSON _ = fail "Bad datatype ;("
5860
5961data Options = Options
@@ -92,6 +94,7 @@ elmType _ BoolType = pure $ ETyCon $ ETCon "Bool"
9294elmType _ IntType = pure $ ETyCon $ ETCon "Int"
9395elmType _ FloatType = pure $ ETyCon $ ETCon "Float"
9496elmType _ StringType = pure $ ETyCon $ ETCon "String"
97+elmType _ (CustomType t) = pure $ ETyCon $ ETCon $ toString t
9598elmType name (List inner) = do
9699 inner' <- elmType name inner
97100 simpleElmAlias (toString name <> "_List") (elAp "List" inner')
@@ -179,6 +182,14 @@ psType _ BoolType = pure psBool
179182psType _ IntType = pure psInt
180183psType _ FloatType = pure psNumber
181184psType _ StringType = pure psString
185+psType _ (CustomType t) = do
186+ pure
187+ TypeInfo
188+ { _typePackage = "bridge",
189+ _typeModule = "Bridge",
190+ _typeName = t,
191+ _typeParameters = []
192+ }
182193psType name (List inner) = do
183194 inner' <- psType name inner
184195 simplePSAlias (name <> "_List") (psAp "builtins" "Prim" "Array" inner')