-
Notifications
You must be signed in to change notification settings - Fork 62
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
STOP/SKIP raise StopGlom(), ContinueGlom()? #156
Comments
I think the names'd be like |
yup, 100% these should have the same semantics as BadSpec -- if they are uncaught that is like having a break outside of a loop in python; syntax error |
(Note that, for the moment, it's possible for BadSpec to come at runtime.
glompilation may change that, but BadSpec may remain a combination
runtime/compiletime thing.)
…On Tue, Jun 30, 2020 at 12:59 PM Kurt Rose ***@***.***> wrote:
yup, 100%
these should have the same semantics as BadSpec -- if they are uncaught
that is like having a break outside of a loop in python; syntax error
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
<#156 (comment)>, or
unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAA7ZEKT55BPWARAJKJQTNLRZI725ANCNFSM4OKIJGMQ>
.
|
this may also dovetail into "breadcrumbs" / branching if we want SKIP and STOP to be handled more centrally by so you could imagine: def _glom(spec, target, scope):
result = spec.glomit(target, scope)
if iterable(result):
def result_stream():
while 1: # assuming underlying StopIteration just bubbles up
try:
yield result.next()
except GlomContinue:
pass
state = spec.blank()
try:
for item in result_stream():
spec.add(state, item)
except GlomBreak:
pass
return state |
or maybe it could just be a helper function for iterable-specs; basically catch Continue "inside the loop", catch Break "outside the loop" that code pattern is worth abstracting, and by re-using it all over the place we can get broadly compatible / similar behaviors |
the most useful pattern of "SKIP as value" is things like one alternative to this would be if default used a new basically |
rather than scanning one level for STOP and SKIP literals, should instead STOP and SKIP have a glomit() which raises StopGlom() and ContinueGlom()?
then, specs for which these make sense can do try/except (StopGlom) within their own glomit()
this gives similar behavior to
break
andcontinue
keywords in python that they rise to the closest enclosing loop, and it is an error if there is no enclosing loopThe text was updated successfully, but these errors were encountered: