php-parser/node/stmt/foreach.go

60 lines
1.1 KiB
Go
Raw Normal View History

2017-12-07 16:27:56 +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 Foreach) Name() string {
return "Foreach"
}
2017-12-07 16:27:56 +00:00
type Foreach struct {
2017-12-27 17:55:58 +00:00
name string
2017-12-07 16:27:56 +00:00
token token.Token
expr node.Node
key node.Node
variable node.Node
stmt node.Node
2017-12-22 12:07:38 +00:00
byRef bool
2017-12-07 16:27:56 +00:00
}
2017-12-22 12:07:38 +00:00
func NewForeach(token token.Token, expr node.Node, key node.Node, variable node.Node, stmt node.Node, byRef bool) node.Node {
2017-12-07 16:27:56 +00:00
return Foreach{
2017-12-27 17:55:58 +00:00
"Foreach",
2017-12-07 16:27:56 +00:00
token,
expr,
key,
variable,
stmt,
2017-12-22 12:07:38 +00:00
byRef,
2017-12-07 16:27:56 +00:00
}
}
func (n Foreach) 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:27:56 +00:00
if n.expr != nil {
fmt.Fprintf(out, "\n%vexpr:", indent+" ")
n.expr.Print(out, indent+" ")
}
if n.key != nil {
fmt.Fprintf(out, "\n%vkey:", indent+" ")
n.key.Print(out, indent+" ")
}
if n.variable != nil {
2017-12-22 12:07:38 +00:00
fmt.Fprintf(out, "\n%vvariable[byRef: %t]:", indent+" ", n.byRef)
2017-12-07 16:27:56 +00:00
n.variable.Print(out, indent+" ")
}
if n.stmt != nil {
fmt.Fprintf(out, "\n%vstmt:", indent+" ")
n.stmt.Print(out, indent+" ")
}
}