array_item node

This commit is contained in:
z7zmey
2017-12-16 21:08:39 +02:00
parent 9d17cc7477
commit d971494d12
3 changed files with 85 additions and 50 deletions

39
node/expr/array_item.go Normal file
View File

@@ -0,0 +1,39 @@
package expr
import (
"fmt"
"io"
"github.com/z7zmey/php-parser/node"
)
type ArrayItem struct {
node.SimpleNode
key node.Node
val node.Node
byRef bool
}
func NewArrayItem(key node.Node, val node.Node, byRef bool) node.Node {
return ArrayItem{
node.SimpleNode{Name: "ArrayItem", Attributes: make(map[string]string)},
key,
val,
byRef,
}
}
func (n ArrayItem) Print(out io.Writer, indent string) {
fmt.Fprintf(out, "\n%v%v [- -]", indent, n.Name)
fmt.Fprintf(out, "\n%vbyRef: %t", indent+" ", n.byRef)
if n.key != nil {
fmt.Fprintf(out, "\n%vkey:", indent+" ")
n.key.Print(out, indent+" ")
}
if n.val != nil {
fmt.Fprintf(out, "\n%vval:", indent+" ")
n.val.Print(out, indent+" ")
}
}