Don't use hints with custom error messages

Close #75.

Now accumulated hints are not used with ‘ParseError’ records that have
only custom messages in them (created with ‘Message’ constructor, as
opposed to ‘Unexpected’ or ‘Expected’). This strips “expected” line from
custom error messages where it's unlikely to be relevant anyway.
This commit is contained in:
mrkkrp 2016-01-02 20:19:40 +06:00
parent 028b775885
commit 718b0f358a

View File

@ -136,9 +136,18 @@ toHints err = Hints hints
msgs = filter ((== 1) . fromEnum) $ errorMessages err msgs = filter ((== 1) . fromEnum) $ errorMessages err
-- | @withHints hs c@ makes “error” continuation @c@ use given hints @hs@. -- | @withHints hs c@ makes “error” continuation @c@ use given hints @hs@.
--
-- Note that if resulting continuation gets 'ParseError' where all messages
-- are created with 'Message' constructor, hints are ignored.
withHints :: Hints -> (ParseError -> m b) -> ParseError -> m b withHints :: Hints -> (ParseError -> m b) -> ParseError -> m b
withHints (Hints xs) c = c . addErrorMessages (Expected <$> concat xs) withHints (Hints xs) c e =
let isMessage (Message _) = True
isMessage _ = False
in (if all isMessage (errorMessages e)
then c
else c . addErrorMessages (Expected <$> concat xs))
e
-- | @accHints hs c@ results in “OK” continuation that will add given hints -- | @accHints hs c@ results in “OK” continuation that will add given hints
-- @hs@ to third argument of original continuation @c@. -- @hs@ to third argument of original continuation @c@.