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 ready(): log() log(bold('Yalix [{0}]') + ' on Python {1} {2}', version(), sys.version, sys.platform) log('Type "help", "copyright", "credits" or "license" for more information.')