Example #1
0
def source(value):
    from yalix.utils import highlight_syntax
    from yalix.source_view import source_view
    src = source_view(value)
    if src:
        print('-----------------')
        print(highlight_syntax(source_view(value)))
Example #2
0
def source(value):
    from yalix.utils import highlight_syntax
    from yalix.source_view import source_view
    src = source_view(value)
    if src:
        print('-----------------')
        print(highlight_syntax(source_view(value)))
Example #3
0
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