summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaul McGuire <ptmcg@users.noreply.github.com>2020-07-30 22:12:00 -0500
committerPaul McGuire <ptmcg@users.noreply.github.com>2020-07-30 22:12:00 -0500
commit71e061efc2f3fed3dd7f69f280538ec79607da9f (patch)
tree4e871a5eeb638ad4869905894c5b33ed13afa62f
parentc1e365bfa036492222837f8c6372a3b818961823 (diff)
downloadpyparsing-git-71e061efc2f3fed3dd7f69f280538ec79607da9f.tar.gz
Better display of single-character Words
-rw-r--r--pyparsing/core.py5
-rw-r--r--tests/test_unit.py4
2 files changed, 8 insertions, 1 deletions
diff --git a/pyparsing/core.py b/pyparsing/core.py
index 008fb01..d865283 100644
--- a/pyparsing/core.py
+++ b/pyparsing/core.py
@@ -2282,7 +2282,10 @@ class Word(Token):
# add length specification
if self.minLen > 1 or self.maxLen != _MAX_INT:
if self.minLen == self.maxLen:
- return base + "{{{}}}".format(self.minLen)
+ if self.minLen == 1:
+ return base[2:]
+ else:
+ return base + "{{{}}}".format(self.minLen)
elif self.maxLen == _MAX_INT:
return base + "{{{},...}}".format(self.minLen)
else:
diff --git a/tests/test_unit.py b/tests/test_unit.py
index 19258dd..42a6c73 100644
--- a/tests/test_unit.py
+++ b/tests/test_unit.py
@@ -7953,6 +7953,10 @@ class Test2_WithoutPackrat(ppt.TestParseResultsAsserts, TestCase):
print(expr)
self.assertEqual("W:(0-9){2,3}", repr(expr))
+ expr = pp.Char(pp.nums)
+ print(expr)
+ self.assertEqual("(0-9)", repr(expr))
+
class Test3_EnablePackratParsing(TestCase):
def runTest(self):