php-parser/node/expr/ternary.go

47 lines
696 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) {
if v.Visit(n) == false {
return
}
2017-12-18 18:17:32 +00:00
if n.condition != nil {
2017-12-27 23:23:32 +00:00
vv := v.Children("condition")
n.condition.Walk(vv)
2017-12-18 18:17:32 +00:00
}
if n.ifTrue != nil {
2017-12-27 23:23:32 +00:00
vv := v.Children("ifTrue")
n.ifTrue.Walk(vv)
2017-12-18 18:17:32 +00:00
}
if n.ifFalse != nil {
2017-12-27 23:23:32 +00:00
vv := v.Children("ifFalse")
n.ifFalse.Walk(vv)
2017-12-18 18:17:32 +00:00
}
}