Changeset 8607 for src/Pugs/Prim/Yaml.hs

Show
Ignore:
Timestamp:
01/08/06 15:26:21 (3 years ago)
Author:
gaal
Message:

* eval :lang<yaml> deserializes pugs objects.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • src/Pugs/Prim/Yaml.hs

    r8606 r8607  
    3030        IntMap.fromAscList ([0..] `zip` map lazyScalar vals) 
    3131    return $ VRef (arrayRef av) 
    32 fromYaml MkYamlNode{el=YamlMap nodes} = do 
    33     vals    <- forM nodes $ \(keyNode, valNode) -> do 
    34         key <- fromVal =<< fromYaml keyNode 
    35         val <- newScalar =<< fromYaml valNode 
    36         return (key, val) 
    37     hv      <- liftSTM $ (newTVar (Map.fromList vals) :: STM IHash) 
    38     -- XXX: if YamlMap (Just "!perl/":type) nodes then mkObject etc. 
    39     return $ VRef (hashRef hv) 
     32fromYaml MkYamlNode{el=YamlMap nodes,tag=tag} = do 
     33    case tag of 
     34        Nothing  -> do 
     35            vals    <- forM nodes $ \(keyNode, valNode) -> do 
     36                key <- fromVal =<< fromYaml keyNode 
     37                val <- newScalar =<< fromYaml valNode 
     38                return (key, val) 
     39            hv      <- liftSTM $ (newTVar (Map.fromList vals) :: STM IHash) 
     40            return $ VRef (hashRef hv) 
     41        Just ('p':'u':'g':'s':'/':'o':'b':'j':'e':'c':'t':':':typ) -> do 
     42            vals    <- forM nodes $ \(keyNode, valNode) -> do 
     43                key <- fromVal =<< fromYaml keyNode 
     44                val <- fromYaml valNode 
     45                return (key, val) 
     46            return . VObject =<< createObject (mkType typ) vals 
     47        Just x   -> error ("can't deserialize: " ++ x) 
    4048 
    4149dumpYaml :: Int -> Val -> Eval Val