1
0
forked from VimPlug/jedi

removed code part of Statement

This commit is contained in:
David Halter
2013-02-21 21:26:22 +04:30
parent 0084b9f04d
commit 774c191d7e
3 changed files with 13 additions and 37 deletions

View File

@@ -508,7 +508,7 @@ class Execution(Executable):
arr.values = values arr.values = values
key_stmts = [] key_stmts = []
for key in keys: for key in keys:
stmt = pr.Statement(self._sub_module, 'XXX code', [], [], [], [], stmt = pr.Statement(self._sub_module, [], [], [], [],
start_pos, None) start_pos, None)
stmt._commands = [key] stmt._commands = [key]
key_stmts.append(stmt) key_stmts.append(stmt)
@@ -624,7 +624,7 @@ class Execution(Executable):
old = stmt old = stmt
# generate a statement if it's not already one. # generate a statement if it's not already one.
module = builtin.Builtin.scope module = builtin.Builtin.scope
stmt = pr.Statement(module, 'XXX code', [], [], [], [], (0, 0), None) stmt = pr.Statement(module, [], [], [], [], (0, 0), None)
stmt._commands = [old] stmt._commands = [old]
# *args # *args

View File

@@ -14,12 +14,10 @@ being parsed completely. ``Statement`` is just a representation of the tokens
within the statement. This lowers memory usage and cpu time and reduces the within the statement. This lowers memory usage and cpu time and reduces the
complexity of the ``Parser`` (there's another parser sitting inside complexity of the ``Parser`` (there's another parser sitting inside
``Statement``, which produces ``Array`` and ``Call``). ``Statement``, which produces ``Array`` and ``Call``).
""" """
from _compatibility import next, StringIO, unicode from _compatibility import next, StringIO
import tokenize import tokenize
import re
import keyword import keyword
import debug import debug
@@ -313,8 +311,6 @@ class Parser(object):
:return: Statement + last parsed token. :return: Statement + last parsed token.
:rtype: (Statement, str) :rtype: (Statement, str)
""" """
string = unicode('')
set_vars = [] set_vars = []
used_funcs = [] used_funcs = []
used_vars = [] used_vars = []
@@ -350,18 +346,15 @@ class Parser(object):
or tok in not_first_break and not tok_list or tok in not_first_break and not tok_list
or tok in breaks and level <= 0): or tok in breaks and level <= 0):
try: try:
set_string = None
#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':
string += " %s " % tok
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)
string += ".".join(n.names)
continue continue
elif tok == 'lambda': elif tok == 'lambda':
params = [] params = []
@@ -428,19 +421,12 @@ class Parser(object):
i = 0 i = 0
tok_list, toks = tok_list[:-i], tok_list[-i:-1] tok_list, toks = tok_list[:-i], tok_list[-i:-1]
src = '' st = pr.Statement(self.module, [], [], [],
for t in toks:
src += t[1] if isinstance(t, tuple) \
else t.get_code()
st = pr.Statement(self.module, src, [], [], [],
toks, first_pos, self.end_pos) toks, first_pos, self.end_pos)
tok = pr.ListComprehension(st, middle, in_clause, tok = pr.ListComprehension(st, middle, in_clause,
self.scope) self.scope)
tok_list.append(tok) tok_list.append(tok)
if list_comp:
string = ''
string += tok.get_code()
continue continue
else: else:
n, token_type, tok = self._parse_dot_name(self.current) n, token_type, tok = self._parse_dot_name(self.current)
@@ -453,9 +439,6 @@ class Parser(object):
used_funcs.append(n) used_funcs.append(n)
else: else:
used_vars.append(n) used_vars.append(n)
if string and re.match(r'[\w\d\'"]', string[-1]):
string += ' '
string += ".".join(n.names)
continue continue
elif tok.endswith('=') and tok not in ['>=', '<=', '==', '!=']: elif tok.endswith('=') and tok not in ['>=', '<=', '==', '!=']:
# there has been an assignement -> change vars # there has been an assignement -> change vars
@@ -467,21 +450,20 @@ class Parser(object):
elif tok in closing_brackets: elif tok in closing_brackets:
level -= 1 level -= 1
string = set_string if set_string is not None else string + tok
token_type, tok = self.next() token_type, tok = self.next()
except (StopIteration, common.MultiLevelStopIteration): except (StopIteration, common.MultiLevelStopIteration):
# comes from tokenizer # comes from tokenizer
break break
if not string: if not tok_list:
return None, tok return None, tok
#print 'new_stat', string, set_vars, used_funcs, used_vars #print 'new_stat', set_vars, used_funcs, used_vars
if self.freshscope and not self.no_docstr and len(tok_list) == 1 \ if self.freshscope and not self.no_docstr and len(tok_list) == 1 \
and self.last_token[0] == tokenize.STRING: and self.last_token[0] == tokenize.STRING:
self.scope.add_docstr(self.last_token[1]) self.scope.add_docstr(self.last_token[1])
return None, tok return None, tok
else: else:
stmt = stmt_class(self.module, string, set_vars, used_funcs, stmt = stmt_class(self.module, set_vars, used_funcs,
used_vars, tok_list, first_pos, self.end_pos) used_vars, tok_list, first_pos, self.end_pos)
self._check_user_stmt(stmt) self._check_user_stmt(stmt)
@@ -667,7 +649,6 @@ class Parser(object):
n, token_type, tok = self._parse_dot_name() n, token_type, tok = self._parse_dot_name()
if n: if n:
statement.set_vars.append(n) statement.set_vars.append(n)
statement.code += ',' + n.get_code()
if statement: if statement:
inputs.append(statement) inputs.append(statement)
first = False first = False

View File

@@ -649,9 +649,6 @@ class Statement(Simple):
stores pretty much all the Python code, except functions, classes, imports, stores pretty much all the Python code, except functions, classes, imports,
and flow functions like if, for, etc. and flow functions like if, for, etc.
:param code: The full code of a statement. This is import, if one wants \
to execute the code at some level.
:param code: str
:param set_vars: The variables which are defined by the statement. :param set_vars: The variables which are defined by the statement.
:param set_vars: str :param set_vars: str
:param used_funcs: The functions which are used by the statement. :param used_funcs: The functions which are used by the statement.
@@ -663,14 +660,12 @@ class Statement(Simple):
:param start_pos: Position (line, column) of the Statement. :param start_pos: Position (line, column) of the Statement.
:type start_pos: tuple(int, int) :type start_pos: tuple(int, int)
""" """
__slots__ = ('used_funcs', 'code', 'token_list', 'used_vars', __slots__ = ('used_funcs', 'token_list', 'used_vars',
'set_vars', '_commands', '_assignment_details') 'set_vars', '_commands', '_assignment_details')
def __init__(self, module, code, set_vars, used_funcs, used_vars, def __init__(self, module, set_vars, used_funcs, used_vars,
token_list, start_pos, end_pos, parent=None): token_list, start_pos, end_pos, parent=None):
super(Statement, self).__init__(module, start_pos, end_pos) super(Statement, self).__init__(module, start_pos, end_pos)
# TODO remove code -> much cleaner
self.code = code
self.used_funcs = used_funcs self.used_funcs = used_funcs
self.used_vars = used_vars self.used_vars = used_vars
self.token_list = token_list self.token_list = token_list
@@ -847,7 +842,7 @@ class Statement(Simple):
if not token_list: if not token_list:
return None, tok return None, tok
statement = Statement(self._sub_module, "XXX" + self.code, [], [], [], statement = Statement(self._sub_module, [], [], [],
token_list, start_pos, end_pos) token_list, start_pos, end_pos)
statement.parent = self.parent statement.parent = self.parent
return statement, tok return statement, tok
@@ -932,9 +927,9 @@ class Param(Statement):
__slots__ = ('position_nr', 'is_generated', 'annotation_stmt', __slots__ = ('position_nr', 'is_generated', 'annotation_stmt',
'parent_function') 'parent_function')
def __init__(self, module, code, set_vars, used_funcs, used_vars, def __init__(self, module, set_vars, used_funcs, used_vars,
token_list, start_pos, end_pos): token_list, start_pos, end_pos):
super(Param, self).__init__(module, code, set_vars, used_funcs, super(Param, self).__init__(module, set_vars, used_funcs,
used_vars, token_list, start_pos, end_pos) used_vars, token_list, start_pos, end_pos)
# this is defined by the parser later on, not at the initialization # this is defined by the parser later on, not at the initialization