diff --git a/internal/php5/php5.go b/internal/php5/php5.go index 3841713..6647192 100644 Binary files a/internal/php5/php5.go and b/internal/php5/php5.go differ diff --git a/internal/php5/php5.y b/internal/php5/php5.y index 5349205..e58d0cf 100644 --- a/internal/php5/php5.y +++ b/internal/php5/php5.y @@ -229,7 +229,7 @@ import ( %type variable_name variable_without_objects dynamic_class_name_reference new_expr class_name_reference static_member %type function_call fully_qualified_class_name combined_scalar combined_scalar_offset general_constant parenthesis_expr %type exit_expr yield_expr function_declaration_statement class_declaration_statement constant_declaration -%type else_single new_else_single unset_variable declare_statement +%type else_single new_else_single unset_variable declare_statement parameter_list non_empty_parameter_list %type finally_statement additional_catch unticked_function_declaration_statement unticked_class_declaration_statement %type optional_class_type parameter class_entry_type class_statement class_constant_declaration %type trait_use_statement function_call_parameter trait_adaptation_statement trait_precedence trait_alias @@ -250,7 +250,7 @@ import ( %type inner_statement_list encaps_list %type elseif_list new_elseif_list non_empty_for_expr %type for_expr case_list catch_statement additional_catches -%type non_empty_additional_catches parameter_list non_empty_parameter_list class_statement_list +%type non_empty_additional_catches class_statement_list %type class_statement_list variable_modifiers method_modifiers %type trait_adaptation_list non_empty_trait_adaptation_list %type non_empty_member_modifiers backticks_expr @@ -1383,7 +1383,8 @@ unticked_function_declaration_statement: Value: $3.Value, }, OpenParenthesisTkn: $4, - Params: $5, + Params: $5.(*ast.ParserSeparatedList).Items, + SeparatorTkns: $5.(*ast.ParserSeparatedList).SeparatorTkns, CloseParenthesisTkn: $6, OpenCurlyBracketTkn: $7, Stmts: $8, @@ -2003,25 +2004,27 @@ new_else_single: parameter_list: non_empty_parameter_list { - $$ = $1; + $$ = $1 } | /* empty */ { - $$ = nil + $$ = &ast.ParserSeparatedList{} } ; non_empty_parameter_list: parameter { - $$ = []ast.Vertex{$1} + $$ = &ast.ParserSeparatedList{ + Items: []ast.Vertex{$1}, + } } | 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 - yylex.(*Parser).setFreeFloating(lastNode($1), token.End, $2.SkippedTokens) + $$ = $1 } ; @@ -2447,7 +2450,8 @@ class_statement: Value: $4.Value, }, OpenParenthesisTkn: $5, - Params: $6, + Params: $6.(*ast.ParserSeparatedList).Items, + SeparatorTkns: $6.(*ast.ParserSeparatedList).SeparatorTkns, CloseParenthesisTkn: $7, Stmt: $8, } @@ -3893,7 +3897,8 @@ expr_without_variable: FunctionTkn: $1, AmpersandTkn: $2, OpenParenthesisTkn: $3, - Params: $4, + Params: $4.(*ast.ParserSeparatedList).Items, + SeparatorTkns: $4.(*ast.ParserSeparatedList).SeparatorTkns, CloseParenthesisTkn: $5, ClosureUse: $6, OpenCurlyBracketTkn: $7, @@ -3911,7 +3916,8 @@ expr_without_variable: FunctionTkn: $2, AmpersandTkn: $3, OpenParenthesisTkn: $4, - Params: $5, + Params: $5.(*ast.ParserSeparatedList).Items, + SeparatorTkns: $5.(*ast.ParserSeparatedList).SeparatorTkns, CloseParenthesisTkn: $6, ClosureUse: $7, OpenCurlyBracketTkn: $8, diff --git a/internal/php7/php7.go b/internal/php7/php7.go index ee03b47..4eb3784 100644 Binary files a/internal/php7/php7.go and b/internal/php7/php7.go differ diff --git a/internal/php7/php7.y b/internal/php7/php7.y index 35d271e..8248833 100644 --- a/internal/php7/php7.y +++ b/internal/php7/php7.y @@ -235,7 +235,7 @@ import ( %type group_use_declaration inline_use_declaration %type mixed_group_use_declaration use_declaration unprefixed_use_declaration %type const_decl inner_statement -%type expr optional_expr +%type expr optional_expr parameter_list non_empty_parameter_list %type declare_statement finally_statement unset_variable variable %type parameter optional_type argument expr_without_variable global_var_list global_var %type static_var_list static_var class_statement trait_adaptation trait_precedence trait_alias @@ -277,7 +277,7 @@ import ( %type case_list trait_adaptation_list %type use_declarations %type top_statement_list -%type inner_statement_list parameter_list non_empty_parameter_list class_statement_list +%type inner_statement_list class_statement_list %type method_modifiers variable_modifiers %type non_empty_member_modifiers class_modifiers @@ -1222,7 +1222,8 @@ function_declaration_statement: Value: $3.Value, }, OpenParenthesisTkn: $5, - Params: $6, + Params: $6.(*ast.ParserSeparatedList).Items, + SeparatorTkns: $6.(*ast.ParserSeparatedList).SeparatorTkns, CloseParenthesisTkn: $7, ColonTkn: $8.(*ast.ReturnType).ColonTkn, ReturnType: $8.(*ast.ReturnType).Type, @@ -1828,21 +1829,23 @@ parameter_list: } | /* empty */ { - $$ = nil + $$ = &ast.ParserSeparatedList{} } ; non_empty_parameter_list: parameter { - $$ = []ast.Vertex{$1} + $$ = &ast.ParserSeparatedList{ + Items: []ast.Vertex{$1}, + } } | 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 - yylex.(*Parser).setFreeFloating(lastNode($1), token.End, $2.SkippedTokens) + $$ = $1 } ; @@ -2201,7 +2204,8 @@ class_statement: Value: $4.Value, }, OpenParenthesisTkn: $6, - Params: $7, + Params: $7.(*ast.ParserSeparatedList).Items, + SeparatorTkns: $7.(*ast.ParserSeparatedList).SeparatorTkns, CloseParenthesisTkn: $8, ColonTkn: $9.(*ast.ReturnType).ColonTkn, ReturnType: $9.(*ast.ReturnType).Type, @@ -3608,7 +3612,8 @@ inline_function: FunctionTkn: $1, AmpersandTkn: $2, OpenParenthesisTkn: $4, - Params: $5, + Params: $5.(*ast.ParserSeparatedList).Items, + SeparatorTkns: $5.(*ast.ParserSeparatedList).SeparatorTkns, CloseParenthesisTkn: $6, ClosureUse: $7, ColonTkn: $8.(*ast.ReturnType).ColonTkn, @@ -3627,7 +3632,8 @@ inline_function: FnTkn: $1, AmpersandTkn: $2, OpenParenthesisTkn: $3, - Params: $4, + Params: $4.(*ast.ParserSeparatedList).Items, + SeparatorTkns: $4.(*ast.ParserSeparatedList).SeparatorTkns, CloseParenthesisTkn: $5, ColonTkn: $6.(*ast.ReturnType).ColonTkn, ReturnType: $6.(*ast.ReturnType).Type, diff --git a/pkg/ast/node.go b/pkg/ast/node.go index 6283064..c231894 100644 --- a/pkg/ast/node.go +++ b/pkg/ast/node.go @@ -269,6 +269,7 @@ type StmtClassMethod struct { MethodName Vertex OpenParenthesisTkn *token.Token Params []Vertex + SeparatorTkns []*token.Token CloseParenthesisTkn *token.Token ColonTkn *token.Token ReturnType Vertex @@ -482,6 +483,7 @@ type StmtFunction struct { FunctionName Vertex OpenParenthesisTkn *token.Token Params []Vertex + SeparatorTkns []*token.Token CloseParenthesisTkn *token.Token ColonTkn *token.Token ReturnType Vertex @@ -955,6 +957,7 @@ type ExprArrowFunction struct { AmpersandTkn *token.Token OpenParenthesisTkn *token.Token Params []Vertex + SeparatorTkns []*token.Token CloseParenthesisTkn *token.Token ColonTkn *token.Token ReturnType Vertex @@ -1019,6 +1022,7 @@ type ExprClosure struct { AmpersandTkn *token.Token OpenParenthesisTkn *token.Token Params []Vertex + SeparatorTkns []*token.Token CloseParenthesisTkn *token.Token ClosureUse *ExprClosureUse ColonTkn *token.Token