diff --git a/internal/php5/php5.go b/internal/php5/php5.go index 5cc2459..8aa85e6 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 bcdf386..d4cc523 100644 --- a/internal/php5/php5.y +++ b/internal/php5/php5.y @@ -1609,13 +1609,13 @@ foreach_variable: } | '&' variable { - $$ = &ast.ExprReference{ast.Node{}, $2} - - // save position - $$.GetNode().Position = position.NewTokenNodePosition($1, $2) - - // save comments - yylex.(*Parser).setFreeFloating($$, token.Start, $1.SkippedTokens) + $$ = &ast.ExprReference{ + Node: ast.Node{ + Position: position.NewTokenNodePosition($1, $2), + }, + AmpersandTkn: $1, + Var: $2, + } } | T_LIST '(' assignment_list ')' { @@ -3943,13 +3943,13 @@ expr_without_variable: } | T_PRINT expr { - $$ = &ast.ExprPrint{ast.Node{}, $2} - - // save position - $$.GetNode().Position = position.NewTokenNodePosition($1, $2) - - // save comments - yylex.(*Parser).setFreeFloating($$, token.Start, $1.SkippedTokens) + $$ = &ast.ExprPrint{ + Node: ast.Node{ + Position: position.NewTokenNodePosition($1, $2), + }, + PrintTkn: $1, + Expr: $2, + } } | T_YIELD { @@ -4182,6 +4182,7 @@ lexical_var_list: Node: ast.Node{ Position: position.NewTokensPosition($3, $4), }, + AmpersandTkn: $3, Var: &ast.ExprVariable{ Node: ast.Node{ Position: position.NewTokenPosition($4), @@ -4228,6 +4229,7 @@ lexical_var_list: Node: ast.Node{ Position: position.NewTokensPosition($1, $2), }, + AmpersandTkn: $1, Var: &ast.ExprVariable{ Node: ast.Node{ Position: position.NewTokenPosition($2), @@ -6100,7 +6102,8 @@ non_empty_array_pair_list: Node: ast.Node{ Position: position.NewTokenNodePosition($5, $6), }, - Var: $6, + AmpersandTkn: $5, + Var: $6, }, } @@ -6119,7 +6122,8 @@ non_empty_array_pair_list: Node: ast.Node{ Position: position.NewTokenNodePosition($3, $4), }, - Var: $4, + AmpersandTkn: $3, + Var: $4, }, } @@ -6142,7 +6146,8 @@ non_empty_array_pair_list: Node: ast.Node{ Position: position.NewTokenNodePosition($3, $4), }, - Var: $4, + AmpersandTkn: $3, + Var: $4, }, }, }, @@ -6160,7 +6165,8 @@ non_empty_array_pair_list: Node: ast.Node{ Position: position.NewTokenNodePosition($1, $2), }, - Var: $2, + AmpersandTkn: $1, + Var: $2, }, }, }, @@ -6471,23 +6477,23 @@ internal_functions_in_yacc: } | T_REQUIRE expr { - $$ = &ast.ExprRequire{ast.Node{}, $2} - - // save position - $$.GetNode().Position = position.NewTokenNodePosition($1, $2) - - // save comments - yylex.(*Parser).setFreeFloating($$, token.Start, $1.SkippedTokens) + $$ = &ast.ExprRequire{ + Node: ast.Node{ + Position: position.NewTokenNodePosition($1, $2), + }, + RequireTkn: $1, + Expr: $2, + } } | T_REQUIRE_ONCE expr { - $$ = &ast.ExprRequireOnce{ast.Node{}, $2} - - // save position - $$.GetNode().Position = position.NewTokenNodePosition($1, $2) - - // save comments - yylex.(*Parser).setFreeFloating($$, token.Start, $1.SkippedTokens) + $$ = &ast.ExprRequireOnce{ + Node: ast.Node{ + Position: position.NewTokenNodePosition($1, $2), + }, + RequireOnceTkn: $1, + Expr: $2, + } } ; diff --git a/internal/php7/php7.go b/internal/php7/php7.go index cfb8eb3..8e48f1b 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 581403b..bd1fe44 100644 --- a/internal/php7/php7.y +++ b/internal/php7/php7.y @@ -1443,13 +1443,13 @@ foreach_variable: } | '&' variable { - $$ = &ast.ExprReference{ast.Node{}, $2} - - // save position - $$.GetNode().Position = position.NewTokenNodePosition($1, $2) - - // save comments - yylex.(*Parser).setFreeFloating($$, token.Start, $1.SkippedTokens) + $$ = &ast.ExprReference{ + Node: ast.Node{ + Position: position.NewTokenNodePosition($1, $2), + }, + AmpersandTkn: $1, + Var: $2, + } } | T_LIST '(' array_pair_list ')' { @@ -3581,13 +3581,13 @@ expr_without_variable: } | T_PRINT expr { - $$ = &ast.ExprPrint{ast.Node{}, $2} - - // save position - $$.GetNode().Position = position.NewTokenNodePosition($1, $2) - - // save comments - yylex.(*Parser).setFreeFloating($$, token.Start, $1.SkippedTokens) + $$ = &ast.ExprPrint{ + Node: ast.Node{ + Position: position.NewTokenNodePosition($1, $2), + }, + PrintTkn: $1, + Expr: $2, + } } | T_YIELD { @@ -3759,23 +3759,24 @@ lexical_var: } | '&' T_VARIABLE { - identifier := &ast.Identifier{ + $$ = &ast.ExprReference{ Node: ast.Node{ - Position: position.NewTokenPosition($2), + Position: position.NewTokensPosition($1, $2), + }, + AmpersandTkn: $1, + Var: &ast.ExprVariable{ + Node: ast.Node{ + Position: position.NewTokenPosition($2), + }, + VarName: &ast.Identifier{ + Node: ast.Node{ + Position: position.NewTokenPosition($2), + }, + IdentifierTkn: $2, + Value: $2.Value, + }, }, - IdentifierTkn: $2, - Value: $2.Value, } - variable := &ast.ExprVariable{ast.Node{}, identifier} - $$ = &ast.ExprReference{ast.Node{}, variable} - - // save position - variable.GetNode().Position = position.NewTokenPosition($2) - $$.GetNode().Position = position.NewTokensPosition($1, $2) - - // save comments - yylex.(*Parser).setFreeFloating($$, token.Start, $1.SkippedTokens) - yylex.(*Parser).setFreeFloating(variable, token.Start, $2.SkippedTokens) } ; @@ -4577,7 +4578,8 @@ array_pair: Node: ast.Node{ Position: position.NewTokenNodePosition($3, $4), }, - Var: $4, + AmpersandTkn: $3, + Var: $4, }, } } @@ -4591,7 +4593,8 @@ array_pair: Node: ast.Node{ Position: position.NewTokenNodePosition($1, $2), }, - Var: $2, + AmpersandTkn: $1, + Var: $2, }, } } @@ -4960,23 +4963,23 @@ internal_functions_in_yacc: } | T_REQUIRE expr { - $$ = &ast.ExprRequire{ast.Node{}, $2} - - // save position - $$.GetNode().Position = position.NewTokenNodePosition($1, $2) - - // save comments - yylex.(*Parser).setFreeFloating($$, token.Start, $1.SkippedTokens) + $$ = &ast.ExprRequire{ + Node: ast.Node{ + Position: position.NewTokenNodePosition($1, $2), + }, + RequireTkn: $1, + Expr: $2, + } } | T_REQUIRE_ONCE expr { - $$ = &ast.ExprRequireOnce{ast.Node{}, $2} - - // save position - $$.GetNode().Position = position.NewTokenNodePosition($1, $2) - - // save comments - yylex.(*Parser).setFreeFloating($$, token.Start, $1.SkippedTokens) + $$ = &ast.ExprRequireOnce{ + Node: ast.Node{ + Position: position.NewTokenNodePosition($1, $2), + }, + RequireOnceTkn: $1, + Expr: $2, + } } ; diff --git a/pkg/ast/node.go b/pkg/ast/node.go index cadaa12..c6d4c8d 100644 --- a/pkg/ast/node.go +++ b/pkg/ast/node.go @@ -1288,7 +1288,8 @@ func (n *ExprPreInc) Accept(v NodeVisitor) { // ExprPrint node type ExprPrint struct { Node - Expr Vertex + PrintTkn *token.Token + Expr Vertex } func (n *ExprPrint) Accept(v NodeVisitor) { @@ -1310,7 +1311,8 @@ func (n *ExprPropertyFetch) Accept(v NodeVisitor) { // ExprReference node type ExprReference struct { Node - Var Vertex + AmpersandTkn *token.Token + Var Vertex } func (n *ExprReference) Accept(v NodeVisitor) { @@ -1320,7 +1322,8 @@ func (n *ExprReference) Accept(v NodeVisitor) { // ExprRequire node type ExprRequire struct { Node - Expr Vertex + RequireTkn *token.Token + Expr Vertex } func (n *ExprRequire) Accept(v NodeVisitor) { @@ -1330,7 +1333,8 @@ func (n *ExprRequire) Accept(v NodeVisitor) { // ExprRequireOnce node type ExprRequireOnce struct { Node - Expr Vertex + RequireOnceTkn *token.Token + Expr Vertex } func (n *ExprRequireOnce) Accept(v NodeVisitor) {