split Exit and Die nodes
This commit is contained in:
parent
f107e8bb57
commit
1c6633e47d
38
node/expr/n_die.go
Normal file
38
node/expr/n_die.go
Normal file
@ -0,0 +1,38 @@
|
||||
package expr
|
||||
|
||||
import (
|
||||
"github.com/z7zmey/php-parser/node"
|
||||
"github.com/z7zmey/php-parser/walker"
|
||||
)
|
||||
|
||||
// Die node
|
||||
type Die struct {
|
||||
Expr node.Node
|
||||
}
|
||||
|
||||
// NewDie node constuctor
|
||||
func NewDie(Expr node.Node) *Die {
|
||||
return &Die{
|
||||
Expr,
|
||||
}
|
||||
}
|
||||
|
||||
// Attributes returns node attributes as map
|
||||
func (n *Die) Attributes() map[string]interface{} {
|
||||
return nil
|
||||
}
|
||||
|
||||
// Walk traverses nodes
|
||||
// Walk is invoked recursively until v.EnterNode returns true
|
||||
func (n *Die) Walk(v walker.Visitor) {
|
||||
if v.EnterNode(n) == false {
|
||||
return
|
||||
}
|
||||
|
||||
if n.Expr != nil {
|
||||
vv := v.GetChildrenVisitor("Expr")
|
||||
n.Expr.Walk(vv)
|
||||
}
|
||||
|
||||
v.LeaveNode(n)
|
||||
}
|
@ -7,23 +7,19 @@ import (
|
||||
|
||||
// Exit node
|
||||
type Exit struct {
|
||||
Expr node.Node
|
||||
IsDie bool
|
||||
Expr node.Node
|
||||
}
|
||||
|
||||
// NewExit node constuctor
|
||||
func NewExit(Expr node.Node, IsDie bool) *Exit {
|
||||
func NewExit(Expr node.Node) *Exit {
|
||||
return &Exit{
|
||||
Expr,
|
||||
IsDie,
|
||||
}
|
||||
}
|
||||
|
||||
// Attributes returns node attributes as map
|
||||
func (n *Exit) Attributes() map[string]interface{} {
|
||||
return map[string]interface{}{
|
||||
"IsDie": n.IsDie,
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// Walk traverses nodes
|
||||
|
@ -18,9 +18,7 @@ func TestExit(t *testing.T) {
|
||||
expected := &stmt.StmtList{
|
||||
Stmts: []node.Node{
|
||||
&stmt.Expression{
|
||||
Expr: &expr.Exit{
|
||||
IsDie: false,
|
||||
},
|
||||
Expr: &expr.Exit{},
|
||||
},
|
||||
},
|
||||
}
|
||||
@ -39,8 +37,7 @@ func TestExitExpr(t *testing.T) {
|
||||
Stmts: []node.Node{
|
||||
&stmt.Expression{
|
||||
Expr: &expr.Exit{
|
||||
IsDie: false,
|
||||
Expr: &expr.Variable{VarName: &node.Identifier{Value: "$a"}},
|
||||
Expr: &expr.Variable{VarName: &node.Identifier{Value: "$a"}},
|
||||
},
|
||||
},
|
||||
},
|
||||
@ -59,9 +56,7 @@ func TestDie(t *testing.T) {
|
||||
expected := &stmt.StmtList{
|
||||
Stmts: []node.Node{
|
||||
&stmt.Expression{
|
||||
Expr: &expr.Exit{
|
||||
IsDie: true,
|
||||
},
|
||||
Expr: &expr.Die{},
|
||||
},
|
||||
},
|
||||
}
|
||||
@ -79,9 +74,8 @@ func TestDieExpr(t *testing.T) {
|
||||
expected := &stmt.StmtList{
|
||||
Stmts: []node.Node{
|
||||
&stmt.Expression{
|
||||
Expr: &expr.Exit{
|
||||
IsDie: true,
|
||||
Expr: &expr.Variable{VarName: &node.Identifier{Value: "$a"}},
|
||||
Expr: &expr.Die{
|
||||
Expr: &expr.Variable{VarName: &node.Identifier{Value: "$a"}},
|
||||
},
|
||||
},
|
||||
},
|
||||
|
@ -132,11 +132,17 @@ var nodesToTest = []struct {
|
||||
},
|
||||
{
|
||||
&expr.Exit{
|
||||
Expr: &expr.Variable{VarName: &node.Identifier{Value: "$a"}},
|
||||
IsDie: false,
|
||||
Expr: &expr.Variable{VarName: &node.Identifier{Value: "$a"}},
|
||||
},
|
||||
[]string{"Expr"},
|
||||
map[string]interface{}{"IsDie": false},
|
||||
map[string]interface{}{},
|
||||
},
|
||||
{
|
||||
&expr.Die{
|
||||
Expr: &expr.Variable{VarName: &node.Identifier{Value: "$a"}},
|
||||
},
|
||||
[]string{"Expr"},
|
||||
map[string]interface{}{},
|
||||
},
|
||||
{
|
||||
&expr.FunctionCall{
|
||||
|
450
php5/php5.go
450
php5/php5.go
File diff suppressed because it is too large
Load Diff
@ -2226,7 +2226,11 @@ expr_without_variable:
|
||||
}
|
||||
| T_EXIT exit_expr
|
||||
{
|
||||
$$ = expr.NewExit($2, strings.EqualFold($1.Value, "die"))
|
||||
if (strings.EqualFold($1.Value, "die")) {
|
||||
$$ = expr.NewDie($2)
|
||||
} else {
|
||||
$$ = expr.NewExit($2)
|
||||
}
|
||||
positions.AddPosition($$, positionBuilder.NewTokenNodePosition($1, $2))
|
||||
comments.AddComments($$, $1.Comments())
|
||||
}
|
||||
|
@ -2119,25 +2119,19 @@ CAD;
|
||||
},
|
||||
},
|
||||
&stmt.Expression{
|
||||
Expr: &expr.Exit{
|
||||
IsDie: false,
|
||||
},
|
||||
Expr: &expr.Exit{},
|
||||
},
|
||||
&stmt.Expression{
|
||||
Expr: &expr.Exit{
|
||||
IsDie: false,
|
||||
Expr: &expr.Variable{VarName: &node.Identifier{Value: "$a"}},
|
||||
Expr: &expr.Variable{VarName: &node.Identifier{Value: "$a"}},
|
||||
},
|
||||
},
|
||||
&stmt.Expression{
|
||||
Expr: &expr.Exit{
|
||||
IsDie: true,
|
||||
},
|
||||
Expr: &expr.Die{},
|
||||
},
|
||||
&stmt.Expression{
|
||||
Expr: &expr.Exit{
|
||||
IsDie: true,
|
||||
Expr: &expr.Variable{VarName: &node.Identifier{Value: "$a"}},
|
||||
Expr: &expr.Die{
|
||||
Expr: &expr.Variable{VarName: &node.Identifier{Value: "$a"}},
|
||||
},
|
||||
},
|
||||
&stmt.Expression{
|
||||
|
266
php7/php7.go
266
php7/php7.go
File diff suppressed because it is too large
Load Diff
@ -1844,7 +1844,11 @@ expr_without_variable:
|
||||
}
|
||||
| T_EXIT exit_expr
|
||||
{
|
||||
$$ = expr.NewExit($2, strings.EqualFold($1.Value, "die"))
|
||||
if (strings.EqualFold($1.Value, "die")) {
|
||||
$$ = expr.NewDie($2)
|
||||
} else {
|
||||
$$ = expr.NewExit($2)
|
||||
}
|
||||
positions.AddPosition($$, positionBuilder.NewTokenNodePosition($1, $2))
|
||||
comments.AddComments($$, $1.Comments())
|
||||
}
|
||||
|
@ -2206,25 +2206,19 @@ CAD;
|
||||
},
|
||||
},
|
||||
&stmt.Expression{
|
||||
Expr: &expr.Exit{
|
||||
IsDie: false,
|
||||
},
|
||||
Expr: &expr.Exit{},
|
||||
},
|
||||
&stmt.Expression{
|
||||
Expr: &expr.Exit{
|
||||
IsDie: false,
|
||||
Expr: &expr.Variable{VarName: &node.Identifier{Value: "$a"}},
|
||||
Expr: &expr.Variable{VarName: &node.Identifier{Value: "$a"}},
|
||||
},
|
||||
},
|
||||
&stmt.Expression{
|
||||
Expr: &expr.Exit{
|
||||
IsDie: true,
|
||||
},
|
||||
Expr: &expr.Die{},
|
||||
},
|
||||
&stmt.Expression{
|
||||
Expr: &expr.Exit{
|
||||
IsDie: true,
|
||||
Expr: &expr.Variable{VarName: &node.Identifier{Value: "$a"}},
|
||||
Expr: &expr.Die{
|
||||
Expr: &expr.Variable{VarName: &node.Identifier{Value: "$a"}},
|
||||
},
|
||||
},
|
||||
&stmt.Expression{
|
||||
|
Loading…
Reference in New Issue
Block a user