Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions construct/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -2633,6 +2633,32 @@ def _sizeof(self, context, path):
def _emitfulltype(self, ksy, bitwise):
return dict(type=self.subcon._compileprimitivetype(ksy, bitwise), repeat="eos")

def _emitparse(self, code):
fname = f"parse_greedyrange_{code.allocateId()}"
work_item = {False: f"yield {self.subcon._compileparse(code)}",
True: f"{self.subcon._compileparse(code)}"}[self.discard]
block = f"""
def {fname}(io, this):
try:
while True:
fallback = io.tell()
{work_item}
except StopFieldError:
pass
except ExplicitError:
raise
except Exception:
io.seek(fallback)
"""
code.append(block)
if False == self.discard:
return f"ListContainer({fname}(io, this))"
else:
return f"({fname}(io, this), ListContainer())[1]"

def _emitbuild(self, code):
return f"ListContainer([{self.subcon._compilebuild(code)} for obj in iter(obj)])"


class RepeatUntil(Subconstruct):
r"""
Expand Down