php8.2: added readonly classes support (#26)

This commit is contained in:
Makhnev Petr 2022-06-26 01:18:40 +03:00 committed by GitHub
parent 3dd40d3b5a
commit 7f6cd25376
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 2185 additions and 2052 deletions

View File

@ -0,0 +1,101 @@
package php8_test
import (
"testing"
"github.com/VKCOM/php-parser/internal/tester"
)
func TestClassReadonlyModifier(t *testing.T) {
suite := tester.NewParserDumpTestSuite(t)
suite.UsePHP8()
suite.Code = `<?php
readonly class Foo {
public string $a;
}
final readonly class Boo {
public string $a;
}
`
suite.Expected = `&ast.Root{
Stmts: []ast.Vertex{
&ast.StmtClass{
Modifiers: []ast.Vertex{
&ast.Identifier{
Val: []byte("readonly"),
},
},
Name: &ast.Identifier{
Val: []byte("Foo"),
},
Stmts: []ast.Vertex{
&ast.StmtPropertyList{
Modifiers: []ast.Vertex{
&ast.Identifier{
Val: []byte("public"),
},
},
Type: &ast.Name{
Parts: []ast.Vertex{
&ast.NamePart{
Val: []byte("string"),
},
},
},
Props: []ast.Vertex{
&ast.StmtProperty{
Var: &ast.ExprVariable{
Name: &ast.Identifier{
Val: []byte("$a"),
},
},
},
},
},
},
},
&ast.StmtClass{
Modifiers: []ast.Vertex{
&ast.Identifier{
Val: []byte("final"),
},
&ast.Identifier{
Val: []byte("readonly"),
},
},
Name: &ast.Identifier{
Val: []byte("Boo"),
},
Stmts: []ast.Vertex{
&ast.StmtPropertyList{
Modifiers: []ast.Vertex{
&ast.Identifier{
Val: []byte("public"),
},
},
Type: &ast.Name{
Parts: []ast.Vertex{
&ast.NamePart{
Val: []byte("string"),
},
},
},
Props: []ast.Vertex{
&ast.StmtProperty{
Var: &ast.ExprVariable{
Name: &ast.Identifier{
Val: []byte("$a"),
},
},
},
},
},
},
},
},
},`
suite.Run()
}

File diff suppressed because it is too large Load Diff

View File

@ -869,6 +869,7 @@ class_modifiers:
class_modifier: class_modifier:
T_ABSTRACT { $$ = yylex.(*Parser).builder.NewIdentifier($1) } T_ABSTRACT { $$ = yylex.(*Parser).builder.NewIdentifier($1) }
| T_FINAL { $$ = yylex.(*Parser).builder.NewIdentifier($1) } | T_FINAL { $$ = yylex.(*Parser).builder.NewIdentifier($1) }
| T_READONLY { $$ = yylex.(*Parser).builder.NewIdentifier($1) }
; ;
class_declaration_statement: class_declaration_statement: