Exemple #1
0
def interact(show_tokens=False):
    try:
        import readline
    except ImportError:
        pass

    sys.modules['__main__'] = global_env

    while True:
        buffer = ''
        continuation_flag = False
        tokens = []
        while True:
            try:
                if continuation_flag:
                    s = input('... ')
                    if s == '\n':
                        continue
                    buffer = buffer + '\n' + s
                else:
                    s = input('>>> ')
                    if s == '\n':
                        continue
                    buffer = s
            except EOFError:
                print()
                sys.exit()

            try:
                lexer = lex(buffer, repl_mode=True, debug=show_tokens)

                for last in lexer:
                    tokens.append(last)

                if len(tokens) == 0:
                    buffer = ''
                    continue

                if last is REPL_CONTINUE or last.name == 'COLON' or last.name == 'THINARROW':
                    continuation_flag = True
                    tokens = []
                    continue
                else:
                    break
            except Exception:
                traceback.print_exc(file=current_error_port)
                continuation_flag = False
                buffer = ''
                continue
        try:
            eval_tokens(tokens)
        except ParsingError as e:
            print(e, file=current_error_port)
        except Exception:
            traceback.print_exc(file=current_error_port)
Exemple #2
0
def interact(show_tokens=False):
    try:
        import readline
    except ImportError:
        pass

    sys.modules['__main__'] = global_env

    while True:
        buffer = ''
        continuation_flag = False
        tokens = []
        while True:
            try:
                if continuation_flag:
                    s = input('... ')
                    if s == '\n':
                        continue
                    buffer = buffer + '\n' + s
                else:
                    s = input('>>> ')
                    if s == '\n':
                        continue
                    buffer = s
            except EOFError:
                print()
                sys.exit()

            try:
                lexer = lex(buffer, repl_mode=True, debug=show_tokens)

                for last in lexer:
                    tokens.append(last)

                if len(tokens) == 0:
                    buffer = ''
                    continue

                if last is REPL_CONTINUE or last.name == 'COLON' or last.name == 'THINARROW':
                    continuation_flag = True
                    tokens = []
                    continue
                else:
                    break
            except Exception:
                traceback.print_exc(file=current_error_port)
                continuation_flag = False
                buffer = ''
                continue
        try:
            eval_tokens(tokens)
        except ParsingError as e:
            print(e, file=current_error_port)
        except Exception:
            traceback.print_exc(file=current_error_port)
Exemple #3
0
def eval_code_block(block, globals=global_env, locals=None):
    lexer = lex(block + '\n', repl_mode=True)
    eval_tokens(lexer, globals, locals)
Exemple #4
0
def eval_code_block(block):
    lexer = lex(block + '\n', repl_mode=True)
    eval_tokens(lexer)
Exemple #5
0
def eval_code_block(block):
    lexer = lex(block + '\n', repl_mode=True)
    eval_tokens(lexer)
Exemple #6
0
def eval_code_block(block, globals=global_env, locals=None):
    lexer = lex(block + '\n', repl_mode=True)
    eval_tokens(lexer, globals, locals)