[refactoring] update ast structure of "StmtPropertyList", "StmtTraitAdaptationList", "StmtTraitMethodRef" and "StmtTraitUseAlias" nodes

This commit is contained in:
Vadym Slizov 2020-11-29 21:50:33 +02:00
parent 5bd63d90ba
commit 43f6fab862
No known key found for this signature in database
GPG Key ID: AEA2A9388EF42A4A
5 changed files with 204 additions and 187 deletions

BIN
internal/php5/php5.go generated

Binary file not shown.

View File

@ -237,7 +237,7 @@ import (
%type <node> trait_use_statement function_call_parameter trait_adaptation_statement trait_precedence trait_alias
%type <node> trait_method_reference_fully_qualified trait_method_reference trait_modifiers member_modifier method
%type <node> static_scalar_value static_operation static_var_list global_var_list
%type <node> ctor_arguments function_call_parameter_list echo_expr_list
%type <node> ctor_arguments function_call_parameter_list echo_expr_list class_variable_declaration
%type <node> trait_adaptations unset_variables declare_list
%type <node> switch_case_list non_empty_function_call_parameter_list
%type <node> method_body trait_reference_list
@ -253,7 +253,7 @@ import (
%type <list> array_pair_list assignment_list lexical_var_list elseif_list new_elseif_list non_empty_for_expr
%type <list> for_expr case_list catch_statement additional_catches
%type <list> non_empty_additional_catches parameter_list non_empty_parameter_list class_statement_list
%type <list> class_statement_list variable_modifiers method_modifiers class_variable_declaration
%type <list> class_statement_list variable_modifiers method_modifiers
%type <list> trait_adaptation_list non_empty_trait_adaptation_list
%type <list> non_empty_member_modifiers backticks_expr static_array_pair_list non_empty_static_array_pair_list
@ -2456,15 +2456,15 @@ class_statement_list:
class_statement:
variable_modifiers class_variable_declaration ';'
{
$$ = &ast.StmtPropertyList{ast.Node{}, $1, nil, $2}
// save position
$$.GetNode().Position = position.NewNodeListTokenPosition($1, $3)
// save comments
yylex.(*Parser).MoveFreeFloating($1[0], $$)
yylex.(*Parser).setFreeFloating($$, token.PropertyList, $3.SkippedTokens)
yylex.(*Parser).setToken($$, token.SemiColon, $3.SkippedTokens)
$$ = &ast.StmtPropertyList{
Node: ast.Node{
Position: position.NewNodeListTokenPosition($1, $3),
},
Modifiers: $1,
Properties: $2.(*ast.ParserSeparatedList).Items,
SeparatorTkns: $2.(*ast.ParserSeparatedList).SeparatorTkns,
SemiColonTkn: $3,
}
}
| class_constant_declaration ';'
{
@ -2548,13 +2548,14 @@ trait_adaptations:
}
| '{' trait_adaptation_list '}'
{
$$ = &ast.StmtTraitAdaptationList{ast.Node{}, $2}
$$.GetNode().Position = position.NewTokensPosition($1, $3)
// save comments
yylex.(*Parser).setFreeFloating($$, token.Start, $1.SkippedTokens)
yylex.(*Parser).setFreeFloating($$, token.AdaptationList, $3.SkippedTokens)
$$ = &ast.StmtTraitAdaptationList{
Node: ast.Node{
Position: position.NewTokensPosition($1, $3),
},
OpenParenthesisTkn: $1,
Adaptations: $2,
CloseParenthesisTkn: $3,
}
}
;
@ -2633,20 +2634,18 @@ trait_reference_list:
trait_method_reference:
T_STRING
{
name := &ast.Identifier{
$$ = &ast.StmtTraitMethodRef{
Node: ast.Node{
Position: position.NewTokenPosition($1),
},
IdentifierTkn: $1,
Value: $1.Value,
Method: &ast.Identifier{
Node: ast.Node{
Position: position.NewTokenPosition($1),
},
IdentifierTkn: $1,
Value: $1.Value,
},
}
$$ = &ast.StmtTraitMethodRef{ast.Node{}, nil, name}
// save position
$$.GetNode().Position = position.NewTokenPosition($1)
// save comments
yylex.(*Parser).setFreeFloating($$, token.Start, $1.SkippedTokens)
}
| trait_method_reference_fully_qualified
{
@ -2657,53 +2656,52 @@ trait_method_reference:
trait_method_reference_fully_qualified:
fully_qualified_class_name T_PAAMAYIM_NEKUDOTAYIM T_STRING
{
target := &ast.Identifier{
$$ = &ast.StmtTraitMethodRef{
Node: ast.Node{
Position: position.NewTokenPosition($3),
Position: position.NewNodeTokenPosition($1, $3),
},
Trait: $1,
DoubleColonTkn: $2,
Method: &ast.Identifier{
Node: ast.Node{
Position: position.NewTokenPosition($3),
},
IdentifierTkn: $3,
Value: $3.Value,
},
IdentifierTkn: $3,
Value: $3.Value,
}
$$ = &ast.StmtTraitMethodRef{ast.Node{}, $1, target}
// save position
$$.GetNode().Position = position.NewNodeTokenPosition($1, $3)
// save comments
yylex.(*Parser).MoveFreeFloating($1, $$)
yylex.(*Parser).setFreeFloating($$, token.Name, $2.SkippedTokens)
}
;
trait_alias:
trait_method_reference T_AS trait_modifiers T_STRING
{
alias := &ast.Identifier{
$$ = &ast.StmtTraitUseAlias{
Node: ast.Node{
Position: position.NewTokenPosition($4),
Position: position.NewNodeTokenPosition($1, $4),
},
Ref: $1,
AsTkn: $2,
Modifier: $3,
Alias: &ast.Identifier{
Node: ast.Node{
Position: position.NewTokenPosition($4),
},
IdentifierTkn: $4,
Value: $4.Value,
},
IdentifierTkn: $4,
Value: $4.Value,
}
$$ = &ast.StmtTraitUseAlias{ast.Node{}, $1, $3, alias}
// save position
$$.GetNode().Position = position.NewNodeTokenPosition($1, $4)
// save comments
yylex.(*Parser).MoveFreeFloating($1, $$)
yylex.(*Parser).setFreeFloating($$, token.Ref, $2.SkippedTokens)
}
| trait_method_reference T_AS member_modifier
{
$$ = &ast.StmtTraitUseAlias{ast.Node{}, $1, $3, nil}
// save position
$$.GetNode().Position = position.NewNodesPosition($1, $3)
// save comments
yylex.(*Parser).MoveFreeFloating($1, $$)
yylex.(*Parser).setFreeFloating($$, token.Ref, $2.SkippedTokens)
$$ = &ast.StmtTraitUseAlias{
Node: ast.Node{
Position: position.NewNodesPosition($1, $3),
},
Ref: $1,
AsTkn: $2,
Modifier: $3,
}
}
;
@ -2848,7 +2846,7 @@ member_modifier:
class_variable_declaration:
class_variable_declaration ',' T_VARIABLE
{
$$ = append($1, &ast.StmtProperty{
item := &ast.StmtProperty{
Node: ast.Node{
Position: position.NewTokenPosition($3),
},
@ -2864,11 +2862,16 @@ class_variable_declaration:
Value: $3.Value,
},
},
})
}
$1.(*ast.ParserSeparatedList).SeparatorTkns = append($1.(*ast.ParserSeparatedList).SeparatorTkns, $2)
$1.(*ast.ParserSeparatedList).Items = append($1.(*ast.ParserSeparatedList).Items, item)
$$ = $1
}
| class_variable_declaration ',' T_VARIABLE '=' static_scalar
{
$$ = append($1, &ast.StmtProperty{
item := &ast.StmtProperty{
Node: ast.Node{
Position: position.NewTokenNodePosition($3, $5),
},
@ -2886,52 +2889,61 @@ class_variable_declaration:
},
EqualTkn: $4,
Expr: $5,
})
}
$1.(*ast.ParserSeparatedList).SeparatorTkns = append($1.(*ast.ParserSeparatedList).SeparatorTkns, $2)
$1.(*ast.ParserSeparatedList).Items = append($1.(*ast.ParserSeparatedList).Items, item)
$$ = $1
}
| T_VARIABLE
{
$$ = []ast.Vertex{
&ast.StmtProperty{
Node: ast.Node{
Position: position.NewTokenPosition($1),
},
Var: &ast.ExprVariable{
$$ = &ast.ParserSeparatedList{
Items: []ast.Vertex{
&ast.StmtProperty{
Node: ast.Node{
Position: position.NewTokenPosition($1),
},
VarName: &ast.Identifier{
Var: &ast.ExprVariable{
Node: ast.Node{
Position: position.NewTokenPosition($1),
},
IdentifierTkn: $1,
Value: $1.Value,
VarName: &ast.Identifier{
Node: ast.Node{
Position: position.NewTokenPosition($1),
},
IdentifierTkn: $1,
Value: $1.Value,
},
},
Expr: nil,
},
Expr: nil,
},
}
}
| T_VARIABLE '=' static_scalar
{
$$ = []ast.Vertex{
&ast.StmtProperty{
Node: ast.Node{
Position: position.NewTokenNodePosition($1, $3),
},
Var: &ast.ExprVariable{
$$ = &ast.ParserSeparatedList{
Items: []ast.Vertex{
&ast.StmtProperty{
Node: ast.Node{
Position: position.NewTokenPosition($1),
Position: position.NewTokenNodePosition($1, $3),
},
VarName: &ast.Identifier{
Var: &ast.ExprVariable{
Node: ast.Node{
Position: position.NewTokenPosition($1),
},
IdentifierTkn: $1,
Value: $1.Value,
VarName: &ast.Identifier{
Node: ast.Node{
Position: position.NewTokenPosition($1),
},
IdentifierTkn: $1,
Value: $1.Value,
},
},
EqualTkn: $2,
Expr: $3,
},
EqualTkn: $2,
Expr: $3,
},
}
}

BIN
internal/php7/php7.go generated

Binary file not shown.

View File

@ -247,7 +247,7 @@ import (
%type <node> variable_class_name dereferencable_scalar constant dereferencable
%type <node> callable_expr callable_variable static_member new_variable
%type <node> encaps_var encaps_var_offset echo_expr_list catch_name_list name_list
%type <node> if_stmt const_list non_empty_argument_list
%type <node> if_stmt const_list non_empty_argument_list property_list
%type <node> alt_if_stmt
%type <node> if_stmt_without_else
%type <node> class_const_decl
@ -274,7 +274,7 @@ import (
%type <list> encaps_list backticks_expr namespace_name catch_list class_const_list
%type <list> for_exprs non_empty_for_exprs
%type <list> unprefixed_use_declarations inline_use_declarations property_list
%type <list> unprefixed_use_declarations inline_use_declarations
%type <list> case_list trait_adaptation_list
%type <list> use_declarations lexical_var_list isset_variables non_empty_array_pair_list
%type <list> array_pair_list top_statement_list
@ -2193,15 +2193,16 @@ class_statement_list:
class_statement:
variable_modifiers optional_type property_list ';'
{
$$ = &ast.StmtPropertyList{ast.Node{}, $1, $2, $3}
// save position
$$.GetNode().Position = position.NewNodeListTokenPosition($1, $4)
// save comments
yylex.(*Parser).MoveFreeFloating($1[0], $$)
yylex.(*Parser).setFreeFloating($$, token.PropertyList, $4.SkippedTokens)
yylex.(*Parser).setToken($$, token.SemiColon, $4.SkippedTokens)
$$ = &ast.StmtPropertyList{
Node: ast.Node{
Position: position.NewNodeListTokenPosition($1, $4),
},
Modifiers: $1,
Type: $2,
Properties: $3.(*ast.ParserSeparatedList).Items,
SeparatorTkns: $3.(*ast.ParserSeparatedList).SeparatorTkns,
SemiColonTkn: $4,
}
}
| method_modifiers T_CONST class_const_list ';'
{
@ -2286,23 +2287,24 @@ trait_adaptations:
}
| '{' '}'
{
$$ = &ast.StmtTraitAdaptationList{ast.Node{}, nil}
$$.GetNode().Position = position.NewTokensPosition($1, $2)
// save comments
yylex.(*Parser).setFreeFloating($$, token.Start, $1.SkippedTokens)
yylex.(*Parser).setFreeFloating($$, token.AdaptationList, $2.SkippedTokens)
$$ = &ast.StmtTraitAdaptationList{
Node: ast.Node{
Position: position.NewTokensPosition($1, $2),
},
OpenParenthesisTkn: $1,
CloseParenthesisTkn: $2,
}
}
| '{' trait_adaptation_list '}'
{
$$ = &ast.StmtTraitAdaptationList{ast.Node{}, $2}
$$.GetNode().Position = position.NewTokensPosition($1, $3)
// save comments
yylex.(*Parser).setFreeFloating($$, token.Start, $1.SkippedTokens)
yylex.(*Parser).setFreeFloating($$, token.AdaptationList, $3.SkippedTokens)
$$ = &ast.StmtTraitAdaptationList{
Node: ast.Node{
Position: position.NewTokensPosition($1, $3),
},
OpenParenthesisTkn: $1,
Adaptations: $2,
CloseParenthesisTkn: $3,
}
}
;
@ -2354,88 +2356,84 @@ trait_precedence:
trait_alias:
trait_method_reference T_AS T_STRING
{
alias := &ast.Identifier{
$$ = &ast.StmtTraitUseAlias{
Node: ast.Node{
Position: position.NewTokenPosition($3),
Position: position.NewNodeTokenPosition($1, $3),
},
Ref: $1,
AsTkn: $2,
Alias: &ast.Identifier{
Node: ast.Node{
Position: position.NewTokenPosition($3),
},
IdentifierTkn: $3,
Value: $3.Value,
},
IdentifierTkn: $3,
Value: $3.Value,
}
$$ = &ast.StmtTraitUseAlias{ast.Node{}, $1, nil, alias}
// save position
$$.GetNode().Position = position.NewNodeTokenPosition($1, $3)
// save comments
yylex.(*Parser).MoveFreeFloating($1, $$)
yylex.(*Parser).setFreeFloating($$, token.Ref, $2.SkippedTokens)
}
| trait_method_reference T_AS reserved_non_modifiers
{
alias := &ast.Identifier{
$$ = &ast.StmtTraitUseAlias{
Node: ast.Node{
Position: position.NewTokenPosition($3),
Position: position.NewNodeTokenPosition($1, $3),
},
Ref: $1,
AsTkn: $2,
Alias: &ast.Identifier{
Node: ast.Node{
Position: position.NewTokenPosition($3),
},
IdentifierTkn: $3,
Value: $3.Value,
},
IdentifierTkn: $3,
Value: $3.Value,
}
$$ = &ast.StmtTraitUseAlias{ast.Node{}, $1, nil, alias}
// save position
$$.GetNode().Position = position.NewNodeTokenPosition($1, $3)
// save comments
yylex.(*Parser).MoveFreeFloating($1, $$)
yylex.(*Parser).setFreeFloating($$, token.Ref, $2.SkippedTokens)
}
| trait_method_reference T_AS member_modifier identifier
{
alias := &ast.Identifier{
$$ = &ast.StmtTraitUseAlias{
Node: ast.Node{
Position: position.NewTokenPosition($4),
Position: position.NewNodeTokenPosition($1, $4),
},
Ref: $1,
AsTkn: $2,
Modifier: $3,
Alias: &ast.Identifier{
Node: ast.Node{
Position: position.NewTokenPosition($4),
},
IdentifierTkn: $4,
Value: $4.Value,
},
IdentifierTkn: $4,
Value: $4.Value,
}
$$ = &ast.StmtTraitUseAlias{ast.Node{}, $1, $3, alias}
// save position
$$.GetNode().Position = position.NewNodeTokenPosition($1, $4)
// save comments
yylex.(*Parser).MoveFreeFloating($1, $$)
yylex.(*Parser).setFreeFloating($$, token.Ref, $2.SkippedTokens)
}
| trait_method_reference T_AS member_modifier
{
$$ = &ast.StmtTraitUseAlias{ast.Node{}, $1, $3, nil}
// save position
$$.GetNode().Position = position.NewNodesPosition($1, $3)
// save comments
yylex.(*Parser).MoveFreeFloating($1, $$)
yylex.(*Parser).setFreeFloating($$, token.Ref, $2.SkippedTokens)
$$ = &ast.StmtTraitUseAlias{
Node: ast.Node{
Position: position.NewNodesPosition($1, $3),
},
Ref: $1,
AsTkn: $2,
Modifier: $3,
}
}
;
trait_method_reference:
identifier
{
name := &ast.Identifier{
$$ = &ast.StmtTraitMethodRef{
Node: ast.Node{
Position: position.NewTokenPosition($1),
},
IdentifierTkn: $1,
Value: $1.Value,
Method: &ast.Identifier{
Node: ast.Node{
Position: position.NewTokenPosition($1),
},
IdentifierTkn: $1,
Value: $1.Value,
},
}
$$ = &ast.StmtTraitMethodRef{ast.Node{}, nil, name}
// save position
$$.GetNode().Position = position.NewTokenPosition($1)
// save comments
yylex.(*Parser).setFreeFloating($$, token.Start, $1.SkippedTokens)
}
| absolute_trait_method_reference
{
@ -2446,21 +2444,20 @@ trait_method_reference:
absolute_trait_method_reference:
name T_PAAMAYIM_NEKUDOTAYIM identifier
{
target := &ast.Identifier{
$$ = &ast.StmtTraitMethodRef{
Node: ast.Node{
Position: position.NewTokenPosition($3),
Position: position.NewNodeTokenPosition($1, $3),
},
Trait: $1,
DoubleColonTkn: $2,
Method: &ast.Identifier{
Node: ast.Node{
Position: position.NewTokenPosition($3),
},
IdentifierTkn: $3,
Value: $3.Value,
},
IdentifierTkn: $3,
Value: $3.Value,
}
$$ = &ast.StmtTraitMethodRef{ast.Node{}, $1, target}
// save position
$$.GetNode().Position = position.NewNodeTokenPosition($1, $3)
// save comments
yylex.(*Parser).MoveFreeFloating($1, $$)
yylex.(*Parser).setFreeFloating($$, token.Name, $2.SkippedTokens)
}
;
@ -2594,14 +2591,16 @@ member_modifier:
property_list:
property_list ',' property
{
$$ = append($1, $3)
$1.(*ast.ParserSeparatedList).SeparatorTkns = append($1.(*ast.ParserSeparatedList).SeparatorTkns, $2)
$1.(*ast.ParserSeparatedList).Items = append($1.(*ast.ParserSeparatedList).Items, $3)
// save comments
yylex.(*Parser).setFreeFloating(lastNode($1), token.End, $2.SkippedTokens)
$$ = $1
}
| property
{
$$ = []ast.Vertex{$1}
$$ = &ast.ParserSeparatedList{
Items: []ast.Vertex{$1},
}
}
;

View File

@ -670,9 +670,11 @@ func (n *StmtProperty) Accept(v NodeVisitor) {
// StmtPropertyList node
type StmtPropertyList struct {
Node
Modifiers []Vertex
Type Vertex
Properties []Vertex
Modifiers []Vertex
Type Vertex
Properties []Vertex
SeparatorTkns []*token.Token
SemiColonTkn *token.Token
}
func (n *StmtPropertyList) Accept(v NodeVisitor) {
@ -780,7 +782,9 @@ func (n *StmtTrait) Accept(v NodeVisitor) {
// StmtTraitAdaptationList node
type StmtTraitAdaptationList struct {
Node
Adaptations []Vertex
OpenParenthesisTkn *token.Token
Adaptations []Vertex
CloseParenthesisTkn *token.Token
}
func (n *StmtTraitAdaptationList) Accept(v NodeVisitor) {
@ -790,8 +794,9 @@ func (n *StmtTraitAdaptationList) Accept(v NodeVisitor) {
// StmtTraitMethodRef node
type StmtTraitMethodRef struct {
Node
Trait Vertex
Method Vertex
Trait Vertex
DoubleColonTkn *token.Token
Method Vertex
}
func (n *StmtTraitMethodRef) Accept(v NodeVisitor) {
@ -815,6 +820,7 @@ func (n *StmtTraitUse) Accept(v NodeVisitor) {
type StmtTraitUseAlias struct {
Node
Ref Vertex
AsTkn *token.Token
Modifier Vertex
Alias Vertex
}