[refactoring] update ast structure of "array" and "list" nodes

This commit is contained in:
Vadym Slizov 2020-11-30 23:42:56 +02:00
parent 43f6fab862
commit 47b974a3a4
No known key found for this signature in database
GPG Key ID: AEA2A9388EF42A4A
11 changed files with 267 additions and 286 deletions

BIN
internal/php5/php5.go generated

Binary file not shown.

View File

@ -238,9 +238,9 @@ import (
%type <node> trait_method_reference_fully_qualified trait_method_reference trait_modifiers member_modifier method
%type <node> static_scalar_value static_operation static_var_list global_var_list
%type <node> ctor_arguments function_call_parameter_list echo_expr_list class_variable_declaration
%type <node> trait_adaptations unset_variables declare_list
%type <node> switch_case_list non_empty_function_call_parameter_list
%type <node> method_body trait_reference_list
%type <node> trait_adaptations unset_variables declare_list non_empty_array_pair_list array_pair_list
%type <node> switch_case_list non_empty_function_call_parameter_list assignment_list
%type <node> method_body trait_reference_list static_array_pair_list non_empty_static_array_pair_list
%type <node> foreach_statement for_statement while_statement
%type <node> foreach_variable foreach_optional_arg
%type <node> extends_from interface_list trait_list
@ -249,13 +249,13 @@ import (
%type <ClosureUse> lexical_vars
%type <list> top_statement_list namespace_name use_declarations use_function_declarations use_const_declarations
%type <list> inner_statement_list encaps_list isset_variables non_empty_array_pair_list
%type <list> array_pair_list assignment_list lexical_var_list elseif_list new_elseif_list non_empty_for_expr
%type <list> inner_statement_list encaps_list isset_variables
%type <list> lexical_var_list elseif_list new_elseif_list non_empty_for_expr
%type <list> for_expr case_list catch_statement additional_catches
%type <list> non_empty_additional_catches parameter_list non_empty_parameter_list class_statement_list
%type <list> class_statement_list variable_modifiers method_modifiers
%type <list> trait_adaptation_list non_empty_trait_adaptation_list
%type <list> non_empty_member_modifiers backticks_expr static_array_pair_list non_empty_static_array_pair_list
%type <list> non_empty_member_modifiers backticks_expr
%type <list> chaining_dereference chaining_instance_call chaining_method_or_property instance_call variable_property
%type <list> method_or_not array_method_dereference object_property object_dim_list dynamic_class_name_variable_property
@ -1620,15 +1620,23 @@ foreach_variable:
}
| T_LIST '(' assignment_list ')'
{
$$ = &ast.ExprList{ast.Node{}, $3}
pairList := $3.(*ast.ParserSeparatedList)
fistPair := pairList.Items[0].(*ast.ExprArrayItem)
// save position
$$.GetNode().Position = position.NewTokensPosition($1, $4)
if fistPair.Key == nil && fistPair.Val == nil && len(pairList.Items) == 1 {
pairList.Items = nil
}
// save comments
yylex.(*Parser).setFreeFloating($$, token.Start, $1.SkippedTokens)
yylex.(*Parser).setFreeFloating($$, token.List, $2.SkippedTokens)
yylex.(*Parser).setFreeFloating($$, token.ArrayPairList, $4.SkippedTokens)
$$ = &ast.ExprList{
Node: ast.Node{
Position: position.NewTokensPosition($1, $4),
},
ListTkn: $1,
OpenBracketTkn: $2,
Items: $3.(*ast.ParserSeparatedList).Items,
SeparatorTkns: $3.(*ast.ParserSeparatedList).SeparatorTkns,
CloseBracketTkn: $4,
}
}
;
@ -3129,7 +3137,23 @@ new_expr:
expr_without_variable:
T_LIST '(' assignment_list ')' '=' expr
{
listNode := &ast.ExprList{ast.Node{}, $3}
pairList := $3.(*ast.ParserSeparatedList)
fistPair := pairList.Items[0].(*ast.ExprArrayItem)
if fistPair.Key == nil && fistPair.Val == nil && len(pairList.Items) == 1 {
pairList.Items = nil
}
listNode := &ast.ExprList{
Node: ast.Node{
Position: position.NewTokensPosition($1, $4),
},
ListTkn: $1,
OpenBracketTkn: $2,
Items: $3.(*ast.ParserSeparatedList).Items,
SeparatorTkns: $3.(*ast.ParserSeparatedList).SeparatorTkns,
CloseBracketTkn: $4,
}
$$ = &ast.ExprAssign{ast.Node{}, listNode, $6}
// save position
@ -4051,26 +4075,28 @@ combined_scalar_offset:
combined_scalar:
T_ARRAY '(' array_pair_list ')'
{
$$ = &ast.ExprArray{ast.Node{}, $3}
// save position
$$.GetNode().Position = position.NewTokensPosition($1, $4)
// save comments
yylex.(*Parser).setFreeFloating($$, token.Start, $1.SkippedTokens)
yylex.(*Parser).setFreeFloating($$, token.Array, $2.SkippedTokens)
yylex.(*Parser).setFreeFloating($$, token.ArrayPairList, $4.SkippedTokens)
$$ = &ast.ExprArray{
Node: ast.Node{
Position: position.NewTokensPosition($1, $4),
},
ArrayTkn: $1,
OpenBracketTkn: $2,
Items: $3.(*ast.ParserSeparatedList).Items,
SeparatorTkns: $3.(*ast.ParserSeparatedList).SeparatorTkns,
CloseBracketTkn: $4,
}
}
| '[' array_pair_list ']'
{
$$ = &ast.ExprShortArray{ast.Node{}, $2}
// save position
$$.GetNode().Position = position.NewTokensPosition($1, $3)
// save comments
yylex.(*Parser).setFreeFloating($$, token.Start, $1.SkippedTokens)
yylex.(*Parser).setFreeFloating($$, token.ArrayPairList, $3.SkippedTokens)
$$ = &ast.ExprArray{
Node: ast.Node{
Position: position.NewTokensPosition($1, $3),
},
OpenBracketTkn: $1,
Items: $2.(*ast.ParserSeparatedList).Items,
SeparatorTkns: $2.(*ast.ParserSeparatedList).SeparatorTkns,
CloseBracketTkn: $3,
}
}
;
@ -4710,26 +4736,28 @@ static_scalar_value:
}
| T_ARRAY '(' static_array_pair_list ')'
{
$$ = &ast.ExprArray{ast.Node{}, $3}
// save position
$$.GetNode().Position = position.NewTokensPosition($1, $4)
// save comments
yylex.(*Parser).setFreeFloating($$, token.Start, $1.SkippedTokens)
yylex.(*Parser).setFreeFloating($$, token.Array, $2.SkippedTokens)
yylex.(*Parser).setFreeFloating($$, token.ArrayPairList, $4.SkippedTokens)
$$ = &ast.ExprArray{
Node: ast.Node{
Position: position.NewTokensPosition($1, $4),
},
ArrayTkn: $1,
OpenBracketTkn: $2,
Items: $3.(*ast.ParserSeparatedList).Items,
SeparatorTkns: $3.(*ast.ParserSeparatedList).SeparatorTkns,
CloseBracketTkn: $4,
}
}
| '[' static_array_pair_list ']'
{
$$ = &ast.ExprShortArray{ast.Node{}, $2}
// save position
$$.GetNode().Position = position.NewTokensPosition($1, $3)
// save comments
yylex.(*Parser).setFreeFloating($$, token.Start, $1.SkippedTokens)
yylex.(*Parser).setFreeFloating($$, token.ArrayPairList, $3.SkippedTokens)
$$ = &ast.ExprArray{
Node: ast.Node{
Position: position.NewTokensPosition($1, $3),
},
OpenBracketTkn: $1,
Items: $2.(*ast.ParserSeparatedList).Items,
SeparatorTkns: $2.(*ast.ParserSeparatedList).SeparatorTkns,
CloseBracketTkn: $3,
}
}
| static_class_constant
{
@ -5229,16 +5257,16 @@ scalar:
static_array_pair_list:
/* empty */
{
$$ = nil
$$ = &ast.ParserSeparatedList{}
}
| non_empty_static_array_pair_list possible_comma
{
$$ = $1
// save comments
if $2 != nil {
yylex.(*Parser).setFreeFloating(lastNode($1), token.End, $2.SkippedTokens)
$1.(*ast.ParserSeparatedList).SeparatorTkns = append($1.(*ast.ParserSeparatedList).SeparatorTkns, $2)
$1.(*ast.ParserSeparatedList).Items = append($1.(*ast.ParserSeparatedList).Items, &ast.ExprArrayItem{})
}
$$ = $1
}
;
@ -5257,32 +5285,41 @@ non_empty_static_array_pair_list:
non_empty_static_array_pair_list ',' static_scalar_value T_DOUBLE_ARROW static_scalar_value
{
arrayItem := &ast.ExprArrayItem{ast.Node{}, false, $3, $5}
$$ = append($1, arrayItem)
$1.(*ast.ParserSeparatedList).SeparatorTkns = append($1.(*ast.ParserSeparatedList).SeparatorTkns, $2)
$1.(*ast.ParserSeparatedList).Items = append($1.(*ast.ParserSeparatedList).Items, arrayItem)
$$ = $1
// save position
arrayItem.GetNode().Position = position.NewNodesPosition($3, $5)
// save comments
yylex.(*Parser).setFreeFloating(lastNode($1), token.End, $2.SkippedTokens)
yylex.(*Parser).MoveFreeFloating($3, arrayItem)
yylex.(*Parser).setFreeFloating(arrayItem, token.Expr, $4.SkippedTokens)
}
| non_empty_static_array_pair_list ',' static_scalar_value
{
arrayItem := &ast.ExprArrayItem{ast.Node{}, false, nil, $3}
$$ = append($1, arrayItem)
$1.(*ast.ParserSeparatedList).SeparatorTkns = append($1.(*ast.ParserSeparatedList).SeparatorTkns, $2)
$1.(*ast.ParserSeparatedList).Items = append($1.(*ast.ParserSeparatedList).Items, arrayItem)
$$ = $1
// save position
arrayItem.GetNode().Position = position.NewNodePosition($3)
// save comments
yylex.(*Parser).setFreeFloating(lastNode($1), token.End, $2.SkippedTokens)
yylex.(*Parser).MoveFreeFloating($3, arrayItem)
}
| static_scalar_value T_DOUBLE_ARROW static_scalar_value
{
arrayItem := &ast.ExprArrayItem{ast.Node{}, false, $1, $3}
$$ = []ast.Vertex{arrayItem}
$$ = &ast.ParserSeparatedList{
Items: []ast.Vertex{arrayItem},
}
// save position
arrayItem.GetNode().Position = position.NewNodesPosition($1, $3)
@ -5294,7 +5331,10 @@ non_empty_static_array_pair_list:
| static_scalar_value
{
arrayItem := &ast.ExprArrayItem{ast.Node{}, false, nil, $1}
$$ = []ast.Vertex{arrayItem}
$$ = &ast.ParserSeparatedList{
Items: []ast.Vertex{arrayItem},
}
// save position
arrayItem.GetNode().Position = position.NewNodePosition($1)
@ -5804,21 +5844,15 @@ simple_indirect_reference:
assignment_list:
assignment_list ',' assignment_list_element
{
if len($1) == 0 {
$1 = []ast.Vertex{&ast.ExprArrayItem{ast.Node{}, false, nil, nil}}
}
$1.(*ast.ParserSeparatedList).SeparatorTkns = append($1.(*ast.ParserSeparatedList).SeparatorTkns, $2)
$1.(*ast.ParserSeparatedList).Items = append($1.(*ast.ParserSeparatedList).Items, $3)
$$ = append($1, $3)
// save comments
yylex.(*Parser).setFreeFloating(lastNode($1), token.End, $2.SkippedTokens)
$$ = $1
}
| assignment_list_element
{
if $1.(*ast.ExprArrayItem).Key == nil && $1.(*ast.ExprArrayItem).Val == nil {
$$ = []ast.Vertex{}
} else {
$$ = []ast.Vertex{$1}
$$ = &ast.ParserSeparatedList{
Items: []ast.Vertex{$1},
}
}
;
@ -5837,7 +5871,23 @@ assignment_list_element:
}
| T_LIST '(' assignment_list ')'
{
listNode := &ast.ExprList{ast.Node{}, $3}
pairList := $3.(*ast.ParserSeparatedList)
fistPair := pairList.Items[0].(*ast.ExprArrayItem)
if fistPair.Key == nil && fistPair.Val == nil && len(pairList.Items) == 1 {
pairList.Items = nil
}
listNode := &ast.ExprList{
Node: ast.Node{
Position: position.NewTokensPosition($1, $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
@ -5859,20 +5909,16 @@ assignment_list_element:
array_pair_list:
/* empty */
{
$$ = []ast.Vertex{}
$$ = &ast.ParserSeparatedList{}
}
| non_empty_array_pair_list possible_comma
{
if $2 != nil {
$1.(*ast.ParserSeparatedList).SeparatorTkns = append($1.(*ast.ParserSeparatedList).SeparatorTkns, $2)
$1.(*ast.ParserSeparatedList).Items = append($1.(*ast.ParserSeparatedList).Items, &ast.ExprArrayItem{})
}
$$ = $1
if $2 != nil {
$$ = append($1, &ast.ExprArrayItem{ast.Node{}, false, nil, nil})
}
// save comments
if $2 != nil {
yylex.(*Parser).setFreeFloating(lastNode($1), token.End, $2.SkippedTokens)
}
}
;
@ -5880,32 +5926,41 @@ non_empty_array_pair_list:
non_empty_array_pair_list ',' expr T_DOUBLE_ARROW expr
{
arrayItem := &ast.ExprArrayItem{ast.Node{}, false, $3, $5}
$$ = append($1, arrayItem)
$1.(*ast.ParserSeparatedList).SeparatorTkns = append($1.(*ast.ParserSeparatedList).SeparatorTkns, $2)
$1.(*ast.ParserSeparatedList).Items = append($1.(*ast.ParserSeparatedList).Items, arrayItem)
$$ = $1
// save position
arrayItem.GetNode().Position = position.NewNodesPosition($3, $5)
// save comments
yylex.(*Parser).setFreeFloating(lastNode($1), token.End, $2.SkippedTokens)
yylex.(*Parser).MoveFreeFloating($3, arrayItem)
yylex.(*Parser).setFreeFloating(arrayItem, token.Expr, $4.SkippedTokens)
}
| non_empty_array_pair_list ',' expr
{
arrayItem := &ast.ExprArrayItem{ast.Node{}, false, nil, $3}
$$ = append($1, arrayItem)
$1.(*ast.ParserSeparatedList).SeparatorTkns = append($1.(*ast.ParserSeparatedList).SeparatorTkns, $2)
$1.(*ast.ParserSeparatedList).Items = append($1.(*ast.ParserSeparatedList).Items, arrayItem)
$$ = $1
// save position
arrayItem.GetNode().Position = position.NewNodePosition($3)
// save comments
yylex.(*Parser).setFreeFloating(lastNode($1), token.End, $2.SkippedTokens)
yylex.(*Parser).MoveFreeFloating($3, arrayItem)
}
| expr T_DOUBLE_ARROW expr
{
arrayItem := &ast.ExprArrayItem{ast.Node{}, false, $1, $3}
$$ = []ast.Vertex{arrayItem}
$$ = &ast.ParserSeparatedList{
Items: []ast.Vertex{arrayItem},
}
// save position
arrayItem.GetNode().Position = position.NewNodesPosition($1, $3)
@ -5917,7 +5972,10 @@ non_empty_array_pair_list:
| expr
{
arrayItem := &ast.ExprArrayItem{ast.Node{}, false, nil, $1}
$$ = []ast.Vertex{arrayItem}
$$ = &ast.ParserSeparatedList{
Items: []ast.Vertex{arrayItem},
}
// save position
arrayItem.GetNode().Position = position.NewNodePosition($1)
@ -5929,14 +5987,17 @@ non_empty_array_pair_list:
{
reference := &ast.ExprReference{ast.Node{}, $6}
arrayItem := &ast.ExprArrayItem{ast.Node{}, false, $3, reference}
$$ = append($1, arrayItem)
$1.(*ast.ParserSeparatedList).SeparatorTkns = append($1.(*ast.ParserSeparatedList).SeparatorTkns, $2)
$1.(*ast.ParserSeparatedList).Items = append($1.(*ast.ParserSeparatedList).Items, arrayItem)
$$ = $1
// save position
reference.GetNode().Position = position.NewTokenNodePosition($5, $6)
arrayItem.GetNode().Position = position.NewNodesPosition($3, $6)
// save comments
yylex.(*Parser).setFreeFloating(lastNode($1), token.End, $2.SkippedTokens)
yylex.(*Parser).MoveFreeFloating($3, arrayItem)
yylex.(*Parser).setFreeFloating(arrayItem, token.Expr, $4.SkippedTokens)
yylex.(*Parser).setFreeFloating(reference, token.Start, $5.SkippedTokens)
@ -5945,21 +6006,27 @@ non_empty_array_pair_list:
{
reference := &ast.ExprReference{ast.Node{}, $4}
arrayItem := &ast.ExprArrayItem{ast.Node{}, false, nil, reference}
$$ = append($1, arrayItem)
$1.(*ast.ParserSeparatedList).SeparatorTkns = append($1.(*ast.ParserSeparatedList).SeparatorTkns, $2)
$1.(*ast.ParserSeparatedList).Items = append($1.(*ast.ParserSeparatedList).Items, arrayItem)
$$ = $1
// save position
reference.GetNode().Position = position.NewTokenNodePosition($3, $4)
arrayItem.GetNode().Position = position.NewTokenNodePosition($3, $4)
// save comments
yylex.(*Parser).setFreeFloating(lastNode($1), token.End, $2.SkippedTokens)
yylex.(*Parser).setFreeFloating(arrayItem, token.Start, $3.SkippedTokens)
}
| expr T_DOUBLE_ARROW '&' w_variable
{
reference := &ast.ExprReference{ast.Node{}, $4}
arrayItem := &ast.ExprArrayItem{ast.Node{}, false, $1, reference}
$$ = []ast.Vertex{arrayItem}
$$ = &ast.ParserSeparatedList{
Items: []ast.Vertex{arrayItem},
}
// save position
reference.GetNode().Position = position.NewTokenNodePosition($3, $4)
@ -5974,7 +6041,10 @@ non_empty_array_pair_list:
{
reference := &ast.ExprReference{ast.Node{}, $2}
arrayItem := &ast.ExprArrayItem{ast.Node{}, false, nil, reference}
$$ = []ast.Vertex{arrayItem}
$$ = &ast.ParserSeparatedList{
Items: []ast.Vertex{arrayItem},
}
// save position
reference.GetNode().Position = position.NewTokenNodePosition($1, $2)

BIN
internal/php7/php7.go generated

Binary file not shown.

View File

@ -242,7 +242,7 @@ import (
%type <node> static_var_list static_var class_statement trait_adaptation trait_precedence trait_alias
%type <node> absolute_trait_method_reference trait_method_reference property echo_expr
%type <node> new_expr anonymous_class class_name class_name_reference simple_variable
%type <node> internal_functions_in_yacc
%type <node> internal_functions_in_yacc non_empty_array_pair_list array_pair_list
%type <node> exit_expr scalar lexical_var function_call member_name property_name
%type <node> variable_class_name dereferencable_scalar constant dereferencable
%type <node> callable_expr callable_variable static_member new_variable
@ -276,8 +276,8 @@ import (
%type <list> for_exprs non_empty_for_exprs
%type <list> unprefixed_use_declarations inline_use_declarations
%type <list> case_list trait_adaptation_list
%type <list> use_declarations lexical_var_list isset_variables non_empty_array_pair_list
%type <list> array_pair_list top_statement_list
%type <list> use_declarations lexical_var_list isset_variables
%type <list> top_statement_list
%type <list> inner_statement_list parameter_list non_empty_parameter_list class_statement_list
%type <list> method_modifiers variable_modifiers
%type <list> non_empty_member_modifiers class_modifiers
@ -1454,26 +1454,28 @@ foreach_variable:
}
| T_LIST '(' array_pair_list ')'
{
$$ = &ast.ExprList{ast.Node{}, $3}
// save position
$$.GetNode().Position = position.NewTokensPosition($1, $4)
// save comments
yylex.(*Parser).setFreeFloating($$, token.Start, $1.SkippedTokens)
yylex.(*Parser).setFreeFloating($$, token.List, $2.SkippedTokens)
yylex.(*Parser).setFreeFloating($$, token.ArrayPairList, $4.SkippedTokens)
$$ = &ast.ExprList{
Node: ast.Node{
Position: position.NewTokensPosition($1, $4),
},
ListTkn: $1,
OpenBracketTkn: $2,
Items: $3.(*ast.ParserSeparatedList).Items,
SeparatorTkns: $3.(*ast.ParserSeparatedList).SeparatorTkns,
CloseBracketTkn: $4,
}
}
| '[' array_pair_list ']'
{
$$ = &ast.ExprShortList{ast.Node{}, $2}
// save position
$$.GetNode().Position = position.NewTokensPosition($1, $3)
// save commentsc
yylex.(*Parser).setFreeFloating($$, token.Start, $1.SkippedTokens)
yylex.(*Parser).setFreeFloating($$, token.ArrayPairList, $3.SkippedTokens)
$$ = &ast.ExprList{
Node: ast.Node{
Position: position.NewTokensPosition($1, $3),
},
OpenBracketTkn: $1,
Items: $2.(*ast.ParserSeparatedList).Items,
SeparatorTkns: $2.(*ast.ParserSeparatedList).SeparatorTkns,
CloseBracketTkn: $3,
}
}
;
@ -2802,31 +2804,41 @@ new_expr:
expr_without_variable:
T_LIST '(' array_pair_list ')' '=' expr
{
listNode := &ast.ExprList{ast.Node{}, $3}
listNode := &ast.ExprList{
Node: ast.Node{
Position: position.NewTokensPosition($1, $4),
},
ListTkn: $1,
OpenBracketTkn: $2,
Items: $3.(*ast.ParserSeparatedList).Items,
SeparatorTkns: $3.(*ast.ParserSeparatedList).SeparatorTkns,
CloseBracketTkn: $4,
}
$$ = &ast.ExprAssign{ast.Node{}, listNode, $6}
// save position
listNode.GetNode().Position = position.NewTokensPosition($1, $4)
$$.GetNode().Position = position.NewTokenNodePosition($1, $6)
// 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)
yylex.(*Parser).setFreeFloating($$, token.Var, $5.SkippedTokens)
}
| '[' array_pair_list ']' '=' expr
{
shortList := &ast.ExprShortList{ast.Node{}, $2}
$$ = &ast.ExprAssign{ast.Node{}, shortList, $5}
listNode := &ast.ExprList{
Node: ast.Node{
Position: position.NewTokensPosition($1, $3),
},
OpenBracketTkn: $1,
Items: $2.(*ast.ParserSeparatedList).Items,
SeparatorTkns: $2.(*ast.ParserSeparatedList).SeparatorTkns,
CloseBracketTkn: $3,
}
$$ = &ast.ExprAssign{ast.Node{}, listNode, $5}
// save position
shortList.GetNode().Position = position.NewTokensPosition($1, $3)
$$.GetNode().Position = position.NewTokenNodePosition($1, $5)
// save comments
yylex.(*Parser).setFreeFloating($$, token.Start, $1.SkippedTokens)
yylex.(*Parser).setFreeFloating(shortList, token.ArrayPairList, $3.SkippedTokens)
yylex.(*Parser).setFreeFloating($$, token.Var, $4.SkippedTokens)
}
| variable '=' expr
@ -3890,26 +3902,28 @@ ctor_arguments:
dereferencable_scalar:
T_ARRAY '(' array_pair_list ')'
{
$$ = &ast.ExprArray{ast.Node{}, $3}
// save position
$$.GetNode().Position = position.NewTokensPosition($1, $4)
// save comments
yylex.(*Parser).setFreeFloating($$, token.Start, $1.SkippedTokens)
yylex.(*Parser).setFreeFloating($$, token.Array, $2.SkippedTokens)
yylex.(*Parser).setFreeFloating($$, token.ArrayPairList, $4.SkippedTokens)
$$ = &ast.ExprArray{
Node: ast.Node{
Position: position.NewTokensPosition($1, $4),
},
ArrayTkn: $1,
OpenBracketTkn: $2,
Items: $3.(*ast.ParserSeparatedList).Items,
SeparatorTkns: $3.(*ast.ParserSeparatedList).SeparatorTkns,
CloseBracketTkn: $4,
}
}
| '[' array_pair_list ']'
{
$$ = &ast.ExprShortArray{ast.Node{}, $2}
// save position
$$.GetNode().Position = position.NewTokensPosition($1, $3)
// save comments
yylex.(*Parser).setFreeFloating($$, token.Start, $1.SkippedTokens)
yylex.(*Parser).setFreeFloating($$, token.ArrayPairList, $3.SkippedTokens)
$$ = &ast.ExprArray{
Node: ast.Node{
Position: position.NewTokensPosition($1, $3),
},
OpenBracketTkn: $1,
Items: $2.(*ast.ParserSeparatedList).Items,
SeparatorTkns: $2.(*ast.ParserSeparatedList).SeparatorTkns,
CloseBracketTkn: $3,
}
}
| T_CONSTANT_ENCAPSED_STRING
{
@ -4474,6 +4488,13 @@ property_name:
array_pair_list:
non_empty_array_pair_list
{
pairList := $1.(*ast.ParserSeparatedList)
fistPair := pairList.Items[0].(*ast.ExprArrayItem)
if fistPair.Key == nil && fistPair.Val == nil && len(pairList.Items) == 1 {
pairList.Items = nil
}
$$ = $1
}
;
@ -4481,7 +4502,7 @@ array_pair_list:
possible_array_pair:
/* empty */
{
$$ = &ast.ExprArrayItem{ast.Node{}, false, nil, nil}
$$ = &ast.ExprArrayItem{}
}
| array_pair
{
@ -4492,21 +4513,15 @@ possible_array_pair:
non_empty_array_pair_list:
non_empty_array_pair_list ',' possible_array_pair
{
if len($1) == 0 {
$1 = []ast.Vertex{&ast.ExprArrayItem{ast.Node{}, false, nil, nil}}
}
$1.(*ast.ParserSeparatedList).SeparatorTkns = append($1.(*ast.ParserSeparatedList).SeparatorTkns, $2)
$1.(*ast.ParserSeparatedList).Items = append($1.(*ast.ParserSeparatedList).Items, $3)
$$ = append($1, $3)
// save comments
yylex.(*Parser).setFreeFloating(lastNode($1), token.End, $2.SkippedTokens)
$$ = $1
}
| possible_array_pair
{
if $1.(*ast.ExprArrayItem).Key == nil && $1.(*ast.ExprArrayItem).Val == nil {
$$ = []ast.Vertex{}
} else {
$$ = []ast.Vertex{$1}
$$ = &ast.ParserSeparatedList{
Items: []ast.Vertex{$1},
}
}
;
@ -4571,35 +4586,41 @@ array_pair:
}
| expr T_DOUBLE_ARROW T_LIST '(' array_pair_list ')'
{
// TODO: Cannot use list() as standalone expression
listNode := &ast.ExprList{ast.Node{}, $5}
listNode := &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,
}
$$ = &ast.ExprArrayItem{ast.Node{}, false, $1, listNode}
// save position
listNode.GetNode().Position = position.NewTokensPosition($3, $6)
$$.GetNode().Position = position.NewNodeTokenPosition($1, $6)
// save comments
yylex.(*Parser).MoveFreeFloating($1, $$)
yylex.(*Parser).setFreeFloating($$, token.Expr, $2.SkippedTokens)
yylex.(*Parser).setFreeFloating(listNode, token.Start, $3.SkippedTokens)
yylex.(*Parser).setFreeFloating(listNode, token.List, $4.SkippedTokens)
yylex.(*Parser).setFreeFloating(listNode, token.ArrayPairList, $6.SkippedTokens)
}
| T_LIST '(' array_pair_list ')'
{
// TODO: Cannot use list() as standalone expression
listNode := &ast.ExprList{ast.Node{}, $3}
listNode := &ast.ExprList{
Node: ast.Node{
Position: position.NewTokensPosition($1, $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.NewTokensPosition($1, $4)
// 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)
}
;

View File

@ -113,8 +113,6 @@ type NodeVisitor interface {
ExprRequire(n *ExprRequire)
ExprRequireOnce(n *ExprRequireOnce)
ExprShellExec(n *ExprShellExec)
ExprShortArray(n *ExprShortArray)
ExprShortList(n *ExprShortList)
ExprStaticCall(n *ExprStaticCall)
ExprStaticPropertyFetch(n *ExprStaticPropertyFetch)
ExprTernary(n *ExprTernary)

View File

@ -939,7 +939,11 @@ func (n *StmtWhile) Accept(v NodeVisitor) {
// ExprArray node
type ExprArray struct {
Node
Items []Vertex
ArrayTkn *token.Token
OpenBracketTkn *token.Token
Items []Vertex
SeparatorTkns []*token.Token
CloseBracketTkn *token.Token
}
func (n *ExprArray) Accept(v NodeVisitor) {
@ -1166,7 +1170,11 @@ func (n *ExprIsset) Accept(v NodeVisitor) {
// ExprList node
type ExprList struct {
Node
Items []Vertex
ListTkn *token.Token
OpenBracketTkn *token.Token
Items []Vertex
SeparatorTkns []*token.Token
CloseBracketTkn *token.Token
}
func (n *ExprList) Accept(v NodeVisitor) {
@ -1297,26 +1305,6 @@ func (n *ExprShellExec) Accept(v NodeVisitor) {
v.ExprShellExec(n)
}
// ExprShortArray node
type ExprShortArray struct {
Node
Items []Vertex
}
func (n *ExprShortArray) Accept(v NodeVisitor) {
v.ExprShortArray(n)
}
// ExprShortList node
type ExprShortList struct {
Node
Items []Vertex
}
func (n *ExprShortList) Accept(v NodeVisitor) {
v.ExprShortList(n)
}
// ExprStaticCall node
type ExprStaticCall struct {
Node

View File

@ -1543,34 +1543,6 @@ func (t *DFS) Traverse(n ast.Vertex) {
}
t.visitor.Leave("Parts", false)
}
case *ast.ExprShortArray:
if nn == nil {
return
}
if !t.visitor.EnterNode(nn) {
return
}
if nn.Items != nil {
t.visitor.Enter("Items", false)
for _, c := range nn.Items {
t.Traverse(c)
}
t.visitor.Leave("Items", false)
}
case *ast.ExprShortList:
if nn == nil {
return
}
if !t.visitor.EnterNode(nn) {
return
}
if nn.Items != nil {
t.visitor.Enter("Items", false)
for _, c := range nn.Items {
t.Traverse(c)
}
t.visitor.Leave("Items", false)
}
case *ast.ExprStaticCall:
if nn == nil {
return

View File

@ -812,18 +812,6 @@ func (v *Dump) ExprShellExec(n *ast.ExprShellExec) {
v.printNode(n.GetNode())
}
func (v *Dump) ExprShortArray(n *ast.ExprShortArray) {
v.printIndentIfNotSingle(v.indent - 1)
v.print("&ast.ExprShortArray{\n")
v.printNode(n.GetNode())
}
func (v *Dump) ExprShortList(n *ast.ExprShortList) {
v.printIndentIfNotSingle(v.indent - 1)
v.print("&ast.ExprShortList{\n")
v.printNode(n.GetNode())
}
func (v *Dump) ExprStaticCall(n *ast.ExprStaticCall) {
v.printIndentIfNotSingle(v.indent - 1)
v.print("&ast.ExprStaticCall{\n")

View File

@ -394,14 +394,6 @@ func (v *Null) ExprShellExec(_ *ast.ExprShellExec) {
// do nothing
}
func (v *Null) ExprShortArray(_ *ast.ExprShortArray) {
// do nothing
}
func (v *Null) ExprShortList(_ *ast.ExprShortList) {
// do nothing
}
func (v *Null) ExprStaticCall(_ *ast.ExprStaticCall) {
// do nothing
}

View File

@ -274,10 +274,6 @@ func (p *PrettyPrinter) printNode(n ast.Vertex) {
p.printExprRequireOnce(n)
case *ast.ExprShellExec:
p.printExprShellExec(n)
case *ast.ExprShortArray:
p.printExprShortArray(n)
case *ast.ExprShortList:
p.printExprShortList(n)
case *ast.ExprStaticCall:
p.printExprStaticCall(n)
case *ast.ExprStaticPropertyFetch:
@ -1240,22 +1236,6 @@ func (p *PrettyPrinter) printExprShellExec(n ast.Vertex) {
io.WriteString(p.w, "`")
}
func (p *PrettyPrinter) printExprShortArray(n ast.Vertex) {
nn := n.(*ast.ExprShortArray)
io.WriteString(p.w, "[")
p.joinPrint(", ", nn.Items)
io.WriteString(p.w, "]")
}
func (p *PrettyPrinter) printExprShortList(n ast.Vertex) {
nn := n.(*ast.ExprShortList)
io.WriteString(p.w, "[")
p.joinPrint(", ", nn.Items)
io.WriteString(p.w, "]")
}
func (p *PrettyPrinter) printExprStaticCall(n ast.Vertex) {
nn := n.(*ast.ExprStaticCall)

View File

@ -363,10 +363,6 @@ func (p *Printer) printNode(n ast.Vertex) {
p.printExprRequireOnce(n)
case *ast.ExprShellExec:
p.printExprShellExec(n)
case *ast.ExprShortArray:
p.printExprShortArray(n)
case *ast.ExprShortList:
p.printExprShortList(n)
case *ast.ExprStaticCall:
p.printExprStaticCall(n)
case *ast.ExprStaticPropertyFetch:
@ -1837,30 +1833,6 @@ func (p *Printer) printExprShellExec(n ast.Vertex) {
p.printFreeFloating(nn, token.End)
}
func (p *Printer) printExprShortArray(n ast.Vertex) {
nn := n.(*ast.ExprShortArray)
p.printFreeFloating(nn, token.Start)
p.write([]byte("["))
p.joinPrint(",", nn.Items)
p.printFreeFloating(nn, token.ArrayPairList)
p.write([]byte("]"))
p.printFreeFloating(nn, token.End)
}
func (p *Printer) printExprShortList(n ast.Vertex) {
nn := n.(*ast.ExprShortList)
p.printFreeFloating(nn, token.Start)
p.write([]byte("["))
p.joinPrint(",", nn.Items)
p.printFreeFloating(nn, token.ArrayPairList)
p.write([]byte("]"))
p.printFreeFloating(nn, token.End)
}
func (p *Printer) printExprStaticCall(n ast.Vertex) {
nn := n.(*ast.ExprStaticCall)
p.printFreeFloating(nn, token.Start)