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

Show
Ignore:
Timestamp:
01/08/06 20:40:46 (3 years ago)
Author:
gaal
Message:

YAML serialization -
* emit PGE Rules (rx:g/a/.yaml works)
* normalize emitted booleans
* src/Data/Yaml/Syck.hsc cleanups

  • YamlNode? structure shouldn't change much henceforth
  • remove implicit vars
Files:
1 modified

Legend:

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

    r8607 r8608  
    5454           (return . VStr) rv 
    5555 
     56strNode :: String -> YamlNode 
     57strNode str = emptyYamlNode{el = YamlStr str } 
     58 
    5659toYaml :: (?d :: Int) => Val -> Eval YamlNode 
    57 toYaml _ | ?d == 0  = return $ emptyYamlNode{el = YamlStr "<deep recursion>"} -- fail? make this configurable? 
     60toYaml _ | ?d == 0  = return $ strNode "<deep recursion>" -- fail? make this configurable? 
    5861toYaml VUndef       = return emptyYamlNode 
    59 toYaml (VStr str)   = return $ emptyYamlNode{el = YamlStr (encodeUTF8 str)} 
     62toYaml (VBool x)    = return $ boolToYaml x 
     63toYaml (VStr str)   = return $ strNode (encodeUTF8 str) 
    6064toYaml v@(VRef r)   = let ?d = pred ?d in do 
    6165    t  <- evalValType v 
     
    6569        ifValTypeIsa v "Array" (return nodes) $ case v' of 
    6670            VObject _   -> return nodes 
    67             _           -> return emptyYamlNode{el = YamlMap [(emptyYamlNode{el=YamlStr "<ref>"}, nodes)]} 
     71            _           -> return emptyYamlNode{el = YamlMap [(strNode "<ref>", nodes)]} 
    6872toYaml (VList nodes) = let ?d = pred ?d in do 
    6973    n <- mapM toYaml nodes 
     
    7882    attrs   <- toYaml $ VRef (hashRef hash) 
    7983    return $ tagNode (Just $ "tag:pugs:object:" ++ showType (objType obj)) attrs 
    80 toYaml v = return $ emptyYamlNode{el=YamlStr p} 
    81     where p = (encodeUTF8 . pretty) v 
     84toYaml (VRule MkRulePGE{rxRule=rule, rxGlobal=global, rxStringify=stringify, rxAdverbs=adverbs}) = let ?d = pred ?d in do 
     85    adverbs' <- toYaml adverbs 
     86    return emptyYamlNode{el = YamlMap 
     87                            [ (strNode "rule", strNode rule) 
     88                            , (strNode "global", boolToYaml global) 
     89                            , (strNode "stringify", boolToYaml stringify) 
     90                            , (strNode "adverbs", adverbs') 
     91                            ] , tag = Just "tag:pugs:Rule"} 
     92toYaml v = return $ strNode $ (encodeUTF8 . pretty) v 
    8293 
    8394 
     
    93104hashToYaml r = error ("unexpected node: " ++ show r) 
    94105 
     106boolToYaml :: VBool -> YamlNode 
     107boolToYaml True  = strNode "true" 
     108boolToYaml False = strNode "false"