Permalink
Browse files

Fixed implementation of hash merge in Yst.Yaml.

  • Loading branch information...
1 parent eb776e5 commit 16f9241c0a188b862be6f78f10f40633a6427c2f @jgm committed Aug 3, 2009
Showing with 9 additions and 2 deletions.
  1. +9 −2 Yst/Yaml.hs
View
@@ -37,8 +37,15 @@ yamlNodeToNode n =
Nothing -> NString (unpackBuf s)
Just d -> NDate d
EMap xs | all (\(k,_) -> isStrNode k) xs -> NMap pairs
- where pairs = map mkPair xs
- mkPair (k,v) = (strFrom k, yamlNodeToNode v)
+ where pairs = foldr addPair [] xs
+ addPair (k,v) acc = if isStrNode k && strFrom k == "<<" -- hash merge, unsupported in Syck!
+ then case n_elem v of -- so we do it ourselves
+ EMap ys -> foldr addPair acc ys
+ _ -> error "Tried hash merge on non-hash"
+ else case lookup kstr acc of
+ Just _ -> acc -- overridden
+ Nothing -> (kstr, yamlNodeToNode v) : acc
+ where kstr = strFrom k
EMap _ -> error "Map keys must all be strings."
ESeq xs -> NList $ map yamlNodeToNode xs
ENil -> NNil

0 comments on commit 16f9241

Please sign in to comment.