47 lines
1.1 KiB
Haskell
47 lines
1.1 KiB
Haskell
module Main where
|
|
|
|
import Data.Aeson (FromJSON, parseJSON, withObject, withText, (.:), decode)
|
|
|
|
data Program = Program { programFns :: [Function] }
|
|
deriving (Show)
|
|
|
|
data Function = Function {
|
|
functionName :: String,
|
|
returnType :: Maybe Type,
|
|
functionArgs :: [FunctionArg]
|
|
} deriving (Show)
|
|
|
|
data Type = Int | Bool
|
|
deriving (Show)
|
|
|
|
data FunctionArg = FunctionArg {
|
|
argName :: String,
|
|
argType :: Type
|
|
} deriving (Show)
|
|
|
|
instance FromJSON Program where
|
|
parseJSON = withObject "Program" $ \v -> Program
|
|
<$> v .: "functions"
|
|
|
|
instance FromJSON Function where
|
|
parseJSON = withObject "Function" $ \v -> Function
|
|
<$> v .: "name"
|
|
<*> v .: "type"
|
|
<*> v .: "args"
|
|
|
|
instance FromJSON FunctionArg where
|
|
parseJSON = withObject "FunctionArg" $ \v -> FunctionArg
|
|
<$> v .: "name"
|
|
<*> v .: "type"
|
|
|
|
instance FromJSON Type where
|
|
parseJSON = withText "Type" $ \v ->
|
|
case v of
|
|
"int" -> return Int
|
|
"bool" -> return Bool
|
|
_ -> fail "wrong type"
|
|
|
|
main :: IO ()
|
|
main = do
|
|
putStrLn $ show (decode "int" :: Maybe Type)
|