[refactoring] update ast structure of "Argument" and "ArgumentList" nodes
This commit is contained in:
parent
73d819eb6c
commit
7e2965f53b
BIN
internal/php5/php5.go
generated
BIN
internal/php5/php5.go
generated
Binary file not shown.
@ -242,7 +242,7 @@ import (
|
|||||||
%type <node> static_scalar_value static_operation static_var_list global_var_list
|
%type <node> static_scalar_value static_operation static_var_list global_var_list
|
||||||
%type <node> ctor_arguments function_call_parameter_list echo_expr_list
|
%type <node> ctor_arguments function_call_parameter_list echo_expr_list
|
||||||
%type <node> trait_adaptations unset_variables declare_list
|
%type <node> trait_adaptations unset_variables declare_list
|
||||||
%type <node> switch_case_list
|
%type <node> switch_case_list non_empty_function_call_parameter_list
|
||||||
%type <node> method_body
|
%type <node> method_body
|
||||||
%type <node> foreach_statement for_statement while_statement
|
%type <node> foreach_statement for_statement while_statement
|
||||||
%type <node> foreach_variable foreach_optional_arg
|
%type <node> foreach_variable foreach_optional_arg
|
||||||
@ -258,7 +258,7 @@ import (
|
|||||||
%type <list> for_expr case_list catch_statement additional_catches
|
%type <list> for_expr case_list catch_statement additional_catches
|
||||||
%type <list> non_empty_additional_catches parameter_list non_empty_parameter_list class_statement_list
|
%type <list> non_empty_additional_catches parameter_list non_empty_parameter_list class_statement_list
|
||||||
%type <list> class_statement_list variable_modifiers method_modifiers class_variable_declaration
|
%type <list> class_statement_list variable_modifiers method_modifiers class_variable_declaration
|
||||||
%type <list> interface_list non_empty_function_call_parameter_list trait_list trait_adaptation_list non_empty_trait_adaptation_list
|
%type <list> interface_list trait_list trait_adaptation_list non_empty_trait_adaptation_list
|
||||||
%type <list> trait_reference_list non_empty_member_modifiers backticks_expr static_array_pair_list non_empty_static_array_pair_list
|
%type <list> trait_reference_list non_empty_member_modifiers backticks_expr static_array_pair_list non_empty_static_array_pair_list
|
||||||
|
|
||||||
%type <list> chaining_dereference chaining_instance_call chaining_method_or_property instance_call variable_property
|
%type <list> chaining_dereference chaining_instance_call chaining_method_or_property instance_call variable_property
|
||||||
@ -2170,38 +2170,40 @@ optional_class_type:
|
|||||||
function_call_parameter_list:
|
function_call_parameter_list:
|
||||||
'(' ')'
|
'(' ')'
|
||||||
{
|
{
|
||||||
$$ = &ast.ArgumentList{ast.Node{}, nil}
|
$$ = &ast.ArgumentList{
|
||||||
|
Node: ast.Node{
|
||||||
// save position
|
Position: position.NewTokensPosition($1, $2),
|
||||||
$$.GetNode().Position = position.NewTokensPosition($1, $2)
|
},
|
||||||
|
OpenParenthesisTkn: $1,
|
||||||
// save comments
|
CloseParenthesisTkn: $2,
|
||||||
yylex.(*Parser).setFreeFloatingTokens($$, token.Start, $1.SkippedTokens)
|
}
|
||||||
yylex.(*Parser).setFreeFloatingTokens($$, token.End, $2.SkippedTokens)
|
|
||||||
}
|
}
|
||||||
| '(' non_empty_function_call_parameter_list ')'
|
| '(' non_empty_function_call_parameter_list ')'
|
||||||
{
|
{
|
||||||
$$ = &ast.ArgumentList{ast.Node{}, $2}
|
argumentList := $2.(*ast.ArgumentList)
|
||||||
|
argumentList.Position = position.NewTokensPosition($1, $3)
|
||||||
|
argumentList.OpenParenthesisTkn = $1
|
||||||
|
argumentList.CloseParenthesisTkn = $3
|
||||||
|
|
||||||
// save position
|
$$ = argumentList
|
||||||
$$.GetNode().Position = position.NewTokensPosition($1, $3)
|
|
||||||
|
|
||||||
// save comments
|
|
||||||
yylex.(*Parser).setFreeFloatingTokens($$, token.Start, $1.SkippedTokens)
|
|
||||||
yylex.(*Parser).setFreeFloatingTokens($$, token.End, $3.SkippedTokens)
|
|
||||||
}
|
}
|
||||||
| '(' yield_expr ')'
|
| '(' yield_expr ')'
|
||||||
{
|
{
|
||||||
arg := &ast.Argument{ast.Node{}, false, false, $2}
|
$$ = &ast.ArgumentList{
|
||||||
$$ = &ast.ArgumentList{ast.Node{}, []ast.Vertex{arg}}
|
Node: ast.Node{
|
||||||
|
Position: position.NewTokensPosition($1, $3),
|
||||||
// save position
|
},
|
||||||
arg.GetNode().Position = position.NewNodePosition($2)
|
OpenParenthesisTkn: $1,
|
||||||
$$.GetNode().Position = position.NewTokensPosition($1, $3)
|
Arguments: []ast.Vertex{
|
||||||
|
&ast.Argument{
|
||||||
// save comments
|
Node: ast.Node{
|
||||||
yylex.(*Parser).setFreeFloatingTokens($$, token.Start, $1.SkippedTokens)
|
Position: position.NewNodePosition($2),
|
||||||
yylex.(*Parser).setFreeFloatingTokens($$, token.End, $3.SkippedTokens)
|
},
|
||||||
|
Expr: $2,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
CloseParenthesisTkn: $3,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
;
|
;
|
||||||
|
|
||||||
@ -2209,57 +2211,57 @@ function_call_parameter_list:
|
|||||||
non_empty_function_call_parameter_list:
|
non_empty_function_call_parameter_list:
|
||||||
function_call_parameter
|
function_call_parameter
|
||||||
{
|
{
|
||||||
$$ = []ast.Vertex{$1}
|
$$ = &ast.ArgumentList{
|
||||||
|
Arguments: []ast.Vertex{$1},
|
||||||
|
}
|
||||||
}
|
}
|
||||||
| non_empty_function_call_parameter_list ',' function_call_parameter
|
| non_empty_function_call_parameter_list ',' function_call_parameter
|
||||||
{
|
{
|
||||||
$$ = append($1, $3)
|
$1.(*ast.ArgumentList).SeparatorTkns = append($1.(*ast.ArgumentList).SeparatorTkns, $2)
|
||||||
|
$1.(*ast.ArgumentList).Arguments = append($1.(*ast.ArgumentList).Arguments, $3)
|
||||||
|
|
||||||
// save comments
|
$$ = $1
|
||||||
yylex.(*Parser).setFreeFloating(lastNode($1), token.End, $2.SkippedTokens)
|
|
||||||
}
|
}
|
||||||
;
|
;
|
||||||
|
|
||||||
function_call_parameter:
|
function_call_parameter:
|
||||||
expr_without_variable
|
expr_without_variable
|
||||||
{
|
{
|
||||||
$$ = &ast.Argument{ast.Node{}, false, false, $1}
|
$$ = &ast.Argument{
|
||||||
|
Node: ast.Node{
|
||||||
// save position
|
Position: position.NewNodePosition($1),
|
||||||
$$.GetNode().Position = position.NewNodePosition($1)
|
},
|
||||||
|
Expr: $1,
|
||||||
// save comments
|
}
|
||||||
yylex.(*Parser).MoveFreeFloating($1, $$)
|
|
||||||
}
|
}
|
||||||
| variable
|
| variable
|
||||||
{
|
{
|
||||||
$$ = &ast.Argument{ast.Node{}, false, false, $1}
|
$$ = &ast.Argument{
|
||||||
|
Node: ast.Node{
|
||||||
// save position
|
Position: position.NewNodePosition($1),
|
||||||
$$.GetNode().Position = position.NewNodePosition($1)
|
},
|
||||||
|
Expr: $1,
|
||||||
// save comments
|
}
|
||||||
yylex.(*Parser).MoveFreeFloating($1, $$)
|
|
||||||
}
|
}
|
||||||
| '&' w_variable
|
| '&' w_variable
|
||||||
{
|
{
|
||||||
$$ = &ast.Argument{ast.Node{}, false, true, $2}
|
$$ = &ast.Argument{
|
||||||
|
Node: ast.Node{
|
||||||
// save position
|
Position: position.NewTokenNodePosition($1, $2),
|
||||||
$$.GetNode().Position = position.NewNodePosition($2)
|
},
|
||||||
|
AmpersandTkn: $1,
|
||||||
// save comments
|
Expr: $2,
|
||||||
yylex.(*Parser).setFreeFloating($$, token.Start, $1.SkippedTokens)
|
}
|
||||||
}
|
}
|
||||||
| T_ELLIPSIS expr
|
| T_ELLIPSIS expr
|
||||||
{
|
{
|
||||||
$$ = &ast.Argument{ast.Node{}, true, false, $2}
|
$$ = &ast.Argument{
|
||||||
|
Node: ast.Node{
|
||||||
// save position
|
Position: position.NewTokenNodePosition($1, $2),
|
||||||
$$.GetNode().Position = position.NewTokenNodePosition($1, $2)
|
},
|
||||||
|
VariadicTkn: $1,
|
||||||
// save comments
|
Expr: $2,
|
||||||
yylex.(*Parser).setFreeFloating($$, token.Start, $1.SkippedTokens)
|
}
|
||||||
}
|
}
|
||||||
;
|
;
|
||||||
|
|
||||||
|
BIN
internal/php7/php7.go
generated
BIN
internal/php7/php7.go
generated
Binary file not shown.
@ -250,7 +250,7 @@ import (
|
|||||||
%type <node> variable_class_name dereferencable_scalar constant dereferencable
|
%type <node> variable_class_name dereferencable_scalar constant dereferencable
|
||||||
%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
|
%type <node> encaps_var encaps_var_offset echo_expr_list catch_name_list
|
||||||
%type <node> if_stmt const_list
|
%type <node> if_stmt const_list non_empty_argument_list
|
||||||
%type <node> alt_if_stmt
|
%type <node> alt_if_stmt
|
||||||
%type <node> if_stmt_without_else
|
%type <node> if_stmt_without_else
|
||||||
%type <node> class_const_decl
|
%type <node> class_const_decl
|
||||||
@ -280,7 +280,7 @@ import (
|
|||||||
%type <list> unprefixed_use_declarations inline_use_declarations property_list
|
%type <list> unprefixed_use_declarations inline_use_declarations property_list
|
||||||
%type <list> case_list trait_adaptation_list
|
%type <list> case_list trait_adaptation_list
|
||||||
%type <list> use_declarations lexical_var_list isset_variables non_empty_array_pair_list
|
%type <list> use_declarations lexical_var_list isset_variables non_empty_array_pair_list
|
||||||
%type <list> array_pair_list non_empty_argument_list top_statement_list
|
%type <list> array_pair_list top_statement_list
|
||||||
%type <list> inner_statement_list parameter_list non_empty_parameter_list class_statement_list
|
%type <list> inner_statement_list parameter_list non_empty_parameter_list class_statement_list
|
||||||
%type <list> method_modifiers variable_modifiers
|
%type <list> method_modifiers variable_modifiers
|
||||||
%type <list> non_empty_member_modifiers name_list class_modifiers
|
%type <list> non_empty_member_modifiers name_list class_modifiers
|
||||||
@ -2030,66 +2030,61 @@ return_type:
|
|||||||
argument_list:
|
argument_list:
|
||||||
'(' ')'
|
'(' ')'
|
||||||
{
|
{
|
||||||
$$ = &ast.ArgumentList{ast.Node{}, nil}
|
$$ = &ast.ArgumentList{
|
||||||
|
Node: ast.Node{
|
||||||
// save position
|
Position: position.NewTokensPosition($1, $2),
|
||||||
$$.GetNode().Position = position.NewTokensPosition($1, $2)
|
},
|
||||||
|
OpenParenthesisTkn: $1,
|
||||||
// save comments
|
CloseParenthesisTkn: $2,
|
||||||
yylex.(*Parser).setFreeFloatingTokens($$, token.Start, $1.SkippedTokens)
|
}
|
||||||
yylex.(*Parser).setFreeFloatingTokens($$, token.End, $2.SkippedTokens)
|
|
||||||
}
|
}
|
||||||
| '(' non_empty_argument_list possible_comma ')'
|
| '(' non_empty_argument_list possible_comma ')'
|
||||||
{
|
{
|
||||||
$$ = &ast.ArgumentList{ast.Node{}, $2}
|
argumentList := $2.(*ast.ArgumentList)
|
||||||
|
argumentList.Position = position.NewTokensPosition($1, $4)
|
||||||
|
argumentList.OpenParenthesisTkn = $1
|
||||||
|
argumentList.SeparatorTkns = append(argumentList.SeparatorTkns, $3)
|
||||||
|
argumentList.CloseParenthesisTkn = $4
|
||||||
|
|
||||||
// save position
|
$$ = argumentList
|
||||||
$$.GetNode().Position = position.NewTokensPosition($1, $4)
|
|
||||||
|
|
||||||
// save comments
|
|
||||||
yylex.(*Parser).setFreeFloatingTokens($$, token.Start, $1.SkippedTokens)
|
|
||||||
if $3 != nil {
|
|
||||||
yylex.(*Parser).setFreeFloatingTokens($$, token.End, append($3.SkippedTokens, $4.SkippedTokens...))
|
|
||||||
} else {
|
|
||||||
yylex.(*Parser).setFreeFloatingTokens($$, token.End, $4.SkippedTokens)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
;
|
;
|
||||||
|
|
||||||
non_empty_argument_list:
|
non_empty_argument_list:
|
||||||
argument
|
argument
|
||||||
{
|
{
|
||||||
$$ = []ast.Vertex{$1}
|
$$ = &ast.ArgumentList{
|
||||||
|
Arguments: []ast.Vertex{$1},
|
||||||
|
}
|
||||||
}
|
}
|
||||||
| non_empty_argument_list ',' argument
|
| non_empty_argument_list ',' argument
|
||||||
{
|
{
|
||||||
$$ = append($1, $3)
|
$1.(*ast.ArgumentList).SeparatorTkns = append($1.(*ast.ArgumentList).SeparatorTkns, $2)
|
||||||
|
$1.(*ast.ArgumentList).Arguments = append($1.(*ast.ArgumentList).Arguments, $3)
|
||||||
|
|
||||||
// save comments
|
$$ = $1
|
||||||
yylex.(*Parser).setFreeFloating(lastNode($1), token.End, $2.SkippedTokens)
|
|
||||||
}
|
}
|
||||||
;
|
;
|
||||||
|
|
||||||
argument:
|
argument:
|
||||||
expr
|
expr
|
||||||
{
|
{
|
||||||
$$ = &ast.Argument{ast.Node{}, false, false, $1}
|
$$ = &ast.Argument{
|
||||||
|
Node: ast.Node{
|
||||||
// save position
|
Position: position.NewNodePosition($1),
|
||||||
$$.GetNode().Position = position.NewNodePosition($1)
|
},
|
||||||
|
Expr: $1,
|
||||||
// save comments
|
}
|
||||||
yylex.(*Parser).MoveFreeFloating($1, $$)
|
|
||||||
}
|
}
|
||||||
| T_ELLIPSIS expr
|
| T_ELLIPSIS expr
|
||||||
{
|
{
|
||||||
$$ = &ast.Argument{ast.Node{}, true, false, $2}
|
$$ = &ast.Argument{
|
||||||
|
Node: ast.Node{
|
||||||
// save position
|
Position: position.NewTokenNodePosition($1, $2),
|
||||||
$$.GetNode().Position = position.NewTokenNodePosition($1, $2)
|
},
|
||||||
|
VariadicTkn: $1,
|
||||||
// save comments
|
Expr: $2,
|
||||||
yylex.(*Parser).setFreeFloating($$, token.Start, $1.SkippedTokens)
|
}
|
||||||
}
|
}
|
||||||
;
|
;
|
||||||
|
|
||||||
|
@ -90,7 +90,10 @@ func (n *Identifier) Accept(v NodeVisitor) {
|
|||||||
// ArgumentList node
|
// ArgumentList node
|
||||||
type ArgumentList struct {
|
type ArgumentList struct {
|
||||||
Node
|
Node
|
||||||
|
OpenParenthesisTkn *token.Token
|
||||||
Arguments []Vertex
|
Arguments []Vertex
|
||||||
|
SeparatorTkns []*token.Token
|
||||||
|
CloseParenthesisTkn *token.Token
|
||||||
}
|
}
|
||||||
|
|
||||||
func (n *ArgumentList) Accept(v NodeVisitor) {
|
func (n *ArgumentList) Accept(v NodeVisitor) {
|
||||||
@ -100,8 +103,8 @@ func (n *ArgumentList) Accept(v NodeVisitor) {
|
|||||||
// Argument node
|
// Argument node
|
||||||
type Argument struct {
|
type Argument struct {
|
||||||
Node
|
Node
|
||||||
Variadic bool
|
VariadicTkn *token.Token
|
||||||
IsReference bool
|
AmpersandTkn *token.Token
|
||||||
Expr Vertex
|
Expr Vertex
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -240,16 +240,6 @@ func (v *Dump) Argument(n *ast.Argument) {
|
|||||||
v.printIndentIfNotSingle(v.indent - 1)
|
v.printIndentIfNotSingle(v.indent - 1)
|
||||||
v.print("&ast.Argument{\n")
|
v.print("&ast.Argument{\n")
|
||||||
v.printNode(n.GetNode())
|
v.printNode(n.GetNode())
|
||||||
|
|
||||||
if n.Variadic {
|
|
||||||
v.printIndent(v.indent)
|
|
||||||
v.print("Variadic: true,\n")
|
|
||||||
}
|
|
||||||
|
|
||||||
if n.IsReference {
|
|
||||||
v.printIndent(v.indent)
|
|
||||||
v.print("IsReference: true,\n")
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (v *Dump) StmtBreak(n *ast.StmtBreak) {
|
func (v *Dump) StmtBreak(n *ast.StmtBreak) {
|
||||||
|
@ -465,11 +465,11 @@ func (p *PrettyPrinter) printNodeNullable(n ast.Vertex) {
|
|||||||
func (p *PrettyPrinter) printNodeArgument(n ast.Vertex) {
|
func (p *PrettyPrinter) printNodeArgument(n ast.Vertex) {
|
||||||
nn := n.(*ast.Argument)
|
nn := n.(*ast.Argument)
|
||||||
|
|
||||||
if nn.IsReference {
|
if nn.AmpersandTkn != nil {
|
||||||
io.WriteString(p.w, "&")
|
io.WriteString(p.w, "&")
|
||||||
}
|
}
|
||||||
|
|
||||||
if nn.Variadic {
|
if nn.VariadicTkn != nil {
|
||||||
io.WriteString(p.w, "...")
|
io.WriteString(p.w, "...")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -561,12 +561,12 @@ func (p *Printer) printNodeArgument(n ast.Vertex) {
|
|||||||
nn := n.(*ast.Argument)
|
nn := n.(*ast.Argument)
|
||||||
p.printFreeFloating(nn, token.Start)
|
p.printFreeFloating(nn, token.Start)
|
||||||
|
|
||||||
if nn.IsReference {
|
if nn.AmpersandTkn != nil {
|
||||||
p.write([]byte("&"))
|
p.write([]byte("&"))
|
||||||
}
|
}
|
||||||
p.printFreeFloating(nn, token.Ampersand)
|
p.printFreeFloating(nn, token.Ampersand)
|
||||||
|
|
||||||
if nn.Variadic {
|
if nn.VariadicTkn != nil {
|
||||||
p.write([]byte("..."))
|
p.write([]byte("..."))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user