fix break and foreach nodes

This commit is contained in:
vadim
2017-12-22 14:07:38 +02:00
parent ae6fe52005
commit 9f48ca2968
4 changed files with 1389 additions and 1371 deletions

View File

@@ -24,6 +24,9 @@ func NewBreak(token token.Token, expr node.Node) node.Node {
func (n Break) Print(out io.Writer, indent string) {
fmt.Fprintf(out, "\n%v%v [%d %d] %q", indent, n.Name, n.token.StartLine, n.token.EndLine, n.token.Value)
fmt.Fprintf(out, "\n%vexpr:", indent+" ")
n.expr.Print(out, indent+" ")
if n.expr != nil {
fmt.Fprintf(out, "\n%vexpr:", indent+" ")
n.expr.Print(out, indent+" ")
}
}

View File

@@ -15,9 +15,10 @@ type Foreach struct {
key node.Node
variable node.Node
stmt node.Node
byRef bool
}
func NewForeach(token token.Token, expr node.Node, key node.Node, variable node.Node, stmt node.Node) node.Node {
func NewForeach(token token.Token, expr node.Node, key node.Node, variable node.Node, stmt node.Node, byRef bool) node.Node {
return Foreach{
node.SimpleNode{Name: "Foreach", Attributes: make(map[string]string)},
token,
@@ -25,6 +26,7 @@ func NewForeach(token token.Token, expr node.Node, key node.Node, variable node.
key,
variable,
stmt,
byRef,
}
}
@@ -42,7 +44,7 @@ func (n Foreach) Print(out io.Writer, indent string) {
}
if n.variable != nil {
fmt.Fprintf(out, "\n%vvariable:", indent+" ")
fmt.Fprintf(out, "\n%vvariable[byRef: %t]:", indent+" ", n.byRef)
n.variable.Print(out, indent+" ")
}