def test_parser():
    from pymbolic import parse
    parse('(2*a[1]*b[1]+2*a[0]*b[0])*(hankel_1(-1,sqrt(a[1]**2+a[0]**2)*k) -hankel_1(1,sqrt(a[1]**2+a[0]**2)*k))*k /(4*sqrt(a[1]**2+a[0]**2)) +hankel_1(0,sqrt(a[1]**2+a[0]**2)*k)')
    print(repr(parse('d4knl0')))
    print(repr(parse('0.')))
    print(repr(parse('0.e1')))
    assert (parse('0.e1') == 0)
    assert (parse('1e-12') == 1e-12)
    print(repr(parse('a >= 1')))
    print(repr(parse('a <= 1')))
    print(repr(parse(':')))
    print(repr(parse('1:')))
    print(repr(parse(':2')))
    print(repr(parse('1:2')))
    print(repr(parse('::')))
    print(repr(parse('0000:0000:0000:0000:0000:0000:0000:0000')))
    print(repr(parse(':1:')))
    print(repr(parse('::1')))
    print(repr(parse('0000:0000:0000:0000:0000:0000:0000:0000')))
    print(repr(parse(':5:1')))
    print(repr(parse('3:5:1')))
    assert_parse_roundtrip('()')
    assert_parse_roundtrip('(3,)')
    assert_parse_roundtrip('[x + 3, 3, 5]')
    assert_parse_roundtrip('[]')
    assert_parse_roundtrip('[x]')
    assert_parse_roundtrip('g[i, k] + 2.0*h[i, k]')
    parse('g[i,k]+(+2.0)*h[i, k]')
    print(repr(parse('a - b - c')))
    print(repr(parse('-a - -b - -c')))
    print(repr(parse('- - - a - - - - b - - - - - c')))
    print(repr(parse('~(a ^ b)')))
    print(repr(parse('(a | b) | ~(~a & ~b)')))
    print(repr(parse('3 << 1')))
    print(repr(parse('1 >> 3')))
    print(parse('0000:0000:0000:0000:0000:0000:0000:0000'))
    assert (parse('e1') == prim.Variable('e1'))
    assert (parse('d1') == prim.Variable('d1'))
    from pymbolic import variables
    (f, x, y, z) = variables('f x y z')
    assert (parse('f((x,y),z)') == f((x, y), z))
    assert (parse('f((x,),z)') == f((x,), z))
    assert (parse('f(x,(y,z),z)') == f(x, (y, z), z))
    assert (parse('f(x,(y,z),z, name=15)') == f(x, (y, z), z, name=15))
    assert (parse('f(x,(y,z),z, name=15, name2=17)') == f(x, (y, z), z, name=15, name2=17))
    assert_parsed_same_as_python('5+i if i>=0 else (0 if i<-1 else 10)')
    assert_parsed_same_as_python('0 if 1 if 2 else 3 else 4')
    assert_parsed_same_as_python('0 if (1 if 2 else 3) else 4')
    assert_parsed_same_as_python('(2, 3,)')
    with pytest.deprecated_call():
        parse('1+if(0, 1, 2)')
def test_parser():
    from pymbolic import parse
    parse('(2*a[1]*b[1]+2*a[0]*b[0])*(hankel_1(-1,sqrt(a[1]**2+a[0]**2)*k) -hankel_1(1,sqrt(a[1]**2+a[0]**2)*k))*k /(4*sqrt(a[1]**2+a[0]**2)) +hankel_1(0,sqrt(a[1]**2+a[0]**2)*k)')
    print(repr(parse('d4knl0')))
    print(repr(parse('0.')))
    print(repr(parse('0.e1')))
    assert (parse('0.e1') == 0)
    assert (parse('1e-12') == 1e-12)
    print(repr(parse('a >= 1')))
    print(repr(parse('a <= 1')))
    print(repr(parse(':')))
    print(repr(parse('1:')))
    print(repr(parse(':2')))
    print(repr(parse('1:2')))
    print(repr(parse('::')))
    print(repr(parse('0000:0000:0000:0000:0000:0000:0000:0000')))
    print(repr(parse(':1:')))
    print(repr(parse('::1')))
    print(repr(parse('0000:0000:0000:0000:0000:0000:0000:0000')))
    print(repr(parse(':5:1')))
    print(repr(parse('3:5:1')))
    assert_parse_roundtrip('()')
    assert_parse_roundtrip('(3,)')
    assert_parse_roundtrip('[x + 3, 3, 5]')
    assert_parse_roundtrip('[]')
    assert_parse_roundtrip('[x]')
    assert_parse_roundtrip('g[i, k] + 2.0*h[i, k]')
    parse('g[i,k]+(+2.0)*h[i, k]')
    print(repr(parse('a - b - c')))
    print(repr(parse('-a - -b - -c')))
    print(repr(parse('- - - a - - - - b - - - - - c')))
    print(repr(parse('~(a ^ b)')))
    print(repr(parse('(a | b) | ~(~a & ~b)')))
    print(repr(parse('3 << 1')))
    print(repr(parse('1 >> 3')))
    print(parse('0000:0000:0000:0000:0000:0000:0000:0000'))
    assert (parse('e1') == prim.Variable('e1'))
    assert (parse('d1') == prim.Variable('d1'))
    from pymbolic import variables
    (f, x, y, z) = variables('f x y z')
    assert (parse('f((x,y),z)') == f((x, y), z))
    assert (parse('f((x,),z)') == f((x,), z))
    assert (parse('f(x,(y,z),z)') == f(x, (y, z), z))
    assert (parse('f(x,(y,z),z, name=15)') == f(x, (y, z), z, name=15))
    assert (parse('f(x,(y,z),z, name=15, name2=17)') == f(x, (y, z), z, name=15, name2=17))
    assert_parsed_same_as_python('5+i if i>=0 else (0 if i<-1 else 10)')
    assert_parsed_same_as_python('0 if 1 if 2 else 3 else 4')
    assert_parsed_same_as_python('0 if (1 if 2 else 3) else 4')
    assert_parsed_same_as_python('(2, 3,)')
    with pytest.deprecated_call():
        parse('1+if(0, 1, 2)')