refactoring: update ast structure of "ArrayItem" node

This commit is contained in:
Vadym Slizov 2020-12-26 20:13:50 +02:00
parent 8bf1fa822d
commit 0f5f5e7dc7
No known key found for this signature in database
GPG Key ID: AEA2A9388EF42A4A
10 changed files with 149 additions and 174 deletions

View File

@ -30780,13 +30780,6 @@ func TestExprArray_Items(t *testing.T) {
},
},
&ast.ExprArrayItem{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 15,
EndPos: 18,
},
Val: &ast.ExprReference{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
@ -30815,7 +30808,7 @@ func TestExprArray_Items(t *testing.T) {
},
},
},
Var: &ast.ExprVariable{
Val: &ast.ExprVariable{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
@ -30843,7 +30836,6 @@ func TestExprArray_Items(t *testing.T) {
},
},
},
},
&ast.ExprArrayItem{},
},
SeparatorTkns: []*token.Token{
@ -39019,13 +39011,6 @@ func TestExprShortArray_Items(t *testing.T) {
},
},
&ast.ExprArrayItem{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 10,
EndPos: 13,
},
Val: &ast.ExprReference{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
@ -39054,7 +39039,7 @@ func TestExprShortArray_Items(t *testing.T) {
},
},
},
Var: &ast.ExprVariable{
Val: &ast.ExprVariable{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
@ -39082,7 +39067,6 @@ func TestExprShortArray_Items(t *testing.T) {
},
},
},
},
&ast.ExprArrayItem{},
},
SeparatorTkns: []*token.Token{

BIN
internal/php5/php5.go generated

Binary file not shown.

View File

@ -5258,11 +5258,8 @@ non_empty_array_pair_list:
Position: yylex.(*Parser).builder.NewNodesPosition($3, $6),
Key: $3,
DoubleArrowTkn: $4,
Val: &ast.ExprReference{
Position: yylex.(*Parser).builder.NewTokenNodePosition($5, $6),
AmpersandTkn: $5,
Var: $6,
},
Val: $6,
}
$1.(*ast.ParserSeparatedList).SeparatorTkns = append($1.(*ast.ParserSeparatedList).SeparatorTkns, $2)
@ -5273,12 +5270,9 @@ non_empty_array_pair_list:
| non_empty_array_pair_list ',' '&' w_variable
{
arrayItem := &ast.ExprArrayItem{
Position: yylex.(*Parser).builder.NewTokenNodePosition($3, $4),
Val: &ast.ExprReference{
Position: yylex.(*Parser).builder.NewTokenNodePosition($3, $4),
AmpersandTkn: $3,
Var: $4,
},
Val: $4,
}
$1.(*ast.ParserSeparatedList).SeparatorTkns = append($1.(*ast.ParserSeparatedList).SeparatorTkns, $2)
@ -5294,11 +5288,8 @@ non_empty_array_pair_list:
Position: yylex.(*Parser).builder.NewNodesPosition($1, $4),
Key: $1,
DoubleArrowTkn: $2,
Val: &ast.ExprReference{
Position: yylex.(*Parser).builder.NewTokenNodePosition($3, $4),
AmpersandTkn: $3,
Var: $4,
},
Val: $4,
},
},
}
@ -5308,12 +5299,9 @@ non_empty_array_pair_list:
$$ = &ast.ParserSeparatedList{
Items: []ast.Vertex{
&ast.ExprArrayItem{
Position: yylex.(*Parser).builder.NewTokenNodePosition($1, $2),
Val: &ast.ExprReference{
Position: yylex.(*Parser).builder.NewTokenNodePosition($1, $2),
AmpersandTkn: $1,
Var: $2,
},
Val: $2,
},
},
}

View File

@ -34712,13 +34712,6 @@ func TestExprArray_Items(t *testing.T) {
},
},
&ast.ExprArrayItem{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 15,
EndPos: 18,
},
Val: &ast.ExprReference{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
@ -34747,7 +34740,7 @@ func TestExprArray_Items(t *testing.T) {
},
},
},
Var: &ast.ExprVariable{
Val: &ast.ExprVariable{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
@ -34775,7 +34768,6 @@ func TestExprArray_Items(t *testing.T) {
},
},
},
},
&ast.ExprArrayItem{},
},
SeparatorTkns: []*token.Token{
@ -43977,13 +43969,6 @@ func TestExprShortArray_Items(t *testing.T) {
},
},
&ast.ExprArrayItem{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 10,
EndPos: 13,
},
Val: &ast.ExprReference{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
@ -44012,7 +43997,7 @@ func TestExprShortArray_Items(t *testing.T) {
},
},
},
Var: &ast.ExprVariable{
Val: &ast.ExprVariable{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
@ -44040,7 +44025,6 @@ func TestExprShortArray_Items(t *testing.T) {
},
},
},
},
&ast.ExprArrayItem{},
},
SeparatorTkns: []*token.Token{

BIN
internal/php7/php7.go generated

Binary file not shown.

View File

@ -3997,22 +3997,16 @@ array_pair:
Position: yylex.(*Parser).builder.NewNodesPosition($1, $4),
Key: $1,
DoubleArrowTkn: $2,
Val: &ast.ExprReference{
Position: yylex.(*Parser).builder.NewTokenNodePosition($3, $4),
AmpersandTkn: $3,
Var: $4,
},
Val: $4,
}
}
| '&' variable
{
$$ = &ast.ExprArrayItem{
Position: yylex.(*Parser).builder.NewTokenNodePosition($1, $2),
Val: &ast.ExprReference{
Position: yylex.(*Parser).builder.NewTokenNodePosition($1, $2),
AmpersandTkn: $1,
Var: $2,
},
Val: $2,
}
}
| T_ELLIPSIS expr

View File

@ -1177,6 +1177,7 @@ type ExprArrayItem struct {
EllipsisTkn *token.Token
Key Vertex
DoubleArrowTkn *token.Token
AmpersandTkn *token.Token
Val Vertex
}

View File

@ -1056,6 +1056,7 @@ func (v *Dumper) ExprArrayItem(n *ast.ExprArrayItem) {
v.dumpToken("EllipsisTkn", n.EllipsisTkn)
v.dumpVertex("Key", n.Key)
v.dumpToken("DoubleArrowTkn", n.DoubleArrowTkn)
v.dumpToken("AmpersandTkn", n.AmpersandTkn)
v.dumpVertex("Val", n.Val)
v.indent--

View File

@ -641,6 +641,7 @@ func (p *printer) ExprArrayItem(n *ast.ExprArrayItem) {
p.printToken(n.EllipsisTkn, nil)
p.printNode(n.Key)
p.printToken(n.DoubleArrowTkn, p.ifNode(n.Key, []byte("=>")))
p.printToken(n.AmpersandTkn, nil)
p.printNode(n.Val)
}

View File

@ -1559,9 +1559,31 @@ func TestPrinterPrintExprArrayItem(t *testing.T) {
p := visitor.NewPrinter(o).WithState(visitor.PrinterStatePHP)
n := &ast.ExprArrayItem{
Val: &ast.ExprReference{Var: &ast.ExprVariable{
Val: &ast.ExprVariable{
VarName: &ast.Identifier{Value: []byte("$world")},
}},
},
}
n.Accept(p)
expected := `$world`
actual := o.String()
if expected != actual {
t.Errorf("\nexpected: %s\ngot: %s\n", expected, actual)
}
}
func TestPrinterPrintExprArrayItem_Reference(t *testing.T) {
o := bytes.NewBufferString("")
p := visitor.NewPrinter(o).WithState(visitor.PrinterStatePHP)
n := &ast.ExprArrayItem{
AmpersandTkn: &token.Token{
Value: []byte("&"),
},
Val: &ast.ExprVariable{
VarName: &ast.Identifier{Value: []byte("$world")},
},
}
n.Accept(p)