Example #1
0
 /**
  * @param string $input
  *
  * @throws ParseException
  * @return mixed
  */
 public function parseString($input)
 {
     $input = new Input($input);
     $parser = new Closure(new Sequence($this, new EofParser()), function ($data) {
         return $data[0];
     });
     $result = $parser->parse($input);
     if ($result->errorMessage) {
         $location = '';
         if ($result->offset) {
             $location = 'At ' . $input->getPositionDescription($result->offset) . ': ';
         }
         throw new ParseException($location . $result->errorMessage . "\nParser Stack:\n - " . $result->getParserStack() . "\n");
     }
     return $result->data;
 }