mirror of
https://github.com/davidhalter/parso.git
synced 2026-05-18 06:20:03 +08:00
Move more stuff and fix tests.
This commit is contained in:
+5
-5
@@ -76,12 +76,12 @@ class Normalizer(use_metaclass(_NormalizerMeta)):
|
|||||||
@classmethod
|
@classmethod
|
||||||
def register_rule(cls, **kwargs):
|
def register_rule(cls, **kwargs):
|
||||||
"""
|
"""
|
||||||
Use it as a class decorator:
|
Use it as a class decorator::
|
||||||
|
|
||||||
>>> normalizer = Normalizer('grammar', 'config')
|
normalizer = Normalizer('grammar', 'config')
|
||||||
>>> @normalizer.register_rule(value='foo')
|
@normalizer.register_rule(value='foo')
|
||||||
... class MyRule(Rule):
|
class MyRule(Rule):
|
||||||
... error_code = 42
|
error_code = 42
|
||||||
"""
|
"""
|
||||||
return cls._register_rule(**kwargs)
|
return cls._register_rule(**kwargs)
|
||||||
|
|
||||||
|
|||||||
+13
-8
@@ -655,13 +655,6 @@ 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 in ('for_stmt', 'while_stmt'):
|
|
||||||
in_loop = True
|
|
||||||
if not in_loop:
|
|
||||||
self._add_syntax_error("'break' outside loop", leaf)
|
|
||||||
elif leaf.value in ('yield', 'return'):
|
elif leaf.value in ('yield', 'return'):
|
||||||
if self.context.node.type != 'funcdef':
|
if self.context.node.type != 'funcdef':
|
||||||
self._add_syntax_error("'%s' outside function" % leaf.value, leaf.parent)
|
self._add_syntax_error("'%s' outside function" % leaf.value, leaf.parent)
|
||||||
@@ -797,7 +790,7 @@ class IndentationRule(Rule):
|
|||||||
|
|
||||||
|
|
||||||
@ErrorFinder.register_rule(value='await')
|
@ErrorFinder.register_rule(value='await')
|
||||||
class AwaitOutsideAsync(SyntaxRule):
|
class _AwaitOutsideAsync(SyntaxRule):
|
||||||
message = "'await' outside async function"
|
message = "'await' outside async function"
|
||||||
|
|
||||||
def is_issue(self, leaf):
|
def is_issue(self, leaf):
|
||||||
@@ -806,3 +799,15 @@ class AwaitOutsideAsync(SyntaxRule):
|
|||||||
def get_error_node(self, node):
|
def get_error_node(self, node):
|
||||||
# Return the whole await statement.
|
# Return the whole await statement.
|
||||||
return node.parent
|
return node.parent
|
||||||
|
|
||||||
|
|
||||||
|
@ErrorFinder.register_rule(value='break')
|
||||||
|
class _BreakOutsideLoop(SyntaxRule):
|
||||||
|
message = "'break' outside loop"
|
||||||
|
|
||||||
|
def is_issue(self, leaf):
|
||||||
|
in_loop = False
|
||||||
|
for block in self._normalizer.context.blocks:
|
||||||
|
if block.type in ('for_stmt', 'while_stmt'):
|
||||||
|
in_loop = True
|
||||||
|
return not in_loop
|
||||||
|
|||||||
@@ -712,10 +712,11 @@ class PEP8NormalizerConfig(ErrorFinderConfig):
|
|||||||
self.spaces_before_comment = spaces_before_comment
|
self.spaces_before_comment = spaces_before_comment
|
||||||
|
|
||||||
|
|
||||||
@PEP8Normalizer.register_rule(type='endmarker')
|
# TODO this is not yet ready.
|
||||||
|
#@PEP8Normalizer.register_rule(type='endmarker')
|
||||||
class BlankLineAtEnd(Rule):
|
class BlankLineAtEnd(Rule):
|
||||||
code = 392
|
code = 392
|
||||||
message = 'Blank line at end of file'
|
message = 'Blank line at end of file'
|
||||||
|
|
||||||
def check(self, leaf):
|
def is_issue(self, leaf):
|
||||||
return self._newline_count >= 2
|
return self._newline_count >= 2
|
||||||
|
|||||||
Reference in New Issue
Block a user