Example #1
0
File: lark.py Project: ktravis/lark
def import_file(name, env, _as=None):
    path, ns_name, parts = parse_import_path(name)
    try:
        with open(path, 'rb') as f:
            content = f.read()
    except IOError as error:
        raise LarkException(error.message)
    ns = env.get_or_create_ns(ns_name)
    last = run_program(parse(content), ns)
    for n in parts:
        ns = ns.get_ns(n)
        ns_name = n
    if _as is not None:
        ns_name = _as
    env.set_ns(ns_name, ns)
    return last
Example #2
0
File: lark.py Project: ktravis/lark
pairs = {
    '(': ')',
    '[': ']',
    '{': '}',
    'if|loop': 'end',
}
even = [
    '"""',
    "'''",
]

if __name__ == '__main__':
    if len(sys.argv) > 1:
        with open(sys.argv[1], 'rb') as f:
            prog = parse(f.read())
        run_program(prog, root)
    else:
        import readline
        import traceback

        lines = ""
        partial = False
        while True:
            l = raw_input(".... " if partial else "lrk> ")
            lines += l + '\n'
            partial = False
            for start,end in pairs.items():
                if sum(lines.count(s) for s in start.split('|')) != lines.count(end):
                    partial = True
                    break