adding in forloop

This commit is contained in:
Paul Tagliamonte 2012-12-22 21:40:23 -05:00
parent c458fa6a37
commit 63a276692a

View File

@ -84,6 +84,7 @@ def _ast_return(node, children, obj):
return ast.Return(value=children[-1])
special_cases = {
"print": _ast_print,
@ -121,6 +122,8 @@ class AST27Converter(object):
"defn": self._defn,
"def": self._def,
"import": _ast_import,
"doseq": self._ast_for, "for": self._ast_for,
}
def _def(self, node):
@ -136,6 +139,23 @@ class AST27Converter(object):
)
return ret
def _ast_for(self, node):
i = node.get_invocation()
args = i['args']
sig = args.pop(0)
body = args.pop(0)
aname, seq = sig
body = self.render(body)
body = body if isinstance(body, list) else [body]
return ast.For(
target=ast.Name(id=str(aname), ctx=ast.Store()),
iter=self.render(seq),
body=body,
orelse=[]
)
def _defn(self, node):
""" For the defn operator """
inv = node.get_invocation()