[refactoring] update ast structure of "Yield", "YieldFrom" and "Cast" nodes

This commit is contained in:
Vadym Slizov 2020-12-04 09:42:45 +02:00
parent 01d695c416
commit 5a6418e853
No known key found for this signature in database
GPG Key ID: AEA2A9388EF42A4A
5 changed files with 185 additions and 188 deletions

BIN
internal/php5/php5.go generated

Binary file not shown.

View File

@ -3799,80 +3799,73 @@ expr_without_variable:
} }
| T_INT_CAST expr | T_INT_CAST expr
{ {
$$ = &ast.ExprCastInt{ast.Node{}, $2} $$ = &ast.ExprCastInt{
Node: ast.Node{
// save position Position: position.NewTokenNodePosition($1, $2),
$$.GetNode().Position = position.NewTokenNodePosition($1, $2) },
CastTkn: $1,
// save comments Expr: $2,
yylex.(*Parser).setFreeFloating($$, token.Start, $1.SkippedTokens) }
yylex.(*Parser).setToken($$, token.Cast, $1.SkippedTokens)
} }
| T_DOUBLE_CAST expr | T_DOUBLE_CAST expr
{ {
$$ = &ast.ExprCastDouble{ast.Node{}, $2} $$ = &ast.ExprCastDouble{
Node: ast.Node{
// save position Position: position.NewTokenNodePosition($1, $2),
$$.GetNode().Position = position.NewTokenNodePosition($1, $2) },
CastTkn: $1,
// save comments Expr: $2,
yylex.(*Parser).setFreeFloating($$, token.Start, $1.SkippedTokens) }
yylex.(*Parser).setToken($$, token.Cast, $1.SkippedTokens)
} }
| T_STRING_CAST expr | T_STRING_CAST expr
{ {
$$ = &ast.ExprCastString{ast.Node{}, $2} $$ = &ast.ExprCastString{
Node: ast.Node{
// save position Position: position.NewTokenNodePosition($1, $2),
$$.GetNode().Position = position.NewTokenNodePosition($1, $2) },
CastTkn: $1,
// save comments Expr: $2,
yylex.(*Parser).setFreeFloating($$, token.Start, $1.SkippedTokens) }
yylex.(*Parser).setToken($$, token.Cast, $1.SkippedTokens)
} }
| T_ARRAY_CAST expr | T_ARRAY_CAST expr
{ {
$$ = &ast.ExprCastArray{ast.Node{}, $2} $$ = &ast.ExprCastArray{
Node: ast.Node{
// save position Position: position.NewTokenNodePosition($1, $2),
$$.GetNode().Position = position.NewTokenNodePosition($1, $2) },
CastTkn: $1,
// save comments Expr: $2,
yylex.(*Parser).setFreeFloating($$, token.Start, $1.SkippedTokens) }
yylex.(*Parser).setToken($$, token.Cast, $1.SkippedTokens)
} }
| T_OBJECT_CAST expr | T_OBJECT_CAST expr
{ {
$$ = &ast.ExprCastObject{ast.Node{}, $2} $$ = &ast.ExprCastObject{
Node: ast.Node{
// save position Position: position.NewTokenNodePosition($1, $2),
$$.GetNode().Position = position.NewTokenNodePosition($1, $2) },
CastTkn: $1,
// save comments Expr: $2,
yylex.(*Parser).setFreeFloating($$, token.Start, $1.SkippedTokens) }
yylex.(*Parser).setToken($$, token.Cast, $1.SkippedTokens)
} }
| T_BOOL_CAST expr | T_BOOL_CAST expr
{ {
$$ = &ast.ExprCastBool{ast.Node{}, $2} $$ = &ast.ExprCastBool{
Node: ast.Node{
// save position Position: position.NewTokenNodePosition($1, $2),
$$.GetNode().Position = position.NewTokenNodePosition($1, $2) },
CastTkn: $1,
// save comments Expr: $2,
yylex.(*Parser).setFreeFloating($$, token.Start, $1.SkippedTokens) }
yylex.(*Parser).setToken($$, token.Cast, $1.SkippedTokens)
} }
| T_UNSET_CAST expr | T_UNSET_CAST expr
{ {
$$ = &ast.ExprCastUnset{ast.Node{}, $2} $$ = &ast.ExprCastUnset{
Node: ast.Node{
// save position Position: position.NewTokenNodePosition($1, $2),
$$.GetNode().Position = position.NewTokenNodePosition($1, $2) },
CastTkn: $1,
// save comments Expr: $2,
yylex.(*Parser).setFreeFloating($$, token.Start, $1.SkippedTokens) }
yylex.(*Parser).setToken($$, token.Cast, $1.SkippedTokens)
} }
| T_EXIT exit_expr | T_EXIT exit_expr
{ {
@ -3936,13 +3929,12 @@ expr_without_variable:
} }
| T_YIELD | T_YIELD
{ {
$$ = &ast.ExprYield{ast.Node{}, nil, nil} $$ = &ast.ExprYield{
Node: ast.Node{
// save position Position: position.NewTokenPosition($1),
$$.GetNode().Position = position.NewTokenPosition($1) },
YieldTkn: $1,
// save comments }
yylex.(*Parser).setFreeFloating($$, token.Start, $1.SkippedTokens)
} }
| function is_reference '(' parameter_list ')' lexical_vars '{' inner_statement_list '}' | function is_reference '(' parameter_list ')' lexical_vars '{' inner_statement_list '}'
{ {
@ -3984,45 +3976,47 @@ expr_without_variable:
yield_expr: yield_expr:
T_YIELD expr_without_variable T_YIELD expr_without_variable
{ {
$$ = &ast.ExprYield{ast.Node{}, nil, $2} $$ = &ast.ExprYield{
Node: ast.Node{
// save position Position: position.NewTokenNodePosition($1, $2),
$$.GetNode().Position = position.NewTokenNodePosition($1, $2) },
YieldTkn: $1,
// save comments Value: $2,
yylex.(*Parser).setFreeFloating($$, token.Start, $1.SkippedTokens) }
} }
| T_YIELD variable | T_YIELD variable
{ {
$$ = &ast.ExprYield{ast.Node{}, nil, $2} $$ = &ast.ExprYield{
Node: ast.Node{
// save position Position: position.NewTokenNodePosition($1, $2),
$$.GetNode().Position = position.NewTokenNodePosition($1, $2) },
YieldTkn: $1,
// save comments Value: $2,
yylex.(*Parser).setFreeFloating($$, token.Start, $1.SkippedTokens) }
} }
| T_YIELD expr T_DOUBLE_ARROW expr_without_variable | T_YIELD expr T_DOUBLE_ARROW expr_without_variable
{ {
$$ = &ast.ExprYield{ast.Node{}, $2, $4} $$ = &ast.ExprYield{
Node: ast.Node{
// save position Position: position.NewTokenNodePosition($1, $4),
$$.GetNode().Position = position.NewTokenNodePosition($1, $4) },
YieldTkn: $1,
// save comments Key: $2,
yylex.(*Parser).setFreeFloating($$, token.Start, $1.SkippedTokens) DoubleArrowTkn: $3,
yylex.(*Parser).setFreeFloating($$, token.Expr, $3.SkippedTokens) Value: $4,
}
} }
| T_YIELD expr T_DOUBLE_ARROW variable | T_YIELD expr T_DOUBLE_ARROW variable
{ {
$$ = &ast.ExprYield{ast.Node{}, $2, $4} $$ = &ast.ExprYield{
Node: ast.Node{
// save position Position: position.NewTokenNodePosition($1, $4),
$$.GetNode().Position = position.NewTokenNodePosition($1, $4) },
YieldTkn: $1,
// save comments Key: $2,
yylex.(*Parser).setFreeFloating($$, token.Start, $1.SkippedTokens) DoubleArrowTkn: $3,
yylex.(*Parser).setFreeFloating($$, token.Expr, $3.SkippedTokens) Value: $4,
}
} }
; ;

BIN
internal/php7/php7.go generated

Binary file not shown.

View File

@ -3455,80 +3455,73 @@ expr_without_variable:
} }
| T_INT_CAST expr | T_INT_CAST expr
{ {
$$ = &ast.ExprCastInt{ast.Node{}, $2} $$ = &ast.ExprCastInt{
Node: ast.Node{
// save position Position: position.NewTokenNodePosition($1, $2),
$$.GetNode().Position = position.NewTokenNodePosition($1, $2) },
CastTkn: $1,
// save comments Expr: $2,
yylex.(*Parser).setFreeFloating($$, token.Start, $1.SkippedTokens) }
yylex.(*Parser).setToken($$, token.Cast, $1.SkippedTokens)
} }
| T_DOUBLE_CAST expr | T_DOUBLE_CAST expr
{ {
$$ = &ast.ExprCastDouble{ast.Node{}, $2} $$ = &ast.ExprCastDouble{
Node: ast.Node{
// save position Position: position.NewTokenNodePosition($1, $2),
$$.GetNode().Position = position.NewTokenNodePosition($1, $2) },
CastTkn: $1,
// save comments Expr: $2,
yylex.(*Parser).setFreeFloating($$, token.Start, $1.SkippedTokens) }
yylex.(*Parser).setToken($$, token.Cast, $1.SkippedTokens)
} }
| T_STRING_CAST expr | T_STRING_CAST expr
{ {
$$ = &ast.ExprCastString{ast.Node{}, $2} $$ = &ast.ExprCastString{
Node: ast.Node{
// save position Position: position.NewTokenNodePosition($1, $2),
$$.GetNode().Position = position.NewTokenNodePosition($1, $2) },
CastTkn: $1,
// save comments Expr: $2,
yylex.(*Parser).setFreeFloating($$, token.Start, $1.SkippedTokens) }
yylex.(*Parser).setToken($$, token.Cast, $1.SkippedTokens)
} }
| T_ARRAY_CAST expr | T_ARRAY_CAST expr
{ {
$$ = &ast.ExprCastArray{ast.Node{}, $2} $$ = &ast.ExprCastArray{
Node: ast.Node{
// save position Position: position.NewTokenNodePosition($1, $2),
$$.GetNode().Position = position.NewTokenNodePosition($1, $2) },
CastTkn: $1,
// save comments Expr: $2,
yylex.(*Parser).setFreeFloating($$, token.Start, $1.SkippedTokens) }
yylex.(*Parser).setToken($$, token.Cast, $1.SkippedTokens)
} }
| T_OBJECT_CAST expr | T_OBJECT_CAST expr
{ {
$$ = &ast.ExprCastObject{ast.Node{}, $2} $$ = &ast.ExprCastObject{
Node: ast.Node{
// save position Position: position.NewTokenNodePosition($1, $2),
$$.GetNode().Position = position.NewTokenNodePosition($1, $2) },
CastTkn: $1,
// save comments Expr: $2,
yylex.(*Parser).setFreeFloating($$, token.Start, $1.SkippedTokens) }
yylex.(*Parser).setToken($$, token.Cast, $1.SkippedTokens)
} }
| T_BOOL_CAST expr | T_BOOL_CAST expr
{ {
$$ = &ast.ExprCastBool{ast.Node{}, $2} $$ = &ast.ExprCastBool{
Node: ast.Node{
// save position Position: position.NewTokenNodePosition($1, $2),
$$.GetNode().Position = position.NewTokenNodePosition($1, $2) },
CastTkn: $1,
// save comments Expr: $2,
yylex.(*Parser).setFreeFloating($$, token.Start, $1.SkippedTokens) }
yylex.(*Parser).setToken($$, token.Cast, $1.SkippedTokens)
} }
| T_UNSET_CAST expr | T_UNSET_CAST expr
{ {
$$ = &ast.ExprCastUnset{ast.Node{}, $2} $$ = &ast.ExprCastUnset{
Node: ast.Node{
// save position Position: position.NewTokenNodePosition($1, $2),
$$.GetNode().Position = position.NewTokenNodePosition($1, $2) },
CastTkn: $1,
// save comments Expr: $2,
yylex.(*Parser).setFreeFloating($$, token.Start, $1.SkippedTokens) }
yylex.(*Parser).setToken($$, token.Cast, $1.SkippedTokens)
} }
| T_EXIT exit_expr | T_EXIT exit_expr
{ {
@ -3584,44 +3577,44 @@ expr_without_variable:
} }
| T_YIELD | T_YIELD
{ {
$$ = &ast.ExprYield{ast.Node{}, nil, nil} $$ = &ast.ExprYield{
Node: ast.Node{
// save position Position: position.NewTokenPosition($1),
$$.GetNode().Position = position.NewTokenPosition($1) },
YieldTkn: $1,
// save comments }
yylex.(*Parser).setFreeFloating($$, token.Start, $1.SkippedTokens)
} }
| T_YIELD expr | T_YIELD expr
{ {
$$ = &ast.ExprYield{ast.Node{}, nil, $2} $$ = &ast.ExprYield{
Node: ast.Node{
// save position Position: position.NewTokenNodePosition($1, $2),
$$.GetNode().Position = position.NewTokenNodePosition($1, $2) },
YieldTkn: $1,
// save comments Value: $2,
yylex.(*Parser).setFreeFloating($$, token.Start, $1.SkippedTokens) }
} }
| T_YIELD expr T_DOUBLE_ARROW expr | T_YIELD expr T_DOUBLE_ARROW expr
{ {
$$ = &ast.ExprYield{ast.Node{}, $2, $4} $$ = &ast.ExprYield{
Node: ast.Node{
// save position Position: position.NewTokenNodePosition($1, $4),
$$.GetNode().Position = position.NewTokenNodePosition($1, $4) },
YieldTkn: $1,
// save comments Key: $2,
yylex.(*Parser).setFreeFloating($$, token.Start, $1.SkippedTokens) DoubleArrowTkn: $3,
yylex.(*Parser).setFreeFloating($$, token.Expr, $3.SkippedTokens) Value: $4,
}
} }
| T_YIELD_FROM expr | T_YIELD_FROM expr
{ {
$$ = &ast.ExprYieldFrom{ast.Node{}, $2} $$ = &ast.ExprYieldFrom{
Node: ast.Node{
// save position Position: position.NewTokenNodePosition($1, $2),
$$.GetNode().Position = position.NewTokenNodePosition($1, $2) },
YieldFromTkn: $1,
// save comments Expr: $2,
yylex.(*Parser).setFreeFloating($$, token.Start, $1.SkippedTokens) }
} }
| inline_function | inline_function
{ {

View File

@ -1428,8 +1428,10 @@ func (n *ExprVariable) Accept(v NodeVisitor) {
// ExprYield node // ExprYield node
type ExprYield struct { type ExprYield struct {
Node Node
Key Vertex YieldTkn *token.Token
Value Vertex Key Vertex
DoubleArrowTkn *token.Token
Value Vertex
} }
func (n *ExprYield) Accept(v NodeVisitor) { func (n *ExprYield) Accept(v NodeVisitor) {
@ -1439,7 +1441,8 @@ func (n *ExprYield) Accept(v NodeVisitor) {
// ExprYieldFrom node // ExprYieldFrom node
type ExprYieldFrom struct { type ExprYieldFrom struct {
Node Node
Expr Vertex YieldFromTkn *token.Token
Expr Vertex
} }
func (n *ExprYieldFrom) Accept(v NodeVisitor) { func (n *ExprYieldFrom) Accept(v NodeVisitor) {
@ -1449,7 +1452,8 @@ func (n *ExprYieldFrom) Accept(v NodeVisitor) {
// ExprCastArray node // ExprCastArray node
type ExprCastArray struct { type ExprCastArray struct {
Node Node
Expr Vertex CastTkn *token.Token
Expr Vertex
} }
func (n *ExprCastArray) Accept(v NodeVisitor) { func (n *ExprCastArray) Accept(v NodeVisitor) {
@ -1459,7 +1463,8 @@ func (n *ExprCastArray) Accept(v NodeVisitor) {
// ExprCastBool node // ExprCastBool node
type ExprCastBool struct { type ExprCastBool struct {
Node Node
Expr Vertex CastTkn *token.Token
Expr Vertex
} }
func (n *ExprCastBool) Accept(v NodeVisitor) { func (n *ExprCastBool) Accept(v NodeVisitor) {
@ -1469,7 +1474,8 @@ func (n *ExprCastBool) Accept(v NodeVisitor) {
// ExprCastDouble node // ExprCastDouble node
type ExprCastDouble struct { type ExprCastDouble struct {
Node Node
Expr Vertex CastTkn *token.Token
Expr Vertex
} }
func (n *ExprCastDouble) Accept(v NodeVisitor) { func (n *ExprCastDouble) Accept(v NodeVisitor) {
@ -1479,7 +1485,8 @@ func (n *ExprCastDouble) Accept(v NodeVisitor) {
// ExprCastInt node // ExprCastInt node
type ExprCastInt struct { type ExprCastInt struct {
Node Node
Expr Vertex CastTkn *token.Token
Expr Vertex
} }
func (n *ExprCastInt) Accept(v NodeVisitor) { func (n *ExprCastInt) Accept(v NodeVisitor) {
@ -1489,7 +1496,8 @@ func (n *ExprCastInt) Accept(v NodeVisitor) {
// ExprCastObject node // ExprCastObject node
type ExprCastObject struct { type ExprCastObject struct {
Node Node
Expr Vertex CastTkn *token.Token
Expr Vertex
} }
func (n *ExprCastObject) Accept(v NodeVisitor) { func (n *ExprCastObject) Accept(v NodeVisitor) {
@ -1499,7 +1507,8 @@ func (n *ExprCastObject) Accept(v NodeVisitor) {
// ExprCastString node // ExprCastString node
type ExprCastString struct { type ExprCastString struct {
Node Node
Expr Vertex CastTkn *token.Token
Expr Vertex
} }
func (n *ExprCastString) Accept(v NodeVisitor) { func (n *ExprCastString) Accept(v NodeVisitor) {
@ -1509,7 +1518,8 @@ func (n *ExprCastString) Accept(v NodeVisitor) {
// ExprCastUnset node // ExprCastUnset node
type ExprCastUnset struct { type ExprCastUnset struct {
Node Node
Expr Vertex CastTkn *token.Token
Expr Vertex
} }
func (n *ExprCastUnset) Accept(v NodeVisitor) { func (n *ExprCastUnset) Accept(v NodeVisitor) {