diff --git a/internal/php5/php5.go b/internal/php5/php5.go index 199faec..1e89fea 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 0e7e6fa..f905e1d 100644 --- a/internal/php5/php5.y +++ b/internal/php5/php5.y @@ -242,7 +242,7 @@ import ( %type static_scalar_value static_operation static_var_list global_var_list %type ctor_arguments function_call_parameter_list echo_expr_list %type trait_adaptations unset_variables declare_list -%type switch_case_list +%type switch_case_list non_empty_function_call_parameter_list %type method_body %type foreach_statement for_statement while_statement %type foreach_variable foreach_optional_arg @@ -258,7 +258,7 @@ import ( %type for_expr case_list catch_statement additional_catches %type non_empty_additional_catches parameter_list non_empty_parameter_list class_statement_list %type class_statement_list variable_modifiers method_modifiers class_variable_declaration -%type interface_list non_empty_function_call_parameter_list trait_list trait_adaptation_list non_empty_trait_adaptation_list +%type interface_list trait_list trait_adaptation_list non_empty_trait_adaptation_list %type trait_reference_list non_empty_member_modifiers backticks_expr static_array_pair_list non_empty_static_array_pair_list %type chaining_dereference chaining_instance_call chaining_method_or_property instance_call variable_property @@ -2170,38 +2170,40 @@ optional_class_type: function_call_parameter_list: '(' ')' { - $$ = &ast.ArgumentList{ast.Node{}, nil} - - // save position - $$.GetNode().Position = position.NewTokensPosition($1, $2) - - // save comments - yylex.(*Parser).setFreeFloatingTokens($$, token.Start, $1.SkippedTokens) - yylex.(*Parser).setFreeFloatingTokens($$, token.End, $2.SkippedTokens) + $$ = &ast.ArgumentList{ + Node: ast.Node{ + Position: position.NewTokensPosition($1, $2), + }, + OpenParenthesisTkn: $1, + CloseParenthesisTkn: $2, + } } | '(' non_empty_function_call_parameter_list ')' { - $$ = &ast.ArgumentList{ast.Node{}, $2} + argumentList := $2.(*ast.ArgumentList) + argumentList.Position = position.NewTokensPosition($1, $3) + argumentList.OpenParenthesisTkn = $1 + argumentList.CloseParenthesisTkn = $3 - // save position - $$.GetNode().Position = position.NewTokensPosition($1, $3) - - // save comments - yylex.(*Parser).setFreeFloatingTokens($$, token.Start, $1.SkippedTokens) - yylex.(*Parser).setFreeFloatingTokens($$, token.End, $3.SkippedTokens) + $$ = argumentList } | '(' yield_expr ')' { - arg := &ast.Argument{ast.Node{}, false, false, $2} - $$ = &ast.ArgumentList{ast.Node{}, []ast.Vertex{arg}} - - // save position - arg.GetNode().Position = position.NewNodePosition($2) - $$.GetNode().Position = position.NewTokensPosition($1, $3) - - // save comments - yylex.(*Parser).setFreeFloatingTokens($$, token.Start, $1.SkippedTokens) - yylex.(*Parser).setFreeFloatingTokens($$, token.End, $3.SkippedTokens) + $$ = &ast.ArgumentList{ + Node: ast.Node{ + Position: position.NewTokensPosition($1, $3), + }, + OpenParenthesisTkn: $1, + Arguments: []ast.Vertex{ + &ast.Argument{ + Node: ast.Node{ + Position: position.NewNodePosition($2), + }, + Expr: $2, + }, + }, + CloseParenthesisTkn: $3, + } } ; @@ -2209,57 +2211,57 @@ function_call_parameter_list: non_empty_function_call_parameter_list: function_call_parameter { - $$ = []ast.Vertex{$1} + $$ = &ast.ArgumentList{ + Arguments: []ast.Vertex{$1}, + } } | non_empty_function_call_parameter_list ',' function_call_parameter { - $$ = append($1, $3) + $1.(*ast.ArgumentList).SeparatorTkns = append($1.(*ast.ArgumentList).SeparatorTkns, $2) + $1.(*ast.ArgumentList).Arguments = append($1.(*ast.ArgumentList).Arguments, $3) - // save comments - yylex.(*Parser).setFreeFloating(lastNode($1), token.End, $2.SkippedTokens) + $$ = $1 } ; function_call_parameter: expr_without_variable { - $$ = &ast.Argument{ast.Node{}, false, false, $1} - - // save position - $$.GetNode().Position = position.NewNodePosition($1) - - // save comments - yylex.(*Parser).MoveFreeFloating($1, $$) + $$ = &ast.Argument{ + Node: ast.Node{ + Position: position.NewNodePosition($1), + }, + Expr: $1, + } } | variable { - $$ = &ast.Argument{ast.Node{}, false, false, $1} - - // save position - $$.GetNode().Position = position.NewNodePosition($1) - - // save comments - yylex.(*Parser).MoveFreeFloating($1, $$) + $$ = &ast.Argument{ + Node: ast.Node{ + Position: position.NewNodePosition($1), + }, + Expr: $1, + } } | '&' w_variable { - $$ = &ast.Argument{ast.Node{}, false, true, $2} - - // save position - $$.GetNode().Position = position.NewNodePosition($2) - - // save comments - yylex.(*Parser).setFreeFloating($$, token.Start, $1.SkippedTokens) + $$ = &ast.Argument{ + Node: ast.Node{ + Position: position.NewTokenNodePosition($1, $2), + }, + AmpersandTkn: $1, + Expr: $2, + } } | T_ELLIPSIS expr { - $$ = &ast.Argument{ast.Node{}, true, false, $2} - - // save position - $$.GetNode().Position = position.NewTokenNodePosition($1, $2) - - // save comments - yylex.(*Parser).setFreeFloating($$, token.Start, $1.SkippedTokens) + $$ = &ast.Argument{ + Node: ast.Node{ + Position: position.NewTokenNodePosition($1, $2), + }, + VariadicTkn: $1, + Expr: $2, + } } ; diff --git a/internal/php7/php7.go b/internal/php7/php7.go index 62c54a9..a66ce92 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 586a9aa..b246064 100644 --- a/internal/php7/php7.y +++ b/internal/php7/php7.y @@ -250,7 +250,7 @@ import ( %type variable_class_name dereferencable_scalar constant dereferencable %type callable_expr callable_variable static_member new_variable %type encaps_var encaps_var_offset echo_expr_list catch_name_list -%type if_stmt const_list +%type if_stmt const_list non_empty_argument_list %type alt_if_stmt %type if_stmt_without_else %type class_const_decl @@ -280,7 +280,7 @@ import ( %type unprefixed_use_declarations inline_use_declarations property_list %type case_list trait_adaptation_list %type use_declarations lexical_var_list isset_variables non_empty_array_pair_list -%type array_pair_list non_empty_argument_list top_statement_list +%type array_pair_list top_statement_list %type inner_statement_list parameter_list non_empty_parameter_list class_statement_list %type method_modifiers variable_modifiers %type non_empty_member_modifiers name_list class_modifiers @@ -2030,66 +2030,61 @@ return_type: argument_list: '(' ')' { - $$ = &ast.ArgumentList{ast.Node{}, nil} - - // save position - $$.GetNode().Position = position.NewTokensPosition($1, $2) - - // save comments - yylex.(*Parser).setFreeFloatingTokens($$, token.Start, $1.SkippedTokens) - yylex.(*Parser).setFreeFloatingTokens($$, token.End, $2.SkippedTokens) + $$ = &ast.ArgumentList{ + Node: ast.Node{ + Position: position.NewTokensPosition($1, $2), + }, + OpenParenthesisTkn: $1, + CloseParenthesisTkn: $2, + } } | '(' non_empty_argument_list possible_comma ')' { - $$ = &ast.ArgumentList{ast.Node{}, $2} + argumentList := $2.(*ast.ArgumentList) + argumentList.Position = position.NewTokensPosition($1, $4) + argumentList.OpenParenthesisTkn = $1 + argumentList.SeparatorTkns = append(argumentList.SeparatorTkns, $3) + argumentList.CloseParenthesisTkn = $4 - // save position - $$.GetNode().Position = position.NewTokensPosition($1, $4) - - // save comments - yylex.(*Parser).setFreeFloatingTokens($$, token.Start, $1.SkippedTokens) - if $3 != nil { - yylex.(*Parser).setFreeFloatingTokens($$, token.End, append($3.SkippedTokens, $4.SkippedTokens...)) - } else { - yylex.(*Parser).setFreeFloatingTokens($$, token.End, $4.SkippedTokens) - } + $$ = argumentList } ; non_empty_argument_list: argument { - $$ = []ast.Vertex{$1} + $$ = &ast.ArgumentList{ + Arguments: []ast.Vertex{$1}, + } } | non_empty_argument_list ',' argument { - $$ = append($1, $3) + $1.(*ast.ArgumentList).SeparatorTkns = append($1.(*ast.ArgumentList).SeparatorTkns, $2) + $1.(*ast.ArgumentList).Arguments = append($1.(*ast.ArgumentList).Arguments, $3) - // save comments - yylex.(*Parser).setFreeFloating(lastNode($1), token.End, $2.SkippedTokens) + $$ = $1 } ; argument: expr { - $$ = &ast.Argument{ast.Node{}, false, false, $1} - - // save position - $$.GetNode().Position = position.NewNodePosition($1) - - // save comments - yylex.(*Parser).MoveFreeFloating($1, $$) + $$ = &ast.Argument{ + Node: ast.Node{ + Position: position.NewNodePosition($1), + }, + Expr: $1, + } } | T_ELLIPSIS expr { - $$ = &ast.Argument{ast.Node{}, true, false, $2} - - // save position - $$.GetNode().Position = position.NewTokenNodePosition($1, $2) - - // save comments - yylex.(*Parser).setFreeFloating($$, token.Start, $1.SkippedTokens) + $$ = &ast.Argument{ + Node: ast.Node{ + Position: position.NewTokenNodePosition($1, $2), + }, + VariadicTkn: $1, + Expr: $2, + } } ; diff --git a/pkg/ast/node.go b/pkg/ast/node.go index 8d4b885..9cc59f4 100644 --- a/pkg/ast/node.go +++ b/pkg/ast/node.go @@ -90,7 +90,10 @@ func (n *Identifier) Accept(v NodeVisitor) { // ArgumentList node type ArgumentList struct { Node - Arguments []Vertex + OpenParenthesisTkn *token.Token + Arguments []Vertex + SeparatorTkns []*token.Token + CloseParenthesisTkn *token.Token } func (n *ArgumentList) Accept(v NodeVisitor) { @@ -100,9 +103,9 @@ func (n *ArgumentList) Accept(v NodeVisitor) { // Argument node type Argument struct { Node - Variadic bool - IsReference bool - Expr Vertex + VariadicTkn *token.Token + AmpersandTkn *token.Token + Expr Vertex } func (n *Argument) Accept(v NodeVisitor) { diff --git a/pkg/ast/visitor/dump.go b/pkg/ast/visitor/dump.go index d8160c1..7e11d72 100644 --- a/pkg/ast/visitor/dump.go +++ b/pkg/ast/visitor/dump.go @@ -240,16 +240,6 @@ func (v *Dump) Argument(n *ast.Argument) { v.printIndentIfNotSingle(v.indent - 1) v.print("&ast.Argument{\n") v.printNode(n.GetNode()) - - if n.Variadic { - v.printIndent(v.indent) - v.print("Variadic: true,\n") - } - - if n.IsReference { - v.printIndent(v.indent) - v.print("IsReference: true,\n") - } } func (v *Dump) StmtBreak(n *ast.StmtBreak) { diff --git a/pkg/printer/pretty_printer.go b/pkg/printer/pretty_printer.go index 67d4571..6caa793 100644 --- a/pkg/printer/pretty_printer.go +++ b/pkg/printer/pretty_printer.go @@ -465,11 +465,11 @@ func (p *PrettyPrinter) printNodeNullable(n ast.Vertex) { func (p *PrettyPrinter) printNodeArgument(n ast.Vertex) { nn := n.(*ast.Argument) - if nn.IsReference { + if nn.AmpersandTkn != nil { io.WriteString(p.w, "&") } - if nn.Variadic { + if nn.VariadicTkn != nil { io.WriteString(p.w, "...") } diff --git a/pkg/printer/printer.go b/pkg/printer/printer.go index 2dd68a4..7f5fae5 100644 --- a/pkg/printer/printer.go +++ b/pkg/printer/printer.go @@ -561,12 +561,12 @@ func (p *Printer) printNodeArgument(n ast.Vertex) { nn := n.(*ast.Argument) p.printFreeFloating(nn, token.Start) - if nn.IsReference { + if nn.AmpersandTkn != nil { p.write([]byte("&")) } p.printFreeFloating(nn, token.Ampersand) - if nn.Variadic { + if nn.VariadicTkn != nil { p.write([]byte("...")) }