adding in dotted notation
This commit is contained in:
parent
44f5035919
commit
4f856c35d4
@ -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=[],
|
||||
|
@ -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")))
|
||||
|
Loading…
Reference in New Issue
Block a user