Skip to content
This repository has been archived by the owner on Dec 8, 2022. It is now read-only.

"with" statement #29

Closed
arshajii opened this issue Jan 3, 2019 · 3 comments
Closed

"with" statement #29

arshajii opened this issue Jan 3, 2019 · 3 comments
Labels
Feature New language features

Comments

@arshajii
Copy link
Member

arshajii commented Jan 3, 2019

with can be transformed into try...finally at the compiler level:

with <expr> as v:
    <block>

can be converted to:

# new scope so `v` is not accessible outside `with` body
v = <expr>
v.__enter__()
try:
    <block>
finally:
    v.__exit__()

withs with multiple clauses can be converted to single-clause nested withs:

with <e1> as v1, <e2> as v2, ..., <eN> as vN:
    <block>

becomes

with <e1> as v1:
    with <e2> as v2:
        ...
            with <eN> as vN:
                <block>

before applying the preceding transformation.
@arshajii
Copy link
Member Author

arshajii commented Jan 3, 2019

Python's __exit__() also takes exception info -- we can think about how/if we want to support that as well.

@inumanag
Copy link
Collaborator

inumanag commented Jan 3, 2019

Real pythonic with requires nested try statements:
https://stackoverflow.com/questions/26096435/is-python-with-statement-exactly-equivalent-to-a-try-except-finally-bloc

I'd prefer postponing this until we have working nested try statements

@arshajii
Copy link
Member Author

Nested try-except is #34.

@arshajii arshajii added Parser Issues related to the lexer/parser Feature New language features and removed Parser Issues related to the lexer/parser labels Sep 5, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Feature New language features
Projects
None yet
Development

No branches or pull requests

2 participants