@@ -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"
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.