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

Raise exceptions (METALError, TALError) for syntax errors.

parent 120b95ab
...@@ -252,7 +252,7 @@ class METALCompiler(DOMVisitor): ...@@ -252,7 +252,7 @@ class METALCompiler(DOMVisitor):
if macroName: if macroName:
# Save macro definitions # Save macro definitions
if self.macros.has_key(macroName): if self.macros.has_key(macroName):
print "Warning: duplicate macro definition for", macroName raise METALError("duplicate macro definition: %s" % macroName)
self.pushProgram() self.pushProgram()
self.compileElement(node) self.compileElement(node)
macro = self.popProgram() macro = self.popProgram()
...@@ -345,15 +345,14 @@ class TALCompiler(METALCompiler): ...@@ -345,15 +345,14 @@ class TALCompiler(METALCompiler):
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:
print "Bad syntax in z:define argument:", `part` raise TALError("invalid z:define syntax: " + `part`)
scope, name, expr = m.group(1, 2, 3)
scope = scope or "local"
cexpr = self.compileExpression(expr)
if scope == "local":
self.emit("setLocal", name, cexpr)
else: else:
scope, name, expr = m.group(1, 2, 3) self.emit("setGlobal", name, cexpr)
scope = scope or "local"
cexpr = self.compileExpression(expr)
if scope == "local":
self.emit("setLocal", name, cexpr)
else:
self.emit("setGlobal", name, cexpr)
def conditionalElement(self, node): def conditionalElement(self, node):
condition = node.getAttributeNS(ZOPE_TAL_NS, "condition") condition = node.getAttributeNS(ZOPE_TAL_NS, "condition")
...@@ -374,7 +373,7 @@ class TALCompiler(METALCompiler): ...@@ -374,7 +373,7 @@ class TALCompiler(METALCompiler):
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:
print "Please use only one of z:insert, z:replace, z:repeat" raise TALError("can't use z:insert, z:replace, z:repeat together")
ok = 0 ok = 0
if insert: if insert:
ok = self.doInsert(node, insert) ok = self.doInsert(node, insert)
...@@ -417,8 +416,7 @@ class TALCompiler(METALCompiler): ...@@ -417,8 +416,7 @@ class TALCompiler(METALCompiler):
def doRepeat(self, node, arg): def doRepeat(self, node, arg):
m = re.match("\s*(%s)\s+(.*)" % NAME_RE, arg) m = re.match("\s*(%s)\s+(.*)" % NAME_RE, arg)
if not m: if not m:
print "Bad syntax in z:repeat:", `arg` raise TALError("invalid z:repeat syntax: " + `arg`)
return 0
name, expr = m.group(1, 2) name, expr = m.group(1, 2)
cexpr = self.compileExpression(expr) cexpr = self.compileExpression(expr)
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