@@ -138,6 +138,7 @@ import Data.Attoparsec.Text.Internal (Parser, Result, parse, takeWhile1)
138138import Data.Bits (Bits, (.|.), shiftL)
139139import Data.Char (isAlpha, isDigit, isSpace, ord)
140140import Data.Int (Int8, Int16, Int32, Int64)
141+import Data.List (intercalate)
141142import Data.Text (Text)
142143import Data.Word (Word8, Word16, Word32, Word64)
143144import qualified Data.Attoparsec.Internal as I
@@ -264,9 +265,10 @@ maybeResult _ = Nothing
264265-- | Convert a 'Result' value to an 'Either' value. A 'Partial' result
265266-- is treated as failure.
266267eitherResult :: Result r -> Either String r
267−eitherResult (T.Done _ r) = Right r
268−eitherResult (T.Fail _ _ msg) = Left msg
269−eitherResult _ = Left "Result: incomplete input"
268+eitherResult (T.Done _ r) = Right r
269+eitherResult (T.Fail _ [] msg) = Left msg
270+eitherResult (T.Fail _ ctxs msg) = Left (intercalate " > " ctxs ++ ": " ++ msg)
271+eitherResult _ = Left "Result: incomplete input"
270272
271273-- | A predicate that matches either a carriage return @\'\\r\'@ or
272274-- newline @\'\\n\'@ character.