public parse ( $code, PhpParser\ErrorHandler $errorHandler = null ) | ||
$errorHandler | PhpParser\ErrorHandler |
public function parse($code, ErrorHandler $errorHandler = null)
{
if (null === $errorHandler) {
$errorHandler = new ErrorHandler\Throwing();
}
list($firstStmts, $firstError) = $this->tryParse($this->parsers[0], $errorHandler, $code);
if ($firstError === null) {
return $firstStmts;
}
for ($i = 1, $c = count($this->parsers); $i < $c; ++$i) {
list($stmts, $error) = $this->tryParse($this->parsers[$i], $errorHandler, $code);
if ($error === null) {
return $stmts;
}
}
throw $firstError;
}
public function testThrownError() { $this->setExpectedException('PhpParser\\Error', 'FAIL A'); $parserA = $this->getMockBuilder('PhpParser\\Parser')->getMock(); $parserA->expects($this->at(0))->method('parse')->will($this->throwException(new Error('FAIL A'))); $parserB = $this->getMockBuilder('PhpParser\\Parser')->getMock(); $parserB->expects($this->at(0))->method('parse')->will($this->throwException(new Error('FAIL B'))); $parser = new Multiple([$parserA, $parserB]); $parser->parse('dummy'); }