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
|
return ret
|
||||||
|
|
||||||
def _parse_lambda_list(self, exprs):
|
def _parse_lambda_list(self, exprs):
|
||||||
""" Return args, keywords, starargs, kwargs from exprs."""
|
""" Return args, keywords, varargs, kwargs from exprs."""
|
||||||
exprs.reverse()
|
exprs.reverse()
|
||||||
args = []
|
args = []
|
||||||
keywords = []
|
keywords = []
|
||||||
starargs = None
|
varargs = None
|
||||||
kwargs = {}
|
kwargs = {}
|
||||||
lambda_keyword = None
|
lambda_keyword = None
|
||||||
|
|
||||||
@ -191,7 +191,6 @@ class HyASTCompiler(object):
|
|||||||
raise HyCompileError("{0} is not a valid "
|
raise HyCompileError("{0} is not a valid "
|
||||||
"lambda-keyword.".format(repr(expr)))
|
"lambda-keyword.".format(repr(expr)))
|
||||||
if expr == "&rest" and lambda_keyword is None:
|
if expr == "&rest" and lambda_keyword is None:
|
||||||
print("Found &rest")
|
|
||||||
lambda_keyword = expr
|
lambda_keyword = expr
|
||||||
elif expr == "&optional" and lambda_keyword == "&rest":
|
elif expr == "&optional" and lambda_keyword == "&rest":
|
||||||
lambda_keyword = expr
|
lambda_keyword = expr
|
||||||
@ -207,11 +206,10 @@ class HyASTCompiler(object):
|
|||||||
if lambda_keyword is None:
|
if lambda_keyword is None:
|
||||||
args.append(expr)
|
args.append(expr)
|
||||||
elif lambda_keyword == "&rest":
|
elif lambda_keyword == "&rest":
|
||||||
print("The keyword is &rest, the expr is {0}".format(expr))
|
if varargs:
|
||||||
if starargs:
|
|
||||||
raise HyCompileError("There can only be one "
|
raise HyCompileError("There can only be one "
|
||||||
"&rest argument")
|
"&rest argument")
|
||||||
starargs = str(expr)
|
varargs = 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
|
||||||
@ -221,7 +219,7 @@ class HyASTCompiler(object):
|
|||||||
|
|
||||||
if not kwargs:
|
if not kwargs:
|
||||||
kwargs = None
|
kwargs = None
|
||||||
return args, keywords, starargs, kwargs
|
return args, keywords, varargs, kwargs
|
||||||
|
|
||||||
@builds(list)
|
@builds(list)
|
||||||
def compile_raw_list(self, entries):
|
def compile_raw_list(self, entries):
|
||||||
|
@ -167,7 +167,7 @@ class ListeyThing(State):
|
|||||||
return Idle
|
return Idle
|
||||||
|
|
||||||
if char in ")]}":
|
if char in ")]}":
|
||||||
raise LexException("Unexpected closing character: `%s'" % (char))
|
raise LexException("Unexpected closing character: `{0}'".format(char))
|
||||||
|
|
||||||
if char in WHITESPACE:
|
if char in WHITESPACE:
|
||||||
self.commit()
|
self.commit()
|
||||||
@ -248,7 +248,7 @@ class String(State):
|
|||||||
self.nodes.append("\"")
|
self.nodes.append("\"")
|
||||||
return
|
return
|
||||||
|
|
||||||
raise LexException("Unknown modifier: `%s'" % (char))
|
raise LexException("Unknown modifier: `{0}'".format(char))
|
||||||
|
|
||||||
if char == "\"":
|
if char == "\"":
|
||||||
return Idle
|
return Idle
|
||||||
@ -292,7 +292,7 @@ class Idle(State):
|
|||||||
if char in WHITESPACE:
|
if char in WHITESPACE:
|
||||||
return
|
return
|
||||||
|
|
||||||
raise LexException("Unknown char (Idle state): `%s`" % (char))
|
raise LexException("Unknown char (Idle state): `{0}`".format(char))
|
||||||
|
|
||||||
|
|
||||||
class Comment(State):
|
class Comment(State):
|
||||||
@ -327,4 +327,4 @@ class Hash(State):
|
|||||||
if char == "!":
|
if char == "!":
|
||||||
return Comment
|
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
|
assert type(code) == ast.Tuple
|
||||||
|
|
||||||
|
|
||||||
def test_lambda_list_keywords_rest():
|
def test_lambda_list_keywords():
|
||||||
src = ("(defun foo (x &rest xs) (print xs))\n"
|
""" Ensure we can compile functions with lambda list keywords."""
|
||||||
"(foo 1 2 3 4 5)")
|
hy_compile(tokenize("(fn (x &rest xs) (print xs))"))
|
||||||
code = hy_compile(tokenize(src))
|
cant_compile("(fn (x &rest xs &rest ys) (print xs))")
|
||||||
print(dump(code))
|
|
||||||
assert False
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user