本文整理汇总了Python中tokenize.tokenprog.match函数的典型用法代码示例。如果您正苦于以下问题:Python match函数的具体用法?Python match怎么用?Python match使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了match函数的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: fixline
def fixline(line):
# Quick check for easy case
if '=' not in line: return line
i, n = 0, len(line)
stack = []
while i < n:
j = tokenprog.match(line, i)
if j < 0:
# A bad token; forget about the rest of this line
print '(Syntax error:)'
print line,
return line
a, b = tokenprog.regs[3] # Location of the token proper
token = line[a:b]
i = i+j
if stack and token == stack[-1]:
del stack[-1]
elif match.has_key(token):
stack.append(match[token])
elif token == '=' and stack:
line = line[:a] + '==' + line[b:]
i, n = a + len('=='), len(line)
elif token == '==' and not stack:
print '(Warning: \'==\' at top level:)'
print line,
return line
开发者ID:Claruarius,项目名称:stblinux-2.6.37,代码行数:27,代码来源:eqfix.py
示例2: lex
def lex(text, textpos, filepath):
offset = pos = 0
end = len(text)
escaped = False
while 1:
if escaped:
offset = text.find(PREFIX, offset + 2)
escaped = False
else:
offset = text.find(PREFIX, pos)
if offset < 0 or offset == end - 1:
break
next = text[offset + 1]
if next == '{':
if offset > pos:
yield False, text[pos:offset]
pos = offset + 2
level = 1
while level:
match = tokenprog.match(text, pos)
if match is None:
raise TemplateSyntaxError('invalid syntax', filepath,
*textpos[1:])
pos = match.end()
tstart, tend = match.regs[3]
token = text[tstart:tend]
if token == '{':
level += 1
elif token == '}':
level -= 1
yield True, text[offset + 2:pos - 1]
elif next in NAMESTART:
if offset > pos:
yield False, text[pos:offset]
pos = offset
pos += 1
while pos < end:
char = text[pos]
if char not in NAMECHARS:
break
pos += 1
yield True, text[offset + 1:pos].strip()
elif not escaped and next == PREFIX:
escaped = True
pos = offset + 1
else:
yield False, text[pos:offset + 1]
pos = offset + 1
if pos < end:
yield False, text[pos:]
开发者ID:jacoco,项目名称:www.eclemma.org,代码行数:56,代码来源:interpolation.py
示例3: _matchorfail
def _matchorfail(text, pos):
match = tokenprog.match(text, pos)
if match is None: raise ValueError(text, pos)
return match, match.end()
开发者ID:DDRBoxman,项目名称:Spherebot-Host-GUI,代码行数:4,代码来源:extformat.py
示例4: match_or_fail
def match_or_fail(text, pos):
"""match_or_fail(text, pos)"""
match = tokenprog.match(text, pos)
if match is None:
raise ItplError(text, pos)
return match, match.end()
开发者ID:profes0rul,项目名称:mentor,代码行数:6,代码来源:utils.py
示例5: matchorfail
def matchorfail(text, pos):
match = tokenprog.match(text, pos) # @UndefinedVariable
if match is None:
raise _ItplError(text, pos)
return match, match.end()
开发者ID:jeshica,项目名称:DataCenter,代码行数:5,代码来源:mydb.py
示例6:
开发者ID:mcyril,项目名称:ravel-ftn,代码行数:1,代码来源:eqfix.py
注:本文中的tokenize.tokenprog.match函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论