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