on bbbd6ee help sign in
elk/compiler/Model/Libraries.hs
35 lines 1.0 kB history raw
1module Libraries (libraries) where
3import qualified Data.Map as Map
4import Text.JSON
5import LoadLibraries (docs)
7libraries :: Map.Map String (Map.Map String String)
8libraries = case getLibs of
9 Ok libs -> libs
10 Error err -> error err
12getLibs :: Result (Map.Map String (Map.Map String String))
13getLibs = do
14 obj <- decodeStrict docs :: Result (JSObject JSValue)
15 modules <- valFromObj "modules" obj :: Result [JSObject JSValue]
16 Map.fromList `fmap` mapM getValues modules
19getName :: JSObject JSValue -> Result String
20getName obj = valFromObj "name" obj
22getType :: JSObject JSValue -> Result String
23getType obj = valFromObj "type" obj
25getValue :: JSObject JSValue -> Result (String,String)
26getValue obj = do n <- getName obj
27 t <- getType obj
28 return (n,t)
30getValues :: JSObject JSValue -> Result (String, Map.Map String String)
31getValues obj = do
32 name <- getName obj
33 vs <- valFromObj "values" obj
34 vals <- mapM getValue vs
35 return (name, Map.fromList vals)