Exemple #1
0
def test_aspattern1():
    x = aparse('x')

    a0 = dslparse('b: f(a@x) -> a')
    v = free(a0[0].lhs)

    assert list(v) == [
        (x, 'a', ast.aterm)
    ]
Exemple #2
0
def test_aspattern3():
    a0 = dslparse('b: a@f(x,y) -> a')
    v = free(a0[0].lhs)

    f = aparse('f(x,y)')

    assert list(v) == [
        (f, 'a', ast.aappl)
    ]
Exemple #3
0
def test_rule3():
    rule = dslparse('b: @a(x,y) -> F(a,y,x)')
    l = rule[0].lhs
    r = rule[0].rhs

    rr = build_rule(l,r)

    sub = aparse('f(1,2)')
    res = aparse('F(f,2,1)')
    assert rr(sub) == res
Exemple #4
0
def test_rule2():
    rule = dslparse('b: a@f(x,y) -> g(a,a(a))')
    l = rule[0].lhs
    r = rule[0].rhs

    rr = build_rule(l,r)

    sub = aparse('f(1,2)')
    res = aparse('g(f(1, 2), a(f(1, 2)))')
    assert rr(sub) == res
Exemple #5
0
def test_rule1():
    rule = dslparse('b: f(x,y) -> f(x,x,y,x,f(x,y))')
    l = rule[0].lhs
    r = rule[0].rhs

    rr = build_rule(l,r)

    sub = aparse('f(1,2)')
    res = aparse('f(1,1,2,1,f(1,2))')
    assert rr(sub) == res
Exemple #6
0
def test_rule5():
    rule = dslparse('b: f(x,g(y,z)) -> (x,y,z)')
    l = rule[0].lhs
    r = rule[0].rhs

    rr = build_rule(l,r)

    sub = aparse('f(1,g(2,3))')
    res = aparse('(1,2,3)')
    assert rr(sub) == res
Exemple #7
0
def test_aspattern2():
    a0 = dslparse('b: @f(x,y) -> a')
    v = free(a0[0].lhs)

    f = aparse('f')
    x = aparse('x')
    y = aparse('y')

    assert list(v) == [
        (f, 'f', ast.aterm),
        (x, 'x', ast.aterm),
        (y, 'y', ast.aterm)
    ]
Exemple #8
0
def test_rule4():
    rule = dslparse('b: f(x,x) -> x')
    l = rule[0].lhs
    r = rule[0].rhs

    rr = build_rule(l,r)

    sub = aparse('f(1,1)')
    res = aparse('1')
    assert rr(sub) == res

    with assert_raises(NoMatch):
        sub = aparse('f(1,2)')
        assert rr(sub) == res
Exemple #9
0
def test_patterns_parse():
    dslparse(patterns)
Exemple #10
0
def test_simple_parse():
    dslparse(simple)