Fast parser fix.

This commit is contained in:
Dave Halter
2015-02-23 01:00:17 +01:00
parent 3a5b2d396e
commit 2fcb1b9b65
2 changed files with 16 additions and 5 deletions

View File

@@ -478,15 +478,15 @@ class FastTokenizer(object):
if typ == INDENT:
self._indent_counter += 1
if not self._expect_indent and not self._first_stmt:
# This does not mean that there is an actual flow, but it means
# that the INDENT is either syntactically wrong or a flow.
if not self._expect_indent and not self._first_stmt and not self._in_flow:
# This does not mean that there is an actual flow, it means
# that the INDENT is syntactically wrong.
self._flow_indent_counter = self._indent_counter - 1
self._in_flow = True
self._expect_indent = False
elif typ == DEDENT:
self._indent_counter -= 1
if self._in_flow:
# TODO add <= for flows without INDENT in classes.
if self._indent_counter == self._flow_indent_counter:
self._in_flow = False
else:
@@ -507,7 +507,6 @@ class FastTokenizer(object):
# new lines.
if self.previous[0] in (NEWLINE, INDENT, DEDENT) \
and not self._parentheses_level and typ not in (INDENT, DEDENT):
# Check for NEWLINE, which symbolizes the indent.
if not self._in_flow:
if value in FLOWS:
self._flow_indent_counter = self._indent_counter

View File

@@ -322,6 +322,18 @@ def test_wrong_indentation():
""")
check_fp(src, 1)
src = dedent("""\
def complex():
def nested():
a
b
a
def other():
pass
""")
check_fp(src, 3)
def test_open_parentheses():
func = 'def func():\n a'