on 263bf1c help sign in
elk/compiler/Model/Libraries.hs
37 lines 1.1 kB history raw
1{-# LANGUAGE TemplateHaskell #-}
3module Libraries (libraries) where
5import qualified Data.Map as Map
6import Text.JSON
7import LoadLibraries
9libraries :: Map.Map String (Map.Map String String)
10libraries = case getLibs of
11 Ok libs -> libs
12 Error err -> error err
14getLibs :: Result (Map.Map String (Map.Map String String))
15getLibs = do
16 obj <- decodeStrict $(docs) :: Result (JSObject JSValue)
17 modules <- valFromObj "modules" obj :: Result [JSObject JSValue]
18 Map.fromList `fmap` mapM getValues modules
21getName :: JSObject JSValue -> Result String
22getName obj = valFromObj "name" obj
24getType :: JSObject JSValue -> Result String
25getType obj = valFromObj "type" obj
27getValue :: JSObject JSValue -> Result (String,String)
28getValue obj = do n <- getName obj
29 t <- getType obj
30 return (n,t)
32getValues :: JSObject JSValue -> Result (String, Map.Map String String)
33getValues obj = do
34 name <- getName obj
35 vs <- valFromObj "values" obj
36 vals <- mapM getValue vs
37 return (name, Map.fromList vals)