implmenting with
This commit is contained in:
parent
ed310197dd
commit
dd6a883060
@ -309,6 +309,33 @@ class HyASTCompiler(object):
|
|||||||
fn.decorator_list = [self.compile(x) for x in expr]
|
fn.decorator_list = [self.compile(x) for x in expr]
|
||||||
return fn
|
return fn
|
||||||
|
|
||||||
|
@builds("with")
|
||||||
|
def compile_with_expression(self, expr):
|
||||||
|
expr.pop(0) # with
|
||||||
|
return ast.With(context_expr=self.compile(expr.pop(0)),
|
||||||
|
lineno=expr.start_line,
|
||||||
|
col_offset=expr.start_column,
|
||||||
|
optional_vars=None,
|
||||||
|
body=self._mangle_branch([
|
||||||
|
self.compile(x) for x in expr]))
|
||||||
|
|
||||||
|
@builds("with_as")
|
||||||
|
def compile_with_as_expression(self, expr):
|
||||||
|
expr.pop(0) # with-as
|
||||||
|
ctx = self.compile(expr.pop(0))
|
||||||
|
thing = self.compile(expr.pop(0))
|
||||||
|
thing.ctx = ast.Store()
|
||||||
|
|
||||||
|
# Module(body=[With(items=[withitem(context_expr=Name(id='foo', ctx=Load()), optional_vars=Name(id='e', ctx=Store()))], body=[Pass()])])
|
||||||
|
# Module(body=[With(context_expr=Name(id='foo', ctx=Load()), optional_vars=Name(id='e', ctx=Store()), body=[Pass()])])
|
||||||
|
|
||||||
|
return ast.With(context_expr=ctx,
|
||||||
|
lineno=expr.start_line,
|
||||||
|
col_offset=expr.start_column,
|
||||||
|
optional_vars=thing,
|
||||||
|
body=self._mangle_branch([
|
||||||
|
self.compile(x) for x in expr]))
|
||||||
|
|
||||||
@builds("kwapply")
|
@builds("kwapply")
|
||||||
def compile_kwapply_expression(self, expr):
|
def compile_kwapply_expression(self, expr):
|
||||||
expr.pop(0) # kwapply
|
expr.pop(0) # kwapply
|
||||||
|
@ -194,3 +194,11 @@
|
|||||||
(defn test-importas []
|
(defn test-importas []
|
||||||
"NATIVE: test import as"
|
"NATIVE: test import as"
|
||||||
(assert (!= (len systest.path) 0)))
|
(assert (!= (len systest.path) 0)))
|
||||||
|
|
||||||
|
|
||||||
|
(defn test-context []
|
||||||
|
"NATIVE: test with"
|
||||||
|
(with (open "README.md" "r")
|
||||||
|
(pass))
|
||||||
|
(with-as (open "README.md" "r") fd
|
||||||
|
(pass)))
|
||||||
|
Loading…
x
Reference in New Issue
Block a user