mirror of
https://github.com/davidhalter/jedi.git
synced 2026-05-19 23:09:43 +08:00
Check more precisely for flow keywords.
This commit is contained in:
+7
-4
@@ -15,7 +15,7 @@ from jedi import debug
|
|||||||
from jedi.parser.tokenize import (source_tokens, NEWLINE,
|
from jedi.parser.tokenize import (source_tokens, NEWLINE,
|
||||||
ENDMARKER, INDENT, DEDENT)
|
ENDMARKER, INDENT, DEDENT)
|
||||||
|
|
||||||
FLOWS = ['if', 'else', 'elif', 'while', 'with', 'try', 'except', 'finally', 'for']
|
FLOWS = 'if', 'else', 'elif', 'while', 'with', 'try', 'except', 'finally', 'for'
|
||||||
|
|
||||||
|
|
||||||
class FastModule(pr.Module):
|
class FastModule(pr.Module):
|
||||||
@@ -220,8 +220,11 @@ class ParserNode(object):
|
|||||||
|
|
||||||
|
|
||||||
class FastParser(use_metaclass(CachedFastParser)):
|
class FastParser(use_metaclass(CachedFastParser)):
|
||||||
|
_FLOWS_NEED_SPACE = 'if', 'elif', 'while', 'with', 'except', 'for'
|
||||||
_keyword_re = re.compile('^[ \t]*(def |class |@|%s)' % '|'.join(FLOWS))
|
_FLOWS_NEED_COLON = 'else', 'try', 'except', 'finally'
|
||||||
|
_keyword_re = re.compile('^[ \t]*(def |class |@|(?:%s)|(?:%s)\s*:)'
|
||||||
|
% ('|'.join(_FLOWS_NEED_SPACE),
|
||||||
|
'|'.join(_FLOWS_NEED_COLON)))
|
||||||
|
|
||||||
def __init__(self, grammar, source, module_path=None):
|
def __init__(self, grammar, source, module_path=None):
|
||||||
# set values like `pr.Module`.
|
# set values like `pr.Module`.
|
||||||
@@ -300,7 +303,7 @@ class FastParser(use_metaclass(CachedFastParser)):
|
|||||||
if not in_flow:
|
if not in_flow:
|
||||||
m = self._keyword_re.match(l)
|
m = self._keyword_re.match(l)
|
||||||
if m:
|
if m:
|
||||||
in_flow = m.group(1) in FLOWS
|
in_flow = m.group(1).strip(' \t\r\n:') in FLOWS
|
||||||
if not is_decorator and not in_flow:
|
if not is_decorator and not in_flow:
|
||||||
if not just_newlines(current_lines):
|
if not just_newlines(current_lines):
|
||||||
yield gen_part()
|
yield gen_part()
|
||||||
|
|||||||
Reference in New Issue
Block a user