[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,6 +6102,7 @@ non_empty_array_pair_list:
Node: ast.Node{
Position: position.NewTokenNodePosition($5, $6),
},
AmpersandTkn: $5,
Var: $6,
},
}
@ -6119,6 +6122,7 @@ non_empty_array_pair_list:
Node: ast.Node{
Position: position.NewTokenNodePosition($3, $4),
},
AmpersandTkn: $3,
Var: $4,
},
}
@ -6142,6 +6146,7 @@ non_empty_array_pair_list:
Node: ast.Node{
Position: position.NewTokenNodePosition($3, $4),
},
AmpersandTkn: $3,
Var: $4,
},
},
@ -6160,6 +6165,7 @@ non_empty_array_pair_list:
Node: ast.Node{
Position: position.NewTokenNodePosition($1, $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.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,
},
},
}
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,6 +4578,7 @@ array_pair:
Node: ast.Node{
Position: position.NewTokenNodePosition($3, $4),
},
AmpersandTkn: $3,
Var: $4,
},
}
@ -4591,6 +4593,7 @@ array_pair:
Node: ast.Node{
Position: position.NewTokenNodePosition($1, $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,6 +1288,7 @@ func (n *ExprPreInc) Accept(v NodeVisitor) {
// ExprPrint node
type ExprPrint struct {
Node
PrintTkn *token.Token
Expr Vertex
}
@ -1310,6 +1311,7 @@ func (n *ExprPropertyFetch) Accept(v NodeVisitor) {
// ExprReference node
type ExprReference struct {
Node
AmpersandTkn *token.Token
Var Vertex
}
@ -1320,6 +1322,7 @@ func (n *ExprReference) Accept(v NodeVisitor) {
// ExprRequire node
type ExprRequire struct {
Node
RequireTkn *token.Token
Expr Vertex
}
@ -1330,6 +1333,7 @@ func (n *ExprRequire) Accept(v NodeVisitor) {
// ExprRequireOnce node
type ExprRequireOnce struct {
Node
RequireOnceTkn *token.Token
Expr Vertex
}