Example #1
0
 public function parse(Input $input)
 {
     if (!$input->complete()) {
         return $input->errorHere("Unable to process {$input->get()}")->addParser($this);
     }
     return $input->nonCapturingMatchHere()->addParser($this);
 }
Example #2
0
 /**
  * Parse the given input
  *
  * @param Input $input
  *
  * @return mixed result
  */
 public function parse(Input $input)
 {
     if ($input->peek(0) === $this->char) {
         $input->consume(1);
         return $input->matchHere($this->char);
     }
     return $input->errorHere("{$this->char} was not found.")->addParser($this);
 }
Example #3
0
 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);
     }
 }
Example #4
0
 public function parse(Input $input)
 {
     if ($input->complete()) {
         return $input->errorHere('Not cannot be matched at end of stream.')->addParser($this);
     }
     // Initially no parser should match, this would be a zero width result
     if ($this->matches($input)) {
         return $input->errorHere("Found a match at the start of the source {$input->get()}")->addParser($this);
     }
     $consumed = '';
     while (!$this->matches($input) && !$input->complete()) {
         $consumed .= $input->peek(0);
         $input->consume(1);
     }
     return $input->matchHere([$consumed])->addParser($this);
 }