Commit 5560cbeb authored by Guido van Rossum's avatar Guido van Rossum

Whenever a tag has any TAL content, emit the new tagDict opcode with a

dict of the raw attribute values.  Also, put beginScope/endScope
around each tag for which a tagDict is emitted, rather than only for
tags using define or repeat.  This affects the generated code, but
doesn't affect semantics (according to the tests).
parent 2175aad2
...@@ -408,8 +408,10 @@ class TALGenerator: ...@@ -408,8 +408,10 @@ class TALGenerator:
if fillSlot: if fillSlot:
self.pushProgram() self.pushProgram()
todo["fillSlot"] = fillSlot todo["fillSlot"] = fillSlot
if define: if taldict:
self.emit("beginScope") self.emit("beginScope")
self.emit("tagDict", self.makeAttrDict(attrlist))
todo["scope"] = 1
if onError: if onError:
self.pushProgram() # handler self.pushProgram() # handler
self.emitStartTag(name, attrlist) self.emitStartTag(name, attrlist)
...@@ -423,7 +425,6 @@ class TALGenerator: ...@@ -423,7 +425,6 @@ class TALGenerator:
todo["condition"] = condition todo["condition"] = condition
if repeat: if repeat:
todo["repeat"] = repeat todo["repeat"] = repeat
self.emit("beginScope")
self.pushProgram() self.pushProgram()
if repeatWhitespace: if repeatWhitespace:
self.emitText(repeatWhitespace) self.emitText(repeatWhitespace)
...@@ -435,7 +436,7 @@ class TALGenerator: ...@@ -435,7 +436,7 @@ class TALGenerator:
if attrsubst: if attrsubst:
repldict = parseAttributeReplacements(attrsubst) repldict = parseAttributeReplacements(attrsubst)
for key, value in repldict.items(): for key, value in repldict.items():
repldict[key] = self.expressionCompiler.compile(value) repldict[key] = self.compileExpression(value)
else: else:
repldict = {} repldict = {}
if replace: if replace:
...@@ -450,6 +451,13 @@ class TALGenerator: ...@@ -450,6 +451,13 @@ class TALGenerator:
if isend: if isend:
self.emitEndElement(name, isend) self.emitEndElement(name, isend)
def makeAttrDict(self, attrlist):
dict = {}
for item in attrlist:
key, value = item[:2]
dict[key] = value
return dict
def emitEndElement(self, name, isend=0, implied=0): def emitEndElement(self, name, isend=0, implied=0):
todo = self.todoPop() todo = self.todoPop()
if not todo: if not todo:
...@@ -470,6 +478,7 @@ class TALGenerator: ...@@ -470,6 +478,7 @@ class TALGenerator:
onError = todo.get("onError") onError = todo.get("onError")
define = todo.get("define") define = todo.get("define")
repldict = todo.get("repldict", {}) repldict = todo.get("repldict", {})
scope = todo.get("scope")
if implied > 0: if implied > 0:
if defineMacro or useMacro or defineSlot or fillSlot: if defineMacro or useMacro or defineSlot or fillSlot:
...@@ -489,12 +498,11 @@ class TALGenerator: ...@@ -489,12 +498,11 @@ class TALGenerator:
self.emitSubstitution(replace, repldict, position) self.emitSubstitution(replace, repldict, position)
if repeat: if repeat:
self.emitRepeat(repeat, position) self.emitRepeat(repeat, position)
self.emit("endScope")
if condition: if condition:
self.emitCondition(condition) self.emitCondition(condition)
if onError: if onError:
self.emitOnError(name, onError, position) self.emitOnError(name, onError, position)
if define: if scope:
self.emit("endScope") self.emit("endScope")
if defineMacro: if defineMacro:
self.emitDefineMacro(defineMacro, position) self.emitDefineMacro(defineMacro, position)
......
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