Example #1
0
 public function __construct($name, $options = [])
 {
     parent::__construct($name, $options);
     if (isset($options['inject'])) {
         $this->inject = $options['inject'];
     }
 }
 public function testStartSucceedsEnd()
 {
     $start = new Token('name', ['pos' => 1]);
     $end = new Token('name', ['pos' => 1]);
     $start->setEnd($end);
     $this->assertEquals(-1, Token::compare($start, $end));
     $this->assertEquals(1, Token::compare($end, $start));
 }
Example #3
0
 protected function testToken($desired, Token $actual)
 {
     if (isset($desired['pos']) && $desired['pos'] !== $actual->pos) {
         return false;
     }
     if (isset($desired['name']) && $desired['name'] !== $actual->name) {
         return false;
     }
     if (isset($desired['rule']) && $desired['rule'] !== $actual->rule) {
         return false;
     }
     if (isset($desired['index']) && $desired['index'] !== $actual->index) {
         return false;
     }
     if (in_array('start', $desired, true) && !$actual->isStart()) {
         return false;
     }
     if (in_array('end', $desired, true) && !$actual->isEnd()) {
         return false;
     }
     return true;
 }
Example #4
0
 public static function compare(Token $a, Token $b)
 {
     $multiplier = $a->isEnd() ? -1 : 1;
     if ($a->isStart() && $b->isEnd() || $a->isEnd() && $b->isStart()) {
         if ($a->getStart() == $b) {
             return 1;
         }
         if ($a->getEnd() == $b) {
             return -1;
         } else {
             return $multiplier;
         }
     } elseif (($rule = Helper::cmp($b->rule->priority, $a->rule->priority)) !== 0) {
         return $multiplier * $rule;
     } else {
         return $multiplier * ($a->id < $b->id ? -1 : 1);
     }
 }