From 4f856c35d4d0547eeeabbac4befb6f3bc72c1f5b Mon Sep 17 00:00:00 2001 From: "Paul R. Tagliamonte" Date: Sat, 9 Mar 2013 22:04:38 -0500 Subject: [PATCH] adding in dotted notation --- hy/compiler.py | 25 +++++++++++++++++++++++++ tests/native_tests/language.hy | 5 +++++ 2 files changed, 30 insertions(+) diff --git a/hy/compiler.py b/hy/compiler.py index cd915bb..3ae31c8 100644 --- a/hy/compiler.py +++ b/hy/compiler.py @@ -248,6 +248,28 @@ class HyASTCompiler(object): left = calc return calc + def compile_dotted_expression(self, expr): + ofn = expr.pop(0) # .join + + fn = HySymbol(ofn[1:]) + fn.replace(ofn) + + obj = expr.pop(0) # [1 2 3 4] + + return ast.Call( + func=ast.Attribute( + lineno=expr.start_line, + col_offset=expr.start_column, + value=self.compile(obj), + attr=str(fn), + ctx=ast.Load()), + args=[self.compile(x) for x in expr], + keywords=[], + lineno=expr.start_line, + col_offset=expr.start_column, + starargs=None, + kwargs=None) + @builds(HyExpression) def compile_expression(self, expression): fn = expression[0] @@ -255,6 +277,9 @@ class HyASTCompiler(object): if fn in _compile_table: return _compile_table[fn](self, expression) + if expression[0].startswith("."): + return self.compile_dotted_expression(expression) + return ast.Call(func=self.compile(fn), args=[self.compile(x) for x in expression[1:]], keywords=[], diff --git a/tests/native_tests/language.hy b/tests/native_tests/language.hy index f531c70..f8b676f 100644 --- a/tests/native_tests/language.hy +++ b/tests/native_tests/language.hy @@ -109,3 +109,8 @@ (defn test-kwargs [] "NATIVE: test kwargs things." (assert (= (kwapply (kwtest) {"one" "two"}) {"one" "two"}))) + + +(defn test-dotted [] + "NATIVE: test dotted invocation" + (assert (= (.join " " ["one" "two"]) "one two")))