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
if isinstance(t, parsing.Array):
# these are "sub" tuples
print 'arr', t
result += assign_tuples(t, eval_results(i), seek_name)
print 'arr2', result
else:
if t.name.names[-1] == seek_name:
result += eval_results(i)
print 't', t, result
else:
print 'name not found', t.name
print seek_name, tup, results
return result
@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
# variables
if len(stmt.get_set_vars()) > 1 and seek_name and stmt.assignment_details:
print 'seek', seek_name
new_result = []
for op, set_vars in stmt.assignment_details:
print '\ntup'
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
return result
@@ -392,18 +381,20 @@ def follow_call_list(scope, call_list):
The call list has a special structure.
This can be either `parsing.Array` or `list`.
"""
if isinstance(call_list, parsing.Array) \
and call_list.type != parsing.Array.NOARRAY:
# Especially tuples can stand just alone without any braces. These
# would be recognized as separate calls, but actually are a tuple.
if parsing.Array.is_type(call_list, parsing.Array.TUPLE):
# Tuples can stand just alone without any braces. These would be
# recognized as separate calls, but actually are a tuple.
result = follow_call(scope, call_list)
else:
result = []
for calls in call_list:
for call in calls:
if not isinstance(call, str):
# The string tokens are just operations (+, -, etc.)
result += follow_call(scope, call)
if parsing.Array.is_type(call, parsing.Array.NOARRAY):
result += follow_call_list(scope, call)
else:
if not isinstance(call, str):
# The string tokens are just operations (+, -, etc.)
result += follow_call(scope, call)
return result
@@ -444,9 +435,6 @@ def follow_paths(path, results):
for i, r in enumerate(results):
results_new += follow_path(iter_paths[i], r)
except StopIteration:
#if isinstance(s, parsing.Array):
# completions += s.
#else:
return results
return results_new

View File

@@ -808,6 +808,16 @@ class Array(Call):
raise AttributeError("More than one value found")
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):
return len(self.values)

View File

@@ -32,11 +32,28 @@ a2.imag
#? ['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
# -----------------
(a3, (b3, c3)) = (1, ("", list))
##? ['append']
#? ['append']
c3.append
#? []
c3.upper
@@ -59,8 +76,23 @@ b4.upper
# -----------------
# unnessecary braces
# -----------------
#? ['real']
(1).real
#? ['real']
((1)).real
#? ['real']
((1)+1).real
u, v = 1, ""
#? ['real']
u.real
#? []
u.upper
((u1, v1)) = 1, ""
#? ['real']
u1.real
#? ['real']
(u1).real
#? []
u1.upper