Changeset 8608 for src/Pugs/Prim/Yaml.hs
- Timestamp:
- 01/08/06 20:40:46 (3 years ago)
- Files:
-
- 1 modified
-
src/Pugs/Prim/Yaml.hs (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
-
src/Pugs/Prim/Yaml.hs
r8607 r8608 54 54 (return . VStr) rv 55 55 56 strNode :: String -> YamlNode 57 strNode str = emptyYamlNode{el = YamlStr str } 58 56 59 toYaml :: (?d :: Int) => Val -> Eval YamlNode 57 toYaml _ | ?d == 0 = return $ emptyYamlNode{el = YamlStr "<deep recursion>"}-- fail? make this configurable?60 toYaml _ | ?d == 0 = return $ strNode "<deep recursion>" -- fail? make this configurable? 58 61 toYaml VUndef = return emptyYamlNode 59 toYaml (VStr str) = return $ emptyYamlNode{el = YamlStr (encodeUTF8 str)} 62 toYaml (VBool x) = return $ boolToYaml x 63 toYaml (VStr str) = return $ strNode (encodeUTF8 str) 60 64 toYaml v@(VRef r) = let ?d = pred ?d in do 61 65 t <- evalValType v … … 65 69 ifValTypeIsa v "Array" (return nodes) $ case v' of 66 70 VObject _ -> return nodes 67 _ -> return emptyYamlNode{el = YamlMap [( emptyYamlNode{el=YamlStr "<ref>"}, nodes)]}71 _ -> return emptyYamlNode{el = YamlMap [(strNode "<ref>", nodes)]} 68 72 toYaml (VList nodes) = let ?d = pred ?d in do 69 73 n <- mapM toYaml nodes … … 78 82 attrs <- toYaml $ VRef (hashRef hash) 79 83 return $ tagNode (Just $ "tag:pugs:object:" ++ showType (objType obj)) attrs 80 toYaml v = return $ emptyYamlNode{el=YamlStr p} 81 where p = (encodeUTF8 . pretty) v 84 toYaml (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"} 92 toYaml v = return $ strNode $ (encodeUTF8 . pretty) v 82 93 83 94 … … 93 104 hashToYaml r = error ("unexpected node: " ++ show r) 94 105 106 boolToYaml :: VBool -> YamlNode 107 boolToYaml True = strNode "true" 108 boolToYaml False = strNode "false"
