diff --git a/parso/python/normalizer.py b/parso/python/normalizer.py index 6da90fd..3ff3f1a 100644 --- a/parso/python/normalizer.py +++ b/parso/python/normalizer.py @@ -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): diff --git a/test/test_python_errors.py b/test/test_python_errors.py index 136f91a..bb7b3da 100644 --- a/test/test_python_errors.py +++ b/test/test_python_errors.py @@ -67,7 +67,8 @@ def test_indentation_errors(code, positions): finally: continue '''), # 'continue' not supported inside 'finally' clause" - 'continue' + 'continue', + 'break', # IndentationError ' foo',