git.iko.soy/typeable/attoparsec
on master help sign in
Report error contexts.
5b8d8d0Matthias Fischmann
Data/Attoparsec/ByteString.hs+5−3
@@ -92,6 +92,7 @@ module Data.Attoparsec.ByteString
92 ) where
92 ) where
93
93
94import Data.Attoparsec.Combinator
94import Data.Attoparsec.Combinator
95+import Data.List (intercalate)
95import qualified Data.Attoparsec.ByteString.Internal as I
96import qualified Data.Attoparsec.ByteString.Internal as I
96import qualified Data.Attoparsec.Internal as I
97import qualified Data.Attoparsec.Internal as I
97import qualified Data.ByteString as B
98import qualified Data.ByteString as B
@@ -218,6 +219,7 @@ maybeResult _ = Nothing
218-- | Convert a 'Result' value to an 'Either' value. A 'T.Partial'
219-- | Convert a 'Result' value to an 'Either' value. A 'T.Partial'
219-- result is treated as failure.
220-- result is treated as failure.
220eitherResult :: Result r -> Either String r
221eitherResult :: Result r -> Either String r
221−eitherResult (T.Done _ r) = Right r
222+eitherResult (T.Done _ r) = Right r
222−eitherResult (T.Fail _ _ msg) = Left msg
223+eitherResult (T.Fail _ [] msg) = Left msg
224+eitherResult (T.Fail _ ctxs msg) = Left (intercalate " > " ctxs ++ ": " ++ msg)
223−eitherResult _ = Left "Result: incomplete input"
225+eitherResult _ = Left "Result: incomplete input"
Data/Attoparsec/ByteString/Internal.hs+5−3
@@ -74,6 +74,7 @@ import Data.Attoparsec.Internal
74import Data.Attoparsec.Internal.Fhthagn (inlinePerformIO)
74import Data.Attoparsec.Internal.Fhthagn (inlinePerformIO)
75import Data.Attoparsec.Internal.Types hiding (Parser, Failure, Success)
75import Data.Attoparsec.Internal.Types hiding (Parser, Failure, Success)
76import Data.ByteString (ByteString)
76import Data.ByteString (ByteString)
77+import Data.List (intercalate)
77import Data.Word (Word8)
78import Data.Word (Word8)
78import Foreign.ForeignPtr (withForeignPtr)
79import Foreign.ForeignPtr (withForeignPtr)
79import Foreign.Ptr (castPtr, minusPtr, plusPtr)
80import Foreign.Ptr (castPtr, minusPtr, plusPtr)
@@ -416,9 +417,10 @@ parse m s = T.runParser m (buffer s) (Pos 0) Incomplete failK successK
416-- @
417-- @
417parseOnly :: Parser a -> ByteString -> Either String a
418parseOnly :: Parser a -> ByteString -> Either String a
418parseOnly m s = case T.runParser m (buffer s) (Pos 0) Complete failK successK of
419parseOnly m s = case T.runParser m (buffer s) (Pos 0) Complete failK successK of
420+ Fail _ [] err -> Left err
419− Fail _ _ err -> Left err
421+ Fail _ ctxs err -> Left (intercalate " > " ctxs ++ ": " ++ err)
420− Done _ a -> Right a
422+ Done _ a -> Right a
421− _ -> error "parseOnly: impossible error!"
423+ _ -> error "parseOnly: impossible error!"
422{-# INLINE parseOnly #-}
424{-# INLINE parseOnly #-}
423
425
424get :: Parser ByteString
426get :: Parser ByteString
Data/Attoparsec/ByteString/Lazy.hs+4−2
@@ -36,6 +36,7 @@ module Data.Attoparsec.ByteString.Lazy
36
36
37import Control.DeepSeq (NFData(rnf))
37import Control.DeepSeq (NFData(rnf))
38import Data.ByteString.Lazy.Internal (ByteString(..), chunk)
38import Data.ByteString.Lazy.Internal (ByteString(..), chunk)
39+import Data.List (intercalate)
39import qualified Data.ByteString as B
40import qualified Data.ByteString as B
40import qualified Data.Attoparsec.ByteString as A
41import qualified Data.Attoparsec.ByteString as A
41import qualified Data.Attoparsec.Internal.Types as T
42import qualified Data.Attoparsec.Internal.Types as T
@@ -99,5 +100,6 @@ maybeResult _ = Nothing
99
100
100-- | Convert a 'Result' value to an 'Either' value.
101-- | Convert a 'Result' value to an 'Either' value.
101eitherResult :: Result r -> Either String r
102eitherResult :: Result r -> Either String r
102−eitherResult (Done _ r) = Right r
103+eitherResult (Done _ r) = Right r
103−eitherResult (Fail _ _ msg) = Left msg
104+eitherResult (Fail _ [] msg) = Left msg
105+eitherResult (Fail _ ctxs msg) = Left (intercalate " > " ctxs ++ ": " ++ msg)
Data/Attoparsec/Text.hs+5−3
@@ -131,6 +131,7 @@ import Data.Attoparsec.Text.Internal (Parser, Result, parse, takeWhile1)
131import Data.Bits (Bits, (.|.), shiftL)
131import Data.Bits (Bits, (.|.), shiftL)
132import Data.Char (isAlpha, isDigit, isSpace, ord)
132import Data.Char (isAlpha, isDigit, isSpace, ord)
133import Data.Int (Int8, Int16, Int32, Int64)
133import Data.Int (Int8, Int16, Int32, Int64)
134+import Data.List (intercalate)
134import Data.Text (Text)
135import Data.Text (Text)
135import Data.Word (Word8, Word16, Word32, Word64, Word)
136import Data.Word (Word8, Word16, Word32, Word64, Word)
136import qualified Data.Attoparsec.Internal as I
137import qualified Data.Attoparsec.Internal as I
@@ -257,9 +258,10 @@ maybeResult _ = Nothing
257-- | Convert a 'Result' value to an 'Either' value. A 'Partial' result
258-- | Convert a 'Result' value to an 'Either' value. A 'Partial' result
258-- is treated as failure.
259-- is treated as failure.
259eitherResult :: Result r -> Either String r
260eitherResult :: Result r -> Either String r
260−eitherResult (T.Done _ r) = Right r
261+eitherResult (T.Done _ r) = Right r
261−eitherResult (T.Fail _ _ msg) = Left msg
262+eitherResult (T.Fail _ [] msg) = Left msg
263+eitherResult (T.Fail _ ctxs msg) = Left (intercalate " > " ctxs ++ ": " ++ msg)
262−eitherResult _ = Left "Result: incomplete input"
264+eitherResult _ = Left "Result: incomplete input"
263
265
264-- | A predicate that matches either a carriage return @\'\\r\'@ or
266-- | A predicate that matches either a carriage return @\'\\r\'@ or
265-- newline @\'\\n\'@ character.
267-- newline @\'\\n\'@ character.
Data/Attoparsec/Text/Internal.hs+5−3
@@ -73,6 +73,7 @@ import Data.Attoparsec.Internal.Types hiding (Parser, Failure, Success)
73import qualified Data.Attoparsec.Text.Buffer as Buf
73import qualified Data.Attoparsec.Text.Buffer as Buf
74import Data.Attoparsec.Text.Buffer (Buffer, buffer)
74import Data.Attoparsec.Text.Buffer (Buffer, buffer)
75import Data.Char (chr, ord)
75import Data.Char (chr, ord)
76+import Data.List (intercalate)
76import Data.String (IsString(..))
77import Data.String (IsString(..))
77import Data.Text.Internal (Text(..))
78import Data.Text.Internal (Text(..))
78import Prelude hiding (getChar, length, succ, take, takeWhile)
79import Prelude hiding (getChar, length, succ, take, takeWhile)
@@ -429,9 +430,10 @@ parse m s = runParser m (buffer s) 0 Incomplete failK successK
429-- @
430-- @
430parseOnly :: Parser a -> Text -> Either String a
431parseOnly :: Parser a -> Text -> Either String a
431parseOnly m s = case runParser m (buffer s) 0 Complete failK successK of
432parseOnly m s = case runParser m (buffer s) 0 Complete failK successK of
433+ Fail _ [] err -> Left err
432− Fail _ _ err -> Left err
434+ Fail _ ctxs err -> Left (intercalate " > " ctxs ++ ": " ++ err)
433− Done _ a -> Right a
435+ Done _ a -> Right a
434− _ -> error "parseOnly: impossible error!"
436+ _ -> error "parseOnly: impossible error!"
435{-# INLINE parseOnly #-}
437{-# INLINE parseOnly #-}
436
438
437get :: Parser Text
439get :: Parser Text
Data/Attoparsec/Text/Lazy.hs+4−2
@@ -36,6 +36,7 @@ module Data.Attoparsec.Text.Lazy
36 ) where
36 ) where
37
37
38import Control.DeepSeq (NFData(rnf))
38import Control.DeepSeq (NFData(rnf))
39+import Data.List (intercalate)
39import Data.Text.Lazy.Internal (Text(..), chunk)
40import Data.Text.Lazy.Internal (Text(..), chunk)
40import qualified Data.Attoparsec.Internal.Types as T
41import qualified Data.Attoparsec.Internal.Types as T
41import qualified Data.Attoparsec.Text as A
42import qualified Data.Attoparsec.Text as A
@@ -94,5 +95,6 @@ maybeResult _ = Nothing
94
95
95-- | Convert a 'Result' value to an 'Either' value.
96-- | Convert a 'Result' value to an 'Either' value.
96eitherResult :: Result r -> Either String r
97eitherResult :: Result r -> Either String r
97−eitherResult (Done _ r) = Right r
98+eitherResult (Done _ r) = Right r
98−eitherResult (Fail _ _ msg) = Left msg
99+eitherResult (Fail _ [] msg) = Left msg
100+eitherResult (Fail _ ctxs msg) = Left (intercalate " > " ctxs ++ ": " ++ msg)