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

Use compilefile() in evaluateMacro(), rather than parsefile().

parent b8d80e71
...@@ -165,20 +165,29 @@ class DummyEngine: ...@@ -165,20 +165,29 @@ class DummyEngine:
return self.evaluate(expr) return self.evaluate(expr)
def evaluateMacro(self, macroName): def evaluateMacro(self, macroName):
doc, localName = self.findMacroDocument(macroName) file, localName = self.findMacroFile(macroName)
if not doc: if not file:
# Local macro # Local macro
macro = self.macros[localName] macro = self.macros[localName]
else: else:
# External macro # External macro
macroDict = macroIndexer(doc) from driver import compilefile
if not macroDict.has_key(localName): program, macros = compilefile(file)
raise TALESError("macro not found: " + `macroName`) macro = macros.get(localName)
macroNode = macroDict[localName] if not macro:
macro, dummy = TALCompiler(macroNode)() raise TALESError("macro %s not found in file %s" %
(localName, file))
return macro return macro
def findMacroDocument(self, macroName): def findMacroDocument(self, macroName):
file, localName = self.findMacroFile(macroName)
if not file:
return file, localName
from driver import parsefile
doc = parsefile(file)
return doc, localName
def findMacroFile(self, macroName):
if not macroName: if not macroName:
raise TALESError("empty macro name") raise TALESError("empty macro name")
i = string.rfind(macroName, '/') i = string.rfind(macroName, '/')
...@@ -188,9 +197,8 @@ class DummyEngine: ...@@ -188,9 +197,8 @@ class DummyEngine:
else: else:
# Up to last slash is the filename # Up to last slash is the filename
fileName = macroName[:i] fileName = macroName[:i]
from driver import parsefile localName = macroName[i+1:]
doc = parsefile(fileName) return fileName, localName
return doc, macroName[i+1:]
def setRepeat(self, name, expr): def setRepeat(self, name, expr):
seq = self.evaluateSequence(expr) seq = self.evaluateSequence(expr)
......
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