mirror of
https://github.com/davidhalter/jedi.git
synced 2025-12-23 05:41:27 +08:00
small refactorings of the tokenizer
This commit is contained in:
@@ -158,9 +158,8 @@ def generate_tokens(readline, line_offset=0):
|
|||||||
contstr = ''
|
contstr = ''
|
||||||
contline = None
|
contline = None
|
||||||
while True: # loop over lines in stream
|
while True: # loop over lines in stream
|
||||||
try:
|
line = readline() # readline returns empty if it's finished. See StringIO
|
||||||
line = readline()
|
if not line:
|
||||||
except StopIteration:
|
|
||||||
if contstr:
|
if contstr:
|
||||||
yield TokenInfo(ERRORTOKEN, contstr, strstart, (lnum, pos))
|
yield TokenInfo(ERRORTOKEN, contstr, strstart, (lnum, pos))
|
||||||
break
|
break
|
||||||
@@ -179,12 +178,15 @@ def generate_tokens(readline, line_offset=0):
|
|||||||
contstr = contstr + line
|
contstr = contstr + line
|
||||||
contline = contline + line
|
contline = contline + line
|
||||||
continue
|
continue
|
||||||
elif pos == max:
|
|
||||||
break # Don't really understand why this must be here.
|
|
||||||
|
|
||||||
while pos < max:
|
while pos < max:
|
||||||
pseudomatch = pseudoprog.match(line, pos)
|
pseudomatch = pseudoprog.match(line, pos)
|
||||||
if pseudomatch: # scan for tokens
|
if not pseudomatch: # scan for tokens
|
||||||
|
yield TokenInfo(ERRORTOKEN, line[pos],
|
||||||
|
(lnum, pos), (lnum, pos + 1))
|
||||||
|
pos += 1
|
||||||
|
continue
|
||||||
|
|
||||||
start, end = pseudomatch.span(1)
|
start, end = pseudomatch.span(1)
|
||||||
spos, epos, pos = (lnum, start), (lnum, end), end
|
spos, epos, pos = (lnum, start), (lnum, end), end
|
||||||
token, initial = line[start:end], line[start]
|
token, initial = line[start:end], line[start]
|
||||||
@@ -227,10 +229,6 @@ def generate_tokens(readline, line_offset=0):
|
|||||||
continue
|
continue
|
||||||
else:
|
else:
|
||||||
yield TokenInfo(OP, token, spos, epos)
|
yield TokenInfo(OP, token, spos, epos)
|
||||||
else:
|
|
||||||
yield TokenInfo(ERRORTOKEN, line[pos],
|
|
||||||
(lnum, pos), (lnum, pos + 1))
|
|
||||||
pos += 1
|
|
||||||
|
|
||||||
yield TokenInfo(ENDMARKER, '', (lnum, 0), (lnum, 0))
|
yield TokenInfo(ENDMARKER, '', (lnum, 0), (lnum, 0))
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user