adding in dotted notation

This commit is contained in:
Paul R. Tagliamonte 2013-03-09 22:04:38 -05:00
parent 44f5035919
commit 4f856c35d4
2 changed files with 30 additions and 0 deletions

View File

@ -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=[],

View File

@ -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")))