[refactoring] update ast structure of "ClassConstList", "Constant", "Use", "GroupUse", "UseDeclaration", "Closure", "Name", "FullyQualified", "Relative" and "NamePart" nodes

This commit is contained in:
Vadym Slizov 2020-12-04 14:38:47 +02:00
parent 94897d8c66
commit 40b944a272
No known key found for this signature in database
GPG Key ID: AEA2A9388EF42A4A
9 changed files with 271 additions and 1562 deletions

BIN
internal/php5/php5.go generated

Binary file not shown.

View File

@ -15,8 +15,6 @@ import (
node ast.Vertex node ast.Vertex
token *token.Token token *token.Token
list []ast.Vertex list []ast.Vertex
ClosureUse *ast.ExprClosureUse
} }
%token <token> T_INCLUDE %token <token> T_INCLUDE
@ -219,6 +217,7 @@ import (
%type <token> function interface_entry %type <token> function interface_entry
%type <token> possible_comma %type <token> possible_comma
%type <token> case_separator %type <token> case_separator
%type <token> is_reference is_variadic
%type <node> top_statement use_declaration use_function_declaration use_const_declaration common_scalar %type <node> top_statement use_declaration use_function_declaration use_const_declaration common_scalar
%type <node> static_class_constant compound_variable reference_variable class_name variable_class_name %type <node> static_class_constant compound_variable reference_variable class_name variable_class_name
@ -241,12 +240,12 @@ import (
%type <node> method_body trait_reference_list static_array_pair_list non_empty_static_array_pair_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 isset_variables %type <node> foreach_statement for_statement while_statement isset_variables
%type <node> foreach_variable foreach_optional_arg for_expr non_empty_for_expr %type <node> foreach_variable foreach_optional_arg for_expr non_empty_for_expr
%type <node> extends_from interface_list trait_list %type <node> extends_from interface_list trait_list namespace_name
%type <node> implements_list %type <node> implements_list use_declarations use_function_declarations use_const_declarations
%type <node> interface_extends_list %type <node> interface_extends_list
%type <ClosureUse> lexical_vars %type <node> lexical_vars
%type <list> top_statement_list namespace_name use_declarations use_function_declarations use_const_declarations %type <list> top_statement_list
%type <list> inner_statement_list encaps_list %type <list> inner_statement_list encaps_list
%type <list> elseif_list new_elseif_list %type <list> elseif_list new_elseif_list
%type <list> case_list catch_statement additional_catches %type <list> case_list catch_statement additional_catches
@ -260,7 +259,6 @@ import (
%type <list> dynamic_class_name_variable_properties variable_properties %type <list> dynamic_class_name_variable_properties variable_properties
%type <list> simple_indirect_reference %type <list> simple_indirect_reference
%type <token> is_reference is_variadic
%% %%
@ -293,26 +291,32 @@ top_statement_list:
namespace_name: namespace_name:
T_STRING T_STRING
{ {
$$ = []ast.Vertex{ $$ = &ast.ParserSeparatedList{
&ast.NameNamePart{ Items: []ast.Vertex{
Node: ast.Node{ &ast.NameNamePart{
Position: position.NewTokenPosition($1), Node: ast.Node{
Position: position.NewTokenPosition($1),
},
StringTkn: $1,
Value: $1.Value,
}, },
StringTkn: $1,
Value: $1.Value,
}, },
} }
} }
| namespace_name T_NS_SEPARATOR T_STRING | namespace_name T_NS_SEPARATOR T_STRING
{ {
$$ = append($1, &ast.NameNamePart{ part := &ast.NameNamePart{
Node: ast.Node{ Node: ast.Node{
Position: position.NewTokensPosition($2, $3), Position: position.NewTokenPosition($3),
}, },
NsSeparatorTkn: $2,
StringTkn: $3, StringTkn: $3,
Value: $3.Value, Value: $3.Value,
}) }
$1.(*ast.ParserSeparatedList).SeparatorTkns = append($1.(*ast.ParserSeparatedList).SeparatorTkns, $2)
$1.(*ast.ParserSeparatedList).Items = append($1.(*ast.ParserSeparatedList).Items, part)
$$ = $1
} }
; ;
@ -355,9 +359,10 @@ top_statement:
NsTkn: $1, NsTkn: $1,
Name: &ast.NameName{ Name: &ast.NameName{
Node: ast.Node{ Node: ast.Node{
Position: position.NewNodeListPosition($2), Position: position.NewNodeListPosition($2.(*ast.ParserSeparatedList).Items),
}, },
Parts: $2, Parts: $2.(*ast.ParserSeparatedList).Items,
SeparatorTkns: $2.(*ast.ParserSeparatedList).SeparatorTkns,
}, },
SemiColonTkn: $3, SemiColonTkn: $3,
} }
@ -371,9 +376,10 @@ top_statement:
NsTkn: $1, NsTkn: $1,
Name: &ast.NameName{ Name: &ast.NameName{
Node: ast.Node{ Node: ast.Node{
Position: position.NewNodeListPosition($2), Position: position.NewNodeListPosition($2.(*ast.ParserSeparatedList).Items),
}, },
Parts: $2, Parts: $2.(*ast.ParserSeparatedList).Items,
SeparatorTkns: $2.(*ast.ParserSeparatedList).SeparatorTkns,
}, },
OpenCurlyBracket: $3, OpenCurlyBracket: $3,
Stmts: $4, Stmts: $4,
@ -399,7 +405,8 @@ top_statement:
Position: position.NewTokensPosition($1, $3), Position: position.NewTokensPosition($1, $3),
}, },
UseTkn: $1, UseTkn: $1,
UseDeclarations: $2, UseDeclarations: $2.(*ast.ParserSeparatedList).Items,
SeparatorTkns: $2.(*ast.ParserSeparatedList).SeparatorTkns,
SemiColonTkn: $3, SemiColonTkn: $3,
} }
} }
@ -417,7 +424,8 @@ top_statement:
IdentifierTkn: $2, IdentifierTkn: $2,
Value: $2.Value, Value: $2.Value,
}, },
UseDeclarations: $3, UseDeclarations: $3.(*ast.ParserSeparatedList).Items,
SeparatorTkns: $3.(*ast.ParserSeparatedList).SeparatorTkns,
SemiColonTkn: $4, SemiColonTkn: $4,
} }
} }
@ -435,7 +443,8 @@ top_statement:
IdentifierTkn: $2, IdentifierTkn: $2,
Value: $2.Value, Value: $2.Value,
}, },
UseDeclarations: $3, UseDeclarations: $3.(*ast.ParserSeparatedList).Items,
SeparatorTkns: $3.(*ast.ParserSeparatedList).SeparatorTkns,
SemiColonTkn: $4, SemiColonTkn: $4,
} }
} }
@ -450,13 +459,16 @@ top_statement:
use_declarations: use_declarations:
use_declarations ',' use_declaration use_declarations ',' use_declaration
{ {
$1[len($1)-1].(*ast.StmtUseDeclaration).CommaTkn = $2 $1.(*ast.ParserSeparatedList).SeparatorTkns = append($1.(*ast.ParserSeparatedList).SeparatorTkns, $2)
$1.(*ast.ParserSeparatedList).Items = append($1.(*ast.ParserSeparatedList).Items, $3)
$$ = append($1, $3) $$ = $1
} }
| use_declaration | use_declaration
{ {
$$ = []ast.Vertex{$1} $$ = &ast.ParserSeparatedList{
Items: []ast.Vertex{$1},
}
} }
; ;
@ -465,13 +477,14 @@ use_declaration:
{ {
$$ = &ast.StmtUseDeclaration{ $$ = &ast.StmtUseDeclaration{
Node: ast.Node{ Node: ast.Node{
Position: position.NewNodeListPosition($1), Position: position.NewNodeListPosition($1.(*ast.ParserSeparatedList).Items),
}, },
Use: &ast.NameName{ Use: &ast.NameName{
Node: ast.Node{ Node: ast.Node{
Position: position.NewNodeListPosition($1), Position: position.NewNodeListPosition($1.(*ast.ParserSeparatedList).Items),
}, },
Parts: $1, Parts: $1.(*ast.ParserSeparatedList).Items,
SeparatorTkns: $1.(*ast.ParserSeparatedList).SeparatorTkns,
}, },
} }
} }
@ -479,13 +492,14 @@ use_declaration:
{ {
$$ = &ast.StmtUseDeclaration{ $$ = &ast.StmtUseDeclaration{
Node: ast.Node{ Node: ast.Node{
Position: position.NewNodeListTokenPosition($1, $3), Position: position.NewNodeListTokenPosition($1.(*ast.ParserSeparatedList).Items, $3),
}, },
Use: &ast.NameName{ Use: &ast.NameName{
Node: ast.Node{ Node: ast.Node{
Position: position.NewNodeListPosition($1), Position: position.NewNodeListPosition($1.(*ast.ParserSeparatedList).Items),
}, },
Parts: $1, Parts: $1.(*ast.ParserSeparatedList).Items,
SeparatorTkns: $1.(*ast.ParserSeparatedList).SeparatorTkns,
}, },
AsTkn: $2, AsTkn: $2,
Alias: &ast.Identifier{ Alias: &ast.Identifier{
@ -501,14 +515,15 @@ use_declaration:
{ {
$$ = &ast.StmtUseDeclaration{ $$ = &ast.StmtUseDeclaration{
Node: ast.Node{ Node: ast.Node{
Position: position.NewTokenNodeListPosition($1, $2), Position: position.NewTokenNodeListPosition($1, $2.(*ast.ParserSeparatedList).Items),
}, },
NsSeparatorTkn: $1, NsSeparatorTkn: $1,
Use: &ast.NameName{ Use: &ast.NameName{
Node: ast.Node{ Node: ast.Node{
Position: position.NewNodeListPosition($2), Position: position.NewNodeListPosition($2.(*ast.ParserSeparatedList).Items),
}, },
Parts: $2, Parts: $2.(*ast.ParserSeparatedList).Items,
SeparatorTkns: $2.(*ast.ParserSeparatedList).SeparatorTkns,
}, },
} }
} }
@ -521,9 +536,10 @@ use_declaration:
NsSeparatorTkn: $1, NsSeparatorTkn: $1,
Use: &ast.NameName{ Use: &ast.NameName{
Node: ast.Node{ Node: ast.Node{
Position: position.NewNodeListPosition($2), Position: position.NewNodeListPosition($2.(*ast.ParserSeparatedList).Items),
}, },
Parts: $2, Parts: $2.(*ast.ParserSeparatedList).Items,
SeparatorTkns: $2.(*ast.ParserSeparatedList).SeparatorTkns,
}, },
AsTkn: $3, AsTkn: $3,
Alias: &ast.Identifier{ Alias: &ast.Identifier{
@ -540,13 +556,16 @@ use_declaration:
use_function_declarations: use_function_declarations:
use_function_declarations ',' use_function_declaration use_function_declarations ',' use_function_declaration
{ {
$1[len($1)-1].(*ast.StmtUseDeclaration).CommaTkn = $2 $1.(*ast.ParserSeparatedList).SeparatorTkns = append($1.(*ast.ParserSeparatedList).SeparatorTkns, $2)
$1.(*ast.ParserSeparatedList).Items = append($1.(*ast.ParserSeparatedList).Items, $3)
$$ = append($1, $3) $$ = $1
} }
| use_function_declaration | use_function_declaration
{ {
$$ = []ast.Vertex{$1} $$ = &ast.ParserSeparatedList{
Items: []ast.Vertex{$1},
}
} }
; ;
@ -555,13 +574,14 @@ use_function_declaration:
{ {
$$ = &ast.StmtUseDeclaration{ $$ = &ast.StmtUseDeclaration{
Node: ast.Node{ Node: ast.Node{
Position: position.NewNodeListPosition($1), Position: position.NewNodeListPosition($1.(*ast.ParserSeparatedList).Items),
}, },
Use: &ast.NameName{ Use: &ast.NameName{
Node: ast.Node{ Node: ast.Node{
Position: position.NewNodeListPosition($1), Position: position.NewNodeListPosition($1.(*ast.ParserSeparatedList).Items),
}, },
Parts: $1, Parts: $1.(*ast.ParserSeparatedList).Items,
SeparatorTkns: $1.(*ast.ParserSeparatedList).SeparatorTkns,
}, },
} }
} }
@ -569,13 +589,14 @@ use_function_declaration:
{ {
$$ = &ast.StmtUseDeclaration{ $$ = &ast.StmtUseDeclaration{
Node: ast.Node{ Node: ast.Node{
Position: position.NewNodeListTokenPosition($1, $3), Position: position.NewNodeListTokenPosition($1.(*ast.ParserSeparatedList).Items, $3),
}, },
Use: &ast.NameName{ Use: &ast.NameName{
Node: ast.Node{ Node: ast.Node{
Position: position.NewNodeListPosition($1), Position: position.NewNodeListPosition($1.(*ast.ParserSeparatedList).Items),
}, },
Parts: $1, Parts: $1.(*ast.ParserSeparatedList).Items,
SeparatorTkns: $1.(*ast.ParserSeparatedList).SeparatorTkns,
}, },
AsTkn: $2, AsTkn: $2,
Alias: &ast.Identifier{ Alias: &ast.Identifier{
@ -591,14 +612,15 @@ use_function_declaration:
{ {
$$ = &ast.StmtUseDeclaration{ $$ = &ast.StmtUseDeclaration{
Node: ast.Node{ Node: ast.Node{
Position: position.NewTokenNodeListPosition($1, $2), Position: position.NewTokenNodeListPosition($1, $2.(*ast.ParserSeparatedList).Items),
}, },
NsSeparatorTkn: $1, NsSeparatorTkn: $1,
Use: &ast.NameName{ Use: &ast.NameName{
Node: ast.Node{ Node: ast.Node{
Position: position.NewNodeListPosition($2), Position: position.NewNodeListPosition($2.(*ast.ParserSeparatedList).Items),
}, },
Parts: $2, Parts: $2.(*ast.ParserSeparatedList).Items,
SeparatorTkns: $2.(*ast.ParserSeparatedList).SeparatorTkns,
}, },
} }
} }
@ -611,9 +633,10 @@ use_function_declaration:
NsSeparatorTkn: $1, NsSeparatorTkn: $1,
Use: &ast.NameName{ Use: &ast.NameName{
Node: ast.Node{ Node: ast.Node{
Position: position.NewNodeListPosition($2), Position: position.NewNodeListPosition($2.(*ast.ParserSeparatedList).Items),
}, },
Parts: $2, Parts: $2.(*ast.ParserSeparatedList).Items,
SeparatorTkns: $2.(*ast.ParserSeparatedList).SeparatorTkns,
}, },
AsTkn: $3, AsTkn: $3,
Alias: &ast.Identifier{ Alias: &ast.Identifier{
@ -630,13 +653,16 @@ use_function_declaration:
use_const_declarations: use_const_declarations:
use_const_declarations ',' use_const_declaration use_const_declarations ',' use_const_declaration
{ {
$1[len($1)-1].(*ast.StmtUseDeclaration).CommaTkn = $2 $1.(*ast.ParserSeparatedList).SeparatorTkns = append($1.(*ast.ParserSeparatedList).SeparatorTkns, $2)
$1.(*ast.ParserSeparatedList).Items = append($1.(*ast.ParserSeparatedList).Items, $3)
$$ = append($1, $3) $$ = $1
} }
| use_const_declaration | use_const_declaration
{ {
$$ = []ast.Vertex{$1} $$ = &ast.ParserSeparatedList{
Items: []ast.Vertex{$1},
}
} }
; ;
@ -645,13 +671,14 @@ use_const_declaration:
{ {
$$ = &ast.StmtUseDeclaration{ $$ = &ast.StmtUseDeclaration{
Node: ast.Node{ Node: ast.Node{
Position: position.NewNodeListPosition($1), Position: position.NewNodeListPosition($1.(*ast.ParserSeparatedList).Items),
}, },
Use: &ast.NameName{ Use: &ast.NameName{
Node: ast.Node{ Node: ast.Node{
Position: position.NewNodeListPosition($1), Position: position.NewNodeListPosition($1.(*ast.ParserSeparatedList).Items),
}, },
Parts: $1, Parts: $1.(*ast.ParserSeparatedList).Items,
SeparatorTkns: $1.(*ast.ParserSeparatedList).SeparatorTkns,
}, },
} }
} }
@ -659,13 +686,14 @@ use_const_declaration:
{ {
$$ = &ast.StmtUseDeclaration{ $$ = &ast.StmtUseDeclaration{
Node: ast.Node{ Node: ast.Node{
Position: position.NewNodeListTokenPosition($1, $3), Position: position.NewNodeListTokenPosition($1.(*ast.ParserSeparatedList).Items, $3),
}, },
Use: &ast.NameName{ Use: &ast.NameName{
Node: ast.Node{ Node: ast.Node{
Position: position.NewNodeListPosition($1), Position: position.NewNodeListPosition($1.(*ast.ParserSeparatedList).Items),
}, },
Parts: $1, Parts: $1.(*ast.ParserSeparatedList).Items,
SeparatorTkns: $1.(*ast.ParserSeparatedList).SeparatorTkns,
}, },
AsTkn: $2, AsTkn: $2,
Alias: &ast.Identifier{ Alias: &ast.Identifier{
@ -681,14 +709,15 @@ use_const_declaration:
{ {
$$ = &ast.StmtUseDeclaration{ $$ = &ast.StmtUseDeclaration{
Node: ast.Node{ Node: ast.Node{
Position: position.NewTokenNodeListPosition($1, $2), Position: position.NewTokenNodeListPosition($1, $2.(*ast.ParserSeparatedList).Items),
}, },
NsSeparatorTkn: $1, NsSeparatorTkn: $1,
Use: &ast.NameName{ Use: &ast.NameName{
Node: ast.Node{ Node: ast.Node{
Position: position.NewNodeListPosition($2), Position: position.NewNodeListPosition($2.(*ast.ParserSeparatedList).Items),
}, },
Parts: $2, Parts: $2.(*ast.ParserSeparatedList).Items,
SeparatorTkns: $2.(*ast.ParserSeparatedList).SeparatorTkns,
}, },
} }
} }
@ -701,9 +730,10 @@ use_const_declaration:
NsSeparatorTkn: $1, NsSeparatorTkn: $1,
Use: &ast.NameName{ Use: &ast.NameName{
Node: ast.Node{ Node: ast.Node{
Position: position.NewNodeListPosition($2), Position: position.NewNodeListPosition($2.(*ast.ParserSeparatedList).Items),
}, },
Parts: $2, Parts: $2.(*ast.ParserSeparatedList).Items,
SeparatorTkns: $2.(*ast.ParserSeparatedList).SeparatorTkns,
}, },
AsTkn: $3, AsTkn: $3,
Alias: &ast.Identifier{ Alias: &ast.Identifier{
@ -2888,7 +2918,7 @@ class_constant_declaration:
{ {
constList := $1.(*ast.StmtClassConstList) constList := $1.(*ast.StmtClassConstList)
constList.Node.Position = position.NewNodesPosition($1, $5) constList.Node.Position = position.NewNodesPosition($1, $5)
lastNode($$.(*ast.StmtClassConstList).Consts).(*ast.StmtConstant).CommaTkn = $2 constList.SeparatorTkns = append(constList.SeparatorTkns, $2)
constList.Consts = append(constList.Consts, &ast.StmtConstant{ constList.Consts = append(constList.Consts, &ast.StmtConstant{
Node: ast.Node{ Node: ast.Node{
Position: position.NewTokenNodePosition($3, $5), Position: position.NewTokenNodePosition($3, $5),
@ -4165,13 +4195,14 @@ function_call:
{ {
$$ = &ast.ExprFunctionCall{ $$ = &ast.ExprFunctionCall{
Node: ast.Node{ Node: ast.Node{
Position: position.NewNodeListNodePosition($1, $2), Position: position.NewNodeListNodePosition($1.(*ast.ParserSeparatedList).Items, $2),
}, },
Function: &ast.NameName{ Function: &ast.NameName{
Node: ast.Node{ Node: ast.Node{
Position: position.NewNodeListPosition($1), Position: position.NewNodeListPosition($1.(*ast.ParserSeparatedList).Items),
}, },
Parts: $1, Parts: $1.(*ast.ParserSeparatedList).Items,
SeparatorTkns: $1.(*ast.ParserSeparatedList).SeparatorTkns,
}, },
OpenParenthesisTkn: $2.(*ast.ArgumentList).OpenParenthesisTkn, OpenParenthesisTkn: $2.(*ast.ArgumentList).OpenParenthesisTkn,
Arguments: $2.(*ast.ArgumentList).Arguments, Arguments: $2.(*ast.ArgumentList).Arguments,
@ -4187,11 +4218,12 @@ function_call:
}, },
Function: &ast.NameRelative{ Function: &ast.NameRelative{
Node: ast.Node{ Node: ast.Node{
Position: position.NewTokenNodeListPosition($1, $3), Position: position.NewTokenNodeListPosition($1, $3.(*ast.ParserSeparatedList).Items),
}, },
NsTkn: $1, NsTkn: $1,
NsSeparatorTkn: $2, NsSeparatorTkn: $2,
Parts: $3, Parts: $3.(*ast.ParserSeparatedList).Items,
SeparatorTkns: $3.(*ast.ParserSeparatedList).SeparatorTkns,
}, },
OpenParenthesisTkn: $4.(*ast.ArgumentList).OpenParenthesisTkn, OpenParenthesisTkn: $4.(*ast.ArgumentList).OpenParenthesisTkn,
Arguments: $4.(*ast.ArgumentList).Arguments, Arguments: $4.(*ast.ArgumentList).Arguments,
@ -4207,10 +4239,11 @@ function_call:
}, },
Function: &ast.NameFullyQualified{ Function: &ast.NameFullyQualified{
Node: ast.Node{ Node: ast.Node{
Position: position.NewTokenNodeListPosition($1, $2), Position: position.NewTokenNodeListPosition($1, $2.(*ast.ParserSeparatedList).Items),
}, },
NsSeparatorTkn: $1, NsSeparatorTkn: $1,
Parts: $2, Parts: $2.(*ast.ParserSeparatedList).Items,
SeparatorTkns: $2.(*ast.ParserSeparatedList).SeparatorTkns,
}, },
OpenParenthesisTkn: $3.(*ast.ArgumentList).OpenParenthesisTkn, OpenParenthesisTkn: $3.(*ast.ArgumentList).OpenParenthesisTkn,
Arguments: $3.(*ast.ArgumentList).Arguments, Arguments: $3.(*ast.ArgumentList).Arguments,
@ -4308,30 +4341,33 @@ class_name:
{ {
$$ = &ast.NameName{ $$ = &ast.NameName{
Node: ast.Node{ Node: ast.Node{
Position: position.NewNodeListPosition($1), Position: position.NewNodeListPosition($1.(*ast.ParserSeparatedList).Items),
}, },
Parts: $1, Parts: $1.(*ast.ParserSeparatedList).Items,
SeparatorTkns: $1.(*ast.ParserSeparatedList).SeparatorTkns,
} }
} }
| T_NAMESPACE T_NS_SEPARATOR namespace_name | T_NAMESPACE T_NS_SEPARATOR namespace_name
{ {
$$ = &ast.NameRelative{ $$ = &ast.NameRelative{
Node: ast.Node{ Node: ast.Node{
Position: position.NewTokenNodeListPosition($1, $3), Position: position.NewTokenNodeListPosition($1, $3.(*ast.ParserSeparatedList).Items),
}, },
NsTkn: $1, NsTkn: $1,
NsSeparatorTkn: $2, NsSeparatorTkn: $2,
Parts: $3, Parts: $3.(*ast.ParserSeparatedList).Items,
SeparatorTkns: $3.(*ast.ParserSeparatedList).SeparatorTkns,
} }
} }
| T_NS_SEPARATOR namespace_name | T_NS_SEPARATOR namespace_name
{ {
$$ = &ast.NameFullyQualified{ $$ = &ast.NameFullyQualified{
Node: ast.Node{ Node: ast.Node{
Position: position.NewTokenNodeListPosition($1, $2), Position: position.NewTokenNodeListPosition($1, $2.(*ast.ParserSeparatedList).Items),
}, },
NsSeparatorTkn: $1, NsSeparatorTkn: $1,
Parts: $2, Parts: $2.(*ast.ParserSeparatedList).Items,
SeparatorTkns: $2.(*ast.ParserSeparatedList).SeparatorTkns,
} }
} }
; ;
@ -4341,30 +4377,33 @@ fully_qualified_class_name:
{ {
$$ = &ast.NameName{ $$ = &ast.NameName{
Node: ast.Node{ Node: ast.Node{
Position: position.NewNodeListPosition($1), Position: position.NewNodeListPosition($1.(*ast.ParserSeparatedList).Items),
}, },
Parts: $1, Parts: $1.(*ast.ParserSeparatedList).Items,
SeparatorTkns: $1.(*ast.ParserSeparatedList).SeparatorTkns,
} }
} }
| T_NAMESPACE T_NS_SEPARATOR namespace_name | T_NAMESPACE T_NS_SEPARATOR namespace_name
{ {
$$ = &ast.NameRelative{ $$ = &ast.NameRelative{
Node: ast.Node{ Node: ast.Node{
Position: position.NewTokenNodeListPosition($1, $3), Position: position.NewTokenNodeListPosition($1, $3.(*ast.ParserSeparatedList).Items),
}, },
NsTkn: $1, NsTkn: $1,
NsSeparatorTkn: $2, NsSeparatorTkn: $2,
Parts: $3, Parts: $3.(*ast.ParserSeparatedList).Items,
SeparatorTkns: $3.(*ast.ParserSeparatedList).SeparatorTkns,
} }
} }
| T_NS_SEPARATOR namespace_name | T_NS_SEPARATOR namespace_name
{ {
$$ = &ast.NameFullyQualified{ $$ = &ast.NameFullyQualified{
Node: ast.Node{ Node: ast.Node{
Position: position.NewTokenNodeListPosition($1, $2), Position: position.NewTokenNodeListPosition($1, $2.(*ast.ParserSeparatedList).Items),
}, },
NsSeparatorTkn: $1, NsSeparatorTkn: $1,
Parts: $2, Parts: $2.(*ast.ParserSeparatedList).Items,
SeparatorTkns: $2.(*ast.ParserSeparatedList).SeparatorTkns,
} }
} }
; ;
@ -4670,13 +4709,14 @@ static_scalar_value:
{ {
$$ = &ast.ExprConstFetch{ $$ = &ast.ExprConstFetch{
Node: ast.Node{ Node: ast.Node{
Position: position.NewNodeListPosition($1), Position: position.NewNodeListPosition($1.(*ast.ParserSeparatedList).Items),
}, },
Const: &ast.NameName{ Const: &ast.NameName{
Node: ast.Node{ Node: ast.Node{
Position: position.NewNodeListPosition($1), Position: position.NewNodeListPosition($1.(*ast.ParserSeparatedList).Items),
}, },
Parts: $1, Parts: $1.(*ast.ParserSeparatedList).Items,
SeparatorTkns: $1.(*ast.ParserSeparatedList).SeparatorTkns,
}, },
} }
} }
@ -4684,15 +4724,16 @@ static_scalar_value:
{ {
$$ = &ast.ExprConstFetch{ $$ = &ast.ExprConstFetch{
Node: ast.Node{ Node: ast.Node{
Position: position.NewTokenNodeListPosition($1, $3), Position: position.NewTokenNodeListPosition($1, $3.(*ast.ParserSeparatedList).Items),
}, },
Const: &ast.NameRelative{ Const: &ast.NameRelative{
Node: ast.Node{ Node: ast.Node{
Position: position.NewTokenNodeListPosition($1, $3), Position: position.NewTokenNodeListPosition($1, $3.(*ast.ParserSeparatedList).Items),
}, },
NsTkn: $1, NsTkn: $1,
NsSeparatorTkn: $2, NsSeparatorTkn: $2,
Parts: $3, Parts: $3.(*ast.ParserSeparatedList).Items,
SeparatorTkns: $3.(*ast.ParserSeparatedList).SeparatorTkns,
}, },
} }
} }
@ -4700,14 +4741,15 @@ static_scalar_value:
{ {
$$ = &ast.ExprConstFetch{ $$ = &ast.ExprConstFetch{
Node: ast.Node{ Node: ast.Node{
Position: position.NewTokenNodeListPosition($1, $2), Position: position.NewTokenNodeListPosition($1, $2.(*ast.ParserSeparatedList).Items),
}, },
Const: &ast.NameFullyQualified{ Const: &ast.NameFullyQualified{
Node: ast.Node{ Node: ast.Node{
Position: position.NewTokenNodeListPosition($1, $2), Position: position.NewTokenNodeListPosition($1, $2.(*ast.ParserSeparatedList).Items),
}, },
NsSeparatorTkn: $1, NsSeparatorTkn: $1,
Parts: $2, Parts: $2.(*ast.ParserSeparatedList).Items,
SeparatorTkns: $2.(*ast.ParserSeparatedList).SeparatorTkns,
}, },
} }
} }
@ -5131,13 +5173,14 @@ general_constant:
{ {
$$ = &ast.ExprConstFetch{ $$ = &ast.ExprConstFetch{
Node: ast.Node{ Node: ast.Node{
Position: position.NewNodeListPosition($1), Position: position.NewNodeListPosition($1.(*ast.ParserSeparatedList).Items),
}, },
Const: &ast.NameName{ Const: &ast.NameName{
Node: ast.Node{ Node: ast.Node{
Position: position.NewNodeListPosition($1), Position: position.NewNodeListPosition($1.(*ast.ParserSeparatedList).Items),
}, },
Parts: $1, Parts: $1.(*ast.ParserSeparatedList).Items,
SeparatorTkns: $1.(*ast.ParserSeparatedList).SeparatorTkns,
}, },
} }
} }
@ -5145,15 +5188,16 @@ general_constant:
{ {
$$ = &ast.ExprConstFetch{ $$ = &ast.ExprConstFetch{
Node: ast.Node{ Node: ast.Node{
Position: position.NewTokenNodeListPosition($1, $3), Position: position.NewTokenNodeListPosition($1, $3.(*ast.ParserSeparatedList).Items),
}, },
Const: &ast.NameRelative{ Const: &ast.NameRelative{
Node: ast.Node{ Node: ast.Node{
Position: position.NewTokenNodeListPosition($1, $3), Position: position.NewTokenNodeListPosition($1, $3.(*ast.ParserSeparatedList).Items),
}, },
NsTkn: $1, NsTkn: $1,
NsSeparatorTkn: $2, NsSeparatorTkn: $2,
Parts: $3, Parts: $3.(*ast.ParserSeparatedList).Items,
SeparatorTkns: $3.(*ast.ParserSeparatedList).SeparatorTkns,
}, },
} }
} }
@ -5161,14 +5205,15 @@ general_constant:
{ {
$$ = &ast.ExprConstFetch{ $$ = &ast.ExprConstFetch{
Node: ast.Node{ Node: ast.Node{
Position: position.NewTokenNodeListPosition($1, $2), Position: position.NewTokenNodeListPosition($1, $2.(*ast.ParserSeparatedList).Items),
}, },
Const: &ast.NameFullyQualified{ Const: &ast.NameFullyQualified{
Node: ast.Node{ Node: ast.Node{
Position: position.NewTokenNodeListPosition($1, $2), Position: position.NewTokenNodeListPosition($1, $2.(*ast.ParserSeparatedList).Items),
}, },
NsSeparatorTkn: $1, NsSeparatorTkn: $1,
Parts: $2, Parts: $2.(*ast.ParserSeparatedList).Items,
SeparatorTkns: $2.(*ast.ParserSeparatedList).SeparatorTkns,
}, },
} }
} }

BIN
internal/php7/php7.go generated

Binary file not shown.

View File

@ -14,10 +14,7 @@ import (
%union{ %union{
node ast.Vertex node ast.Vertex
token *token.Token token *token.Token
tkn *token.Token
list []ast.Vertex list []ast.Vertex
ClosureUse *ast.ExprClosureUse
} }
%token <token> T_INCLUDE %token <token> T_INCLUDE
@ -247,9 +244,9 @@ import (
%type <node> callable_expr callable_variable static_member new_variable %type <node> callable_expr callable_variable static_member new_variable
%type <node> encaps_var encaps_var_offset echo_expr_list catch_name_list name_list %type <node> encaps_var encaps_var_offset echo_expr_list catch_name_list name_list
%type <node> if_stmt const_list non_empty_argument_list property_list %type <node> if_stmt const_list non_empty_argument_list property_list
%type <node> alt_if_stmt lexical_var_list isset_variables %type <node> alt_if_stmt lexical_var_list isset_variables class_const_list
%type <node> if_stmt_without_else %type <node> if_stmt_without_else unprefixed_use_declarations inline_use_declarations use_declarations
%type <node> class_const_decl %type <node> class_const_decl namespace_name
%type <node> alt_if_stmt_without_else %type <node> alt_if_stmt_without_else
%type <node> array_pair possible_array_pair %type <node> array_pair possible_array_pair
%type <node> isset_variable type return_type type_expr %type <node> isset_variable type return_type type_expr
@ -264,17 +261,15 @@ import (
%type <node> extends_from %type <node> extends_from
%type <node> implements_list %type <node> implements_list
%type <node> interface_extends_list %type <node> interface_extends_list
%type <ClosureUse> lexical_vars %type <node> lexical_vars
%type <node> member_modifier %type <node> member_modifier
%type <node> use_type %type <node> use_type
%type <node> foreach_variable %type <node> foreach_variable
%type <list> encaps_list backticks_expr namespace_name catch_list class_const_list %type <list> encaps_list backticks_expr catch_list
%type <list> unprefixed_use_declarations inline_use_declarations
%type <list> case_list trait_adaptation_list %type <list> case_list trait_adaptation_list
%type <list> use_declarations
%type <list> top_statement_list %type <list> top_statement_list
%type <list> inner_statement_list class_statement_list %type <list> inner_statement_list class_statement_list
%type <list> method_modifiers variable_modifiers %type <list> method_modifiers variable_modifiers
@ -342,26 +337,32 @@ top_statement_list:
namespace_name: namespace_name:
T_STRING T_STRING
{ {
$$ = []ast.Vertex{ $$ = &ast.ParserSeparatedList{
&ast.NameNamePart{ Items: []ast.Vertex{
Node: ast.Node{ &ast.NameNamePart{
Position: position.NewTokenPosition($1), Node: ast.Node{
Position: position.NewTokenPosition($1),
},
StringTkn: $1,
Value: $1.Value,
}, },
StringTkn: $1,
Value: $1.Value,
}, },
} }
} }
| namespace_name T_NS_SEPARATOR T_STRING | namespace_name T_NS_SEPARATOR T_STRING
{ {
$$ = append($1, &ast.NameNamePart{ part := &ast.NameNamePart{
Node: ast.Node{ Node: ast.Node{
Position: position.NewTokensPosition($2, $3), Position: position.NewTokenPosition($3),
}, },
NsSeparatorTkn: $2,
StringTkn: $3, StringTkn: $3,
Value: $3.Value, Value: $3.Value,
}) }
$1.(*ast.ParserSeparatedList).SeparatorTkns = append($1.(*ast.ParserSeparatedList).SeparatorTkns, $2)
$1.(*ast.ParserSeparatedList).Items = append($1.(*ast.ParserSeparatedList).Items, part)
$$ = $1
} }
; ;
@ -370,30 +371,33 @@ name:
{ {
$$ = &ast.NameName{ $$ = &ast.NameName{
Node: ast.Node{ Node: ast.Node{
Position: position.NewNodeListPosition($1), Position: position.NewNodeListPosition($1.(*ast.ParserSeparatedList).Items),
}, },
Parts: $1, Parts: $1.(*ast.ParserSeparatedList).Items,
SeparatorTkns: $1.(*ast.ParserSeparatedList).SeparatorTkns,
} }
} }
| T_NAMESPACE T_NS_SEPARATOR namespace_name | T_NAMESPACE T_NS_SEPARATOR namespace_name
{ {
$$ = &ast.NameRelative{ $$ = &ast.NameRelative{
Node: ast.Node{ Node: ast.Node{
Position: position.NewTokenNodeListPosition($1, $3), Position: position.NewTokenNodeListPosition($1, $3.(*ast.ParserSeparatedList).Items),
}, },
NsTkn: $1, NsTkn: $1,
NsSeparatorTkn: $2, NsSeparatorTkn: $2,
Parts: $3, Parts: $3.(*ast.ParserSeparatedList).Items,
SeparatorTkns: $3.(*ast.ParserSeparatedList).SeparatorTkns,
} }
} }
| T_NS_SEPARATOR namespace_name | T_NS_SEPARATOR namespace_name
{ {
$$ = &ast.NameFullyQualified{ $$ = &ast.NameFullyQualified{
Node: ast.Node{ Node: ast.Node{
Position: position.NewTokenNodeListPosition($1, $2), Position: position.NewTokenNodeListPosition($1, $2.(*ast.ParserSeparatedList).Items),
}, },
NsSeparatorTkn: $1, NsSeparatorTkn: $1,
Parts: $2, Parts: $2.(*ast.ParserSeparatedList).Items,
SeparatorTkns: $2.(*ast.ParserSeparatedList).SeparatorTkns,
} }
} }
; ;
@ -445,9 +449,10 @@ top_statement:
NsTkn: $1, NsTkn: $1,
Name: &ast.NameName{ Name: &ast.NameName{
Node: ast.Node{ Node: ast.Node{
Position: position.NewNodeListPosition($2), Position: position.NewNodeListPosition($2.(*ast.ParserSeparatedList).Items),
}, },
Parts: $2, Parts: $2.(*ast.ParserSeparatedList).Items,
SeparatorTkns: $2.(*ast.ParserSeparatedList).SeparatorTkns,
}, },
SemiColonTkn: $3, SemiColonTkn: $3,
} }
@ -461,9 +466,10 @@ top_statement:
NsTkn: $1, NsTkn: $1,
Name: &ast.NameName{ Name: &ast.NameName{
Node: ast.Node{ Node: ast.Node{
Position: position.NewNodeListPosition($2), Position: position.NewNodeListPosition($2.(*ast.ParserSeparatedList).Items),
}, },
Parts: $2, Parts: $2.(*ast.ParserSeparatedList).Items,
SeparatorTkns: $2.(*ast.ParserSeparatedList).SeparatorTkns,
}, },
OpenCurlyBracket: $3, OpenCurlyBracket: $3,
Stmts: $4, Stmts: $4,
@ -510,7 +516,8 @@ top_statement:
Position: position.NewTokensPosition($1, $3), Position: position.NewTokensPosition($1, $3),
}, },
UseTkn: $1, UseTkn: $1,
UseDeclarations: $2, UseDeclarations: $2.(*ast.ParserSeparatedList).Items,
SeparatorTkns: $2.(*ast.ParserSeparatedList).SeparatorTkns,
SemiColonTkn: $3, SemiColonTkn: $3,
} }
} }
@ -522,7 +529,8 @@ top_statement:
}, },
UseTkn: $1, UseTkn: $1,
Type: $2, Type: $2,
UseDeclarations: $3, UseDeclarations: $3.(*ast.ParserSeparatedList).Items,
SeparatorTkns: $3.(*ast.ParserSeparatedList).SeparatorTkns,
SemiColonTkn: $4, SemiColonTkn: $4,
} }
} }
@ -566,29 +574,29 @@ use_type:
group_use_declaration: group_use_declaration:
namespace_name T_NS_SEPARATOR '{' unprefixed_use_declarations possible_comma '}' namespace_name T_NS_SEPARATOR '{' unprefixed_use_declarations possible_comma '}'
{ {
if len($4) > 0 { $4.(*ast.ParserSeparatedList).SeparatorTkns = append($4.(*ast.ParserSeparatedList).SeparatorTkns, $5)
$4[len($4)-1].(*ast.StmtUseDeclaration).CommaTkn = $5
}
$$ = &ast.StmtGroupUse{ $$ = &ast.StmtGroupUse{
Node: ast.Node{ Node: ast.Node{
Position: position.NewNodeListTokenPosition($1, $6), Position: position.NewNodeListTokenPosition($1.(*ast.ParserSeparatedList).Items, $6),
}, },
Prefix: &ast.NameName{ Prefix: &ast.NameName{
Node: ast.Node{ Node: ast.Node{
Position: position.NewNodeListPosition($1), Position: position.NewNodeListPosition($1.(*ast.ParserSeparatedList).Items),
}, },
Parts: $1, Parts: $1.(*ast.ParserSeparatedList).Items,
SeparatorTkns: $1.(*ast.ParserSeparatedList).SeparatorTkns,
}, },
NsSeparatorTkn: $2, NsSeparatorTkn: $2,
OpenCurlyBracketTkn: $3, OpenCurlyBracketTkn: $3,
UseDeclarations: $4, UseDeclarations: $4.(*ast.ParserSeparatedList).Items,
SeparatorTkns: $4.(*ast.ParserSeparatedList).SeparatorTkns,
CloseCurlyBracketTkn: $6, CloseCurlyBracketTkn: $6,
} }
} }
| T_NS_SEPARATOR namespace_name T_NS_SEPARATOR '{' unprefixed_use_declarations possible_comma '}' | T_NS_SEPARATOR namespace_name T_NS_SEPARATOR '{' unprefixed_use_declarations possible_comma '}'
{ {
$5[len($5)-1].(*ast.StmtUseDeclaration).CommaTkn = $6 $5.(*ast.ParserSeparatedList).SeparatorTkns = append($5.(*ast.ParserSeparatedList).SeparatorTkns, $6)
$$ = &ast.StmtGroupUse{ $$ = &ast.StmtGroupUse{
Node: ast.Node{ Node: ast.Node{
@ -597,13 +605,15 @@ group_use_declaration:
LeadingNsSeparatorTkn: $1, LeadingNsSeparatorTkn: $1,
Prefix: &ast.NameName{ Prefix: &ast.NameName{
Node: ast.Node{ Node: ast.Node{
Position: position.NewNodeListPosition($2), Position: position.NewNodeListPosition($2.(*ast.ParserSeparatedList).Items),
}, },
Parts: $2, Parts: $2.(*ast.ParserSeparatedList).Items,
SeparatorTkns: $2.(*ast.ParserSeparatedList).SeparatorTkns,
}, },
NsSeparatorTkn: $3, NsSeparatorTkn: $3,
OpenCurlyBracketTkn: $4, OpenCurlyBracketTkn: $4,
UseDeclarations: $5, UseDeclarations: $5.(*ast.ParserSeparatedList).Items,
SeparatorTkns: $5.(*ast.ParserSeparatedList).SeparatorTkns,
CloseCurlyBracketTkn: $7, CloseCurlyBracketTkn: $7,
} }
} }
@ -612,27 +622,29 @@ group_use_declaration:
mixed_group_use_declaration: mixed_group_use_declaration:
namespace_name T_NS_SEPARATOR '{' inline_use_declarations possible_comma '}' namespace_name T_NS_SEPARATOR '{' inline_use_declarations possible_comma '}'
{ {
$4[len($4)-1].(*ast.StmtUseDeclaration).CommaTkn = $5 $4.(*ast.ParserSeparatedList).SeparatorTkns = append($4.(*ast.ParserSeparatedList).SeparatorTkns, $5)
$$ = &ast.StmtGroupUse{ $$ = &ast.StmtGroupUse{
Node: ast.Node{ Node: ast.Node{
Position: position.NewNodeListTokenPosition($1, $6), Position: position.NewNodeListTokenPosition($1.(*ast.ParserSeparatedList).Items, $6),
}, },
Prefix: &ast.NameName{ Prefix: &ast.NameName{
Node: ast.Node{ Node: ast.Node{
Position: position.NewNodeListPosition($1), Position: position.NewNodeListPosition($1.(*ast.ParserSeparatedList).Items),
}, },
Parts: $1, Parts: $1.(*ast.ParserSeparatedList).Items,
SeparatorTkns: $1.(*ast.ParserSeparatedList).SeparatorTkns,
}, },
NsSeparatorTkn: $2, NsSeparatorTkn: $2,
OpenCurlyBracketTkn: $3, OpenCurlyBracketTkn: $3,
UseDeclarations: $4, UseDeclarations: $4.(*ast.ParserSeparatedList).Items,
SeparatorTkns: $4.(*ast.ParserSeparatedList).SeparatorTkns,
CloseCurlyBracketTkn: $6, CloseCurlyBracketTkn: $6,
} }
} }
| T_NS_SEPARATOR namespace_name T_NS_SEPARATOR '{' inline_use_declarations possible_comma '}' | T_NS_SEPARATOR namespace_name T_NS_SEPARATOR '{' inline_use_declarations possible_comma '}'
{ {
$5[len($5)-1].(*ast.StmtUseDeclaration).CommaTkn = $6 $5.(*ast.ParserSeparatedList).SeparatorTkns = append($5.(*ast.ParserSeparatedList).SeparatorTkns, $6)
$$ = &ast.StmtGroupUse{ $$ = &ast.StmtGroupUse{
Node: ast.Node{ Node: ast.Node{
@ -641,13 +653,15 @@ mixed_group_use_declaration:
LeadingNsSeparatorTkn: $1, LeadingNsSeparatorTkn: $1,
Prefix: &ast.NameName{ Prefix: &ast.NameName{
Node: ast.Node{ Node: ast.Node{
Position: position.NewNodeListPosition($2), Position: position.NewNodeListPosition($2.(*ast.ParserSeparatedList).Items),
}, },
Parts: $2, Parts: $2.(*ast.ParserSeparatedList).Items,
SeparatorTkns: $2.(*ast.ParserSeparatedList).SeparatorTkns,
}, },
NsSeparatorTkn: $3, NsSeparatorTkn: $3,
OpenCurlyBracketTkn: $4, OpenCurlyBracketTkn: $4,
UseDeclarations: $5, UseDeclarations: $5.(*ast.ParserSeparatedList).Items,
SeparatorTkns: $5.(*ast.ParserSeparatedList).SeparatorTkns,
CloseCurlyBracketTkn: $7, CloseCurlyBracketTkn: $7,
} }
} }
@ -667,39 +681,48 @@ possible_comma:
inline_use_declarations: inline_use_declarations:
inline_use_declarations ',' inline_use_declaration inline_use_declarations ',' inline_use_declaration
{ {
$1[len($1)-1].(*ast.StmtUseDeclaration).CommaTkn = $2 $1.(*ast.ParserSeparatedList).SeparatorTkns = append($1.(*ast.ParserSeparatedList).SeparatorTkns, $2)
$1.(*ast.ParserSeparatedList).Items = append($1.(*ast.ParserSeparatedList).Items, $3)
$$ = append($1, $3) $$ = $1
} }
| inline_use_declaration | inline_use_declaration
{ {
$$ = []ast.Vertex{$1} $$ = &ast.ParserSeparatedList{
Items: []ast.Vertex{$1},
}
} }
; ;
unprefixed_use_declarations: unprefixed_use_declarations:
unprefixed_use_declarations ',' unprefixed_use_declaration unprefixed_use_declarations ',' unprefixed_use_declaration
{ {
$1[len($1)-1].(*ast.StmtUseDeclaration).CommaTkn = $2 $1.(*ast.ParserSeparatedList).SeparatorTkns = append($1.(*ast.ParserSeparatedList).SeparatorTkns, $2)
$1.(*ast.ParserSeparatedList).Items = append($1.(*ast.ParserSeparatedList).Items, $3)
$$ = append($1, $3) $$ = $1
} }
| unprefixed_use_declaration | unprefixed_use_declaration
{ {
$$ = []ast.Vertex{$1} $$ = &ast.ParserSeparatedList{
Items: []ast.Vertex{$1},
}
} }
; ;
use_declarations: use_declarations:
use_declarations ',' use_declaration use_declarations ',' use_declaration
{ {
$1[len($1)-1].(*ast.StmtUseDeclaration).CommaTkn = $2 $1.(*ast.ParserSeparatedList).SeparatorTkns = append($1.(*ast.ParserSeparatedList).SeparatorTkns, $2)
$1.(*ast.ParserSeparatedList).Items = append($1.(*ast.ParserSeparatedList).Items, $3)
$$ = append($1, $3) $$ = $1
} }
| use_declaration | use_declaration
{ {
$$ = []ast.Vertex{$1} $$ = &ast.ParserSeparatedList{
Items: []ast.Vertex{$1},
}
} }
; ;
@ -723,13 +746,14 @@ unprefixed_use_declaration:
{ {
$$ = &ast.StmtUseDeclaration{ $$ = &ast.StmtUseDeclaration{
Node: ast.Node{ Node: ast.Node{
Position: position.NewNodeListPosition($1), Position: position.NewNodeListPosition($1.(*ast.ParserSeparatedList).Items),
}, },
Use: &ast.NameName{ Use: &ast.NameName{
Node: ast.Node{ Node: ast.Node{
Position: position.NewNodeListPosition($1), Position: position.NewNodeListPosition($1.(*ast.ParserSeparatedList).Items),
}, },
Parts: $1, Parts: $1.(*ast.ParserSeparatedList).Items,
SeparatorTkns: $1.(*ast.ParserSeparatedList).SeparatorTkns,
}, },
} }
} }
@ -737,13 +761,14 @@ unprefixed_use_declaration:
{ {
$$ = &ast.StmtUseDeclaration{ $$ = &ast.StmtUseDeclaration{
Node: ast.Node{ Node: ast.Node{
Position: position.NewNodeListTokenPosition($1, $3), Position: position.NewNodeListTokenPosition($1.(*ast.ParserSeparatedList).Items, $3),
}, },
Use: &ast.NameName{ Use: &ast.NameName{
Node: ast.Node{ Node: ast.Node{
Position: position.NewNodeListPosition($1), Position: position.NewNodeListPosition($1.(*ast.ParserSeparatedList).Items),
}, },
Parts: $1, Parts: $1.(*ast.ParserSeparatedList).Items,
SeparatorTkns: $1.(*ast.ParserSeparatedList).SeparatorTkns,
}, },
AsTkn: $2, AsTkn: $2,
Alias: &ast.Identifier{ Alias: &ast.Identifier{
@ -2156,10 +2181,11 @@ class_statement:
Node: ast.Node{ Node: ast.Node{
Position: position.NewOptionalListTokensPosition($1, $2, $4), Position: position.NewOptionalListTokensPosition($1, $2, $4),
}, },
Modifiers: $1, Modifiers: $1,
ConstTkn: $2, ConstTkn: $2,
Consts: $3, Consts: $3.(*ast.ParserSeparatedList).Items,
SemiColonTkn: $4, SeparatorTkns: $3.(*ast.ParserSeparatedList).SeparatorTkns,
SemiColonTkn: $4,
} }
} }
| T_USE name_list trait_adaptations | T_USE name_list trait_adaptations
@ -2596,13 +2622,16 @@ property:
class_const_list: class_const_list:
class_const_list ',' class_const_decl class_const_list ',' class_const_decl
{ {
lastNode($1).(*ast.StmtConstant).CommaTkn = $2 $1.(*ast.ParserSeparatedList).SeparatorTkns = append($1.(*ast.ParserSeparatedList).SeparatorTkns, $2)
$1.(*ast.ParserSeparatedList).Items = append($1.(*ast.ParserSeparatedList).Items, $3)
$$ = append($1, $3) $$ = $1
} }
| class_const_decl | class_const_decl
{ {
$$ = []ast.Vertex{$1} $$ = &ast.ParserSeparatedList{
Items: []ast.Vertex{$1},
}
} }
; ;

View File

@ -227,10 +227,11 @@ func (n *StmtClass) Accept(v NodeVisitor) {
// StmtClassConstList node // StmtClassConstList node
type StmtClassConstList struct { type StmtClassConstList struct {
Node Node
Modifiers []Vertex Modifiers []Vertex
ConstTkn *token.Token ConstTkn *token.Token
Consts []Vertex Consts []Vertex
SemiColonTkn *token.Token SeparatorTkns []*token.Token
SemiColonTkn *token.Token
} }
func (n *StmtClassConstList) Accept(v NodeVisitor) { func (n *StmtClassConstList) Accept(v NodeVisitor) {
@ -299,7 +300,6 @@ type StmtConstant struct {
Name Vertex Name Vertex
EqualTkn *token.Token EqualTkn *token.Token
Expr Vertex Expr Vertex
CommaTkn *token.Token
} }
func (n *StmtConstant) Accept(v NodeVisitor) { func (n *StmtConstant) Accept(v NodeVisitor) {
@ -856,6 +856,7 @@ type StmtUse struct {
UseTkn *token.Token UseTkn *token.Token
Type Vertex Type Vertex
UseDeclarations []Vertex UseDeclarations []Vertex
SeparatorTkns []*token.Token
SemiColonTkn *token.Token SemiColonTkn *token.Token
} }
@ -873,6 +874,7 @@ type StmtGroupUse struct {
NsSeparatorTkn *token.Token NsSeparatorTkn *token.Token
OpenCurlyBracketTkn *token.Token OpenCurlyBracketTkn *token.Token
UseDeclarations []Vertex UseDeclarations []Vertex
SeparatorTkns []*token.Token
CloseCurlyBracketTkn *token.Token CloseCurlyBracketTkn *token.Token
SemiColonTkn *token.Token SemiColonTkn *token.Token
} }
@ -889,7 +891,6 @@ type StmtUseDeclaration struct {
Use Vertex Use Vertex
AsTkn *token.Token AsTkn *token.Token
Alias Vertex Alias Vertex
CommaTkn *token.Token
} }
func (n *StmtUseDeclaration) Accept(v NodeVisitor) { func (n *StmtUseDeclaration) Accept(v NodeVisitor) {
@ -1029,7 +1030,7 @@ type ExprClosure struct {
Params []Vertex Params []Vertex
SeparatorTkns []*token.Token SeparatorTkns []*token.Token
CloseParenthesisTkn *token.Token CloseParenthesisTkn *token.Token
ClosureUse *ExprClosureUse ClosureUse Vertex
ColonTkn *token.Token ColonTkn *token.Token
ReturnType Vertex ReturnType Vertex
OpenCurlyBracketTkn *token.Token OpenCurlyBracketTkn *token.Token
@ -2017,8 +2018,8 @@ func (n *ExprBinarySpaceship) Accept(v NodeVisitor) {
type NameName struct { type NameName struct {
Node Node
Parts []Vertex Parts []Vertex
ListSeparatorTkn *token.Token SeparatorTkns []*token.Token
} }
func (n *NameName) Accept(v NodeVisitor) { func (n *NameName) Accept(v NodeVisitor) {
@ -2027,9 +2028,9 @@ func (n *NameName) Accept(v NodeVisitor) {
type NameFullyQualified struct { type NameFullyQualified struct {
Node Node
NsSeparatorTkn *token.Token NsSeparatorTkn *token.Token
Parts []Vertex Parts []Vertex
ListSeparatorTkn *token.Token SeparatorTkns []*token.Token
} }
func (n *NameFullyQualified) Accept(v NodeVisitor) { func (n *NameFullyQualified) Accept(v NodeVisitor) {
@ -2038,10 +2039,10 @@ func (n *NameFullyQualified) Accept(v NodeVisitor) {
type NameRelative struct { type NameRelative struct {
Node Node
NsTkn *token.Token NsTkn *token.Token
NsSeparatorTkn *token.Token NsSeparatorTkn *token.Token
Parts []Vertex Parts []Vertex
ListSeparatorTkn *token.Token SeparatorTkns []*token.Token
} }
func (n *NameRelative) Accept(v NodeVisitor) { func (n *NameRelative) Accept(v NodeVisitor) {
@ -2050,9 +2051,8 @@ func (n *NameRelative) Accept(v NodeVisitor) {
type NameNamePart struct { type NameNamePart struct {
Node Node
NsSeparatorTkn *token.Token StringTkn *token.Token
StringTkn *token.Token Value []byte
Value []byte
} }
func (n *NameNamePart) Accept(v NodeVisitor) { func (n *NameNamePart) Accept(v NodeVisitor) {

View File

@ -572,7 +572,6 @@ func (v *Dump) StmtUseDeclaration(n *ast.StmtUseDeclaration) {
v.printNode(n.GetNode()) v.printNode(n.GetNode())
v.printToken("NsSeparatorTkn", n.NsSeparatorTkn) v.printToken("NsSeparatorTkn", n.NsSeparatorTkn)
v.printToken("AsTkn", n.AsTkn) v.printToken("AsTkn", n.AsTkn)
v.printToken("CommaTkn", n.CommaTkn)
} }
func (v *Dump) StmtWhile(n *ast.StmtWhile) { func (v *Dump) StmtWhile(n *ast.StmtWhile) {

File diff suppressed because it is too large Load Diff

View File

@ -1,276 +0,0 @@
package visitor
import (
"github.com/z7zmey/php-parser/pkg/ast"
)
type FilterTokens struct {
Null
}
func (v *FilterTokens) EnterNode(n ast.Vertex) bool {
n.GetNode().Tokens = nil
n.Accept(v)
return true
}
func (v *FilterTokens) StmtUse(n *ast.StmtUse) {
n.UseTkn = nil
n.SemiColonTkn = nil
}
func (v *FilterTokens) StmtGroupUse(n *ast.StmtGroupUse) {
n.UseTkn = nil
n.LeadingNsSeparatorTkn = nil
n.NsSeparatorTkn = nil
n.OpenCurlyBracketTkn = nil
n.CloseCurlyBracketTkn = nil
n.SemiColonTkn = nil
}
func (v *FilterTokens) StmtUseDeclaration(n *ast.StmtUseDeclaration) {
n.NsSeparatorTkn = nil
n.AsTkn = nil
n.CommaTkn = nil
}
func (v *FilterTokens) NameNamePart(n *ast.NameNamePart) {
n.NsSeparatorTkn = nil
n.StringTkn = nil
}
func (v *FilterTokens) NameName(n *ast.NameName) {
n.ListSeparatorTkn = nil
}
func (v *FilterTokens) NameFullyQualified(n *ast.NameFullyQualified) {
n.NsSeparatorTkn = nil
n.ListSeparatorTkn = nil
}
func (v *FilterTokens) NameRelative(n *ast.NameRelative) {
n.NsTkn = nil
n.NsSeparatorTkn = nil
n.ListSeparatorTkn = nil
}
func (v *FilterTokens) StmtNamespace(n *ast.StmtNamespace) {
n.NsTkn = nil
n.OpenCurlyBracket = nil
n.CloseCurlyBracket = nil
n.SemiColonTkn = nil
}
func (v *FilterTokens) StmtHaltCompiler(n *ast.StmtHaltCompiler) {
n.HaltCompilerTkn = nil
n.OpenParenthesisTkn = nil
n.CloseParenthesisTkn = nil
n.SemiColonTkn = nil
}
func (v *FilterTokens) StmtConstList(n *ast.StmtConstList) {
n.ConstTkn = nil
n.SeparatorTkns = nil
n.SemiColonTkn = nil
}
func (v *FilterTokens) StmtClassConstList(n *ast.StmtClassConstList) {
n.ConstTkn = nil
n.SemiColonTkn = nil
}
func (v *FilterTokens) StmtConstant(n *ast.StmtConstant) {
n.EqualTkn = nil
n.CommaTkn = nil
}
func (v *FilterTokens) StmtStmtList(n *ast.StmtStmtList) {
n.OpenCurlyBracket = nil
n.CloseCurlyBracket = nil
}
func (v *FilterTokens) StmtIf(n *ast.StmtIf) {
n.IfTkn = nil
n.OpenParenthesisTkn = nil
n.CloseParenthesisTkn = nil
n.ColonTkn = nil
n.EndIfTkn = nil
n.SemiColonTkn = nil
}
func (v *FilterTokens) StmtElseIf(n *ast.StmtElseIf) {
n.ElseIfTkn = nil
n.OpenParenthesisTkn = nil
n.CloseParenthesisTkn = nil
n.ColonTkn = nil
}
func (v *FilterTokens) StmtElse(n *ast.StmtElse) {
n.ElseTkn = nil
n.ColonTkn = nil
}
func (v *FilterTokens) ParserBrackets(n *ast.ParserBrackets) {
n.OpenBracketTkn = nil
n.CloseBracketTkn = nil
}
func (v *FilterTokens) StmtWhile(n *ast.StmtWhile) {
n.WhileTkn = nil
n.OpenParenthesisTkn = nil
n.CloseParenthesisTkn = nil
n.ColonTkn = nil
n.EndWhileTkn = nil
n.SemiColonTkn = nil
}
func (v *FilterTokens) StmtDo(n *ast.StmtDo) {
n.DoTkn = nil
n.WhileTkn = nil
n.OpenParenthesisTkn = nil
n.CloseParenthesisTkn = nil
n.SemiColonTkn = nil
}
func (v *FilterTokens) StmtFor(n *ast.StmtFor) {
n.ForTkn = nil
n.OpenParenthesisTkn = nil
n.InitSemiColonTkn = nil
n.CondSemiColonTkn = nil
n.CloseParenthesisTkn = nil
n.ColonTkn = nil
n.EndForTkn = nil
n.SemiColonTkn = nil
}
func (v *FilterTokens) StmtSwitch(n *ast.StmtSwitch) {
n.SwitchTkn = nil
n.OpenParenthesisTkn = nil
n.CloseParenthesisTkn = nil
n.OpenCurlyBracketTkn = nil
n.CaseSeparatorTkn = nil
n.ColonTkn = nil
n.CloseCurlyBracketTkn = nil
n.EndSwitchTkn = nil
n.SemiColonTkn = nil
}
func (v *FilterTokens) StmtCase(n *ast.StmtCase) {
n.CaseTkn = nil
n.CaseSeparatorTkn = nil
}
func (v *FilterTokens) StmtDefault(n *ast.StmtDefault) {
n.DefaultTkn = nil
n.CaseSeparatorTkn = nil
}
func (v *FilterTokens) StmtBreak(n *ast.StmtBreak) {
n.BreakTkn = nil
n.SemiColonTkn = nil
}
func (v *FilterTokens) StmtContinue(n *ast.StmtContinue) {
n.ContinueTkn = nil
n.SemiColonTkn = nil
}
func (v *FilterTokens) StmtReturn(n *ast.StmtReturn) {
n.ReturnTkn = nil
n.SemiColonTkn = nil
}
func (v *FilterTokens) StmtGlobal(n *ast.StmtGlobal) {
n.GlobalTkn = nil
n.SeparatorTkns = nil
n.SemiColonTkn = nil
}
func (v *FilterTokens) StmtStatic(n *ast.StmtStatic) {
n.StaticTkn = nil
n.SeparatorTkns = nil
n.SemiColonTkn = nil
}
func (v *FilterTokens) StmtStaticVar(n *ast.StmtStaticVar) {
n.EqualTkn = nil
}
func (v *FilterTokens) StmtEcho(n *ast.StmtEcho) {
n.EchoTkn = nil
n.SeparatorTkns = nil
n.SemiColonTkn = nil
}
func (v *FilterTokens) StmtInlineHtml(n *ast.StmtInlineHtml) {
n.InlineHtmlTkn = nil
}
func (v *FilterTokens) StmtUnset(n *ast.StmtUnset) {
n.UnsetTkn = nil
n.OpenParenthesisTkn = nil
n.SeparatorTkns = nil
n.CloseParenthesisTkn = nil
n.SemiColonTkn = nil
n.SemiColonTkn = nil
}
func (v *FilterTokens) StmtForeach(n *ast.StmtForeach) {
n.ForeachTkn = nil
n.OpenParenthesisTkn = nil
n.AsTkn = nil
n.DoubleArrowTkn = nil
n.CloseParenthesisTkn = nil
n.ColonTkn = nil
n.EndForeachTkn = nil
n.SemiColonTkn = nil
}
func (v *FilterTokens) StmtDeclare(n *ast.StmtDeclare) {
n.DeclareTkn = nil
n.OpenParenthesisTkn = nil
n.SeparatorTkns = nil
n.CloseParenthesisTkn = nil
n.ColonTkn = nil
n.EndDeclareTkn = nil
n.SemiColonTkn = nil
}
func (v *FilterTokens) StmtNop(n *ast.StmtNop) {
n.SemiColonTkn = nil
}
func (v *FilterTokens) StmtTry(n *ast.StmtTry) {
n.TryTkn = nil
n.OpenCurlyBracket = nil
n.CloseCurlyBracket = nil
}
func (v *FilterTokens) StmtCatch(n *ast.StmtCatch) {
n.CatchTkn = nil
n.OpenParenthesisTkn = nil
n.SeparatorTkns = nil
n.CloseParenthesisTkn = nil
n.OpenCurlyBracketTkn = nil
n.CloseCurlyBracketTkn = nil
}
func (v *FilterTokens) StmtFinally(n *ast.StmtFinally) {
n.FinallyTkn = nil
n.OpenCurlyBracketTkn = nil
n.CloseCurlyBracketTkn = nil
}
func (v *FilterTokens) StmtThrow(n *ast.StmtThrow) {
n.ThrowTkn = nil
n.SemiColonTkn = nil
}
func (v *FilterTokens) StmtGoto(n *ast.StmtGoto) {
n.GotoTkn = nil
n.SemiColonTkn = nil
}
func (v *FilterTokens) StmtLabel(n *ast.StmtLabel) {
n.ColonTkn = nil
}

View File

@ -550,7 +550,6 @@ func (p *Printer) printNodeArgument(n ast.Vertex) {
// name // name
func (p *Printer) printNameNamePart(n *ast.NameNamePart) { func (p *Printer) printNameNamePart(n *ast.NameNamePart) {
p.printToken(n.NsSeparatorTkn, "")
p.printToken(n.StringTkn, string(n.Value)) p.printToken(n.StringTkn, string(n.Value))
} }
@ -558,8 +557,6 @@ func (p *Printer) printNameName(n *ast.NameName) {
p.printFreeFloating(n, token.Start) p.printFreeFloating(n, token.Start)
p.joinPrintRefactored("\\", n.Parts) p.joinPrintRefactored("\\", n.Parts)
p.printToken(n.ListSeparatorTkn, "")
} }
func (p *Printer) printNameFullyQualified(n *ast.NameFullyQualified) { func (p *Printer) printNameFullyQualified(n *ast.NameFullyQualified) {
@ -567,8 +564,6 @@ func (p *Printer) printNameFullyQualified(n *ast.NameFullyQualified) {
p.printToken(n.NsSeparatorTkn, "\\") p.printToken(n.NsSeparatorTkn, "\\")
p.joinPrintRefactored("\\", n.Parts) p.joinPrintRefactored("\\", n.Parts)
p.printToken(n.ListSeparatorTkn, "")
} }
func (p *Printer) printNameRelative(n *ast.NameRelative) { func (p *Printer) printNameRelative(n *ast.NameRelative) {
@ -577,8 +572,6 @@ func (p *Printer) printNameRelative(n *ast.NameRelative) {
p.printToken(n.NsSeparatorTkn, "\\") p.printToken(n.NsSeparatorTkn, "\\")
p.joinPrintRefactored("\\", n.Parts) p.joinPrintRefactored("\\", n.Parts)
p.printToken(n.ListSeparatorTkn, "")
} }
// scalar // scalar
@ -2099,7 +2092,6 @@ func (p *Printer) printStmtConstant(n *ast.StmtConstant) {
p.Print(n.Name) p.Print(n.Name)
p.printToken(n.EqualTkn, "=") p.printToken(n.EqualTkn, "=")
p.Print(n.Expr) p.Print(n.Expr)
p.printToken(n.CommaTkn, "")
} }
func (p *Printer) printStmtContinue(n *ast.StmtContinue) { func (p *Printer) printStmtContinue(n *ast.StmtContinue) {
@ -2795,7 +2787,6 @@ func (p *Printer) printStmtUseDeclaration(n *ast.StmtUseDeclaration) {
p.Print(n.Use) p.Print(n.Use)
if n.Alias == nil { if n.Alias == nil {
p.printToken(n.CommaTkn, "")
return return
} }
@ -2804,8 +2795,6 @@ func (p *Printer) printStmtUseDeclaration(n *ast.StmtUseDeclaration) {
p.bufStart = " " p.bufStart = " "
p.Print(n.Alias) p.Print(n.Alias)
p.printToken(n.CommaTkn, "")
} }
func (p *Printer) printStmtWhile(n *ast.StmtWhile) { func (p *Printer) printStmtWhile(n *ast.StmtWhile) {