def parse(self, nodes):
    """Given a stream of node data, try to parse the nodes according to the machine's graph."""
    self.last_node_type = self.initial_node_type
    for node_number, node in enumerate(nodes):
      try:
        self.step(node)
      except Exception as ex:
        raise Exception("An error occurred on node {}".format(node_number)) from ex
Given a stream of node data, try to parse the nodes according to the machine's graph.