From a0ea3ffb8f9f7bde6c7f28a8d4eb389c33c896de Mon Sep 17 00:00:00 2001 From: Paul Tagliamonte Date: Thu, 27 Dec 2012 23:08:26 -0500 Subject: [PATCH] adding dot-notation --- hy/compiler/ast27.py | 36 ++++++++++++++++++++++++++++++++++-- 1 file changed, 34 insertions(+), 2 deletions(-) diff --git a/hy/compiler/ast27.py b/hy/compiler/ast27.py index 3d8a42f..cab102b 100644 --- a/hy/compiler/ast27.py +++ b/hy/compiler/ast27.py @@ -135,6 +135,10 @@ class AST27Converter(object): "for": self._ast_for, "kwapply": self._ast_kwapply, } + + self.starts_with = { + ".": self._ast_dot_fnc + } self.in_fn = False def _def(self, node): @@ -150,6 +154,30 @@ class AST27Converter(object): ) return ret + def _ast_dot_fnc(self, node): + i = node.get_invocation() + fn = i['function'][1:] + args = i['args'] + attr = args.pop(0) + val = self.render(attr) + + a = [] + for arg in args: + a.append(self.render(arg)) + + return ast.Call( + func=ast.Attribute( + value=val, + attr=fn, + ctx=ast.Load() + ), + args=a, + keywords=[], + starargs=None, + kwargs=None + ) + + def _ast_kwapply(self, node): i = node.get_invocation() args = i['args'] @@ -174,8 +202,8 @@ class AST27Converter(object): body = body if isinstance(body, list) else [body] orel = [] - body = _adjust_body(body, do_ret=self.in_fn) - orel = _adjust_body(orel, do_ret=self.in_fn) + body = _adjust_body(body, do_ret=False) + orel = _adjust_body(orel, do_ret=False) return ast.While( test=test, @@ -306,6 +334,10 @@ class AST27Converter(object): if inv['function'] in self.native_cases: return self.native_cases[inv['function']](node) + for flag in self.starts_with: + if inv['function'].startswith(flag): + return self.starts_with[flag](node) + c = [] for child in node.get_children(): c.append(self.render(child))