public function matchSymbol(Symbol $symbol)
 {
     $matches = $this->predicate->matchSymbol($symbol);
     if ($matches) {
         $this->matchCount++;
     }
     return $matches;
 }
Exemplo n.º 2
0
 /**
  * @param SymbolSet $otherSet
  * @param SymbolPredicate $acceptPredicate
  * @return bool
  */
 public function addSome(SymbolSet $otherSet, SymbolPredicate $acceptPredicate)
 {
     $newSymbolsAdded = false;
     foreach ($otherSet as $otherSymbol) {
         if ($acceptPredicate->matchSymbol($otherSymbol)) {
             $newSymbolsAdded |= $this->add($otherSymbol);
         }
     }
     return $newSymbolsAdded;
 }
Exemplo n.º 3
0
 /**
  * @param Expression $lastVisited
  * @return boolean
  */
 public function continueWalkingAfterVisit(Expression $lastVisited)
 {
     if ($this->countLeft == 0) {
         return false;
     }
     $found = $this->predicateAdapter->matchExpression($lastVisited);
     if ($found) {
         $this->countLeft--;
     }
     return $this->countLeft == 0 ? false : true;
 }
Exemplo n.º 4
0
 /**
  * @param Expression $lastVisited
  * @return boolean
  */
 public function continueWalkingAfterVisit(Expression $lastVisited)
 {
     if (!is_null($this->foundExpression)) {
         return false;
     }
     $found = $this->predicateAdapter->matchExpression($lastVisited);
     if ($found) {
         $this->foundExpression = $lastVisited;
     }
     return !$found;
 }
Exemplo n.º 5
0
 /**
  * @param Symbol $nonTerminal
  * @param SymbolPredicate $acceptPredicate
  * @return ArraySet
  */
 public function filterTerminalSet(Symbol $nonTerminal, SymbolPredicate $acceptPredicate)
 {
     $terminalSetIterator = $this->getTerminalSetIterator($nonTerminal);
     $filtered = new ArraySet();
     while ($terminalSetIterator->valid()) {
         $terminal = $terminalSetIterator->current();
         $terminalSetIterator->next();
         if ($acceptPredicate->matchSymbol($terminal)) {
             $filtered->add($terminal);
         }
     }
     return $filtered;
 }
 /**
  * @param Symbol $symbol
  * @return bool
  */
 protected function collectSymbol(Symbol $symbol)
 {
     if ($this->symbolPredicate->matchSymbol($symbol)) {
         $this->collectedSymbols[] = $symbol;
         return true;
     }
     return false;
 }
Exemplo n.º 7
0
 /**
  * @param \Helstern\Nomsky\Grammar\Symbol\Predicate\SymbolPredicate $predicate
  *
  * @return Symbol|null
  */
 public function findFirst(SymbolPredicate $predicate)
 {
     $found = null;
     foreach ($this->rhs as $symbol) {
         if ($predicate->matchSymbol($symbol)) {
             $found = $symbol;
         }
     }
     return $found;
 }
 /**
  * @param Symbol $symbol
  * @return mixed
  */
 public function matchSymbol(Symbol $symbol)
 {
     return $this->symbolPredicate->matchSymbol($symbol);
 }