packages feed

property-list 0.0.0.5 → 0.0.0.6

raw patch · 5 files changed

+57/−25 lines, 5 filesdep +bytestring-class

Dependencies added: bytestring-class

Files

property-list.cabal view
@@ -1,5 +1,5 @@ name:                   property-list-version:                0.0.0.5+version:                0.0.0.6 stability:              experimental license:                PublicDomain @@ -14,7 +14,10 @@ synopsis:               XML property list parser description:            Parser, data type and formatter for Apple's XML property list 1.0 format. -flag data_object_uses_lazy_bytestrings+flag new-data-object+  description:          Use the new version of the data-object package (>= 0.0.2)+                        Which has a "generic object" type in place of the simpler+                        Object type in previous versions.   default:              True  Library@@ -28,6 +31,7 @@                         Data.PropertyList.Object   build-depends:        base >= 3 && <5,                         bytestring,+                        bytestring-class,                         containers,                          dataenc,                         HaXml >= 1.19,@@ -39,9 +43,9 @@                         template-haskell,                         th-fold -  if flag(data_object_uses_lazy_bytestrings)+  if flag(new-data-object)     build-depends:      data-object >= 0.0.2-    cpp-options:        -Ddata_object_uses_lazy_bytestrings+    cpp-options:        -DNEW_DATA_OBJECT   else     build-depends:      data-object <  0.0.2     
src/Data/PropertyList/Object.hs view
@@ -1,5 +1,5 @@ {-# LANGUAGE -        FlexibleContexts, UndecidableInstances, CPP+        FlexibleContexts, UndecidableInstances   #-} module Data.PropertyList.Object ({- instances only -}) where @@ -7,30 +7,25 @@ import Data.PropertyList.Type import Data.PropertyList.Parse import Data.PropertyList.Xml-#ifdef data_object_uses_lazy_bytestrings-import Data.ByteString.Lazy.Char8-#else-import Data.ByteString.Char8-#endif import qualified Data.Map as M import Control.Monad import Control.Monad import Control.Monad.Error  instance ToScalar UnparsedPlistItem where-    toScalar = pack . showXml . plistItemToPlist . unparsedPlistItemToPlistItem+    toScalar = toScalar . showXml . plistItemToPlist . unparsedPlistItemToPlistItem instance ToObject UnparsedPlistItem where     toObject = Scalar . toScalar  instance (ToObject (l a), ToObject (m a)) => ToObject (PropertyListS l m a) where     toObject (PLArray a)    = toObject a     toObject (PLData bs)    = toObject bs-    toObject (PLDate d)     = showToScalar d+    toObject (PLDate d)     = showToObject d     toObject (PLDict d)     = toObject d-    toObject (PLReal d)     = showToScalar d-    toObject (PLInt i)      = showToScalar i-    toObject (PLString s)   = stringToScalar s-    toObject (PLBool b)     = showToScalar b+    toObject (PLReal d)     = showToObject d+    toObject (PLInt i)      = showToObject i+    toObject (PLString s)   = toObject s+    toObject (PLBool b)     = showToObject b  instance (ToObject (f (M f a)), ToObject a) => ToObject (M f a) where     toObject (S x) = toObject x@@ -39,8 +34,8 @@ instance (ToScalar k, ToObject v) => ToObject (M.Map k v) where     toObject = toObject . M.assocs -stringToScalar = Scalar . pack-showToScalar :: Show a => a -> Object-showToScalar = stringToScalar . show+showToObject :: Show a => a -> Object+showToObject = toObject . show +test :: Object test = toObject (undefined :: PropertyList)
src/Data/PropertyList/Parse.hs view
@@ -22,10 +22,11 @@  -- |run an incremental parser - a function which takes -- a token type and returns either a subterm (possibly still--- containing unparsed tokens) or an unparsed token (possibly+-- containing unparsed tokens) or an unparseable token (possibly -- a new token, maybe even of a new type).  This interpretation -- of the action of this function is based on a term-algebra--- view of the monad in question.+-- view of the monad in question, where the 'variable' sort+-- consists of unparsed fragments of the source data. parseT :: Monad t => (a -> Either (t a) b) -> a -> t b parseT f = parse         where parse token =
src/Data/PropertyList/PropertyListItem.hs view
@@ -2,7 +2,7 @@     TypeSynonymInstances,     FlexibleInstances,     GeneralizedNewtypeDeriving,-    TemplateHaskell+    TemplateHaskell, CPP   #-}  module Data.PropertyList.PropertyListItem where@@ -15,6 +15,9 @@  import qualified Data.Map as M import Data.ByteString (ByteString)+import qualified Data.ByteString.Lazy as Lazy (ByteString)+import Data.ByteString.Lazy.Char8 (pack, unpack)+import Data.ByteString.Class import Data.Time import Data.Char @@ -23,6 +26,8 @@ import Control.Monad import Control.Monad.State +import Data.Object+ -- |A class for items which can be converted to and from property lists class PropertyListItem i where     -- |Convert the item to a property list, usually by simply wrapping the@@ -159,9 +164,16 @@  instance PropertyListItem ByteString where     toPropertyList = plData-    fromPropertyList (S (PLData x)) = Just x+    fromPropertyList (S (PLData x))   = Just x+    fromPropertyList (S (PLString x)) = Just (toStrictByteString x)     fromPropertyList _ = Nothing +instance PropertyListItem Lazy.ByteString where+    toPropertyList = plData . toStrictByteString+    fromPropertyList (S (PLData   x)) = Just (toLazyByteString x)+    fromPropertyList (S (PLString x)) = Just (toLazyByteString x)+    fromPropertyList _ = Nothing+ instance PropertyListItem UTCTime where     toPropertyList = plDate     fromPropertyList (S (PLDate x)) = Just x@@ -213,6 +225,7 @@          listToPropertyList = plString     listFromPropertyList (S (PLString x)) = Just x+    listFromPropertyList (S (PLData x))   = Just (fromStrictByteString x)     listFromPropertyList (S (PLBool True)) = Just "YES"     listFromPropertyList (S (PLBool False)) = Just "NO"     listFromPropertyList (S (PLInt i)) = Just (show i)@@ -233,6 +246,27 @@     toPropertyList = plVar     fromPropertyList (V d) = Just d     fromPropertyList _ = Nothing++-- |Note that due to 'Object''s use of 'Lazy.ByteString's, scalars become data, not strings.+-- Using @GenObject key String@ instead of 'Object' will cause scalars to be encoded as plist strings.+#ifdef NEW_DATA_OBJECT+instance (PropertyListItem val, LazyByteString key) => PropertyListItem (GenObject key val) where+#else+instance PropertyListItem Object where+#endif+    toPropertyList (Mapping  m) = toPropertyList (M.fromList [(toStr k, v) | (k,v) <- m])+        where toStr = unpack . toLazyByteString+    toPropertyList (Sequence s) = toPropertyList s+    toPropertyList (Scalar   s) = toPropertyList s+    +    fromPropertyList plist = msum+        [ do+            m <- fromPropertyList plist+            let fromStr = fromLazyByteString . pack+            return (Mapping [(fromStr k, v) | (k,v) <- M.assocs m])+        , fmap Sequence (fromPropertyList plist)+        , fmap Scalar   (fromPropertyList plist)+        ]  -- The following TH generates, for Either and for all OneOfN types --  (N in [2..20]), an instance of the form:
src/Data/PropertyList/Type.hs view
@@ -94,8 +94,6 @@     (S x) >>= f = S (fmap (>>= f) x)     (V x) >>= f = f x --- TODO: if possible, make 'fold' in th-utils detect the Functor instances for--- [] and Map k and automagically generate the call to fmap here foldPropertyList :: (Functor list, Functor map)                  => (list a -> a)                  -> (ByteString -> a)