[refactoring] update ast structure of "Print", "Reference", "Require" and "RequireOnce" nodes

This commit is contained in:
Vadym Slizov 2020-12-03 22:20:50 +02:00
parent 45e959056b
commit 592c9b9aff
No known key found for this signature in database
GPG Key ID: AEA2A9388EF42A4A
5 changed files with 93 additions and 80 deletions

BIN
internal/php5/php5.go generated

Binary file not shown.

View File

@ -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,
}
}
;

BIN
internal/php7/php7.go generated

Binary file not shown.

View File

@ -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,
}
}
;

View File

@ -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) {