def repl(inprompt=stdin_read, outprompt=stdout_prn): try: env = create_initial_env() except EvaluationError as ex: log("{0}: {1}", red(type(ex).__name__, style='bold'), ex) log(highlight_syntax(source_view(ex.primitive))) sys.exit() env['copyright'] = left_margin(copyright()) env['license'] = left_margin(license()) env['help'] = left_margin(help()) env['credits'] = left_margin(credits()) init_readline(env) ready() parser = scheme_parser() count = 1 while True: try: text = next(inprompt(count)) for ast in parser.parseString(text, parseAll=True).asList(): result = ast.eval(env) # Evaluate lazy list representations result = Repr(result).eval(env) outprompt(result, count) if text.strip() != '': print('') except EOFError: log(blue('\nBye!', style='bold')) break except KeyboardInterrupt: log(red('\nKeyboardInterrupt', style='bold')) except EvaluationError as ex: log("{0}: {1}", red(type(ex).__name__, style='bold'), ex) log(highlight_syntax(source_view(ex.primitive))) except ParseException as ex: log("{0}: {1}", red(type(ex).__name__, style='bold'), ex) count += 1
def bootstrap_lisp_functions(env, from_file): for ast in scheme_parser().parseFile(from_file, parseAll=True).asList(): # TODO: brand AST nodes with filename ast.eval(env)
def read_string(value): return scheme_parser().parseString(value, parseAll=True).asList()[0]