Permalink
Browse files

move handling of escaped variables and directives to the parser

Once text reaches the compiler, it is too late to parse escaped
variables and directives.  The compiler does not know where the text
came from, and can not determine when it should skip processing of
escape sequences for raw blocks.

Signed-off-by: R. Tyler Ballance <tyler@monkeypox.org>
  • Loading branch information...
karmix authored and rtyler committed Dec 15, 2009
1 parent 5cd0220 commit 0cc9f781eeeb98d6c0d2812145a525f5dfe27b40
Showing with 16 additions and 16 deletions.
  1. +1 −16 cheetah/Compiler.py
  2. +15 −0 cheetah/Parser.py
View
@@ -428,27 +428,12 @@ def _appendToPrevStrConst(self, strConst):
else:
self._pendingStrConstChunks = [strConst]
- def _unescapeCheetahVars(self, theString):
- """Unescape any escaped Cheetah \$vars in the string.
- """
-
- token = self.setting('cheetahVarStartToken')
- return theString.replace('\\' + token, token)
-
- def _unescapeDirectives(self, theString):
- """Unescape any escaped Cheetah \$vars in the string.
- """
-
- token = self.setting('directiveStartToken')
- return theString.replace('\\' + token, token)
-
def commitStrConst(self):
"""Add the code for outputting the pending strConst without chopping off
any whitespace from it.
"""
if self._pendingStrConstChunks:
- strConst = self._unescapeCheetahVars(''.join(self._pendingStrConstChunks))
- strConst = self._unescapeDirectives(strConst)
+ strConst = ''.join(self._pendingStrConstChunks)
self._pendingStrConstChunks = []
if not strConst:
return
View
@@ -510,6 +510,19 @@ def _makePspREs(self):
endTokenEsc = escapeRegexChars(endToken)
self.PSPEndTokenRE = cachedRegex(escCharLookBehind + endTokenEsc)
+ def _unescapeCheetahVars(self, theString):
+ """Unescape any escaped Cheetah \$vars in the string.
+ """
+
+ token = self.setting('cheetahVarStartToken')
+ return theString.replace('\\' + token, token)
+
+ def _unescapeDirectives(self, theString):
+ """Unescape any escaped Cheetah directives in the string.
+ """
+
+ token = self.setting('directiveStartToken')
+ return theString.replace('\\' + token, token)
def isLineClearToStartToken(self, pos=None):
return self.isLineClearToPos(pos)
@@ -1497,6 +1510,8 @@ def eatPlainText(self):
else:
self.advance()
strConst = self.readTo(self.pos(), start=startPos)
+ strConst = self._unescapeCheetahVars(strConst)
+ strConst = self._unescapeDirectives(strConst)
self._compiler.addStrConst(strConst)
return match

0 comments on commit 0cc9f78

Please sign in to comment.