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)

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 .