Ejemplo n.º 1
0
def compile_ex_python_from_source(source_code):
    filename = '<shell>'
    result = parse_ext_py(source_code)
    result.state.filename = filename
    check_parsing_complete(source_code, result.tokens, result.state)
    ast = result.result
    code = compile(ast, filename, "exec")
    return code
Ejemplo n.º 2
0
def compile_ex_python_from_source(source_code, is_entry_point=True):
    filename = '<unknown>'
    result = parse_ext_py(source_code)
    result.state.filename = filename
    check_parsing_complete(source_code, result.tokens, result.state)
    ast = result.result
    code = py_compile(ast, filename, is_entrypoint=is_entry_point)
    return code
Ejemplo n.º 3
0
def compile_ex_python_from_filename(filename):
    with Path(filename).open('r') as fr:
        source_code = fr.read()
        result = parse_ext_py(source_code)
    result.state.filename = filename
    check_parsing_complete(source_code, result.tokens, result.state)
    ast = result.result
    code = compile(ast, filename, "exec")
    return code
Ejemplo n.º 4
0
def compile_ex_python_from_filename(filename, is_entry_point=True):
    with Path(filename).open('r') as fr:
        source_code = fr.read()
        result = parse_ext_py(source_code)
    result.state.filename = filename
    # double check parsed result.
    check_parsing_complete(source_code, result.tokens, result.state)
    ast = result.result
    code = py_compile(ast, filename, is_entrypoint=is_entry_point)
    return code
Ejemplo n.º 5
0
def gen(i: 'input filename', o: 'output filename'):
    """
    generate python source code for dbg-lang
    """
    with Path(i).open('r') as fr:
        code = fr.read()
    res = parse(code)
    check_parsing_complete(code, res.tokens, res.state)

    with Path(o).open('w') as fw:
        fw.write(code_gen(res.result))
Ejemplo n.º 6
0
def parse(text: str, strict_match=False) -> ze.ResultDescription:
    tokens = tuple(ulang.lexer(text))

    state = State(_impl, filename='<rush>')

    result = _command.match(tokens, state)

    if not strict_match:
        check_parsing_complete(text, tokens, state)

    return ze.ResultDescription(state, result, tokens)
Ejemplo n.º 7
0
def get_yapypy_module_spec_from_path(names, module_path):
    with Path(module_path).open('r') as fr:
        spec = ModuleSpec(names, YAPyPyLoader(names, module_path))
        __source__ = fr.read()
        result = parse(__source__, module_path)
        # pprint(result.result)
        check_parsing_complete(__source__, result.tokens, result.state)
        __bytecode__ = py_compile(result.result,
                                  filename=module_path,
                                  is_entrypoint=False)
        spec.__source__ = __source__
        spec.__bytecode__ = __bytecode__
        return spec
Ejemplo n.º 8
0
def get_reley_module_spec_from_path(names, module_path):
    with Path(module_path).open('r') as fr:
        spec = ModuleSpec(names, ReleyLoader(names, module_path))
        reley_module_specs[names] = spec
        code = fr.read()
        parse = get_parse_fn()

        result = parse(code, module_path)
        check_parsing_complete(code, result.tokens, result.state)
        ast = result.result
        ctx = Ctx({}, {}, Bytecode(), {}, False)
        ctx.visit(ast)
        ctx.bc.filename = module_path
        spec.source_code = code
        spec.context = ctx
        return spec
Ejemplo n.º 9
0
def _build_language(text: str, state):
    tokens = tuple(rbnf.lexer(text))
    Grammar.match(tokens, state)
    check_parsing_complete(text, tokens, state)
Ejemplo n.º 10
0
from auto_orm.database.dbg_grammar import *
from auto_orm.database.dbg_emit import *
from rbnf.edsl.rbnf_analyze import check_parsing_complete

test_code = r"""
engine {
     url = "sqlite:///:memory:"
}

Spirit { name: String(30) }
Site   {}

Spirit^ with ^Site {
    score: Float
}


"""
res = parse(test_code)

check_parsing_complete(test_code, res.tokens, res.state)
with open('generated.py', 'w') as f:
    f.write(code_gen(res.result))