create expr.Reference node
[wip] create expr.Reference node [wip] create expr.Reference node [wip] create expr.Reference node fix
This commit is contained in:
@@ -7,7 +7,6 @@ import (
|
||||
|
||||
// AltForeach node
|
||||
type AltForeach struct {
|
||||
ByRef bool
|
||||
Expr node.Node
|
||||
Key node.Node
|
||||
Variable node.Node
|
||||
@@ -15,9 +14,8 @@ type AltForeach struct {
|
||||
}
|
||||
|
||||
// NewAltForeach node constructor
|
||||
func NewAltForeach(Expr node.Node, Key node.Node, Variable node.Node, Stmt node.Node, ByRef bool) *AltForeach {
|
||||
func NewAltForeach(Expr node.Node, Key node.Node, Variable node.Node, Stmt node.Node) *AltForeach {
|
||||
return &AltForeach{
|
||||
ByRef,
|
||||
Expr,
|
||||
Key,
|
||||
Variable,
|
||||
@@ -27,9 +25,7 @@ func NewAltForeach(Expr node.Node, Key node.Node, Variable node.Node, Stmt node.
|
||||
|
||||
// Attributes returns node attributes as map
|
||||
func (n *AltForeach) Attributes() map[string]interface{} {
|
||||
return map[string]interface{}{
|
||||
"ByRef": n.ByRef,
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// Walk traverses nodes
|
||||
|
||||
@@ -7,7 +7,6 @@ import (
|
||||
|
||||
// Foreach node
|
||||
type Foreach struct {
|
||||
ByRef bool
|
||||
Expr node.Node
|
||||
Key node.Node
|
||||
Variable node.Node
|
||||
@@ -15,9 +14,8 @@ type Foreach struct {
|
||||
}
|
||||
|
||||
// NewForeach node constructor
|
||||
func NewForeach(Expr node.Node, Key node.Node, Variable node.Node, Stmt node.Node, ByRef bool) *Foreach {
|
||||
func NewForeach(Expr node.Node, Key node.Node, Variable node.Node, Stmt node.Node) *Foreach {
|
||||
return &Foreach{
|
||||
ByRef,
|
||||
Expr,
|
||||
Key,
|
||||
Variable,
|
||||
@@ -27,9 +25,7 @@ func NewForeach(Expr node.Node, Key node.Node, Variable node.Node, Stmt node.Nod
|
||||
|
||||
// Attributes returns node attributes as map
|
||||
func (n *Foreach) Attributes() map[string]interface{} {
|
||||
return map[string]interface{}{
|
||||
"ByRef": n.ByRef,
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// Walk traverses nodes
|
||||
|
||||
@@ -140,10 +140,9 @@ func TestForeachWithRef(t *testing.T) {
|
||||
expected := &node.Root{
|
||||
Stmts: []node.Node{
|
||||
&stmt.Foreach{
|
||||
ByRef: true,
|
||||
Expr: &expr.Variable{VarName: &node.Identifier{Value: "a"}},
|
||||
Key: &expr.Variable{VarName: &node.Identifier{Value: "k"}},
|
||||
Variable: &expr.Variable{VarName: &node.Identifier{Value: "v"}},
|
||||
Variable: &expr.Reference{Variable: &expr.Variable{VarName: &node.Identifier{Value: "v"}}},
|
||||
Stmt: &stmt.StmtList{Stmts: []node.Node{}},
|
||||
},
|
||||
},
|
||||
@@ -166,14 +165,12 @@ func TestForeachWithList(t *testing.T) {
|
||||
expected := &node.Root{
|
||||
Stmts: []node.Node{
|
||||
&stmt.Foreach{
|
||||
ByRef: false,
|
||||
Expr: &expr.Variable{VarName: &node.Identifier{Value: "a"}},
|
||||
Key: &expr.Variable{VarName: &node.Identifier{Value: "k"}},
|
||||
Expr: &expr.Variable{VarName: &node.Identifier{Value: "a"}},
|
||||
Key: &expr.Variable{VarName: &node.Identifier{Value: "k"}},
|
||||
Variable: &expr.List{
|
||||
Items: []node.Node{
|
||||
&expr.ArrayItem{
|
||||
ByRef: false,
|
||||
Val: &expr.Variable{VarName: &node.Identifier{Value: "v"}},
|
||||
Val: &expr.Variable{VarName: &node.Identifier{Value: "v"}},
|
||||
},
|
||||
},
|
||||
},
|
||||
|
||||
@@ -224,25 +224,23 @@ var nodesToTest = []struct {
|
||||
},
|
||||
{
|
||||
&stmt.Foreach{
|
||||
ByRef: true,
|
||||
Expr: &stmt.Expression{},
|
||||
Key: &expr.Variable{},
|
||||
Variable: &expr.Variable{},
|
||||
Stmt: &stmt.StmtList{},
|
||||
},
|
||||
[]string{"Expr", "Key", "Variable", "Stmt"},
|
||||
map[string]interface{}{"ByRef": true},
|
||||
map[string]interface{}{},
|
||||
},
|
||||
{
|
||||
&stmt.AltForeach{
|
||||
ByRef: true,
|
||||
Expr: &stmt.Expression{},
|
||||
Key: &expr.Variable{},
|
||||
Variable: &expr.Variable{},
|
||||
Stmt: &stmt.StmtList{},
|
||||
},
|
||||
[]string{"Expr", "Key", "Variable", "Stmt"},
|
||||
map[string]interface{}{"ByRef": true},
|
||||
map[string]interface{}{},
|
||||
},
|
||||
{
|
||||
&stmt.Function{
|
||||
|
||||
Reference in New Issue
Block a user