[refactoring] update ast structure of "ArrayDimFetch" and "ArrayItem" nodes

This commit is contained in:
Vadym Slizov 2020-12-01 00:42:45 +02:00
parent 47b974a3a4
commit 4b8d431767
No known key found for this signature in database
GPG Key ID: AEA2A9388EF42A4A
7 changed files with 476 additions and 438 deletions

BIN
internal/php5/php5.go generated

Binary file not shown.

View File

@ -3067,27 +3067,31 @@ chaining_method_or_property:
chaining_dereference: chaining_dereference:
chaining_dereference '[' dim_offset ']' chaining_dereference '[' dim_offset ']'
{ {
fetch := &ast.ExprArrayDimFetch{ast.Node{}, nil, $3} fetch := &ast.ExprArrayDimFetch{
Node: ast.Node{
Position: position.NewTokensPosition($2, $4),
},
Var: nil,
OpenBracketTkn: $2,
Dim: $3,
CloseBracketTkn: $4,
}
$$ = append($1, fetch) $$ = append($1, fetch)
// save position
fetch.GetNode().Position = position.NewNodePosition($3)
// save comments
yylex.(*Parser).setFreeFloatingTokens(fetch, token.Var, $2.SkippedTokens)
yylex.(*Parser).setFreeFloatingTokens(fetch, token.Expr, $4.SkippedTokens)
} }
| '[' dim_offset ']' | '[' dim_offset ']'
{ {
fetch := &ast.ExprArrayDimFetch{ast.Node{}, nil, $2} fetch := &ast.ExprArrayDimFetch{
Node: ast.Node{
Position: position.NewTokensPosition($1, $3),
},
Var: nil,
OpenBracketTkn: $1,
Dim: $2,
CloseBracketTkn: $3,
}
$$ = []ast.Vertex{fetch} $$ = []ast.Vertex{fetch}
// save position
fetch.GetNode().Position = position.NewNodePosition($2)
// save comments
yylex.(*Parser).setFreeFloatingTokens(fetch, token.Var, $1.SkippedTokens)
yylex.(*Parser).setFreeFloatingTokens(fetch, token.Expr, $3.SkippedTokens)
} }
; ;
@ -4021,54 +4025,57 @@ yield_expr:
combined_scalar_offset: combined_scalar_offset:
combined_scalar '[' dim_offset ']' combined_scalar '[' dim_offset ']'
{ {
$$ = &ast.ExprArrayDimFetch{ast.Node{}, $1, $3} $$ = &ast.ExprArrayDimFetch{
Node: ast.Node{
// save position Position: position.NewNodeTokenPosition($1, $4),
$$.GetNode().Position = position.NewNodeTokenPosition($1, $4) },
Var: $1,
// save comments OpenBracketTkn: $2,
yylex.(*Parser).setFreeFloatingTokens($$, token.Var, $2.SkippedTokens) Dim: $3,
yylex.(*Parser).setFreeFloatingTokens($$, token.Expr, $4.SkippedTokens) CloseBracketTkn: $4,
}
} }
| combined_scalar_offset '[' dim_offset ']' | combined_scalar_offset '[' dim_offset ']'
{ {
$$ = &ast.ExprArrayDimFetch{ast.Node{}, $1, $3} $$ = &ast.ExprArrayDimFetch{
Node: ast.Node{
// save position Position: position.NewNodeTokenPosition($1, $4),
$$.GetNode().Position = position.NewNodeTokenPosition($1, $4) },
Var: $1,
// save comments OpenBracketTkn: $2,
yylex.(*Parser).setFreeFloatingTokens($$, token.Var, $2.SkippedTokens) Dim: $3,
yylex.(*Parser).setFreeFloatingTokens($$, token.Expr, $4.SkippedTokens) CloseBracketTkn: $4,
}
} }
| T_CONSTANT_ENCAPSED_STRING '[' dim_offset ']' | T_CONSTANT_ENCAPSED_STRING '[' dim_offset ']'
{ {
str := &ast.ScalarString{ $$ = &ast.ExprArrayDimFetch{
Node: ast.Node{ Node: ast.Node{
Position: position.NewTokenPosition($1), Position: position.NewTokensPosition($1, $4),
}, },
StringTkn: $1, Var: &ast.ScalarString{
Value: $1.Value, Node: ast.Node{
Position: position.NewTokenPosition($1),
},
StringTkn: $1,
Value: $1.Value,
},
OpenBracketTkn: $2,
Dim: $3,
CloseBracketTkn: $4,
} }
$$ = &ast.ExprArrayDimFetch{ast.Node{}, str, $3}
// save position
$$.GetNode().Position = position.NewNodeTokenPosition(str, $4)
// save comments
yylex.(*Parser).setFreeFloatingTokens($$, token.Var, $2.SkippedTokens)
yylex.(*Parser).setFreeFloatingTokens($$, token.Expr, $4.SkippedTokens)
} }
| general_constant '[' dim_offset ']' | general_constant '[' dim_offset ']'
{ {
$$ = &ast.ExprArrayDimFetch{ast.Node{}, $1, $3} $$ = &ast.ExprArrayDimFetch{
Node: ast.Node{
// save position Position: position.NewNodeTokenPosition($1, $4),
$$.GetNode().Position = position.NewNodeTokenPosition($1, $4) },
Var: $1,
// save comments OpenBracketTkn: $2,
yylex.(*Parser).setFreeFloatingTokens($$, token.Var, $2.SkippedTokens) Dim: $3,
yylex.(*Parser).setFreeFloatingTokens($$, token.Expr, $4.SkippedTokens) CloseBracketTkn: $4,
}
} }
; ;
@ -4782,14 +4789,15 @@ static_scalar_value:
static_operation: static_operation:
static_scalar_value '[' static_scalar_value ']' static_scalar_value '[' static_scalar_value ']'
{ {
$$ = &ast.ExprArrayDimFetch{ast.Node{}, $1, $3} $$ = &ast.ExprArrayDimFetch{
Node: ast.Node{
// save position Position: position.NewNodeTokenPosition($1, $4),
$$.GetNode().Position = position.NewNodeTokenPosition($1, $4) },
Var: $1,
// save comments OpenBracketTkn: $2,
yylex.(*Parser).setFreeFloatingTokens($$, token.Var, $2.SkippedTokens) Dim: $3,
yylex.(*Parser).setFreeFloatingTokens($$, token.Expr, $4.SkippedTokens) CloseBracketTkn: $4,
}
} }
| static_scalar_value '+' static_scalar_value | static_scalar_value '+' static_scalar_value
{ {
@ -5284,63 +5292,61 @@ possible_comma:
non_empty_static_array_pair_list: non_empty_static_array_pair_list:
non_empty_static_array_pair_list ',' static_scalar_value T_DOUBLE_ARROW static_scalar_value non_empty_static_array_pair_list ',' static_scalar_value T_DOUBLE_ARROW static_scalar_value
{ {
arrayItem := &ast.ExprArrayItem{ast.Node{}, false, $3, $5} arrayItem := &ast.ExprArrayItem{
Node: ast.Node{
Position: position.NewNodesPosition($3, $5),
},
Key: $3,
DoubleArrowTkn: $4,
Val: $5,
}
$1.(*ast.ParserSeparatedList).SeparatorTkns = append($1.(*ast.ParserSeparatedList).SeparatorTkns, $2) $1.(*ast.ParserSeparatedList).SeparatorTkns = append($1.(*ast.ParserSeparatedList).SeparatorTkns, $2)
$1.(*ast.ParserSeparatedList).Items = append($1.(*ast.ParserSeparatedList).Items, arrayItem) $1.(*ast.ParserSeparatedList).Items = append($1.(*ast.ParserSeparatedList).Items, arrayItem)
$$ = $1 $$ = $1
// save position
arrayItem.GetNode().Position = position.NewNodesPosition($3, $5)
// save comments
yylex.(*Parser).MoveFreeFloating($3, arrayItem)
yylex.(*Parser).setFreeFloating(arrayItem, token.Expr, $4.SkippedTokens)
} }
| non_empty_static_array_pair_list ',' static_scalar_value | non_empty_static_array_pair_list ',' static_scalar_value
{ {
arrayItem := &ast.ExprArrayItem{ast.Node{}, false, nil, $3} arrayItem := &ast.ExprArrayItem{
Node: ast.Node{
Position: position.NewNodePosition($3),
},
Val: $3,
}
$1.(*ast.ParserSeparatedList).SeparatorTkns = append($1.(*ast.ParserSeparatedList).SeparatorTkns, $2) $1.(*ast.ParserSeparatedList).SeparatorTkns = append($1.(*ast.ParserSeparatedList).SeparatorTkns, $2)
$1.(*ast.ParserSeparatedList).Items = append($1.(*ast.ParserSeparatedList).Items, arrayItem) $1.(*ast.ParserSeparatedList).Items = append($1.(*ast.ParserSeparatedList).Items, arrayItem)
$$ = $1 $$ = $1
// save position
arrayItem.GetNode().Position = position.NewNodePosition($3)
// save comments
yylex.(*Parser).MoveFreeFloating($3, arrayItem)
} }
| static_scalar_value T_DOUBLE_ARROW static_scalar_value | static_scalar_value T_DOUBLE_ARROW static_scalar_value
{ {
arrayItem := &ast.ExprArrayItem{ast.Node{}, false, $1, $3}
$$ = &ast.ParserSeparatedList{ $$ = &ast.ParserSeparatedList{
Items: []ast.Vertex{arrayItem}, Items: []ast.Vertex{
&ast.ExprArrayItem{
Node: ast.Node{
Position: position.NewNodesPosition($1, $3),
},
Key: $1,
DoubleArrowTkn: $2,
Val: $3,
},
},
} }
// save position
arrayItem.GetNode().Position = position.NewNodesPosition($1, $3)
// save comments
yylex.(*Parser).MoveFreeFloating($1, arrayItem)
yylex.(*Parser).setFreeFloating(arrayItem, token.Expr, $2.SkippedTokens)
} }
| static_scalar_value | static_scalar_value
{ {
arrayItem := &ast.ExprArrayItem{ast.Node{}, false, nil, $1}
$$ = &ast.ParserSeparatedList{ $$ = &ast.ParserSeparatedList{
Items: []ast.Vertex{arrayItem}, Items: []ast.Vertex{
&ast.ExprArrayItem{
Node: ast.Node{
Position: position.NewNodePosition($1),
},
Val: $1,
},
},
} }
// save position
arrayItem.GetNode().Position = position.NewNodePosition($1)
// save comments
yylex.(*Parser).MoveFreeFloating($1, arrayItem)
} }
; ;
@ -5504,27 +5510,31 @@ variable_property:
array_method_dereference: array_method_dereference:
array_method_dereference '[' dim_offset ']' array_method_dereference '[' dim_offset ']'
{ {
fetch := &ast.ExprArrayDimFetch{ast.Node{}, nil, $3} fetch := &ast.ExprArrayDimFetch{
Node: ast.Node{
Position: position.NewTokensPosition($2, $4),
},
Var: nil,
OpenBracketTkn: $2,
Dim: $3,
CloseBracketTkn: $4,
}
$$ = append($1, fetch) $$ = append($1, fetch)
// save position
fetch.GetNode().Position = position.NewNodePosition($3)
// save comments
yylex.(*Parser).setFreeFloatingTokens(fetch, token.Var, $2.SkippedTokens)
yylex.(*Parser).setFreeFloatingTokens(fetch, token.Expr, $4.SkippedTokens)
} }
| method '[' dim_offset ']' | method '[' dim_offset ']'
{ {
fetch := &ast.ExprArrayDimFetch{ast.Node{}, nil, $3} fetch := &ast.ExprArrayDimFetch{
Node: ast.Node{
Position: position.NewTokensPosition($2, $4),
},
Var: nil,
OpenBracketTkn: $2,
Dim: $3,
CloseBracketTkn: $4,
}
$$ = []ast.Vertex{$1, fetch} $$ = []ast.Vertex{$1, fetch}
// save position
fetch.GetNode().Position = position.NewNodePosition($3)
// save comments
yylex.(*Parser).setFreeFloatingTokens(fetch, token.Var, $2.SkippedTokens)
yylex.(*Parser).setFreeFloatingTokens(fetch, token.Expr, $4.SkippedTokens)
} }
; ;
@ -5605,25 +5615,27 @@ variable_class_name:
array_function_dereference: array_function_dereference:
array_function_dereference '[' dim_offset ']' array_function_dereference '[' dim_offset ']'
{ {
$$ = &ast.ExprArrayDimFetch{ast.Node{}, $1, $3} $$ = &ast.ExprArrayDimFetch{
Node: ast.Node{
// save position Position: position.NewNodeTokenPosition($1, $4),
$$.GetNode().Position = position.NewNodeTokenPosition($1, $4) },
Var: $1,
// save comments OpenBracketTkn: $2,
yylex.(*Parser).setFreeFloatingTokens($$, token.Var, $2.SkippedTokens) Dim: $3,
yylex.(*Parser).setFreeFloatingTokens($$, token.Expr, $4.SkippedTokens) CloseBracketTkn: $4,
}
} }
| function_call '[' dim_offset ']' | function_call '[' dim_offset ']'
{ {
$$ = &ast.ExprArrayDimFetch{ast.Node{}, $1, $3} $$ = &ast.ExprArrayDimFetch{
Node: ast.Node{
// save position Position: position.NewNodeTokenPosition($1, $4),
$$.GetNode().Position = position.NewNodeTokenPosition($1, $4) },
Var: $1,
// save comments OpenBracketTkn: $2,
yylex.(*Parser).setFreeFloatingTokens($$, token.Var, $2.SkippedTokens) Dim: $3,
yylex.(*Parser).setFreeFloatingTokens($$, token.Expr, $4.SkippedTokens) CloseBracketTkn: $4,
}
} }
; ;
@ -5667,25 +5679,27 @@ base_variable:
reference_variable: reference_variable:
reference_variable '[' dim_offset ']' reference_variable '[' dim_offset ']'
{ {
$$ = &ast.ExprArrayDimFetch{ast.Node{}, $1, $3} $$ = &ast.ExprArrayDimFetch{
Node: ast.Node{
// save position Position: position.NewNodeTokenPosition($1, $4),
$$.GetNode().Position = position.NewNodeTokenPosition($1, $4) },
Var: $1,
// save comments OpenBracketTkn: $2,
yylex.(*Parser).setFreeFloatingTokens($$, token.Var, $2.SkippedTokens) Dim: $3,
yylex.(*Parser).setFreeFloatingTokens($$, token.Expr, $4.SkippedTokens) CloseBracketTkn: $4,
}
} }
| reference_variable '{' expr '}' | reference_variable '{' expr '}'
{ {
$$ = &ast.ExprArrayDimFetch{ast.Node{}, $1, $3} $$ = &ast.ExprArrayDimFetch{
Node: ast.Node{
// save position Position: position.NewNodeTokenPosition($1, $4),
$$.GetNode().Position = position.NewNodeTokenPosition($1, $4) },
Var: $1,
// save comments OpenBracketTkn: $2,
yylex.(*Parser).setFreeFloatingTokens($$, token.Var, $2.SkippedTokens) Dim: $3,
yylex.(*Parser).setFreeFloatingTokens($$, token.Expr, $4.SkippedTokens) CloseBracketTkn: $4,
}
} }
| compound_variable | compound_variable
{ {
@ -5756,27 +5770,31 @@ object_property:
object_dim_list: object_dim_list:
object_dim_list '[' dim_offset ']' object_dim_list '[' dim_offset ']'
{ {
fetch := &ast.ExprArrayDimFetch{ast.Node{}, nil, $3} fetch := &ast.ExprArrayDimFetch{
Node: ast.Node{
Position: position.NewTokensPosition($2, $4),
},
Var: nil,
OpenBracketTkn: $2,
Dim: $3,
CloseBracketTkn: $4,
}
$$ = append($1, fetch) $$ = append($1, fetch)
// save position
fetch.GetNode().Position = position.NewNodePosition($3)
// save comments
yylex.(*Parser).setFreeFloatingTokens(fetch, token.Var, $2.SkippedTokens)
yylex.(*Parser).setFreeFloatingTokens(fetch, token.Expr, $4.SkippedTokens)
} }
| object_dim_list '{' expr '}' | object_dim_list '{' expr '}'
{ {
fetch := &ast.ExprArrayDimFetch{ast.Node{}, nil, $3} fetch := &ast.ExprArrayDimFetch{
Node: ast.Node{
Position: position.NewTokensPosition($2, $4),
},
Var: nil,
OpenBracketTkn: $2,
Dim: $3,
CloseBracketTkn: $4,
}
$$ = append($1, fetch) $$ = append($1, fetch)
// save position
fetch.GetNode().Position = position.NewNodePosition($3)
// save comments
yylex.(*Parser).setFreeFloatingTokens(fetch, token.Var, $2.SkippedTokens)
yylex.(*Parser).setFreeFloatingTokens(fetch, token.Expr, $4.SkippedTokens)
} }
| variable_name | variable_name
{ {
@ -5861,13 +5879,12 @@ assignment_list:
assignment_list_element: assignment_list_element:
variable variable
{ {
$$ = &ast.ExprArrayItem{ast.Node{}, false, nil, $1} $$ = &ast.ExprArrayItem{
Node: ast.Node{
// save position Position: position.NewNodePosition($1),
$$.GetNode().Position = position.NewNodePosition($1) },
Val: $1,
// save comments }
yylex.(*Parser).MoveFreeFloating($1, $$)
} }
| T_LIST '(' assignment_list ')' | T_LIST '(' assignment_list ')'
{ {
@ -5878,30 +5895,25 @@ assignment_list_element:
pairList.Items = nil pairList.Items = nil
} }
listNode := &ast.ExprList{ $$ = &ast.ExprArrayItem{
Node: ast.Node{ Node: ast.Node{
Position: position.NewTokensPosition($1, $4), Position: position.NewTokensPosition($1, $4),
}, },
ListTkn: $1, Val: &ast.ExprList{
OpenBracketTkn: $2, Node: ast.Node{
Items: $3.(*ast.ParserSeparatedList).Items, Position: position.NewTokensPosition($1, $4),
SeparatorTkns: $3.(*ast.ParserSeparatedList).SeparatorTkns, },
CloseBracketTkn: $4, ListTkn: $1,
OpenBracketTkn: $2,
Items: $3.(*ast.ParserSeparatedList).Items,
SeparatorTkns: $3.(*ast.ParserSeparatedList).SeparatorTkns,
CloseBracketTkn: $4,
},
} }
$$ = &ast.ExprArrayItem{ast.Node{}, false, nil, listNode}
// save position
listNode.GetNode().Position = position.NewTokensPosition($1, $4)
$$.GetNode().Position = position.NewNodePosition(listNode)
// save comments
yylex.(*Parser).setFreeFloating($$, token.Start, $1.SkippedTokens)
yylex.(*Parser).setFreeFloating(listNode, token.List, $2.SkippedTokens)
yylex.(*Parser).setFreeFloating(listNode, token.ArrayPairList, $4.SkippedTokens)
} }
| /* empty */ | /* empty */
{ {
$$ = &ast.ExprArrayItem{ast.Node{}, false, nil, nil} $$ = &ast.ExprArrayItem{}
} }
; ;
@ -5925,133 +5937,139 @@ array_pair_list:
non_empty_array_pair_list: non_empty_array_pair_list:
non_empty_array_pair_list ',' expr T_DOUBLE_ARROW expr non_empty_array_pair_list ',' expr T_DOUBLE_ARROW expr
{ {
arrayItem := &ast.ExprArrayItem{ast.Node{}, false, $3, $5} arrayItem := &ast.ExprArrayItem{
Node: ast.Node{
Position: position.NewNodesPosition($3, $5),
},
Key: $3,
DoubleArrowTkn: $4,
Val: $5,
}
$1.(*ast.ParserSeparatedList).SeparatorTkns = append($1.(*ast.ParserSeparatedList).SeparatorTkns, $2) $1.(*ast.ParserSeparatedList).SeparatorTkns = append($1.(*ast.ParserSeparatedList).SeparatorTkns, $2)
$1.(*ast.ParserSeparatedList).Items = append($1.(*ast.ParserSeparatedList).Items, arrayItem) $1.(*ast.ParserSeparatedList).Items = append($1.(*ast.ParserSeparatedList).Items, arrayItem)
$$ = $1 $$ = $1
// save position
arrayItem.GetNode().Position = position.NewNodesPosition($3, $5)
// save comments
yylex.(*Parser).MoveFreeFloating($3, arrayItem)
yylex.(*Parser).setFreeFloating(arrayItem, token.Expr, $4.SkippedTokens)
} }
| non_empty_array_pair_list ',' expr | non_empty_array_pair_list ',' expr
{ {
arrayItem := &ast.ExprArrayItem{ast.Node{}, false, nil, $3} arrayItem := &ast.ExprArrayItem{
Node: ast.Node{
Position: position.NewNodePosition($3),
},
Val: $3,
}
$1.(*ast.ParserSeparatedList).SeparatorTkns = append($1.(*ast.ParserSeparatedList).SeparatorTkns, $2) $1.(*ast.ParserSeparatedList).SeparatorTkns = append($1.(*ast.ParserSeparatedList).SeparatorTkns, $2)
$1.(*ast.ParserSeparatedList).Items = append($1.(*ast.ParserSeparatedList).Items, arrayItem) $1.(*ast.ParserSeparatedList).Items = append($1.(*ast.ParserSeparatedList).Items, arrayItem)
$$ = $1 $$ = $1
// save position
arrayItem.GetNode().Position = position.NewNodePosition($3)
// save comments
yylex.(*Parser).MoveFreeFloating($3, arrayItem)
} }
| expr T_DOUBLE_ARROW expr | expr T_DOUBLE_ARROW expr
{ {
arrayItem := &ast.ExprArrayItem{ast.Node{}, false, $1, $3}
$$ = &ast.ParserSeparatedList{ $$ = &ast.ParserSeparatedList{
Items: []ast.Vertex{arrayItem}, Items: []ast.Vertex{
&ast.ExprArrayItem{
Node: ast.Node{
Position: position.NewNodesPosition($1, $3),
},
Key: $1,
DoubleArrowTkn: $2,
Val: $3,
},
},
} }
// save position
arrayItem.GetNode().Position = position.NewNodesPosition($1, $3)
// save comments
yylex.(*Parser).MoveFreeFloating($1, arrayItem)
yylex.(*Parser).setFreeFloating(arrayItem, token.Expr, $2.SkippedTokens)
} }
| expr | expr
{ {
arrayItem := &ast.ExprArrayItem{ast.Node{}, false, nil, $1}
$$ = &ast.ParserSeparatedList{ $$ = &ast.ParserSeparatedList{
Items: []ast.Vertex{arrayItem}, Items: []ast.Vertex{
&ast.ExprArrayItem{
Node: ast.Node{
Position: position.NewNodePosition($1),
},
Val: $1,
},
},
} }
// save position
arrayItem.GetNode().Position = position.NewNodePosition($1)
// save comments
yylex.(*Parser).MoveFreeFloating($1, arrayItem)
} }
| non_empty_array_pair_list ',' expr T_DOUBLE_ARROW '&' w_variable | non_empty_array_pair_list ',' expr T_DOUBLE_ARROW '&' w_variable
{ {
reference := &ast.ExprReference{ast.Node{}, $6} arrayItem := &ast.ExprArrayItem{
arrayItem := &ast.ExprArrayItem{ast.Node{}, false, $3, reference} Node: ast.Node{
Position: position.NewNodesPosition($3, $6),
},
Key: $3,
DoubleArrowTkn: $4,
Val: &ast.ExprReference{
Node: ast.Node{
Position: position.NewTokenNodePosition($5, $6),
},
Var: $6,
},
}
$1.(*ast.ParserSeparatedList).SeparatorTkns = append($1.(*ast.ParserSeparatedList).SeparatorTkns, $2) $1.(*ast.ParserSeparatedList).SeparatorTkns = append($1.(*ast.ParserSeparatedList).SeparatorTkns, $2)
$1.(*ast.ParserSeparatedList).Items = append($1.(*ast.ParserSeparatedList).Items, arrayItem) $1.(*ast.ParserSeparatedList).Items = append($1.(*ast.ParserSeparatedList).Items, arrayItem)
$$ = $1 $$ = $1
// save position
reference.GetNode().Position = position.NewTokenNodePosition($5, $6)
arrayItem.GetNode().Position = position.NewNodesPosition($3, $6)
// save comments
yylex.(*Parser).MoveFreeFloating($3, arrayItem)
yylex.(*Parser).setFreeFloating(arrayItem, token.Expr, $4.SkippedTokens)
yylex.(*Parser).setFreeFloating(reference, token.Start, $5.SkippedTokens)
} }
| non_empty_array_pair_list ',' '&' w_variable | non_empty_array_pair_list ',' '&' w_variable
{ {
reference := &ast.ExprReference{ast.Node{}, $4} arrayItem := &ast.ExprArrayItem{
arrayItem := &ast.ExprArrayItem{ast.Node{}, false, nil, reference} Node: ast.Node{
Position: position.NewTokenNodePosition($3, $4),
},
Val: &ast.ExprReference{
Node: ast.Node{
Position: position.NewTokenNodePosition($3, $4),
},
Var: $4,
},
}
$1.(*ast.ParserSeparatedList).SeparatorTkns = append($1.(*ast.ParserSeparatedList).SeparatorTkns, $2) $1.(*ast.ParserSeparatedList).SeparatorTkns = append($1.(*ast.ParserSeparatedList).SeparatorTkns, $2)
$1.(*ast.ParserSeparatedList).Items = append($1.(*ast.ParserSeparatedList).Items, arrayItem) $1.(*ast.ParserSeparatedList).Items = append($1.(*ast.ParserSeparatedList).Items, arrayItem)
$$ = $1 $$ = $1
// save position
reference.GetNode().Position = position.NewTokenNodePosition($3, $4)
arrayItem.GetNode().Position = position.NewTokenNodePosition($3, $4)
// save comments
yylex.(*Parser).setFreeFloating(arrayItem, token.Start, $3.SkippedTokens)
} }
| expr T_DOUBLE_ARROW '&' w_variable | expr T_DOUBLE_ARROW '&' w_variable
{ {
reference := &ast.ExprReference{ast.Node{}, $4}
arrayItem := &ast.ExprArrayItem{ast.Node{}, false, $1, reference}
$$ = &ast.ParserSeparatedList{ $$ = &ast.ParserSeparatedList{
Items: []ast.Vertex{arrayItem}, Items: []ast.Vertex{
&ast.ExprArrayItem{
Node: ast.Node{
Position: position.NewNodesPosition($1, $4),
},
Key: $1,
DoubleArrowTkn: $2,
Val: &ast.ExprReference{
Node: ast.Node{
Position: position.NewTokenNodePosition($3, $4),
},
Var: $4,
},
},
},
} }
// save position
reference.GetNode().Position = position.NewTokenNodePosition($3, $4)
arrayItem.GetNode().Position = position.NewNodesPosition($1, $4)
// save comments
yylex.(*Parser).MoveFreeFloating($1, arrayItem)
yylex.(*Parser).setFreeFloating(arrayItem, token.Expr, $2.SkippedTokens)
yylex.(*Parser).setFreeFloating(reference, token.Start, $3.SkippedTokens)
} }
| '&' w_variable | '&' w_variable
{ {
reference := &ast.ExprReference{ast.Node{}, $2}
arrayItem := &ast.ExprArrayItem{ast.Node{}, false, nil, reference}
$$ = &ast.ParserSeparatedList{ $$ = &ast.ParserSeparatedList{
Items: []ast.Vertex{arrayItem}, Items: []ast.Vertex{
&ast.ExprArrayItem{
Node: ast.Node{
Position: position.NewTokenNodePosition($1, $2),
},
Val: &ast.ExprReference{
Node: ast.Node{
Position: position.NewTokenNodePosition($1, $2),
},
Var: $2,
},
},
},
} }
// save position
reference.GetNode().Position = position.NewTokenNodePosition($1, $2)
arrayItem.GetNode().Position = position.NewTokenNodePosition($1, $2)
// save comments
yylex.(*Parser).setFreeFloating(arrayItem, token.Start, $1.SkippedTokens)
} }
; ;
@ -6112,23 +6130,26 @@ encaps_var:
} }
| T_VARIABLE '[' encaps_var_offset ']' | T_VARIABLE '[' encaps_var_offset ']'
{ {
identifier := &ast.Identifier{ $$ = &ast.ExprArrayDimFetch{
Node: ast.Node{ Node: ast.Node{
Position: position.NewTokenPosition($1), Position: position.NewTokensPosition($1, $4),
}, },
IdentifierTkn: $1, Var: &ast.ExprVariable{
Value: $1.Value, Node: ast.Node{
Position: position.NewTokenPosition($1),
},
VarName: &ast.Identifier{
Node: ast.Node{
Position: position.NewTokenPosition($1),
},
IdentifierTkn: $1,
Value: $1.Value,
},
},
OpenBracketTkn: $2,
Dim: $3,
CloseBracketTkn: $4,
} }
variable := &ast.ExprVariable{ast.Node{}, identifier}
$$ = &ast.ExprArrayDimFetch{ast.Node{}, variable, $3}
// save position
variable.GetNode().Position = position.NewTokenPosition($1)
$$.GetNode().Position = position.NewTokensPosition($1, $4)
// save comments
yylex.(*Parser).setFreeFloatingTokens($$, token.Var, $2.SkippedTokens)
yylex.(*Parser).setFreeFloatingTokens($$, token.Expr, $4.SkippedTokens)
} }
| T_VARIABLE T_OBJECT_OPERATOR T_STRING | T_VARIABLE T_OBJECT_OPERATOR T_STRING
{ {
@ -6191,25 +6212,28 @@ encaps_var:
} }
| T_DOLLAR_OPEN_CURLY_BRACES T_STRING_VARNAME '[' expr ']' '}' | T_DOLLAR_OPEN_CURLY_BRACES T_STRING_VARNAME '[' expr ']' '}'
{ {
identifier := &ast.Identifier{ $$ = &ast.ExprArrayDimFetch{
Node: ast.Node{ Node: ast.Node{
Position: position.NewTokenPosition($2), Position: position.NewTokensPosition($1, $6),
}, },
IdentifierTkn: $2, OpenCurlyBracketTkn: $1,
Value: $2.Value, 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,
},
},
OpenBracketTkn: $3,
Dim: $4,
CloseBracketTkn: $5,
CloseCurlyBracketTkn: $6,
} }
variable := &ast.ExprVariable{ast.Node{}, identifier}
$$ = &ast.ExprArrayDimFetch{ast.Node{}, variable, $4}
// save position
variable.GetNode().Position = position.NewTokenPosition($2)
$$.GetNode().Position = position.NewTokensPosition($1, $6)
// save comments
yylex.(*Parser).setToken(variable, token.Start, $1.SkippedTokens)
yylex.(*Parser).setFreeFloatingTokens($$, token.Var, $3.SkippedTokens)
yylex.(*Parser).setFreeFloatingTokens($$, token.Expr, $5.SkippedTokens)
yylex.(*Parser).setFreeFloatingTokens($$, token.End, $6.SkippedTokens)
} }
| T_CURLY_OPEN variable '}' | T_CURLY_OPEN variable '}'
{ {

BIN
internal/php7/php7.go generated

Binary file not shown.

View File

@ -4236,36 +4236,39 @@ callable_variable:
} }
| dereferencable '[' optional_expr ']' | dereferencable '[' optional_expr ']'
{ {
$$ = &ast.ExprArrayDimFetch{ast.Node{}, $1, $3} $$ = &ast.ExprArrayDimFetch{
Node: ast.Node{
// save position Position: position.NewNodeTokenPosition($1, $4),
$$.GetNode().Position = position.NewNodeTokenPosition($1, $4) },
Var: $1,
// save comments OpenBracketTkn: $2,
yylex.(*Parser).setFreeFloatingTokens($$, token.Var, $2.SkippedTokens) Dim: $3,
yylex.(*Parser).setFreeFloatingTokens($$, token.Expr, $4.SkippedTokens) CloseBracketTkn: $4,
}
} }
| constant '[' optional_expr ']' | constant '[' optional_expr ']'
{ {
$$ = &ast.ExprArrayDimFetch{ast.Node{}, $1, $3} $$ = &ast.ExprArrayDimFetch{
Node: ast.Node{
// save position Position: position.NewNodeTokenPosition($1, $4),
$$.GetNode().Position = position.NewNodeTokenPosition($1, $4) },
Var: $1,
// save comments OpenBracketTkn: $2,
yylex.(*Parser).setFreeFloatingTokens($$, token.Var, $2.SkippedTokens) Dim: $3,
yylex.(*Parser).setFreeFloatingTokens($$, token.Expr, $4.SkippedTokens) CloseBracketTkn: $4,
}
} }
| dereferencable '{' expr '}' | dereferencable '{' expr '}'
{ {
$$ = &ast.ExprArrayDimFetch{ast.Node{}, $1, $3} $$ = &ast.ExprArrayDimFetch{
Node: ast.Node{
// save position Position: position.NewNodeTokenPosition($1, $4),
$$.GetNode().Position = position.NewNodeTokenPosition($1, $4) },
Var: $1,
// save comments OpenBracketTkn: $2,
yylex.(*Parser).setFreeFloatingTokens($$, token.Var, $2.SkippedTokens) Dim: $3,
yylex.(*Parser).setFreeFloatingTokens($$, token.Expr, $4.SkippedTokens) CloseBracketTkn: $4,
}
} }
| dereferencable T_OBJECT_OPERATOR property_name argument_list | dereferencable T_OBJECT_OPERATOR property_name argument_list
{ {
@ -4380,25 +4383,27 @@ new_variable:
} }
| new_variable '[' optional_expr ']' | new_variable '[' optional_expr ']'
{ {
$$ = &ast.ExprArrayDimFetch{ast.Node{}, $1, $3} $$ = &ast.ExprArrayDimFetch{
Node: ast.Node{
// save position Position: position.NewNodeTokenPosition($1, $4),
$$.GetNode().Position = position.NewNodeTokenPosition($1, $4) },
Var: $1,
// save comments OpenBracketTkn: $2,
yylex.(*Parser).setFreeFloatingTokens($$, token.Var, $2.SkippedTokens) Dim: $3,
yylex.(*Parser).setFreeFloatingTokens($$, token.Expr, $4.SkippedTokens) CloseBracketTkn: $4,
}
} }
| new_variable '{' expr '}' | new_variable '{' expr '}'
{ {
$$ = &ast.ExprArrayDimFetch{ast.Node{}, $1, $3} $$ = &ast.ExprArrayDimFetch{
Node: ast.Node{
// save position Position: position.NewNodeTokenPosition($1, $4),
$$.GetNode().Position = position.NewNodeTokenPosition($1, $4) },
Var: $1,
// save comments OpenBracketTkn: $2,
yylex.(*Parser).setFreeFloatingTokens($$, token.Var, $2.SkippedTokens) Dim: $3,
yylex.(*Parser).setFreeFloatingTokens($$, token.Expr, $4.SkippedTokens) CloseBracketTkn: $4,
}
} }
| new_variable T_OBJECT_OPERATOR property_name | new_variable T_OBJECT_OPERATOR property_name
{ {
@ -4529,98 +4534,101 @@ non_empty_array_pair_list:
array_pair: array_pair:
expr T_DOUBLE_ARROW expr expr T_DOUBLE_ARROW expr
{ {
$$ = &ast.ExprArrayItem{ast.Node{}, false, $1, $3} $$ = &ast.ExprArrayItem{
Node: ast.Node{
// save position Position: position.NewNodesPosition($1, $3),
$$.GetNode().Position = position.NewNodesPosition($1, $3) },
Key: $1,
// save comments DoubleArrowTkn: $2,
yylex.(*Parser).MoveFreeFloating($1, $$) Val: $3,
yylex.(*Parser).setFreeFloating($$, token.Expr, $2.SkippedTokens) }
} }
| expr | expr
{ {
$$ = &ast.ExprArrayItem{ast.Node{}, false, nil, $1} $$ = &ast.ExprArrayItem{
Node: ast.Node{
// save position Position: position.NewNodePosition($1),
$$.GetNode().Position = position.NewNodePosition($1) },
Val: $1,
// save comments }
yylex.(*Parser).MoveFreeFloating($1, $$)
} }
| expr T_DOUBLE_ARROW '&' variable | expr T_DOUBLE_ARROW '&' variable
{ {
reference := &ast.ExprReference{ast.Node{}, $4} $$ = &ast.ExprArrayItem{
$$ = &ast.ExprArrayItem{ast.Node{}, false, $1, reference} Node: ast.Node{
Position: position.NewNodesPosition($1, $4),
// save position },
$$.GetNode().Position = position.NewNodesPosition($1, $4) Key: $1,
reference.GetNode().Position = position.NewTokenNodePosition($3, $4) DoubleArrowTkn: $2,
Val: &ast.ExprReference{
// save comments Node: ast.Node{
yylex.(*Parser).MoveFreeFloating($1, $$) Position: position.NewTokenNodePosition($3, $4),
yylex.(*Parser).setFreeFloating($$, token.Expr, $2.SkippedTokens) },
yylex.(*Parser).setFreeFloating(reference, token.Start, $3.SkippedTokens) Var: $4,
},
}
} }
| '&' variable | '&' variable
{ {
reference := &ast.ExprReference{ast.Node{}, $2} $$ = &ast.ExprArrayItem{
$$ = &ast.ExprArrayItem{ast.Node{}, false, nil, reference} Node: ast.Node{
Position: position.NewTokenNodePosition($1, $2),
// save position },
$$.GetNode().Position = position.NewTokenNodePosition($1, $2) Val: &ast.ExprReference{
reference.GetNode().Position = position.NewTokenNodePosition($1, $2) Node: ast.Node{
Position: position.NewTokenNodePosition($1, $2),
// save comments },
yylex.(*Parser).setFreeFloating($$, token.Start, $1.SkippedTokens) Var: $2,
},
}
} }
| T_ELLIPSIS expr | T_ELLIPSIS expr
{ {
$$ = &ast.ExprArrayItem{ast.Node{}, true, nil, $2} $$ = &ast.ExprArrayItem{
Node: ast.Node{
// save position Position: position.NewTokenNodePosition($1, $2),
$$.GetNode().Position = position.NewTokenNodePosition($1, $2) },
EllipsisTkn: $1,
// save comments Val: $2,
yylex.(*Parser).setFreeFloating($$, token.Start, $1.SkippedTokens) }
} }
| expr T_DOUBLE_ARROW T_LIST '(' array_pair_list ')' | expr T_DOUBLE_ARROW T_LIST '(' array_pair_list ')'
{ {
listNode := &ast.ExprList{ $$ = &ast.ExprArrayItem{
Node: ast.Node{ Node: ast.Node{
Position: position.NewTokensPosition($3, $6), Position: position.NewNodeTokenPosition($1, $6),
},
Key: $1,
DoubleArrowTkn: $2,
Val: &ast.ExprList{
Node: ast.Node{
Position: position.NewTokensPosition($3, $6),
},
ListTkn: $3,
OpenBracketTkn: $4,
Items: $5.(*ast.ParserSeparatedList).Items,
SeparatorTkns: $5.(*ast.ParserSeparatedList).SeparatorTkns,
CloseBracketTkn: $6,
}, },
ListTkn: $3,
OpenBracketTkn: $4,
Items: $5.(*ast.ParserSeparatedList).Items,
SeparatorTkns: $5.(*ast.ParserSeparatedList).SeparatorTkns,
CloseBracketTkn: $6,
} }
$$ = &ast.ExprArrayItem{ast.Node{}, false, $1, listNode}
// save position
$$.GetNode().Position = position.NewNodeTokenPosition($1, $6)
// save comments
yylex.(*Parser).MoveFreeFloating($1, $$)
yylex.(*Parser).setFreeFloating($$, token.Expr, $2.SkippedTokens)
} }
| T_LIST '(' array_pair_list ')' | T_LIST '(' array_pair_list ')'
{ {
listNode := &ast.ExprList{ $$ = &ast.ExprArrayItem{
Node: ast.Node{ Node: ast.Node{
Position: position.NewTokensPosition($1, $4), Position: position.NewTokensPosition($1, $4),
}, },
ListTkn: $1, Val: &ast.ExprList{
OpenBracketTkn: $2, Node: ast.Node{
Items: $3.(*ast.ParserSeparatedList).Items, Position: position.NewTokensPosition($1, $4),
SeparatorTkns: $3.(*ast.ParserSeparatedList).SeparatorTkns, },
CloseBracketTkn: $4, ListTkn: $1,
OpenBracketTkn: $2,
Items: $3.(*ast.ParserSeparatedList).Items,
SeparatorTkns: $3.(*ast.ParserSeparatedList).SeparatorTkns,
CloseBracketTkn: $4,
},
} }
$$ = &ast.ExprArrayItem{ast.Node{}, false, nil, listNode}
// save position
$$.GetNode().Position = position.NewTokensPosition($1, $4)
} }
; ;
@ -4681,23 +4689,26 @@ encaps_var:
} }
| T_VARIABLE '[' encaps_var_offset ']' | T_VARIABLE '[' encaps_var_offset ']'
{ {
identifier := &ast.Identifier{ $$ = &ast.ExprArrayDimFetch{
Node: ast.Node{ Node: ast.Node{
Position: position.NewTokenPosition($1), Position: position.NewTokensPosition($1, $4),
}, },
IdentifierTkn: $1, Var: &ast.ExprVariable{
Value: $1.Value, Node: ast.Node{
Position: position.NewTokenPosition($1),
},
VarName: &ast.Identifier{
Node: ast.Node{
Position: position.NewTokenPosition($1),
},
IdentifierTkn: $1,
Value: $1.Value,
},
},
OpenBracketTkn: $2,
Dim: $3,
CloseBracketTkn: $4,
} }
variable := &ast.ExprVariable{ast.Node{}, identifier}
$$ = &ast.ExprArrayDimFetch{ast.Node{}, variable, $3}
// save position
variable.GetNode().Position = position.NewTokenPosition($1)
$$.GetNode().Position = position.NewTokensPosition($1, $4)
// save comments
yylex.(*Parser).setFreeFloatingTokens($$, token.Var, $2.SkippedTokens)
yylex.(*Parser).setFreeFloatingTokens($$, token.Expr, $4.SkippedTokens)
} }
| T_VARIABLE T_OBJECT_OPERATOR T_STRING | T_VARIABLE T_OBJECT_OPERATOR T_STRING
{ {
@ -4760,25 +4771,28 @@ encaps_var:
} }
| T_DOLLAR_OPEN_CURLY_BRACES T_STRING_VARNAME '[' expr ']' '}' | T_DOLLAR_OPEN_CURLY_BRACES T_STRING_VARNAME '[' expr ']' '}'
{ {
identifier := &ast.Identifier{ $$ = &ast.ExprArrayDimFetch{
Node: ast.Node{ Node: ast.Node{
Position: position.NewTokenPosition($2), Position: position.NewTokensPosition($1, $6),
}, },
IdentifierTkn: $2, OpenCurlyBracketTkn: $1,
Value: $2.Value, 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,
},
},
OpenBracketTkn: $3,
Dim: $4,
CloseBracketTkn: $5,
CloseCurlyBracketTkn: $6,
} }
variable := &ast.ExprVariable{ast.Node{}, identifier}
$$ = &ast.ExprArrayDimFetch{ast.Node{}, variable, $4}
// save position
variable.GetNode().Position = position.NewTokenPosition($2)
$$.GetNode().Position = position.NewTokensPosition($1, $6)
// save comments
yylex.(*Parser).setToken(variable, token.Start, $1.SkippedTokens)
yylex.(*Parser).setFreeFloatingTokens($$, token.Var, $3.SkippedTokens)
yylex.(*Parser).setFreeFloatingTokens($$, token.Expr, $5.SkippedTokens)
yylex.(*Parser).setFreeFloatingTokens($$, token.End, $6.SkippedTokens)
} }
| T_CURLY_OPEN variable '}' | T_CURLY_OPEN variable '}'
{ {

View File

@ -953,8 +953,12 @@ func (n *ExprArray) Accept(v NodeVisitor) {
// ExprArrayDimFetch node // ExprArrayDimFetch node
type ExprArrayDimFetch struct { type ExprArrayDimFetch struct {
Node Node
Var Vertex Var Vertex
Dim Vertex OpenCurlyBracketTkn *token.Token
OpenBracketTkn *token.Token
Dim Vertex
CloseBracketTkn *token.Token
CloseCurlyBracketTkn *token.Token
} }
func (n *ExprArrayDimFetch) Accept(v NodeVisitor) { func (n *ExprArrayDimFetch) Accept(v NodeVisitor) {
@ -964,9 +968,10 @@ func (n *ExprArrayDimFetch) Accept(v NodeVisitor) {
// ExprArrayItem node // ExprArrayItem node
type ExprArrayItem struct { type ExprArrayItem struct {
Node Node
Unpack bool EllipsisTkn *token.Token
Key Vertex Key Vertex
Val Vertex DoubleArrowTkn *token.Token
Val Vertex
} }
func (n *ExprArrayItem) Accept(v NodeVisitor) { func (n *ExprArrayItem) Accept(v NodeVisitor) {

View File

@ -620,11 +620,6 @@ func (v *Dump) ExprArrayItem(n *ast.ExprArrayItem) {
v.printIndentIfNotSingle(v.indent - 1) v.printIndentIfNotSingle(v.indent - 1)
v.print("&ast.ExprArrayItem{\n") v.print("&ast.ExprArrayItem{\n")
v.printNode(n.GetNode()) v.printNode(n.GetNode())
if n.Unpack {
v.printIndent(v.indent)
v.print("Unpack: true,\n")
}
} }
func (v *Dump) ExprArrowFunction(n *ast.ExprArrowFunction) { func (v *Dump) ExprArrowFunction(n *ast.ExprArrowFunction) {

View File

@ -1369,7 +1369,7 @@ func (p *Printer) printExprArrayItem(n ast.Vertex) {
nn := n.(*ast.ExprArrayItem) nn := n.(*ast.ExprArrayItem)
p.printFreeFloating(nn, token.Start) p.printFreeFloating(nn, token.Start)
if nn.Unpack { if nn.EllipsisTkn != nil {
p.write([]byte("...")) p.write([]byte("..."))
} }