def compile_(output, filename): env = Env() with open(output, "w") as outfile: outfile.write( compile_list(parse(lex(pycell.library.as_text(env))), env)) with open(filename, encoding="ascii") as infile: outfile.write( compile_list(parse(lex(chars_in_file(infile))), env))
def import_(env): env.set("char_at", ("native", pycell.prologue.native.char_at.char_at)) env.set("equals", ("native", pycell.prologue.native.equals.equals)) env.set("if", ("native", pycell.prologue.native.if_.if_)) env.set("len", ("native", pycell.prologue.native.len_.len_)) env.set("print", ("native", pycell.prologue.native.print_.print_)) env.set("set", ("native", pycell.prologue.native.set_.set_)) env.set("None", ("none",)) eval_list(parse(lex(as_text(env))), env)
def import_(env): env.set("char_at", ("native", pycell.prologue.native.char_at.char_at)) env.set("concat", ("native", pycell.prologue.native.concat.concat)) env.set("equals", ("native", pycell.prologue.native.equals.equals)) env.set("if", ("native", pycell.prologue.native.if_.if_)) env.set("len", ("native", pycell.prologue.native.len_.len_)) env.set("print", ("native", pycell.prologue.native.print_.print_)) env.set("set", ("native", pycell.prologue.native.set_.set_)) env.set("None", ("none",)) eval_list(parse(lex(as_text(env))), env)
def repl(stdin, stdout, stderr): env = Env(parent=None, stdin=stdin, stdout=stdout, stderr=stderr) pycell.library.import_(env) while True: try: p = Prompt(stdout) for value in eval_iter( parse(lex(p.handle_chars(chars_in_file(stdin)))), env): p.value(value) break except Exception as e: stderr.write(str(e)) stderr.write("\n") stdout.write("\n") stdout.flush()
def compiled(inp, env=None): if env is None: env = Env() return compile_list(parse(lex(inp)), env)
def runned(inp): with StringIO() as stdin, StringIO() as stdout: env = Env(stdin=stdin, stdout=stdout, stderr=stdout) pycell.library.import_(env) return eval_list(parse(lex(inp)), env)
def evald(inp, stdout=None): env = Env(stdout=stdout) pycell.library.import_(env) return eval_list(parse(lex(inp)), env)
def evald(inp, env=None): if env is None: env = Env() return eval_list(parse(lex(inp)), env)
def run(filename, stdin, stdout, stderr): env = Env(stdin=stdin, stdout=stdout, stderr=stdout) pycell.library.import_(env) with open(filename, encoding="ascii") as f: eval_list(parse(lex(chars_in_file(f))), env)
def parsed(inp): return list(parse(lex(inp)))