Commit 45bc66e3 authored by 's avatar

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.
parent 83ee138f
...@@ -90,7 +90,7 @@ import sys ...@@ -90,7 +90,7 @@ import sys
import string import string
from TALGenerator import TALGenerator 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 from nsgmllib import SGMLParser
BOOLEAN_HTML_ATTRS = [ BOOLEAN_HTML_ATTRS = [
...@@ -209,7 +209,8 @@ class HTMLTALParser(SGMLParser): ...@@ -209,7 +209,8 @@ class HTMLTALParser(SGMLParser):
else: else:
self.tagstack.append(tag) self.tagstack.append(tag)
attrlist, taldict, metaldict = self.extract_attrs(attrs) 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): def finish_endtag(self, tag, implied=0):
if tag in EMPTY_HTML_TAGS: if tag in EMPTY_HTML_TAGS:
...@@ -284,11 +285,17 @@ class HTMLTALParser(SGMLParser): ...@@ -284,11 +285,17 @@ class HTMLTALParser(SGMLParser):
prefix, suffix = string.split(key, ':', 1) prefix, suffix = string.split(key, ':', 1)
nsuri = self.nsdict.get(prefix) nsuri = self.nsdict.get(prefix)
if nsuri == ZOPE_METAL_NS: if nsuri == ZOPE_METAL_NS:
if metaldict.has_key(suffix):
raise METALError("duplicate METAL attribute " +
`suffix`, self.getpos())
item = (key, value) item = (key, value)
metaldict[suffix] = value metaldict[suffix] = value
if suffix == "define-macro": if suffix == "define-macro":
item = (key,value,"macroHack") item = (key,value,"macroHack")
elif nsuri == ZOPE_TAL_NS: elif nsuri == ZOPE_TAL_NS:
if taldict.has_key(suffix):
raise TALError("duplicate TAL attribute " +
`suffix`, self.getpos())
item = (key, value) item = (key, value)
taldict[suffix] = value taldict[suffix] = value
attrlist.append(item) attrlist.append(item)
......
############################################################################## ##############################################################################
# #
# Zope Public License (ZPL) Version 1.0 # Zope Public License (ZPL) Version 1.0
# ------------------------------------- # -------------------------------------
# #
# Copyright (c) Digital Creations. All rights reserved. # Copyright (c) Digital Creations. All rights reserved.
# #
# This license has been certified as Open Source(tm). # This license has been certified as Open Source(tm).
# #
# Redistribution and use in source and binary forms, with or without # Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are # modification, are permitted provided that the following conditions are
# met: # met:
# #
# 1. Redistributions in source code must retain the above copyright # 1. Redistributions in source code must retain the above copyright
# notice, this list of conditions, and the following disclaimer. # notice, this list of conditions, and the following disclaimer.
# #
# 2. Redistributions in binary form must reproduce the above copyright # 2. Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions, and the following disclaimer in # notice, this list of conditions, and the following disclaimer in
# the documentation and/or other materials provided with the # the documentation and/or other materials provided with the
# distribution. # distribution.
# #
# 3. Digital Creations requests that attribution be given to Zope # 3. Digital Creations requests that attribution be given to Zope
# in any manner possible. Zope includes a "Powered by Zope" # in any manner possible. Zope includes a "Powered by Zope"
# button that is installed by default. While it is not a license # button that is installed by default. While it is not a license
...@@ -26,43 +26,43 @@ ...@@ -26,43 +26,43 @@
# attribution remain. A significant investment has been put # attribution remain. A significant investment has been put
# into Zope, and this effort will continue if the Zope community # into Zope, and this effort will continue if the Zope community
# continues to grow. This is one way to assure that growth. # continues to grow. This is one way to assure that growth.
# #
# 4. All advertising materials and documentation mentioning # 4. All advertising materials and documentation mentioning
# features derived from or use of this software must display # features derived from or use of this software must display
# the following acknowledgement: # the following acknowledgement:
# #
# "This product includes software developed by Digital Creations # "This product includes software developed by Digital Creations
# for use in the Z Object Publishing Environment # for use in the Z Object Publishing Environment
# (http://www.zope.org/)." # (http://www.zope.org/)."
# #
# In the event that the product being advertised includes an # In the event that the product being advertised includes an
# intact Zope distribution (with copyright and license included) # intact Zope distribution (with copyright and license included)
# then this clause is waived. # then this clause is waived.
# #
# 5. Names associated with Zope or Digital Creations must not be used to # 5. Names associated with Zope or Digital Creations must not be used to
# endorse or promote products derived from this software without # endorse or promote products derived from this software without
# prior written permission from Digital Creations. # prior written permission from Digital Creations.
# #
# 6. Modified redistributions of any form whatsoever must retain # 6. Modified redistributions of any form whatsoever must retain
# the following acknowledgment: # the following acknowledgment:
# #
# "This product includes software developed by Digital Creations # "This product includes software developed by Digital Creations
# for use in the Z Object Publishing Environment # for use in the Z Object Publishing Environment
# (http://www.zope.org/)." # (http://www.zope.org/)."
# #
# Intact (re-)distributions of any official Zope release do not # Intact (re-)distributions of any official Zope release do not
# require an external acknowledgement. # require an external acknowledgement.
# #
# 7. Modifications are encouraged but must be packaged separately as # 7. Modifications are encouraged but must be packaged separately as
# patches to official Zope releases. Distributions that do not # patches to official Zope releases. Distributions that do not
# clearly separate the patches from the original work must be clearly # clearly separate the patches from the original work must be clearly
# labeled as unofficial distributions. Modifications which do not # labeled as unofficial distributions. Modifications which do not
# carry the name Zope may be packaged in any form, as long as they # carry the name Zope may be packaged in any form, as long as they
# conform to all of the clauses above. # conform to all of the clauses above.
# #
# #
# Disclaimer # Disclaimer
# #
# THIS SOFTWARE IS PROVIDED BY DIGITAL CREATIONS ``AS IS'' AND ANY # THIS SOFTWARE IS PROVIDED BY DIGITAL CREATIONS ``AS IS'' AND ANY
# EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE # EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
...@@ -75,12 +75,12 @@ ...@@ -75,12 +75,12 @@
# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT # OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
# OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF # OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
# SUCH DAMAGE. # SUCH DAMAGE.
# #
# #
# This software consists of contributions made by Digital Creations and # This software consists of contributions made by Digital Creations and
# many individuals on behalf of Digital Creations. Specific # many individuals on behalf of Digital Creations. Specific
# attributions are listed in the accompanying credits file. # attributions are listed in the accompanying credits file.
# #
############################################################################## ##############################################################################
""" """
Common definitions used by TAL and METAL compilation an transformation. Common definitions used by TAL and METAL compilation an transformation.
...@@ -111,7 +111,17 @@ KNOWN_TAL_ATTRIBUTES = [ ...@@ -111,7 +111,17 @@ KNOWN_TAL_ATTRIBUTES = [
] ]
class TALError(Exception): 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): class METALError(TALError):
pass pass
......
...@@ -202,12 +202,13 @@ class TALGenerator: ...@@ -202,12 +202,13 @@ class TALGenerator:
def emitText(self, text): def emitText(self, text):
self.emitRawText(cgi.escape(text)) self.emitRawText(cgi.escape(text))
def emitDefines(self, defines): def emitDefines(self, defines, position):
for part in splitParts(defines): for part in splitParts(defines):
m = re.match( m = re.match(
r"\s*(?:(global|local)\s+)?(%s)\s+(.*)" % NAME_RE, part) r"\s*(?:(global|local)\s+)?(%s)\s+(.*)" % NAME_RE, part)
if not m: 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, name, expr = m.group(1, 2, 3)
scope = scope or "local" scope = scope or "local"
cexpr = self.compileExpression(expr) cexpr = self.compileExpression(expr)
...@@ -304,13 +305,14 @@ class TALGenerator: ...@@ -304,13 +305,14 @@ class TALGenerator:
newlist.append(item) newlist.append(item)
return newlist return newlist
def emitStartElement(self, name, attrlist, taldict, metaldict): def emitStartElement(self, name, attrlist, taldict, metaldict,
position):
for key in taldict.keys(): for key in taldict.keys():
if key not in KNOWN_TAL_ATTRIBUTES: 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(): for key in metaldict.keys():
if key not in KNOWN_METAL_ATTRIBUTES: if key not in KNOWN_METAL_ATTRIBUTES:
raise METALError("bad METAL attribute: " + `key`) raise METALError("bad METAL attribute: " + `key`, position)
todo = {} todo = {}
defineMacro = metaldict.get("define-macro") defineMacro = metaldict.get("define-macro")
useMacro = metaldict.get("use-macro") useMacro = metaldict.get("use-macro")
...@@ -328,13 +330,15 @@ class TALGenerator: ...@@ -328,13 +330,15 @@ class TALGenerator:
if fillSlot: n = n+1 if fillSlot: n = n+1
if defineSlot: n = n+1 if defineSlot: n = n+1
if n > 1: if n > 1:
raise METALError("only one METAL attribute per element") raise METALError("only one METAL attribute per element",
position)
n = 0 n = 0
if content: n = n+1 if content: n = n+1
if replace: n + n+1 if replace: n = n+1
if repeat: n = n+1 if repeat: n = n+1
if 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 repeatWhitespace = None
if repeat: if repeat:
# Hack to include preceding whitespace in the loop program # Hack to include preceding whitespace in the loop program
...@@ -354,7 +358,7 @@ class TALGenerator: ...@@ -354,7 +358,7 @@ class TALGenerator:
todo["fillSlot"] = fillSlot todo["fillSlot"] = fillSlot
if defines: if defines:
self.emit("beginScope") self.emit("beginScope")
self.emitDefines(defines) self.emitDefines(defines, position)
todo["define"] = defines todo["define"] = defines
if condition: if condition:
self.pushProgram() self.pushProgram()
......
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