/**
  * Constructor.
  *
  * @param \Dissect\Parser\Rule $rule The conflicting grammar rule.
  * @param string $lookahead The conflicting lookahead to shift.
  * @param \Dissect\Parser\LALR1\Analysis\Automaton $automaton The faulty automaton.
  */
 public function __construct($state, Rule $rule, $lookahead, Automaton $automaton)
 {
     $components = $rule->getComponents();
     parent::__construct(sprintf(self::MESSAGE, $rule->getNumber(), $rule->getName(), empty($components) ? '/* empty */' : implode(' ', $components), $lookahead, $state), $state, $automaton);
     $this->rule = $rule;
     $this->lookahead = $lookahead;
 }
示例#2
0
 /**
  * Sets the callback for the current rule.
  *
  * @param callable $callback The callback.
  *
  * @return \Dissect\Parser\Grammar This instance.
  */
 public function call($callback)
 {
     if ($this->currentRule === null) {
         throw new LogicException('You must specify a rule first.');
     }
     $this->currentRule->setCallback($callback);
     return $this;
 }
示例#3
0
 /**
  * @test
  */
 public function getComponentShouldReturnNullIfAskedForComponentOutOfRange()
 {
     $r = new Rule(1, 'Foo', array('x', 'y'));
     $this->assertEquals('y', $r->getComponent(1));
     $this->assertNull($r->getComponent(2));
 }
示例#4
0
 /**
  * Returns all components that haven't been recognized
  * so far.
  *
  * @return array The unrecognized components.
  */
 public function getUnrecognizedComponents()
 {
     return array_slice($this->rule->getComponents(), $this->dotIndex + 1);
 }