php-parser/node/expr/ternary.go

63 lines
1.0 KiB
Go
Raw Normal View History

2017-12-18 18:17:32 +00:00
package expr
import (
"github.com/z7zmey/php-parser/node"
)
type Ternary struct {
2017-12-29 15:53:13 +00:00
name string
attributes map[string]interface{}
condition node.Node
ifTrue node.Node
ifFalse node.Node
2017-12-18 18:17:32 +00:00
}
func NewTernary(condition node.Node, ifTrue node.Node, ifFalse node.Node) node.Node {
return Ternary{
2017-12-27 17:55:58 +00:00
"Ternary",
2017-12-29 15:53:13 +00:00
map[string]interface{}{},
2017-12-18 18:17:32 +00:00
condition,
ifTrue,
ifFalse,
}
}
2017-12-29 15:20:24 +00:00
func (n Ternary) Name() string {
return "Ternary"
}
func (n Ternary) Attributes() map[string]interface{} {
2017-12-29 15:53:13 +00:00
return n.attributes
2017-12-29 15:20:24 +00:00
}
2017-12-31 09:57:55 +00:00
func (n Ternary) Attribute(key string) interface{} {
return n.attributes[key]
}
func (n Ternary) SetAttribute(key string, value interface{}) {
n.attributes[key] = value
}
2017-12-27 23:23:32 +00:00
func (n Ternary) Walk(v node.Visitor) {
2017-12-28 11:36:27 +00:00
if v.EnterNode(n) == false {
2017-12-27 23:23:32 +00:00
return
}
2017-12-18 18:17:32 +00:00
if n.condition != nil {
2017-12-28 11:36:27 +00:00
vv := v.GetChildrenVisitor("condition")
2017-12-27 23:23:32 +00:00
n.condition.Walk(vv)
2017-12-18 18:17:32 +00:00
}
if n.ifTrue != nil {
2017-12-28 11:36:27 +00:00
vv := v.GetChildrenVisitor("ifTrue")
2017-12-27 23:23:32 +00:00
n.ifTrue.Walk(vv)
2017-12-18 18:17:32 +00:00
}
if n.ifFalse != nil {
2017-12-28 11:36:27 +00:00
vv := v.GetChildrenVisitor("ifFalse")
2017-12-27 23:23:32 +00:00
n.ifFalse.Walk(vv)
2017-12-18 18:17:32 +00:00
}
2017-12-28 11:36:27 +00:00
v.LeaveNode(n)
2017-12-18 18:17:32 +00:00
}