summaryrefslogtreecommitdiff
path: root/pyparsing/core.py
diff options
context:
space:
mode:
authorptmcg <ptmcg@austin.rr.com>2023-03-07 00:52:09 -0600
committerptmcg <ptmcg@austin.rr.com>2023-03-07 00:52:09 -0600
commite6706c178564abdce4296629001291eb1ba68a6c (patch)
tree282c3cc6a7912793a8e6a920b7990613e5374cf4 /pyparsing/core.py
parent28e4abe1c394e52c39b0dd00537e8312eb2cd9ae (diff)
downloadpyparsing-git-e6706c178564abdce4296629001291eb1ba68a6c.tar.gz
Don't always override exception messages in MatchFirst or Or classes - addresses #464
Diffstat (limited to 'pyparsing/core.py')
-rw-r--r--pyparsing/core.py9
1 files changed, 7 insertions, 2 deletions
diff --git a/pyparsing/core.py b/pyparsing/core.py
index 71c2690..02ae50a 100644
--- a/pyparsing/core.py
+++ b/pyparsing/core.py
@@ -4147,7 +4147,10 @@ class Or(ParseExpression):
raise max_fatal
if maxException is not None:
- # maxException.msg = self.errmsg
+ # infer from this check that all alternatives failed at the current position
+ # so emit this collective error message instead of any single error message
+ if maxExcLoc == loc:
+ maxException.msg = self.errmsg
raise maxException
else:
raise ParseException(
@@ -4260,7 +4263,9 @@ class MatchFirst(ParseExpression):
maxExcLoc = len(instring)
if maxException is not None:
- if maxException.msg == self.exprs[0].errmsg:
+ # infer from this check that all alternatives failed at the current position
+ # so emit this collective error message instead of any individual error message
+ if maxExcLoc == loc:
maxException.msg = self.errmsg
raise maxException
else: