on master help sign in
add records for error handling
commit6d40221e40928bea3a3cea080d5f961bda131aec authorBoris Lykah <lykahb@gmail.com> dateSat 29 Sep 2012, 12:31 (14 years ago) parentfe08234
1 file changed+10−4
Text/Libyaml.hs+10−4
Text/Libyaml.hs+10−4
@@ -23,8 +23,9 @@ module Text.Libyaml
2323 , decode
2424 , encodeFile
2525 , decodeFile
26− -- * Exception
26+ -- * Error handling
2727 , YamlException (..)
28+ , YamlMark (..)
2829 ) where
2930
3031import qualified Data.ByteString.Internal as B
@@ -533,7 +534,8 @@ parserParseOne' parser = allocaBytes eventSize $ \er -> do
533534 index <- c_get_parser_error_index parser
534535 line <- c_get_parser_error_line parser
535536 column <- c_get_parser_error_column parser
536− return $ Left $ YamlParseException problem context (fromIntegral index, fromIntegral line, fromIntegral column)
537+ let problemMark = YamlMark (fromIntegral index) (fromIntegral line) (fromIntegral column)
538+ return $ Left $ YamlParseException problem context problemMark
537539 else Right <$> getEvent er
538540
539541encode :: MonadResource m => GSink Event m ByteString
@@ -593,8 +595,12 @@ runEmitter allocI closeI =
593595 loop
594596 close u = liftIO $ closeI u a
595597
598+-- | The pointer position
599+data YamlMark = YamlMark { yamlIndex :: Int, yamlLine :: Int, yamlColumn :: Int }
600+ deriving Show
601+
596602data YamlException = YamlException String
597603 -- | problem, context, index, position line, position column
598− | YamlParseException String String (Int, Int, Int)
604+ | YamlParseException { yamlProblem :: String, yamlContext :: String, yamlProblemMark :: YamlMark }
599605 deriving (Show, Typeable)
600−instance Exception YamlException
606+instance Exception YamlException