コード例 #1
0
ファイル: asrl_rewrite.py プロジェクト: EvelynHf/basil
def test_asrl_unit (unit):
    asdl_file_name = unit.asdl_file
    asts_for_combination = []
    asts_for_tests = []
    for rwast in unit.rws:
        if rwast.label.startswith("test"):
            asts_for_tests.append(rwast)
        else:
            asts_for_combination.insert(0, rwast)
    rwcomb = id_combinator
    for rwast in asts_for_combination:
        rwcomb = compose_combinators(mk_rewrite_combinator(rwast),
                                     rwcomb)
    rwcomb = fixpt_combinator(rwcomb)
    # Build the base environment.
    base_env = {}
    base_env["asrlassert"] = asrl_utils.asrlassert
    # XXX
    for rwast in asts_for_tests:
        startobj = build(rwast.match, base_env)
        expectedobj = build(rwast.build, base_env)
        endobj, endenv = rwcomb(startobj, base_env)
        if __DEBUG__:
            print ("%s: %r => %r (expected %r)" %
                   ("PASS" if endobj == expectedobj else "FAIL",
                    startobj, endobj, expectedobj))
コード例 #2
0
ファイル: asrl_rewrite.py プロジェクト: EvelynHf/basil
def rewrite (asrl_ast, obj, env = None):
    assert isinstance(asrl_ast, ASRL.Rewrite)
    env = match(asrl_ast.match, obj, env)
    if asrl_ast.where_clause is not None:
        exec asrl_ast.where_clause in globals(), env
    return build(asrl_ast.build, env), env