php-parser/node/expr/ternary.go

49 lines
747 B
Go
Raw Normal View History

2017-12-18 18:17:32 +00:00
package expr
import (
"github.com/z7zmey/php-parser/node"
)
2017-12-27 17:55:58 +00:00
func (n Ternary) Name() string {
return "Ternary"
}
2017-12-18 18:17:32 +00:00
type Ternary struct {
2017-12-27 17:55:58 +00:00
name string
2017-12-18 18:17:32 +00:00
condition node.Node
ifTrue node.Node
ifFalse node.Node
}
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-18 18:17:32 +00:00
condition,
ifTrue,
ifFalse,
}
}
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
}