Changeset 8587

Show
Ignore:
Timestamp:
01/05/06 23:48:09 (3 years ago)
Author:
gaal
Message:

Data.Yaml.Syck: broken support for hash emitting; thinks hashes are
lists of pairs.
Lots of trace prints left in the code till I figure this out.

Location:
src
Files:
2 modified

Legend:

Unmodified
Added
Removed
  • src/Data/Yaml/Syck.hsc

    r8586 r8587  
    103103            withCString "array" $ \array_literal -> 
    104104                syck_emit_seq e array_literal seqNone 
     105            -- TODO: fix pesky warning about "integer from pointer without a cast" here 
    105106            mapM_ (syck_emit_item e) =<< (mapM freezeNode seq) 
    106107            syck_emit_end e 
    107108        (YamlMap m) -> do 
    108             error "not yet" 
    109109            -- syck_emit_map(e, "hash", map_none); 
     110            trace ("a hash: " ++ (show m)) $ return () 
    110111            withCString "hash" $ \hash_literal -> 
    111112                syck_emit_map e hash_literal mapNone 
     113            mapM_ (\(k,v) -> (syck_emit_item e =<< freezeNode k) >> (syck_emit_item e =<< freezeNode v)) m 
     114            syck_emit_end e 
    112115 
    113116 
  • src/Pugs/Prim/Yaml.hs

    r8586 r8587  
    4949--toYaml (VNum num) = return $ YamlStr -- better handled by pretty? 
    5050toYaml _ (VStr str) = return $ YamlStr (encodeUTF8 str) 
    51 toYaml (d+1) (VList nodes) = do 
    52     fmap YamlSeq $ mapM (toYaml d) nodes 
    5351toYaml (d+1) v@(VRef r) = do  -- stolen from Pugs.Prim prettyVal. Can these be refactored together? 
    5452    v'  <- readRef r 
    55     ifValTypeIsa v "Pair" 
    56         (case v' of 
    57             VList [ks, vs] -> do 
    58                 kStr <- toYaml d ks 
    59                 vStr <- toYaml d vs 
    60                 return $ YamlMap [(kStr, vStr)] -- assume a pair is a one-element hash 
    61             _ -> toYaml d v'                    -- XXX: probably broken to blithingly ignore ref levels here 
     53    t <- evalValType v 
     54    trace ("toYaml VRef: " ++ (show v) ++ " type=" ++ (show t)) $ return () 
     55    (ifValTypeIsa v "Hash" 
     56        (do  
     57            case r of 
     58                MkRef (IHash hv) -> do 
     59                    h <- hash_fetch hv 
     60                    let assocs = Map.toList h 
     61                    yamlmap <- mapM ( \(k, v) -> do 
     62                        k' <- toYaml d (VStr k) 
     63                        v' <- toYaml d v 
     64                        return (k', v')) assocs 
     65                    return $ YamlMap yamlmap 
     66                _ -> error ("can't process hash: " ++ show v') -- XXX 
    6267        ) 
    6368        (do nodes <- toYaml d v' 
    6469            ifValTypeIsa v "Array" 
    6570                (return $ nodes) 
    66                 (ifValTypeIsa v "Hash" 
    67                     --(return $ YamlMap('{':(init (tail str))) ++ "}") 
    68                     (return nodes) 
    69                     (return $ YamlMap [(YamlStr "<ref>", nodes)])) -- XXX 
     71                (return $ YamlMap [(YamlStr "<ref>", nodes)])) -- XXX 
    7072        ) 
     73toYaml (d+1) (VList nodes) = do 
     74    trace ("toYaml VList: " ++ (show nodes)) $ return () 
     75    fmap YamlSeq $ mapM (toYaml d) nodes 
    7176toYaml _ v = return $ YamlStr $ encodeUTF8 $ pretty v 
    7277 
    7378 
    74      
     79    
     80{- 
     81ifValTypeIsa v "Pair" 
     82    (case v' of 
     83        VList [ks, vs] -> do 
     84            kStr <- toYaml d ks 
     85            vStr <- toYaml d vs 
     86            return $ YamlMap [(kStr, vStr)] -- assume a pair is a one-element hash 
     87        _ -> toYaml d v'                    -- XXX: probably broken to blithingly ignore ref levels here 
     88    ) 
     89    (ifValTypeIsa v "Hash" 
     90        --fmap YamlMap $ mapM (\(k, v) -> do {k' <- toYaml k; v' <- toYaml v; return (k', v')}) Map.toList =<< hash_fetch v') 
     91        (do  
     92            case r of 
     93                MkRef (IHash hv) -> do 
     94                    h <- hash_fetch hv 
     95                    let assocs = Map.toList h 
     96                    yamlmap <- mapM (\(k, v) -> do 
     97                        k' <- toYaml d (VStr k) 
     98                        v' <- toYaml d v 
     99                        return (k', v')) assocs 
     100                    return $ YamlMap yamlmap 
     101                _ -> error ("can't process hash: " ++ show v') -- XXX 
     102        ) 
     103        (do nodes <- toYaml d v' 
     104            ifValTypeIsa v "Array" 
     105                (return $ nodes) 
     106                (return $ YamlMap [(YamlStr "<ref>", nodes)])) -- XXX 
     107    ) 
     108-}