pyebnf/operator.py
def _reduce(nodes):
  """Finds the first operator in the list, converts it and its operands to a OptreeNode, then
  returns a new list with the operator and operands replaced by the new OptreeNode.
  """
  i = 0
  while i < len(nodes):
    if isinstance(nodes[i], OperatorNode):
      break
    else:
      i += 1

  if i == len(nodes):
    raise OperatorError("No operator found")

  operator_node = nodes[i]
  operator = operator_node.operator
  operands_lbound = i - operator.cardinality

  if operands_lbound < 0:
    raise OperatorError("Insufficient operands for operator {0}".format(operator.symbol))

  return nodes[:operands_lbound] + \
         [OptreeNode(operator_node, tuple(nodes[operands_lbound:i]))] + \
         nodes[i+1:]
def _reduce(nodes):
  """Finds the first operator in the list, converts it and its operands to a OptreeNode, then
  returns a new list with the operator and operands replaced by the new OptreeNode.
  """
  i = 0
  while i < len(nodes):
    if isinstance(nodes[i], OperatorNode):
      break
    else:
      i += 1

  if i == len(nodes):
    raise OperatorError("No operator found")

  operator_node = nodes[i]
  operator = operator_node.operator
  operands_lbound = i - operator.cardinality

  if operands_lbound < 0:
    raise OperatorError("Insufficient operands for operator {0}".format(operator.symbol))

  return nodes[:operands_lbound] + \
         [OptreeNode(operator_node, tuple(nodes[operands_lbound:i]))] + \
         nodes[i+1:]
Finds the first operator in the list, converts it and its operands to a OptreeNode, then
  returns a new list with the operator and operands replaced by the new OptreeNode.