@@ -164,8 +164,14 @@ foreign import ccall "get_parser_error_problem"
164164foreign import ccall "get_parser_error_context"
165165 c_get_parser_error_context :: Parser -> IO (Ptr CUChar)
166166
167−foreign import ccall unsafe "get_parser_error_offset"
168− c_get_parser_error_offset :: Parser -> IO CULong
167+foreign import ccall unsafe "get_parser_error_index"
168+ c_get_parser_error_index :: Parser -> IO CULong
169+
170+foreign import ccall unsafe "get_parser_error_line"
171+ c_get_parser_error_line :: Parser -> IO CULong
172+
173+foreign import ccall unsafe "get_parser_error_column"
174+ c_get_parser_error_column :: Parser -> IO CULong
169175
170176makeString :: MonadIO m => (a -> m (Ptr CUChar)) -> a -> m String
171177makeString f a = do
@@ -511,12 +517,12 @@ runParser :: MonadResource m => Parser -> GSource m Event
511517runParser parser = do
512518 e <- liftIO $ parserParseOne' parser
513519 case e of
514− Left err -> liftIO $ throwIO $ YamlException err
520+ Left err -> liftIO $ throwIO err
515521 Right Nothing -> return ()
516522 Right (Just ev) -> yield ev >> runParser parser
517523
518524parserParseOne' :: Parser
519− -> IO (Either String (Maybe Event))
525+ -> IO (Either YamlException (Maybe Event))
520526parserParseOne' parser = allocaBytes eventSize $ \er -> do
521527 res <- liftIO $ c_yaml_parser_parse parser er
522528 flip finally (c_yaml_event_delete er) $
@@ -524,16 +530,10 @@ parserParseOne' parser = allocaBytes eventSize $ \er -> do
524530 then do
525531 problem <- makeString c_get_parser_error_problem parser
526532 context <- makeString c_get_parser_error_context parser
527− offset <- c_get_parser_error_offset parser
528− return $ Left $ concat
529− [ "YAML parse error: "
530− , problem
531− , "\nContext: "
532− , context
533− , "\nOffset: "
534− , show offset
535− , "\n"
536− ]
533+ index <- c_get_parser_error_index parser
534+ line <- c_get_parser_error_line parser
535+ column <- c_get_parser_error_column parser
536+ return $ Left $ YamlParseException problem context (fromIntegral index, fromIntegral line, fromIntegral column)
537537 else Right <$> getEvent er
538538
539539encode :: MonadResource m => GSink Event m ByteString
@@ -594,5 +594,7 @@ runEmitter allocI closeI =
594594 close u = liftIO $ closeI u a
595595
596596data YamlException = YamlException String
597+ -- | problem, context, index, position line, position column
598+ | YamlParseException String String (Int, Int, Int)
597599 deriving (Show, Typeable)
598−instance Exception YamlException
600+instance Exception YamlException