Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
yield stashed
stashed = None
yield TokenInfo(OP, token, spos, epos, line)
else:
yield TokenInfo(
ERRORTOKEN, line[pos], (lnum, pos), (lnum, pos + 1), line
)
pos += 1
if stashed:
yield stashed
stashed = None
for indent in indents[1:]: # pop remaining indent levels
yield TokenInfo(DEDENT, "", (lnum, 0), (lnum, 0), "")
yield TokenInfo(ENDMARKER, "", (lnum, 0), (lnum, 0), "")
initial in single_quoted
or token[:2] in single_quoted
or token[:3] in single_quoted
):
if token[-1] == "\n": # continued string
strstart = (lnum, start)
endprog = _compile(
endpats[initial] or endpats[token[1]] or endpats[token[2]]
)
contstr, needcont = line[start:], 1
contline = line
break
else: # ordinary string
yield TokenInfo(STRING, token, spos, epos, line)
elif token.startswith("$") and token[1:].isidentifier():
yield TokenInfo(DOLLARNAME, token, spos, epos, line)
elif initial.isidentifier(): # ordinary name
if token in ("async", "await"):
if async_def:
yield TokenInfo(
ASYNC if token == "async" else AWAIT,
token,
spos,
epos,
line,
)
continue
tok = TokenInfo(NAME, token, spos, epos, line)
if token == "async" and not stashed:
stashed = tok
continue
if line[pos] in "#\r\n": # skip comments or blank lines
if line[pos] == "#":
comment_token = line[pos:].rstrip("\r\n")
nl_pos = pos + len(comment_token)
yield TokenInfo(
COMMENT,
comment_token,
(lnum, pos),
(lnum, pos + len(comment_token)),
line,
)
yield TokenInfo(
NL, line[nl_pos:], (lnum, nl_pos), (lnum, len(line)), line
)
else:
yield TokenInfo(
(NL, COMMENT)[line[pos] == "#"],
line[pos:],
(lnum, pos),
(lnum, len(line)),
line,
)
continue
if column > indents[-1]: # count indents or dedents
indents.append(column)
yield TokenInfo(INDENT, line[:pos], (lnum, 0), (lnum, pos), line)
while column < indents[-1]:
if column not in indents:
raise IndentationError(
"unindent does not match any outer indentation level",
("", lnum, pos, line),
token, initial = line[start:end], line[start]
if token in _redir_check:
yield TokenInfo(IOREDIRECT, token, spos, epos, line)
elif initial in numchars or ( # ordinary number
initial == "." and token != "." and token != "..."
):
yield TokenInfo(NUMBER, token, spos, epos, line)
elif initial in "\r\n":
if stashed:
yield stashed
stashed = None
if parenlev > 0:
yield TokenInfo(NL, token, spos, epos, line)
else:
yield TokenInfo(NEWLINE, token, spos, epos, line)
if async_def:
async_def_nl = True
elif initial == "#":
assert not token.endswith("\n")
if stashed:
yield stashed
stashed = None
yield TokenInfo(COMMENT, token, spos, epos, line)
# Xonsh-specific Regex Globbing
elif re.match(SearchPath, token):
yield TokenInfo(SEARCHPATH, token, spos, epos, line)
elif token in triple_quoted:
endprog = _compile(endpats[token])
endmatch = endprog.match(line, pos)
if endmatch: # all on one line
if stashed:
yield stashed
stashed = None
yield TokenInfo(OP, token, spos, epos, line)
else:
yield TokenInfo(
ERRORTOKEN, line[pos], (lnum, pos), (lnum, pos + 1), line
)
pos += 1
if stashed:
yield stashed
stashed = None
for indent in indents[1:]: # pop remaining indent levels
yield TokenInfo(DEDENT, "", (lnum, 0), (lnum, 0), "")
yield TokenInfo(ENDMARKER, "", (lnum, 0), (lnum, 0), "")
break
elif (
initial in single_quoted
or token[:2] in single_quoted
or token[:3] in single_quoted
):
if token[-1] == "\n": # continued string
strstart = (lnum, start)
endprog = _compile(
endpats[initial] or endpats[token[1]] or endpats[token[2]]
)
contstr, needcont = line[start:], 1
contline = line
break
else: # ordinary string
yield TokenInfo(STRING, token, spos, epos, line)
elif token.startswith("$") and token[1:].isidentifier():
yield TokenInfo(DOLLARNAME, token, spos, epos, line)
elif initial.isidentifier(): # ordinary name
if token in ("async", "await"):
if async_def:
yield TokenInfo(
ASYNC if token == "async" else AWAIT,
token,
spos,
epos,
line,
)
continue
tok = TokenInfo(NAME, token, spos, epos, line)
if token == "async" and not stashed:
line = readline()
except StopIteration:
line = b""
if encoding is not None:
line = line.decode(encoding)
lnum += 1
pos, max = 0, len(line)
if contstr: # continued string
if not line:
raise TokenError("EOF in multi-line string", strstart)
endmatch = endprog.match(line)
if endmatch:
pos = end = endmatch.end(0)
yield TokenInfo(
STRING, contstr + line[:end], strstart, (lnum, end), contline + line
)
contstr, needcont = "", 0
contline = None
elif needcont and line[-2:] != "\\\n" and line[-3:] != "\\\r\n":
yield TokenInfo(
ERRORTOKEN, contstr + line, strstart, (lnum, len(line)), contline
)
contstr = ""
contline = None
continue
else:
contstr = contstr + line
contline = contline + line
continue
pos += 1
if pos == max:
break
if line[pos] in "#\r\n": # skip comments or blank lines
if line[pos] == "#":
comment_token = line[pos:].rstrip("\r\n")
nl_pos = pos + len(comment_token)
yield TokenInfo(
COMMENT,
comment_token,
(lnum, pos),
(lnum, pos + len(comment_token)),
line,
)
yield TokenInfo(
NL, line[nl_pos:], (lnum, nl_pos), (lnum, len(line)), line
)
else:
yield TokenInfo(
(NL, COMMENT)[line[pos] == "#"],
line[pos:],
(lnum, pos),
(lnum, len(line)),
line,
)
continue
if column > indents[-1]: # count indents or dedents
indents.append(column)
yield TokenInfo(INDENT, line[:pos], (lnum, 0), (lnum, pos), line)
while column < indents[-1]: