class_docstr: A data structure to represent a parse tree
class_docstr_tok: ["A","data","structure","to","represent","a","parse","tree"]
docstr: Print with newlines & indentation on each line
  
  Preterminals and nodes with all preterminal children go on their own line
  
  You can pass in your own normalize() function.  If you do,
  make sure the function updates the parens to be something
  other than () or the brackets will be broken
docstr_tok: ["Print","with","newlines","&","indentation","on","each","line","Preterminals","and","nodes","with","all","preterminal","children","go","on","their","own","line","You","can","pass","in","your","own","normalize","(",")","function",".","If","you","do",",","make","sure","the","function","updates","the","parens","to","be","something","other","than","(",")","or","the","brackets","will","be","broken"]
code: def pretty_print(self, normalize=None):
      """
      Print with newlines & indentation on each line
  
      Preterminals and nodes with all preterminal children go on their own line
  
      You can pass in your own normalize() function.  If you do,
      make sure the function updates the parens to be something
      other than () or the brackets will be broken
      """
      if normalize is None:
          normalize = lambda x: x.replace("(", "-LRB-").replace(
              ")", "-RRB-"
          )
  
      indent = 0
      with StringIO() as buf:
          stack = deque()
          stack.append(self)
          while len(stack) > 0:
              node = stack.pop()
  
              if node is CLOSE_PAREN:
                  # if we're trying to pretty print trees, pop all off close parens
                  # then write a newline
                  while node is CLOSE_PAREN:
                      indent -= 1
                      buf.write(CLOSE_PAREN)
                      if len(stack) == 0:
                          node = None
                          break
                      node = stack.pop()
                  buf.write("\n")
                  if node is None:
                      break
                  stack.append(node)
              elif node.is_preterminal():
                  buf.write("  " * indent)
                  buf.write(
                      "%s%s %s%s"
                      % (
                          OPEN_PAREN,
                          normalize(node.label),
                          normalize(node.children[0].label),
                          CLOSE_PAREN,
                      )
                  )
                  if len(stack) == 0 or stack[-1] is not CLOSE_PAREN:
                      buf.write("\n")
              elif all(x.is_preterminal() for x in node.children):
                  buf.write("  " * indent)
                  buf.write(
                      "%s%s" % (OPEN_PAREN, normalize(node.label))
                  )
                  for child in node.children:
                      buf.write(
                          " %s%s %s%s"
                          % (
                              OPEN_PAREN,
                              normalize(child.label),
                              normalize(child.children[0].label),
                              CLOSE_PAREN,
                          )
                      )
                  buf.write(CLOSE_PAREN)
                  if len(stack) == 0 or stack[-1] is not CLOSE_PAREN:
                      buf.write("\n")
              else:
                  buf.write("  " * indent)
                  buf.write(
                      "%s%s\n" % (OPEN_PAREN, normalize(node.label))
                  )
                  stack.append(CLOSE_PAREN)
                  for child in reversed(node.children):
                      stack.append(child)
                  indent += 1
  
          buf.seek(0)
          return buf.read()
  
imports: from collections import deque, Counter
  from enum import Enum
  from io import StringIO
  import itertools
  import re
  import warnings
  from stanza.models.common.stanza_object import StanzaObject
label_desc: Use image node_id 8 for calling the Tree obj's underlying member method code with example usage: obj.pretty_print(normalize) and returns: buf