Hacking on some AST, I think.

This commit is contained in:
Paul Tagliamonte 2012-12-22 14:40:54 -05:00
parent ff1a97485b
commit cb0d6d45f9

View File

@ -2,6 +2,7 @@
import ast
from hy.lang.expression import HYExpression
from hy.lang.number import HYNumber
from hy.lang.string import HYString
from hy.lang.builtins import builtins
@ -23,8 +24,25 @@ def _ast_print(node, children):
)
def _ast_binop(node, children):
inv = node.get_invocation()
ops = {
"+": ast.Add
}
op = ops[inv['function']]
left = children.pop(0)
calc = None
for child in children:
calc = ast.BinOp(left=left, op=op(), right=child)
left = calc
return calc
special_cases = {
"print": _ast_print
"print": _ast_print,
"+": _ast_binop
}
@ -32,14 +50,15 @@ class AST27Converter(object):
def __init__(self):
self.table = {
HYString: self.render_string,
HYExpression: self.render_expression
HYExpression: self.render_expression,
HYNumber: self.render_number
}
def render_string(self, node):
return ast.Str(s=node)
def render_number(self, node):
pass
return ast.Num(n=node)
def render_expression(self, node):
c = []
@ -68,3 +87,4 @@ def forge_ast(name, forest):
statements.append(conv.render(tree))
print [ast.dump(x) for x in statements]
return ast.fix_missing_locations(ast.Module(body=statements))