def parseBlock(self, text, taglist, start, tagreg, name): """ should return node, last. This is only called for non-empty tags """ cur = start #create a new node n = DTParser.Node() #get current tag t = taglist[cur] #this is in case they started a block with the close tag (for whatever #reason) if t.isclose: raise DTExcept.DTCompileError(t, 'close tag out of context') #add current tag to the node n.add(t) #while we haven't eaten the taglist while cur < (len(taglist) - 1): cur = cur + 1 curtag = taglist[cur] if type(curtag) == types.StringType: n.add(curtag) else: #if it's our close tag, add it and return if curtag.tagname == self.tagname and curtag.isclose: n.add(curtag) return n, cur #else it's not our tag so we pass it to the generic handler nodeortag, last = DTParser.genHandler(text, taglist, cur, tagreg, name) n.add(nodeortag) cur = last raise DTExcept.DTCompileError( t, 'unexpected EOF encountered ' 'parsing <:%s:> block' % self.tagname)
def parseBlock(self, text, taglist, start, tagreg, name): cur = start n = DTParser.Node() t = taglist[cur] while cur < (len(taglist) - 1): #basically, ignore tokens until we see <:/comment:> cur = cur + 1 curtagl = taglist[cur] if type(curtagl) == types.StringType: pass else: if curtagl.tagname == self.tagname and curtagl.isclose: n.add(curtagl) return n, cur else: pass raise DTExcept.DTCompileError( t, 'unexpected EOF encountered ' 'parsing <:%s:> block' % self.tagname)
def parseBlock(self, text, taglist, start, tagreg, name): """ should return node, last. This is only called for non-empty tags """ cur=start #create a new node n=DTParser.Node() #get current tag t=taglist[cur] #this is in case they started a block with the close tag (for whatever #reason) if t.isclose: raise DTExcept.DTCompileError( t, 'close tag out of context' ) #add current tag to the node n.add(t) #while we haven't eaten the taglist while cur < (len(taglist)-1): cur=cur+1 curtag=taglist[cur] if type(curtag)==types.StringType: n.add(curtag) else: #if it's our close tag, add it and return if curtag.tagname == self.tagname and curtag.isclose: n.add(curtag) return n, cur #else it's not our tag so we pass it to the generic handler nodeortag, last=DTParser.genHandler(text, taglist, cur, tagreg, name) n.add(nodeortag) cur=last raise DTExcept.DTCompileError ( t, 'unexpected EOF encountered ' 'parsing <:%s:> block' % self.tagname )
import DTLexer import DTParser import DTExcept import ErrorHandler from SkunkExcept import * def compileTemplate(text, name=None, tagreg=None, meta=None): try: taglist = DTLexer.doTag(text, name) except DTExcept.DTLexicalError, val: # Ok, force the name here - its a decent hack Drew val.name = name raise val node = DTParser.parseit(text, taglist, tagreg, name) indent = 0 codeout = DTCompilerUtil.Output() DTCompilerUtil.genCodeNode(indent, codeout, tagreg, node.children, meta) return codeout.getText() def compileText(text, name): # Only catch syntax errors in the text, all else will fall through try: cobj = compile(text, name, 'exec') except SyntaxError, val: raise SkunkSyntaxError(name, text, val) return cobj
import DTCompilerUtil import DTLexer import DTParser import DTExcept import ErrorHandler from SkunkExcept import * def compileTemplate ( text, name = None, tagreg = None, meta = None ): try: taglist=DTLexer.doTag(text, name) except DTExcept.DTLexicalError, val: # Ok, force the name here - its a decent hack Drew val.name = name raise val node = DTParser.parseit(text, taglist, tagreg, name) indent=0 codeout=DTCompilerUtil.Output() DTCompilerUtil.genCodeNode ( indent, codeout, tagreg, node.children, meta ) return codeout.getText() def compileText(text, name): # Only catch syntax errors in the text, all else will fall through try: cobj = compile(text, name, 'exec') except SyntaxError, val: raise SkunkSyntaxError ( name, text, val ) return cobj