本文整理汇总了Python中stream.Stream.eof方法的典型用法代码示例。如果您正苦于以下问题:Python Stream.eof方法的具体用法?Python Stream.eof怎么用?Python Stream.eof使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类stream.Stream
的用法示例。
在下文中一共展示了Stream.eof方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: Scanner
# 需要导入模块: from stream import Stream [as 别名]
# 或者: from stream.Stream import eof [as 别名]
class Scanner(object):
def initialize_scan(self, string):
self.tokens = []
self.stream = Stream(string)
def produce(self, token):
self.tokens.append(token)
def tokenize(self):
while self.tokenize_one():
pass
return self.tokens
def tokenize_one(self):
i = self.stream.index
if self.stream.eof():
self.eof()
return False
for tokenizer_pair in self.state:
tokenizer = tokenizer_pair[0]
action = tokenizer_pair[1]
if tokenizer.applies(self.stream):
j = self.stream.index
action(self, tokenizer.token(self.stream, i, j))
return True
raise StandardError("No tokenizer applied.")
示例2: ParseError
# 需要导入模块: from stream import Stream [as 别名]
# 或者: from stream.Stream import eof [as 别名]
class Tokenizer:
class ParseError(RuntimeError):
pass
class ModuleError(RuntimeError):
pass
def parse(self, src):
self.strm = Stream(src)
self.tokens = []
s = self.strm
m = 'text block'
buf = ''
while not s.eof():
c = s.get()
if m == 'text block':
if c == '{' and s.cur() == '@':
if len(buf):
self.tokens.append(Token(kind='text-block', value=buf))
buf = ''
s.get()
self.tokens.append(Token(kind='lbraceat', value='{@'))
m = 'code block'
elif c == '{' and s.cur() == '{':
if len(buf):
self.tokens.append(Token(kind='text-block', value=buf))
buf = ''
s.get()
self.tokens.append(Token(kind='ldbrace', value='{{'))
m = 'ref block'
else:
buf += c
elif m == 'ref block':
if c == '}' and s.cur() == '}':
s.get()
self.tokens.append(Token(kind='rdbrace', value='}}'))
m = 'text block'
elif self.is_identifier_char(c):
s.prev()
self.read_identifier()
elif c == '(':
self.tokens.append(Token(kind='lparen', value='('))
elif c == ')':
self.tokens.append(Token(kind='rparen', value=')'))
elif c == '.':
self.tokens.append(Token(kind='operator', value='.'))
elif c == '"':
s.prev()
self.read_string()
elif m == 'code block':
if c == '@' and s.cur() == '}':
s.get()
self.tokens.append(Token(kind='rbraceat', value='@}'))
m = 'text block'
elif c == '.':
self.tokens.append(Token(kind='operator', value='.'))
elif c == ',':
self.tokens.append(Token(kind='comma', value=','))
elif c == '(':
self.tokens.append(Token(kind='lparen', value='('))
elif c == ')':
self.tokens.append(Token(kind='rparen', value=')'))
elif c == ':':
self.tokens.append(Token(kind='colon', value=':'))
elif c == '=':
s.prev()
self.read_assign()
elif c == '!':
s.prev()
self.read_not()
elif c == '<':
s.prev()
self.read_lt()
elif c == '>':
s.prev()
self.read_gt()
elif c == '+':
s.prev()
self.read_add()
elif c == '-':
s.prev()
self.read_sub()
elif c == '*':
self.tokens.append(Token(kind='operator', value='*'))
elif c == '/':
self.tokens.append(Token(kind='operator', value='/'))
elif c == '"':
s.prev()
self.read_string()
elif c.isdigit():
s.prev()
self.read_digit()
elif self.is_identifier_char(c):
s.prev()
self.read_identifier()
elif c.isspace():
pass
else:
raise Tokenizer.ParseError('unsupprted character %s' % c)
#.........这里部分代码省略.........
示例3: ModuleError
# 需要导入模块: from stream import Stream [as 别名]
# 或者: from stream.Stream import eof [as 别名]
#.........这里部分代码省略.........
raise AST.NameError('"%s" is not defined' % first)
def call_alias_package(self, node):
if not self.context.imported_alias:
raise AST.ImportError('alias is not imported')
method = node.identifiers[1]
if method == 'set':
if len(node.args) != 2:
AST.SyntaxError('alias.set need two arguments')
name = node.args[0]
cmd = node.args[1]
self.context.alias_map[name] = cmd
def call_config_package(self, node):
if not self.context.imported_config:
raise AST.ImportError('config is not imported')
method = node.identifiers[1]
if method == 'set':
if len(node.args) != 2:
AST.SyntaxError('config.set need two arguments')
name = node.args[0]
cmd = node.args[1]
self.context.config_map[name] = cmd
def show_parse(self, name, dep):
if self.debug_parse:
t = self.strm.cur()
print(dep, name + ': ' + str(t))
def block(self, dep=0):
self.show_parse('block', dep=dep)
if self.strm.eof():
return None
t = self.strm.cur()
if t.kind in ('rbraceat', 'end', 'if', 'elif', 'else'):
return None
node = BlockNode()
node.code_block = self.code_block(dep=dep+1)
if node.code_block is None:
node.ref_block = self.ref_block(dep=dep+1)
if node.ref_block is None:
node.text_block = self.text_block(dep=dep+1)
node.block = self.block(dep=dep+1)
return node
def ref_block(self, dep=0):
self.show_parse('ref_block', dep=dep)
if self.strm.eof():
return None
node = RefBlockNode()
t = self.strm.get()
if t.kind != 'ldbrace':
self.strm.prev()
return None
t = self.strm.get()
if t.kind == 'identifier':
t2 = self.strm.cur()