php-parser/node/expr/ternary.go

48 lines
842 B
Go
Raw Normal View History

2017-12-18 18:17:32 +00:00
package expr
import (
"fmt"
"io"
"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,
}
}
func (n Ternary) 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-18 18:17:32 +00:00
if n.condition != nil {
fmt.Fprintf(out, "\n%vcondition:", indent+" ")
n.condition.Print(out, indent+" ")
}
if n.ifTrue != nil {
fmt.Fprintf(out, "\n%vifTrue:", indent+" ")
n.ifTrue.Print(out, indent+" ")
}
if n.ifFalse != nil {
fmt.Fprintf(out, "\n%vifFalse:", indent+" ")
n.ifFalse.Print(out, indent+" ")
}
}