mirror of
https://github.com/danog/phpdoc-parser.git
synced 2025-01-22 22:01:36 +01:00
TypeParser: add support for $this type
This commit is contained in:
parent
85464aa76e
commit
0b3dbb212f
@ -13,6 +13,7 @@ Nullable
|
||||
|
||||
Atomic
|
||||
::= Identifier (Generic | Array)?
|
||||
| ThisType
|
||||
| '(' Type ')' Array?
|
||||
|
||||
Generic
|
||||
@ -21,8 +22,11 @@ Generic
|
||||
Array
|
||||
::= ('[' ']')+
|
||||
|
||||
ThisType
|
||||
::= '$this'
|
||||
|
||||
Identifier
|
||||
::= ('\'? Word)+
|
||||
::= ('\\'? Word)+
|
||||
|
||||
Word
|
||||
::= [a-zA-Z_#x7F-#x10FFFF][0-9a-zA-Z_#x7F-#x10FFFF]*
|
||||
|
@ -13,6 +13,7 @@ Nullable
|
||||
|
||||
Atomic
|
||||
= Identifier (Generic / Array)?
|
||||
/ ThisType
|
||||
/ '(' Type ')' Array?
|
||||
|
||||
Generic
|
||||
@ -21,8 +22,11 @@ Generic
|
||||
Array
|
||||
= ('[' ']')+
|
||||
|
||||
ThisType
|
||||
= '$this'
|
||||
|
||||
Identifier
|
||||
= ('\'? Word)+
|
||||
= ('\\'? Word)+
|
||||
|
||||
Word
|
||||
= [a-zA-Z_\127-\255\\][a-zA-Z0-9_\127-\255\\]*
|
||||
= [a-zA-Z_\\127-\\255][a-zA-Z0-9_\\127-\\255]*
|
||||
|
12
src/Ast/Type/ThisTypeNode.php
Normal file
12
src/Ast/Type/ThisTypeNode.php
Normal file
@ -0,0 +1,12 @@
|
||||
<?php declare(strict_types = 1);
|
||||
|
||||
namespace PHPStan\PhpDocParser\Ast\Type;
|
||||
|
||||
|
||||
class ThisTypeNode implements TypeNode
|
||||
{
|
||||
public function __toString(): string
|
||||
{
|
||||
return '$this';
|
||||
}
|
||||
}
|
@ -38,6 +38,9 @@ class TypeParser
|
||||
$type = $this->parseArray($tokens, $type);
|
||||
}
|
||||
|
||||
} elseif ($tokens->tryConsumeTokenType(Lexer::TOKEN_THIS_VARIABLE)) {
|
||||
return new Ast\Type\ThisTypeNode();
|
||||
|
||||
} else {
|
||||
$type = new Ast\Type\IdentifierTypeNode($tokens->currentTokenValue());
|
||||
$tokens->consumeTokenType(Lexer::TOKEN_IDENTIFIER);
|
||||
|
Loading…
x
Reference in New Issue
Block a user