break should be in loop.

This commit is contained in:
Dave Halter
2017-07-20 00:11:15 +02:00
parent 4a86571b21
commit d21504e2ca
2 changed files with 11 additions and 2 deletions

View File

@@ -15,7 +15,8 @@ class CompressNormalizer(Normalizer):
class Context(object): class Context(object):
def __init__(self, scope, parent_context=None): def __init__(self, node, parent_context=None):
self.node = node
self.blocks = [] self.blocks = []
@contextmanager @contextmanager
@@ -97,6 +98,13 @@ class ErrorFinder(Normalizer):
if not in_loop: if not in_loop:
message = "'continue' not properly in loop" message = "'continue' not properly in loop"
self._add_syntax_error(message, leaf) 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 '' return ''
def _add_indentation_error(self, message, spacing): def _add_indentation_error(self, message, spacing):

View File

@@ -67,7 +67,8 @@ def test_indentation_errors(code, positions):
finally: finally:
continue continue
'''), # 'continue' not supported inside 'finally' clause" '''), # 'continue' not supported inside 'finally' clause"
'continue' 'continue',
'break',
# IndentationError # IndentationError
' foo', ' foo',