def TreeRepr(tree, depth=0):

  def _NodeRepr(node):
    text = str(node.getType())
    if node.getText():
      text = '%s: %s' % (text, node.getText())
    return text

  children = ''
  if tree.children:
    children = '\n' + '\n'.join([TreeRepr(child, depth=depth+1)
                                 for child in tree.children if child])
  return depth * '  ' + _NodeRepr(tree) + children
Generate a string representation of an ANTLR parse tree for debugging.
dataset/ETHPy150Open AppScale/appscale/AppServer/google/appengine/api/search/search_util.py/TreeRepr