diff --git a/internal/php5/php5.go b/internal/php5/php5.go index 9b23a93..8501768 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 0613a54..07db4b4 100644 --- a/internal/php5/php5.y +++ b/internal/php5/php5.y @@ -240,7 +240,7 @@ import ( %type trait_adaptations unset_variables declare_list non_empty_array_pair_list array_pair_list %type switch_case_list non_empty_function_call_parameter_list assignment_list lexical_var_list %type method_body trait_reference_list static_array_pair_list non_empty_static_array_pair_list -%type foreach_statement for_statement while_statement +%type foreach_statement for_statement while_statement isset_variables %type foreach_variable foreach_optional_arg %type extends_from interface_list trait_list %type implements_list @@ -248,7 +248,7 @@ import ( %type lexical_vars %type top_statement_list namespace_name use_declarations use_function_declarations use_const_declarations -%type inner_statement_list encaps_list isset_variables +%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 @@ -3717,14 +3717,14 @@ expr_without_variable: } | expr T_INSTANCEOF class_name_reference { - $$ = &ast.ExprInstanceOf{ast.Node{}, $1, $3} - - // save position - $$.GetNode().Position = position.NewNodesPosition($1, $3) - - // save comments - yylex.(*Parser).MoveFreeFloating($1, $$) - yylex.(*Parser).setFreeFloating($$, token.Expr, $2.SkippedTokens) + $$ = &ast.ExprInstanceOf{ + Node: ast.Node{ + Position: position.NewNodesPosition($1, $3), + }, + Expr: $1, + InstanceOfTkn: $2, + Class: $3, + } } | parenthesis_expr { @@ -6331,15 +6331,16 @@ encaps_var_offset: internal_functions_in_yacc: T_ISSET '(' isset_variables ')' { - $$ = &ast.ExprIsset{ast.Node{}, $3} - - // save position - $$.GetNode().Position = position.NewTokensPosition($1, $4) - - // save comments - yylex.(*Parser).setFreeFloating($$, token.Start, $1.SkippedTokens) - yylex.(*Parser).setFreeFloating($$, token.Isset, $2.SkippedTokens) - yylex.(*Parser).setFreeFloating($$, token.VarList, $4.SkippedTokens) + $$ = &ast.ExprIsset{ + Node: ast.Node{ + Position: position.NewTokensPosition($1, $4), + }, + IssetTkn: $1, + OpenParenthesisTkn: $2, + Vars: $3.(*ast.ParserSeparatedList).Items, + SeparatorTkns: $3.(*ast.ParserSeparatedList).SeparatorTkns, + CloseParenthesisTkn: $4, + } } | T_EMPTY '(' variable ')' { @@ -6422,14 +6423,16 @@ internal_functions_in_yacc: isset_variables: isset_variable { - $$ = []ast.Vertex{$1} + $$ = &ast.ParserSeparatedList{ + Items: []ast.Vertex{$1}, + } } | isset_variables ',' isset_variable { - $$ = 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 } ; diff --git a/internal/php7/php7.go b/internal/php7/php7.go index 25bfa12..9fde4cd 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 5fe9dd0..2e1cdb4 100644 --- a/internal/php7/php7.y +++ b/internal/php7/php7.y @@ -247,7 +247,7 @@ import ( %type callable_expr callable_variable static_member new_variable %type encaps_var encaps_var_offset echo_expr_list catch_name_list name_list %type if_stmt const_list non_empty_argument_list property_list -%type alt_if_stmt lexical_var_list +%type alt_if_stmt lexical_var_list isset_variables %type if_stmt_without_else %type class_const_decl %type alt_if_stmt_without_else @@ -275,7 +275,7 @@ import ( %type for_exprs non_empty_for_exprs %type unprefixed_use_declarations inline_use_declarations %type case_list trait_adaptation_list -%type use_declarations isset_variables +%type use_declarations %type top_statement_list %type inner_statement_list parameter_list non_empty_parameter_list class_statement_list %type method_modifiers variable_modifiers @@ -3386,14 +3386,14 @@ expr_without_variable: } | expr T_INSTANCEOF class_name_reference { - $$ = &ast.ExprInstanceOf{ast.Node{}, $1, $3} - - // save position - $$.GetNode().Position = position.NewNodesPosition($1, $3) - - // save comments - yylex.(*Parser).MoveFreeFloating($1, $$) - yylex.(*Parser).setFreeFloating($$, token.Expr, $2.SkippedTokens) + $$ = &ast.ExprInstanceOf{ + Node: ast.Node{ + Position: position.NewNodesPosition($1, $3), + }, + Expr: $1, + InstanceOfTkn: $2, + Class: $3, + } } | '(' expr ')' { @@ -4886,18 +4886,19 @@ encaps_var_offset: internal_functions_in_yacc: T_ISSET '(' isset_variables possible_comma ')' { - $$ = &ast.ExprIsset{ast.Node{}, $3} + if $4 != nil { + $3.(*ast.ParserSeparatedList).SeparatorTkns = append($3.(*ast.ParserSeparatedList).SeparatorTkns, $4) + } - // save position - $$.GetNode().Position = position.NewTokensPosition($1, $5) - - // save comments - yylex.(*Parser).setFreeFloating($$, token.Start, $1.SkippedTokens) - yylex.(*Parser).setFreeFloating($$, token.Isset, $2.SkippedTokens) - if $4 == nil { - yylex.(*Parser).setFreeFloating($$, token.VarList, $5.SkippedTokens) - } else { - yylex.(*Parser).setFreeFloating($$, token.VarList, append($4.SkippedTokens, $5.SkippedTokens...)) + $$ = &ast.ExprIsset{ + Node: ast.Node{ + Position: position.NewTokensPosition($1, $5), + }, + IssetTkn: $1, + OpenParenthesisTkn: $2, + Vars: $3.(*ast.ParserSeparatedList).Items, + SeparatorTkns: $3.(*ast.ParserSeparatedList).SeparatorTkns, + CloseParenthesisTkn: $5, } } | T_EMPTY '(' expr ')' @@ -4969,14 +4970,16 @@ internal_functions_in_yacc: isset_variables: isset_variable { - $$ = []ast.Vertex{$1} + $$ = &ast.ParserSeparatedList{ + Items: []ast.Vertex{$1}, + } } | isset_variables ',' isset_variable { - $$ = 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 } ; diff --git a/pkg/ast/node.go b/pkg/ast/node.go index 93d9001..54ae3de 100644 --- a/pkg/ast/node.go +++ b/pkg/ast/node.go @@ -1175,8 +1175,9 @@ func (n *ExprIncludeOnce) Accept(v NodeVisitor) { // ExprInstanceOf node type ExprInstanceOf struct { Node - Expr Vertex - Class Vertex + Expr Vertex + InstanceOfTkn *token.Token + Class Vertex } func (n *ExprInstanceOf) Accept(v NodeVisitor) { @@ -1186,7 +1187,11 @@ func (n *ExprInstanceOf) Accept(v NodeVisitor) { // ExprIsset node type ExprIsset struct { Node - Vars []Vertex + IssetTkn *token.Token + OpenParenthesisTkn *token.Token + Vars []Vertex + SeparatorTkns []*token.Token + CloseParenthesisTkn *token.Token } func (n *ExprIsset) Accept(v NodeVisitor) {