Ejemplo n.º 1
0
def test_no_assoc_precedence():
    scope = Scope()
    op = '=='
    slurp = [
        'w', (op, op, 4, 'none'), 'x', ('*', '*', 7, 'left'), 'y',
        (op, op, 4, 'none'), 'z'
    ]
    pos, ast = scope.parse_binary_subexpr(slurp, slurp[0])
    assert ast == ASTCall('==',
                          List(['w', ASTCall('*', List(['x', 'y'])), 'z']))
Ejemplo n.º 2
0
def test_precedence():
    scope = Scope()
    slurp = [
        'w', ('+', '+', 6, 'left'), 'x', ('*', '*', 7, 'left'), 'y',
        ('+', '+', 6, 'left'), 'z'
    ]
    pos, ast = scope.parse_binary_subexpr(slurp, slurp[0])
    assert ast == ASTCall(
        '+',
        List([ASTCall('+', List(['w', ASTCall('*', List(['x', 'y']))])), 'z']))
Ejemplo n.º 3
0
def test_right():
    scope = Scope()
    slurp = [
        'w', ('^', '^', 6, 'right'), 'x', ('^', '^', 6, 'right'), 'y',
        ('^', '^', 6, 'right'), 'z'
    ]
    pos, ast = scope.parse_binary_subexpr(slurp, slurp[0])
    assert ast == ASTCall(
        '^',
        List(['w',
              ASTCall('^', List(['x', ASTCall('^', List(['y', 'z']))]))]))
Ejemplo n.º 4
0
def test_multi_no_assoc():
    scope = Scope()
    op = '=='
    slurp = [
        'w', (op, op, 4, 'none'), 'x', ('!=', '!=', 4, 'none'), 'y',
        (op, op, 4, 'none'), 'z'
    ]
    pos, ast = scope.parse_binary_subexpr(slurp, slurp[0])
    assert ast == ASTCall(
        '==',
        List(
            [ASTCall('!=', List([ASTCall('==', List(['w', 'x'])), 'y'])),
             'z']))
Ejemplo n.º 5
0
def test_no_assoc_single():
    scope = Scope()
    op = '=='
    slurp = ['w', (op, op, 4, 'none'), 'x']
    pos, ast = scope.parse_binary_subexpr(slurp, slurp[0])
    assert ast == ASTCall('==', List(['w', 'x']))
Ejemplo n.º 6
0
def test_simple():
    scope = Scope()
    slurp = ['x', ('+', '+', 6, 'left'), 'y']
    pos, ast = scope.parse_binary_subexpr(slurp, slurp[0])
    assert ast == ASTCall('+', List(['x', 'y']))