method_call node

This commit is contained in:
z7zmey 2017-12-18 18:39:04 +02:00
parent 661e8cc551
commit 4fc5d37b48
3 changed files with 47 additions and 2 deletions

45
node/expr/method_call.go Normal file
View File

@ -0,0 +1,45 @@
package expr
import (
"fmt"
"io"
"github.com/z7zmey/php-parser/node"
)
type MethodCall struct {
node.SimpleNode
variable node.Node
name node.Node
arguments []node.Node
}
func NewMethodCall(variable node.Node, name node.Node, arguments []node.Node) node.Node {
return MethodCall{
node.SimpleNode{Name: "MethodCall", Attributes: make(map[string]string)},
variable,
name,
arguments,
}
}
func (n MethodCall) Print(out io.Writer, indent string) {
fmt.Fprintf(out, "\n%v%v [- -]", indent, n.Name)
if n.variable != nil {
fmt.Fprintf(out, "\n%vvariable:", indent+" ")
n.variable.Print(out, indent+" ")
}
if n.name != nil {
fmt.Fprintf(out, "\n%vname:", indent+" ")
n.name.Print(out, indent+" ")
}
if n.arguments != nil {
fmt.Fprintf(out, "\n%varguments:", indent+" ")
for _, nn := range n.arguments {
nn.Print(out, indent+" ")
}
}
}

View File

@ -4617,7 +4617,7 @@ yydefault:
yyDollar = yyS[yypt-4 : yypt+1] yyDollar = yyS[yypt-4 : yypt+1]
//line parser/parser.y:1029 //line parser/parser.y:1029
{ {
yyVAL.node = node.NewSimpleNode("MethodCall").Append(yyDollar[1].node).Append(yyDollar[3].node).Append(yyDollar[4].node) yyVAL.node = expr.NewMethodCall(yyDollar[1].node, yyDollar[3].node, yyDollar[4].node.(node.SimpleNode).Children)
} }
case 430: case 430:
yyDollar = yyS[yypt-1 : yypt+1] yyDollar = yyS[yypt-1 : yypt+1]

View File

@ -1026,7 +1026,7 @@ callable_variable:
| constant '[' optional_expr ']' { $$ = expr.NewArrayDimFetch($1, $3) } | constant '[' optional_expr ']' { $$ = expr.NewArrayDimFetch($1, $3) }
| dereferencable '{' expr '}' { $$ = expr.NewArrayDimFetch($1, $3) } | dereferencable '{' expr '}' { $$ = expr.NewArrayDimFetch($1, $3) }
| dereferencable T_OBJECT_OPERATOR property_name argument_list | dereferencable T_OBJECT_OPERATOR property_name argument_list
{ $$ = node.NewSimpleNode("MethodCall").Append($1).Append($3).Append($4)} { $$ = expr.NewMethodCall($1, $3, $4.(node.SimpleNode).Children) }
| function_call { $$ = $1; } | function_call { $$ = $1; }
; ;