[refactoring] update ast structure of "StmtExpression", "StmtInterface" and "StmtProperty" nodes

This commit is contained in:
Vadym Slizov 2020-11-22 18:54:13 +02:00
parent 2d6ae3a9a2
commit 5bd63d90ba
No known key found for this signature in database
GPG Key ID: AEA2A9388EF42A4A
5 changed files with 158 additions and 148 deletions

BIN
internal/php5/php5.go generated

Binary file not shown.

View File

@ -1033,15 +1033,13 @@ unticked_statement:
}
| yield_expr ';'
{
$$ = &ast.StmtExpression{ast.Node{}, $1}
// save position
$$.GetNode().Position = position.NewNodeTokenPosition($1, $2)
// save comments
yylex.(*Parser).MoveFreeFloating($1, $$)
yylex.(*Parser).setFreeFloating($$, token.Expr, $2.SkippedTokens)
yylex.(*Parser).setToken($$, token.SemiColon, $2.SkippedTokens)
$$ = &ast.StmtExpression{
Node: ast.Node{
Position: position.NewNodeTokenPosition($1, $2),
},
Expr: $1,
SemiColonTkn: $2,
}
}
| T_GLOBAL global_var_list ';'
{
@ -1081,15 +1079,13 @@ unticked_statement:
}
| expr ';'
{
$$ = &ast.StmtExpression{ast.Node{}, $1}
// save position
$$.GetNode().Position = position.NewNodeTokenPosition($1, $2)
// save comments
yylex.(*Parser).MoveFreeFloating($1, $$)
yylex.(*Parser).setFreeFloating($$, token.Expr, $2.SkippedTokens)
yylex.(*Parser).setToken($$, token.SemiColon, $2.SkippedTokens)
$$ = &ast.StmtExpression{
Node: ast.Node{
Position: position.NewNodeTokenPosition($1, $2),
},
Expr: $1,
SemiColonTkn: $2,
}
}
| T_UNSET '(' unset_variables ')' ';'
{
@ -1439,22 +1435,23 @@ unticked_class_declaration_statement:
}
| interface_entry T_STRING interface_extends_list '{' class_statement_list '}'
{
name := &ast.Identifier{
$$ = &ast.StmtInterface{
Node: ast.Node{
Position: position.NewTokensPosition($1, $6),
},
InterfaceTkn: $1,
InterfaceName: &ast.Identifier{
Node: ast.Node{
Position: position.NewTokenPosition($2),
},
IdentifierTkn: $2,
Value: $2.Value,
},
Extends: $3,
OpenCurlyBracketTkn: $4,
Stmts: $5,
CloseCurlyBracketTkn: $6,
}
$$ = &ast.StmtInterface{ast.Node{}, name, $3, $5}
// save position
$$.GetNode().Position = position.NewTokensPosition($1, $6)
// save comments
yylex.(*Parser).setFreeFloating($$, token.Start, $1.SkippedTokens)
yylex.(*Parser).setFreeFloating($$, token.Name, $4.SkippedTokens)
yylex.(*Parser).setFreeFloating($$, token.Stmts, $6.SkippedTokens)
}
;
@ -2851,87 +2848,92 @@ member_modifier:
class_variable_declaration:
class_variable_declaration ',' T_VARIABLE
{
identifier := &ast.Identifier{
$$ = append($1, &ast.StmtProperty{
Node: ast.Node{
Position: position.NewTokenPosition($3),
},
Var: &ast.ExprVariable{
Node: ast.Node{
Position: position.NewTokenPosition($3),
},
VarName: &ast.Identifier{
Node: ast.Node{
Position: position.NewTokenPosition($3),
},
IdentifierTkn: $3,
Value: $3.Value,
}
variable := &ast.ExprVariable{ast.Node{}, identifier}
property := &ast.StmtProperty{ast.Node{}, variable, nil}
$$ = append($1, property)
// save position
variable.GetNode().Position = position.NewTokenPosition($3)
property.GetNode().Position = position.NewTokenPosition($3)
// save comments
yylex.(*Parser).setFreeFloating(lastNode($1), token.End, $2.SkippedTokens)
yylex.(*Parser).setFreeFloating(property, token.Start, $3.SkippedTokens)
},
},
})
}
| class_variable_declaration ',' T_VARIABLE '=' static_scalar
{
identifier := &ast.Identifier{
$$ = append($1, &ast.StmtProperty{
Node: ast.Node{
Position: position.NewTokenNodePosition($3, $5),
},
Var: &ast.ExprVariable{
Node: ast.Node{
Position: position.NewTokenPosition($3),
},
VarName: &ast.Identifier{
Node: ast.Node{
Position: position.NewTokenPosition($3),
},
IdentifierTkn: $3,
Value: $3.Value,
}
variable := &ast.ExprVariable{ast.Node{}, identifier}
property := &ast.StmtProperty{ast.Node{}, variable, $5}
$$ = append($1, property)
// save position
variable.GetNode().Position = position.NewTokenPosition($3)
property.GetNode().Position = position.NewTokenNodePosition($3, $5)
// save comments
yylex.(*Parser).setFreeFloating(lastNode($1), token.End, $2.SkippedTokens)
yylex.(*Parser).setFreeFloating(property, token.Start, $3.SkippedTokens)
yylex.(*Parser).setFreeFloating(property, token.Var, $4.SkippedTokens)
},
},
EqualTkn: $4,
Expr: $5,
})
}
| T_VARIABLE
{
identifier := &ast.Identifier{
$$ = []ast.Vertex{
&ast.StmtProperty{
Node: ast.Node{
Position: position.NewTokenPosition($1),
},
Var: &ast.ExprVariable{
Node: ast.Node{
Position: position.NewTokenPosition($1),
},
VarName: &ast.Identifier{
Node: ast.Node{
Position: position.NewTokenPosition($1),
},
IdentifierTkn: $1,
Value: $1.Value,
},
},
Expr: nil,
},
}
variable := &ast.ExprVariable{ast.Node{}, identifier}
property := &ast.StmtProperty{ast.Node{}, variable, nil}
$$ = []ast.Vertex{property}
// save position
variable.GetNode().Position = position.NewTokenPosition($1)
property.GetNode().Position = position.NewTokenPosition($1)
// save comments
yylex.(*Parser).setFreeFloating(property, token.Start, $1.SkippedTokens)
}
| T_VARIABLE '=' static_scalar
{
identifier := &ast.Identifier{
$$ = []ast.Vertex{
&ast.StmtProperty{
Node: ast.Node{
Position: position.NewTokenNodePosition($1, $3),
},
Var: &ast.ExprVariable{
Node: ast.Node{
Position: position.NewTokenPosition($1),
},
VarName: &ast.Identifier{
Node: ast.Node{
Position: position.NewTokenPosition($1),
},
IdentifierTkn: $1,
Value: $1.Value,
},
},
EqualTkn: $2,
Expr: $3,
},
}
variable := &ast.ExprVariable{ast.Node{}, identifier}
property := &ast.StmtProperty{ast.Node{}, variable, $3}
$$ = []ast.Vertex{property}
// save position
variable.GetNode().Position = position.NewTokenPosition($1)
property.GetNode().Position = position.NewTokenNodePosition($1, $3)
// save comments
yylex.(*Parser).setFreeFloating(property, token.Start, $2.SkippedTokens)
yylex.(*Parser).setFreeFloating(property, token.Var, $2.SkippedTokens)
}
;

BIN
internal/php7/php7.go generated

Binary file not shown.

View File

@ -989,15 +989,13 @@ statement:
}
| expr ';'
{
$$ = &ast.StmtExpression{ast.Node{}, $1}
// save position
$$.GetNode().Position = position.NewNodeTokenPosition($1, $2)
// save comments
yylex.(*Parser).MoveFreeFloating($1, $$)
yylex.(*Parser).setFreeFloating($$, token.Expr, $2.SkippedTokens)
yylex.(*Parser).setToken($$, token.SemiColon, $2.SkippedTokens)
$$ = &ast.StmtExpression{
Node: ast.Node{
Position: position.NewNodeTokenPosition($1, $2),
},
Expr: $1,
SemiColonTkn: $2,
}
}
| T_UNSET '(' unset_variables possible_comma ')' ';'
{
@ -1366,22 +1364,23 @@ trait_declaration_statement:
interface_declaration_statement:
T_INTERFACE T_STRING interface_extends_list backup_doc_comment '{' class_statement_list '}'
{
name := &ast.Identifier{
$$ = &ast.StmtInterface{
Node: ast.Node{
Position: position.NewTokensPosition($1, $7),
},
InterfaceTkn: $1,
InterfaceName: &ast.Identifier{
Node: ast.Node{
Position: position.NewTokenPosition($2),
},
IdentifierTkn: $2,
Value: $2.Value,
},
Extends: $3,
OpenCurlyBracketTkn: $5,
Stmts: $6,
CloseCurlyBracketTkn: $7,
}
$$ = &ast.StmtInterface{ast.Node{}, name, $3, $6}
// save position
$$.GetNode().Position = position.NewTokensPosition($1, $7)
// save comments
yylex.(*Parser).setFreeFloating($$, token.Start, $1.SkippedTokens)
yylex.(*Parser).setFreeFloating($$, token.Name, $5.SkippedTokens)
yylex.(*Parser).setFreeFloating($$, token.Stmts, $7.SkippedTokens)
}
;
@ -2609,42 +2608,46 @@ property_list:
property:
T_VARIABLE backup_doc_comment
{
identifier := &ast.Identifier{
$$ = &ast.StmtProperty{
Node: ast.Node{
Position: position.NewTokenPosition($1),
},
Var: &ast.ExprVariable{
Node: ast.Node{
Position: position.NewTokenPosition($1),
},
VarName: &ast.Identifier{
Node: ast.Node{
Position: position.NewTokenPosition($1),
},
IdentifierTkn: $1,
Value: $1.Value,
},
},
Expr: nil,
}
variable := &ast.ExprVariable{ast.Node{}, identifier}
$$ = &ast.StmtProperty{ast.Node{}, variable, nil}
// save position
variable.GetNode().Position = position.NewTokenPosition($1)
$$.GetNode().Position = position.NewTokenPosition($1)
// save comments
yylex.(*Parser).setFreeFloating($$, token.Start, $1.SkippedTokens)
}
| T_VARIABLE '=' expr backup_doc_comment
{
identifier := &ast.Identifier{
$$ = &ast.StmtProperty{
Node: ast.Node{
Position: position.NewTokenNodePosition($1, $3),
},
Var: &ast.ExprVariable{
Node: ast.Node{
Position: position.NewTokenPosition($1),
},
VarName: &ast.Identifier{
Node: ast.Node{
Position: position.NewTokenPosition($1),
},
IdentifierTkn: $1,
Value: $1.Value,
},
},
EqualTkn: $2,
Expr: $3,
}
variable := &ast.ExprVariable{ast.Node{}, identifier}
$$ = &ast.StmtProperty{ast.Node{}, variable, $3}
// save position
variable.GetNode().Position = position.NewTokenPosition($1)
$$.GetNode().Position = position.NewTokenNodePosition($1, $3)
// save comments
yylex.(*Parser).setFreeFloating($$, token.Start, $1.SkippedTokens)
yylex.(*Parser).setFreeFloating($$, token.Var, $2.SkippedTokens)
}
;

View File

@ -439,6 +439,7 @@ func (n *StmtElseIf) Accept(v NodeVisitor) {
type StmtExpression struct {
Node
Expr Vertex
SemiColonTkn *token.Token
}
func (n *StmtExpression) Accept(v NodeVisitor) {
@ -594,9 +595,12 @@ func (n *StmtInlineHtml) Accept(v NodeVisitor) {
// StmtInterface node
type StmtInterface struct {
Node
InterfaceTkn *token.Token
InterfaceName Vertex
Extends Vertex
OpenCurlyBracketTkn *token.Token
Stmts []Vertex
CloseCurlyBracketTkn *token.Token
}
func (n *StmtInterface) Accept(v NodeVisitor) {
@ -655,6 +659,7 @@ func (n *StmtNop) Accept(v NodeVisitor) {
type StmtProperty struct {
Node
Var Vertex
EqualTkn *token.Token
Expr Vertex
}