def genCode(self, indent, codeout, tagreg, node, meta):
        tag = node.children[0]
        DTCompilerUtil.tagDebug(indent, codeout, tag)
        pargs = args = DTUtil.tagCall(tag,
                                      ['expr', ('name', '"sequence_item"')])
        args = DTCompilerUtil.pyifyArgs(tag, args)

        name = DTCompilerUtil.checkName(tag, 'name', args['name'],
                                        pargs['name'])
        exprval = DTCompilerUtil.getTempName()

        codeout.write(indent, '%s = %s' % (exprval, args['expr']))
        codeout.write(indent, 'if %s:' % exprval)
        codeout.write(indent + 4, 'for %s in %s:' % (name, exprval))
        #do main loop shit
        for i in node.children[1:-1]:
            if (type(i) == InstanceType and i.__class__ == DTLexer.DTToken
                    and i.tagname == 'else'):
                break
            else:
                DTCompilerUtil.genCodeChild(indent + 8, codeout, tagreg, i,
                                            meta)
        codeout.write(indent, 'else:')
        codeout.write(indent + 4, 'pass')
        #do else clause
        on = 0
        for i in node.children[1:-1]:
            if (type(i) == InstanceType and i.__class__ == DTLexer.DTToken
                    and i.tagname == 'else'):
                on = 1
            elif on:
                DTCompilerUtil.genCodeChild(indent + 4, codeout, tagreg, i,
                                            meta)
        codeout.write(indent, 'del %s' % exprval)
    def genCode(self, indent, codeout, tagreg, node, meta):
        tag = node.children[0]
        DTCompilerUtil.tagDebug(indent, codeout, tag)
        tagargs = ['name']
        if self._attend_to_comments:
            tagargs.append(('comments', None))
        pargs = args = DTUtil.tagCall(tag, tagargs)
        args = DTCompilerUtil.pyifyArgs(tag, args)
        if self._attend_to_comments and args['comments'] is not None:
            self._testCommentLevel(indent, codeout, args['comments'])
            stuff = self._pushCommentLevel(indent, codeout, args['comments'])

        name = DTCompilerUtil.checkName(tag, 'name', args['name'],
                                        pargs['name'])

        oldout = DTCompilerUtil.getTempName()
        codeout.write(indent, '%s = __h.OUTPUT' % oldout)
        codeout.write(indent, '__h.OUTPUT=__h.NEWOUTPUT()')
        for i in node.children[1:-1]:
            DTCompilerUtil.genCodeChild(indent, codeout, tagreg, i, meta)
        codeout.write(indent, '%s = __h.OUTPUT.getvalue()' % name)
        codeout.write(indent, '__h.OUTPUT = %s' % oldout)
        codeout.write(indent, 'del %s' % oldout)
        if self._attend_to_comments and args['comments'] is not None:
            self._popCommentLevel(indent, codeout, *stuff)
    def genCode ( self, indent, codeout, tagreg, node, meta):
        tag = node.children[0]
        DTCompilerUtil.tagDebug(indent, codeout, tag)
        tagargs=['name']
        if self._attend_to_comments:
            tagargs.append(('comments', None))
        pargs = args = DTUtil.tagCall(tag, tagargs)
        args = DTCompilerUtil.pyifyArgs(tag, args)
        if self._attend_to_comments and args['comments'] is not None:
            self._testCommentLevel(indent, codeout, args['comments'])
            stuff=self._pushCommentLevel(indent, codeout, args['comments'])

        name = DTCompilerUtil.checkName(tag, 'name', args['name'],
                                        pargs['name'])
        
        oldout = DTCompilerUtil.getTempName()
        codeout.write(indent, '%s = __h.OUTPUT' % oldout)
        codeout.write(indent, '__h.OUTPUT=__h.NEWOUTPUT()')
        for i in node.children[1:-1]:
            DTCompilerUtil.genCodeChild(indent, codeout, tagreg, i, meta)
        codeout.write(indent, '%s = __h.OUTPUT.getvalue()' % name)
        codeout.write(indent, '__h.OUTPUT = %s' % oldout)
        codeout.write(indent, 'del %s' % oldout)
        if self._attend_to_comments and args['comments'] is not None:
            self._popCommentLevel(indent, codeout, *stuff)
    def genCode(self, indent, codeout, tagreg, node, meta):
        tag=node.children[0]
        DTCompilerUtil.tagDebug(indent, codeout, tag)
        pargs=args=DTUtil.tagCall(tag, ['expr', ('name','"sequence_item"')])
        args=DTCompilerUtil.pyifyArgs(tag, args)

        name = DTCompilerUtil.checkName(tag, 'name', args['name'],
                                        pargs['name'])
        exprval=DTCompilerUtil.getTempName()

        codeout.write(indent, '%s = %s' % (exprval, args['expr']))
        codeout.write(indent, 'if %s:' % exprval)
        codeout.write(indent+4, 'for %s in %s:' % (name, exprval))
        #do main loop shit
        for i in node.children[1:-1]:
            if (type(i) == InstanceType
                and i.__class__ == DTLexer.DTToken
                and i.tagname == 'else'):
                break
            else:
                DTCompilerUtil.genCodeChild(indent+8, codeout, tagreg, i, meta)
        codeout.write(indent, 'else:')
        codeout.write(indent+4, 'pass')
        #do else clause
        on=0
        for i in node.children[1:-1]:
            if (type(i) == InstanceType
                and i.__class__ == DTLexer.DTToken
                and i.tagname == 'else'):
                on=1
            elif on:
                DTCompilerUtil.genCodeChild(indent+4, codeout, tagreg, i, meta)
        codeout.write(indent, 'del %s' % exprval)
    def genCode(self, indent, codeout, tagreg, node):
        tag = node.children[0]
        DTCompilerUtil.tagDebug(indent, codeout, tag)
        pargs = args = DTUtil.tagCall(tag, ['name'])
        args = DTCompilerUtil.pyifyArgs(tag, args)
        name = DTCompilerUtil.checkName(tag, 'name', args['name'],
                                        pargs['name'])

        oldout = DTCompilerUtil.getTempName()
        codeout.write(indent, '%s = __h.OUTPUT' % oldout)
        codeout.write(indent, '__h.OUTPUT=__h.NEWOUTPUT()')
        for i in node.children[1:-1]:
            DTCompilerUtil.genCodeChild(indent, codeout, tagreg, i)
        codeout.write(indent, '%s = __h.OUTPUT.getvalue()' % name)
        codeout.write(indent, '__h.OUTPUT = %s' % oldout)
        codeout.write(indent, 'del %s' % oldout)
    def genCode(self, indent, codeout, tagreg, tag):
        DTCompilerUtil.tagDebug(indent, codeout, tag)
        args = DTUtil.tagCall(tag, [('exc', None)])
        args = DTCompilerUtil.pyifyArgs(tag, args)
        tvar = DTCompilerUtil.getTempName()

        # Just do a regular python raise - you should know to raise instances
        #
        # <:raise MyExcept('hello'):> works
        # <:raise MyExcept, 'hello':> doesn't
        # <:raise 'string exception':> works
        # <:raise:> by itself now re-raises exception properly
        if args['exc'] is None:
            codeout.write(indent, 'import sys')
            codeout.write(indent, 'raise')
        else:
            codeout.write(indent, 'raise (%s)' % args['exc'])
    def genCode ( self, indent, codeout, tagreg, tag ):
        DTCompilerUtil.tagDebug ( indent, codeout, tag )
        args=DTUtil.tagCall ( tag, [('exc', None)] )
        args=DTCompilerUtil.pyifyArgs(tag, args)
        tvar=DTCompilerUtil.getTempName()
        
        # Just do a regular python raise - you should know to raise instances
        # 
        # <:raise MyExcept('hello'):> works
        # <:raise MyExcept, 'hello':> doesn't
        # <:raise 'string exception':> works
	# <:raise:> by itself now re-raises exception properly
	if args['exc'] is None:
            codeout.write ( indent, 'import sys' )
            codeout.write ( indent, 'raise' )
	else:
            codeout.write ( indent, 'raise (%s)' % args['exc'] )
    def genCode(self, indent, codeout, tagreg, node, meta):
        tag = node.children[0]

        # Do the debug
        DTCompilerUtil.tagDebug(indent, codeout, tag)
        DTUtil.tagCall(tag, [])
        oldout = DTCompilerUtil.getTempName()

        #
        # First, determine if this is a 'try...finally' form
        #
        for i in node.children[1:-1]:
            if (type(i) == InstanceType and i.__class__ == DTLexer.DTToken
                    and i.tagname in ('finally', )):
                has_finally = 1
                break
        else:
            has_finally = 0

        if has_finally:
            # This is a try...finally block
            codeout.write(indent, 'try:')

            for i in node.children[1:-1]:
                if (type(i) == InstanceType and i.__class__ == DTLexer.DTToken
                        and i.tagname in ('else', 'except', 'finally')):

                    if i.tagname in ('else', 'except'):
                        # This is an error
                        raise DTExcept.DTCompileError(
                            i,
                            'tag %s inside of a try...finally block' % str(i))
                    else:  # i.tagname == 'finally':
                        codeout.write(indent, 'finally:')
                        codeout.write(indent + 4, '__d.FTAG=__d.CURRENT_TAG')
                        codeout.write(indent + 4,
                                      '__d.FLINENO=__d.CURRENT_LINENO')
                        DTCompilerUtil.tagDebug(indent + 4, codeout, i)
                else:
                    DTCompilerUtil.genCodeChild(indent + 4, codeout, tagreg, i,
                                                meta)
            codeout.write(indent + 4, '__d.CURRENT_TAG=__d.FTAG')
            codeout.write(indent + 4, '__d.CURRENT_LINENO=__d.FLINENO')
            codeout.write(indent + 4, 'del __d.FTAG, __d.FLINENO')
            #
            # Ok, we're done - return
            #
            return

        #
        # Store a reference to current output object. Basically, if an exception
        # occurs we kind of rollback to the point before the 'try' block
        #
        codeout.write(indent, '%s = __h.OUTPUT' % oldout)
        codeout.write(indent, '__h.OUTPUT=__h.NEWOUTPUT()')
        codeout.write(indent, 'try:')

        waselse = 0
        wasexcept = 0

        for i in node.children[1:-1]:
            if (type(i) == InstanceType and i.__class__ == DTLexer.DTToken
                    and i.tagname in ('else', 'except')):
                if i.tagname == 'except':
                    # Get the arguments for the except clause
                    args = DTUtil.tagCall(i, [('exc', 'None')])
                    args = DTCompilerUtil.pyifyArgs(tag, args)

                    if args['exc'] != None:
                        codeout.write(indent, 'except %s:' % args['exc'])
                    else:
                        codeout.write(indent, 'except:')

                    # Do the debugging
                    DTCompilerUtil.tagDebug(indent + 4, codeout, i)

                    # Restore the original output
                    codeout.write(indent + 4, '__h.OUTPUT = %s' % oldout)
                    codeout.write(indent + 4, 'del %s' % oldout)

                    wasexcept = 1
                else:  # i.tagname == 'else':
                    codeout.write(indent, 'else:')

                    DTCompilerUtil.tagDebug(indent + 4, codeout, i)

                    # Print and restore the original output
                    codeout.write(indent + 4,
                                  '%s.write(__h.OUTPUT.getvalue())' % oldout)
                    codeout.write(indent + 4, '__h.OUTPUT = %s' % oldout)
                    codeout.write(indent + 4, 'del %s' % oldout)

                    waselse = 1
            else:
                DTCompilerUtil.genCodeChild(indent + 4, codeout, tagreg, i,
                                            meta)

        if not wasexcept:
            raise DTExcept.DTCompileError(tag, '<:try:> without <:except:>')

        if not waselse:
            codeout.write(indent, 'else:')
            codeout.write(indent + 4,
                          '%s.write(__h.OUTPUT.getvalue())' % oldout)
            codeout.write(indent + 4, '__h.OUTPUT = %s' % oldout)
            codeout.write(indent + 4, 'del %s' % oldout)
    def genCode(self, indent, codeout, tagreg, node, meta):
        tag=node.children[0]

        # Do the debug
        DTCompilerUtil.tagDebug(indent, codeout, tag)
        DTUtil.tagCall(tag,[])
        oldout=DTCompilerUtil.getTempName()

        #
        # First, determine if this is a 'try...finally' form
        #
        for i in node.children[1:-1]:
            if ( type(i) == InstanceType
                 and i.__class__ == DTLexer.DTToken 
                 and i.tagname in ( 'finally', )):
                has_finally = 1
                break
        else:
            has_finally = 0

        if has_finally:
            # This is a try...finally block
            codeout.write ( indent, 'try:')

            for i in node.children[1:-1]:
                if ( type(i) == InstanceType
                     and i.__class__ == DTLexer.DTToken
                     and i.tagname in ( 'else', 'except', 'finally' ) ):

                    if i.tagname in ( 'else', 'except' ):
                        # This is an error
                        raise DTExcept.DTCompileError ( i, 
                          'tag %s inside of a try...finally block' % str(i) )
                    else:            # i.tagname == 'finally':
                        codeout.write ( indent, 'finally:' )
                        codeout.write ( indent+4, '__d.FTAG=__d.CURRENT_TAG')
                        codeout.write ( indent+4,
                                        '__d.FLINENO=__d.CURRENT_LINENO')
                        DTCompilerUtil.tagDebug ( indent + 4, codeout, i)
                else:
                    DTCompilerUtil.genCodeChild(indent + 4, codeout, tagreg, i,
                                                meta)
            codeout.write( indent+4, '__d.CURRENT_TAG=__d.FTAG')
            codeout.write( indent+4, '__d.CURRENT_LINENO=__d.FLINENO')
            codeout.write( indent+4, 'del __d.FTAG, __d.FLINENO')
            #
            # Ok, we're done - return
            #
            return

        #
        # Store a reference to current output object. Basically, if an exception
        # occurs we kind of rollback to the point before the 'try' block
        #
        codeout.write ( indent, '%s = __h.OUTPUT' % oldout)
        codeout.write ( indent, '__h.OUTPUT=__h.NEWOUTPUT()')
        codeout.write ( indent, 'try:')

        waselse = 0
        wasexcept = 0

        for i in node.children[1:-1]:
            if ( type(i) == InstanceType
                 and i.__class__ == DTLexer.DTToken 
                 and i.tagname in ( 'else', 'except' )):
                if i.tagname == 'except':
                    # Get the arguments for the except clause
                    args = DTUtil.tagCall ( i, [('exc', 'None')] )
                    args = DTCompilerUtil.pyifyArgs(tag, args)

                    if args['exc'] != None:
                        codeout.write ( indent, 'except %s:' % args['exc'])
                    else:
                        codeout.write ( indent, 'except:' )

                    # Do the debugging
                    DTCompilerUtil.tagDebug ( indent + 4, codeout, i)
                        
                    # Restore the original output
                    codeout.write(indent + 4, '__h.OUTPUT = %s' % oldout)
                    codeout.write(indent + 4, 'del %s' % oldout)

                    wasexcept = 1
                else:      # i.tagname == 'else':
                    codeout.write ( indent, 'else:' )

                    DTCompilerUtil.tagDebug ( indent + 4, codeout, i)

                    # Print and restore the original output
                    codeout.write(indent+4, '%s.write(__h.OUTPUT.getvalue())' %
                                            oldout )
                    codeout.write(indent + 4, '__h.OUTPUT = %s' % oldout)
                    codeout.write(indent + 4, 'del %s' % oldout)

                    waselse = 1
            else:
                DTCompilerUtil.genCodeChild(indent + 4, codeout, tagreg, i,
                                            meta)

        if not wasexcept:
            raise DTExcept.DTCompileError ( tag, '<:try:> without <:except:>' )
            
        if not waselse:
            codeout.write(indent, 'else:')
            codeout.write(indent+4, '%s.write(__h.OUTPUT.getvalue())' % oldout)
            codeout.write(indent+4, '__h.OUTPUT = %s' % oldout)
            codeout.write(indent+4, 'del %s' % oldout)