pyebnf/operator.py
def postfix_to_optree(nodes):
  """Convert a list of nodes in postfix order to an Optree."""
  while len(nodes) > 1:
    nodes = _reduce(nodes)

  if len(nodes) == 0:
    raise OperatorError("Empty node list")

  node = nodes[0]

  if isinstance(node, OperatorNode):
    raise OperatorError("Operator without operands")

  if isinstance(node, OptreeNode):
    return node

  return OptreeNode(None, (node, ))
def postfix_to_optree(nodes):
  """Convert a list of nodes in postfix order to an Optree."""
  while len(nodes) > 1:
    nodes = _reduce(nodes)

  if len(nodes) == 0:
    raise OperatorError("Empty node list")

  node = nodes[0]

  if isinstance(node, OperatorNode):
    raise OperatorError("Operator without operands")

  if isinstance(node, OptreeNode):
    return node

  return OptreeNode(None, (node, ))
Convert a list of nodes in postfix order to an Optree.