mirror of
https://github.com/danog/phpdoc-parser.git
synced 2025-01-23 06:12:09 +01:00
TypeParser: add support for $this type
This commit is contained in:
parent
85464aa76e
commit
0b3dbb212f
@ -13,6 +13,7 @@ Nullable
|
|||||||
|
|
||||||
Atomic
|
Atomic
|
||||||
::= Identifier (Generic | Array)?
|
::= Identifier (Generic | Array)?
|
||||||
|
| ThisType
|
||||||
| '(' Type ')' Array?
|
| '(' Type ')' Array?
|
||||||
|
|
||||||
Generic
|
Generic
|
||||||
@ -21,8 +22,11 @@ Generic
|
|||||||
Array
|
Array
|
||||||
::= ('[' ']')+
|
::= ('[' ']')+
|
||||||
|
|
||||||
|
ThisType
|
||||||
|
::= '$this'
|
||||||
|
|
||||||
Identifier
|
Identifier
|
||||||
::= ('\'? Word)+
|
::= ('\\'? Word)+
|
||||||
|
|
||||||
Word
|
Word
|
||||||
::= [a-zA-Z_#x7F-#x10FFFF][0-9a-zA-Z_#x7F-#x10FFFF]*
|
::= [a-zA-Z_#x7F-#x10FFFF][0-9a-zA-Z_#x7F-#x10FFFF]*
|
||||||
|
@ -13,6 +13,7 @@ Nullable
|
|||||||
|
|
||||||
Atomic
|
Atomic
|
||||||
= Identifier (Generic / Array)?
|
= Identifier (Generic / Array)?
|
||||||
|
/ ThisType
|
||||||
/ '(' Type ')' Array?
|
/ '(' Type ')' Array?
|
||||||
|
|
||||||
Generic
|
Generic
|
||||||
@ -21,8 +22,11 @@ Generic
|
|||||||
Array
|
Array
|
||||||
= ('[' ']')+
|
= ('[' ']')+
|
||||||
|
|
||||||
|
ThisType
|
||||||
|
= '$this'
|
||||||
|
|
||||||
Identifier
|
Identifier
|
||||||
= ('\'? Word)+
|
= ('\\'? 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);
|
$type = $this->parseArray($tokens, $type);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
} elseif ($tokens->tryConsumeTokenType(Lexer::TOKEN_THIS_VARIABLE)) {
|
||||||
|
return new Ast\Type\ThisTypeNode();
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
$type = new Ast\Type\IdentifierTypeNode($tokens->currentTokenValue());
|
$type = new Ast\Type\IdentifierTypeNode($tokens->currentTokenValue());
|
||||||
$tokens->consumeTokenType(Lexer::TOKEN_IDENTIFIER);
|
$tokens->consumeTokenType(Lexer::TOKEN_IDENTIFIER);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user