[refactoring] update ast structure of "ClassMethod", "Function", "ArrowFunction" and "Closure" nodes

This commit is contained in:
Vadym Slizov 2020-12-04 12:22:06 +02:00
parent f3203c0b5f
commit 132db0e06b
No known key found for this signature in database
GPG Key ID: AEA2A9388EF42A4A
5 changed files with 39 additions and 23 deletions

BIN
internal/php5/php5.go generated

Binary file not shown.

View File

@ -229,7 +229,7 @@ import (
%type <node> variable_name variable_without_objects dynamic_class_name_reference new_expr class_name_reference static_member %type <node> variable_name variable_without_objects dynamic_class_name_reference new_expr class_name_reference static_member
%type <node> function_call fully_qualified_class_name combined_scalar combined_scalar_offset general_constant parenthesis_expr %type <node> function_call fully_qualified_class_name combined_scalar combined_scalar_offset general_constant parenthesis_expr
%type <node> exit_expr yield_expr function_declaration_statement class_declaration_statement constant_declaration %type <node> exit_expr yield_expr function_declaration_statement class_declaration_statement constant_declaration
%type <node> else_single new_else_single unset_variable declare_statement %type <node> else_single new_else_single unset_variable declare_statement parameter_list non_empty_parameter_list
%type <node> finally_statement additional_catch unticked_function_declaration_statement unticked_class_declaration_statement %type <node> finally_statement additional_catch unticked_function_declaration_statement unticked_class_declaration_statement
%type <node> optional_class_type parameter class_entry_type class_statement class_constant_declaration %type <node> optional_class_type parameter class_entry_type class_statement class_constant_declaration
%type <node> trait_use_statement function_call_parameter trait_adaptation_statement trait_precedence trait_alias %type <node> trait_use_statement function_call_parameter trait_adaptation_statement trait_precedence trait_alias
@ -250,7 +250,7 @@ import (
%type <list> inner_statement_list encaps_list %type <list> inner_statement_list encaps_list
%type <list> elseif_list new_elseif_list non_empty_for_expr %type <list> elseif_list new_elseif_list non_empty_for_expr
%type <list> for_expr case_list catch_statement additional_catches %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> non_empty_additional_catches class_statement_list
%type <list> class_statement_list variable_modifiers method_modifiers %type <list> class_statement_list variable_modifiers method_modifiers
%type <list> trait_adaptation_list non_empty_trait_adaptation_list %type <list> trait_adaptation_list non_empty_trait_adaptation_list
%type <list> non_empty_member_modifiers backticks_expr %type <list> non_empty_member_modifiers backticks_expr
@ -1383,7 +1383,8 @@ unticked_function_declaration_statement:
Value: $3.Value, Value: $3.Value,
}, },
OpenParenthesisTkn: $4, OpenParenthesisTkn: $4,
Params: $5, Params: $5.(*ast.ParserSeparatedList).Items,
SeparatorTkns: $5.(*ast.ParserSeparatedList).SeparatorTkns,
CloseParenthesisTkn: $6, CloseParenthesisTkn: $6,
OpenCurlyBracketTkn: $7, OpenCurlyBracketTkn: $7,
Stmts: $8, Stmts: $8,
@ -2003,25 +2004,27 @@ new_else_single:
parameter_list: parameter_list:
non_empty_parameter_list non_empty_parameter_list
{ {
$$ = $1; $$ = $1
} }
| /* empty */ | /* empty */
{ {
$$ = nil $$ = &ast.ParserSeparatedList{}
} }
; ;
non_empty_parameter_list: non_empty_parameter_list:
parameter parameter
{ {
$$ = []ast.Vertex{$1} $$ = &ast.ParserSeparatedList{
Items: []ast.Vertex{$1},
}
} }
| non_empty_parameter_list ',' parameter | non_empty_parameter_list ',' parameter
{ {
$$ = 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 $$ = $1
yylex.(*Parser).setFreeFloating(lastNode($1), token.End, $2.SkippedTokens)
} }
; ;
@ -2447,7 +2450,8 @@ class_statement:
Value: $4.Value, Value: $4.Value,
}, },
OpenParenthesisTkn: $5, OpenParenthesisTkn: $5,
Params: $6, Params: $6.(*ast.ParserSeparatedList).Items,
SeparatorTkns: $6.(*ast.ParserSeparatedList).SeparatorTkns,
CloseParenthesisTkn: $7, CloseParenthesisTkn: $7,
Stmt: $8, Stmt: $8,
} }
@ -3893,7 +3897,8 @@ expr_without_variable:
FunctionTkn: $1, FunctionTkn: $1,
AmpersandTkn: $2, AmpersandTkn: $2,
OpenParenthesisTkn: $3, OpenParenthesisTkn: $3,
Params: $4, Params: $4.(*ast.ParserSeparatedList).Items,
SeparatorTkns: $4.(*ast.ParserSeparatedList).SeparatorTkns,
CloseParenthesisTkn: $5, CloseParenthesisTkn: $5,
ClosureUse: $6, ClosureUse: $6,
OpenCurlyBracketTkn: $7, OpenCurlyBracketTkn: $7,
@ -3911,7 +3916,8 @@ expr_without_variable:
FunctionTkn: $2, FunctionTkn: $2,
AmpersandTkn: $3, AmpersandTkn: $3,
OpenParenthesisTkn: $4, OpenParenthesisTkn: $4,
Params: $5, Params: $5.(*ast.ParserSeparatedList).Items,
SeparatorTkns: $5.(*ast.ParserSeparatedList).SeparatorTkns,
CloseParenthesisTkn: $6, CloseParenthesisTkn: $6,
ClosureUse: $7, ClosureUse: $7,
OpenCurlyBracketTkn: $8, OpenCurlyBracketTkn: $8,

BIN
internal/php7/php7.go generated

Binary file not shown.

View File

@ -235,7 +235,7 @@ import (
%type <node> group_use_declaration inline_use_declaration %type <node> group_use_declaration inline_use_declaration
%type <node> mixed_group_use_declaration use_declaration unprefixed_use_declaration %type <node> mixed_group_use_declaration use_declaration unprefixed_use_declaration
%type <node> const_decl inner_statement %type <node> const_decl inner_statement
%type <node> expr optional_expr %type <node> expr optional_expr parameter_list non_empty_parameter_list
%type <node> declare_statement finally_statement unset_variable variable %type <node> declare_statement finally_statement unset_variable variable
%type <node> parameter optional_type argument expr_without_variable global_var_list global_var %type <node> parameter optional_type argument expr_without_variable global_var_list global_var
%type <node> static_var_list static_var class_statement trait_adaptation trait_precedence trait_alias %type <node> static_var_list static_var class_statement trait_adaptation trait_precedence trait_alias
@ -277,7 +277,7 @@ import (
%type <list> case_list trait_adaptation_list %type <list> case_list trait_adaptation_list
%type <list> use_declarations %type <list> use_declarations
%type <list> top_statement_list %type <list> top_statement_list
%type <list> inner_statement_list parameter_list non_empty_parameter_list class_statement_list %type <list> inner_statement_list class_statement_list
%type <list> method_modifiers variable_modifiers %type <list> method_modifiers variable_modifiers
%type <list> non_empty_member_modifiers class_modifiers %type <list> non_empty_member_modifiers class_modifiers
@ -1222,7 +1222,8 @@ function_declaration_statement:
Value: $3.Value, Value: $3.Value,
}, },
OpenParenthesisTkn: $5, OpenParenthesisTkn: $5,
Params: $6, Params: $6.(*ast.ParserSeparatedList).Items,
SeparatorTkns: $6.(*ast.ParserSeparatedList).SeparatorTkns,
CloseParenthesisTkn: $7, CloseParenthesisTkn: $7,
ColonTkn: $8.(*ast.ReturnType).ColonTkn, ColonTkn: $8.(*ast.ReturnType).ColonTkn,
ReturnType: $8.(*ast.ReturnType).Type, ReturnType: $8.(*ast.ReturnType).Type,
@ -1828,21 +1829,23 @@ parameter_list:
} }
| /* empty */ | /* empty */
{ {
$$ = nil $$ = &ast.ParserSeparatedList{}
} }
; ;
non_empty_parameter_list: non_empty_parameter_list:
parameter parameter
{ {
$$ = []ast.Vertex{$1} $$ = &ast.ParserSeparatedList{
Items: []ast.Vertex{$1},
}
} }
| non_empty_parameter_list ',' parameter | non_empty_parameter_list ',' parameter
{ {
$$ = 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 $$ = $1
yylex.(*Parser).setFreeFloating(lastNode($1), token.End, $2.SkippedTokens)
} }
; ;
@ -2201,7 +2204,8 @@ class_statement:
Value: $4.Value, Value: $4.Value,
}, },
OpenParenthesisTkn: $6, OpenParenthesisTkn: $6,
Params: $7, Params: $7.(*ast.ParserSeparatedList).Items,
SeparatorTkns: $7.(*ast.ParserSeparatedList).SeparatorTkns,
CloseParenthesisTkn: $8, CloseParenthesisTkn: $8,
ColonTkn: $9.(*ast.ReturnType).ColonTkn, ColonTkn: $9.(*ast.ReturnType).ColonTkn,
ReturnType: $9.(*ast.ReturnType).Type, ReturnType: $9.(*ast.ReturnType).Type,
@ -3608,7 +3612,8 @@ inline_function:
FunctionTkn: $1, FunctionTkn: $1,
AmpersandTkn: $2, AmpersandTkn: $2,
OpenParenthesisTkn: $4, OpenParenthesisTkn: $4,
Params: $5, Params: $5.(*ast.ParserSeparatedList).Items,
SeparatorTkns: $5.(*ast.ParserSeparatedList).SeparatorTkns,
CloseParenthesisTkn: $6, CloseParenthesisTkn: $6,
ClosureUse: $7, ClosureUse: $7,
ColonTkn: $8.(*ast.ReturnType).ColonTkn, ColonTkn: $8.(*ast.ReturnType).ColonTkn,
@ -3627,7 +3632,8 @@ inline_function:
FnTkn: $1, FnTkn: $1,
AmpersandTkn: $2, AmpersandTkn: $2,
OpenParenthesisTkn: $3, OpenParenthesisTkn: $3,
Params: $4, Params: $4.(*ast.ParserSeparatedList).Items,
SeparatorTkns: $4.(*ast.ParserSeparatedList).SeparatorTkns,
CloseParenthesisTkn: $5, CloseParenthesisTkn: $5,
ColonTkn: $6.(*ast.ReturnType).ColonTkn, ColonTkn: $6.(*ast.ReturnType).ColonTkn,
ReturnType: $6.(*ast.ReturnType).Type, ReturnType: $6.(*ast.ReturnType).Type,

View File

@ -269,6 +269,7 @@ type StmtClassMethod struct {
MethodName Vertex MethodName Vertex
OpenParenthesisTkn *token.Token OpenParenthesisTkn *token.Token
Params []Vertex Params []Vertex
SeparatorTkns []*token.Token
CloseParenthesisTkn *token.Token CloseParenthesisTkn *token.Token
ColonTkn *token.Token ColonTkn *token.Token
ReturnType Vertex ReturnType Vertex
@ -482,6 +483,7 @@ type StmtFunction struct {
FunctionName Vertex FunctionName Vertex
OpenParenthesisTkn *token.Token OpenParenthesisTkn *token.Token
Params []Vertex Params []Vertex
SeparatorTkns []*token.Token
CloseParenthesisTkn *token.Token CloseParenthesisTkn *token.Token
ColonTkn *token.Token ColonTkn *token.Token
ReturnType Vertex ReturnType Vertex
@ -955,6 +957,7 @@ type ExprArrowFunction struct {
AmpersandTkn *token.Token AmpersandTkn *token.Token
OpenParenthesisTkn *token.Token OpenParenthesisTkn *token.Token
Params []Vertex Params []Vertex
SeparatorTkns []*token.Token
CloseParenthesisTkn *token.Token CloseParenthesisTkn *token.Token
ColonTkn *token.Token ColonTkn *token.Token
ReturnType Vertex ReturnType Vertex
@ -1019,6 +1022,7 @@ type ExprClosure struct {
AmpersandTkn *token.Token AmpersandTkn *token.Token
OpenParenthesisTkn *token.Token OpenParenthesisTkn *token.Token
Params []Vertex Params []Vertex
SeparatorTkns []*token.Token
CloseParenthesisTkn *token.Token CloseParenthesisTkn *token.Token
ClosureUse *ExprClosureUse ClosureUse *ExprClosureUse
ColonTkn *token.Token ColonTkn *token.Token