diff options
-rw-r--r-- | CHANGES | 4 | ||||
-rw-r--r-- | pyparsing/__init__.py | 2 | ||||
-rw-r--r-- | pyparsing/core.py | 9 |
3 files changed, 12 insertions, 3 deletions
@@ -55,6 +55,10 @@ help from Devin J. Pohly in structuring the code to enable this peaceful transit `DelimitedList`. `delimited_list` and the older `delimitedList` method will be deprecated in a future release, in favor of `DelimitedList`. +- Error messages from `MatchFirst` and `Or` expressions will try to give more details + if one of the alternatives matches better than the others, but still fails. + Question raised in Issue #464 by msdemlei, thanks! + - Added new class method `ParserElement.using_each`, to simplify code that creates a sequence of `Literals`, `Keywords`, or other `ParserElement` subclasses. diff --git a/pyparsing/__init__.py b/pyparsing/__init__.py index 22bc21f..336041e 100644 --- a/pyparsing/__init__.py +++ b/pyparsing/__init__.py @@ -121,7 +121,7 @@ class version_info(NamedTuple): __version_info__ = version_info(3, 1, 0, "alpha", 1) -__version_time__ = "07 Mar 2023 01:33 UTC" +__version_time__ = "07 Mar 2023 06:50 UTC" __version__ = __version_info__.__version__ __versionTime__ = __version_time__ __author__ = "Paul McGuire <ptmcg.gm+pyparsing@gmail.com>" 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: |