Fix multi line param issues in the fast parser.

This commit is contained in:
Dave Halter
2015-02-17 15:24:49 +01:00
parent 7663703989
commit 506d602795
2 changed files with 20 additions and 9 deletions

View File

@@ -275,7 +275,8 @@ class FastParser(use_metaclass(CachedFastParser)):
self._lines = source.splitlines(True)
current_lines = []
is_decorator = False
indent_list = [0]
# Use -1, because that indent is always smaller than any other.
indent_list = [-1, 0]
new_indent = False
flow_indent = None
# All things within flows are simply being ignored.
@@ -287,7 +288,13 @@ class FastParser(use_metaclass(CachedFastParser)):
current_lines.append(l) # just ignore comments and blank lines
continue
while indent < indent_list[-1]: # -> dedent
if new_indent:
if indent > indent_list[-2]:
# Set the actual indent, not just the random old indent + 1.
indent_list[-1] = indent
new_indent = False
while indent <= indent_list[-2]: # -> dedent
indent_list.pop()
# This automatically resets the flow_indent if there was a
# dedent or a flow just on one line (with one simple_stmt).
@@ -297,12 +304,6 @@ class FastParser(use_metaclass(CachedFastParser)):
yield gen_part()
flow_indent = None
if new_indent:
if indent > indent_list[-1]:
# Set the actual indent, not just the random old indent + 1.
indent_list[-1] = indent
new_indent = False
# Check lines for functions/classes and split the code there.
if flow_indent is None:
m = self._keyword_re.match(l)
@@ -358,7 +359,6 @@ class FastParser(use_metaclass(CachedFastParser)):
else:
debug.dbg('While parsing %s, line %s slowed down the fast parser',
self.module_path, line_offset)
print(line_offset, repr(code_part))
line_offset += code_part.count('\n')
start += len(code_part)

View File

@@ -244,6 +244,17 @@ def test_func_with_for_and_comment():
check_fp('a\n' + src, 2, 3)
def test_multi_line_params():
src = dedent("""\
def x(a,
b):
pass
foo = 1
""")
check_fp(src, 2)
def test_one_statement_func():
src = dedent("""\
first