Example #1
0
 /**
  * @param Item $item
  * @return bool
  */
 public function hasItem(Item $item)
 {
     /** @var \ArrayIterator|Item[] $items */
     $items = new \ArrayIterator($this->items->getArrayCopy());
     foreach ($items as $currentItem) {
         $matches = true;
         $matches = $matches && $item->getRule() === $currentItem->getRule();
         $matches = $matches && $item->getEntryPosition() === $currentItem->getEntryPosition();
         $matches = $matches && $item->getInputPosition() === $currentItem->getInputPosition();
         if ($matches) {
             return true;
         }
     }
     return false;
 }
Example #2
0
 /**
  * @param State $state
  * @param Token[] $input
  * @param Item $item
  * @param TokenReference $tokenReference
  */
 private function scan(State $state, $input, Item $item, TokenReference $tokenReference)
 {
     $inputPosition = $state->getSets()->key();
     if (!array_key_exists($inputPosition, $input)) {
         return;
     }
     $token = $input[$inputPosition];
     if ($tokenReference->matchesToken($token)) {
         $nextInputPosition = $inputPosition + 1;
         if (!array_key_exists($nextInputPosition, $state->getSets())) {
             $state->addSet(new Set());
         }
         $nextSet = $state->getSets()[$nextInputPosition];
         $nextSet->addItem(new Item($item->getRule(), $item->getEntryPosition() + 1, $item->getInputPosition()));
     }
 }