parsers = $parsers; $this->errors = []; } public function parse($code) { list($firstStmts, $firstErrors, $firstError) = $this->tryParse($this->parsers[0], $code); if ($firstErrors === []) { $this->errors = []; return $firstStmts; } for ($i = 1, $c = count($this->parsers); $i < $c; ++$i) { list($stmts, $errors) = $this->tryParse($this->parsers[$i], $code); if ($errors === []) { $this->errors = []; return $stmts; } } $this->errors = $firstErrors; if ($firstError) { throw $firstError; } return $firstStmts; } public function getErrors() { return $this->errors; } private function tryParse(ParserInterface $parser, $code) { $stmts = null; $error = null; try { $stmts = $parser->parse($code); } catch (Error $error) {} $errors = $parser->getErrors(); return [$stmts, $errors, $error]; } }