[ZPT] CVS: Packages/TAL - HTMLTALParser.py:1.15 TALDefs.py:1.10 TALGenerator.py:1.15

tim@digicool.com tim@digicool.com
Fri, 16 Mar 2001 15:38:05 -0500 (EST)


Update of /cvs-repository/Packages/TAL
In directory korak:/tmp/cvs-serv11657

Modified Files:
	HTMLTALParser.py TALDefs.py TALGenerator.py 
Log Message:
Start adding start-tag column + lineno info in error msgs.
Repaired test for ""at most one of content, replace, repeat" TAL error
and improved the msg.



--- Updated File HTMLTALParser.py in package Packages/TAL --
--- HTMLTALParser.py	2001/03/16 19:25:59	1.14
+++ HTMLTALParser.py	2001/03/16 20:38:05	1.15
@@ -90,7 +90,7 @@
 import string
 
 from TALGenerator import TALGenerator
-from TALDefs import ZOPE_METAL_NS, ZOPE_TAL_NS
+from TALDefs import ZOPE_METAL_NS, ZOPE_TAL_NS, METALError, TALError
 from nsgmllib import SGMLParser
 
 BOOLEAN_HTML_ATTRS = [
@@ -209,7 +209,8 @@
         else:
             self.tagstack.append(tag)
         attrlist, taldict, metaldict = self.extract_attrs(attrs)
-        self.gen.emitStartElement(tag, attrlist, taldict, metaldict)
+        self.gen.emitStartElement(tag, attrlist, taldict, metaldict,
+                                  self.getpos())
 
     def finish_endtag(self, tag, implied=0):
         if tag in EMPTY_HTML_TAGS:
@@ -284,11 +285,17 @@
                 prefix, suffix = string.split(key, ':', 1)
                 nsuri = self.nsdict.get(prefix)
                 if nsuri == ZOPE_METAL_NS:
+                    if metaldict.has_key(suffix):
+                        raise METALError("duplicate METAL attribute " +
+                                         `suffix`, self.getpos())
                     item = (key, value)
                     metaldict[suffix] = value
                     if suffix == "define-macro":
                         item = (key,value,"macroHack")
                 elif nsuri == ZOPE_TAL_NS:
+                    if taldict.has_key(suffix):
+                        raise TALError("duplicate TAL attribute " +
+                                       `suffix`, self.getpos())
                     item = (key, value)
                     taldict[suffix] = value
             attrlist.append(item)

--- Updated File TALDefs.py in package Packages/TAL --
--- TALDefs.py	2001/03/16 17:06:26	1.9
+++ TALDefs.py	2001/03/16 20:38:05	1.10
@@ -1,24 +1,24 @@
 ##############################################################################
-# 
+#
 # Zope Public License (ZPL) Version 1.0
 # -------------------------------------
-# 
+#
 # Copyright (c) Digital Creations.  All rights reserved.
-# 
+#
 # This license has been certified as Open Source(tm).
-# 
+#
 # Redistribution and use in source and binary forms, with or without
 # modification, are permitted provided that the following conditions are
 # met:
-# 
+#
 # 1. Redistributions in source code must retain the above copyright
 #    notice, this list of conditions, and the following disclaimer.
-# 
+#
 # 2. Redistributions in binary form must reproduce the above copyright
 #    notice, this list of conditions, and the following disclaimer in
 #    the documentation and/or other materials provided with the
 #    distribution.
-# 
+#
 # 3. Digital Creations requests that attribution be given to Zope
 #    in any manner possible. Zope includes a "Powered by Zope"
 #    button that is installed by default. While it is not a license
@@ -26,43 +26,43 @@
 #    attribution remain. A significant investment has been put
 #    into Zope, and this effort will continue if the Zope community
 #    continues to grow. This is one way to assure that growth.
-# 
+#
 # 4. All advertising materials and documentation mentioning
 #    features derived from or use of this software must display
 #    the following acknowledgement:
-# 
+#
 #      "This product includes software developed by Digital Creations
 #      for use in the Z Object Publishing Environment
 #      (http://www.zope.org/)."
-# 
+#
 #    In the event that the product being advertised includes an
 #    intact Zope distribution (with copyright and license included)
 #    then this clause is waived.
-# 
+#
 # 5. Names associated with Zope or Digital Creations must not be used to
 #    endorse or promote products derived from this software without
 #    prior written permission from Digital Creations.
-# 
+#
 # 6. Modified redistributions of any form whatsoever must retain
 #    the following acknowledgment:
-# 
+#
 #      "This product includes software developed by Digital Creations
 #      for use in the Z Object Publishing Environment
 #      (http://www.zope.org/)."
-# 
+#
 #    Intact (re-)distributions of any official Zope release do not
 #    require an external acknowledgement.
-# 
+#
 # 7. Modifications are encouraged but must be packaged separately as
 #    patches to official Zope releases.  Distributions that do not
 #    clearly separate the patches from the original work must be clearly
 #    labeled as unofficial distributions.  Modifications which do not
 #    carry the name Zope may be packaged in any form, as long as they
 #    conform to all of the clauses above.
-# 
-# 
+#
+#
 # Disclaimer
-# 
+#
 #   THIS SOFTWARE IS PROVIDED BY DIGITAL CREATIONS ``AS IS'' AND ANY
 #   EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 #   IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
@@ -75,12 +75,12 @@
 #   OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
 #   OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 #   SUCH DAMAGE.
-# 
-# 
+#
+#
 # This software consists of contributions made by Digital Creations and
 # many individuals on behalf of Digital Creations.  Specific
 # attributions are listed in the accompanying credits file.
-# 
+#
 ##############################################################################
 """
 Common definitions used by TAL and METAL compilation an transformation.
@@ -111,7 +111,17 @@
     ]
 
 class TALError(Exception):
-    pass
+    def __init__(self, msg, position=None):
+        self.msg = msg
+        self.position = position    # (line, offset) pair
+
+    def __str__(self):
+        if self.position:
+            result = "%s, at line %d, column %d" % (
+                self.msg, self.position[0], self.position[1]+1)
+        else:
+            result = self.msg
+        return result
 
 class METALError(TALError):
     pass

--- Updated File TALGenerator.py in package Packages/TAL --
--- TALGenerator.py	2001/03/16 18:42:58	1.14
+++ TALGenerator.py	2001/03/16 20:38:05	1.15
@@ -202,12 +202,13 @@
     def emitText(self, text):
         self.emitRawText(cgi.escape(text))
 
-    def emitDefines(self, defines):
+    def emitDefines(self, defines, position):
         for part in splitParts(defines):
             m = re.match(
                 r"\s*(?:(global|local)\s+)?(%s)\s+(.*)" % NAME_RE, part)
             if not m:
-                raise TALError("invalid define syntax: " + `part`)
+                raise TALError("invalid define syntax: " + `part`,
+                               position)
             scope, name, expr = m.group(1, 2, 3)
             scope = scope or "local"
             cexpr = self.compileExpression(expr)
@@ -304,13 +305,14 @@
             newlist.append(item)
         return newlist
 
-    def emitStartElement(self, name, attrlist, taldict, metaldict):
+    def emitStartElement(self, name, attrlist, taldict, metaldict,
+                         position):
         for key in taldict.keys():
             if key not in KNOWN_TAL_ATTRIBUTES:
-                raise TALError("bad TAL attribute: " + `key`)
+                raise TALError("bad TAL attribute: " + `key`, position)
         for key in metaldict.keys():
             if key not in KNOWN_METAL_ATTRIBUTES:
-                raise METALError("bad METAL attribute: " + `key`)
+                raise METALError("bad METAL attribute: " + `key`, position)
         todo = {}
         defineMacro = metaldict.get("define-macro")
         useMacro = metaldict.get("use-macro")
@@ -328,13 +330,15 @@
         if fillSlot: n = n+1
         if defineSlot: n = n+1
         if n > 1:
-            raise METALError("only one METAL attribute per element")
+            raise METALError("only one METAL attribute per element",
+                             position)
         n = 0
         if content: n = n+1
-        if replace: n + n+1
+        if replace: n = n+1
         if repeat: n = n+1
         if n > 1:
-            raise TALError("can't use content, replace, repeat together")
+            raise TALError("at most one of content, replace, repeat",
+                           position)
         repeatWhitespace = None
         if repeat:
             # Hack to include preceding whitespace in the loop program
@@ -354,7 +358,7 @@
             todo["fillSlot"] = fillSlot
         if defines:
             self.emit("beginScope")
-            self.emitDefines(defines)
+            self.emitDefines(defines, position)
             todo["define"] = defines
         if condition:
             self.pushProgram()