def __repr__(self): """ Returns the debug string representation of this comment. """ parts = [ colors.white(self.typeName + ':'), colors.black(self.left) + colors.black(self.right) + colors.black(self.tail), ] return ' '.join(parts)
def innerDump(root, offset): token, indent = root.token, ' ' * offset start, stop = root.tokenStartIndex, root.tokenStopIndex idxes, ttyp = '', tokens.map.get(token.type, '?') line = token.line if start and stop and start == stop: idxes = 'start={}'.format(start) elif start and stop: idxes = 'start={}, stop={}'.format(start, stop) if line: idxes = 'line={}{}{}'.format(line, ', ' if idxes else '', idxes) idxes = ' [{}]'.format(idxes) if idxes else '' idxes = colors.black(idxes) args = [indent, self.colorType(ttyp), '', idxes, ''] if extras(token.text, ttyp): args[2] = ' ' + self.colorText(ttyp, token.text) for com in self.selectComments(start, seen): for line in self.colorComments(com): print >> fd, '{0}{1}'.format(indent, line) print >> fd, nform.format(*args) for child in root.getChildren(): innerDump(child, offset+1) for com in self.selectComments(root.tokenStopIndex, seen): for line in self.colorComments(com): print >> fd, '{0}{1}'.format(indent, line)
def colorComments(self, token): """ Formats, colors, and returns the comment text from the given token. """ ttyp = tokens.map.get(token.type) text = token.text.replace('\n', '\\n').replace('\r', '\\r').replace('\t', '\\t') item = '{0} [{1}:{2}] {3}'.format(ttyp, token.start, token.stop, text) yield colors.black(item)
def __repr__(self): """ Returns the debug string representation of this template. """ parts, parent, showfs = [colors.blue(self.typeName)], self.parent, True if isinstance(self.left, (basestring, )) and self.left: parts.append(colors.white('left:') + colors.yellow(self.left)) showfs = False if isinstance(self.right, (basestring, )) and self.right: parts.append(colors.white('right:') + colors.yellow(self.right)) showfs = False if showfs: parts.append(colors.white('format:') + colors.yellow(self.fs)) if self.tail: parts.append(colors.white('tail:') + colors.black(self.tail)) return ' '.join(parts)
def __repr__(self): """ Returns the debug string representation of this comment. """ parts = [colors.white(self.typeName+':'), colors.black(self.left) + colors.black(self.right) + colors.black(self.tail), ] return ' '.join(parts)