Commit fdb191dc authored by Guido van Rossum's avatar Guido van Rossum

Add a simple optimizing pass. This collapses consecutive rawtext

items and start and end tags without attributes into a single rawtext
item.

We could do more, by also changing start tags with only plain
(non-substituted) attributes into rawtext and collapsing.  After
breakfast.
parent 6a8155da
......@@ -114,7 +114,34 @@ class TALGenerator:
return self.optimize(self.program), self.macros
def optimize(self, program):
return program # XXX later
output = []
collect = []
rawseen = cursor = 0
for cursor in xrange(len(program)+1):
try:
item = program[cursor]
except IndexError:
item = (None, None)
if item[0] == "rawtext":
collect.append(item[1])
continue
if item[0] == "endTag":
collect.append("</%s>" % item[1])
continue
if item[0] == "startTag" and not item[2]:
collect.append("<%s>" % item[1])
continue
if item[0] == "startEndTag" and not item[2]:
collect.append("<%s/>" % item[1])
continue
text = string.join(collect, "")
if text:
output.append(("rawtext", text))
if item[0] != None:
output.append(item)
rawseen = cursor+1
collect = []
return output
def todoPush(self, todo):
self.todoStack.append(todo)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment