forked from VimPlug/jedi
move current to _current in parsing
This commit is contained in:
@@ -57,7 +57,7 @@ class Parser(object):
|
|||||||
# initialize global Scope
|
# initialize global Scope
|
||||||
self.module = pr.SubModule(module_path, self.start_pos, top_module)
|
self.module = pr.SubModule(module_path, self.start_pos, top_module)
|
||||||
self._scope = self.module
|
self._scope = self.module
|
||||||
self.current = (None, None)
|
self._current = (None, None)
|
||||||
|
|
||||||
source = source + '\n' # end with \n, because the parser needs it
|
source = source + '\n' # end with \n, because the parser needs it
|
||||||
buf = StringIO(source)
|
buf = StringIO(source)
|
||||||
@@ -78,10 +78,10 @@ class Parser(object):
|
|||||||
# because of `self.module.used_names`.
|
# because of `self.module.used_names`.
|
||||||
d.parent = self.module
|
d.parent = self.module
|
||||||
|
|
||||||
if self.current[0] in (tokenize.NL, tokenize.NEWLINE):
|
if self._current[0] in (tokenize.NL, tokenize.NEWLINE):
|
||||||
# we added a newline before, so we need to "remove" it again.
|
# we added a newline before, so we need to "remove" it again.
|
||||||
self.end_pos = self._gen.previous[2]
|
self.end_pos = self._gen.previous[2]
|
||||||
if self.current[0] == tokenize.INDENT:
|
if self._current[0] == tokenize.INDENT:
|
||||||
self.end_pos = self._gen.last_previous[2]
|
self.end_pos = self._gen.last_previous[2]
|
||||||
|
|
||||||
self.start_pos = self.module.start_pos
|
self.start_pos = self.module.start_pos
|
||||||
@@ -180,7 +180,7 @@ class Parser(object):
|
|||||||
if tok == '(': # python allows only one `(` in the statement.
|
if tok == '(': # python allows only one `(` in the statement.
|
||||||
brackets = True
|
brackets = True
|
||||||
self.next()
|
self.next()
|
||||||
i, token_type, tok = self._parse_dot_name(self.current)
|
i, token_type, tok = self._parse_dot_name(self._current)
|
||||||
if not i:
|
if not i:
|
||||||
defunct = True
|
defunct = True
|
||||||
name2 = None
|
name2 = None
|
||||||
@@ -191,6 +191,7 @@ class Parser(object):
|
|||||||
token_type, tok = self.next()
|
token_type, tok = self.next()
|
||||||
if not (tok == "," or brackets and tok == '\n'):
|
if not (tok == "," or brackets and tok == '\n'):
|
||||||
break
|
break
|
||||||
|
print imports
|
||||||
return imports
|
return imports
|
||||||
|
|
||||||
def _parse_parentheses(self):
|
def _parse_parentheses(self):
|
||||||
@@ -349,11 +350,11 @@ class Parser(object):
|
|||||||
or tok in breaks and level <= 0):
|
or tok in breaks and level <= 0):
|
||||||
try:
|
try:
|
||||||
# print 'parse_stmt', tok, tokenize.tok_name[token_type]
|
# print 'parse_stmt', tok, tokenize.tok_name[token_type]
|
||||||
tok_list.append(self.current + (self.start_pos,))
|
tok_list.append(self._current + (self.start_pos,))
|
||||||
if tok == 'as':
|
if tok == 'as':
|
||||||
token_type, tok = self.next()
|
token_type, tok = self.next()
|
||||||
if token_type == tokenize.NAME:
|
if token_type == tokenize.NAME:
|
||||||
n, token_type, tok = self._parse_dot_name(self.current)
|
n, token_type, tok = self._parse_dot_name(self._current)
|
||||||
if n:
|
if n:
|
||||||
set_vars.append(n)
|
set_vars.append(n)
|
||||||
tok_list.append(n)
|
tok_list.append(n)
|
||||||
@@ -363,7 +364,7 @@ class Parser(object):
|
|||||||
if tok == 'lambda':
|
if tok == 'lambda':
|
||||||
breaks.discard(':')
|
breaks.discard(':')
|
||||||
elif token_type == tokenize.NAME:
|
elif token_type == tokenize.NAME:
|
||||||
n, token_type, tok = self._parse_dot_name(self.current)
|
n, token_type, tok = self._parse_dot_name(self._current)
|
||||||
# removed last entry, because we add Name
|
# removed last entry, because we add Name
|
||||||
tok_list.pop()
|
tok_list.pop()
|
||||||
if n:
|
if n:
|
||||||
@@ -445,9 +446,9 @@ class Parser(object):
|
|||||||
debug.dbg('user scope found [%s] = %s' %
|
debug.dbg('user scope found [%s] = %s' %
|
||||||
(self.parserline.replace('\n', ''), repr(self._scope)))
|
(self.parserline.replace('\n', ''), repr(self._scope)))
|
||||||
self.user_scope = self._scope
|
self.user_scope = self._scope
|
||||||
self.last_token = self.current
|
self.last_token = self._current
|
||||||
self.current = (typ, tok)
|
self._current = (typ, tok)
|
||||||
return self.current
|
return self._current
|
||||||
|
|
||||||
def _parse(self):
|
def _parse(self):
|
||||||
"""
|
"""
|
||||||
@@ -538,7 +539,7 @@ class Parser(object):
|
|||||||
break
|
break
|
||||||
relative_count += 1
|
relative_count += 1
|
||||||
# the from import
|
# the from import
|
||||||
mod, token_type, tok = self._parse_dot_name(self.current)
|
mod, token_type, tok = self._parse_dot_name(self._current)
|
||||||
if str(mod) == 'import' and relative_count:
|
if str(mod) == 'import' and relative_count:
|
||||||
self._gen.push_last_back()
|
self._gen.push_last_back()
|
||||||
tok = 'import'
|
tok = 'import'
|
||||||
@@ -645,7 +646,7 @@ class Parser(object):
|
|||||||
debug.warning('return in non-function')
|
debug.warning('return in non-function')
|
||||||
# globals
|
# globals
|
||||||
elif tok == 'global':
|
elif tok == 'global':
|
||||||
stmt, tok = self._parse_statement(self.current)
|
stmt, tok = self._parse_statement(self._current)
|
||||||
if stmt:
|
if stmt:
|
||||||
self._scope.add_statement(stmt)
|
self._scope.add_statement(stmt)
|
||||||
for name in stmt.used_vars:
|
for name in stmt.used_vars:
|
||||||
@@ -670,7 +671,7 @@ class Parser(object):
|
|||||||
# this is the main part - a name can be a function or a
|
# this is the main part - a name can be a function or a
|
||||||
# normal var, which can follow anything. but this is done
|
# normal var, which can follow anything. but this is done
|
||||||
# by the statement parser.
|
# by the statement parser.
|
||||||
stmt, tok = self._parse_statement(self.current)
|
stmt, tok = self._parse_statement(self._current)
|
||||||
if stmt:
|
if stmt:
|
||||||
self._scope.add_statement(stmt)
|
self._scope.add_statement(stmt)
|
||||||
self.freshscope = False
|
self.freshscope = False
|
||||||
|
|||||||
Reference in New Issue
Block a user