Skip to content

Commit

Permalink
Fixed PEP-8 compatibility logic in WordStart and WordEnd (Issue #346)
Browse files Browse the repository at this point in the history
  • Loading branch information
ptmcg committed Dec 18, 2021
1 parent 3a12ded commit 5e3e1bb
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 3 deletions.
4 changes: 4 additions & 0 deletions CHANGES
Expand Up @@ -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!

Expand Down
2 changes: 1 addition & 1 deletion pyparsing/__init__.py
Expand Up @@ -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 <ptmcg.gm+pyparsing@gmail.com>"
Expand Down
4 changes: 2 additions & 2 deletions pyparsing/core.py
Expand Up @@ -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"
Expand All @@ -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
Expand Down
18 changes: 18 additions & 0 deletions tests/test_unit.py
Expand Up @@ -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")
Expand Down

0 comments on commit 5e3e1bb

Please sign in to comment.