public function parse(Input $input) { if (!$input->complete()) { return $input->errorHere("Unable to process {$input->get()}")->addParser($this); } return $input->nonCapturingMatchHere()->addParser($this); }
public function testSetOffset() { $input = new Input('asdf'); $input->setOffset(2); $this->assertEquals(2, $input->getOffset()); $this->assertEquals('df', $input->get()); }
public function parse(Input $input) { if (!$input->match($this->expression, $matches)) { return $input->errorHere("Expected regex '{$this->expression}' to match '{$input->get()}', it does not.")->addParser($this); } $output = $input->getAndConsume(strlen($matches[0])); if (!$this->capturing) { return $input->nonCapturingMatchHere($output)->addParser($this); } else { return $input->matchHere($output)->addParser($this); } }