summaryrefslogtreecommitdiff
path: root/pyparsing/helpers.py
diff options
context:
space:
mode:
authorptmcg <ptmcg@austin.rr.com>2021-09-25 12:00:21 -0500
committerptmcg <ptmcg@austin.rr.com>2021-09-25 12:00:21 -0500
commit49add35c746ae91c662f68ca58b11f814a45ac8f (patch)
treed7d5a273adc399d988d2404a1f771e46a29e044b /pyparsing/helpers.py
parent66ec9e93dd1d07652d2c4a18ac7eb6afb95e8f8c (diff)
downloadpyparsing-git-49add35c746ae91c662f68ca58b11f814a45ac8f.tar.gz
Added start_line and end_line args to with_line_numbers, and more docstring
Diffstat (limited to 'pyparsing/helpers.py')
-rw-r--r--pyparsing/helpers.py13
1 files changed, 7 insertions, 6 deletions
diff --git a/pyparsing/helpers.py b/pyparsing/helpers.py
index 251092a..27d293a 100644
--- a/pyparsing/helpers.py
+++ b/pyparsing/helpers.py
@@ -992,23 +992,24 @@ class IndentedBlock(ParseElementEnhance):
def parseImpl(self, instring, loc, doActions=True):
# advance parse position to non-whitespace by using an Empty()
# this should be the column to be used for all subsequent indented lines
- loc = Empty().preParse(instring, loc)
+ anchor_loc = Empty().preParse(instring, loc)
# see if self.expr matches at the current location - if not it will raise an exception
# and no further work is necessary
- self.expr.try_parse(instring, loc, doActions)
+ self.expr.try_parse(instring, anchor_loc, doActions)
- indent_col = col(loc, instring)
+ indent_col = col(anchor_loc, instring)
peer_parse_action = match_only_at_col(indent_col)
- peer_expr = FollowedBy(self.expr).add_parse_action(peer_parse_action)
- inner_expr = Empty() + peer_expr.suppress() + self.expr
+ peer_detect_expr = Empty().add_parse_action(peer_parse_action)
+ inner_expr = Empty() + peer_detect_expr + self.expr
+ inner_expr.set_name(f"inner {hex(id(inner_expr))[-4:].upper()}@{indent_col}")
if self._recursive:
indent_parse_action = condition_as_parse_action(
lambda s, l, t, relative_to_col=indent_col: col(l, s) > relative_to_col
)
indent_expr = FollowedBy(self.expr).add_parse_action(indent_parse_action)
- inner_expr += Opt(indent_expr + self)
+ inner_expr += Opt(Group(indent_expr + self.copy()))
return OneOrMore(inner_expr).parseImpl(instring, loc, doActions)