adding in dotted notation
This commit is contained in:
parent
44f5035919
commit
4f856c35d4
@ -248,6 +248,28 @@ class HyASTCompiler(object):
|
|||||||
left = calc
|
left = calc
|
||||||
return 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)
|
@builds(HyExpression)
|
||||||
def compile_expression(self, expression):
|
def compile_expression(self, expression):
|
||||||
fn = expression[0]
|
fn = expression[0]
|
||||||
@ -255,6 +277,9 @@ class HyASTCompiler(object):
|
|||||||
if fn in _compile_table:
|
if fn in _compile_table:
|
||||||
return _compile_table[fn](self, expression)
|
return _compile_table[fn](self, expression)
|
||||||
|
|
||||||
|
if expression[0].startswith("."):
|
||||||
|
return self.compile_dotted_expression(expression)
|
||||||
|
|
||||||
return ast.Call(func=self.compile(fn),
|
return ast.Call(func=self.compile(fn),
|
||||||
args=[self.compile(x) for x in expression[1:]],
|
args=[self.compile(x) for x in expression[1:]],
|
||||||
keywords=[],
|
keywords=[],
|
||||||
|
@ -109,3 +109,8 @@
|
|||||||
(defn test-kwargs []
|
(defn test-kwargs []
|
||||||
"NATIVE: test kwargs things."
|
"NATIVE: test kwargs things."
|
||||||
(assert (= (kwapply (kwtest) {"one" "two"}) {"one" "two"})))
|
(assert (= (kwapply (kwtest) {"one" "two"}) {"one" "two"})))
|
||||||
|
|
||||||
|
|
||||||
|
(defn test-dotted []
|
||||||
|
"NATIVE: test dotted invocation"
|
||||||
|
(assert (= (.join " " ["one" "two"]) "one two")))
|
||||||
|
Loading…
x
Reference in New Issue
Block a user