mirror of
https://github.com/mrkkrp/megaparsec.git
synced 2024-12-24 16:51:38 +03:00
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:
parent
028b775885
commit
718b0f358a
@ -136,9 +136,18 @@ toHints err = Hints hints
|
||||
msgs = filter ((== 1) . fromEnum) $ errorMessages err
|
||||
|
||||
-- | @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 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
|
||||
-- @hs@ to third argument of original continuation @c@.
|
||||
|
Loading…
Reference in New Issue
Block a user