This commit is contained in:
z7zmey 2017-12-18 18:51:16 +02:00
parent 4fc5d37b48
commit 85f7765e79
3 changed files with 42 additions and 4 deletions

38
node/expr/new.go Normal file
View File

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

View File

@ -3787,13 +3787,13 @@ yydefault:
yyDollar = yyS[yypt-3 : yypt+1] yyDollar = yyS[yypt-3 : yypt+1]
//line parser/parser.y:811 //line parser/parser.y:811
{ {
yyVAL.node = node.NewSimpleNode("New").Append(yyDollar[2].node).Append(yyDollar[3].node) yyVAL.node = expr.NewNew(yyDollar[2].node, yyDollar[3].node.(node.SimpleNode).Children)
} }
case 292: case 292:
yyDollar = yyS[yypt-2 : yypt+1] yyDollar = yyS[yypt-2 : yypt+1]
//line parser/parser.y:812 //line parser/parser.y:812
{ {
yyVAL.node = node.NewSimpleNode("New").Append(yyDollar[2].node) yyVAL.node = expr.NewNew(yyDollar[2].node, nil)
} }
case 293: case 293:
yyDollar = yyS[yypt-6 : yypt+1] yyDollar = yyS[yypt-6 : yypt+1]

View File

@ -808,8 +808,8 @@ anonymous_class:
; ;
new_expr: new_expr:
T_NEW class_name_reference ctor_arguments { $$ = node.NewSimpleNode("New").Append($2).Append($3) } T_NEW class_name_reference ctor_arguments { $$ = expr.NewNew($2, $3.(node.SimpleNode).Children) }
| T_NEW anonymous_class { $$ = node.NewSimpleNode("New").Append($2) } | T_NEW anonymous_class { $$ = expr.NewNew($2, nil) }
; ;
expr_without_variable: expr_without_variable: