Exemplo n.º 1
0
def _gorun(el, repls):
    s = E.func(';', repls + [el])
    s = Unclosure.bind(s)
    MACRO.clear()
    s = cody(s, 'py', 'generators/py.py')
    s = execute(s)
    s = s()
    s = _res2E(s)
    return s
Exemplo n.º 2
0
 def go_js(s, q):
     q = unquote(q)
     try:
         q = create(q)
         q = cody(q, 'py', 'generators/js.py')
     except BaseException:
         print_exc()
         s.go_send(400, 'text/html', '<h1>Error</h1>'.encode('utf8'))
         return
     s.go_send(200, 'text/javascript', q.encode('utf8'))
Exemplo n.º 3
0
def test_js_oneline_func():
    s = r"""
    f(x,y,z) = \left\{ x, y, z \right\};
    g = \left\{ 1, 2, 3 \right\};
    f
    """
    s = create(s)
    s = cody(s, 'py', 'generators/js.py')
    print(s)
    assert s.find('(x,y,z){') >= 0
Exemplo n.º 4
0
def fastExec(s):
    s = create(s)
    s = Unclosure.bind(s)
    # print(s)
    s = cody(s, 'py', 'generators/py.py')
    print('-' * 20)
    print(s)
    s = execute(s)
    s = s()
    print('-' * 20)
    print(s)
    return s
Exemplo n.º 5
0
def test_templator():
    src = create(r"?(\text{a}) + ?(\text{b})")[0]
    dst = create(r"?(\text{a}) * 2 - ?(\text{b})")[0]
    eqn1 = create(r"""
    f(x) = x * (3 + \text{hello world}) - (6+(3*x)^2);
    f(10)
    """)
    eqn2 = create(r"""
    f(x) = x * (3 * 2 - \text{hello world}) - (6 * 2 - (3*x)^2);
    f(10)
    """)
    eqn1 = apply(eqn1, src, dst)
    assert eqn1 == eqn2
    [eqn1, eqn2] = [cody(s, 'py', 'generators/latex.py') for s in [eqn1, eqn2]]
    assert eqn1 == eqn2
Exemplo n.º 6
0
def test_consty():
    import os
    with open(os.path.join('pbtests', 'consty.pb'), 'r', encoding='utf8') as f:
        fd = f.read()
    s = create(fd)
    from consty import consty
    s = consty(s)
    print('-' * 10, 'CONSTY', '-' * 10)
    print(s)
    s = Unclosure.bind(s)
    s = cody(s, 'py', 'generators/py.py')
    s = execute(s)
    s = s()
    print(s)
    assert [s(i) for i in range(4)] == [6, 6, 11, 46]
    assert s(4)(4) == 7
Exemplo n.º 7
0
def trr_inbuilt():
    return lambda t, s, n: cody(s, 'py', 'generators/%s.py' % t, n)
Exemplo n.º 8
0
def trr_typed(t, f):
    return lambda _, s, n: cody(s, t, f, n)