summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMax Fischer <maxfischer2781@gmail.com>2021-06-26 20:30:56 +0200
committerMax Fischer <maxfischer2781@gmail.com>2021-06-26 20:30:56 +0200
commit3d4fc86116ecd1c47eaaab76531152a39007ac4e (patch)
treeaa40e99f411c75dc51f4bc0c2869116d61a0440d
parent6f6024fc653322d6c46e8ea51b359cf2a35e6161 (diff)
downloadpyparsing-git-3d4fc86116ecd1c47eaaab76531152a39007ac4e.tar.gz
cleanup
-rw-r--r--pyparsing/core.py2
-rw-r--r--tests/test_unit.py34
2 files changed, 17 insertions, 19 deletions
diff --git a/pyparsing/core.py b/pyparsing/core.py
index 98c707e..8a0f4dd 100644
--- a/pyparsing/core.py
+++ b/pyparsing/core.py
@@ -4492,8 +4492,6 @@ class Forward(ParseElementEnhance):
raise
prev_loc, prev_peek = memo[self, False] = new_loc, new_peek
-
-
def leaveWhitespace(self, recursive=True):
self.skipWhitespace = False
return self
diff --git a/tests/test_unit.py b/tests/test_unit.py
index 2609476..ba40392 100644
--- a/tests/test_unit.py
+++ b/tests/test_unit.py
@@ -1610,7 +1610,7 @@ class Test2_WithoutPackrat(ppt.TestParseResultsAsserts, TestCase):
def testRepeater(self):
if ParserElement._packratEnabled or ParserElement._left_recursion_enabled:
- print("skipping this test, not compatible with packratting")
+ print("skipping this test, not compatible with memoization")
return
first = pp.Word("abcdef").setName("word1")
@@ -1716,7 +1716,7 @@ class Test2_WithoutPackrat(ppt.TestParseResultsAsserts, TestCase):
"""test matchPreviousLiteral with empty repeater"""
if ParserElement._packratEnabled or ParserElement._left_recursion_enabled:
- print("skipping this test, not compatible with packratting")
+ print("skipping this test, not compatible with memoization")
return
first = pp.Optional(pp.Word("abcdef").setName("words1"))
@@ -1736,7 +1736,7 @@ class Test2_WithoutPackrat(ppt.TestParseResultsAsserts, TestCase):
"""test matchPreviousLiteral with multiple repeater tokens"""
if ParserElement._packratEnabled or ParserElement._left_recursion_enabled:
- print("skipping this test, not compatible with packratting")
+ print("skipping this test, not compatible with memoization")
return
first = pp.Word("a") + pp.Word("d")
@@ -1756,7 +1756,7 @@ class Test2_WithoutPackrat(ppt.TestParseResultsAsserts, TestCase):
"""test matchPreviousExpr with multiple repeater tokens"""
if ParserElement._packratEnabled or ParserElement._left_recursion_enabled:
- print("skipping this test, not compatible with packratting")
+ print("skipping this test, not compatible with memoization")
return
first = pp.Group(pp.Word(pp.alphas) + pp.Word(pp.alphas))
@@ -1783,7 +1783,7 @@ class Test2_WithoutPackrat(ppt.TestParseResultsAsserts, TestCase):
"""a simplified testRepeater4 to examine matchPreviousExpr with a single repeater token"""
if ParserElement._packratEnabled or ParserElement._left_recursion_enabled:
- print("skipping this test, not compatible with packratting")
+ print("skipping this test, not compatible with memoization")
return
first = pp.Word(pp.alphas)
@@ -8100,7 +8100,7 @@ class TestLR1_Recursion(ppt.TestParseResultsAsserts, TestCase):
def test_repeat_as_recurse(self):
"""repetition rules formulated with recursion"""
- one_or_more = pp.Forward("one_or_more")
+ one_or_more = pp.Forward()("one_or_more")
one_or_more <<= one_or_more + "a" | "a"
self.assertParseResultsEquals(
one_or_more.parseString("a"),
@@ -8110,7 +8110,7 @@ class TestLR1_Recursion(ppt.TestParseResultsAsserts, TestCase):
one_or_more.parseString("aaa aa"),
expected_list=["a", "a", "a", "a", "a"],
)
- delimited_list = pp.Forward("delimited_list")
+ delimited_list = pp.Forward()("delimited_list")
delimited_list <<= delimited_list + pp.Suppress(',') + "b" | "b"
self.assertParseResultsEquals(
delimited_list.parseString("b"),
@@ -8127,7 +8127,7 @@ class TestLR1_Recursion(ppt.TestParseResultsAsserts, TestCase):
def test_binary_recursive(self):
"""parsing of single left-recursive binary operator"""
- expr = pp.Forward("expr")
+ expr = pp.Forward()("expr")
num = pp.Word(pp.nums)
expr <<= expr + '+' - num | num
self.assertParseResultsEquals(
@@ -8141,7 +8141,7 @@ class TestLR1_Recursion(ppt.TestParseResultsAsserts, TestCase):
def test_binary_associative(self):
"""associative is preserved for single left-recursive binary operator"""
- expr = pp.Forward("expr")
+ expr = pp.Forward()("expr")
num = pp.Word(pp.nums)
expr <<= pp.Group(expr) + '+' - num | num
self.assertParseResultsEquals(
@@ -8155,7 +8155,7 @@ class TestLR1_Recursion(ppt.TestParseResultsAsserts, TestCase):
def test_add_sub(self):
"""indirectly left-recursive/associative add/sub calculator"""
- expr = pp.Forward("expr")
+ expr = pp.Forward()("expr")
num = pp.Word(pp.nums).setParseAction(lambda t: int(t[0]))
expr <<= (
(expr + '+' - num).setParseAction(lambda t: t[0] + t[2])
@@ -8171,11 +8171,11 @@ class TestLR1_Recursion(ppt.TestParseResultsAsserts, TestCase):
def test_math(self):
"""precedence climbing parser for math"""
# named references
- expr = pp.Forward("expr")
- add_sub = pp.Forward("add_sub")
- mul_div = pp.Forward("mul_div")
- power = pp.Forward("power")
- terminal = pp.Forward("terminal")
+ expr = pp.Forward()("expr")
+ add_sub = pp.Forward()("add_sub")
+ mul_div = pp.Forward()("mul_div")
+ power = pp.Forward()("power")
+ terminal = pp.Forward()("terminal")
# concrete rules
number = pp.Word(pp.nums).setParseAction(lambda t: int(t[0]))
signed = ('+' - expr) | ('-' - expr).setParseAction(lambda t: -t[1])
@@ -8216,13 +8216,13 @@ class TestLR1_Recursion(ppt.TestParseResultsAsserts, TestCase):
def test_terminate_empty(self):
"""Recursion with ``Empty`` terminates"""
- empty = pp.Forward('e')
+ empty = pp.Forward()('e')
empty <<= empty + pp.Empty() | pp.Empty()
self.assertParseResultsEquals(empty.parseString(""), expected_list=[])
def test_non_peg(self):
"""Recursion works for non-PEG operators"""
- expr = pp.Forward('expr')
+ expr = pp.Forward()('expr')
expr <<= expr + "a" ^ expr + "ab" ^ expr + "abc" ^ "."
self.assertParseResultsEquals(
expr.parseString(".abcabaabc"),