def _compile_rule(rule_translation, rest):
test, binding_translations, ctx_update, branch_translation = \
rule_translation
if len(binding_translations) == 0:
body = branch_translation
else:
body_lambda = astx.make_Lambda(
(ctx_update[id][0]
for id in binding_translations.iterkeys()),
branch_translation)
body = astx.make_simple_Call(
body_lambda,
binding_translations.values())
if len(rest) == 0:
orelse = astx.expr_Raise_Exception_string("Match failure.")
else:
orelse = fn._compile_rule(rest[0], rest[1:])
return ast.IfExp(
test=test,
body=body,
orelse=orelse)
评论列表
文章目录