summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMax Fischer <maxfischer2781@gmail.com>2021-06-23 11:58:06 +0200
committerMax Fischer <maxfischer2781@gmail.com>2021-06-23 11:58:06 +0200
commit06dc2c27ef9cab24210c65eea6aa908537c42a3a (patch)
tree612ee255a8b5e2c726d396956a037ea1e0495790
parent76450307bbd0885b7b5707759c1c27cf16a0b43d (diff)
downloadpyparsing-git-06dc2c27ef9cab24210c65eea6aa908537c42a3a.tar.gz
simplified replacement logic
-rw-r--r--pyparsing/core.py10
1 files changed, 2 insertions, 8 deletions
diff --git a/pyparsing/core.py b/pyparsing/core.py
index a42a835..eba349a 100644
--- a/pyparsing/core.py
+++ b/pyparsing/core.py
@@ -4463,14 +4463,10 @@ class Forward(ParseElementEnhance):
return prev_loc, prev_result.copy()
except KeyError:
# we are searching for the best result – keep on improving
- prev_loc, prev_result = memo[key] = loc, ParseException(
+ prev_loc, prev_result = memo[key] = loc - 1, ParseException(
instring, loc, "Forward recursion without base case", self
)
while True:
- # Note:
- # Medeiros et al. settles on the *previous* result when there is
- # no improvement. Since we can have viable zero-length content
- # (due to parse actions) we use the *newest* result if possible.
try:
new_loc, new_result = super().parseImpl(instring, loc, doActions)
except ParseException:
@@ -4479,9 +4475,7 @@ class Forward(ParseElementEnhance):
raise
new_loc, new_result = prev_loc, prev_result
# the match did not get better: we are done
- if new_loc == prev_loc:
- return new_loc, new_result
- elif new_loc < prev_loc:
+ if new_loc <= prev_loc:
return prev_loc, prev_result
# the match did get better: see if we can improve further
else: