mirror of
https://github.com/davidhalter/parso.git
synced 2025-12-08 13:45:01 +08:00
break should be in loop.
This commit is contained in:
@@ -15,7 +15,8 @@ class CompressNormalizer(Normalizer):
|
||||
|
||||
|
||||
class Context(object):
|
||||
def __init__(self, scope, parent_context=None):
|
||||
def __init__(self, node, parent_context=None):
|
||||
self.node = node
|
||||
self.blocks = []
|
||||
|
||||
@contextmanager
|
||||
@@ -97,6 +98,13 @@ class ErrorFinder(Normalizer):
|
||||
if not in_loop:
|
||||
message = "'continue' not properly in loop"
|
||||
self._add_syntax_error(message, leaf)
|
||||
elif leaf.value == 'break':
|
||||
in_loop = False
|
||||
for block in self._context.blocks:
|
||||
if block.type == 'for_stmt':
|
||||
in_loop = True
|
||||
if not in_loop:
|
||||
self._add_syntax_error("'break' outside loop", leaf)
|
||||
return ''
|
||||
|
||||
def _add_indentation_error(self, message, spacing):
|
||||
|
||||
@@ -67,7 +67,8 @@ def test_indentation_errors(code, positions):
|
||||
finally:
|
||||
continue
|
||||
'''), # 'continue' not supported inside 'finally' clause"
|
||||
'continue'
|
||||
'continue',
|
||||
'break',
|
||||
|
||||
# IndentationError
|
||||
' foo',
|
||||
|
||||
Reference in New Issue
Block a user