php-parser/node/stmt/for.go

64 lines
1.1 KiB
Go
Raw Normal View History

2017-12-07 16:15:48 +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 For) Name() string {
return "For"
}
2017-12-07 16:15:48 +00:00
type For struct {
2017-12-27 17:55:58 +00:00
name string
2017-12-07 16:15:48 +00:00
token token.Token
init []node.Node
cond []node.Node
loop []node.Node
stmt node.Node
}
func NewFor(token token.Token, init []node.Node, cond []node.Node, loop []node.Node, stmt node.Node) node.Node {
return For{
2017-12-27 17:55:58 +00:00
"For",
2017-12-07 16:15:48 +00:00
token,
init,
cond,
loop,
stmt,
}
}
func (n For) 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-07 16:15:48 +00:00
if n.init != nil {
fmt.Fprintf(out, "\n%vinit:", indent+" ")
for _, nn := range n.init {
nn.Print(out, indent+" ")
}
}
if n.cond != nil {
fmt.Fprintf(out, "\n%vcond:", indent+" ")
for _, nn := range n.cond {
nn.Print(out, indent+" ")
}
}
if n.loop != nil {
fmt.Fprintf(out, "\n%vloop:", indent+" ")
for _, nn := range n.loop {
nn.Print(out, indent+" ")
}
}
if n.stmt != nil {
fmt.Fprintf(out, "\n%vstmt:", indent+" ")
n.stmt.Print(out, indent+" ")
}
}