本文整理汇总了Python中stream.Stream.prev方法的典型用法代码示例。如果您正苦于以下问题:Python Stream.prev方法的具体用法?Python Stream.prev怎么用?Python Stream.prev使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类stream.Stream
的用法示例。
在下文中一共展示了Stream.prev方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: ParseError
# 需要导入模块: from stream import Stream [as 别名]
# 或者: from stream.Stream import prev [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)
#.........这里部分代码省略.........
示例2: ModuleError
# 需要导入模块: from stream import Stream [as 别名]
# 或者: from stream.Stream import prev [as 别名]
#.........这里部分代码省略.........
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()
if t2 == Stream.EOF:
raise AST.SyntaxError('reference block not closed')
elif t2.value in ('.', '('):
self.strm.prev()
node.callable = self.callable()
else:
node.identifier = t.value
elif t.kind == 'rdbrace':
return node
t = self.strm.get()
if t == Stream.EOF or t.kind != 'rdbrace':
raise AST.SyntaxError('not found "rdbrace"')
return node
def callable(self, dep=0):
self.show_parse('callable', dep=dep)
if self.strm.eof():
return None
node = CallableNode()
node.caller_list = self.caller_list()
t = self.strm.get()
if t.value != '(':
raise AST.SyntaxError('not found "(" in callable')