global now takes multiple arguments.

This commit is contained in:
unmerged 2014-12-14 23:13:44 +03:00
parent 2bf723a5d1
commit cfa805c102
2 changed files with 15 additions and 6 deletions

View File

@ -1017,13 +1017,21 @@ class HyASTCompiler(object):
return ret
@builds("global")
@checkargs(1)
@checkargs(min=1)
def compile_global_expression(self, expr):
expr.pop(0) # global
e = expr.pop(0)
return ast.Global(names=[ast_str(e)],
lineno=e.start_line,
col_offset=e.start_column)
names = []
while len(expr) > 0:
identifier = expr.pop(0)
name = ast_str(identifier)
names.append(name)
if not isinstance(identifier, HySymbol):
raise HyTypeError(identifier, "(global) arguments must "
" be Symbols")
return ast.Global(names=names,
lineno=expr.start_line,
col_offset=expr.start_column)
@builds("yield")
@checkargs(max=1)

View File

@ -211,12 +211,13 @@ def test_ast_bad_assert():
def test_ast_good_global():
"Make sure AST can compile valid global"
can_compile("(global a)")
can_compile("(global foo bar)")
def test_ast_bad_global():
"Make sure AST can't compile invalid global"
cant_compile("(global)")
cant_compile("(global foo bar)")
cant_compile("(global (foo))")
def test_ast_good_defclass():