@@ -164,8 +164,14 @@ foreign import ccall "get_parser_error_problem"
164foreign import ccall "get_parser_error_context"
164foreign import ccall "get_parser_error_context"
165 c_get_parser_error_context :: Parser -> IO (Ptr CUChar)
165 c_get_parser_error_context :: Parser -> IO (Ptr CUChar)
167−foreign import ccall unsafe "get_parser_error_offset"
167+foreign import ccall unsafe "get_parser_error_index"
168− c_get_parser_error_offset :: Parser -> IO CULong
168+ c_get_parser_error_index :: Parser -> IO CULong
170+foreign import ccall unsafe "get_parser_error_line"
171+ c_get_parser_error_line :: Parser -> IO CULong
173+foreign import ccall unsafe "get_parser_error_column"
174+ c_get_parser_error_column :: Parser -> IO CULong
170makeString :: MonadIO m => (a -> m (Ptr CUChar)) -> a -> m String
176makeString :: MonadIO m => (a -> m (Ptr CUChar)) -> a -> m String
171makeString f a = do
177makeString f a = do
@@ -511,12 +517,12 @@ runParser :: MonadResource m => Parser -> GSource m Event
511runParser parser = do
517runParser parser = do
512 e <- liftIO $ parserParseOne' parser
518 e <- liftIO $ parserParseOne' parser
513 case e of
519 case e of
514− Left err -> liftIO $ throwIO $ YamlException err
520+ Left err -> liftIO $ throwIO err
515 Right Nothing -> return ()
521 Right Nothing -> return ()
516 Right (Just ev) -> yield ev >> runParser parser
522 Right (Just ev) -> yield ev >> runParser parser
518parserParseOne' :: Parser
524parserParseOne' :: Parser
519− -> IO (Either String (Maybe Event))
525+ -> IO (Either YamlException (Maybe Event))
520parserParseOne' parser = allocaBytes eventSize $ \er -> do
526parserParseOne' parser = allocaBytes eventSize $ \er -> do
521 res <- liftIO $ c_yaml_parser_parse parser er
527 res <- liftIO $ c_yaml_parser_parse parser er
522 flip finally (c_yaml_event_delete er) $
528 flip finally (c_yaml_event_delete er) $
@@ -524,16 +530,10 @@ parserParseOne' parser = allocaBytes eventSize $ \er -> do
525 problem <- makeString c_get_parser_error_problem parser
531 problem <- makeString c_get_parser_error_problem parser
526 context <- makeString c_get_parser_error_context parser
532 context <- makeString c_get_parser_error_context parser
527− offset <- c_get_parser_error_offset parser
533+ index <- c_get_parser_error_index parser
528− return $ Left $ concat
534+ line <- c_get_parser_error_line parser
529− [ "YAML parse error: "
535+ column <- c_get_parser_error_column parser
530− , problem
536+ return $ Left $ YamlParseException problem context (fromIntegral index, fromIntegral line, fromIntegral column)
537 else Right <$> getEvent er
537 else Right <$> getEvent er
539encode :: MonadResource m => GSink Event m ByteString
539encode :: MonadResource m => GSink Event m ByteString
@@ -594,5 +594,7 @@ runEmitter allocI closeI =
594 close u = liftIO $ closeI u a
594 close u = liftIO $ closeI u a
596data YamlException = YamlException String
596data YamlException = YamlException String
597+ -- | problem, context, index, position line, position column
598+ | YamlParseException String String (Int, Int, Int)
597 deriving (Show, Typeable)
599 deriving (Show, Typeable)
598−instance Exception YamlException
600+instance Exception YamlException