mirror of
https://github.com/davidhalter/jedi.git
synced 2025-12-15 10:07:06 +08:00
Fix for loop issues in the fast parser.
This commit is contained in:
@@ -12,9 +12,11 @@ from jedi.parser import Parser
|
||||
from jedi.parser import tree as pr
|
||||
from jedi.parser import tokenize
|
||||
from jedi import cache
|
||||
from jedi.parser.tokenize import (source_tokens, FLOWS, NEWLINE,
|
||||
from jedi.parser.tokenize import (source_tokens, NEWLINE,
|
||||
ENDMARKER, INDENT, DEDENT)
|
||||
|
||||
FLOWS = ['if', 'else', 'elif', 'while', 'with', 'try', 'except', 'finally', 'for']
|
||||
|
||||
|
||||
class FastModule(pr.SubModule):
|
||||
type = 'file_input'
|
||||
@@ -278,7 +280,7 @@ class ParserNode(object):
|
||||
|
||||
class FastParser(use_metaclass(CachedFastParser)):
|
||||
|
||||
_keyword_re = re.compile('^[ \t]*(def|class|@|%s)' % '|'.join(tokenize.FLOWS))
|
||||
_keyword_re = re.compile('^[ \t]*(def|class|@|%s)' % '|'.join(FLOWS))
|
||||
|
||||
def __init__(self, grammar, source, module_path=None):
|
||||
# set values like `pr.Module`.
|
||||
@@ -348,7 +350,7 @@ class FastParser(use_metaclass(CachedFastParser)):
|
||||
if not in_flow:
|
||||
m = self._keyword_re.match(l)
|
||||
if m:
|
||||
in_flow = m.group(1) in tokenize.FLOWS
|
||||
in_flow = m.group(1) in FLOWS
|
||||
if not is_decorator and not in_flow:
|
||||
if current_lines:
|
||||
yield gen_part()
|
||||
@@ -540,7 +542,6 @@ class FastTokenizer(object):
|
||||
self._indent_counter += 1
|
||||
elif typ == DEDENT:
|
||||
self._indent_counter -= 1
|
||||
print(self._flow_indent_counter)
|
||||
if self._in_flow and self._indent_counter == self._flow_indent_counter:
|
||||
self._in_flow = False
|
||||
self._next_dedent_noclose = True
|
||||
|
||||
@@ -21,11 +21,6 @@ from jedi.parser.token import (tok_name, N_TOKENS, ENDMARKER, STRING, NUMBER,
|
||||
cookie_re = re.compile("coding[:=]\s*([-\w.]+)")
|
||||
|
||||
|
||||
# From here on we have custom stuff (everything before was originally Python
|
||||
# internal code).
|
||||
FLOWS = ['if', 'else', 'elif', 'while', 'with', 'try', 'except', 'finally']
|
||||
|
||||
|
||||
namechars = string.ascii_letters + '_'
|
||||
|
||||
|
||||
|
||||
@@ -131,6 +131,17 @@ def test_if_simple():
|
||||
check_fp(src + "else:\n a = ''\na", 1)
|
||||
|
||||
|
||||
def test_for():
|
||||
src = dedent("""\
|
||||
for a in [1,2]:
|
||||
a
|
||||
|
||||
for a1 in 1,"":
|
||||
a1
|
||||
""")
|
||||
check_fp(src, 1)
|
||||
|
||||
|
||||
def test_incomplete_function():
|
||||
source = '''return ImportErr'''
|
||||
|
||||
|
||||
Reference in New Issue
Block a user