mirror of
https://github.com/davidhalter/parso.git
synced 2025-12-08 05:34:51 +08:00
Add 'continue' not properly in loop
This commit is contained in:
@@ -85,12 +85,19 @@ class ErrorFinder(Normalizer):
|
|||||||
else:
|
else:
|
||||||
self._add_syntax_error('invalid syntax', leaf)
|
self._add_syntax_error('invalid syntax', leaf)
|
||||||
elif leaf.value == 'continue':
|
elif leaf.value == 'continue':
|
||||||
|
in_loop = False
|
||||||
for block in self._context.blocks:
|
for block in self._context.blocks:
|
||||||
|
if block.type == 'for_stmt':
|
||||||
|
in_loop = True
|
||||||
if block.type == 'try_stmt':
|
if block.type == 'try_stmt':
|
||||||
last_block = block.children[-3]
|
last_block = block.children[-3]
|
||||||
if last_block == 'finally' and leaf.start_pos > last_block.start_pos:
|
if last_block == 'finally' and leaf.start_pos > last_block.start_pos:
|
||||||
message = "'continue' not supported inside 'finally' clause"
|
message = "'continue' not supported inside 'finally' clause"
|
||||||
self._add_syntax_error(message, leaf)
|
self._add_syntax_error(message, leaf)
|
||||||
|
if not in_loop:
|
||||||
|
message = "'continue' not properly in loop"
|
||||||
|
self._add_syntax_error(message, leaf)
|
||||||
|
return ''
|
||||||
|
|
||||||
def _add_indentation_error(self, message, spacing):
|
def _add_indentation_error(self, message, spacing):
|
||||||
self._add_error(903, "IndentationError: " + message, spacing)
|
self._add_error(903, "IndentationError: " + message, spacing)
|
||||||
|
|||||||
@@ -367,6 +367,8 @@ class PEP8Normalizer(ErrorFinder):
|
|||||||
|
|
||||||
self._previous_leaf = leaf
|
self._previous_leaf = leaf
|
||||||
|
|
||||||
|
return leaf.value
|
||||||
|
|
||||||
def _visit_part(self, part, spacing, leaf):
|
def _visit_part(self, part, spacing, leaf):
|
||||||
value = part.value
|
value = part.value
|
||||||
type_ = part.type
|
type_ = part.type
|
||||||
|
|||||||
@@ -9,3 +9,8 @@ for x in [1]:
|
|||||||
finally:
|
finally:
|
||||||
#: E901
|
#: E901
|
||||||
continue
|
continue
|
||||||
|
|
||||||
|
|
||||||
|
for x in [1]:
|
||||||
|
break
|
||||||
|
continue
|
||||||
|
|||||||
@@ -67,6 +67,7 @@ def test_indentation_errors(code, positions):
|
|||||||
finally:
|
finally:
|
||||||
continue
|
continue
|
||||||
'''), # 'continue' not supported inside 'finally' clause"
|
'''), # 'continue' not supported inside 'finally' clause"
|
||||||
|
'continue'
|
||||||
|
|
||||||
# IndentationError
|
# IndentationError
|
||||||
' foo',
|
' foo',
|
||||||
|
|||||||
Reference in New Issue
Block a user