[ZPT] CVS: Packages/TAL - TALGenerator.py:1.36

guido@digicool.com guido@digicool.com
Thu, 17 May 2001 00:16:19 -0400 (EDT)


Update of /cvs-repository/Packages/TAL
In directory korak.digicool.com:/tmp/cvs-serv7360

Modified Files:
	TALGenerator.py 
Log Message:
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).



--- Updated File TALGenerator.py in package Packages/TAL --
--- TALGenerator.py	2001/05/08 01:52:26	1.35
+++ TALGenerator.py	2001/05/17 04:16:18	1.36
@@ -360,7 +360,7 @@
             if isend:
                 self.emitEndElement(name, isend)
             return
-            
+
         for key in taldict.keys():
             if key not in KNOWN_TAL_ATTRIBUTES:
                 raise TALError("bad TAL attribute: " + `key`, position)
@@ -408,8 +408,10 @@
         if fillSlot:
             self.pushProgram()
             todo["fillSlot"] = fillSlot
-        if define:
+        if taldict:
             self.emit("beginScope")
+            self.emit("tagDict", self.makeAttrDict(attrlist))
+            todo["scope"] = 1
         if onError:
             self.pushProgram() # handler
             self.emitStartTag(name, attrlist)
@@ -423,7 +425,6 @@
             todo["condition"] = condition
         if repeat:
             todo["repeat"] = repeat
-            self.emit("beginScope")
             self.pushProgram()
             if repeatWhitespace:
                 self.emitText(repeatWhitespace)
@@ -435,7 +436,7 @@
         if attrsubst:
             repldict = parseAttributeReplacements(attrsubst)
             for key, value in repldict.items():
-                repldict[key] = self.expressionCompiler.compile(value)
+                repldict[key] = self.compileExpression(value)
         else:
             repldict = {}
         if replace:
@@ -450,6 +451,13 @@
         if 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):
         todo = self.todoPop()
         if not todo:
@@ -470,6 +478,7 @@
         onError = todo.get("onError")
         define = todo.get("define")
         repldict = todo.get("repldict", {})
+        scope = todo.get("scope")
 
         if implied > 0:
             if defineMacro or useMacro or defineSlot or fillSlot:
@@ -489,12 +498,11 @@
             self.emitSubstitution(replace, repldict, position)
         if repeat:
             self.emitRepeat(repeat, position)
-            self.emit("endScope")
         if condition:
             self.emitCondition(condition)
         if onError:
             self.emitOnError(name, onError, position)
-        if define:
+        if scope:
             self.emit("endScope")
         if defineMacro:
             self.emitDefineMacro(defineMacro, position)