Пример #1
0
def buffer_lines(lines, prompt="scm> ", show_prompt=False):
    """Return a Buffer instance iterating through LINES."""
    if show_prompt:
        input_lines = lines
    else:
        input_lines = LineReader(lines, prompt)
    return Buffer(tokenize_lines(input_lines))
Пример #2
0
def run_tests(src_file = 'tests.scm'):
    """Run a read-eval loop that reads from src_file and collects outputs."""
    sys.stderr = sys.stdout = io.StringIO() # Collect output to stdout and stderr
    try:
        reader = TestReader(open(src_file).readlines())
        src = Buffer(tokenize_lines(reader))
        def next_line():
            src.current()
            return src
        read_eval_print_loop(next_line, create_global_frame())
    except BaseException as exc:
        sys.stderr = sys.__stderr__
        print("Tests terminated due to unhandled exception "
              "after line {0}:\n>>>".format(reader.line_number),
              file=sys.stderr)
        raise
    output = sys.stdout.getvalue().split('\n')
    sys.stdout = sys.__stdout__  # Revert stdout
    summarize(output, reader.expected_output)
Пример #3
0
def buffer_input(prompt="scm> "): # 从输入获取一行,然后将这一行数据传递给tokenize_lines
    # tokenize_lines处理之后,输出串token,传递个buffer,buffer可是一个可以迭代的对象,所以,你懂的!
    """Return a Buffer instance containing interactive input."""
    return Buffer(tokenize_lines(InputReader(prompt)))
Пример #4
0
def buffer_input():
    return Buffer(tokenize_lines(InputReader('> ')))
Пример #5
0
def read_line(line):
    """Read a single string LINE as a Scheme expression."""
    return scheme_read(Buffer(tokenize_lines([line])))
Пример #6
0
def buffer_input(prompt='scm> '):
    """Return a Buffer instance containing interactive input."""
    return Buffer(tokenize_lines(InputReader(prompt)))
Пример #7
0
def buffer_input(prompt="scm> "):  # 从输入获取一行,然后将这一行数据传递给tokenize_lines
    # tokenize_lines处理之后,输出串token,传递个buffer,buffer可是一个可以迭代的对象,所以,你懂的!
    """Return a Buffer instance containing interactive input."""
    return Buffer(tokenize_lines(InputReader(prompt)))
Пример #8
0
def buffer_lines(lines, prompt='scm> ', show_prompt=False):
    if show_prompt:
        input_lines = lines
    else:
        input_lines = LineReader(lines, prompt)
    return Buffer(tokenize_lines(input_lines))
Пример #9
0
def buffer_lines(lines):
    """Return a Buffer instance iterating through LINES."""
    return Buffer(tokenize_lines(LineReader(lines, "scm> ")))
Пример #10
0
def buffer_input(prompt='scm> '):
    return Buffer(tokenize_lines(InputReader(prompt)))
Пример #11
0
def buffer_input():
    return Buffer(tokenize_lines(InputReader('> ')))
Пример #12
0
def scheme_repl(source, prompt, env, print_input=True):
    """Start a read-eval-print loop reading from SOURCE."""
    read_eval_print(Buffer(tokenize_lines(source)), prompt, env, print_input)
Пример #13
0
# Interactive loop
def read_print_loop():
    """Run a read-print loop for Scheme expressions."""
    while True:
        try:
            src = buffer_input('read> ')
            while src.more_on_line:
                expression = scheme_read(src)
                if expression == 'exit':
                    print()
                    return
                print('str :', expression)
                print('repr:', repr(expression))
        except (SyntaxError, ValueError) as err:
            print(type(err).__name__ + ':', err)
        except (KeyboardInterrupt, EOFError):  # <Control>-D, etc.
            print()
            return


@main
def main(*args):
    if len(args) and '--repl' in args:
        read_print_loop()


#marker 3

print((read_tail(Buffer(tokenize_lines(['2 (3 4))'])))))
Пример #14
0
def buffer_lines(lines, prompt="scm> "):
    """Return a Buffer instance iterating through LINES."""
    return Buffer(tokenize_lines(LineReader(lines, prompt)))
Пример #15
0
def read_line(line):
    return scheme_read(Buffer(tokenize_lines([line])))
Пример #16
0
def buffer_input(prompt="scm> "):
    """Return a Buffer instance containing interactive input."""
    return Buffer(tokenize_lines(InputReader(prompt)))
from scheme_reader import *
from buffer import Buffer, InputReader, LineReader
from scheme_tokens import tokenize_lines, DELIMITERS 

lines = ["(+ 1 ", "(+ 23 4)) ("]
src = Buffer(tokenize_lines(lines))
print(scheme_read(src))
print(repr(read_line("'hello")))
print(read_line("(car '(1 2))"))

print(repr(read_tail(Buffer(tokenize_lines([")"])))))
print(repr(read_tail(Buffer(tokenize_lines(["2 3)"])))))
print(repr(read_tail(Buffer(tokenize_lines(["2 (3 4))"])))))
print(repr(read_line("(1 . 2)")))
print(repr(read_line("(1 2 . 3)")))
print(repr(read_line("(1 . 2 3)")))
print(repr(scheme_read(Buffer(tokenize_lines(["(1", "2 .", "'(3 4))", "4"])))))

Пример #18
0
def read_line(line):
    """Read a single string LINE as a Scheme expression."""
    return scheme_read(Buffer(tokenize_lines([line])))
Пример #19
0
def buffer_input():
    return Buffer(tokenize_lines(InputReader(
        '> ')))  # 将list of token lists放入Buffer,Buffer就像一个流,可以逐步消耗其中的token。