mirror of
https://github.com/davidhalter/parso.git
synced 2025-12-08 05:34:51 +08:00
break should be in loop.
This commit is contained in:
@@ -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):
|
||||||
|
|||||||
@@ -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',
|
||||||
|
|||||||
Reference in New Issue
Block a user