Got &rest working, tests pass
Did a little house cleaning in lex states.py too and started removing stupid print() statements.
This commit is contained in:
parent
484a96abae
commit
9ff3b128b4
@ -175,11 +175,11 @@ class HyASTCompiler(object):
|
||||
return ret
|
||||
|
||||
def _parse_lambda_list(self, exprs):
|
||||
""" Return args, keywords, starargs, kwargs from exprs."""
|
||||
""" Return args, keywords, varargs, kwargs from exprs."""
|
||||
exprs.reverse()
|
||||
args = []
|
||||
keywords = []
|
||||
starargs = None
|
||||
varargs = None
|
||||
kwargs = {}
|
||||
lambda_keyword = None
|
||||
|
||||
@ -191,7 +191,6 @@ class HyASTCompiler(object):
|
||||
raise HyCompileError("{0} is not a valid "
|
||||
"lambda-keyword.".format(repr(expr)))
|
||||
if expr == "&rest" and lambda_keyword is None:
|
||||
print("Found &rest")
|
||||
lambda_keyword = expr
|
||||
elif expr == "&optional" and lambda_keyword == "&rest":
|
||||
lambda_keyword = expr
|
||||
@ -207,11 +206,10 @@ class HyASTCompiler(object):
|
||||
if lambda_keyword is None:
|
||||
args.append(expr)
|
||||
elif lambda_keyword == "&rest":
|
||||
print("The keyword is &rest, the expr is {0}".format(expr))
|
||||
if starargs:
|
||||
if varargs:
|
||||
raise HyCompileError("There can only be one "
|
||||
"&rest argument")
|
||||
starargs = str(expr)
|
||||
varargs = str(expr)
|
||||
elif lambda_keyword == "&optional":
|
||||
# add key to keywords and kwargs, value to kwargs? Look up AST docs you dummy.
|
||||
pass
|
||||
@ -221,7 +219,7 @@ class HyASTCompiler(object):
|
||||
|
||||
if not kwargs:
|
||||
kwargs = None
|
||||
return args, keywords, starargs, kwargs
|
||||
return args, keywords, varargs, kwargs
|
||||
|
||||
@builds(list)
|
||||
def compile_raw_list(self, entries):
|
||||
|
@ -167,7 +167,7 @@ class ListeyThing(State):
|
||||
return Idle
|
||||
|
||||
if char in ")]}":
|
||||
raise LexException("Unexpected closing character: `%s'" % (char))
|
||||
raise LexException("Unexpected closing character: `{0}'".format(char))
|
||||
|
||||
if char in WHITESPACE:
|
||||
self.commit()
|
||||
@ -248,7 +248,7 @@ class String(State):
|
||||
self.nodes.append("\"")
|
||||
return
|
||||
|
||||
raise LexException("Unknown modifier: `%s'" % (char))
|
||||
raise LexException("Unknown modifier: `{0}'".format(char))
|
||||
|
||||
if char == "\"":
|
||||
return Idle
|
||||
@ -292,7 +292,7 @@ class Idle(State):
|
||||
if char in WHITESPACE:
|
||||
return
|
||||
|
||||
raise LexException("Unknown char (Idle state): `%s`" % (char))
|
||||
raise LexException("Unknown char (Idle state): `{0}`".format(char))
|
||||
|
||||
|
||||
class Comment(State):
|
||||
@ -327,4 +327,4 @@ class Hash(State):
|
||||
if char == "!":
|
||||
return Comment
|
||||
|
||||
raise LexException("Unknown char (Hash state): `%s`" % (char))
|
||||
raise LexException("Unknown char (Hash state): `{0}'".format(char))
|
||||
|
@ -328,9 +328,7 @@ def test_ast_tuple():
|
||||
assert type(code) == ast.Tuple
|
||||
|
||||
|
||||
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(dump(code))
|
||||
assert False
|
||||
def test_lambda_list_keywords():
|
||||
""" Ensure we can compile functions with lambda list keywords."""
|
||||
hy_compile(tokenize("(fn (x &rest xs) (print xs))"))
|
||||
cant_compile("(fn (x &rest xs &rest ys) (print xs))")
|
||||
|
Loading…
Reference in New Issue
Block a user