本文整理汇总了Python中tokenize.ERRORTOKEN属性的典型用法代码示例。如果您正苦于以下问题:Python tokenize.ERRORTOKEN属性的具体用法?Python tokenize.ERRORTOKEN怎么用?Python tokenize.ERRORTOKEN使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类tokenize
的用法示例。
在下文中一共展示了tokenize.ERRORTOKEN属性的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _get_all_tokens
# 需要导入模块: import tokenize [as 别名]
# 或者: from tokenize import ERRORTOKEN [as 别名]
def _get_all_tokens(line, lines):
'''Starting from *line*, generate the necessary tokens which represent the
shortest tokenization possible. This is done by catching
:exc:`tokenize.TokenError` when a multi-line string or statement is
encountered.
:returns: tokens, lines
'''
buffer = line
used_lines = [line]
while True:
try:
tokens = _generate(buffer)
except tokenize.TokenError:
# A multi-line string or statement has been encountered:
# start adding lines and stop when tokenize stops complaining
pass
else:
if not any(t[0] == tokenize.ERRORTOKEN for t in tokens):
return tokens, used_lines
# Add another line
next_line = next(lines)
buffer = buffer + '\n' + next_line
used_lines.append(next_line)
示例2: __get_tokens
# 需要导入模块: import tokenize [as 别名]
# 或者: from tokenize import ERRORTOKEN [as 别名]
def __get_tokens(it):
tokens: List[tokenize.TokenInfo] = []
try:
for t in it:
if t.type in tokenizer.SKIP_TOKENS:
continue
if t.type == tokenize.NEWLINE and t.string == '':
continue
if t.type == tokenize.DEDENT:
continue
if t.type == tokenize.ERRORTOKEN:
continue
tokens.append(t)
except tokenize.TokenError as e:
if not e.args[0].startswith('EOF in'):
print(e)
except IndentationError as e:
print(e)
return tokens
示例3: python_tokenize
# 需要导入模块: import tokenize [as 别名]
# 或者: from tokenize import ERRORTOKEN [as 别名]
def python_tokenize(code):
# Since formulas can only contain Python expressions, and Python
# expressions cannot meaningfully contain newlines, we'll just remove all
# the newlines up front to avoid any complications:
code = code.replace("\n", " ").strip()
it = tokenize.generate_tokens(StringIO(code).readline)
try:
for (pytype, string, (_, start), (_, end), code) in it:
if pytype == tokenize.ENDMARKER:
break
origin = Origin(code, start, end)
assert pytype not in (tokenize.NL, tokenize.NEWLINE)
if pytype == tokenize.ERRORTOKEN:
raise PatsyError("error tokenizing input "
"(maybe an unclosed string?)",
origin)
if pytype == tokenize.COMMENT:
raise PatsyError("comments are not allowed", origin)
yield (pytype, string, origin)
else: # pragma: no cover
raise ValueError("stream ended without ENDMARKER?!?")
except tokenize.TokenError as e:
# TokenError is raised iff the tokenizer thinks that there is
# some sort of multi-line construct in progress (e.g., an
# unclosed parentheses, which in Python lets a virtual line
# continue past the end of the physical line), and it hits the
# end of the source text. We have our own error handling for
# such cases, so just treat this as an end-of-stream.
#
# Just in case someone adds some other error case:
assert e.args[0].startswith("EOF in multi-line")
return
示例4: _advance_one_token
# 需要导入模块: import tokenize [as 别名]
# 或者: from tokenize import ERRORTOKEN [as 别名]
def _advance_one_token(self):
self._current_token = ConfigParser.Token(*next(self._token_generator))
# Certain symbols (e.g., "$") cause ERRORTOKENs on all preceding space
# characters. Find the first non-space or non-ERRORTOKEN token.
while (self._current_token.kind == tokenize.ERRORTOKEN and
self._current_token.value in ' \t'):
self._current_token = ConfigParser.Token(*next(self._token_generator))