yaml-light 0.1 → 0.1.1
raw patch · 2 files changed
+35/−3 lines, 2 files
Files
- Data/Yaml/YamlLight.hs +34/−2
- yaml-light.cabal +1/−1
Data/Yaml/YamlLight.hs view
@@ -18,17 +18,24 @@ -- * YamlLight versions of Syck functions , parseYaml, parseYamlFile, parseYamlBytes -- * YamlLight utility functions- , fromYamlNode, lookupYL, lookupYLWith+ , fromYamlNode, lookupYL, lookupYLWith, combineSequencedMaps -- ** Extractors , unSeq, unMap, unStr ) where import Control.Applicative import Data.Data import Data.List+ import Data.Maybe import qualified Data.Yaml.Syck as Syck import qualified Data.Map as Map import qualified Data.ByteString as ByteString + -- | A Single, lighter-weight representation than that of HsSyck. Note that the YMap is an actual Map from+ -- Data.Map, so behavior with respect to identical keys and ordering of entries will behave as Data.Map+ -- dictates. This behavior is also in compliance with the Yaml spec. If you currently rely on HsSyck's+ -- preservation of ordering, you can also consider representing+ -- such maps as sequences of single entry maps. See the examples of \"Ordered Mappings\" in the Yaml spec: <http://www.yaml.org/spec/1.2/spec.html>.+ data YamlLight = YMap (Map.Map YamlLight YamlLight) | YSeq [YamlLight] | YStr ByteString.ByteString@@ -74,10 +81,35 @@ lookupYLWith p (YMap m) = snd <$> (find (p . fst) $ Map.toList m) lookupYLWith _ _ = Nothing + {- | Combine a sequence of maps into a list of (key,value) pairs. The ordering of the result preserves the ordering+ of the sequence, but the ordering of the individual maps is as Data.Map handles it.++ Example:++ @+ - key1: val1+ key2: val2+ - key3: val3+ @++ Would become:++ @+ [(key1,val1),(key2,val2),(key3,val3)]+ @++ where key1 and key2 might be arranged differently as Data.Map would+ arrange them. This does not preserve uniqueness of keys across maps.+ Any items of the sequence that are not maps will be ignored. Returns Nothing if not called on a Sequence+ -}+ combineSequencedMaps :: YamlLight -> Maybe [(YamlLight, YamlLight)]+ combineSequencedMaps (YSeq ys) = Just . concatMap Map.assocs . catMaybes $ map unMap ys+ combineSequencedMaps _ = Nothing+ -- | Get the contents of a sequence unSeq :: YamlLight -> Maybe [YamlLight] unSeq (YSeq s) = Just s- unSeq _ = Nothing+ unSeq _ = Nothing -- | Get the contents of a map unMap :: YamlLight -> Maybe (Map.Map YamlLight YamlLight)
yaml-light.cabal view
@@ -7,7 +7,7 @@ -- The package version. See the Haskell package versioning policy -- (http://www.haskell.org/haskellwiki/Package_versioning_policy) for -- standards guiding when and how versions should be incremented.-Version: 0.1+Version: 0.1.1 -- A short (one-line) description of the package. Synopsis: A light-weight wrapper with utility functions around HsSyck