Fix an issue with Function/Flow combination in the fast parser.

This commit is contained in:
Dave Halter
2015-01-29 02:24:11 +01:00
parent dde0e9c7c6
commit 0a537c05c4
2 changed files with 19 additions and 3 deletions

View File

@@ -542,6 +542,7 @@ class FastTokenizer(object):
self._indent_counter += 1
elif typ == DEDENT:
self._indent_counter -= 1
print('DEDENT', self._flow_indent_counter, start_pos, self._indent_counter)
if self._in_flow and self._indent_counter == self._flow_indent_counter:
self._in_flow = False
self._next_dedent_noclose = True
@@ -549,10 +550,11 @@ class FastTokenizer(object):
if self.previous[0] in (NEWLINE, INDENT, DEDENT):
if self.previous[0] == DEDENT:
if not self._in_flow:
if not self._next_dedent_noclose:
self._first_stmt = False
return self._close()
if not self._in_flow:
self._next_dedent_noclose = False
# Check for NEWLINE, which symbolizes the indent.
#print('X', repr(value), tokenize.tok_name[typ])

View File

@@ -142,6 +142,20 @@ def test_for():
check_fp(src, 1)
def test_func_with_if():
src = dedent("""\
def recursion(a):
if foo:
return recursion(a)
else:
if bar:
return inexistent
else:
return a
""")
check_fp(src, 1)
def test_incomplete_function():
source = '''return ImportErr'''