refactoring: create "ExprBrackets" node

This commit is contained in:
Vadym Slizov
2020-12-28 00:02:14 +02:00
parent ad884c99df
commit e4321b5e90
15 changed files with 281 additions and 180 deletions

View File

@@ -13048,14 +13048,14 @@ func TestStmtContinue(t *testing.T) {
},
},
},
Expr: &ast.ParserBrackets{
Expr: &ast.ExprBrackets{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 23,
EndPos: 26,
},
OpenBracketTkn: &token.Token{
OpenParenthesisTkn: &token.Token{
ID: token.ID(40),
Value: []byte("("),
Position: &position.Position{
@@ -13065,7 +13065,7 @@ func TestStmtContinue(t *testing.T) {
EndPos: 24,
},
},
Child: &ast.ScalarLnumber{
Expr: &ast.ScalarLnumber{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
@@ -13084,7 +13084,7 @@ func TestStmtContinue(t *testing.T) {
},
Value: []byte("3"),
},
CloseBracketTkn: &token.Token{
CloseParenthesisTkn: &token.Token{
ID: token.ID(41),
Value: []byte(")"),
Position: &position.Position{
@@ -14133,14 +14133,14 @@ func TestStmtEcho_Parenthesis(t *testing.T) {
},
},
Exprs: []ast.Vertex{
&ast.ParserBrackets{
&ast.ExprBrackets{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 7,
EndPos: 11,
},
OpenBracketTkn: &token.Token{
OpenParenthesisTkn: &token.Token{
ID: token.ID(40),
Value: []byte("("),
Position: &position.Position{
@@ -14150,7 +14150,7 @@ func TestStmtEcho_Parenthesis(t *testing.T) {
EndPos: 8,
},
},
Child: &ast.ExprVariable{
Expr: &ast.ExprVariable{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
@@ -14177,7 +14177,7 @@ func TestStmtEcho_Parenthesis(t *testing.T) {
Value: []byte("$a"),
},
},
CloseBracketTkn: &token.Token{
CloseParenthesisTkn: &token.Token{
ID: token.ID(41),
Value: []byte(")"),
Position: &position.Position{
@@ -33925,14 +33925,14 @@ func TestStmtBreak(t *testing.T) {
},
},
},
Expr: &ast.ParserBrackets{
Expr: &ast.ExprBrackets{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 20,
EndPos: 23,
},
OpenBracketTkn: &token.Token{
OpenParenthesisTkn: &token.Token{
ID: token.ID(40),
Value: []byte("("),
Position: &position.Position{
@@ -33942,7 +33942,7 @@ func TestStmtBreak(t *testing.T) {
EndPos: 21,
},
},
Child: &ast.ScalarLnumber{
Expr: &ast.ScalarLnumber{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
@@ -33961,7 +33961,7 @@ func TestStmtBreak(t *testing.T) {
},
Value: []byte("3"),
},
CloseBracketTkn: &token.Token{
CloseParenthesisTkn: &token.Token{
ID: token.ID(41),
Value: []byte(")"),
Position: &position.Position{
@@ -35900,14 +35900,14 @@ func TestExprClone_Brackets(t *testing.T) {
},
},
},
Expr: &ast.ParserBrackets{
Expr: &ast.ExprBrackets{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 8,
EndPos: 12,
},
OpenBracketTkn: &token.Token{
OpenParenthesisTkn: &token.Token{
ID: token.ID(40),
Value: []byte("("),
Position: &position.Position{
@@ -35917,7 +35917,7 @@ func TestExprClone_Brackets(t *testing.T) {
EndPos: 9,
},
},
Child: &ast.ExprVariable{
Expr: &ast.ExprVariable{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
@@ -35944,7 +35944,7 @@ func TestExprClone_Brackets(t *testing.T) {
Value: []byte("$a"),
},
},
CloseBracketTkn: &token.Token{
CloseParenthesisTkn: &token.Token{
ID: token.ID(41),
Value: []byte(")"),
Position: &position.Position{
@@ -43295,14 +43295,14 @@ func TestExprPrint(t *testing.T) {
},
},
},
Expr: &ast.ParserBrackets{
Expr: &ast.ExprBrackets{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 8,
EndPos: 12,
},
OpenBracketTkn: &token.Token{
OpenParenthesisTkn: &token.Token{
ID: token.ID(40),
Value: []byte("("),
Position: &position.Position{
@@ -43312,7 +43312,7 @@ func TestExprPrint(t *testing.T) {
EndPos: 9,
},
},
Child: &ast.ExprVariable{
Expr: &ast.ExprVariable{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
@@ -43339,7 +43339,7 @@ func TestExprPrint(t *testing.T) {
Value: []byte("$a"),
},
},
CloseBracketTkn: &token.Token{
CloseParenthesisTkn: &token.Token{
ID: token.ID(41),
Value: []byte(")"),
Position: &position.Position{

46
internal/php7/php7.go generated
View File

@@ -5534,11 +5534,11 @@ yydefault:
yyDollar = yyS[yypt-3 : yypt+1]
// line internal/php7/php7.y:2992
{
yyVAL.node = &ast.ParserBrackets{
Position: yylex.(*Parser).builder.NewTokensPosition(yyDollar[1].token, yyDollar[3].token),
OpenBracketTkn: yyDollar[1].token,
Child: yyDollar[2].node,
CloseBracketTkn: yyDollar[3].token,
yyVAL.node = &ast.ExprBrackets{
Position: yylex.(*Parser).builder.NewTokensPosition(yyDollar[1].token, yyDollar[3].token),
OpenParenthesisTkn: yyDollar[1].token,
Expr: yyDollar[2].node,
CloseParenthesisTkn: yyDollar[3].token,
}
}
case 350:
@@ -5671,9 +5671,9 @@ yydefault:
exit.Position = yylex.(*Parser).builder.NewTokenPosition(yyDollar[1].token)
} else {
exit.Position = yylex.(*Parser).builder.NewTokenNodePosition(yyDollar[1].token, yyDollar[2].node)
exit.OpenParenthesisTkn = yyDollar[2].node.(*ast.ParserBrackets).OpenBracketTkn
exit.Expr = yyDollar[2].node.(*ast.ParserBrackets).Child
exit.CloseParenthesisTkn = yyDollar[2].node.(*ast.ParserBrackets).CloseBracketTkn
exit.OpenParenthesisTkn = yyDollar[2].node.(*ast.ExprBrackets).OpenParenthesisTkn
exit.Expr = yyDollar[2].node.(*ast.ExprBrackets).Expr
exit.CloseParenthesisTkn = yyDollar[2].node.(*ast.ExprBrackets).CloseParenthesisTkn
}
yyVAL.node = exit
@@ -6006,11 +6006,11 @@ yydefault:
yyDollar = yyS[yypt-3 : yypt+1]
// line internal/php7/php7.y:3409
{
yyVAL.node = &ast.ParserBrackets{
Position: yylex.(*Parser).builder.NewTokensPosition(yyDollar[1].token, yyDollar[3].token),
OpenBracketTkn: yyDollar[1].token,
Child: yyDollar[2].node,
CloseBracketTkn: yyDollar[3].token,
yyVAL.node = &ast.ExprBrackets{
Position: yylex.(*Parser).builder.NewTokensPosition(yyDollar[1].token, yyDollar[3].token),
OpenParenthesisTkn: yyDollar[1].token,
Expr: yyDollar[2].node,
CloseParenthesisTkn: yyDollar[3].token,
}
}
case 394:
@@ -6324,11 +6324,11 @@ yydefault:
yyDollar = yyS[yypt-3 : yypt+1]
// line internal/php7/php7.y:3686
{
yyVAL.node = &ast.ParserBrackets{
Position: yylex.(*Parser).builder.NewTokensPosition(yyDollar[1].token, yyDollar[3].token),
OpenBracketTkn: yyDollar[1].token,
Child: yyDollar[2].node,
CloseBracketTkn: yyDollar[3].token,
yyVAL.node = &ast.ExprBrackets{
Position: yylex.(*Parser).builder.NewTokensPosition(yyDollar[1].token, yyDollar[3].token),
OpenParenthesisTkn: yyDollar[1].token,
Expr: yyDollar[2].node,
CloseParenthesisTkn: yyDollar[3].token,
}
}
case 428:
@@ -6347,11 +6347,11 @@ yydefault:
yyDollar = yyS[yypt-3 : yypt+1]
// line internal/php7/php7.y:3706
{
yyVAL.node = &ast.ParserBrackets{
Position: yylex.(*Parser).builder.NewTokensPosition(yyDollar[1].token, yyDollar[3].token),
OpenBracketTkn: yyDollar[1].token,
Child: yyDollar[2].node,
CloseBracketTkn: yyDollar[3].token,
yyVAL.node = &ast.ExprBrackets{
Position: yylex.(*Parser).builder.NewTokensPosition(yyDollar[1].token, yyDollar[3].token),
OpenParenthesisTkn: yyDollar[1].token,
Expr: yyDollar[2].node,
CloseParenthesisTkn: yyDollar[3].token,
}
}
case 431:

View File

@@ -2990,11 +2990,11 @@ expr_without_variable:
}
| '(' expr ')'
{
$$ = &ast.ParserBrackets{
$$ = &ast.ExprBrackets{
Position: yylex.(*Parser).builder.NewTokensPosition($1, $3),
OpenBracketTkn: $1,
Child: $2,
CloseBracketTkn: $3,
OpenParenthesisTkn: $1,
Expr: $2,
CloseParenthesisTkn: $3,
}
}
| new_expr
@@ -3101,9 +3101,9 @@ expr_without_variable:
exit.Position = yylex.(*Parser).builder.NewTokenPosition($1)
} else {
exit.Position = yylex.(*Parser).builder.NewTokenNodePosition($1, $2)
exit.OpenParenthesisTkn = $2.(*ast.ParserBrackets).OpenBracketTkn
exit.Expr = $2.(*ast.ParserBrackets).Child
exit.CloseParenthesisTkn = $2.(*ast.ParserBrackets).CloseBracketTkn
exit.OpenParenthesisTkn = $2.(*ast.ExprBrackets).OpenParenthesisTkn
exit.Expr = $2.(*ast.ExprBrackets).Expr
exit.CloseParenthesisTkn = $2.(*ast.ExprBrackets).CloseParenthesisTkn
}
$$ = exit
@@ -3407,11 +3407,11 @@ exit_expr:
}
| '(' optional_expr ')'
{
$$ = &ast.ParserBrackets{
$$ = &ast.ExprBrackets{
Position: yylex.(*Parser).builder.NewTokensPosition($1, $3),
OpenBracketTkn: $1,
Child: $2,
CloseBracketTkn: $3,
OpenParenthesisTkn: $1,
Expr: $2,
CloseParenthesisTkn: $3,
}
}
;
@@ -3684,11 +3684,11 @@ dereferencable:
}
| '(' expr ')'
{
$$ = &ast.ParserBrackets{
$$ = &ast.ExprBrackets{
Position: yylex.(*Parser).builder.NewTokensPosition($1, $3),
OpenBracketTkn: $1,
Child: $2,
CloseBracketTkn: $3,
OpenParenthesisTkn: $1,
Expr: $2,
CloseParenthesisTkn: $3,
}
}
| dereferencable_scalar
@@ -3704,11 +3704,11 @@ callable_expr:
}
| '(' expr ')'
{
$$ = &ast.ParserBrackets{
$$ = &ast.ExprBrackets{
Position: yylex.(*Parser).builder.NewTokensPosition($1, $3),
OpenBracketTkn: $1,
Child: $2,
CloseBracketTkn: $3,
OpenParenthesisTkn: $1,
Expr: $2,
CloseParenthesisTkn: $3,
}
}
| dereferencable_scalar