private function parseWithPreviousResult(InputStreamInterface $input, RepeaterExpressionResult $previous_result)
 {
     $part_results = $previous_result->getResults();
     $length = count($part_results);
     if ($length > 0) {
         //we can backtrack the previous result
         $index = $length - 1;
         $position = $previous_result->getLength() - $part_results[$index]->getLength();
         $input->move($position);
         $last_part = $this->inner->parseInputStreamWithBacktracking($input, $part_results[$index]);
         if ($last_part !== null) {
             //succesfully backtracked, replace the entry
             $part_results[$index] = $last_part;
             return new RepeaterExpressionResult($part_results);
         }
         //failed to backtrack, fallthrough and find the next entry
         $input->move($part_results[$index]->getLength());
     }
     if ($length >= $this->maximum) {
         return null;
     }
     $next_result = $this->inner->parseInputStreamWithBacktracking($input);
     if ($next_result === null) {
         $input->move(-$previous_result->getLength());
         return null;
     }
     $part_results[] = $next_result;
     return new RepeaterExpressionResult($part_results);
 }
 private function parseWithPreviousResult(InputStreamInterface $input, RepeaterExpressionResult $previous_result)
 {
     $part_results = iterator_to_array($previous_result->getResults());
     $length = count($part_results);
     if ($length === 0) {
         return null;
     }
     $index = $length - 1;
     //we need to backtrack the last result.
     //find the position where the last entry starts
     $position = $previous_result->getLength() - $part_results[$index]->getLength();
     $input->move($position);
     //backtrack that entry
     $last_part = $this->inner->parseInputStreamWithBacktracking($input, $part_results[$index]);
     if ($last_part === null) {
         //it failed, our new result excludes this item. Still atleast the minimum?
         if ($index < $this->minimum) {
             $input->move(-$position);
             return null;
         }
         return new RepeaterExpressionResult(new \ArrayIterator(array_slice($part_results, 0, $index)));
     }
     //replace the entry
     $part_results[$index] = $last_part;
     return new RepeaterExpressionResult(new \ArrayIterator($part_results));
 }