1
0
forked from VimPlug/jedi

StatementElement instead of Call and Call now inherits from that

This commit is contained in:
David Halter
2013-09-05 21:50:05 +04:30
parent 458497747b
commit 9e54abaf22
5 changed files with 34 additions and 24 deletions

View File

@@ -575,7 +575,7 @@ def _check_isinstance_type(stmt, search_name):
assert isinstance(obj[0], pr.Call) assert isinstance(obj[0], pr.Call)
# names fit? # names fit?
assert str(obj[0].name) == search_name assert str(obj[0].name) == search_name
assert isinstance(classes[0], pr.Call) # can be type or tuple assert isinstance(classes[0], pr.StatementElement) # can be type or tuple
except AssertionError: except AssertionError:
return [] return []

View File

@@ -668,7 +668,7 @@ def follow_call_list(call_list, follow_array=False):
result.append(call) result.append(call)
# The string tokens are just operations (+, -, etc.) # The string tokens are just operations (+, -, etc.)
elif not isinstance(call, (str, unicode)): elif not isinstance(call, (str, unicode)):
if str(call.name) == 'if': if isinstance(call, pr.Call) and str(call.name) == 'if':
# Ternary operators. # Ternary operators.
while True: while True:
try: try:

View File

@@ -677,7 +677,7 @@ class Execution(Executable):
call = key_stmt.get_commands()[0] call = key_stmt.get_commands()[0]
if isinstance(call, pr.Name): if isinstance(call, pr.Name):
yield call, value_stmt yield call, value_stmt
elif type(call) is pr.Call: elif isinstance(call, pr.Call):
yield call.name, value_stmt yield call.name, value_stmt
# Normal arguments (including key arguments). # Normal arguments (including key arguments).
else: else:

View File

@@ -321,7 +321,8 @@ def sys_path_with_modifications(module):
if not isinstance(p, pr.Statement): if not isinstance(p, pr.Statement):
continue continue
commands = p.get_commands() commands = p.get_commands()
if len(commands) != 1: # sys.path command is just one thing. # sys.path command is just one thing.
if len(commands) != 1 or not isinstance(commands[0], pr.Call):
continue continue
call = commands[0] call = commands[0]
n = call.name n = call.name

View File

@@ -1069,13 +1069,13 @@ class Statement(Simple):
elif tok in brackets.keys(): elif tok in brackets.keys():
arr, is_ass = parse_array(token_iterator, brackets[tok], arr, is_ass = parse_array(token_iterator, brackets[tok],
start_pos) start_pos)
if result and isinstance(result[-1], Call): if result and isinstance(result[-1], StatementElement):
result[-1].set_execution(arr) result[-1].set_execution(arr)
else: else:
arr.parent = self arr.parent = self
result.append(arr) result.append(arr)
elif tok == '.': elif tok == '.':
if result and isinstance(result[-1], Call): if result and isinstance(result[-1], StatementElement):
is_chain = True is_chain = True
elif tok == ',': # implies a tuple elif tok == ',': # implies a tuple
# commands is now an array not a statement anymore # commands is now an array not a statement anymore
@@ -1140,18 +1140,9 @@ class Param(Statement):
return n[0] return n[0]
class Call(Simple): class StatementElement(Simple):
""" def __init__(self, module, type, start_pos, end_pos, parent):
`Call` contains a call, e.g. `foo.bar` and owns the executions of those super(StatementElement, self).__init__(module, start_pos, end_pos)
calls, which are `Array`s.
"""
NAME = 1
NUMBER = 2
STRING = 3
def __init__(self, module, name, type, start_pos, end_pos, parent=None):
super(Call, self).__init__(module, start_pos, end_pos)
self.name = name
# parent is not the oposite of next. The parent of c: a = [b.c] would # parent is not the oposite of next. The parent of c: a = [b.c] would
# be an array. # be an array.
self.parent = parent self.parent = parent
@@ -1196,22 +1187,40 @@ class Call(Simple):
yield y yield y
def get_code(self): def get_code(self):
if self.type == Call.NAME: s = ''
s = self.name.get_code()
else:
s = '' if self.name is None else repr(self.name)
if self.execution is not None: if self.execution is not None:
s += self.execution.get_code() s += self.execution.get_code()
if self.next is not None: if self.next is not None:
s += '.' + self.next.get_code() s += '.' + self.next.get_code()
return s return s
class Call(StatementElement):
"""
`Call` contains a call, e.g. `foo.bar` and owns the executions of those
calls, which are `Array`s.
"""
NAME = 1
NUMBER = 2
STRING = 3
def __init__(self, module, name, type, start_pos, end_pos, parent=None):
super(Call, self).__init__(module, type, start_pos, end_pos, parent)
self.name = name
def get_code(self):
if self.type == Call.NAME:
s = self.name.get_code()
else:
s = '' if self.name is None else repr(self.name)
return s + super(Call, self).get_code()
def __repr__(self): def __repr__(self):
return "<%s: %s>" % \ return "<%s: %s>" % \
(type(self).__name__, self.name) (type(self).__name__, self.name)
class Array(Call): class Array(StatementElement):
""" """
Describes the different python types for an array, but also empty Describes the different python types for an array, but also empty
statements. In the Python syntax definitions this type is named 'atom'. statements. In the Python syntax definitions this type is named 'atom'.
@@ -1229,7 +1238,7 @@ class Array(Call):
SET = 'set' SET = 'set'
def __init__(self, module, start_pos, arr_type=NOARRAY, parent=None): def __init__(self, module, start_pos, arr_type=NOARRAY, parent=None):
super(Array, self).__init__(module, None, arr_type, start_pos, (None, None), parent) super(Array, self).__init__(module, arr_type, start_pos, (None, None), parent)
self.end_pos = None, None self.end_pos = None, None
self.values = [] self.values = []
self.keys = [] self.keys = []