some style fixes for @algernon

This commit is contained in:
Paul R. Tagliamonte 2013-04-14 21:54:15 -04:00
parent a5a54fc7eb
commit da33f41753

View File

@ -464,13 +464,15 @@ class HyASTCompiler(object):
@builds("import") @builds("import")
def compile_import_expression(self, expr): def compile_import_expression(self, expr):
def _compile_import(expr, module, names = None, importer = ast.Import): def _compile_import(expr, module, names=None, importer=ast.Import):
return [ return [
importer( importer(
lineno=expr.start_line, lineno=expr.start_line,
col_offset=expr.start_column, col_offset=expr.start_column,
module=ast_str(module), module=ast_str(module),
names=names or [ast.alias(name=ast_str(module), asname=None)], names=names or [
ast.alias(name=ast_str(module), asname=None)
],
level=0) level=0)
] ]
@ -479,31 +481,51 @@ class HyASTCompiler(object):
while len(expr) > 0: while len(expr) > 0:
iexpr = expr.pop(0) iexpr = expr.pop(0)
if type(iexpr) == HySymbol: if isinstance(iexpr, HySymbol):
rimports += _compile_import(expr, iexpr) rimports += _compile_import(expr, iexpr)
elif type(iexpr) == HyList and len(iexpr) == 1: continue
if isinstance(iexpr, HyList) and len(iexpr) == 1:
rimports += _compile_import(expr, iexpr.pop(0)) rimports += _compile_import(expr, iexpr.pop(0))
elif type(iexpr) == HyList: continue
if isinstance(iexpr, HyList) and iexpr:
module = iexpr.pop(0) module = iexpr.pop(0)
if type(iexpr[0]) == HyKeyword and iexpr[0] == HyKeyword(":as"): entry = iexpr[0]
if isinstance(entry, HyKeyword) and entry == HyKeyword(":as"):
assert len(iexpr) == 2, "garbage after aliased import" assert len(iexpr) == 2, "garbage after aliased import"
iexpr.pop(0) # :as iexpr.pop(0) # :as
alias=iexpr.pop(0) alias = iexpr.pop(0)
rimports += _compile_import(expr, ast_str(module), rimports += _compile_import(
[ast.alias(name=ast_str(module), expr,
asname=ast_str(alias))]) ast_str(module),
elif type(iexpr[0] == HyList): [
symbol_list = iexpr.pop(0) ast.alias(name=ast_str(module),
asname=ast_str(alias))
]
)
continue
if isinstance(entry, HyList):
names = [] names = []
while len(symbol_list) > 0: while entry:
sym = symbol_list.pop(0) sym = entry.pop(0)
if len(symbol_list) > 0 and type(symbol_list[0]) == HyKeyword: if entry and isinstance(entry[0], HyKeyword):
symbol_list.pop(0) entry.pop(0)
alias = ast_str(symbol_list.pop(0)) alias = ast_str(entry.pop(0))
else: else:
alias = None alias = None
names += [ast.alias(name=ast_str(sym), asname=alias)] names += [
rimports += _compile_import(expr, module, names, ast.ImportFrom) ast.alias(name=ast_str(sym),
asname=alias)
]
rimports += _compile_import(expr, module,
names, ast.ImportFrom)
continue
raise TypeError("Unknown entry (`%s`) in the HyList" % (entry))
return rimports return rimports
@builds("import_as") @builds("import_as")