本文整理汇总了Python中scheme_tokens.tokenize_lines函数的典型用法代码示例。如果您正苦于以下问题:Python tokenize_lines函数的具体用法?Python tokenize_lines怎么用?Python tokenize_lines使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了tokenize_lines函数的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: buffer_lines
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: run_tests
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: read_line
def read_line(line):
"""Read a single string LINE as a Scheme expression."""
return scheme_read(Buffer(tokenize_lines([line])))
示例4: buffer_input
def buffer_input(prompt="scm> "):
"""Return a Buffer instance containing interactive input."""
return Buffer(tokenize_lines(InputReader(prompt)))
示例5: buffer_lines
def buffer_lines(lines, prompt="scm> "):
"""Return a Buffer instance iterating through LINES."""
return Buffer(tokenize_lines(LineReader(lines, prompt)))
示例6: buffer_input
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)))
示例7: buffer_input
def buffer_input():
return Buffer(tokenize_lines(InputReader('> ')))
示例8: Buffer
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"])))))
示例9: scheme_repl
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)