diff --git a/doc/grammars/type.ebnf b/doc/grammars/type.ebnf index 216def1..0ab4ad9 100644 --- a/doc/grammars/type.ebnf +++ b/doc/grammars/type.ebnf @@ -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]* diff --git a/doc/grammars/type.peg b/doc/grammars/type.peg index 721c54e..857f132 100644 --- a/doc/grammars/type.peg +++ b/doc/grammars/type.peg @@ -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]* diff --git a/src/Ast/Type/ThisTypeNode.php b/src/Ast/Type/ThisTypeNode.php new file mode 100644 index 0000000..03e2c52 --- /dev/null +++ b/src/Ast/Type/ThisTypeNode.php @@ -0,0 +1,12 @@ +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);