diff --git a/hy/compiler.py b/hy/compiler.py index bf7e136..e1c7e56 100644 --- a/hy/compiler.py +++ b/hy/compiler.py @@ -22,6 +22,7 @@ from hy.errors import HyError from hy.models.expression import HyExpression from hy.models.integer import HyInteger +from hy.models.lambdalist import HyLambdaListKeyword from hy.models.string import HyString from hy.models.symbol import HySymbol from hy.models.list import HyList @@ -80,6 +81,10 @@ class HyASTCompiler(object): ret.reverse() return ret + def _parse_lambda_list(self, exprs): + """ Return args, keywords, starargs, kwargs from exprs.""" + return [self.compile(expr) for expr in exprs], [], None, None + @builds(list) def compile_raw_list(self, entries): return [self.compile(x) for x in entries] @@ -481,11 +486,13 @@ class HyASTCompiler(object): if expression[0].startswith("."): return self.compile_dotted_expression(expression) + args, keywords, starargs, kwargs = self._parse_lambda_list(expression[1:]) + return ast.Call(func=self.compile(fn), - args=[self.compile(x) for x in expression[1:]], - keywords=[], - starargs=None, - kwargs=None, + args=args, + keywords=keywords, + starargs=starargs, + kwargs=kwargs, lineno=expression.start_line, col_offset=expression.start_column) diff --git a/tests/compilers/test_ast.py b/tests/compilers/test_ast.py index fafcbcf..d3e9d51 100644 --- a/tests/compilers/test_ast.py +++ b/tests/compilers/test_ast.py @@ -101,3 +101,8 @@ def test_ast_tuple(): """ Ensure tuples work. """ code = hy_compile(tokenize("(, 1 2 3)")).body[0].value assert type(code) == ast.Tuple + + +def test_lambda_list_keywords_rest(): + code = hy_compile(tokenize("(defun foo (x &rest xs))")) + assert False == True