diff --git a/CHANGES b/CHANGES index 97e50f6b..663ac9f7 100644 --- a/CHANGES +++ b/CHANGES @@ -7,6 +7,10 @@ Version 3.0.7 - - Fixed bug #345, in which delimitedList changed expressions in place using expr.streamline(). Reported by Kim Gräsman, thanks! +- Fixed bug #346, when a string of word characters was passed to WordStart + or WordEnd instead of just taking the default value. Originally posted + as a question by Parag on StackOverflow, good catch! + - Added optional "min" and "max" arguments to `delimited_list`. PR submitted by Marius, thanks! diff --git a/pyparsing/__init__.py b/pyparsing/__init__.py index 7b5bb1df..0474e8d1 100644 --- a/pyparsing/__init__.py +++ b/pyparsing/__init__.py @@ -126,7 +126,7 @@ def __repr__(self): __version_info__ = version_info(3, 0, 7, "final", 0) -__version_time__ = "15 Dec 2021 05:56 UTC" +__version_time__ = "18 Dec 2021 23:16 UTC" __version__ = __version_info__.__version__ __versionTime__ = __version_time__ __author__ = "Paul McGuire " diff --git a/pyparsing/core.py b/pyparsing/core.py index c2c8eef9..95714999 100644 --- a/pyparsing/core.py +++ b/pyparsing/core.py @@ -3521,7 +3521,7 @@ class WordStart(PositionToken): """ def __init__(self, word_chars: str = printables, *, wordChars: str = printables): - wordChars = word_chars if wordChars != printables else wordChars + wordChars = word_chars if wordChars == printables else wordChars super().__init__() self.wordChars = set(wordChars) self.errmsg = "Not at the start of a word" @@ -3546,7 +3546,7 @@ class WordEnd(PositionToken): """ def __init__(self, word_chars: str = printables, *, wordChars: str = printables): - wordChars = word_chars if wordChars != printables else wordChars + wordChars = word_chars if wordChars == printables else wordChars super().__init__() self.wordChars = set(wordChars) self.skipWhitespace = False diff --git a/tests/test_unit.py b/tests/test_unit.py index 0d957f1b..1da1a638 100644 --- a/tests/test_unit.py +++ b/tests/test_unit.py @@ -4913,6 +4913,24 @@ def testWordBoundaryExpressions(self): ), ) + def testWordBoundaryExpressions2(self): + from itertools import product + ws1 = pp.WordStart(pp.alphas) + ws2 = pp.WordStart(wordChars=pp.alphas) + ws3 = pp.WordStart(word_chars=pp.alphas) + we1 = pp.WordEnd(pp.alphas) + we2 = pp.WordEnd(wordChars=pp.alphas) + we3 = pp.WordEnd(word_chars=pp.alphas) + + for i, (ws, we) in enumerate(product((ws1, ws2, ws3), (we1, we2, we3))): + try: + expr = ("(" + ws + pp.Word(pp.alphas) + we + ")") + expr.parseString("(abc)") + except pp.ParseException as pe: + self.fail(f"Test {i} failed: {pe}") + else: + pass + def testRequiredEach(self): parser = pp.Keyword("bam") & pp.Keyword("boo")