aboutsummaryrefslogtreecommitdiffstats
path: root/auto-auto-complete.py
diff options
context:
space:
mode:
authorMattias Andrée <maandree@operamail.com>2012-10-28 21:03:02 +0100
committerMattias Andrée <maandree@operamail.com>2012-10-28 21:03:02 +0100
commiteb9dc56f5c8df4f6572cf249899894ba594ea1ad (patch)
tree4f41fc4244dbfe93dc2b8283f08761d733148b16 /auto-auto-complete.py
parentwhoops (diff)
downloadauto-auto-complete-eb9dc56f5c8df4f6572cf249899894ba594ea1ad.tar.gz
auto-auto-complete-eb9dc56f5c8df4f6572cf249899894ba594ea1ad.tar.bz2
auto-auto-complete-eb9dc56f5c8df4f6572cf249899894ba594ea1ad.tar.xz
simplifing the tree
Diffstat (limited to '')
-rwxr-xr-xauto-auto-complete.py42
1 files changed, 41 insertions, 1 deletions
diff --git a/auto-auto-complete.py b/auto-auto-complete.py
index 53b455a..0865bca 100755
--- a/auto-auto-complete.py
+++ b/auto-auto-complete.py
@@ -98,6 +98,9 @@ class Parser:
else:
stack[stackptr] = []
elif (c == ')') and (quote is None):
+ if buf is not None:
+ stack[stackptr].append(buf)
+ buf = None
if stackptr == 0:
return stack[0]
stackptr -= 1
@@ -117,7 +120,43 @@ class Parser:
buf += c
raise Exception('premature end of file')
-
+
+
+ '''
+ Simplifies a tree
+
+ @param tree:list<↑|str> The tree
+ '''
+ @staticmethod
+ def simplify(tree):
+ program = tree[0]
+ stack = [tree]
+ while len(stack) > 0:
+ node = stack.pop()
+ new = []
+ edited = False
+ for item in node:
+ if isinstance(item, list):
+ if item[0] == 'multiple':
+ master = item[1]
+ for slave in item[2:]:
+ new.append([master] + slave)
+ edited = True
+ elif item[0] == 'case':
+ for alt in item[1:]:
+ if alt[0] == program:
+ new.append(alt[1])
+ break
+ edited = True
+ else:
+ new.append(item)
+ else:
+ new.append(item)
+ if edited:
+ node[:] = new
+ for item in node:
+ if isinstance(item, list):
+ stack.append(item)
'''
@@ -166,6 +205,7 @@ if __name__ == '__main__':
with open(source, 'rb') as file:
source = file.read().decode('utf8', 'replace')
source = Parser.parse(source)
+ Parser.simplify(source)
print(source)