php-parser/node/stmt/switch.go

46 lines
804 B
Go
Raw Normal View History

2017-12-09 09:59:53 +00:00
package stmt
import (
"fmt"
"io"
"github.com/z7zmey/php-parser/node"
"github.com/z7zmey/php-parser/token"
)
2017-12-27 17:55:58 +00:00
func(n Switch) Name() string {
return "Switch"
}
2017-12-09 09:59:53 +00:00
type Switch struct {
2017-12-27 17:55:58 +00:00
name string
2017-12-09 09:59:53 +00:00
token token.Token
cond node.Node
cases []node.Node
}
func NewSwitch(token token.Token, cond node.Node, cases []node.Node) node.Node {
return Switch{
2017-12-27 17:55:58 +00:00
"Switch",
2017-12-09 09:59:53 +00:00
token,
cond,
cases,
}
}
func (n Switch) Print(out io.Writer, indent string) {
2017-12-27 17:55:58 +00:00
fmt.Fprintf(out, "\n%v%v [%d %d] %q", indent, n.name, n.token.StartLine, n.token.EndLine, n.token.Value)
2017-12-09 09:59:53 +00:00
if n.cond != nil {
fmt.Fprintf(out, "\n%vcond:", indent+" ")
n.cond.Print(out, indent+" ")
}
if n.cases != nil {
fmt.Fprintf(out, "\n%vcases:", indent+" ")
for _, nn := range n.cases {
nn.Print(out, indent+" ")
}
}
}