WIP - Move _parse_lamba_list to the functiondef
This commit is contained in:
parent
160eaaa543
commit
484a96abae
@ -3,6 +3,8 @@ from __future__ import print_function
|
||||
|
||||
from hy.importer import (import_file_to_ast, import_file_to_module,
|
||||
import_file_to_hst)
|
||||
from hy.util import dump
|
||||
|
||||
#import astor.codegen
|
||||
import sys
|
||||
import ast
|
||||
@ -15,7 +17,7 @@ print("")
|
||||
_ast = import_file_to_ast(sys.argv[1])
|
||||
print("")
|
||||
print("")
|
||||
print(ast.dump(_ast))
|
||||
print(dump(_ast))
|
||||
print("")
|
||||
print("")
|
||||
#print(astor.codegen.to_source(_ast))
|
||||
|
@ -205,13 +205,13 @@ class HyASTCompiler(object):
|
||||
continue
|
||||
|
||||
if lambda_keyword is None:
|
||||
args.append(self.compile(expr))
|
||||
args.append(expr)
|
||||
elif lambda_keyword == "&rest":
|
||||
print("The keyword is &rest, the expr is {0}".format(expr))
|
||||
if starargs:
|
||||
raise HyCompileError("There can only be one "
|
||||
"&rest argument")
|
||||
starargs = self.compile(expr)
|
||||
starargs = str(expr)
|
||||
elif lambda_keyword == "&optional":
|
||||
# add key to keywords and kwargs, value to kwargs? Look up AST docs you dummy.
|
||||
pass
|
||||
@ -782,13 +782,11 @@ 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=args,
|
||||
keywords=keywords,
|
||||
starargs=starargs,
|
||||
kwargs=kwargs,
|
||||
args=[self.compile(x) for x in expression[1:]],
|
||||
keywords=[],
|
||||
starargs=None,
|
||||
kwargs=None,
|
||||
lineno=expression.start_line,
|
||||
col_offset=expression.start_column)
|
||||
|
||||
@ -887,8 +885,7 @@ class HyASTCompiler(object):
|
||||
expression.start_line,
|
||||
expression.start_column)
|
||||
|
||||
print("HELLO", sig)
|
||||
# TODO: Parse those args here
|
||||
args, keywords, stararg, kwargs = self._parse_lambda_list(sig)
|
||||
|
||||
ret = ast.FunctionDef(
|
||||
name=name,
|
||||
@ -901,8 +898,8 @@ class HyASTCompiler(object):
|
||||
ctx=ast.Param(),
|
||||
lineno=x.start_line,
|
||||
col_offset=x.start_column)
|
||||
for x in sig],
|
||||
vararg=None,
|
||||
for x in args],
|
||||
vararg=stararg,
|
||||
kwarg=None,
|
||||
kwonlyargs=[],
|
||||
kw_defaults=[],
|
||||
|
@ -21,6 +21,7 @@
|
||||
|
||||
from hy.compiler import hy_compile, HyCompileError
|
||||
from hy.lex import tokenize
|
||||
from hy.util import dump
|
||||
|
||||
import ast
|
||||
import sys
|
||||
@ -331,5 +332,5 @@ def test_lambda_list_keywords_rest():
|
||||
src = ("(defun foo (x &rest xs) (print xs))\n"
|
||||
"(foo 1 2 3 4 5)")
|
||||
code = hy_compile(tokenize(src))
|
||||
print(ast.dump(code))
|
||||
print(dump(code))
|
||||
assert False
|
||||
|
Loading…
Reference in New Issue
Block a user