← All changes
|
vendor/nikic/php-parser/lib/PhpParser/ParserAbstract.php
+23
-1
3.0
→
3.5.9
View file →
| @@ -15,11 +15,14 @@ | ||
| 15 | 15 | use PhpParser\Node\Scalar\String_; |
| 16 | 16 | use PhpParser\Node\Stmt\Class_; |
| 17 | 17 | use PhpParser\Node\Stmt\ClassConst; |
| 18 | 18 | use PhpParser\Node\Stmt\ClassMethod; |
| 19 | +use PhpParser\Node\Stmt\Else_; | |
| 20 | +use PhpParser\Node\Stmt\ElseIf_; | |
| 19 | 21 | use PhpParser\Node\Stmt\Enum_; |
| 20 | 22 | use PhpParser\Node\Stmt\Interface_; |
| 21 | 23 | use PhpParser\Node\Stmt\Namespace_; |
| 24 | +use PhpParser\Node\Stmt\Nop; | |
| 22 | 25 | use PhpParser\Node\Stmt\Property; |
| 23 | 26 | use PhpParser\Node\Stmt\TryCatch; |
| 24 | 27 | use PhpParser\Node\Stmt\UseUse; |
| 25 | 28 | use PhpParser\Node\VarLikeIdentifier; |
| @@ -151,9 +154,9 @@ | ||
| 151 | 154 | * |
| 152 | 155 | * @return Node\Stmt[]|null Array of statements (or null non-throwing error handler is used and |
| 153 | 156 | * the parser was unable to recover from an error). |
| 154 | 157 | */ |
| 155 | - public function parse(string $code, ErrorHandler $errorHandler = null) { | |
| 158 | + public function parse(string $code, ?ErrorHandler $errorHandler = null) { | |
| 156 | 159 | $this->errorHandler = $errorHandler ?: new ErrorHandler\Throwing; |
| 157 | 160 | |
| 158 | 161 | $this->lexer->startLexing($code, $this->errorHandler); |
| 159 | 162 | $result = $this->doParse(); |
| @@ -663,8 +666,9 @@ | ||
| 663 | 666 | 'null' => true, |
| 664 | 667 | 'false' => true, |
| 665 | 668 | 'mixed' => true, |
| 666 | 669 | 'never' => true, |
| 670 | + 'true' => true, | |
| 667 | 671 | ]; |
| 668 | 672 | |
| 669 | 673 | if (!$name->isUnqualified()) { |
| 670 | 674 | return $name; |
| @@ -872,8 +876,26 @@ | ||
| 872 | 876 | $attributes['startTokenPos'] = $commentEndTokenPos + 1; |
| 873 | 877 | $attributes['endTokenPos'] = $commentEndTokenPos; |
| 874 | 878 | } |
| 875 | 879 | return $attributes; |
| 880 | + } | |
| 881 | + | |
| 882 | + /** @param ElseIf_|Else_ $node */ | |
| 883 | + protected function fixupAlternativeElse($node) { | |
| 884 | + // Make sure a trailing nop statement carrying comments is part of the node. | |
| 885 | + $numStmts = \count($node->stmts); | |
| 886 | + if ($numStmts !== 0 && $node->stmts[$numStmts - 1] instanceof Nop) { | |
| 887 | + $nopAttrs = $node->stmts[$numStmts - 1]->getAttributes(); | |
| 888 | + if (isset($nopAttrs['endLine'])) { | |
| 889 | + $node->setAttribute('endLine', $nopAttrs['endLine']); | |
| 890 | + } | |
| 891 | + if (isset($nopAttrs['endFilePos'])) { | |
| 892 | + $node->setAttribute('endFilePos', $nopAttrs['endFilePos']); | |
| 893 | + } | |
| 894 | + if (isset($nopAttrs['endTokenPos'])) { | |
| 895 | + $node->setAttribute('endTokenPos', $nopAttrs['endTokenPos']); | |
| 896 | + } | |
| 897 | + } | |
| 876 | 898 | } |
| 877 | 899 | |
| 878 | 900 | protected function checkClassModifier($a, $b, $modifierPos) { |
| 879 | 901 | try { |