From 952ba5811ed62c5079e7fd5789feaf2d431d2df8 Mon Sep 17 00:00:00 2001 From: Paul Tagliamonte Date: Sat, 22 Dec 2012 21:47:38 -0500 Subject: [PATCH] while loop --- hy/compiler/ast27.py | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/hy/compiler/ast27.py b/hy/compiler/ast27.py index 8c309e5..9ef0437 100644 --- a/hy/compiler/ast27.py +++ b/hy/compiler/ast27.py @@ -123,7 +123,10 @@ class AST27Converter(object): "def": self._def, "import": _ast_import, - "doseq": self._ast_for, "for": self._ast_for, + "while": self._ast_while, + + "doseq": self._ast_for, + "for": self._ast_for, } def _def(self, node): @@ -139,6 +142,22 @@ class AST27Converter(object): ) return ret + def _ast_while(self, node): + i = node.get_invocation() + args = i['args'] + test = args.pop(0) + test = self.render(test) + body = args.pop(0) + body = self.render(body) + body = body if isinstance(body, list) else [body] + + return ast.While( + test=test, + body=body, + orelse=[] + ) + + def _ast_for(self, node): i = node.get_invocation() args = i['args']