pyebnf/primitive.py
def pprint(root, depth=0, space_unit="    ", *, source_len=0, file=None):
  """Pretting print a parse tree."""
  spacing = space_unit * depth

  if isinstance(root, str):
    print("{0}terminal@(?): {1}".format(spacing, root), file=file)
  else:
    if root.position is None:
      position = -1
    elif root.position < 0:
      position = source_len + root.position
    else:
      position = root.position

    if root.is_value:
      print("{0}{1}@({2}:{3}):\t{4}".format(spacing, root.node_type, position, root.consumed, root.svalue), file=file)
    else:
      print("{0}{1}@({2}:{3}):".format(spacing, root.node_type, position, root.consumed), file=file)
      for child in root.children:
        pprint(child, depth + 1, source_len=source_len, file=file)
def pprint(root, depth=0, space_unit="    ", *, source_len=0, file=None):
  spacing = space_unit * depth

  if isinstance(root, str):
    print("{0}terminal@(?): {1}".format(spacing, root), file=file)
  else:
    if root.position is None:
      position = -1
    elif root.position < 0:
      position = source_len + root.position
    else:
      position = root.position

    if root.is_value:
      print("{0}{1}@({2}:{3}):\t{4}".format(spacing, root.node_type, position, root.consumed, root.svalue), file=file)
    else:
      print("{0}{1}@({2}:{3}):".format(spacing, root.node_type, position, root.consumed), file=file)
      for child in root.children:
        pprint(child, depth + 1, source_len=source_len, file=file)
def pprint ( root , depth = 0 , space_unit = "    " , * , source_len = 0 , file = None ) : spacing = space_unit * depth if isinstance ( root , str ) : print ( "{0}terminal@(?): {1}" . format ( spacing , root ) , file = file ) else : if root . position is None : position = - 1 elif root . position < 0 : position = source_len + root . position else : position = root . position if root . is_value : print ( "{0}{1}@({2}:{3}):\t{4}" . format ( spacing , root . node_type , position , root . consumed , root . svalue ) , file = file ) else : print ( "{0}{1}@({2}:{3}):" . format ( spacing , root . node_type , position , root . consumed ) , file = file ) for child in root . children : pprint ( child , depth + 1 , source_len = source_len , file = file )
Pretting print a parse tree.
Pretting print a parse tree .