refactoring: create "ExprBrackets" node

This commit is contained in:
Vadym Slizov 2020-12-28 00:02:14 +02:00
parent ad884c99df
commit e4321b5e90
No known key found for this signature in database
GPG Key ID: AEA2A9388EF42A4A
15 changed files with 281 additions and 180 deletions

View File

@ -11513,14 +11513,14 @@ func TestStmtContinue(t *testing.T) {
}, },
}, },
}, },
Expr: &ast.ParserBrackets{ Expr: &ast.ExprBrackets{
Position: &position.Position{ Position: &position.Position{
StartLine: 1, StartLine: 1,
EndLine: 1, EndLine: 1,
StartPos: 23, StartPos: 23,
EndPos: 26, EndPos: 26,
}, },
OpenBracketTkn: &token.Token{ OpenParenthesisTkn: &token.Token{
ID: token.ID(40), ID: token.ID(40),
Value: []byte("("), Value: []byte("("),
Position: &position.Position{ Position: &position.Position{
@ -11530,7 +11530,7 @@ func TestStmtContinue(t *testing.T) {
EndPos: 24, EndPos: 24,
}, },
}, },
Child: &ast.ScalarLnumber{ Expr: &ast.ScalarLnumber{
Position: &position.Position{ Position: &position.Position{
StartLine: 1, StartLine: 1,
EndLine: 1, EndLine: 1,
@ -11549,7 +11549,7 @@ func TestStmtContinue(t *testing.T) {
}, },
Value: []byte("3"), Value: []byte("3"),
}, },
CloseBracketTkn: &token.Token{ CloseParenthesisTkn: &token.Token{
ID: token.ID(41), ID: token.ID(41),
Value: []byte(")"), Value: []byte(")"),
Position: &position.Position{ Position: &position.Position{
@ -12598,14 +12598,14 @@ func TestStmtEcho_Parenthesis(t *testing.T) {
}, },
}, },
Exprs: []ast.Vertex{ Exprs: []ast.Vertex{
&ast.ParserBrackets{ &ast.ExprBrackets{
Position: &position.Position{ Position: &position.Position{
StartLine: 1, StartLine: 1,
EndLine: 1, EndLine: 1,
StartPos: 7, StartPos: 7,
EndPos: 11, EndPos: 11,
}, },
OpenBracketTkn: &token.Token{ OpenParenthesisTkn: &token.Token{
ID: token.ID(40), ID: token.ID(40),
Value: []byte("("), Value: []byte("("),
Position: &position.Position{ Position: &position.Position{
@ -12615,7 +12615,7 @@ func TestStmtEcho_Parenthesis(t *testing.T) {
EndPos: 8, EndPos: 8,
}, },
}, },
Child: &ast.ExprVariable{ Expr: &ast.ExprVariable{
Position: &position.Position{ Position: &position.Position{
StartLine: 1, StartLine: 1,
EndLine: 1, EndLine: 1,
@ -12642,7 +12642,7 @@ func TestStmtEcho_Parenthesis(t *testing.T) {
Value: []byte("$a"), Value: []byte("$a"),
}, },
}, },
CloseBracketTkn: &token.Token{ CloseParenthesisTkn: &token.Token{
ID: token.ID(41), ID: token.ID(41),
Value: []byte(")"), Value: []byte(")"),
Position: &position.Position{ Position: &position.Position{
@ -12694,14 +12694,14 @@ func TestStmtExpression(t *testing.T) {
StartPos: 3, StartPos: 3,
EndPos: 9, EndPos: 9,
}, },
Expr: &ast.ParserBrackets{ Expr: &ast.ExprBrackets{
Position: &position.Position{ Position: &position.Position{
StartLine: 1, StartLine: 1,
EndLine: 1, EndLine: 1,
StartPos: 3, StartPos: 3,
EndPos: 8, EndPos: 8,
}, },
OpenBracketTkn: &token.Token{ OpenParenthesisTkn: &token.Token{
ID: token.ID(40), ID: token.ID(40),
Value: []byte("("), Value: []byte("("),
Position: &position.Position{ Position: &position.Position{
@ -12733,14 +12733,14 @@ func TestStmtExpression(t *testing.T) {
}, },
}, },
}, },
Child: &ast.ParserBrackets{ Expr: &ast.ExprBrackets{
Position: &position.Position{ Position: &position.Position{
StartLine: 1, StartLine: 1,
EndLine: 1, EndLine: 1,
StartPos: 4, StartPos: 4,
EndPos: 7, EndPos: 7,
}, },
OpenBracketTkn: &token.Token{ OpenParenthesisTkn: &token.Token{
ID: token.ID(40), ID: token.ID(40),
Value: []byte("("), Value: []byte("("),
Position: &position.Position{ Position: &position.Position{
@ -12750,7 +12750,7 @@ func TestStmtExpression(t *testing.T) {
EndPos: 5, EndPos: 5,
}, },
}, },
Child: &ast.ScalarLnumber{ Expr: &ast.ScalarLnumber{
Position: &position.Position{ Position: &position.Position{
StartLine: 1, StartLine: 1,
EndLine: 1, EndLine: 1,
@ -12769,7 +12769,7 @@ func TestStmtExpression(t *testing.T) {
}, },
Value: []byte("1"), Value: []byte("1"),
}, },
CloseBracketTkn: &token.Token{ CloseParenthesisTkn: &token.Token{
ID: token.ID(41), ID: token.ID(41),
Value: []byte(")"), Value: []byte(")"),
Position: &position.Position{ Position: &position.Position{
@ -12780,7 +12780,7 @@ func TestStmtExpression(t *testing.T) {
}, },
}, },
}, },
CloseBracketTkn: &token.Token{ CloseParenthesisTkn: &token.Token{
ID: token.ID(41), ID: token.ID(41),
Value: []byte(")"), Value: []byte(")"),
Position: &position.Position{ Position: &position.Position{
@ -29993,14 +29993,14 @@ func TestStmtBreak(t *testing.T) {
}, },
}, },
}, },
Expr: &ast.ParserBrackets{ Expr: &ast.ExprBrackets{
Position: &position.Position{ Position: &position.Position{
StartLine: 1, StartLine: 1,
EndLine: 1, EndLine: 1,
StartPos: 20, StartPos: 20,
EndPos: 23, EndPos: 23,
}, },
OpenBracketTkn: &token.Token{ OpenParenthesisTkn: &token.Token{
ID: token.ID(40), ID: token.ID(40),
Value: []byte("("), Value: []byte("("),
Position: &position.Position{ Position: &position.Position{
@ -30010,7 +30010,7 @@ func TestStmtBreak(t *testing.T) {
EndPos: 21, EndPos: 21,
}, },
}, },
Child: &ast.ScalarLnumber{ Expr: &ast.ScalarLnumber{
Position: &position.Position{ Position: &position.Position{
StartLine: 1, StartLine: 1,
EndLine: 1, EndLine: 1,
@ -30029,7 +30029,7 @@ func TestStmtBreak(t *testing.T) {
}, },
Value: []byte("3"), Value: []byte("3"),
}, },
CloseBracketTkn: &token.Token{ CloseParenthesisTkn: &token.Token{
ID: token.ID(41), ID: token.ID(41),
Value: []byte(")"), Value: []byte(")"),
Position: &position.Position{ Position: &position.Position{
@ -31402,14 +31402,14 @@ func TestExprClone_Brackets(t *testing.T) {
}, },
}, },
}, },
Expr: &ast.ParserBrackets{ Expr: &ast.ExprBrackets{
Position: &position.Position{ Position: &position.Position{
StartLine: 1, StartLine: 1,
EndLine: 1, EndLine: 1,
StartPos: 8, StartPos: 8,
EndPos: 12, EndPos: 12,
}, },
OpenBracketTkn: &token.Token{ OpenParenthesisTkn: &token.Token{
ID: token.ID(40), ID: token.ID(40),
Value: []byte("("), Value: []byte("("),
Position: &position.Position{ Position: &position.Position{
@ -31419,7 +31419,7 @@ func TestExprClone_Brackets(t *testing.T) {
EndPos: 9, EndPos: 9,
}, },
}, },
Child: &ast.ExprVariable{ Expr: &ast.ExprVariable{
Position: &position.Position{ Position: &position.Position{
StartLine: 1, StartLine: 1,
EndLine: 1, EndLine: 1,
@ -31446,7 +31446,7 @@ func TestExprClone_Brackets(t *testing.T) {
Value: []byte("$a"), Value: []byte("$a"),
}, },
}, },
CloseBracketTkn: &token.Token{ CloseParenthesisTkn: &token.Token{
ID: token.ID(41), ID: token.ID(41),
Value: []byte(")"), Value: []byte(")"),
Position: &position.Position{ Position: &position.Position{
@ -38335,14 +38335,14 @@ func TestExprPrint(t *testing.T) {
}, },
}, },
}, },
Expr: &ast.ParserBrackets{ Expr: &ast.ExprBrackets{
Position: &position.Position{ Position: &position.Position{
StartLine: 1, StartLine: 1,
EndLine: 1, EndLine: 1,
StartPos: 8, StartPos: 8,
EndPos: 12, EndPos: 12,
}, },
OpenBracketTkn: &token.Token{ OpenParenthesisTkn: &token.Token{
ID: token.ID(40), ID: token.ID(40),
Value: []byte("("), Value: []byte("("),
Position: &position.Position{ Position: &position.Position{
@ -38352,7 +38352,7 @@ func TestExprPrint(t *testing.T) {
EndPos: 9, EndPos: 9,
}, },
}, },
Child: &ast.ExprVariable{ Expr: &ast.ExprVariable{
Position: &position.Position{ Position: &position.Position{
StartLine: 1, StartLine: 1,
EndLine: 1, EndLine: 1,
@ -38379,7 +38379,7 @@ func TestExprPrint(t *testing.T) {
Value: []byte("$a"), Value: []byte("$a"),
}, },
}, },
CloseBracketTkn: &token.Token{ CloseParenthesisTkn: &token.Token{
ID: token.ID(41), ID: token.ID(41),
Value: []byte(")"), Value: []byte(")"),
Position: &position.Position{ Position: &position.Position{

86
internal/php5/php5.go generated
View File

@ -2888,9 +2888,9 @@ yydefault:
yyVAL.node = &ast.StmtIf{ yyVAL.node = &ast.StmtIf{
Position: pos, Position: pos,
IfTkn: yyDollar[1].token, IfTkn: yyDollar[1].token,
OpenParenthesisTkn: yyDollar[2].node.(*ast.ParserBrackets).OpenBracketTkn, OpenParenthesisTkn: yyDollar[2].node.(*ast.ExprBrackets).OpenParenthesisTkn,
Cond: yyDollar[2].node.(*ast.ParserBrackets).Child, Cond: yyDollar[2].node.(*ast.ExprBrackets).Expr,
CloseParenthesisTkn: yyDollar[2].node.(*ast.ParserBrackets).CloseBracketTkn, CloseParenthesisTkn: yyDollar[2].node.(*ast.ExprBrackets).CloseParenthesisTkn,
Stmt: yyDollar[3].node, Stmt: yyDollar[3].node,
ElseIf: yyDollar[4].list, ElseIf: yyDollar[4].list,
Else: yyDollar[5].node, Else: yyDollar[5].node,
@ -2903,9 +2903,9 @@ yydefault:
yyVAL.node = &ast.StmtIf{ yyVAL.node = &ast.StmtIf{
Position: yylex.(*Parser).builder.NewTokensPosition(yyDollar[1].token, yyDollar[8].token), Position: yylex.(*Parser).builder.NewTokensPosition(yyDollar[1].token, yyDollar[8].token),
IfTkn: yyDollar[1].token, IfTkn: yyDollar[1].token,
OpenParenthesisTkn: yyDollar[2].node.(*ast.ParserBrackets).OpenBracketTkn, OpenParenthesisTkn: yyDollar[2].node.(*ast.ExprBrackets).OpenParenthesisTkn,
Cond: yyDollar[2].node.(*ast.ParserBrackets).Child, Cond: yyDollar[2].node.(*ast.ExprBrackets).Expr,
CloseParenthesisTkn: yyDollar[2].node.(*ast.ParserBrackets).CloseBracketTkn, CloseParenthesisTkn: yyDollar[2].node.(*ast.ExprBrackets).CloseParenthesisTkn,
ColonTkn: yyDollar[3].token, ColonTkn: yyDollar[3].token,
Stmt: &ast.StmtStmtList{ Stmt: &ast.StmtStmtList{
Position: yylex.(*Parser).builder.NewNodeListPosition(yyDollar[4].list), Position: yylex.(*Parser).builder.NewNodeListPosition(yyDollar[4].list),
@ -2922,9 +2922,9 @@ yydefault:
// line internal/php5/php5.y:818 // line internal/php5/php5.y:818
{ {
yyDollar[3].node.(*ast.StmtWhile).WhileTkn = yyDollar[1].token yyDollar[3].node.(*ast.StmtWhile).WhileTkn = yyDollar[1].token
yyDollar[3].node.(*ast.StmtWhile).OpenParenthesisTkn = yyDollar[2].node.(*ast.ParserBrackets).OpenBracketTkn yyDollar[3].node.(*ast.StmtWhile).OpenParenthesisTkn = yyDollar[2].node.(*ast.ExprBrackets).OpenParenthesisTkn
yyDollar[3].node.(*ast.StmtWhile).Cond = yyDollar[2].node.(*ast.ParserBrackets).Child yyDollar[3].node.(*ast.StmtWhile).Cond = yyDollar[2].node.(*ast.ExprBrackets).Expr
yyDollar[3].node.(*ast.StmtWhile).CloseParenthesisTkn = yyDollar[2].node.(*ast.ParserBrackets).CloseBracketTkn yyDollar[3].node.(*ast.StmtWhile).CloseParenthesisTkn = yyDollar[2].node.(*ast.ExprBrackets).CloseParenthesisTkn
yyDollar[3].node.(*ast.StmtWhile).Position = yylex.(*Parser).builder.NewTokenNodePosition(yyDollar[1].token, yyDollar[3].node) yyDollar[3].node.(*ast.StmtWhile).Position = yylex.(*Parser).builder.NewTokenNodePosition(yyDollar[1].token, yyDollar[3].node)
yyVAL.node = yyDollar[3].node yyVAL.node = yyDollar[3].node
@ -2938,9 +2938,9 @@ yydefault:
DoTkn: yyDollar[1].token, DoTkn: yyDollar[1].token,
Stmt: yyDollar[2].node, Stmt: yyDollar[2].node,
WhileTkn: yyDollar[3].token, WhileTkn: yyDollar[3].token,
OpenParenthesisTkn: yyDollar[4].node.(*ast.ParserBrackets).OpenBracketTkn, OpenParenthesisTkn: yyDollar[4].node.(*ast.ExprBrackets).OpenParenthesisTkn,
Cond: yyDollar[4].node.(*ast.ParserBrackets).Child, Cond: yyDollar[4].node.(*ast.ExprBrackets).Expr,
CloseParenthesisTkn: yyDollar[4].node.(*ast.ParserBrackets).CloseBracketTkn, CloseParenthesisTkn: yyDollar[4].node.(*ast.ExprBrackets).CloseParenthesisTkn,
SemiColonTkn: yyDollar[5].token, SemiColonTkn: yyDollar[5].token,
} }
} }
@ -2968,9 +2968,9 @@ yydefault:
// line internal/php5/php5.y:858 // line internal/php5/php5.y:858
{ {
yyDollar[3].node.(*ast.StmtSwitch).SwitchTkn = yyDollar[1].token yyDollar[3].node.(*ast.StmtSwitch).SwitchTkn = yyDollar[1].token
yyDollar[3].node.(*ast.StmtSwitch).OpenParenthesisTkn = yyDollar[2].node.(*ast.ParserBrackets).OpenBracketTkn yyDollar[3].node.(*ast.StmtSwitch).OpenParenthesisTkn = yyDollar[2].node.(*ast.ExprBrackets).OpenParenthesisTkn
yyDollar[3].node.(*ast.StmtSwitch).Cond = yyDollar[2].node.(*ast.ParserBrackets).Child yyDollar[3].node.(*ast.StmtSwitch).Cond = yyDollar[2].node.(*ast.ExprBrackets).Expr
yyDollar[3].node.(*ast.StmtSwitch).CloseParenthesisTkn = yyDollar[2].node.(*ast.ParserBrackets).CloseBracketTkn yyDollar[3].node.(*ast.StmtSwitch).CloseParenthesisTkn = yyDollar[2].node.(*ast.ExprBrackets).CloseParenthesisTkn
yyDollar[3].node.(*ast.StmtSwitch).Position = yylex.(*Parser).builder.NewTokenNodePosition(yyDollar[1].token, yyDollar[3].node) yyDollar[3].node.(*ast.StmtSwitch).Position = yylex.(*Parser).builder.NewTokenNodePosition(yyDollar[1].token, yyDollar[3].node)
yyVAL.node = yyDollar[3].node yyVAL.node = yyDollar[3].node
@ -3891,9 +3891,9 @@ yydefault:
yyVAL.list = append(yyDollar[1].list, &ast.StmtElseIf{ yyVAL.list = append(yyDollar[1].list, &ast.StmtElseIf{
Position: yylex.(*Parser).builder.NewTokenNodePosition(yyDollar[2].token, yyDollar[4].node), Position: yylex.(*Parser).builder.NewTokenNodePosition(yyDollar[2].token, yyDollar[4].node),
ElseIfTkn: yyDollar[2].token, ElseIfTkn: yyDollar[2].token,
OpenParenthesisTkn: yyDollar[3].node.(*ast.ParserBrackets).OpenBracketTkn, OpenParenthesisTkn: yyDollar[3].node.(*ast.ExprBrackets).OpenParenthesisTkn,
Cond: yyDollar[3].node.(*ast.ParserBrackets).Child, Cond: yyDollar[3].node.(*ast.ExprBrackets).Expr,
CloseParenthesisTkn: yyDollar[3].node.(*ast.ParserBrackets).CloseBracketTkn, CloseParenthesisTkn: yyDollar[3].node.(*ast.ExprBrackets).CloseParenthesisTkn,
Stmt: yyDollar[4].node, Stmt: yyDollar[4].node,
}) })
} }
@ -3910,9 +3910,9 @@ yydefault:
yyVAL.list = append(yyDollar[1].list, &ast.StmtElseIf{ yyVAL.list = append(yyDollar[1].list, &ast.StmtElseIf{
Position: yylex.(*Parser).builder.NewTokenNodeListPosition(yyDollar[2].token, yyDollar[5].list), Position: yylex.(*Parser).builder.NewTokenNodeListPosition(yyDollar[2].token, yyDollar[5].list),
ElseIfTkn: yyDollar[2].token, ElseIfTkn: yyDollar[2].token,
OpenParenthesisTkn: yyDollar[3].node.(*ast.ParserBrackets).OpenBracketTkn, OpenParenthesisTkn: yyDollar[3].node.(*ast.ExprBrackets).OpenParenthesisTkn,
Cond: yyDollar[3].node.(*ast.ParserBrackets).Child, Cond: yyDollar[3].node.(*ast.ExprBrackets).Expr,
CloseParenthesisTkn: yyDollar[3].node.(*ast.ParserBrackets).CloseBracketTkn, CloseParenthesisTkn: yyDollar[3].node.(*ast.ExprBrackets).CloseParenthesisTkn,
ColonTkn: yyDollar[4].token, ColonTkn: yyDollar[4].token,
Stmt: &ast.StmtStmtList{ Stmt: &ast.StmtStmtList{
Position: yylex.(*Parser).builder.NewNodeListPosition(yyDollar[5].list), Position: yylex.(*Parser).builder.NewNodeListPosition(yyDollar[5].list),
@ -5549,11 +5549,11 @@ yydefault:
yyDollar = yyS[yypt-4 : yypt+1] yyDollar = yyS[yypt-4 : yypt+1]
// line internal/php5/php5.y:3216 // line internal/php5/php5.y:3216
{ {
yyVAL.node = &ast.ParserBrackets{ yyVAL.node = &ast.ExprBrackets{
Position: yylex.(*Parser).builder.NewTokensPosition(yyDollar[1].token, yyDollar[3].token), Position: yylex.(*Parser).builder.NewTokensPosition(yyDollar[1].token, yyDollar[3].token),
OpenBracketTkn: yyDollar[1].token, OpenParenthesisTkn: yyDollar[1].token,
Child: yyDollar[2].node, Expr: yyDollar[2].node,
CloseBracketTkn: yyDollar[3].token, CloseParenthesisTkn: yyDollar[3].token,
} }
for _, n := range yyDollar[4].list { for _, n := range yyDollar[4].list {
@ -5693,9 +5693,9 @@ yydefault:
exit.Position = yylex.(*Parser).builder.NewTokenPosition(yyDollar[1].token) exit.Position = yylex.(*Parser).builder.NewTokenPosition(yyDollar[1].token)
} else { } else {
exit.Position = yylex.(*Parser).builder.NewTokenNodePosition(yyDollar[1].token, yyDollar[2].node) exit.Position = yylex.(*Parser).builder.NewTokenNodePosition(yyDollar[1].token, yyDollar[2].node)
exit.OpenParenthesisTkn = yyDollar[2].node.(*ast.ParserBrackets).OpenBracketTkn exit.OpenParenthesisTkn = yyDollar[2].node.(*ast.ExprBrackets).OpenParenthesisTkn
exit.Expr = yyDollar[2].node.(*ast.ParserBrackets).Child exit.Expr = yyDollar[2].node.(*ast.ExprBrackets).Expr
exit.CloseParenthesisTkn = yyDollar[2].node.(*ast.ParserBrackets).CloseBracketTkn exit.CloseParenthesisTkn = yyDollar[2].node.(*ast.ExprBrackets).CloseParenthesisTkn
} }
yyVAL.node = exit yyVAL.node = exit
@ -6329,10 +6329,10 @@ yydefault:
yyDollar = yyS[yypt-2 : yypt+1] yyDollar = yyS[yypt-2 : yypt+1]
// line internal/php5/php5.y:3918 // line internal/php5/php5.y:3918
{ {
yyVAL.node = &ast.ParserBrackets{ yyVAL.node = &ast.ExprBrackets{
Position: yylex.(*Parser).builder.NewTokensPosition(yyDollar[1].token, yyDollar[2].token), Position: yylex.(*Parser).builder.NewTokensPosition(yyDollar[1].token, yyDollar[2].token),
OpenBracketTkn: yyDollar[1].token, OpenParenthesisTkn: yyDollar[1].token,
CloseBracketTkn: yyDollar[2].token, CloseParenthesisTkn: yyDollar[2].token,
} }
} }
case 347: case 347:
@ -6982,11 +6982,11 @@ yydefault:
yyDollar = yyS[yypt-3 : yypt+1] yyDollar = yyS[yypt-3 : yypt+1]
// line internal/php5/php5.y:4466 // line internal/php5/php5.y:4466
{ {
yyVAL.node = &ast.ParserBrackets{ yyVAL.node = &ast.ExprBrackets{
Position: yylex.(*Parser).builder.NewTokensPosition(yyDollar[1].token, yyDollar[3].token), Position: yylex.(*Parser).builder.NewTokensPosition(yyDollar[1].token, yyDollar[3].token),
OpenBracketTkn: yyDollar[1].token, OpenParenthesisTkn: yyDollar[1].token,
Child: yyDollar[2].node, Expr: yyDollar[2].node,
CloseBracketTkn: yyDollar[3].token, CloseParenthesisTkn: yyDollar[3].token,
} }
} }
case 410: case 410:
@ -7203,22 +7203,22 @@ yydefault:
yyDollar = yyS[yypt-3 : yypt+1] yyDollar = yyS[yypt-3 : yypt+1]
// line internal/php5/php5.y:4664 // line internal/php5/php5.y:4664
{ {
yyVAL.node = &ast.ParserBrackets{ yyVAL.node = &ast.ExprBrackets{
Position: yylex.(*Parser).builder.NewTokensPosition(yyDollar[1].token, yyDollar[3].token), Position: yylex.(*Parser).builder.NewTokensPosition(yyDollar[1].token, yyDollar[3].token),
OpenBracketTkn: yyDollar[1].token, OpenParenthesisTkn: yyDollar[1].token,
Child: yyDollar[2].node, Expr: yyDollar[2].node,
CloseBracketTkn: yyDollar[3].token, CloseParenthesisTkn: yyDollar[3].token,
} }
} }
case 432: case 432:
yyDollar = yyS[yypt-3 : yypt+1] yyDollar = yyS[yypt-3 : yypt+1]
// line internal/php5/php5.y:4673 // line internal/php5/php5.y:4673
{ {
yyVAL.node = &ast.ParserBrackets{ yyVAL.node = &ast.ExprBrackets{
Position: yylex.(*Parser).builder.NewTokensPosition(yyDollar[1].token, yyDollar[3].token), Position: yylex.(*Parser).builder.NewTokensPosition(yyDollar[1].token, yyDollar[3].token),
OpenBracketTkn: yyDollar[1].token, OpenParenthesisTkn: yyDollar[1].token,
Child: yyDollar[2].node, Expr: yyDollar[2].node,
CloseBracketTkn: yyDollar[3].token, CloseParenthesisTkn: yyDollar[3].token,
} }
} }
case 433: case 433:

View File

@ -787,9 +787,9 @@ unticked_statement:
$$ = &ast.StmtIf{ $$ = &ast.StmtIf{
Position: pos, Position: pos,
IfTkn: $1, IfTkn: $1,
OpenParenthesisTkn: $2.(*ast.ParserBrackets).OpenBracketTkn, OpenParenthesisTkn: $2.(*ast.ExprBrackets).OpenParenthesisTkn,
Cond: $2.(*ast.ParserBrackets).Child, Cond: $2.(*ast.ExprBrackets).Expr,
CloseParenthesisTkn: $2.(*ast.ParserBrackets).CloseBracketTkn, CloseParenthesisTkn: $2.(*ast.ExprBrackets).CloseParenthesisTkn,
Stmt: $3, Stmt: $3,
ElseIf: $4, ElseIf: $4,
Else: $5, Else: $5,
@ -800,9 +800,9 @@ unticked_statement:
$$ = &ast.StmtIf{ $$ = &ast.StmtIf{
Position: yylex.(*Parser).builder.NewTokensPosition($1, $8), Position: yylex.(*Parser).builder.NewTokensPosition($1, $8),
IfTkn: $1, IfTkn: $1,
OpenParenthesisTkn: $2.(*ast.ParserBrackets).OpenBracketTkn, OpenParenthesisTkn: $2.(*ast.ExprBrackets).OpenParenthesisTkn,
Cond: $2.(*ast.ParserBrackets).Child, Cond: $2.(*ast.ExprBrackets).Expr,
CloseParenthesisTkn: $2.(*ast.ParserBrackets).CloseBracketTkn, CloseParenthesisTkn: $2.(*ast.ExprBrackets).CloseParenthesisTkn,
ColonTkn: $3, ColonTkn: $3,
Stmt: &ast.StmtStmtList{ Stmt: &ast.StmtStmtList{
Position: yylex.(*Parser).builder.NewNodeListPosition($4), Position: yylex.(*Parser).builder.NewNodeListPosition($4),
@ -817,9 +817,9 @@ unticked_statement:
| T_WHILE parenthesis_expr while_statement | T_WHILE parenthesis_expr while_statement
{ {
$3.(*ast.StmtWhile).WhileTkn = $1 $3.(*ast.StmtWhile).WhileTkn = $1
$3.(*ast.StmtWhile).OpenParenthesisTkn = $2.(*ast.ParserBrackets).OpenBracketTkn $3.(*ast.StmtWhile).OpenParenthesisTkn = $2.(*ast.ExprBrackets).OpenParenthesisTkn
$3.(*ast.StmtWhile).Cond = $2.(*ast.ParserBrackets).Child $3.(*ast.StmtWhile).Cond = $2.(*ast.ExprBrackets).Expr
$3.(*ast.StmtWhile).CloseParenthesisTkn = $2.(*ast.ParserBrackets).CloseBracketTkn $3.(*ast.StmtWhile).CloseParenthesisTkn = $2.(*ast.ExprBrackets).CloseParenthesisTkn
$3.(*ast.StmtWhile).Position = yylex.(*Parser).builder.NewTokenNodePosition($1, $3) $3.(*ast.StmtWhile).Position = yylex.(*Parser).builder.NewTokenNodePosition($1, $3)
$$ = $3 $$ = $3
@ -831,9 +831,9 @@ unticked_statement:
DoTkn: $1, DoTkn: $1,
Stmt: $2, Stmt: $2,
WhileTkn: $3, WhileTkn: $3,
OpenParenthesisTkn: $4.(*ast.ParserBrackets).OpenBracketTkn, OpenParenthesisTkn: $4.(*ast.ExprBrackets).OpenParenthesisTkn,
Cond: $4.(*ast.ParserBrackets).Child, Cond: $4.(*ast.ExprBrackets).Expr,
CloseParenthesisTkn: $4.(*ast.ParserBrackets).CloseBracketTkn, CloseParenthesisTkn: $4.(*ast.ExprBrackets).CloseParenthesisTkn,
SemiColonTkn: $5, SemiColonTkn: $5,
} }
} }
@ -857,9 +857,9 @@ unticked_statement:
| T_SWITCH parenthesis_expr switch_case_list | T_SWITCH parenthesis_expr switch_case_list
{ {
$3.(*ast.StmtSwitch).SwitchTkn = $1 $3.(*ast.StmtSwitch).SwitchTkn = $1
$3.(*ast.StmtSwitch).OpenParenthesisTkn = $2.(*ast.ParserBrackets).OpenBracketTkn $3.(*ast.StmtSwitch).OpenParenthesisTkn = $2.(*ast.ExprBrackets).OpenParenthesisTkn
$3.(*ast.StmtSwitch).Cond = $2.(*ast.ParserBrackets).Child $3.(*ast.StmtSwitch).Cond = $2.(*ast.ExprBrackets).Expr
$3.(*ast.StmtSwitch).CloseParenthesisTkn = $2.(*ast.ParserBrackets).CloseBracketTkn $3.(*ast.StmtSwitch).CloseParenthesisTkn = $2.(*ast.ExprBrackets).CloseParenthesisTkn
$3.(*ast.StmtSwitch).Position = yylex.(*Parser).builder.NewTokenNodePosition($1, $3) $3.(*ast.StmtSwitch).Position = yylex.(*Parser).builder.NewTokenNodePosition($1, $3)
$$ = $3 $$ = $3
@ -1717,9 +1717,9 @@ elseif_list:
$$ = append($1, &ast.StmtElseIf{ $$ = append($1, &ast.StmtElseIf{
Position: yylex.(*Parser).builder.NewTokenNodePosition($2, $4), Position: yylex.(*Parser).builder.NewTokenNodePosition($2, $4),
ElseIfTkn: $2, ElseIfTkn: $2,
OpenParenthesisTkn: $3.(*ast.ParserBrackets).OpenBracketTkn, OpenParenthesisTkn: $3.(*ast.ExprBrackets).OpenParenthesisTkn,
Cond: $3.(*ast.ParserBrackets).Child, Cond: $3.(*ast.ExprBrackets).Expr,
CloseParenthesisTkn: $3.(*ast.ParserBrackets).CloseBracketTkn, CloseParenthesisTkn: $3.(*ast.ExprBrackets).CloseParenthesisTkn,
Stmt: $4, Stmt: $4,
}) })
} }
@ -1736,9 +1736,9 @@ new_elseif_list:
$$ = append($1, &ast.StmtElseIf{ $$ = append($1, &ast.StmtElseIf{
Position: yylex.(*Parser).builder.NewTokenNodeListPosition($2, $5), Position: yylex.(*Parser).builder.NewTokenNodeListPosition($2, $5),
ElseIfTkn: $2, ElseIfTkn: $2,
OpenParenthesisTkn: $3.(*ast.ParserBrackets).OpenBracketTkn, OpenParenthesisTkn: $3.(*ast.ExprBrackets).OpenParenthesisTkn,
Cond: $3.(*ast.ParserBrackets).Child, Cond: $3.(*ast.ExprBrackets).Expr,
CloseParenthesisTkn: $3.(*ast.ParserBrackets).CloseBracketTkn, CloseParenthesisTkn: $3.(*ast.ExprBrackets).CloseParenthesisTkn,
ColonTkn: $4, ColonTkn: $4,
Stmt: &ast.StmtStmtList{ Stmt: &ast.StmtStmtList{
Position: yylex.(*Parser).builder.NewNodeListPosition($5), Position: yylex.(*Parser).builder.NewNodeListPosition($5),
@ -3214,11 +3214,11 @@ expr_without_variable:
} }
| '(' new_expr ')' instance_call | '(' new_expr ')' instance_call
{ {
$$ = &ast.ParserBrackets{ $$ = &ast.ExprBrackets{
Position: yylex.(*Parser).builder.NewTokensPosition($1, $3), Position: yylex.(*Parser).builder.NewTokensPosition($1, $3),
OpenBracketTkn: $1, OpenParenthesisTkn: $1,
Child: $2, Expr: $2,
CloseBracketTkn: $3, CloseParenthesisTkn: $3,
} }
for _, n := range($4) { for _, n := range($4) {
@ -3336,9 +3336,9 @@ expr_without_variable:
exit.Position = yylex.(*Parser).builder.NewTokenPosition($1) exit.Position = yylex.(*Parser).builder.NewTokenPosition($1)
} else { } else {
exit.Position = yylex.(*Parser).builder.NewTokenNodePosition($1, $2) exit.Position = yylex.(*Parser).builder.NewTokenNodePosition($1, $2)
exit.OpenParenthesisTkn = $2.(*ast.ParserBrackets).OpenBracketTkn exit.OpenParenthesisTkn = $2.(*ast.ExprBrackets).OpenParenthesisTkn
exit.Expr = $2.(*ast.ParserBrackets).Child exit.Expr = $2.(*ast.ExprBrackets).Expr
exit.CloseParenthesisTkn = $2.(*ast.ParserBrackets).CloseBracketTkn exit.CloseParenthesisTkn = $2.(*ast.ExprBrackets).CloseParenthesisTkn
} }
$$ = exit $$ = exit
@ -3916,10 +3916,10 @@ exit_expr:
} }
| '(' ')' | '(' ')'
{ {
$$ = &ast.ParserBrackets{ $$ = &ast.ExprBrackets{
Position: yylex.(*Parser).builder.NewTokensPosition($1, $2), Position: yylex.(*Parser).builder.NewTokensPosition($1, $2),
OpenBracketTkn: $1, OpenParenthesisTkn: $1,
CloseBracketTkn: $2, CloseParenthesisTkn: $2,
} }
} }
| parenthesis_expr | parenthesis_expr
@ -4464,11 +4464,11 @@ static_operation:
} }
| '(' static_scalar_value ')' | '(' static_scalar_value ')'
{ {
$$ = &ast.ParserBrackets{ $$ = &ast.ExprBrackets{
Position: yylex.(*Parser).builder.NewTokensPosition($1, $3), Position: yylex.(*Parser).builder.NewTokensPosition($1, $3),
OpenBracketTkn: $1, OpenParenthesisTkn: $1,
Child: $2, Expr: $2,
CloseBracketTkn: $3, CloseParenthesisTkn: $3,
} }
} }
; ;
@ -4662,20 +4662,20 @@ expr:
parenthesis_expr: parenthesis_expr:
'(' expr ')' '(' expr ')'
{ {
$$ = &ast.ParserBrackets{ $$ = &ast.ExprBrackets{
Position: yylex.(*Parser).builder.NewTokensPosition($1, $3), Position: yylex.(*Parser).builder.NewTokensPosition($1, $3),
OpenBracketTkn: $1, OpenParenthesisTkn: $1,
Child: $2, Expr: $2,
CloseBracketTkn: $3, CloseParenthesisTkn: $3,
} }
} }
| '(' yield_expr ')' | '(' yield_expr ')'
{ {
$$ = &ast.ParserBrackets{ $$ = &ast.ExprBrackets{
Position: yylex.(*Parser).builder.NewTokensPosition($1, $3), Position: yylex.(*Parser).builder.NewTokensPosition($1, $3),
OpenBracketTkn: $1, OpenParenthesisTkn: $1,
Child: $2, Expr: $2,
CloseBracketTkn: $3, CloseParenthesisTkn: $3,
} }
} }
; ;

View File

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

38
internal/php7/php7.go generated
View File

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

View File

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

View File

@ -82,6 +82,7 @@ type NodeVisitor interface {
ExprArrayDimFetch(n *ExprArrayDimFetch) ExprArrayDimFetch(n *ExprArrayDimFetch)
ExprArrayItem(n *ExprArrayItem) ExprArrayItem(n *ExprArrayItem)
ExprArrowFunction(n *ExprArrowFunction) ExprArrowFunction(n *ExprArrowFunction)
ExprBrackets(n *ExprBrackets)
ExprBitwiseNot(n *ExprBitwiseNot) ExprBitwiseNot(n *ExprBitwiseNot)
ExprBooleanNot(n *ExprBooleanNot) ExprBooleanNot(n *ExprBooleanNot)
ExprClassConstFetch(n *ExprClassConstFetch) ExprClassConstFetch(n *ExprClassConstFetch)

View File

@ -1243,6 +1243,21 @@ func (n *ExprBooleanNot) GetPosition() *position.Position {
return n.Position return n.Position
} }
type ExprBrackets struct {
Position *position.Position
OpenParenthesisTkn *token.Token
Expr Vertex
CloseParenthesisTkn *token.Token
}
func (n *ExprBrackets) Accept(v NodeVisitor) {
v.ExprBrackets(n)
}
func (n *ExprBrackets) GetPosition() *position.Position {
return n.Position
}
// ExprClassConstFetch node // ExprClassConstFetch node
type ExprClassConstFetch struct { type ExprClassConstFetch struct {
Position *position.Position Position *position.Position

View File

@ -1109,6 +1109,18 @@ func (t *DFS) Traverse(n ast.Vertex) {
t.Traverse(nn.Expr) t.Traverse(nn.Expr)
t.visitor.Leave("Expr", true) t.visitor.Leave("Expr", true)
} }
case *ast.ExprBrackets:
if nn == nil {
return
}
if !t.visitor.EnterNode(nn) {
return
}
if nn.Expr != nil {
t.visitor.Enter("Expr", true)
t.Traverse(nn.Expr)
t.visitor.Leave("Expr", true)
}
case *ast.ExprClassConstFetch: case *ast.ExprClassConstFetch:
if nn == nil { if nn == nil {
return return

View File

@ -1108,6 +1108,19 @@ func (v *Dumper) ExprBooleanNot(n *ast.ExprBooleanNot) {
v.print(v.indent, "},\n") v.print(v.indent, "},\n")
} }
func (v *Dumper) ExprBrackets(n *ast.ExprBrackets) {
v.print(0, "&ast.ExprBrackets{\n")
v.indent++
v.dumpPosition(n.Position)
v.dumpToken("OpenParenthesisTkn", n.OpenParenthesisTkn)
v.dumpVertex("Expr", n.Expr)
v.dumpToken("CloseParenthesisTkn", n.CloseParenthesisTkn)
v.indent--
v.print(v.indent, "},\n")
}
func (v *Dumper) ExprClassConstFetch(n *ast.ExprClassConstFetch) { func (v *Dumper) ExprClassConstFetch(n *ast.ExprClassConstFetch) {
v.print(0, "&ast.ExprClassConstFetch{\n") v.print(0, "&ast.ExprClassConstFetch{\n")
v.indent++ v.indent++

View File

@ -1134,6 +1134,12 @@ func (f *formatter) ExprBooleanNot(n *ast.ExprBooleanNot) {
n.Expr.Accept(f) n.Expr.Accept(f)
} }
func (f *formatter) ExprBrackets(n *ast.ExprBrackets) {
n.OpenParenthesisTkn = f.newToken('(', []byte("("))
n.Expr.Accept(f)
n.CloseParenthesisTkn = f.newToken(')', []byte(")"))
}
func (f *formatter) ExprClassConstFetch(n *ast.ExprClassConstFetch) { func (f *formatter) ExprClassConstFetch(n *ast.ExprClassConstFetch) {
n.Class.Accept(f) n.Class.Accept(f)
n.DoubleColonTkn = f.newToken(token.T_PAAMAYIM_NEKUDOTAYIM, []byte("::")) n.DoubleColonTkn = f.newToken(token.T_PAAMAYIM_NEKUDOTAYIM, []byte("::"))

View File

@ -3571,6 +3571,31 @@ func TestFormatter_ExprBooleanNot(t *testing.T) {
} }
} }
func TestFormatter_ExprBrackets(t *testing.T) {
o := bytes.NewBufferString("")
n := &ast.ExprBrackets{
Expr: &ast.ExprVariable{
VarName: &ast.Identifier{
Value: []byte("$foo"),
},
},
}
f := visitor.NewFormatter().WithState(visitor.FormatterStatePHP).WithIndent(1)
n.Accept(f)
p := visitor.NewPrinter(o).WithState(visitor.PrinterStatePHP)
n.Accept(p)
expected := `($foo)`
actual := o.String()
if expected != actual {
t.Errorf("\nexpected: %s\ngot: %s\n", expected, actual)
}
}
func TestFormatter_ExprClassConstFetch(t *testing.T) { func TestFormatter_ExprClassConstFetch(t *testing.T) {
o := bytes.NewBufferString("") o := bytes.NewBufferString("")

View File

@ -270,6 +270,10 @@ func (v *Null) ExprBooleanNot(_ *ast.ExprBooleanNot) {
// do nothing // do nothing
} }
func (v *Null) ExprBrackets(_ *ast.ExprBrackets) {
// do nothing
}
func (v *Null) ExprClassConstFetch(_ *ast.ExprClassConstFetch) { func (v *Null) ExprClassConstFetch(_ *ast.ExprClassConstFetch) {
// do nothing // do nothing
} }

View File

@ -668,6 +668,12 @@ func (p *printer) ExprBooleanNot(n *ast.ExprBooleanNot) {
p.printNode(n.Expr) p.printNode(n.Expr)
} }
func (p *printer) ExprBrackets(n *ast.ExprBrackets) {
p.printToken(n.OpenParenthesisTkn, nil)
p.printNode(n.Expr)
p.printToken(n.CloseParenthesisTkn, nil)
}
func (p *printer) ExprClassConstFetch(n *ast.ExprClassConstFetch) { func (p *printer) ExprClassConstFetch(n *ast.ExprClassConstFetch) {
p.printNode(n.Class) p.printNode(n.Class)
p.printToken(n.DoubleColonTkn, []byte("::")) p.printToken(n.DoubleColonTkn, []byte("::"))

View File

@ -1696,6 +1696,25 @@ func TestPrinterPrintExprBooleanNot(t *testing.T) {
} }
} }
func TestPrinterPrintExprBracket(t *testing.T) {
o := bytes.NewBufferString("")
p := visitor.NewPrinter(o).WithState(visitor.PrinterStatePHP)
n := &ast.ExprBooleanNot{
Expr: &ast.ExprVariable{
VarName: &ast.Identifier{Value: []byte("$var")},
},
}
n.Accept(p)
expected := `!$var`
actual := o.String()
if expected != actual {
t.Errorf("\nexpected: %s\ngot: %s\n", expected, actual)
}
}
func TestPrinterPrintExprClassConstFetch(t *testing.T) { func TestPrinterPrintExprClassConstFetch(t *testing.T) {
o := bytes.NewBufferString("") o := bytes.NewBufferString("")