diff options
Diffstat (limited to 'pyparsing')
-rw-r--r-- | pyparsing/__init__.py | 2 | ||||
-rw-r--r-- | pyparsing/core.py | 5 | ||||
-rw-r--r-- | pyparsing/results.py | 29 |
3 files changed, 31 insertions, 5 deletions
diff --git a/pyparsing/__init__.py b/pyparsing/__init__.py index 9c128ce..22bc21f 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__ = "05 Mar 2023 06:11 UTC" +__version_time__ = "07 Mar 2023 01:33 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 9fbb6d0..71c2690 100644 --- a/pyparsing/core.py +++ b/pyparsing/core.py @@ -4147,7 +4147,7 @@ class Or(ParseExpression): raise max_fatal if maxException is not None: - maxException.msg = self.errmsg + # maxException.msg = self.errmsg raise maxException else: raise ParseException( @@ -4260,7 +4260,8 @@ class MatchFirst(ParseExpression): maxExcLoc = len(instring) if maxException is not None: - maxException.msg = self.errmsg + if maxException.msg == self.exprs[0].errmsg: + maxException.msg = self.errmsg raise maxException else: raise ParseException( diff --git a/pyparsing/results.py b/pyparsing/results.py index 5f4b62c..8c52a3a 100644 --- a/pyparsing/results.py +++ b/pyparsing/results.py @@ -1,5 +1,5 @@ # results.py -from collections.abc import MutableMapping, Mapping, MutableSequence, Iterator +from collections.abc import MutableMapping, Mapping, MutableSequence, Iterator, Sequence, Container import pprint from typing import Tuple, Any, Dict, Set, List @@ -539,7 +539,10 @@ class ParseResults: def copy(self) -> "ParseResults": """ - Returns a new copy of a :class:`ParseResults` object. + Returns a new shallow copy of a :class:`ParseResults` object. `ParseResults` + items contained within the source are shared with the copy. Use + :class:`ParseResults.deepcopy()` to create a copy with its own separate + content values. """ ret = ParseResults(self._toklist) ret._tokdict = self._tokdict.copy() @@ -548,6 +551,28 @@ class ParseResults: ret._name = self._name return ret + def deepcopy(self) -> "ParseResults": + """ + Returns a new deep copy of a :class:`ParseResults` object. + """ + ret = self.copy() + # replace values with copies if they are of known mutable types + for i, obj in enumerate(self._toklist): + if isinstance(obj, ParseResults): + self._toklist[i] = obj.deepcopy() + elif isinstance(obj, (str, bytes)): + pass + elif isinstance(obj, MutableMapping): + self._toklist[i] = dest = type(obj)() + for k, v in obj.items(): + dest[k] = v.deepcopy() if isinstance(v, ParseResults) else v + elif isinstance(obj, Container): + self._toklist[i] = type(obj)( + v.deepcopy() if isinstance(v, ParseResults) else v + for v in obj + ) + return ret + def get_name(self): r""" Returns the results name for this token expression. Useful when several |