protected function power(Parser $t) { $tail = new P\Sequence(); $tail->add(new P\Char('^')); $a = new P\Alternative(); $a->add($t); $a->add(new P\Signed($t)); $tail->add($a); $tail->setHandler(new H\Operator()); $p = new P\Sequence(); $p->add($t); $p->add(new P\Repeat($tail)); return $p; }
public function testErrors() { try { new I\Parser\Repeat(new I\Parser\Number(), 5, 2); $this->assertFalse(true, 'Should exception thrown'); } catch (\Exception $e) { } $a = new I\Parser\Alternative(); $a->add(new I\Parser\Repeat(new I\Parser\Word('Точка'), 1)); $a->add(new I\Parser\Word('Дочка')); $this->assertFalse($a->scan(self::scanner('Почка Ночка'))); $p = new I\Parser\FloatVal('3.14'); $this->assertTrue($p->scan(self::scanner('3.14'))); $this->assertFalse($p->scan(self::scanner('3.16'))); $this->assertFalse($p->scan(self::scanner('3.'))); $this->assertFalse($p->scan(self::scanner('3'))); $p = new I\Parser\FloatVal('3'); $this->assertTrue($p->scan(self::scanner('3'))); $this->assertFalse($p->scan(self::scanner('2'))); $this->assertFalse($p->scan(self::scanner('3.14'))); }