forked from VimPlug/jedi
KeywordStatements are working except for some of the old ones (global, assert, return, yield)
This commit is contained in:
@@ -573,6 +573,11 @@ class Parser(object):
|
|||||||
# add the global to the top, because there it is
|
# add the global to the top, because there it is
|
||||||
# important.
|
# important.
|
||||||
self.module.add_global(t)
|
self.module.add_global(t)
|
||||||
|
elif tok_str == 'assert':
|
||||||
|
stmt, tok = self._parse_statement()
|
||||||
|
if stmt is not None:
|
||||||
|
stmt.parent = use_as_parent_scope
|
||||||
|
self._scope.asserts.append(stmt)
|
||||||
elif tok_str in STATEMENT_KEYWORDS:
|
elif tok_str in STATEMENT_KEYWORDS:
|
||||||
stmt, _ = self._parse_statement()
|
stmt, _ = self._parse_statement()
|
||||||
k = pr.KeywordStatement(tok_str, tok.start_pos,
|
k = pr.KeywordStatement(tok_str, tok.start_pos,
|
||||||
@@ -585,11 +590,6 @@ class Parser(object):
|
|||||||
self._decorators.append(stmt)
|
self._decorators.append(stmt)
|
||||||
elif tok_str == 'pass':
|
elif tok_str == 'pass':
|
||||||
continue
|
continue
|
||||||
elif tok_str == 'assert':
|
|
||||||
stmt, tok = self._parse_statement()
|
|
||||||
if stmt is not None:
|
|
||||||
stmt.parent = use_as_parent_scope
|
|
||||||
self._scope.asserts.append(stmt)
|
|
||||||
# default
|
# default
|
||||||
elif token_type in [tokenize.NAME, tokenize.STRING,
|
elif token_type in [tokenize.NAME, tokenize.STRING,
|
||||||
tokenize.NUMBER] \
|
tokenize.NUMBER] \
|
||||||
|
|||||||
@@ -101,6 +101,23 @@ class Base(object):
|
|||||||
#TODO: we need tab detection
|
#TODO: we need tab detection
|
||||||
return " "
|
return " "
|
||||||
|
|
||||||
|
@Python3Method
|
||||||
|
def get_parent_until(self, classes=(), reverse=False,
|
||||||
|
include_current=True):
|
||||||
|
"""
|
||||||
|
Searches the parent "chain" until the object is an instance of
|
||||||
|
classes. If classes is empty return the last parent in the chain
|
||||||
|
(is without a parent).
|
||||||
|
"""
|
||||||
|
if type(classes) not in (tuple, list):
|
||||||
|
classes = (classes,)
|
||||||
|
scope = self if include_current else self.parent
|
||||||
|
while scope.parent is not None:
|
||||||
|
if classes and reverse != scope.isinstance(*classes):
|
||||||
|
break
|
||||||
|
scope = scope.parent
|
||||||
|
return scope
|
||||||
|
|
||||||
def space(self, from_pos, to_pos):
|
def space(self, from_pos, to_pos):
|
||||||
"""Return the space between two tokens"""
|
"""Return the space between two tokens"""
|
||||||
linecount = to_pos[0] - from_pos[0]
|
linecount = to_pos[0] - from_pos[0]
|
||||||
@@ -160,19 +177,6 @@ class Simple(Base):
|
|||||||
def end_pos(self, value):
|
def end_pos(self, value):
|
||||||
self._end_pos = value
|
self._end_pos = value
|
||||||
|
|
||||||
@Python3Method
|
|
||||||
def get_parent_until(self, classes=(), reverse=False,
|
|
||||||
include_current=True):
|
|
||||||
""" Takes always the parent, until one class (not a Class) """
|
|
||||||
if type(classes) not in (tuple, list):
|
|
||||||
classes = (classes,)
|
|
||||||
scope = self if include_current else self.parent
|
|
||||||
while scope.parent is not None:
|
|
||||||
if classes and reverse != scope.isinstance(*classes):
|
|
||||||
break
|
|
||||||
scope = scope.parent
|
|
||||||
return scope
|
|
||||||
|
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
code = self.get_code().replace('\n', ' ')
|
code = self.get_code().replace('\n', ' ')
|
||||||
if not is_py3:
|
if not is_py3:
|
||||||
@@ -801,7 +805,7 @@ class Import(Simple):
|
|||||||
return n
|
return n
|
||||||
|
|
||||||
|
|
||||||
class KeywordStatement(object):
|
class KeywordStatement(Base):
|
||||||
"""
|
"""
|
||||||
For the following statements: `assert`, `del`, `global`, `nonlocal`,
|
For the following statements: `assert`, `del`, `global`, `nonlocal`,
|
||||||
`raise`, `return`, `yield`, `pass`, `continue`, `break`, `return`, `yield`.
|
`raise`, `return`, `yield`, `pass`, `continue`, `break`, `return`, `yield`.
|
||||||
@@ -819,9 +823,19 @@ class KeywordStatement(object):
|
|||||||
|
|
||||||
def get_code(self):
|
def get_code(self):
|
||||||
if self._stmt is None:
|
if self._stmt is None:
|
||||||
return self.name
|
return "%s\n" % self.name
|
||||||
else:
|
else:
|
||||||
return '%s %s' % (self.name, self._stmt)
|
return '%s %s\n' % (self.name, self._stmt)
|
||||||
|
|
||||||
|
def get_set_vars(self):
|
||||||
|
return []
|
||||||
|
|
||||||
|
@property
|
||||||
|
def end_pos(self):
|
||||||
|
try:
|
||||||
|
return self._stmt.end_pos
|
||||||
|
except AttributeError:
|
||||||
|
return self.start_pos[0], self.start_pos[1] + len(self.name)
|
||||||
|
|
||||||
|
|
||||||
class Statement(Simple, DocstringMixin):
|
class Statement(Simple, DocstringMixin):
|
||||||
|
|||||||
Reference in New Issue
Block a user