mirror of
https://github.com/mrkkrp/megaparsec.git
synced 2024-12-25 01:07:57 +03:00
When merging error messages, prefer known messages to unknown ones
This fixes a regression introduced by: Sun Feb 20 18:24:22 EET 2011 Roman Cheplyaka <roma@ro-che.info> * Choose the longest match when merging error messages The source of the regression is that parsec sometimes generates dummy (aka "unknown") error messages when no actual error has occurred. So, when merging errors, before simply looking at the positions we should check if one of them is unknown and just ignore it. Reported by Matthias Hörmann.
This commit is contained in:
parent
1bac97f3b5
commit
b8990ab042
@ -134,12 +134,16 @@ setErrorMessage msg (ParseError pos msgs)
|
||||
= ParseError pos (msg : filter (msg /=) msgs)
|
||||
|
||||
mergeError :: ParseError -> ParseError -> ParseError
|
||||
mergeError (ParseError pos1 msgs1) (ParseError pos2 msgs2)
|
||||
mergeError e1@(ParseError pos1 msgs1) e2@(ParseError pos2 msgs2)
|
||||
-- prefer meaningful errors
|
||||
| null msgs2 && not (null msgs1) = e1
|
||||
| null msgs1 && not (null msgs2) = e2
|
||||
| otherwise
|
||||
= case pos1 `compare` pos2 of
|
||||
-- select the longest match
|
||||
EQ -> ParseError pos1 (msgs1 ++ msgs2)
|
||||
GT -> ParseError pos1 msgs1
|
||||
LT -> ParseError pos2 msgs2
|
||||
GT -> e1
|
||||
LT -> e2
|
||||
|
||||
instance Show ParseError where
|
||||
show err
|
||||
|
Loading…
Reference in New Issue
Block a user