[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 1732 additions and 1656 deletions

1170
internal/php5/php5.go generated

File diff suppressed because it is too large Load Diff

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{
Position: position.NewTokensPosition($1, $4),
},
Var: &ast.ScalarString{
Node: ast.Node{ Node: ast.Node{
Position: position.NewTokenPosition($1), Position: position.NewTokenPosition($1),
}, },
StringTkn: $1, StringTkn: $1,
Value: $1.Value, 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,7 +5895,11 @@ assignment_list_element:
pairList.Items = nil pairList.Items = nil
} }
listNode := &ast.ExprList{ $$ = &ast.ExprArrayItem{
Node: ast.Node{
Position: position.NewTokensPosition($1, $4),
},
Val: &ast.ExprList{
Node: ast.Node{ Node: ast.Node{
Position: position.NewTokensPosition($1, $4), Position: position.NewTokensPosition($1, $4),
}, },
@ -5887,21 +5908,12 @@ assignment_list_element:
Items: $3.(*ast.ParserSeparatedList).Items, Items: $3.(*ast.ParserSeparatedList).Items,
SeparatorTkns: $3.(*ast.ParserSeparatedList).SeparatorTkns, SeparatorTkns: $3.(*ast.ParserSeparatedList).SeparatorTkns,
CloseBracketTkn: $4, 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{
Position: position.NewTokensPosition($1, $4),
},
Var: &ast.ExprVariable{
Node: ast.Node{
Position: position.NewTokenPosition($1),
},
VarName: &ast.Identifier{
Node: ast.Node{ Node: ast.Node{
Position: position.NewTokenPosition($1), Position: position.NewTokenPosition($1),
}, },
IdentifierTkn: $1, IdentifierTkn: $1,
Value: $1.Value, 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{
Position: position.NewTokensPosition($1, $6),
},
OpenCurlyBracketTkn: $1,
Var: &ast.ExprVariable{
Node: ast.Node{
Position: position.NewTokenPosition($2),
},
VarName: &ast.Identifier{
Node: ast.Node{ Node: ast.Node{
Position: position.NewTokenPosition($2), Position: position.NewTokenPosition($2),
}, },
IdentifierTkn: $2, IdentifierTkn: $2,
Value: $2.Value, 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 '}'
{ {

378
internal/php7/php7.go generated
View File

@ -344,7 +344,7 @@ const yyEofCode = 1
const yyErrCode = 2 const yyErrCode = 2
const yyInitialStackSize = 16 const yyInitialStackSize = 16
// line internal/php7/php7.y:4992 // line internal/php7/php7.y:5006
// line yacctab:1 // line yacctab:1
var yyExca = [...]int{ var yyExca = [...]int{
@ -6879,44 +6879,47 @@ yydefault:
yyDollar = yyS[yypt-4 : yypt+1] yyDollar = yyS[yypt-4 : yypt+1]
// line internal/php7/php7.y:4238 // line internal/php7/php7.y:4238
{ {
yyVAL.node = &ast.ExprArrayDimFetch{ast.Node{}, yyDollar[1].node, yyDollar[3].node} yyVAL.node = &ast.ExprArrayDimFetch{
Node: ast.Node{
// save position Position: position.NewNodeTokenPosition(yyDollar[1].node, yyDollar[4].token),
yyVAL.node.GetNode().Position = position.NewNodeTokenPosition(yyDollar[1].node, yyDollar[4].token) },
Var: yyDollar[1].node,
// save comments OpenBracketTkn: yyDollar[2].token,
yylex.(*Parser).setFreeFloatingTokens(yyVAL.node, token.Var, yyDollar[2].token.SkippedTokens) Dim: yyDollar[3].node,
yylex.(*Parser).setFreeFloatingTokens(yyVAL.node, token.Expr, yyDollar[4].token.SkippedTokens) CloseBracketTkn: yyDollar[4].token,
}
} }
case 434: case 434:
yyDollar = yyS[yypt-4 : yypt+1] yyDollar = yyS[yypt-4 : yypt+1]
// line internal/php7/php7.y:4249 // line internal/php7/php7.y:4250
{ {
yyVAL.node = &ast.ExprArrayDimFetch{ast.Node{}, yyDollar[1].node, yyDollar[3].node} yyVAL.node = &ast.ExprArrayDimFetch{
Node: ast.Node{
// save position Position: position.NewNodeTokenPosition(yyDollar[1].node, yyDollar[4].token),
yyVAL.node.GetNode().Position = position.NewNodeTokenPosition(yyDollar[1].node, yyDollar[4].token) },
Var: yyDollar[1].node,
// save comments OpenBracketTkn: yyDollar[2].token,
yylex.(*Parser).setFreeFloatingTokens(yyVAL.node, token.Var, yyDollar[2].token.SkippedTokens) Dim: yyDollar[3].node,
yylex.(*Parser).setFreeFloatingTokens(yyVAL.node, token.Expr, yyDollar[4].token.SkippedTokens) CloseBracketTkn: yyDollar[4].token,
}
} }
case 435: case 435:
yyDollar = yyS[yypt-4 : yypt+1] yyDollar = yyS[yypt-4 : yypt+1]
// line internal/php7/php7.y:4260 // line internal/php7/php7.y:4262
{ {
yyVAL.node = &ast.ExprArrayDimFetch{ast.Node{}, yyDollar[1].node, yyDollar[3].node} yyVAL.node = &ast.ExprArrayDimFetch{
Node: ast.Node{
// save position Position: position.NewNodeTokenPosition(yyDollar[1].node, yyDollar[4].token),
yyVAL.node.GetNode().Position = position.NewNodeTokenPosition(yyDollar[1].node, yyDollar[4].token) },
Var: yyDollar[1].node,
// save comments OpenBracketTkn: yyDollar[2].token,
yylex.(*Parser).setFreeFloatingTokens(yyVAL.node, token.Var, yyDollar[2].token.SkippedTokens) Dim: yyDollar[3].node,
yylex.(*Parser).setFreeFloatingTokens(yyVAL.node, token.Expr, yyDollar[4].token.SkippedTokens) CloseBracketTkn: yyDollar[4].token,
}
} }
case 436: case 436:
yyDollar = yyS[yypt-4 : yypt+1] yyDollar = yyS[yypt-4 : yypt+1]
// line internal/php7/php7.y:4271 // line internal/php7/php7.y:4274
{ {
yyVAL.node = &ast.ExprMethodCall{ast.Node{}, yyDollar[1].node, yyDollar[3].node, yyDollar[4].node.(*ast.ArgumentList)} yyVAL.node = &ast.ExprMethodCall{ast.Node{}, yyDollar[1].node, yyDollar[3].node, yyDollar[4].node.(*ast.ArgumentList)}
@ -6929,25 +6932,25 @@ yydefault:
} }
case 437: case 437:
yyDollar = yyS[yypt-1 : yypt+1] yyDollar = yyS[yypt-1 : yypt+1]
// line internal/php7/php7.y:4282 // line internal/php7/php7.y:4285
{ {
yyVAL.node = yyDollar[1].node yyVAL.node = yyDollar[1].node
} }
case 438: case 438:
yyDollar = yyS[yypt-1 : yypt+1] yyDollar = yyS[yypt-1 : yypt+1]
// line internal/php7/php7.y:4289 // line internal/php7/php7.y:4292
{ {
yyVAL.node = yyDollar[1].node yyVAL.node = yyDollar[1].node
} }
case 439: case 439:
yyDollar = yyS[yypt-1 : yypt+1] yyDollar = yyS[yypt-1 : yypt+1]
// line internal/php7/php7.y:4293 // line internal/php7/php7.y:4296
{ {
yyVAL.node = yyDollar[1].node yyVAL.node = yyDollar[1].node
} }
case 440: case 440:
yyDollar = yyS[yypt-3 : yypt+1] yyDollar = yyS[yypt-3 : yypt+1]
// line internal/php7/php7.y:4297 // line internal/php7/php7.y:4300
{ {
yyVAL.node = &ast.ExprPropertyFetch{ast.Node{}, yyDollar[1].node, yyDollar[3].node} yyVAL.node = &ast.ExprPropertyFetch{ast.Node{}, yyDollar[1].node, yyDollar[3].node}
@ -6960,7 +6963,7 @@ yydefault:
} }
case 441: case 441:
yyDollar = yyS[yypt-1 : yypt+1] yyDollar = yyS[yypt-1 : yypt+1]
// line internal/php7/php7.y:4311 // line internal/php7/php7.y:4314
{ {
name := &ast.Identifier{ name := &ast.Identifier{
Node: ast.Node{ Node: ast.Node{
@ -6979,7 +6982,7 @@ yydefault:
} }
case 442: case 442:
yyDollar = yyS[yypt-4 : yypt+1] yyDollar = yyS[yypt-4 : yypt+1]
// line internal/php7/php7.y:4328 // line internal/php7/php7.y:4331
{ {
yyVAL.node = &ast.ExprVariable{ast.Node{}, yyDollar[3].node} yyVAL.node = &ast.ExprVariable{ast.Node{}, yyDollar[3].node}
@ -6993,7 +6996,7 @@ yydefault:
} }
case 443: case 443:
yyDollar = yyS[yypt-2 : yypt+1] yyDollar = yyS[yypt-2 : yypt+1]
// line internal/php7/php7.y:4340 // line internal/php7/php7.y:4343
{ {
yyVAL.node = &ast.ExprVariable{ast.Node{}, yyDollar[2].node} yyVAL.node = &ast.ExprVariable{ast.Node{}, yyDollar[2].node}
@ -7005,7 +7008,7 @@ yydefault:
} }
case 444: case 444:
yyDollar = yyS[yypt-3 : yypt+1] yyDollar = yyS[yypt-3 : yypt+1]
// line internal/php7/php7.y:4353 // line internal/php7/php7.y:4356
{ {
yyVAL.node = &ast.ExprStaticPropertyFetch{ast.Node{}, yyDollar[1].node, yyDollar[3].node} yyVAL.node = &ast.ExprStaticPropertyFetch{ast.Node{}, yyDollar[1].node, yyDollar[3].node}
@ -7018,7 +7021,7 @@ yydefault:
} }
case 445: case 445:
yyDollar = yyS[yypt-3 : yypt+1] yyDollar = yyS[yypt-3 : yypt+1]
// line internal/php7/php7.y:4364 // line internal/php7/php7.y:4367
{ {
yyVAL.node = &ast.ExprStaticPropertyFetch{ast.Node{}, yyDollar[1].node, yyDollar[3].node} yyVAL.node = &ast.ExprStaticPropertyFetch{ast.Node{}, yyDollar[1].node, yyDollar[3].node}
@ -7031,39 +7034,41 @@ yydefault:
} }
case 446: case 446:
yyDollar = yyS[yypt-1 : yypt+1] yyDollar = yyS[yypt-1 : yypt+1]
// line internal/php7/php7.y:4378 // line internal/php7/php7.y:4381
{ {
yyVAL.node = yyDollar[1].node yyVAL.node = yyDollar[1].node
} }
case 447: case 447:
yyDollar = yyS[yypt-4 : yypt+1] yyDollar = yyS[yypt-4 : yypt+1]
// line internal/php7/php7.y:4382 // line internal/php7/php7.y:4385
{ {
yyVAL.node = &ast.ExprArrayDimFetch{ast.Node{}, yyDollar[1].node, yyDollar[3].node} yyVAL.node = &ast.ExprArrayDimFetch{
Node: ast.Node{
// save position Position: position.NewNodeTokenPosition(yyDollar[1].node, yyDollar[4].token),
yyVAL.node.GetNode().Position = position.NewNodeTokenPosition(yyDollar[1].node, yyDollar[4].token) },
Var: yyDollar[1].node,
// save comments OpenBracketTkn: yyDollar[2].token,
yylex.(*Parser).setFreeFloatingTokens(yyVAL.node, token.Var, yyDollar[2].token.SkippedTokens) Dim: yyDollar[3].node,
yylex.(*Parser).setFreeFloatingTokens(yyVAL.node, token.Expr, yyDollar[4].token.SkippedTokens) CloseBracketTkn: yyDollar[4].token,
}
} }
case 448: case 448:
yyDollar = yyS[yypt-4 : yypt+1] yyDollar = yyS[yypt-4 : yypt+1]
// line internal/php7/php7.y:4393 // line internal/php7/php7.y:4397
{ {
yyVAL.node = &ast.ExprArrayDimFetch{ast.Node{}, yyDollar[1].node, yyDollar[3].node} yyVAL.node = &ast.ExprArrayDimFetch{
Node: ast.Node{
// save position Position: position.NewNodeTokenPosition(yyDollar[1].node, yyDollar[4].token),
yyVAL.node.GetNode().Position = position.NewNodeTokenPosition(yyDollar[1].node, yyDollar[4].token) },
Var: yyDollar[1].node,
// save comments OpenBracketTkn: yyDollar[2].token,
yylex.(*Parser).setFreeFloatingTokens(yyVAL.node, token.Var, yyDollar[2].token.SkippedTokens) Dim: yyDollar[3].node,
yylex.(*Parser).setFreeFloatingTokens(yyVAL.node, token.Expr, yyDollar[4].token.SkippedTokens) CloseBracketTkn: yyDollar[4].token,
}
} }
case 449: case 449:
yyDollar = yyS[yypt-3 : yypt+1] yyDollar = yyS[yypt-3 : yypt+1]
// line internal/php7/php7.y:4404 // line internal/php7/php7.y:4409
{ {
yyVAL.node = &ast.ExprPropertyFetch{ast.Node{}, yyDollar[1].node, yyDollar[3].node} yyVAL.node = &ast.ExprPropertyFetch{ast.Node{}, yyDollar[1].node, yyDollar[3].node}
@ -7076,7 +7081,7 @@ yydefault:
} }
case 450: case 450:
yyDollar = yyS[yypt-3 : yypt+1] yyDollar = yyS[yypt-3 : yypt+1]
// line internal/php7/php7.y:4415 // line internal/php7/php7.y:4420
{ {
yyVAL.node = &ast.ExprStaticPropertyFetch{ast.Node{}, yyDollar[1].node, yyDollar[3].node} yyVAL.node = &ast.ExprStaticPropertyFetch{ast.Node{}, yyDollar[1].node, yyDollar[3].node}
@ -7089,7 +7094,7 @@ yydefault:
} }
case 451: case 451:
yyDollar = yyS[yypt-3 : yypt+1] yyDollar = yyS[yypt-3 : yypt+1]
// line internal/php7/php7.y:4426 // line internal/php7/php7.y:4431
{ {
yyVAL.node = &ast.ExprStaticPropertyFetch{ast.Node{}, yyDollar[1].node, yyDollar[3].node} yyVAL.node = &ast.ExprStaticPropertyFetch{ast.Node{}, yyDollar[1].node, yyDollar[3].node}
@ -7102,7 +7107,7 @@ yydefault:
} }
case 452: case 452:
yyDollar = yyS[yypt-1 : yypt+1] yyDollar = yyS[yypt-1 : yypt+1]
// line internal/php7/php7.y:4440 // line internal/php7/php7.y:4445
{ {
yyVAL.node = &ast.Identifier{ yyVAL.node = &ast.Identifier{
Node: ast.Node{ Node: ast.Node{
@ -7114,7 +7119,7 @@ yydefault:
} }
case 453: case 453:
yyDollar = yyS[yypt-3 : yypt+1] yyDollar = yyS[yypt-3 : yypt+1]
// line internal/php7/php7.y:4450 // line internal/php7/php7.y:4455
{ {
yyVAL.node = yyDollar[2].node yyVAL.node = yyDollar[2].node
@ -7124,13 +7129,13 @@ yydefault:
} }
case 454: case 454:
yyDollar = yyS[yypt-1 : yypt+1] yyDollar = yyS[yypt-1 : yypt+1]
// line internal/php7/php7.y:4458 // line internal/php7/php7.y:4463
{ {
yyVAL.node = yyDollar[1].node yyVAL.node = yyDollar[1].node
} }
case 455: case 455:
yyDollar = yyS[yypt-1 : yypt+1] yyDollar = yyS[yypt-1 : yypt+1]
// line internal/php7/php7.y:4465 // line internal/php7/php7.y:4470
{ {
yyVAL.node = &ast.Identifier{ yyVAL.node = &ast.Identifier{
Node: ast.Node{ Node: ast.Node{
@ -7142,7 +7147,7 @@ yydefault:
} }
case 456: case 456:
yyDollar = yyS[yypt-3 : yypt+1] yyDollar = yyS[yypt-3 : yypt+1]
// line internal/php7/php7.y:4475 // line internal/php7/php7.y:4480
{ {
yyVAL.node = yyDollar[2].node yyVAL.node = yyDollar[2].node
@ -7152,13 +7157,13 @@ yydefault:
} }
case 457: case 457:
yyDollar = yyS[yypt-1 : yypt+1] yyDollar = yyS[yypt-1 : yypt+1]
// line internal/php7/php7.y:4483 // line internal/php7/php7.y:4488
{ {
yyVAL.node = yyDollar[1].node yyVAL.node = yyDollar[1].node
} }
case 458: case 458:
yyDollar = yyS[yypt-1 : yypt+1] yyDollar = yyS[yypt-1 : yypt+1]
// line internal/php7/php7.y:4490 // line internal/php7/php7.y:4495
{ {
pairList := yyDollar[1].node.(*ast.ParserSeparatedList) pairList := yyDollar[1].node.(*ast.ParserSeparatedList)
fistPair := pairList.Items[0].(*ast.ExprArrayItem) fistPair := pairList.Items[0].(*ast.ExprArrayItem)
@ -7171,19 +7176,19 @@ yydefault:
} }
case 459: case 459:
yyDollar = yyS[yypt-0 : yypt+1] yyDollar = yyS[yypt-0 : yypt+1]
// line internal/php7/php7.y:4504 // line internal/php7/php7.y:4509
{ {
yyVAL.node = &ast.ExprArrayItem{} yyVAL.node = &ast.ExprArrayItem{}
} }
case 460: case 460:
yyDollar = yyS[yypt-1 : yypt+1] yyDollar = yyS[yypt-1 : yypt+1]
// line internal/php7/php7.y:4508 // line internal/php7/php7.y:4513
{ {
yyVAL.node = yyDollar[1].node yyVAL.node = yyDollar[1].node
} }
case 461: case 461:
yyDollar = yyS[yypt-3 : yypt+1] yyDollar = yyS[yypt-3 : yypt+1]
// line internal/php7/php7.y:4515 // line internal/php7/php7.y:4520
{ {
yyDollar[1].node.(*ast.ParserSeparatedList).SeparatorTkns = append(yyDollar[1].node.(*ast.ParserSeparatedList).SeparatorTkns, yyDollar[2].token) yyDollar[1].node.(*ast.ParserSeparatedList).SeparatorTkns = append(yyDollar[1].node.(*ast.ParserSeparatedList).SeparatorTkns, yyDollar[2].token)
yyDollar[1].node.(*ast.ParserSeparatedList).Items = append(yyDollar[1].node.(*ast.ParserSeparatedList).Items, yyDollar[3].node) yyDollar[1].node.(*ast.ParserSeparatedList).Items = append(yyDollar[1].node.(*ast.ParserSeparatedList).Items, yyDollar[3].node)
@ -7192,7 +7197,7 @@ yydefault:
} }
case 462: case 462:
yyDollar = yyS[yypt-1 : yypt+1] yyDollar = yyS[yypt-1 : yypt+1]
// line internal/php7/php7.y:4522 // line internal/php7/php7.y:4527
{ {
yyVAL.node = &ast.ParserSeparatedList{ yyVAL.node = &ast.ParserSeparatedList{
Items: []ast.Vertex{yyDollar[1].node}, Items: []ast.Vertex{yyDollar[1].node},
@ -7200,76 +7205,85 @@ yydefault:
} }
case 463: case 463:
yyDollar = yyS[yypt-3 : yypt+1] yyDollar = yyS[yypt-3 : yypt+1]
// line internal/php7/php7.y:4531 // line internal/php7/php7.y:4536
{ {
yyVAL.node = &ast.ExprArrayItem{ast.Node{}, false, yyDollar[1].node, yyDollar[3].node} yyVAL.node = &ast.ExprArrayItem{
Node: ast.Node{
// save position Position: position.NewNodesPosition(yyDollar[1].node, yyDollar[3].node),
yyVAL.node.GetNode().Position = position.NewNodesPosition(yyDollar[1].node, yyDollar[3].node) },
Key: yyDollar[1].node,
// save comments DoubleArrowTkn: yyDollar[2].token,
yylex.(*Parser).MoveFreeFloating(yyDollar[1].node, yyVAL.node) Val: yyDollar[3].node,
yylex.(*Parser).setFreeFloating(yyVAL.node, token.Expr, yyDollar[2].token.SkippedTokens) }
} }
case 464: case 464:
yyDollar = yyS[yypt-1 : yypt+1] yyDollar = yyS[yypt-1 : yypt+1]
// line internal/php7/php7.y:4542 // line internal/php7/php7.y:4547
{ {
yyVAL.node = &ast.ExprArrayItem{ast.Node{}, false, nil, yyDollar[1].node} yyVAL.node = &ast.ExprArrayItem{
Node: ast.Node{
// save position Position: position.NewNodePosition(yyDollar[1].node),
yyVAL.node.GetNode().Position = position.NewNodePosition(yyDollar[1].node) },
Val: yyDollar[1].node,
// save comments }
yylex.(*Parser).MoveFreeFloating(yyDollar[1].node, yyVAL.node)
} }
case 465: case 465:
yyDollar = yyS[yypt-4 : yypt+1] yyDollar = yyS[yypt-4 : yypt+1]
// line internal/php7/php7.y:4552 // line internal/php7/php7.y:4556
{ {
reference := &ast.ExprReference{ast.Node{}, yyDollar[4].node} yyVAL.node = &ast.ExprArrayItem{
yyVAL.node = &ast.ExprArrayItem{ast.Node{}, false, yyDollar[1].node, reference} Node: ast.Node{
Position: position.NewNodesPosition(yyDollar[1].node, yyDollar[4].node),
// save position },
yyVAL.node.GetNode().Position = position.NewNodesPosition(yyDollar[1].node, yyDollar[4].node) Key: yyDollar[1].node,
reference.GetNode().Position = position.NewTokenNodePosition(yyDollar[3].token, yyDollar[4].node) DoubleArrowTkn: yyDollar[2].token,
Val: &ast.ExprReference{
// save comments Node: ast.Node{
yylex.(*Parser).MoveFreeFloating(yyDollar[1].node, yyVAL.node) Position: position.NewTokenNodePosition(yyDollar[3].token, yyDollar[4].node),
yylex.(*Parser).setFreeFloating(yyVAL.node, token.Expr, yyDollar[2].token.SkippedTokens) },
yylex.(*Parser).setFreeFloating(reference, token.Start, yyDollar[3].token.SkippedTokens) Var: yyDollar[4].node,
},
}
} }
case 466: case 466:
yyDollar = yyS[yypt-2 : yypt+1] yyDollar = yyS[yypt-2 : yypt+1]
// line internal/php7/php7.y:4566 // line internal/php7/php7.y:4572
{ {
reference := &ast.ExprReference{ast.Node{}, yyDollar[2].node} yyVAL.node = &ast.ExprArrayItem{
yyVAL.node = &ast.ExprArrayItem{ast.Node{}, false, nil, reference} Node: ast.Node{
Position: position.NewTokenNodePosition(yyDollar[1].token, yyDollar[2].node),
// save position },
yyVAL.node.GetNode().Position = position.NewTokenNodePosition(yyDollar[1].token, yyDollar[2].node) Val: &ast.ExprReference{
reference.GetNode().Position = position.NewTokenNodePosition(yyDollar[1].token, yyDollar[2].node) Node: ast.Node{
Position: position.NewTokenNodePosition(yyDollar[1].token, yyDollar[2].node),
// save comments },
yylex.(*Parser).setFreeFloating(yyVAL.node, token.Start, yyDollar[1].token.SkippedTokens) Var: yyDollar[2].node,
},
}
} }
case 467: case 467:
yyDollar = yyS[yypt-2 : yypt+1] yyDollar = yyS[yypt-2 : yypt+1]
// line internal/php7/php7.y:4578 // line internal/php7/php7.y:4586
{ {
yyVAL.node = &ast.ExprArrayItem{ast.Node{}, true, nil, yyDollar[2].node} yyVAL.node = &ast.ExprArrayItem{
Node: ast.Node{
// save position Position: position.NewTokenNodePosition(yyDollar[1].token, yyDollar[2].node),
yyVAL.node.GetNode().Position = position.NewTokenNodePosition(yyDollar[1].token, yyDollar[2].node) },
EllipsisTkn: yyDollar[1].token,
// save comments Val: yyDollar[2].node,
yylex.(*Parser).setFreeFloating(yyVAL.node, token.Start, yyDollar[1].token.SkippedTokens) }
} }
case 468: case 468:
yyDollar = yyS[yypt-6 : yypt+1] yyDollar = yyS[yypt-6 : yypt+1]
// line internal/php7/php7.y:4588 // line internal/php7/php7.y:4596
{ {
listNode := &ast.ExprList{ yyVAL.node = &ast.ExprArrayItem{
Node: ast.Node{
Position: position.NewNodeTokenPosition(yyDollar[1].node, yyDollar[6].token),
},
Key: yyDollar[1].node,
DoubleArrowTkn: yyDollar[2].token,
Val: &ast.ExprList{
Node: ast.Node{ Node: ast.Node{
Position: position.NewTokensPosition(yyDollar[3].token, yyDollar[6].token), Position: position.NewTokensPosition(yyDollar[3].token, yyDollar[6].token),
}, },
@ -7278,21 +7292,18 @@ yydefault:
Items: yyDollar[5].node.(*ast.ParserSeparatedList).Items, Items: yyDollar[5].node.(*ast.ParserSeparatedList).Items,
SeparatorTkns: yyDollar[5].node.(*ast.ParserSeparatedList).SeparatorTkns, SeparatorTkns: yyDollar[5].node.(*ast.ParserSeparatedList).SeparatorTkns,
CloseBracketTkn: yyDollar[6].token, CloseBracketTkn: yyDollar[6].token,
},
} }
yyVAL.node = &ast.ExprArrayItem{ast.Node{}, false, yyDollar[1].node, listNode}
// save position
yyVAL.node.GetNode().Position = position.NewNodeTokenPosition(yyDollar[1].node, yyDollar[6].token)
// save comments
yylex.(*Parser).MoveFreeFloating(yyDollar[1].node, yyVAL.node)
yylex.(*Parser).setFreeFloating(yyVAL.node, token.Expr, yyDollar[2].token.SkippedTokens)
} }
case 469: case 469:
yyDollar = yyS[yypt-4 : yypt+1] yyDollar = yyS[yypt-4 : yypt+1]
// line internal/php7/php7.y:4609 // line internal/php7/php7.y:4616
{ {
listNode := &ast.ExprList{ yyVAL.node = &ast.ExprArrayItem{
Node: ast.Node{
Position: position.NewTokensPosition(yyDollar[1].token, yyDollar[4].token),
},
Val: &ast.ExprList{
Node: ast.Node{ Node: ast.Node{
Position: position.NewTokensPosition(yyDollar[1].token, yyDollar[4].token), Position: position.NewTokensPosition(yyDollar[1].token, yyDollar[4].token),
}, },
@ -7301,21 +7312,18 @@ yydefault:
Items: yyDollar[3].node.(*ast.ParserSeparatedList).Items, Items: yyDollar[3].node.(*ast.ParserSeparatedList).Items,
SeparatorTkns: yyDollar[3].node.(*ast.ParserSeparatedList).SeparatorTkns, SeparatorTkns: yyDollar[3].node.(*ast.ParserSeparatedList).SeparatorTkns,
CloseBracketTkn: yyDollar[4].token, CloseBracketTkn: yyDollar[4].token,
},
} }
yyVAL.node = &ast.ExprArrayItem{ast.Node{}, false, nil, listNode}
// save position
yyVAL.node.GetNode().Position = position.NewTokensPosition(yyDollar[1].token, yyDollar[4].token)
} }
case 470: case 470:
yyDollar = yyS[yypt-2 : yypt+1] yyDollar = yyS[yypt-2 : yypt+1]
// line internal/php7/php7.y:4629 // line internal/php7/php7.y:4637
{ {
yyVAL.list = append(yyDollar[1].list, yyDollar[2].node) yyVAL.list = append(yyDollar[1].list, yyDollar[2].node)
} }
case 471: case 471:
yyDollar = yyS[yypt-2 : yypt+1] yyDollar = yyS[yypt-2 : yypt+1]
// line internal/php7/php7.y:4633 // line internal/php7/php7.y:4641
{ {
yyVAL.list = append( yyVAL.list = append(
yyDollar[1].list, yyDollar[1].list,
@ -7330,13 +7338,13 @@ yydefault:
} }
case 472: case 472:
yyDollar = yyS[yypt-1 : yypt+1] yyDollar = yyS[yypt-1 : yypt+1]
// line internal/php7/php7.y:4646 // line internal/php7/php7.y:4654
{ {
yyVAL.list = []ast.Vertex{yyDollar[1].node} yyVAL.list = []ast.Vertex{yyDollar[1].node}
} }
case 473: case 473:
yyDollar = yyS[yypt-2 : yypt+1] yyDollar = yyS[yypt-2 : yypt+1]
// line internal/php7/php7.y:4650 // line internal/php7/php7.y:4658
{ {
yyVAL.list = []ast.Vertex{ yyVAL.list = []ast.Vertex{
&ast.ScalarEncapsedStringPart{ &ast.ScalarEncapsedStringPart{
@ -7351,7 +7359,7 @@ yydefault:
} }
case 474: case 474:
yyDollar = yyS[yypt-1 : yypt+1] yyDollar = yyS[yypt-1 : yypt+1]
// line internal/php7/php7.y:4666 // line internal/php7/php7.y:4674
{ {
name := &ast.Identifier{ name := &ast.Identifier{
Node: ast.Node{ Node: ast.Node{
@ -7370,29 +7378,32 @@ yydefault:
} }
case 475: case 475:
yyDollar = yyS[yypt-4 : yypt+1] yyDollar = yyS[yypt-4 : yypt+1]
// line internal/php7/php7.y:4683 // line internal/php7/php7.y:4691
{ {
identifier := &ast.Identifier{ yyVAL.node = &ast.ExprArrayDimFetch{
Node: ast.Node{
Position: position.NewTokensPosition(yyDollar[1].token, yyDollar[4].token),
},
Var: &ast.ExprVariable{
Node: ast.Node{
Position: position.NewTokenPosition(yyDollar[1].token),
},
VarName: &ast.Identifier{
Node: ast.Node{ Node: ast.Node{
Position: position.NewTokenPosition(yyDollar[1].token), Position: position.NewTokenPosition(yyDollar[1].token),
}, },
IdentifierTkn: yyDollar[1].token, IdentifierTkn: yyDollar[1].token,
Value: yyDollar[1].token.Value, Value: yyDollar[1].token.Value,
},
},
OpenBracketTkn: yyDollar[2].token,
Dim: yyDollar[3].node,
CloseBracketTkn: yyDollar[4].token,
} }
variable := &ast.ExprVariable{ast.Node{}, identifier}
yyVAL.node = &ast.ExprArrayDimFetch{ast.Node{}, variable, yyDollar[3].node}
// save position
variable.GetNode().Position = position.NewTokenPosition(yyDollar[1].token)
yyVAL.node.GetNode().Position = position.NewTokensPosition(yyDollar[1].token, yyDollar[4].token)
// save comments
yylex.(*Parser).setFreeFloatingTokens(yyVAL.node, token.Var, yyDollar[2].token.SkippedTokens)
yylex.(*Parser).setFreeFloatingTokens(yyVAL.node, token.Expr, yyDollar[4].token.SkippedTokens)
} }
case 476: case 476:
yyDollar = yyS[yypt-3 : yypt+1] yyDollar = yyS[yypt-3 : yypt+1]
// line internal/php7/php7.y:4703 // line internal/php7/php7.y:4714
{ {
identifier := &ast.Identifier{ identifier := &ast.Identifier{
Node: ast.Node{ Node: ast.Node{
@ -7420,7 +7431,7 @@ yydefault:
} }
case 477: case 477:
yyDollar = yyS[yypt-3 : yypt+1] yyDollar = yyS[yypt-3 : yypt+1]
// line internal/php7/php7.y:4729 // line internal/php7/php7.y:4740
{ {
variable := &ast.ExprVariable{ast.Node{}, yyDollar[2].node} variable := &ast.ExprVariable{ast.Node{}, yyDollar[2].node}
@ -7435,7 +7446,7 @@ yydefault:
} }
case 478: case 478:
yyDollar = yyS[yypt-3 : yypt+1] yyDollar = yyS[yypt-3 : yypt+1]
// line internal/php7/php7.y:4742 // line internal/php7/php7.y:4753
{ {
name := &ast.Identifier{ name := &ast.Identifier{
Node: ast.Node{ Node: ast.Node{
@ -7457,31 +7468,34 @@ yydefault:
} }
case 479: case 479:
yyDollar = yyS[yypt-6 : yypt+1] yyDollar = yyS[yypt-6 : yypt+1]
// line internal/php7/php7.y:4762 // line internal/php7/php7.y:4773
{ {
identifier := &ast.Identifier{ yyVAL.node = &ast.ExprArrayDimFetch{
Node: ast.Node{
Position: position.NewTokensPosition(yyDollar[1].token, yyDollar[6].token),
},
OpenCurlyBracketTkn: yyDollar[1].token,
Var: &ast.ExprVariable{
Node: ast.Node{
Position: position.NewTokenPosition(yyDollar[2].token),
},
VarName: &ast.Identifier{
Node: ast.Node{ Node: ast.Node{
Position: position.NewTokenPosition(yyDollar[2].token), Position: position.NewTokenPosition(yyDollar[2].token),
}, },
IdentifierTkn: yyDollar[2].token, IdentifierTkn: yyDollar[2].token,
Value: yyDollar[2].token.Value, Value: yyDollar[2].token.Value,
},
},
OpenBracketTkn: yyDollar[3].token,
Dim: yyDollar[4].node,
CloseBracketTkn: yyDollar[5].token,
CloseCurlyBracketTkn: yyDollar[6].token,
} }
variable := &ast.ExprVariable{ast.Node{}, identifier}
yyVAL.node = &ast.ExprArrayDimFetch{ast.Node{}, variable, yyDollar[4].node}
// save position
variable.GetNode().Position = position.NewTokenPosition(yyDollar[2].token)
yyVAL.node.GetNode().Position = position.NewTokensPosition(yyDollar[1].token, yyDollar[6].token)
// save comments
yylex.(*Parser).setToken(variable, token.Start, yyDollar[1].token.SkippedTokens)
yylex.(*Parser).setFreeFloatingTokens(yyVAL.node, token.Var, yyDollar[3].token.SkippedTokens)
yylex.(*Parser).setFreeFloatingTokens(yyVAL.node, token.Expr, yyDollar[5].token.SkippedTokens)
yylex.(*Parser).setFreeFloatingTokens(yyVAL.node, token.End, yyDollar[6].token.SkippedTokens)
} }
case 480: case 480:
yyDollar = yyS[yypt-3 : yypt+1] yyDollar = yyS[yypt-3 : yypt+1]
// line internal/php7/php7.y:4784 // line internal/php7/php7.y:4798
{ {
yyVAL.node = yyDollar[2].node yyVAL.node = yyDollar[2].node
@ -7491,7 +7505,7 @@ yydefault:
} }
case 481: case 481:
yyDollar = yyS[yypt-1 : yypt+1] yyDollar = yyS[yypt-1 : yypt+1]
// line internal/php7/php7.y:4795 // line internal/php7/php7.y:4809
{ {
yyVAL.node = &ast.ScalarString{ yyVAL.node = &ast.ScalarString{
Node: ast.Node{ Node: ast.Node{
@ -7503,7 +7517,7 @@ yydefault:
} }
case 482: case 482:
yyDollar = yyS[yypt-1 : yypt+1] yyDollar = yyS[yypt-1 : yypt+1]
// line internal/php7/php7.y:4805 // line internal/php7/php7.y:4819
{ {
// TODO: add option to handle 64 bit integer // TODO: add option to handle 64 bit integer
if _, err := strconv.Atoi(string(yyDollar[1].token.Value)); err == nil { if _, err := strconv.Atoi(string(yyDollar[1].token.Value)); err == nil {
@ -7526,7 +7540,7 @@ yydefault:
} }
case 483: case 483:
yyDollar = yyS[yypt-2 : yypt+1] yyDollar = yyS[yypt-2 : yypt+1]
// line internal/php7/php7.y:4826 // line internal/php7/php7.y:4840
{ {
_, err := strconv.Atoi(string(yyDollar[2].token.Value)) _, err := strconv.Atoi(string(yyDollar[2].token.Value))
isInt := err == nil isInt := err == nil
@ -7554,7 +7568,7 @@ yydefault:
} }
case 484: case 484:
yyDollar = yyS[yypt-1 : yypt+1] yyDollar = yyS[yypt-1 : yypt+1]
// line internal/php7/php7.y:4852 // line internal/php7/php7.y:4866
{ {
identifier := &ast.Identifier{ identifier := &ast.Identifier{
Node: ast.Node{ Node: ast.Node{
@ -7573,7 +7587,7 @@ yydefault:
} }
case 485: case 485:
yyDollar = yyS[yypt-5 : yypt+1] yyDollar = yyS[yypt-5 : yypt+1]
// line internal/php7/php7.y:4872 // line internal/php7/php7.y:4886
{ {
yyVAL.node = &ast.ExprIsset{ast.Node{}, yyDollar[3].list} yyVAL.node = &ast.ExprIsset{ast.Node{}, yyDollar[3].list}
@ -7591,7 +7605,7 @@ yydefault:
} }
case 486: case 486:
yyDollar = yyS[yypt-4 : yypt+1] yyDollar = yyS[yypt-4 : yypt+1]
// line internal/php7/php7.y:4888 // line internal/php7/php7.y:4902
{ {
exprBrackets := &ast.ParserBrackets{ exprBrackets := &ast.ParserBrackets{
Node: ast.Node{ Node: ast.Node{
@ -7613,7 +7627,7 @@ yydefault:
} }
case 487: case 487:
yyDollar = yyS[yypt-2 : yypt+1] yyDollar = yyS[yypt-2 : yypt+1]
// line internal/php7/php7.y:4908 // line internal/php7/php7.y:4922
{ {
yyVAL.node = &ast.ExprInclude{ast.Node{}, yyDollar[2].node} yyVAL.node = &ast.ExprInclude{ast.Node{}, yyDollar[2].node}
@ -7625,7 +7639,7 @@ yydefault:
} }
case 488: case 488:
yyDollar = yyS[yypt-2 : yypt+1] yyDollar = yyS[yypt-2 : yypt+1]
// line internal/php7/php7.y:4918 // line internal/php7/php7.y:4932
{ {
yyVAL.node = &ast.ExprIncludeOnce{ast.Node{}, yyDollar[2].node} yyVAL.node = &ast.ExprIncludeOnce{ast.Node{}, yyDollar[2].node}
@ -7637,7 +7651,7 @@ yydefault:
} }
case 489: case 489:
yyDollar = yyS[yypt-4 : yypt+1] yyDollar = yyS[yypt-4 : yypt+1]
// line internal/php7/php7.y:4928 // line internal/php7/php7.y:4942
{ {
exprBrackets := &ast.ParserBrackets{ exprBrackets := &ast.ParserBrackets{
Node: ast.Node{ Node: ast.Node{
@ -7659,7 +7673,7 @@ yydefault:
} }
case 490: case 490:
yyDollar = yyS[yypt-2 : yypt+1] yyDollar = yyS[yypt-2 : yypt+1]
// line internal/php7/php7.y:4948 // line internal/php7/php7.y:4962
{ {
yyVAL.node = &ast.ExprRequire{ast.Node{}, yyDollar[2].node} yyVAL.node = &ast.ExprRequire{ast.Node{}, yyDollar[2].node}
@ -7671,7 +7685,7 @@ yydefault:
} }
case 491: case 491:
yyDollar = yyS[yypt-2 : yypt+1] yyDollar = yyS[yypt-2 : yypt+1]
// line internal/php7/php7.y:4958 // line internal/php7/php7.y:4972
{ {
yyVAL.node = &ast.ExprRequireOnce{ast.Node{}, yyDollar[2].node} yyVAL.node = &ast.ExprRequireOnce{ast.Node{}, yyDollar[2].node}
@ -7683,13 +7697,13 @@ yydefault:
} }
case 492: case 492:
yyDollar = yyS[yypt-1 : yypt+1] yyDollar = yyS[yypt-1 : yypt+1]
// line internal/php7/php7.y:4971 // line internal/php7/php7.y:4985
{ {
yyVAL.list = []ast.Vertex{yyDollar[1].node} yyVAL.list = []ast.Vertex{yyDollar[1].node}
} }
case 493: case 493:
yyDollar = yyS[yypt-3 : yypt+1] yyDollar = yyS[yypt-3 : yypt+1]
// line internal/php7/php7.y:4975 // line internal/php7/php7.y:4989
{ {
yyVAL.list = append(yyDollar[1].list, yyDollar[3].node) yyVAL.list = append(yyDollar[1].list, yyDollar[3].node)
@ -7698,7 +7712,7 @@ yydefault:
} }
case 494: case 494:
yyDollar = yyS[yypt-1 : yypt+1] yyDollar = yyS[yypt-1 : yypt+1]
// line internal/php7/php7.y:4985 // line internal/php7/php7.y:4999
{ {
yyVAL.node = yyDollar[1].node yyVAL.node = yyDollar[1].node
} }

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,64 +4534,73 @@ 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{
Position: position.NewNodeTokenPosition($1, $6),
},
Key: $1,
DoubleArrowTkn: $2,
Val: &ast.ExprList{
Node: ast.Node{ Node: ast.Node{
Position: position.NewTokensPosition($3, $6), Position: position.NewTokensPosition($3, $6),
}, },
@ -4595,19 +4609,16 @@ array_pair:
Items: $5.(*ast.ParserSeparatedList).Items, Items: $5.(*ast.ParserSeparatedList).Items,
SeparatorTkns: $5.(*ast.ParserSeparatedList).SeparatorTkns, SeparatorTkns: $5.(*ast.ParserSeparatedList).SeparatorTkns,
CloseBracketTkn: $6, 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{
Position: position.NewTokensPosition($1, $4),
},
Val: &ast.ExprList{
Node: ast.Node{ Node: ast.Node{
Position: position.NewTokensPosition($1, $4), Position: position.NewTokensPosition($1, $4),
}, },
@ -4616,11 +4627,8 @@ array_pair:
Items: $3.(*ast.ParserSeparatedList).Items, Items: $3.(*ast.ParserSeparatedList).Items,
SeparatorTkns: $3.(*ast.ParserSeparatedList).SeparatorTkns, SeparatorTkns: $3.(*ast.ParserSeparatedList).SeparatorTkns,
CloseBracketTkn: $4, 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{
Position: position.NewTokensPosition($1, $4),
},
Var: &ast.ExprVariable{
Node: ast.Node{
Position: position.NewTokenPosition($1),
},
VarName: &ast.Identifier{
Node: ast.Node{ Node: ast.Node{
Position: position.NewTokenPosition($1), Position: position.NewTokenPosition($1),
}, },
IdentifierTkn: $1, IdentifierTkn: $1,
Value: $1.Value, 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{
Position: position.NewTokensPosition($1, $6),
},
OpenCurlyBracketTkn: $1,
Var: &ast.ExprVariable{
Node: ast.Node{
Position: position.NewTokenPosition($2),
},
VarName: &ast.Identifier{
Node: ast.Node{ Node: ast.Node{
Position: position.NewTokenPosition($2), Position: position.NewTokenPosition($2),
}, },
IdentifierTkn: $2, IdentifierTkn: $2,
Value: $2.Value, 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

@ -954,7 +954,11 @@ func (n *ExprArray) Accept(v NodeVisitor) {
type ExprArrayDimFetch struct { type ExprArrayDimFetch struct {
Node Node
Var Vertex Var Vertex
OpenCurlyBracketTkn *token.Token
OpenBracketTkn *token.Token
Dim Vertex Dim Vertex
CloseBracketTkn *token.Token
CloseCurlyBracketTkn *token.Token
} }
func (n *ExprArrayDimFetch) Accept(v NodeVisitor) { func (n *ExprArrayDimFetch) Accept(v NodeVisitor) {
@ -964,8 +968,9 @@ 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
DoubleArrowTkn *token.Token
Val Vertex Val Vertex
} }

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("..."))
} }