php-parser/node/expr/array_item.go

44 lines
725 B
Go
Raw Normal View History

2017-12-16 19:08:39 +00:00
package expr
import (
"fmt"
"io"
"github.com/z7zmey/php-parser/node"
)
2017-12-27 17:55:58 +00:00
func (n ArrayItem) Name() string {
return "ArrayItem"
}
2017-12-16 19:08:39 +00:00
type ArrayItem struct {
2017-12-27 17:55:58 +00:00
name string
key node.Node
val node.Node
2017-12-16 19:08:39 +00:00
byRef bool
}
func NewArrayItem(key node.Node, val node.Node, byRef bool) node.Node {
return ArrayItem{
2017-12-27 17:55:58 +00:00
"ArrayItem",
2017-12-16 19:08:39 +00:00
key,
val,
byRef,
}
}
func (n ArrayItem) Print(out io.Writer, indent string) {
2017-12-27 17:55:58 +00:00
fmt.Fprintf(out, "\n%v%v [- -]", indent, n.name)
2017-12-16 19:08:39 +00:00
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+" ")
}
}