[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 | '&' variable
{ {
$$ = &ast.ExprReference{ast.Node{}, $2} $$ = &ast.ExprReference{
Node: ast.Node{
// save position Position: position.NewTokenNodePosition($1, $2),
$$.GetNode().Position = position.NewTokenNodePosition($1, $2) },
AmpersandTkn: $1,
// save comments Var: $2,
yylex.(*Parser).setFreeFloating($$, token.Start, $1.SkippedTokens) }
} }
| T_LIST '(' assignment_list ')' | T_LIST '(' assignment_list ')'
{ {
@ -3943,13 +3943,13 @@ expr_without_variable:
} }
| T_PRINT expr | T_PRINT expr
{ {
$$ = &ast.ExprPrint{ast.Node{}, $2} $$ = &ast.ExprPrint{
Node: ast.Node{
// save position Position: position.NewTokenNodePosition($1, $2),
$$.GetNode().Position = position.NewTokenNodePosition($1, $2) },
PrintTkn: $1,
// save comments Expr: $2,
yylex.(*Parser).setFreeFloating($$, token.Start, $1.SkippedTokens) }
} }
| T_YIELD | T_YIELD
{ {
@ -4182,6 +4182,7 @@ lexical_var_list:
Node: ast.Node{ Node: ast.Node{
Position: position.NewTokensPosition($3, $4), Position: position.NewTokensPosition($3, $4),
}, },
AmpersandTkn: $3,
Var: &ast.ExprVariable{ Var: &ast.ExprVariable{
Node: ast.Node{ Node: ast.Node{
Position: position.NewTokenPosition($4), Position: position.NewTokenPosition($4),
@ -4228,6 +4229,7 @@ lexical_var_list:
Node: ast.Node{ Node: ast.Node{
Position: position.NewTokensPosition($1, $2), Position: position.NewTokensPosition($1, $2),
}, },
AmpersandTkn: $1,
Var: &ast.ExprVariable{ Var: &ast.ExprVariable{
Node: ast.Node{ Node: ast.Node{
Position: position.NewTokenPosition($2), Position: position.NewTokenPosition($2),
@ -6100,7 +6102,8 @@ non_empty_array_pair_list:
Node: ast.Node{ Node: ast.Node{
Position: position.NewTokenNodePosition($5, $6), Position: position.NewTokenNodePosition($5, $6),
}, },
Var: $6, AmpersandTkn: $5,
Var: $6,
}, },
} }
@ -6119,7 +6122,8 @@ non_empty_array_pair_list:
Node: ast.Node{ Node: ast.Node{
Position: position.NewTokenNodePosition($3, $4), Position: position.NewTokenNodePosition($3, $4),
}, },
Var: $4, AmpersandTkn: $3,
Var: $4,
}, },
} }
@ -6142,7 +6146,8 @@ non_empty_array_pair_list:
Node: ast.Node{ Node: ast.Node{
Position: position.NewTokenNodePosition($3, $4), Position: position.NewTokenNodePosition($3, $4),
}, },
Var: $4, AmpersandTkn: $3,
Var: $4,
}, },
}, },
}, },
@ -6160,7 +6165,8 @@ non_empty_array_pair_list:
Node: ast.Node{ Node: ast.Node{
Position: position.NewTokenNodePosition($1, $2), Position: position.NewTokenNodePosition($1, $2),
}, },
Var: $2, AmpersandTkn: $1,
Var: $2,
}, },
}, },
}, },
@ -6471,23 +6477,23 @@ internal_functions_in_yacc:
} }
| T_REQUIRE expr | T_REQUIRE expr
{ {
$$ = &ast.ExprRequire{ast.Node{}, $2} $$ = &ast.ExprRequire{
Node: ast.Node{
// save position Position: position.NewTokenNodePosition($1, $2),
$$.GetNode().Position = position.NewTokenNodePosition($1, $2) },
RequireTkn: $1,
// save comments Expr: $2,
yylex.(*Parser).setFreeFloating($$, token.Start, $1.SkippedTokens) }
} }
| T_REQUIRE_ONCE expr | T_REQUIRE_ONCE expr
{ {
$$ = &ast.ExprRequireOnce{ast.Node{}, $2} $$ = &ast.ExprRequireOnce{
Node: ast.Node{
// save position Position: position.NewTokenNodePosition($1, $2),
$$.GetNode().Position = position.NewTokenNodePosition($1, $2) },
RequireOnceTkn: $1,
// save comments Expr: $2,
yylex.(*Parser).setFreeFloating($$, token.Start, $1.SkippedTokens) }
} }
; ;

BIN
internal/php7/php7.go generated

Binary file not shown.

View File

@ -1443,13 +1443,13 @@ foreach_variable:
} }
| '&' variable | '&' variable
{ {
$$ = &ast.ExprReference{ast.Node{}, $2} $$ = &ast.ExprReference{
Node: ast.Node{
// save position Position: position.NewTokenNodePosition($1, $2),
$$.GetNode().Position = position.NewTokenNodePosition($1, $2) },
AmpersandTkn: $1,
// save comments Var: $2,
yylex.(*Parser).setFreeFloating($$, token.Start, $1.SkippedTokens) }
} }
| T_LIST '(' array_pair_list ')' | T_LIST '(' array_pair_list ')'
{ {
@ -3581,13 +3581,13 @@ expr_without_variable:
} }
| T_PRINT expr | T_PRINT expr
{ {
$$ = &ast.ExprPrint{ast.Node{}, $2} $$ = &ast.ExprPrint{
Node: ast.Node{
// save position Position: position.NewTokenNodePosition($1, $2),
$$.GetNode().Position = position.NewTokenNodePosition($1, $2) },
PrintTkn: $1,
// save comments Expr: $2,
yylex.(*Parser).setFreeFloating($$, token.Start, $1.SkippedTokens) }
} }
| T_YIELD | T_YIELD
{ {
@ -3759,23 +3759,24 @@ lexical_var:
} }
| '&' T_VARIABLE | '&' T_VARIABLE
{ {
identifier := &ast.Identifier{ $$ = &ast.ExprReference{
Node: ast.Node{ 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{ Node: ast.Node{
Position: position.NewTokenNodePosition($3, $4), Position: position.NewTokenNodePosition($3, $4),
}, },
Var: $4, AmpersandTkn: $3,
Var: $4,
}, },
} }
} }
@ -4591,7 +4593,8 @@ array_pair:
Node: ast.Node{ Node: ast.Node{
Position: position.NewTokenNodePosition($1, $2), Position: position.NewTokenNodePosition($1, $2),
}, },
Var: $2, AmpersandTkn: $1,
Var: $2,
}, },
} }
} }
@ -4960,23 +4963,23 @@ internal_functions_in_yacc:
} }
| T_REQUIRE expr | T_REQUIRE expr
{ {
$$ = &ast.ExprRequire{ast.Node{}, $2} $$ = &ast.ExprRequire{
Node: ast.Node{
// save position Position: position.NewTokenNodePosition($1, $2),
$$.GetNode().Position = position.NewTokenNodePosition($1, $2) },
RequireTkn: $1,
// save comments Expr: $2,
yylex.(*Parser).setFreeFloating($$, token.Start, $1.SkippedTokens) }
} }
| T_REQUIRE_ONCE expr | T_REQUIRE_ONCE expr
{ {
$$ = &ast.ExprRequireOnce{ast.Node{}, $2} $$ = &ast.ExprRequireOnce{
Node: ast.Node{
// save position Position: position.NewTokenNodePosition($1, $2),
$$.GetNode().Position = position.NewTokenNodePosition($1, $2) },
RequireOnceTkn: $1,
// save comments Expr: $2,
yylex.(*Parser).setFreeFloating($$, token.Start, $1.SkippedTokens) }
} }
; ;

View File

@ -1288,7 +1288,8 @@ func (n *ExprPreInc) Accept(v NodeVisitor) {
// ExprPrint node // ExprPrint node
type ExprPrint struct { type ExprPrint struct {
Node Node
Expr Vertex PrintTkn *token.Token
Expr Vertex
} }
func (n *ExprPrint) Accept(v NodeVisitor) { func (n *ExprPrint) Accept(v NodeVisitor) {
@ -1310,7 +1311,8 @@ func (n *ExprPropertyFetch) Accept(v NodeVisitor) {
// ExprReference node // ExprReference node
type ExprReference struct { type ExprReference struct {
Node Node
Var Vertex AmpersandTkn *token.Token
Var Vertex
} }
func (n *ExprReference) Accept(v NodeVisitor) { func (n *ExprReference) Accept(v NodeVisitor) {
@ -1320,7 +1322,8 @@ func (n *ExprReference) Accept(v NodeVisitor) {
// ExprRequire node // ExprRequire node
type ExprRequire struct { type ExprRequire struct {
Node Node
Expr Vertex RequireTkn *token.Token
Expr Vertex
} }
func (n *ExprRequire) Accept(v NodeVisitor) { func (n *ExprRequire) Accept(v NodeVisitor) {
@ -1330,7 +1333,8 @@ func (n *ExprRequire) Accept(v NodeVisitor) {
// ExprRequireOnce node // ExprRequireOnce node
type ExprRequireOnce struct { type ExprRequireOnce struct {
Node Node
Expr Vertex RequireOnceTkn *token.Token
Expr Vertex
} }
func (n *ExprRequireOnce) Accept(v NodeVisitor) { func (n *ExprRequireOnce) Accept(v NodeVisitor) {