diff --git a/internal/php5/php5.go b/internal/php5/php5.go index bff63f6..7f98c48 100644 Binary files a/internal/php5/php5.go and b/internal/php5/php5.go differ diff --git a/internal/php5/php5.y b/internal/php5/php5.y index 2a24915..4027440 100644 --- a/internal/php5/php5.y +++ b/internal/php5/php5.y @@ -15,8 +15,6 @@ import ( node ast.Vertex token *token.Token list []ast.Vertex - - ClosureUse *ast.ExprClosureUse } %token T_INCLUDE @@ -219,6 +217,7 @@ import ( %type function interface_entry %type possible_comma %type case_separator +%type is_reference is_variadic %type top_statement use_declaration use_function_declaration use_const_declaration common_scalar %type static_class_constant compound_variable reference_variable class_name variable_class_name @@ -241,12 +240,12 @@ import ( %type method_body trait_reference_list static_array_pair_list non_empty_static_array_pair_list %type foreach_statement for_statement while_statement isset_variables %type foreach_variable foreach_optional_arg for_expr non_empty_for_expr -%type extends_from interface_list trait_list -%type implements_list +%type extends_from interface_list trait_list namespace_name +%type implements_list use_declarations use_function_declarations use_const_declarations %type interface_extends_list -%type lexical_vars +%type lexical_vars -%type top_statement_list namespace_name use_declarations use_function_declarations use_const_declarations +%type top_statement_list %type inner_statement_list encaps_list %type elseif_list new_elseif_list %type case_list catch_statement additional_catches @@ -260,7 +259,6 @@ import ( %type dynamic_class_name_variable_properties variable_properties %type simple_indirect_reference -%type is_reference is_variadic %% @@ -293,26 +291,32 @@ top_statement_list: namespace_name: T_STRING { - $$ = []ast.Vertex{ - &ast.NameNamePart{ - Node: ast.Node{ - Position: position.NewTokenPosition($1), + $$ = &ast.ParserSeparatedList{ + Items: []ast.Vertex{ + &ast.NameNamePart{ + Node: ast.Node{ + Position: position.NewTokenPosition($1), + }, + StringTkn: $1, + Value: $1.Value, }, - StringTkn: $1, - Value: $1.Value, }, } } | namespace_name T_NS_SEPARATOR T_STRING { - $$ = append($1, &ast.NameNamePart{ + part := &ast.NameNamePart{ Node: ast.Node{ - Position: position.NewTokensPosition($2, $3), + Position: position.NewTokenPosition($3), }, - NsSeparatorTkn: $2, StringTkn: $3, 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, Name: &ast.NameName{ 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, } @@ -371,9 +376,10 @@ top_statement: NsTkn: $1, Name: &ast.NameName{ 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, Stmts: $4, @@ -399,7 +405,8 @@ top_statement: Position: position.NewTokensPosition($1, $3), }, UseTkn: $1, - UseDeclarations: $2, + UseDeclarations: $2.(*ast.ParserSeparatedList).Items, + SeparatorTkns: $2.(*ast.ParserSeparatedList).SeparatorTkns, SemiColonTkn: $3, } } @@ -417,7 +424,8 @@ top_statement: IdentifierTkn: $2, Value: $2.Value, }, - UseDeclarations: $3, + UseDeclarations: $3.(*ast.ParserSeparatedList).Items, + SeparatorTkns: $3.(*ast.ParserSeparatedList).SeparatorTkns, SemiColonTkn: $4, } } @@ -435,7 +443,8 @@ top_statement: IdentifierTkn: $2, Value: $2.Value, }, - UseDeclarations: $3, + UseDeclarations: $3.(*ast.ParserSeparatedList).Items, + SeparatorTkns: $3.(*ast.ParserSeparatedList).SeparatorTkns, SemiColonTkn: $4, } } @@ -450,13 +459,16 @@ top_statement: use_declarations: 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 { - $$ = []ast.Vertex{$1} + $$ = &ast.ParserSeparatedList{ + Items: []ast.Vertex{$1}, + } } ; @@ -465,13 +477,14 @@ use_declaration: { $$ = &ast.StmtUseDeclaration{ Node: ast.Node{ - Position: position.NewNodeListPosition($1), + Position: position.NewNodeListPosition($1.(*ast.ParserSeparatedList).Items), }, Use: &ast.NameName{ 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{ Node: ast.Node{ - Position: position.NewNodeListTokenPosition($1, $3), + Position: position.NewNodeListTokenPosition($1.(*ast.ParserSeparatedList).Items, $3), }, Use: &ast.NameName{ 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, Alias: &ast.Identifier{ @@ -501,14 +515,15 @@ use_declaration: { $$ = &ast.StmtUseDeclaration{ Node: ast.Node{ - Position: position.NewTokenNodeListPosition($1, $2), + Position: position.NewTokenNodeListPosition($1, $2.(*ast.ParserSeparatedList).Items), }, NsSeparatorTkn: $1, Use: &ast.NameName{ 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, Use: &ast.NameName{ 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, Alias: &ast.Identifier{ @@ -540,13 +556,16 @@ use_declaration: use_function_declarations: 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 { - $$ = []ast.Vertex{$1} + $$ = &ast.ParserSeparatedList{ + Items: []ast.Vertex{$1}, + } } ; @@ -555,13 +574,14 @@ use_function_declaration: { $$ = &ast.StmtUseDeclaration{ Node: ast.Node{ - Position: position.NewNodeListPosition($1), + Position: position.NewNodeListPosition($1.(*ast.ParserSeparatedList).Items), }, Use: &ast.NameName{ 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{ Node: ast.Node{ - Position: position.NewNodeListTokenPosition($1, $3), + Position: position.NewNodeListTokenPosition($1.(*ast.ParserSeparatedList).Items, $3), }, Use: &ast.NameName{ 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, Alias: &ast.Identifier{ @@ -591,14 +612,15 @@ use_function_declaration: { $$ = &ast.StmtUseDeclaration{ Node: ast.Node{ - Position: position.NewTokenNodeListPosition($1, $2), + Position: position.NewTokenNodeListPosition($1, $2.(*ast.ParserSeparatedList).Items), }, NsSeparatorTkn: $1, Use: &ast.NameName{ 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, Use: &ast.NameName{ 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, Alias: &ast.Identifier{ @@ -630,13 +653,16 @@ use_function_declaration: use_const_declarations: 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 { - $$ = []ast.Vertex{$1} + $$ = &ast.ParserSeparatedList{ + Items: []ast.Vertex{$1}, + } } ; @@ -645,13 +671,14 @@ use_const_declaration: { $$ = &ast.StmtUseDeclaration{ Node: ast.Node{ - Position: position.NewNodeListPosition($1), + Position: position.NewNodeListPosition($1.(*ast.ParserSeparatedList).Items), }, Use: &ast.NameName{ 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{ Node: ast.Node{ - Position: position.NewNodeListTokenPosition($1, $3), + Position: position.NewNodeListTokenPosition($1.(*ast.ParserSeparatedList).Items, $3), }, Use: &ast.NameName{ 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, Alias: &ast.Identifier{ @@ -681,14 +709,15 @@ use_const_declaration: { $$ = &ast.StmtUseDeclaration{ Node: ast.Node{ - Position: position.NewTokenNodeListPosition($1, $2), + Position: position.NewTokenNodeListPosition($1, $2.(*ast.ParserSeparatedList).Items), }, NsSeparatorTkn: $1, Use: &ast.NameName{ 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, Use: &ast.NameName{ 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, Alias: &ast.Identifier{ @@ -2888,7 +2918,7 @@ class_constant_declaration: { constList := $1.(*ast.StmtClassConstList) 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{ Node: ast.Node{ Position: position.NewTokenNodePosition($3, $5), @@ -4165,13 +4195,14 @@ function_call: { $$ = &ast.ExprFunctionCall{ Node: ast.Node{ - Position: position.NewNodeListNodePosition($1, $2), + Position: position.NewNodeListNodePosition($1.(*ast.ParserSeparatedList).Items, $2), }, Function: &ast.NameName{ 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, Arguments: $2.(*ast.ArgumentList).Arguments, @@ -4187,11 +4218,12 @@ function_call: }, Function: &ast.NameRelative{ Node: ast.Node{ - Position: position.NewTokenNodeListPosition($1, $3), + Position: position.NewTokenNodeListPosition($1, $3.(*ast.ParserSeparatedList).Items), }, NsTkn: $1, NsSeparatorTkn: $2, - Parts: $3, + Parts: $3.(*ast.ParserSeparatedList).Items, + SeparatorTkns: $3.(*ast.ParserSeparatedList).SeparatorTkns, }, OpenParenthesisTkn: $4.(*ast.ArgumentList).OpenParenthesisTkn, Arguments: $4.(*ast.ArgumentList).Arguments, @@ -4207,10 +4239,11 @@ function_call: }, Function: &ast.NameFullyQualified{ Node: ast.Node{ - Position: position.NewTokenNodeListPosition($1, $2), + Position: position.NewTokenNodeListPosition($1, $2.(*ast.ParserSeparatedList).Items), }, NsSeparatorTkn: $1, - Parts: $2, + Parts: $2.(*ast.ParserSeparatedList).Items, + SeparatorTkns: $2.(*ast.ParserSeparatedList).SeparatorTkns, }, OpenParenthesisTkn: $3.(*ast.ArgumentList).OpenParenthesisTkn, Arguments: $3.(*ast.ArgumentList).Arguments, @@ -4308,30 +4341,33 @@ class_name: { $$ = &ast.NameName{ 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 { $$ = &ast.NameRelative{ Node: ast.Node{ - Position: position.NewTokenNodeListPosition($1, $3), + Position: position.NewTokenNodeListPosition($1, $3.(*ast.ParserSeparatedList).Items), }, NsTkn: $1, NsSeparatorTkn: $2, - Parts: $3, + Parts: $3.(*ast.ParserSeparatedList).Items, + SeparatorTkns: $3.(*ast.ParserSeparatedList).SeparatorTkns, } } | T_NS_SEPARATOR namespace_name { $$ = &ast.NameFullyQualified{ Node: ast.Node{ - Position: position.NewTokenNodeListPosition($1, $2), + Position: position.NewTokenNodeListPosition($1, $2.(*ast.ParserSeparatedList).Items), }, NsSeparatorTkn: $1, - Parts: $2, + Parts: $2.(*ast.ParserSeparatedList).Items, + SeparatorTkns: $2.(*ast.ParserSeparatedList).SeparatorTkns, } } ; @@ -4341,30 +4377,33 @@ fully_qualified_class_name: { $$ = &ast.NameName{ 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 { $$ = &ast.NameRelative{ Node: ast.Node{ - Position: position.NewTokenNodeListPosition($1, $3), + Position: position.NewTokenNodeListPosition($1, $3.(*ast.ParserSeparatedList).Items), }, NsTkn: $1, NsSeparatorTkn: $2, - Parts: $3, + Parts: $3.(*ast.ParserSeparatedList).Items, + SeparatorTkns: $3.(*ast.ParserSeparatedList).SeparatorTkns, } } | T_NS_SEPARATOR namespace_name { $$ = &ast.NameFullyQualified{ Node: ast.Node{ - Position: position.NewTokenNodeListPosition($1, $2), + Position: position.NewTokenNodeListPosition($1, $2.(*ast.ParserSeparatedList).Items), }, NsSeparatorTkn: $1, - Parts: $2, + Parts: $2.(*ast.ParserSeparatedList).Items, + SeparatorTkns: $2.(*ast.ParserSeparatedList).SeparatorTkns, } } ; @@ -4670,13 +4709,14 @@ static_scalar_value: { $$ = &ast.ExprConstFetch{ Node: ast.Node{ - Position: position.NewNodeListPosition($1), + Position: position.NewNodeListPosition($1.(*ast.ParserSeparatedList).Items), }, Const: &ast.NameName{ 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{ Node: ast.Node{ - Position: position.NewTokenNodeListPosition($1, $3), + Position: position.NewTokenNodeListPosition($1, $3.(*ast.ParserSeparatedList).Items), }, Const: &ast.NameRelative{ Node: ast.Node{ - Position: position.NewTokenNodeListPosition($1, $3), + Position: position.NewTokenNodeListPosition($1, $3.(*ast.ParserSeparatedList).Items), }, NsTkn: $1, NsSeparatorTkn: $2, - Parts: $3, + Parts: $3.(*ast.ParserSeparatedList).Items, + SeparatorTkns: $3.(*ast.ParserSeparatedList).SeparatorTkns, }, } } @@ -4700,14 +4741,15 @@ static_scalar_value: { $$ = &ast.ExprConstFetch{ Node: ast.Node{ - Position: position.NewTokenNodeListPosition($1, $2), + Position: position.NewTokenNodeListPosition($1, $2.(*ast.ParserSeparatedList).Items), }, Const: &ast.NameFullyQualified{ Node: ast.Node{ - Position: position.NewTokenNodeListPosition($1, $2), + Position: position.NewTokenNodeListPosition($1, $2.(*ast.ParserSeparatedList).Items), }, NsSeparatorTkn: $1, - Parts: $2, + Parts: $2.(*ast.ParserSeparatedList).Items, + SeparatorTkns: $2.(*ast.ParserSeparatedList).SeparatorTkns, }, } } @@ -5131,13 +5173,14 @@ general_constant: { $$ = &ast.ExprConstFetch{ Node: ast.Node{ - Position: position.NewNodeListPosition($1), + Position: position.NewNodeListPosition($1.(*ast.ParserSeparatedList).Items), }, Const: &ast.NameName{ 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{ Node: ast.Node{ - Position: position.NewTokenNodeListPosition($1, $3), + Position: position.NewTokenNodeListPosition($1, $3.(*ast.ParserSeparatedList).Items), }, Const: &ast.NameRelative{ Node: ast.Node{ - Position: position.NewTokenNodeListPosition($1, $3), + Position: position.NewTokenNodeListPosition($1, $3.(*ast.ParserSeparatedList).Items), }, NsTkn: $1, NsSeparatorTkn: $2, - Parts: $3, + Parts: $3.(*ast.ParserSeparatedList).Items, + SeparatorTkns: $3.(*ast.ParserSeparatedList).SeparatorTkns, }, } } @@ -5161,14 +5205,15 @@ general_constant: { $$ = &ast.ExprConstFetch{ Node: ast.Node{ - Position: position.NewTokenNodeListPosition($1, $2), + Position: position.NewTokenNodeListPosition($1, $2.(*ast.ParserSeparatedList).Items), }, Const: &ast.NameFullyQualified{ Node: ast.Node{ - Position: position.NewTokenNodeListPosition($1, $2), + Position: position.NewTokenNodeListPosition($1, $2.(*ast.ParserSeparatedList).Items), }, NsSeparatorTkn: $1, - Parts: $2, + Parts: $2.(*ast.ParserSeparatedList).Items, + SeparatorTkns: $2.(*ast.ParserSeparatedList).SeparatorTkns, }, } } diff --git a/internal/php7/php7.go b/internal/php7/php7.go index c592f8c..e224ae3 100644 Binary files a/internal/php7/php7.go and b/internal/php7/php7.go differ diff --git a/internal/php7/php7.y b/internal/php7/php7.y index bb74f7b..6dd4946 100644 --- a/internal/php7/php7.y +++ b/internal/php7/php7.y @@ -14,10 +14,7 @@ import ( %union{ node ast.Vertex token *token.Token - tkn *token.Token list []ast.Vertex - - ClosureUse *ast.ExprClosureUse } %token T_INCLUDE @@ -247,9 +244,9 @@ import ( %type callable_expr callable_variable static_member new_variable %type encaps_var encaps_var_offset echo_expr_list catch_name_list name_list %type if_stmt const_list non_empty_argument_list property_list -%type alt_if_stmt lexical_var_list isset_variables -%type if_stmt_without_else -%type class_const_decl +%type alt_if_stmt lexical_var_list isset_variables class_const_list +%type if_stmt_without_else unprefixed_use_declarations inline_use_declarations use_declarations +%type class_const_decl namespace_name %type alt_if_stmt_without_else %type array_pair possible_array_pair %type isset_variable type return_type type_expr @@ -264,17 +261,15 @@ import ( %type extends_from %type implements_list %type interface_extends_list -%type lexical_vars +%type lexical_vars %type member_modifier %type use_type %type foreach_variable -%type encaps_list backticks_expr namespace_name catch_list class_const_list -%type unprefixed_use_declarations inline_use_declarations +%type encaps_list backticks_expr catch_list %type case_list trait_adaptation_list -%type use_declarations %type top_statement_list %type inner_statement_list class_statement_list %type method_modifiers variable_modifiers @@ -342,26 +337,32 @@ top_statement_list: namespace_name: T_STRING { - $$ = []ast.Vertex{ - &ast.NameNamePart{ - Node: ast.Node{ - Position: position.NewTokenPosition($1), + $$ = &ast.ParserSeparatedList{ + Items: []ast.Vertex{ + &ast.NameNamePart{ + Node: ast.Node{ + Position: position.NewTokenPosition($1), + }, + StringTkn: $1, + Value: $1.Value, }, - StringTkn: $1, - Value: $1.Value, }, } } | namespace_name T_NS_SEPARATOR T_STRING { - $$ = append($1, &ast.NameNamePart{ + part := &ast.NameNamePart{ Node: ast.Node{ - Position: position.NewTokensPosition($2, $3), + Position: position.NewTokenPosition($3), }, - NsSeparatorTkn: $2, StringTkn: $3, 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{ 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 { $$ = &ast.NameRelative{ Node: ast.Node{ - Position: position.NewTokenNodeListPosition($1, $3), + Position: position.NewTokenNodeListPosition($1, $3.(*ast.ParserSeparatedList).Items), }, NsTkn: $1, NsSeparatorTkn: $2, - Parts: $3, + Parts: $3.(*ast.ParserSeparatedList).Items, + SeparatorTkns: $3.(*ast.ParserSeparatedList).SeparatorTkns, } } | T_NS_SEPARATOR namespace_name { $$ = &ast.NameFullyQualified{ Node: ast.Node{ - Position: position.NewTokenNodeListPosition($1, $2), + Position: position.NewTokenNodeListPosition($1, $2.(*ast.ParserSeparatedList).Items), }, NsSeparatorTkn: $1, - Parts: $2, + Parts: $2.(*ast.ParserSeparatedList).Items, + SeparatorTkns: $2.(*ast.ParserSeparatedList).SeparatorTkns, } } ; @@ -445,9 +449,10 @@ top_statement: NsTkn: $1, Name: &ast.NameName{ 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, } @@ -461,9 +466,10 @@ top_statement: NsTkn: $1, Name: &ast.NameName{ 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, Stmts: $4, @@ -510,7 +516,8 @@ top_statement: Position: position.NewTokensPosition($1, $3), }, UseTkn: $1, - UseDeclarations: $2, + UseDeclarations: $2.(*ast.ParserSeparatedList).Items, + SeparatorTkns: $2.(*ast.ParserSeparatedList).SeparatorTkns, SemiColonTkn: $3, } } @@ -522,7 +529,8 @@ top_statement: }, UseTkn: $1, Type: $2, - UseDeclarations: $3, + UseDeclarations: $3.(*ast.ParserSeparatedList).Items, + SeparatorTkns: $3.(*ast.ParserSeparatedList).SeparatorTkns, SemiColonTkn: $4, } } @@ -566,29 +574,29 @@ use_type: group_use_declaration: namespace_name T_NS_SEPARATOR '{' unprefixed_use_declarations possible_comma '}' { - if len($4) > 0 { - $4[len($4)-1].(*ast.StmtUseDeclaration).CommaTkn = $5 - } + $4.(*ast.ParserSeparatedList).SeparatorTkns = append($4.(*ast.ParserSeparatedList).SeparatorTkns, $5) $$ = &ast.StmtGroupUse{ Node: ast.Node{ - Position: position.NewNodeListTokenPosition($1, $6), + Position: position.NewNodeListTokenPosition($1.(*ast.ParserSeparatedList).Items, $6), }, Prefix: &ast.NameName{ 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, OpenCurlyBracketTkn: $3, - UseDeclarations: $4, + UseDeclarations: $4.(*ast.ParserSeparatedList).Items, + SeparatorTkns: $4.(*ast.ParserSeparatedList).SeparatorTkns, CloseCurlyBracketTkn: $6, } } | 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{ Node: ast.Node{ @@ -597,13 +605,15 @@ group_use_declaration: LeadingNsSeparatorTkn: $1, Prefix: &ast.NameName{ 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, OpenCurlyBracketTkn: $4, - UseDeclarations: $5, + UseDeclarations: $5.(*ast.ParserSeparatedList).Items, + SeparatorTkns: $5.(*ast.ParserSeparatedList).SeparatorTkns, CloseCurlyBracketTkn: $7, } } @@ -612,27 +622,29 @@ group_use_declaration: mixed_group_use_declaration: 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{ Node: ast.Node{ - Position: position.NewNodeListTokenPosition($1, $6), + Position: position.NewNodeListTokenPosition($1.(*ast.ParserSeparatedList).Items, $6), }, Prefix: &ast.NameName{ 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, OpenCurlyBracketTkn: $3, - UseDeclarations: $4, + UseDeclarations: $4.(*ast.ParserSeparatedList).Items, + SeparatorTkns: $4.(*ast.ParserSeparatedList).SeparatorTkns, CloseCurlyBracketTkn: $6, } } | 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{ Node: ast.Node{ @@ -641,13 +653,15 @@ mixed_group_use_declaration: LeadingNsSeparatorTkn: $1, Prefix: &ast.NameName{ 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, OpenCurlyBracketTkn: $4, - UseDeclarations: $5, + UseDeclarations: $5.(*ast.ParserSeparatedList).Items, + SeparatorTkns: $5.(*ast.ParserSeparatedList).SeparatorTkns, CloseCurlyBracketTkn: $7, } } @@ -667,39 +681,48 @@ possible_comma: inline_use_declarations: 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 { - $$ = []ast.Vertex{$1} + $$ = &ast.ParserSeparatedList{ + Items: []ast.Vertex{$1}, + } } ; unprefixed_use_declarations: 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 { - $$ = []ast.Vertex{$1} + $$ = &ast.ParserSeparatedList{ + Items: []ast.Vertex{$1}, + } } ; use_declarations: 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 { - $$ = []ast.Vertex{$1} + $$ = &ast.ParserSeparatedList{ + Items: []ast.Vertex{$1}, + } } ; @@ -723,13 +746,14 @@ unprefixed_use_declaration: { $$ = &ast.StmtUseDeclaration{ Node: ast.Node{ - Position: position.NewNodeListPosition($1), + Position: position.NewNodeListPosition($1.(*ast.ParserSeparatedList).Items), }, Use: &ast.NameName{ 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{ Node: ast.Node{ - Position: position.NewNodeListTokenPosition($1, $3), + Position: position.NewNodeListTokenPosition($1.(*ast.ParserSeparatedList).Items, $3), }, Use: &ast.NameName{ 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, Alias: &ast.Identifier{ @@ -2156,10 +2181,11 @@ class_statement: Node: ast.Node{ Position: position.NewOptionalListTokensPosition($1, $2, $4), }, - Modifiers: $1, - ConstTkn: $2, - Consts: $3, - SemiColonTkn: $4, + Modifiers: $1, + ConstTkn: $2, + Consts: $3.(*ast.ParserSeparatedList).Items, + SeparatorTkns: $3.(*ast.ParserSeparatedList).SeparatorTkns, + SemiColonTkn: $4, } } | T_USE name_list trait_adaptations @@ -2596,13 +2622,16 @@ property: class_const_list: 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 { - $$ = []ast.Vertex{$1} + $$ = &ast.ParserSeparatedList{ + Items: []ast.Vertex{$1}, + } } ; diff --git a/pkg/ast/node.go b/pkg/ast/node.go index 5a71e3d..b375c45 100644 --- a/pkg/ast/node.go +++ b/pkg/ast/node.go @@ -227,10 +227,11 @@ func (n *StmtClass) Accept(v NodeVisitor) { // StmtClassConstList node type StmtClassConstList struct { Node - Modifiers []Vertex - ConstTkn *token.Token - Consts []Vertex - SemiColonTkn *token.Token + Modifiers []Vertex + ConstTkn *token.Token + Consts []Vertex + SeparatorTkns []*token.Token + SemiColonTkn *token.Token } func (n *StmtClassConstList) Accept(v NodeVisitor) { @@ -299,7 +300,6 @@ type StmtConstant struct { Name Vertex EqualTkn *token.Token Expr Vertex - CommaTkn *token.Token } func (n *StmtConstant) Accept(v NodeVisitor) { @@ -856,6 +856,7 @@ type StmtUse struct { UseTkn *token.Token Type Vertex UseDeclarations []Vertex + SeparatorTkns []*token.Token SemiColonTkn *token.Token } @@ -873,6 +874,7 @@ type StmtGroupUse struct { NsSeparatorTkn *token.Token OpenCurlyBracketTkn *token.Token UseDeclarations []Vertex + SeparatorTkns []*token.Token CloseCurlyBracketTkn *token.Token SemiColonTkn *token.Token } @@ -889,7 +891,6 @@ type StmtUseDeclaration struct { Use Vertex AsTkn *token.Token Alias Vertex - CommaTkn *token.Token } func (n *StmtUseDeclaration) Accept(v NodeVisitor) { @@ -1029,7 +1030,7 @@ type ExprClosure struct { Params []Vertex SeparatorTkns []*token.Token CloseParenthesisTkn *token.Token - ClosureUse *ExprClosureUse + ClosureUse Vertex ColonTkn *token.Token ReturnType Vertex OpenCurlyBracketTkn *token.Token @@ -2017,8 +2018,8 @@ func (n *ExprBinarySpaceship) Accept(v NodeVisitor) { type NameName struct { Node - Parts []Vertex - ListSeparatorTkn *token.Token + Parts []Vertex + SeparatorTkns []*token.Token } func (n *NameName) Accept(v NodeVisitor) { @@ -2027,9 +2028,9 @@ func (n *NameName) Accept(v NodeVisitor) { type NameFullyQualified struct { Node - NsSeparatorTkn *token.Token - Parts []Vertex - ListSeparatorTkn *token.Token + NsSeparatorTkn *token.Token + Parts []Vertex + SeparatorTkns []*token.Token } func (n *NameFullyQualified) Accept(v NodeVisitor) { @@ -2038,10 +2039,10 @@ func (n *NameFullyQualified) Accept(v NodeVisitor) { type NameRelative struct { Node - NsTkn *token.Token - NsSeparatorTkn *token.Token - Parts []Vertex - ListSeparatorTkn *token.Token + NsTkn *token.Token + NsSeparatorTkn *token.Token + Parts []Vertex + SeparatorTkns []*token.Token } func (n *NameRelative) Accept(v NodeVisitor) { @@ -2050,9 +2051,8 @@ func (n *NameRelative) Accept(v NodeVisitor) { type NameNamePart struct { Node - NsSeparatorTkn *token.Token - StringTkn *token.Token - Value []byte + StringTkn *token.Token + Value []byte } func (n *NameNamePart) Accept(v NodeVisitor) { diff --git a/pkg/ast/visitor/dump.go b/pkg/ast/visitor/dump.go index d6546f3..abcf932 100644 --- a/pkg/ast/visitor/dump.go +++ b/pkg/ast/visitor/dump.go @@ -572,7 +572,6 @@ func (v *Dump) StmtUseDeclaration(n *ast.StmtUseDeclaration) { v.printNode(n.GetNode()) v.printToken("NsSeparatorTkn", n.NsSeparatorTkn) v.printToken("AsTkn", n.AsTkn) - v.printToken("CommaTkn", n.CommaTkn) } func (v *Dump) StmtWhile(n *ast.StmtWhile) { diff --git a/pkg/ast/visitor/filter_parser_nodes.go b/pkg/ast/visitor/filter_parser_nodes.go deleted file mode 100644 index 6ccd522..0000000 --- a/pkg/ast/visitor/filter_parser_nodes.go +++ /dev/null @@ -1,1077 +0,0 @@ -package visitor - -import ( - "github.com/z7zmey/php-parser/pkg/ast" -) - -type FilterParserNodes struct { - Null -} - -func (v *FilterParserNodes) EnterNode(n ast.Vertex) bool { - n.Accept(v) - return true -} - -func (v *FilterParserNodes) ExprExit(n *ast.ExprExit) { - for { - if nn, ok := n.Expr.(*ast.ParserBrackets); ok { - n.Expr = nn.Child - } else { - break - } - } -} - -func (v *FilterParserNodes) StmtContinue(n *ast.StmtContinue) { - for { - if nn, ok := n.Expr.(*ast.ParserBrackets); ok { - n.Expr = nn.Child - } else { - break - } - } -} - -func (v *FilterParserNodes) StmtBreak(n *ast.StmtBreak) { - for { - if nn, ok := n.Expr.(*ast.ParserBrackets); ok { - n.Expr = nn.Child - } else { - break - } - } -} - -func (v *FilterParserNodes) ExprClone(n *ast.ExprClone) { - for { - if nn, ok := n.Expr.(*ast.ParserBrackets); ok { - n.Expr = nn.Child - } else { - break - } - } -} - -func (v *FilterParserNodes) ExprPrint(n *ast.ExprPrint) { - for { - if nn, ok := n.Expr.(*ast.ParserBrackets); ok { - n.Expr = nn.Child - } else { - break - } - } -} - -func (v *FilterParserNodes) StmtExpression(n *ast.StmtExpression) { - for { - if nn, ok := n.Expr.(*ast.ParserBrackets); ok { - n.Expr = nn.Child - } else { - break - } - } -} - -func (v *FilterParserNodes) StmtEcho(n *ast.StmtEcho) { - for k, v := range n.Exprs { - for { - if nn, ok := v.(*ast.ParserBrackets); ok { - v = nn.Child - } else { - break - } - } - - n.Exprs[k] = v - } -} - -func (v *FilterParserNodes) ExprIsset(n *ast.ExprIsset) { - for k, v := range n.Vars { - for { - if nn, ok := v.(*ast.ParserBrackets); ok { - v = nn.Child - } else { - break - } - } - - n.Vars[k] = v - } -} - -func (v *FilterParserNodes) StmtReturn(n *ast.StmtReturn) { - for { - if nn, ok := n.Expr.(*ast.ParserBrackets); ok { - n.Expr = nn.Child - } else { - break - } - } -} - -func (v *FilterParserNodes) ExprYield(n *ast.ExprYield) { - for { - if nn, ok := n.Key.(*ast.ParserBrackets); ok { - n.Key = nn.Child - } else { - break - } - } - - for { - if nn, ok := n.Value.(*ast.ParserBrackets); ok { - n.Value = nn.Child - } else { - break - } - } -} - -func (v *FilterParserNodes) Argument(n *ast.Argument) { - for { - if nn, ok := n.Expr.(*ast.ParserBrackets); ok { - n.Expr = nn.Child - } else { - break - } - } -} - -func (v *FilterParserNodes) StmtThrow(n *ast.StmtThrow) { - for { - if nn, ok := n.Expr.(*ast.ParserBrackets); ok { - n.Expr = nn.Child - } else { - break - } - } -} - -func (v *FilterParserNodes) StmtCase(n *ast.StmtCase) { - for { - if nn, ok := n.Cond.(*ast.ParserBrackets); ok { - n.Cond = nn.Child - } else { - break - } - } -} - -func (v *FilterParserNodes) ExprVariable(n *ast.ExprVariable) { - for { - if nn, ok := n.VarName.(*ast.ParserBrackets); ok { - n.VarName = nn.Child - } else { - break - } - } -} - -func (v *FilterParserNodes) ExprAssign(n *ast.ExprAssign) { - for { - if nn, ok := n.Expr.(*ast.ParserBrackets); ok { - n.Expr = nn.Child - } else { - break - } - } -} - -func (v *FilterParserNodes) ExprAssignBitwiseAnd(n *ast.ExprAssignBitwiseAnd) { - for { - if nn, ok := n.Expr.(*ast.ParserBrackets); ok { - n.Expr = nn.Child - } else { - break - } - } -} - -func (v *FilterParserNodes) ExprAssignBitwiseOr(n *ast.ExprAssignBitwiseOr) { - for { - if nn, ok := n.Expr.(*ast.ParserBrackets); ok { - n.Expr = nn.Child - } else { - break - } - } -} - -func (v *FilterParserNodes) ExprAssignBitwiseXor(n *ast.ExprAssignBitwiseXor) { - for { - if nn, ok := n.Expr.(*ast.ParserBrackets); ok { - n.Expr = nn.Child - } else { - break - } - } -} - -func (v *FilterParserNodes) ExprAssignCoalesce(n *ast.ExprAssignCoalesce) { - for { - if nn, ok := n.Expr.(*ast.ParserBrackets); ok { - n.Expr = nn.Child - } else { - break - } - } -} - -func (v *FilterParserNodes) ExprAssignConcat(n *ast.ExprAssignConcat) { - for { - if nn, ok := n.Expr.(*ast.ParserBrackets); ok { - n.Expr = nn.Child - } else { - break - } - } -} - -func (v *FilterParserNodes) ExprAssignDiv(n *ast.ExprAssignDiv) { - for { - if nn, ok := n.Expr.(*ast.ParserBrackets); ok { - n.Expr = nn.Child - } else { - break - } - } -} - -func (v *FilterParserNodes) ExprAssignMinus(n *ast.ExprAssignMinus) { - for { - if nn, ok := n.Expr.(*ast.ParserBrackets); ok { - n.Expr = nn.Child - } else { - break - } - } -} - -func (v *FilterParserNodes) ExprAssignMod(n *ast.ExprAssignMod) { - for { - if nn, ok := n.Expr.(*ast.ParserBrackets); ok { - n.Expr = nn.Child - } else { - break - } - } -} - -func (v *FilterParserNodes) ExprAssignMul(n *ast.ExprAssignMul) { - for { - if nn, ok := n.Expr.(*ast.ParserBrackets); ok { - n.Expr = nn.Child - } else { - break - } - } -} - -func (v *FilterParserNodes) ExprAssignPlus(n *ast.ExprAssignPlus) { - for { - if nn, ok := n.Expr.(*ast.ParserBrackets); ok { - n.Expr = nn.Child - } else { - break - } - } -} - -func (v *FilterParserNodes) ExprAssignPow(n *ast.ExprAssignPow) { - for { - if nn, ok := n.Expr.(*ast.ParserBrackets); ok { - n.Expr = nn.Child - } else { - break - } - } -} - -func (v *FilterParserNodes) ExprAssignShiftLeft(n *ast.ExprAssignShiftLeft) { - for { - if nn, ok := n.Expr.(*ast.ParserBrackets); ok { - n.Expr = nn.Child - } else { - break - } - } -} - -func (v *FilterParserNodes) ExprAssignShiftRight(n *ast.ExprAssignShiftRight) { - for { - if nn, ok := n.Expr.(*ast.ParserBrackets); ok { - n.Expr = nn.Child - } else { - break - } - } -} -func (v *FilterParserNodes) ExprBinaryBitwiseAnd(n *ast.ExprBinaryBitwiseAnd) { - for { - if nn, ok := n.Left.(*ast.ParserBrackets); ok { - n.Left = nn.Child - } else { - break - } - } - - for { - if nn, ok := n.Right.(*ast.ParserBrackets); ok { - n.Right = nn.Child - } else { - break - } - } -} - -func (v *FilterParserNodes) ExprBinaryBitwiseOr(n *ast.ExprBinaryBitwiseOr) { - for { - if nn, ok := n.Left.(*ast.ParserBrackets); ok { - n.Left = nn.Child - } else { - break - } - } - - for { - if nn, ok := n.Right.(*ast.ParserBrackets); ok { - n.Right = nn.Child - } else { - break - } - } -} - -func (v *FilterParserNodes) ExprBinaryBitwiseXor(n *ast.ExprBinaryBitwiseXor) { - for { - if nn, ok := n.Left.(*ast.ParserBrackets); ok { - n.Left = nn.Child - } else { - break - } - } - - for { - if nn, ok := n.Right.(*ast.ParserBrackets); ok { - n.Right = nn.Child - } else { - break - } - } -} - -func (v *FilterParserNodes) ExprBinaryBooleanAnd(n *ast.ExprBinaryBooleanAnd) { - for { - if nn, ok := n.Left.(*ast.ParserBrackets); ok { - n.Left = nn.Child - } else { - break - } - } - - for { - if nn, ok := n.Right.(*ast.ParserBrackets); ok { - n.Right = nn.Child - } else { - break - } - } -} - -func (v *FilterParserNodes) ExprBinaryBooleanOr(n *ast.ExprBinaryBooleanOr) { - for { - if nn, ok := n.Left.(*ast.ParserBrackets); ok { - n.Left = nn.Child - } else { - break - } - } - - for { - if nn, ok := n.Right.(*ast.ParserBrackets); ok { - n.Right = nn.Child - } else { - break - } - } -} - -func (v *FilterParserNodes) ExprBinaryCoalesce(n *ast.ExprBinaryCoalesce) { - for { - if nn, ok := n.Left.(*ast.ParserBrackets); ok { - n.Left = nn.Child - } else { - break - } - } - - for { - if nn, ok := n.Right.(*ast.ParserBrackets); ok { - n.Right = nn.Child - } else { - break - } - } -} - -func (v *FilterParserNodes) ExprBinaryConcat(n *ast.ExprBinaryConcat) { - for { - if nn, ok := n.Left.(*ast.ParserBrackets); ok { - n.Left = nn.Child - } else { - break - } - } - - for { - if nn, ok := n.Right.(*ast.ParserBrackets); ok { - n.Right = nn.Child - } else { - break - } - } -} - -func (v *FilterParserNodes) ExprBinaryDiv(n *ast.ExprBinaryDiv) { - for { - if nn, ok := n.Left.(*ast.ParserBrackets); ok { - n.Left = nn.Child - } else { - break - } - } - - for { - if nn, ok := n.Right.(*ast.ParserBrackets); ok { - n.Right = nn.Child - } else { - break - } - } -} - -func (v *FilterParserNodes) ExprBinaryEqual(n *ast.ExprBinaryEqual) { - for { - if nn, ok := n.Left.(*ast.ParserBrackets); ok { - n.Left = nn.Child - } else { - break - } - } - - for { - if nn, ok := n.Right.(*ast.ParserBrackets); ok { - n.Right = nn.Child - } else { - break - } - } -} - -func (v *FilterParserNodes) ExprBinaryGreater(n *ast.ExprBinaryGreater) { - for { - if nn, ok := n.Left.(*ast.ParserBrackets); ok { - n.Left = nn.Child - } else { - break - } - } - - for { - if nn, ok := n.Right.(*ast.ParserBrackets); ok { - n.Right = nn.Child - } else { - break - } - } -} - -func (v *FilterParserNodes) ExprBinaryGreaterOrEqual(n *ast.ExprBinaryGreaterOrEqual) { - for { - if nn, ok := n.Left.(*ast.ParserBrackets); ok { - n.Left = nn.Child - } else { - break - } - } - - for { - if nn, ok := n.Right.(*ast.ParserBrackets); ok { - n.Right = nn.Child - } else { - break - } - } -} - -func (v *FilterParserNodes) ExprBinaryIdentical(n *ast.ExprBinaryIdentical) { - for { - if nn, ok := n.Left.(*ast.ParserBrackets); ok { - n.Left = nn.Child - } else { - break - } - } - - for { - if nn, ok := n.Right.(*ast.ParserBrackets); ok { - n.Right = nn.Child - } else { - break - } - } -} - -func (v *FilterParserNodes) ExprBinaryLogicalAnd(n *ast.ExprBinaryLogicalAnd) { - for { - if nn, ok := n.Left.(*ast.ParserBrackets); ok { - n.Left = nn.Child - } else { - break - } - } - - for { - if nn, ok := n.Right.(*ast.ParserBrackets); ok { - n.Right = nn.Child - } else { - break - } - } -} - -func (v *FilterParserNodes) ExprBinaryLogicalOr(n *ast.ExprBinaryLogicalOr) { - for { - if nn, ok := n.Left.(*ast.ParserBrackets); ok { - n.Left = nn.Child - } else { - break - } - } - - for { - if nn, ok := n.Right.(*ast.ParserBrackets); ok { - n.Right = nn.Child - } else { - break - } - } -} - -func (v *FilterParserNodes) ExprBinaryLogicalXor(n *ast.ExprBinaryLogicalXor) { - for { - if nn, ok := n.Left.(*ast.ParserBrackets); ok { - n.Left = nn.Child - } else { - break - } - } - - for { - if nn, ok := n.Right.(*ast.ParserBrackets); ok { - n.Right = nn.Child - } else { - break - } - } -} - -func (v *FilterParserNodes) ExprBinaryMinus(n *ast.ExprBinaryMinus) { - for { - if nn, ok := n.Left.(*ast.ParserBrackets); ok { - n.Left = nn.Child - } else { - break - } - } - - for { - if nn, ok := n.Right.(*ast.ParserBrackets); ok { - n.Right = nn.Child - } else { - break - } - } -} - -func (v *FilterParserNodes) ExprBinaryMod(n *ast.ExprBinaryMod) { - for { - if nn, ok := n.Left.(*ast.ParserBrackets); ok { - n.Left = nn.Child - } else { - break - } - } - - for { - if nn, ok := n.Right.(*ast.ParserBrackets); ok { - n.Right = nn.Child - } else { - break - } - } -} - -func (v *FilterParserNodes) ExprBinaryMul(n *ast.ExprBinaryMul) { - for { - if nn, ok := n.Left.(*ast.ParserBrackets); ok { - n.Left = nn.Child - } else { - break - } - } - - for { - if nn, ok := n.Right.(*ast.ParserBrackets); ok { - n.Right = nn.Child - } else { - break - } - } -} - -func (v *FilterParserNodes) ExprBinaryNotEqual(n *ast.ExprBinaryNotEqual) { - for { - if nn, ok := n.Left.(*ast.ParserBrackets); ok { - n.Left = nn.Child - } else { - break - } - } - - for { - if nn, ok := n.Right.(*ast.ParserBrackets); ok { - n.Right = nn.Child - } else { - break - } - } -} - -func (v *FilterParserNodes) ExprBinaryNotIdentical(n *ast.ExprBinaryNotIdentical) { - for { - if nn, ok := n.Left.(*ast.ParserBrackets); ok { - n.Left = nn.Child - } else { - break - } - } - - for { - if nn, ok := n.Right.(*ast.ParserBrackets); ok { - n.Right = nn.Child - } else { - break - } - } -} - -func (v *FilterParserNodes) ExprBinaryPlus(n *ast.ExprBinaryPlus) { - for { - if nn, ok := n.Left.(*ast.ParserBrackets); ok { - n.Left = nn.Child - } else { - break - } - } - - for { - if nn, ok := n.Right.(*ast.ParserBrackets); ok { - n.Right = nn.Child - } else { - break - } - } -} - -func (v *FilterParserNodes) ExprBinaryPow(n *ast.ExprBinaryPow) { - for { - if nn, ok := n.Left.(*ast.ParserBrackets); ok { - n.Left = nn.Child - } else { - break - } - } - - for { - if nn, ok := n.Right.(*ast.ParserBrackets); ok { - n.Right = nn.Child - } else { - break - } - } -} - -func (v *FilterParserNodes) ExprBinaryShiftLeft(n *ast.ExprBinaryShiftLeft) { - for { - if nn, ok := n.Left.(*ast.ParserBrackets); ok { - n.Left = nn.Child - } else { - break - } - } - - for { - if nn, ok := n.Right.(*ast.ParserBrackets); ok { - n.Right = nn.Child - } else { - break - } - } -} - -func (v *FilterParserNodes) ExprBinaryShiftRight(n *ast.ExprBinaryShiftRight) { - for { - if nn, ok := n.Left.(*ast.ParserBrackets); ok { - n.Left = nn.Child - } else { - break - } - } - - for { - if nn, ok := n.Right.(*ast.ParserBrackets); ok { - n.Right = nn.Child - } else { - break - } - } -} - -func (v *FilterParserNodes) ExprBinarySmaller(n *ast.ExprBinarySmaller) { - for { - if nn, ok := n.Left.(*ast.ParserBrackets); ok { - n.Left = nn.Child - } else { - break - } - } - - for { - if nn, ok := n.Right.(*ast.ParserBrackets); ok { - n.Right = nn.Child - } else { - break - } - } -} - -func (v *FilterParserNodes) ExprBinarySmallerOrEqual(n *ast.ExprBinarySmallerOrEqual) { - for { - if nn, ok := n.Left.(*ast.ParserBrackets); ok { - n.Left = nn.Child - } else { - break - } - } - - for { - if nn, ok := n.Right.(*ast.ParserBrackets); ok { - n.Right = nn.Child - } else { - break - } - } -} - -func (v *FilterParserNodes) ExprBinarySpaceship(n *ast.ExprBinarySpaceship) { - for { - if nn, ok := n.Left.(*ast.ParserBrackets); ok { - n.Left = nn.Child - } else { - break - } - } - - for { - if nn, ok := n.Right.(*ast.ParserBrackets); ok { - n.Right = nn.Child - } else { - break - } - } -} - -func (v *FilterParserNodes) ExprUnaryMinus(n *ast.ExprUnaryMinus) { - for { - if nn, ok := n.Expr.(*ast.ParserBrackets); ok { - n.Expr = nn.Child - } else { - break - } - } -} - -func (v *FilterParserNodes) ExprUnaryPlus(n *ast.ExprUnaryPlus) { - for { - if nn, ok := n.Expr.(*ast.ParserBrackets); ok { - n.Expr = nn.Child - } else { - break - } - } -} - -func (v *FilterParserNodes) ExprBooleanNot(n *ast.ExprBooleanNot) { - for { - if nn, ok := n.Expr.(*ast.ParserBrackets); ok { - n.Expr = nn.Child - } else { - break - } - } -} - -func (v *FilterParserNodes) ExprBitwiseNot(n *ast.ExprBitwiseNot) { - for { - if nn, ok := n.Expr.(*ast.ParserBrackets); ok { - n.Expr = nn.Child - } else { - break - } - } -} - -func (v *FilterParserNodes) ExprInstanceOf(n *ast.ExprInstanceOf) { - for { - if nn, ok := n.Expr.(*ast.ParserBrackets); ok { - n.Expr = nn.Child - } else { - break - } - } -} - -func (v *FilterParserNodes) ExprTernary(n *ast.ExprTernary) { - for { - if nn, ok := n.Condition.(*ast.ParserBrackets); ok { - n.Condition = nn.Child - } else { - break - } - } - - for { - if nn, ok := n.IfTrue.(*ast.ParserBrackets); ok { - n.IfTrue = nn.Child - } else { - break - } - } - - for { - if nn, ok := n.IfFalse.(*ast.ParserBrackets); ok { - n.IfFalse = nn.Child - } else { - break - } - } -} - -func (v *FilterParserNodes) ExprCastArray(n *ast.ExprCastArray) { - for { - if nn, ok := n.Expr.(*ast.ParserBrackets); ok { - n.Expr = nn.Child - } else { - break - } - } -} - -func (v *FilterParserNodes) ExprCastBool(n *ast.ExprCastBool) { - for { - if nn, ok := n.Expr.(*ast.ParserBrackets); ok { - n.Expr = nn.Child - } else { - break - } - } -} - -func (v *FilterParserNodes) ExprCastDouble(n *ast.ExprCastDouble) { - for { - if nn, ok := n.Expr.(*ast.ParserBrackets); ok { - n.Expr = nn.Child - } else { - break - } - } -} - -func (v *FilterParserNodes) ExprCastInt(n *ast.ExprCastInt) { - for { - if nn, ok := n.Expr.(*ast.ParserBrackets); ok { - n.Expr = nn.Child - } else { - break - } - } -} - -func (v *FilterParserNodes) ExprCastObject(n *ast.ExprCastObject) { - for { - if nn, ok := n.Expr.(*ast.ParserBrackets); ok { - n.Expr = nn.Child - } else { - break - } - } -} - -func (v *FilterParserNodes) ExprCastString(n *ast.ExprCastString) { - for { - if nn, ok := n.Expr.(*ast.ParserBrackets); ok { - n.Expr = nn.Child - } else { - break - } - } -} - -func (v *FilterParserNodes) ExprCastUnset(n *ast.ExprCastUnset) { - for { - if nn, ok := n.Expr.(*ast.ParserBrackets); ok { - n.Expr = nn.Child - } else { - break - } - } -} - -func (v *FilterParserNodes) ExprErrorSuppress(n *ast.ExprErrorSuppress) { - for { - if nn, ok := n.Expr.(*ast.ParserBrackets); ok { - n.Expr = nn.Child - } else { - break - } - } -} - -func (v *FilterParserNodes) ExprArrayDimFetch(n *ast.ExprArrayDimFetch) { - for { - if nn, ok := n.Dim.(*ast.ParserBrackets); ok { - n.Dim = nn.Child - } else { - break - } - } -} - -func (v *FilterParserNodes) ExprArrayItem(n *ast.ExprArrayItem) { - for { - if nn, ok := n.Key.(*ast.ParserBrackets); ok { - n.Key = nn.Child - } else { - break - } - } - - for { - if nn, ok := n.Val.(*ast.ParserBrackets); ok { - n.Val = nn.Child - } else { - break - } - } -} - -func (v *FilterParserNodes) ExprEmpty(n *ast.ExprEmpty) { - for { - if nn, ok := n.Expr.(*ast.ParserBrackets); ok { - n.Expr = nn.Child - } else { - break - } - } -} - -func (v *FilterParserNodes) ExprInclude(n *ast.ExprInclude) { - for { - if nn, ok := n.Expr.(*ast.ParserBrackets); ok { - n.Expr = nn.Child - } else { - break - } - } -} - -func (v *FilterParserNodes) ExprIncludeOnce(n *ast.ExprIncludeOnce) { - for { - if nn, ok := n.Expr.(*ast.ParserBrackets); ok { - n.Expr = nn.Child - } else { - break - } - } -} - -func (v *FilterParserNodes) ExprEval(n *ast.ExprEval) { - for { - if nn, ok := n.Expr.(*ast.ParserBrackets); ok { - n.Expr = nn.Child - } else { - break - } - } -} - -func (v *FilterParserNodes) ExprRequire(n *ast.ExprRequire) { - for { - if nn, ok := n.Expr.(*ast.ParserBrackets); ok { - n.Expr = nn.Child - } else { - break - } - } -} - -func (v *FilterParserNodes) ExprRequireOnce(n *ast.ExprRequireOnce) { - for { - if nn, ok := n.Expr.(*ast.ParserBrackets); ok { - n.Expr = nn.Child - } else { - break - } - } -} - -func (v *FilterParserNodes) ExprPropertyFetch(n *ast.ExprPropertyFetch) { - for { - if nn, ok := n.Var.(*ast.ParserBrackets); ok { - n.Var = nn.Child - } else { - break - } - } - - for { - if nn, ok := n.Property.(*ast.ParserBrackets); ok { - n.Property = nn.Child - } else { - break - } - } -} - -func (v *FilterParserNodes) ExprFunctionCall(n *ast.ExprFunctionCall) { - for { - if nn, ok := n.Function.(*ast.ParserBrackets); ok { - n.Function = nn.Child - } else { - break - } - } -} - -func (v *FilterParserNodes) ExprStaticCall(n *ast.ExprStaticCall) { - for { - if nn, ok := n.Call.(*ast.ParserBrackets); ok { - n.Call = nn.Child - } else { - break - } - } -} diff --git a/pkg/ast/visitor/filter_tokens.go b/pkg/ast/visitor/filter_tokens.go deleted file mode 100644 index 579bb8d..0000000 --- a/pkg/ast/visitor/filter_tokens.go +++ /dev/null @@ -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 -} diff --git a/pkg/printer/printer.go b/pkg/printer/printer.go index 0109652..026708e 100644 --- a/pkg/printer/printer.go +++ b/pkg/printer/printer.go @@ -550,7 +550,6 @@ func (p *Printer) printNodeArgument(n ast.Vertex) { // name func (p *Printer) printNameNamePart(n *ast.NameNamePart) { - p.printToken(n.NsSeparatorTkn, "") p.printToken(n.StringTkn, string(n.Value)) } @@ -558,8 +557,6 @@ func (p *Printer) printNameName(n *ast.NameName) { p.printFreeFloating(n, token.Start) p.joinPrintRefactored("\\", n.Parts) - - p.printToken(n.ListSeparatorTkn, "") } func (p *Printer) printNameFullyQualified(n *ast.NameFullyQualified) { @@ -567,8 +564,6 @@ func (p *Printer) printNameFullyQualified(n *ast.NameFullyQualified) { p.printToken(n.NsSeparatorTkn, "\\") p.joinPrintRefactored("\\", n.Parts) - - p.printToken(n.ListSeparatorTkn, "") } func (p *Printer) printNameRelative(n *ast.NameRelative) { @@ -577,8 +572,6 @@ func (p *Printer) printNameRelative(n *ast.NameRelative) { p.printToken(n.NsSeparatorTkn, "\\") p.joinPrintRefactored("\\", n.Parts) - - p.printToken(n.ListSeparatorTkn, "") } // scalar @@ -2099,7 +2092,6 @@ func (p *Printer) printStmtConstant(n *ast.StmtConstant) { p.Print(n.Name) p.printToken(n.EqualTkn, "=") p.Print(n.Expr) - p.printToken(n.CommaTkn, "") } func (p *Printer) printStmtContinue(n *ast.StmtContinue) { @@ -2795,7 +2787,6 @@ func (p *Printer) printStmtUseDeclaration(n *ast.StmtUseDeclaration) { p.Print(n.Use) if n.Alias == nil { - p.printToken(n.CommaTkn, "") return } @@ -2804,8 +2795,6 @@ func (p *Printer) printStmtUseDeclaration(n *ast.StmtUseDeclaration) { p.bufStart = " " p.Print(n.Alias) - - p.printToken(n.CommaTkn, "") } func (p *Printer) printStmtWhile(n *ast.StmtWhile) {