packages feed

yaml 0.8.0.2 → 0.8.1

raw patch · 5 files changed

+44/−24 lines, 5 filesdep ~hspec

Dependency ranges changed: hspec

Files

Data/Yaml.hs view
@@ -12,6 +12,7 @@     , Parser     , Object     , Array+    , ParseException(..)       -- * Constructors and accessors     , object     , array@@ -33,6 +34,8 @@     , decodeFile       -- ** Better error information     , decodeEither+      -- ** More control over decoding+    , decodeHelper     ) where  import qualified Text.Libyaml as Y@@ -114,7 +117,7 @@                     | UnexpectedEvent { _received :: Maybe Event                                       , _expected :: Maybe Event                                       }-                    | InvalidYaml (Maybe String)+                    | InvalidYaml (Maybe YamlException)     deriving (Show, Typeable) instance Exception ParseException @@ -264,7 +267,7 @@     case x of         Left e             | Just pe <- fromException e -> return $ Left pe-            | Just ye <- fromException e -> return $ Left $ InvalidYaml $ Just $ show (ye :: YamlException)+            | Just ye <- fromException e -> return $ Left $ InvalidYaml $ Just (ye :: YamlException)             | otherwise -> throwIO e         Right y -> return $ Right $ parseEither parseJSON y 
Text/Libyaml.hs view
@@ -23,8 +23,9 @@     , decode     , encodeFile     , decodeFile-      -- * Exception+      -- * Error handling     , YamlException (..)+    , YamlMark (..)     ) where  import qualified Data.ByteString.Internal as B@@ -164,9 +165,15 @@ foreign import ccall "get_parser_error_context"     c_get_parser_error_context :: Parser -> IO (Ptr CUChar) -foreign import ccall unsafe "get_parser_error_offset"-    c_get_parser_error_offset :: Parser -> IO CULong+foreign import ccall unsafe "get_parser_error_index"+    c_get_parser_error_index :: Parser -> IO CULong +foreign import ccall unsafe "get_parser_error_line"+    c_get_parser_error_line :: Parser -> IO CULong++foreign import ccall unsafe "get_parser_error_column"+    c_get_parser_error_column :: Parser -> IO CULong+ makeString :: MonadIO m => (a -> m (Ptr CUChar)) -> a -> m String makeString f a = do     cchar <- castPtr `liftM` f a@@ -511,12 +518,12 @@ runParser parser = do     e <- liftIO $ parserParseOne' parser     case e of-        Left err -> liftIO $ throwIO $ YamlException err+        Left err -> liftIO $ throwIO err         Right Nothing -> return ()         Right (Just ev) -> yield ev >> runParser parser  parserParseOne' :: Parser-                -> IO (Either String (Maybe Event))+                -> IO (Either YamlException (Maybe Event)) parserParseOne' parser = allocaBytes eventSize $ \er -> do     res <- liftIO $ c_yaml_parser_parse parser er     flip finally (c_yaml_event_delete er) $@@ -524,16 +531,11 @@         then do           problem <- makeString c_get_parser_error_problem parser           context <- makeString c_get_parser_error_context parser-          offset <- c_get_parser_error_offset parser-          return $ Left $ concat-            [ "YAML parse error: "-            , problem-            , "\nContext: "-            , context-            , "\nOffset: "-            , show offset-            , "\n"-            ]+          index <- c_get_parser_error_index parser+          line <- c_get_parser_error_line parser+          column <- c_get_parser_error_column parser+          let problemMark = YamlMark (fromIntegral index) (fromIntegral line) (fromIntegral column)+          return $ Left $ YamlParseException problem context problemMark         else Right <$> getEvent er  encode :: MonadResource m => GSink Event m ByteString@@ -593,6 +595,12 @@             loop         close u = liftIO $ closeI u a +-- | The pointer position+data YamlMark = YamlMark { yamlIndex :: Int, yamlLine :: Int, yamlColumn :: Int }+    deriving Show+ data YamlException = YamlException String+                   -- | problem, context, index, position line, position column+                   | YamlParseException { yamlProblem :: String, yamlContext :: String, yamlProblemMark :: YamlMark }     deriving (Show, Typeable) instance Exception YamlException
c/helper.c view
@@ -56,9 +56,19 @@ 	return p->context; } -unsigned int get_parser_error_offset(yaml_parser_t *p)+unsigned int get_parser_error_index(yaml_parser_t *p) {-	return p->offset;+	return p->problem_mark.index;+}++unsigned int get_parser_error_line(yaml_parser_t *p)+{+	return p->problem_mark.line;+}++unsigned int get_parser_error_column(yaml_parser_t *p)+{+	return p->problem_mark.column; }  unsigned char const * get_emitter_error(yaml_emitter_t *e)
test/main.hs view
@@ -14,8 +14,7 @@ import System.Directory import Control.Monad import Control.Exception (try, SomeException)-import Test.Hspec.Monadic-import Test.Hspec.HUnit ()+import Test.Hspec  import qualified Data.Yaml as D import Data.Yaml (object, array)@@ -24,7 +23,7 @@ import qualified Data.Text as T  main :: IO ()-main = hspecX $ do+main = hspec $ do     describe "streaming" $ do         it "count scalars with anchor" caseCountScalarsWithAnchor         it "count sequences with anchor" caseCountSequencesWithAnchor
yaml.cabal view
@@ -1,5 +1,5 @@ name:            yaml-version:         0.8.0.2+version:         0.8.1 license:         BSD3 license-file:    LICENSE author:          Michael Snoyman <michael@snoyman.com>, Anton Ageev <antage@gmail.com>,Kirill Simonov @@ -61,7 +61,7 @@     hs-source-dirs:  test     main-is:         main.hs     cpp-options:     -DTEST-    build-depends:   hspec+    build-depends:   hspec >= 1.3                    , HUnit                    , directory                    , base >= 4 && < 5