This commit is contained in:
David Halter
2012-04-24 16:01:55 +02:00
parent 7de81ca4a5
commit 470e52e95d
3 changed files with 52 additions and 22 deletions

View File

@@ -347,16 +347,10 @@ def assign_tuples(tup, results, seek_name):
# check the left part, if it's still tuples in it or a Call # check the left part, if it's still tuples in it or a Call
if isinstance(t, parsing.Array): if isinstance(t, parsing.Array):
# these are "sub" tuples # these are "sub" tuples
print 'arr', t
result += assign_tuples(t, eval_results(i), seek_name) result += assign_tuples(t, eval_results(i), seek_name)
print 'arr2', result
else: else:
if t.name.names[-1] == seek_name: if t.name.names[-1] == seek_name:
result += eval_results(i) result += eval_results(i)
print 't', t, result
else:
print 'name not found', t.name
print seek_name, tup, results
return result return result
@memoize(default=[]) @memoize(default=[])
@@ -375,14 +369,9 @@ def follow_statement(stmt, scope=None, seek_name=None):
# assignment checking is only important if the statement defines multiple # assignment checking is only important if the statement defines multiple
# variables # variables
if len(stmt.get_set_vars()) > 1 and seek_name and stmt.assignment_details: if len(stmt.get_set_vars()) > 1 and seek_name and stmt.assignment_details:
print 'seek', seek_name
new_result = [] new_result = []
for op, set_vars in stmt.assignment_details: for op, set_vars in stmt.assignment_details:
print '\ntup'
new_result += assign_tuples(set_vars, result, seek_name) new_result += assign_tuples(set_vars, result, seek_name)
print new_result
print '\n\nlala', op, set_vars.values, call_list.values
print stmt, scope
result = new_result result = new_result
return result return result
@@ -392,15 +381,17 @@ def follow_call_list(scope, call_list):
The call list has a special structure. The call list has a special structure.
This can be either `parsing.Array` or `list`. This can be either `parsing.Array` or `list`.
""" """
if isinstance(call_list, parsing.Array) \ if parsing.Array.is_type(call_list, parsing.Array.TUPLE):
and call_list.type != parsing.Array.NOARRAY: # Tuples can stand just alone without any braces. These would be
# Especially tuples can stand just alone without any braces. These # recognized as separate calls, but actually are a tuple.
# would be recognized as separate calls, but actually are a tuple.
result = follow_call(scope, call_list) result = follow_call(scope, call_list)
else: else:
result = [] result = []
for calls in call_list: for calls in call_list:
for call in calls: for call in calls:
if parsing.Array.is_type(call, parsing.Array.NOARRAY):
result += follow_call_list(scope, call)
else:
if not isinstance(call, str): if not isinstance(call, str):
# The string tokens are just operations (+, -, etc.) # The string tokens are just operations (+, -, etc.)
result += follow_call(scope, call) result += follow_call(scope, call)
@@ -444,9 +435,6 @@ def follow_paths(path, results):
for i, r in enumerate(results): for i, r in enumerate(results):
results_new += follow_path(iter_paths[i], r) results_new += follow_path(iter_paths[i], r)
except StopIteration: except StopIteration:
#if isinstance(s, parsing.Array):
# completions += s.
#else:
return results return results
return results_new return results_new

View File

@@ -808,6 +808,16 @@ class Array(Call):
raise AttributeError("More than one value found") raise AttributeError("More than one value found")
return self.values[0][0] return self.values[0][0]
@staticmethod
def is_type(instance, typ):
"""
This is not only used for calls on the actual object, but for
ducktyping, to invoke this function with anything as `self`.
"""
if isinstance(instance, Array):
if instance.type == typ:
return True
return False
def __len__(self): def __len__(self):
return len(self.values) return len(self.values)

View File

@@ -32,11 +32,28 @@ a2.imag
#? ['upper'] #? ['upper']
b2.upper b2.upper
# list assignment
[list1, list2] = (1, "")
#? ['real']
list1.real
#? ['lower']
list2.lower
#? []
list2.real
[list3, list4] = [1, ""]
#? ['real']
list3.real
#? ['lower']
list4.lower
#? []
list4.real
# ----------------- # -----------------
# subtuple assignment # subtuple assignment
# ----------------- # -----------------
(a3, (b3, c3)) = (1, ("", list)) (a3, (b3, c3)) = (1, ("", list))
##? ['append'] #? ['append']
c3.append c3.append
#? [] #? []
c3.upper c3.upper
@@ -59,8 +76,23 @@ b4.upper
# ----------------- # -----------------
# unnessecary braces # unnessecary braces
# ----------------- # -----------------
#? ['real']
(1).real
#? ['real']
((1)).real
#? ['real']
((1)+1).real
u, v = 1, "" u, v = 1, ""
#? ['real'] #? ['real']
u.real u.real
#? [] #? []
u.upper u.upper
((u1, v1)) = 1, ""
#? ['real']
u1.real
#? ['real']
(u1).real
#? []
u1.upper