slit While and AltWhile

This commit is contained in:
z7zmey
2018-02-18 19:44:17 +02:00
parent 1c6633e47d
commit d498ea9863
11 changed files with 1384 additions and 1301 deletions

45
node/stmt/n_alt_while.go Normal file
View File

@@ -0,0 +1,45 @@
package stmt
import (
"github.com/z7zmey/php-parser/node"
"github.com/z7zmey/php-parser/walker"
)
// AltWhile node
type AltWhile struct {
Cond node.Node
Stmt node.Node
}
// NewAltWhile node constuctor
func NewAltWhile(Cond node.Node, Stmt node.Node) *AltWhile {
return &AltWhile{
Cond,
Stmt,
}
}
// Attributes returns node attributes as map
func (n *AltWhile) Attributes() map[string]interface{} {
return nil
}
// Walk traverses nodes
// Walk is invoked recursively until v.EnterNode returns true
func (n *AltWhile) Walk(v walker.Visitor) {
if v.EnterNode(n) == false {
return
}
if n.Cond != nil {
vv := v.GetChildrenVisitor("Cond")
n.Cond.Walk(vv)
}
if n.Stmt != nil {
vv := v.GetChildrenVisitor("Stmt")
n.Stmt.Walk(vv)
}
v.LeaveNode(n)
}

View File

@@ -435,6 +435,14 @@ var nodesToTest = []struct {
[]string{"Cond", "Stmt"},
map[string]interface{}{},
},
{
&stmt.AltWhile{
Cond: &expr.Variable{},
Stmt: &stmt.StmtList{},
},
[]string{"Cond", "Stmt"},
map[string]interface{}{},
},
{
&stmt.StmtList{
Stmts: []node.Node{&stmt.Expression{}},

View File

@@ -65,7 +65,7 @@ func TestBreak(t *testing.T) {
expected := &stmt.StmtList{
Stmts: []node.Node{
&stmt.While{
&stmt.AltWhile{
Cond: &scalar.Lnumber{Value: "1"},
Stmt: &stmt.StmtList{
Stmts: []node.Node{