packages feed

ruby-marshal 0.1.0 → 0.1.1

raw patch · 7 files changed

+114/−127 lines, 7 filesdep ~mtl

Dependency ranges changed: mtl

Files

CHANGELOG.md view
@@ -1,3 +1,8 @@+# 0.1.1++- Added some minor style changes.+- Relaxed mtl lower bound.+ # 0.1.0  - Separated modules by concern.
ruby-marshal.cabal view
@@ -1,31 +1,17 @@-name:-  ruby-marshal-version:-  0.1.0-synopsis:-  Parse a subset of Ruby objects serialised with Marshal.dump.-description:-  Parse a subset of Ruby objects serialised with Marshal.dump.-homepage:-  https://github.com/filib/ruby-marshal-license:-  MIT-license-file:-  LICENSE-author:-  Philip Cunningham-maintainer:-  hello@filib.io-category:-  Data-build-type:-  Simple-tested-with:-  GHC == 7.8, GHC == 7.10-cabal-version:-  >= 1.10-extra-source-files:-  CHANGELOG.md+name: ruby-marshal+version: 0.1.1+synopsis: Parse a subset of Ruby objects serialised with Marshal.dump.+description: Parse a subset of Ruby objects serialised with Marshal.dump.+homepage: https://github.com/filib/ruby-marshal+license: MIT+license-file: LICENSE+author: Philip Cunningham+maintainer: hello@filib.io+category: Data+build-type: Simple+tested-with: GHC == 7.8, GHC == 7.10+cabal-version: >= 1.10+extra-source-files: CHANGELOG.md  Source-repository head   type: git@@ -47,7 +33,7 @@     , bytestring  >= 0.9.0  && <= 0.12.0     , containers  >= 0.5.0  && <= 0.6.0     , string-conv >= 0.1    && <= 0.2-    , mtl         >= 2.2.0  && <= 2.3.0+    , mtl         >= 2.1.0  && <= 2.3.0     , vector      >= 0.10.0 && <= 0.11.0   default-language:     Haskell2010
src/Data/Ruby/Marshal.hs view
@@ -23,15 +23,13 @@   , module Data.Ruby.Marshal.Types ) where -import Data.Ruby.Marshal.Get-import Data.Ruby.Marshal.RubyObject-import Data.Ruby.Marshal.Types--import Control.Monad.State.Strict (evalStateT)-import Data.Ruby.Marshal.Monad    (emptyCache, runMarshal)-import Data.Serialize             (runGet)--import qualified Data.ByteString as BS+import           Control.Monad.State.Strict   (evalStateT)+import qualified Data.ByteString              as BS+import           Data.Ruby.Marshal.Get+import           Data.Ruby.Marshal.Monad      (emptyCache, runMarshal)+import           Data.Ruby.Marshal.RubyObject+import           Data.Ruby.Marshal.Types+import           Data.Serialize               (runGet)  -- | Parses a subset of Ruby objects serialised with Marshal, Ruby's -- built-in binary serialisation format.
src/Data/Ruby/Marshal/Get.hs view
@@ -1,7 +1,7 @@-{-# LANGUAGE LambdaCase #-}-{-# LANGUAGE MultiWayIf #-}+{-# LANGUAGE LambdaCase        #-}+{-# LANGUAGE MultiWayIf        #-} {-# LANGUAGE OverloadedStrings #-}-{-# LANGUAGE PatternSynonyms #-}+{-# LANGUAGE PatternSynonyms   #-}  -------------------------------------------------------------------- -- |@@ -23,20 +23,19 @@   , getRubyObject ) where -import Control.Applicative-import Data.Ruby.Marshal.Int-import Data.Ruby.Marshal.Types-import Prelude--import Control.Monad              (liftM2)-import Data.Ruby.Marshal.Encoding (toEnc)-import Data.Ruby.Marshal.Monad    (liftMarshal, readObject, readSymbol, writeCache)-import Data.Serialize.Get         (Get, getBytes, getTwoOf, label)-import Data.String.Conv           (toS)-import Text.Read                  (readMaybe)--import qualified Data.ByteString as BS-import qualified Data.Vector     as V+import           Control.Applicative+import           Control.Monad              (liftM2)+import qualified Data.ByteString            as BS+import           Data.Ruby.Marshal.Encoding (toEnc)+import           Data.Ruby.Marshal.Int+import           Data.Ruby.Marshal.Monad    (liftMarshal, readObject,+                                             readSymbol, writeCache)+import           Data.Ruby.Marshal.Types+import           Data.Serialize.Get         (Get, getBytes, getTwoOf, label)+import           Data.String.Conv           (toS)+import qualified Data.Vector                as V+import           Prelude+import           Text.Read                  (readMaybe)  -------------------------------------------------------------------- -- Top-level functions.@@ -54,19 +53,19 @@   where     go :: Marshal RubyObject     go = liftMarshal getWord8 >>= \case-      NilChar        -> return RNil-      TrueChar       -> return $ RBool True-      FalseChar      -> return $ RBool False-      FixnumChar     -> RFixnum <$> getFixnum-      FloatChar      -> RFloat  <$> getFloat-      StringChar     -> RString <$> getString-      SymbolChar     -> RSymbol <$> getSymbol-      ObjectLinkChar -> RIVar   <$> getObjectLink-      SymlinkChar    -> RSymbol <$> getSymlink-      ArrayChar      -> RArray  <$> getArray go-      HashChar       -> RHash   <$> getHash go go-      IVarChar       -> RIVar   <$> getIVar go-      _              -> return Unsupported+           NilChar        -> return RNil+           TrueChar       -> return $ RBool True+           FalseChar      -> return $ RBool False+           FixnumChar     -> RFixnum <$> getFixnum+           FloatChar      -> RFloat <$> getFloat+           StringChar     -> RString <$> getString+           SymbolChar     -> RSymbol <$> getSymbol+           ObjectLinkChar -> RIVar <$> getObjectLink+           SymlinkChar    -> RSymbol <$> getSymlink+           ArrayChar      -> RArray <$> getArray go+           HashChar       -> RHash <$> getHash go go+           IVarChar       -> RIVar <$> getIVar go+           _              -> return Unsupported  -------------------------------------------------------------------- -- Ancillary functions.@@ -81,23 +80,25 @@ getFixnum :: Marshal Int getFixnum = liftAndLabel "Fixnum" $ do   x <- getInt8-  if | x ==  0   -> fromIntegral <$> return x-     | x ==  1   -> fromIntegral <$> getWord8-     | x == -1   -> fromIntegral <$> getNegInt16-     | x ==  2   -> fromIntegral <$> getWord16le-     | x == -2   -> fromIntegral <$> getInt16le-     | x ==  3   -> fromIntegral <$> getWord24le-     | x == -3   -> fromIntegral <$> getInt24le-     | x ==  4   -> fromIntegral <$> getWord32le-     | x == -4   -> fromIntegral <$> getInt32le-     | x >=  6   -> fromIntegral <$> return (x - 5)-     | x <= -6   -> fromIntegral <$> return (x + 5)+  if | x == 0 -> fromIntegral <$> return x+     | x == 1 -> fromIntegral <$> getWord8+     | x == -1 -> fromIntegral <$> getNegInt16+     | x == 2 -> fromIntegral <$> getWord16le+     | x == -2 -> fromIntegral <$> getInt16le+     | x == 3 -> fromIntegral <$> getWord24le+     | x == -3 -> fromIntegral <$> getInt24le+     | x == 4 -> fromIntegral <$> getWord32le+     | x == -4 -> fromIntegral <$> getInt32le+     | x >= 6 -> fromIntegral <$> return (x - 5)+     | x <= -6 -> fromIntegral <$> return (x + 5)      | otherwise -> empty   where     getNegInt16 :: Get Int16-    getNegInt16 =  do+    getNegInt16 = do       x <- fromIntegral <$> getInt8-      if x >= 0 && x <= 127 then return (x - 256) else return x+      if x >= 0 && x <= 127+        then return (x - 256)+        else return x  -- | Parses <http://ruby-doc.org/core-2.2.0/Float.html Float>. getFloat :: Marshal Float@@ -119,18 +120,20 @@   str <- g   len <- getFixnum   if | len /= 1 -> fail "expected single character"-     | otherwise   -> do-       symbol <- g-       denote <- g-       case symbol of-         RSymbol "E" -> case denote of-           RBool True  -> return' (str, UTF_8)-           RBool False -> return' (str, US_ASCII)-           _           -> fail "expected bool"-         RSymbol "encoding" -> case denote of-           RString enc -> return' (str, toEnc enc)-           _           -> fail "expected string"-         _          -> fail "invalid ivar"+     | otherwise -> do+        symbol <- g+        denote <- g+        case symbol of+          RSymbol "E" ->+            case denote of+              RBool True  -> return' (str, UTF_8)+              RBool False -> return' (str, US_ASCII)+              _           -> fail "expected bool"+          RSymbol "encoding" ->+            case denote of+              RString enc -> return' (str, toEnc enc)+              _           -> fail "expected string"+          _ -> fail "invalid ivar"   where     return' result = do       writeCache $ RIVar result
src/Data/Ruby/Marshal/Int.hs view
@@ -27,15 +27,14 @@   , Word8 ) where -import Control.Applicative-import Prelude--import Data.Bits          ((.|.), shiftL)-import Data.Int           (Int8, Int16, Int32)-import Data.Serialize.Get (Get, getBytes, getWord8, getWord16le, getWord32le)-import Data.Word          (Word8, Word32)--import qualified Data.ByteString as BS+import           Control.Applicative+import           Data.Bits           (shiftL, (.|.))+import qualified Data.ByteString     as BS+import           Data.Int            (Int16, Int32, Int8)+import           Data.Serialize.Get  (Get, getBytes, getWord16le, getWord32le,+                                      getWord8)+import           Data.Word           (Word32, Word8)+import           Prelude  -- | Read an Int8. getInt8 :: Get Int8@@ -51,7 +50,7 @@ getWord24le = do   s <- getBytes 3   return $! (fromIntegral (s `BS.index` 2) `shiftL` 16) .|.-            (fromIntegral (s `BS.index` 1) `shiftL`  8) .|.+            (fromIntegral (s `BS.index` 1) `shiftL` 8) .|.              fromIntegral (s `BS.index` 0)  -- | Read an Int24. Since Int24 unavailable in Data.Int we use Int32.
src/Data/Ruby/Marshal/Monad.hs view
@@ -16,15 +16,14 @@  module Data.Ruby.Marshal.Monad where -import Control.Applicative-import Prelude--import Control.Monad.State.Strict   (get, gets, lift, put, MonadState, StateT)-import Data.Ruby.Marshal.RubyObject (RubyObject(..))-import Data.Serialize.Get           (Get)-import Data.Vector                  (Vector)--import qualified Data.Vector as V+import           Control.Applicative+import           Control.Monad.State.Strict   (MonadState, StateT, get, gets,+                                               lift, put)+import           Data.Ruby.Marshal.RubyObject (RubyObject (..))+import           Data.Serialize.Get           (Get)+import           Data.Vector                  (Vector)+import qualified Data.Vector                  as V+import           Prelude  -- | Marshal monad endows the underlying Get monad with State. newtype Marshal a = Marshal {@@ -64,6 +63,6 @@ writeCache object = do   cache <- get   case object of-    RIVar   _ -> put $ cache { objects = V.snoc (objects cache) object }+    RIVar _   -> put $ cache { objects = V.snoc (objects cache) object }     RSymbol _ -> put $ cache { symbols = V.snoc (symbols cache) object }     _         -> return ()
src/Data/Ruby/Marshal/RubyObject.hs view
@@ -1,6 +1,6 @@-{-# LANGUAGE FlexibleInstances #-}+{-# LANGUAGE FlexibleInstances   #-} {-# LANGUAGE IncoherentInstances #-}-{-# LANGUAGE LambdaCase #-}+{-# LANGUAGE LambdaCase          #-}  -------------------------------------------------------------------- -- |@@ -18,15 +18,13 @@  module Data.Ruby.Marshal.RubyObject where -import Control.Applicative-import Prelude--import Control.Arrow              ((***))-import Data.Ruby.Marshal.Encoding (RubyStringEncoding(..))--import qualified Data.ByteString as BS-import qualified Data.Map.Strict as DM-import qualified Data.Vector     as V+import           Control.Applicative+import           Control.Arrow              ((***))+import qualified Data.ByteString            as BS+import qualified Data.Map.Strict            as DM+import           Data.Ruby.Marshal.Encoding (RubyStringEncoding (..))+import qualified Data.Vector                as V+import           Prelude  -- | Representation of a Ruby object. data RubyObject@@ -104,8 +102,8 @@ instance Rubyable Float where   toRuby = RFloat   fromRuby = \case-    RFloat  x -> Just x-    _         -> Nothing+    RFloat x -> Just x+    _        -> Nothing  instance Rubyable (BS.ByteString, RubyStringEncoding) where   toRuby (x, y) = RIVar (RString x, y)@@ -119,7 +117,6 @@   toRuby = \case     Just x  -> toRuby x     Nothing -> RNil-   fromRuby = \case     RNil -> Just Nothing     x    -> fromRuby x