예제 #1
0
 /**
  * @param Item[] $items
  * @param string[] $input
  * @param Rule $rule
  * @return Tree
  */
 private function buildTree(&$items, &$input, Rule $rule)
 {
     $result = new Tree($rule);
     $children = [];
     $entries = array_reverse($rule->getEntries());
     foreach ($entries as $entry) {
         $class = get_class($entry);
         switch ($class) {
             case Reference::class:
                 $item = $this->consumeItemMatchingRule($items, $entry->getRuleName());
                 $children[] = $this->buildTree($items, $input, $item->getRule());
                 break;
             case TokenReference::class:
                 $children[] = new Leaf(array_pop($input));
                 break;
             default:
                 echo 'BLERGH!!!!' . "\n";
                 break;
         }
     }
     $children = array_reverse($children);
     foreach ($children as $child) {
         $result->addChild($child);
     }
     return $result;
 }
예제 #2
0
 private function walkRule(Tree $tree)
 {
     list($identifier, $separator, $pattern) = $tree->getChildren();
     $insignificantSeparator = $this->visit($separator) === '_>' ?: false;
     return new Definition($this->visit($identifier), preg_replace('/\\/(.+)\\//', '$1', $this->visit($pattern)), $insignificantSeparator);
 }
예제 #3
0
 private function walkToken(Tree $tree)
 {
     $token = $this->visit($tree->getChildren()[0]);
     $token = substr($token, 1);
     return new TokenReference($token);
 }