From 7eed26f0c3825ae6e92c04cb1b0c4284c91dcf98 Mon Sep 17 00:00:00 2001 From: "Paul R. Tagliamonte" Date: Wed, 27 Mar 2013 20:09:11 -0400 Subject: [PATCH] Adding in tuples. Close #30. Ugly as hell. --- hy/compiler.py | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/hy/compiler.py b/hy/compiler.py index c2a4469..5cf37fe 100644 --- a/hy/compiler.py +++ b/hy/compiler.py @@ -314,6 +314,10 @@ class HyASTCompiler(object): expr.pop(0) # with-as ctx = self.compile(expr.pop(0)) thing = self.compile(expr.pop(0)) + if isinstance(thing, ast.Tuple): + for x in thing.elts: + x.ctx = ast.Store() + thing.ctx = ast.Store() ret = ast.With(context_expr=ctx, @@ -328,6 +332,14 @@ class HyASTCompiler(object): return ret + @builds(",") + def compile_tuple(self, expr): + expr.pop(0) + return ast.Tuple(elts=[self.compile(x) for x in expr], + lineno=expr.start_line, + col_offset=expr.start_column, + ctx=ast.Load()) + @builds("kwapply") def compile_kwapply_expression(self, expr): expr.pop(0) # kwapply @@ -456,6 +468,10 @@ class HyASTCompiler(object): return what name = self.compile(name) + if isinstance(name, ast.Tuple): + for x in name.elts: + x.ctx = ast.Store() + name.ctx = ast.Store() return ast.Assign( @@ -471,6 +487,11 @@ class HyASTCompiler(object): expression.pop(0) # for name, iterable = expression.pop(0) target = self.compile_symbol(name) + + if isinstance(target, ast.Tuple): + for x in target.elts: + x.ctx = ast.Store() + target.ctx = ast.Store() # support stuff like: # (for [x [1 2 3 4]