diff --git a/.gitignore b/.gitignore index 032c7f4..4592fa6 100644 --- a/.gitignore +++ b/.gitignore @@ -1,8 +1,8 @@ .vscode php-parser +**/*.test + *example.php cpu.pprof mem.pprof -php7.test -php5.test diff --git a/node/expr/n_die.go b/node/expr/n_die.go deleted file mode 100644 index 6346645..0000000 --- a/node/expr/n_die.go +++ /dev/null @@ -1,61 +0,0 @@ -package expr - -import ( - "github.com/z7zmey/php-parser/meta" - "github.com/z7zmey/php-parser/node" - "github.com/z7zmey/php-parser/position" - "github.com/z7zmey/php-parser/walker" -) - -// Die node -type Die struct { - Meta []meta.Meta - Position *position.Position - Expr node.Node -} - -// NewDie node constructor -func NewDie(Expr node.Node) *Die { - return &Die{ - Expr: Expr, - } -} - -// SetPosition sets node position -func (n *Die) SetPosition(p *position.Position) { - n.Position = p -} - -// GetPosition returns node positions -func (n *Die) GetPosition() *position.Position { - return n.Position -} - -func (n *Die) AddMeta(m []meta.Meta) { - n.Meta = append(n.Meta, m...) -} - -func (n *Die) GetMeta() []meta.Meta { - return n.Meta -} - -// 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 { - v.EnterChildNode("Expr", n) - n.Expr.Walk(v) - v.LeaveChildNode("Expr", n) - } - - v.LeaveNode(n) -} diff --git a/node/expr/n_exit.go b/node/expr/n_exit.go index d2e90be..721f2f2 100644 --- a/node/expr/n_exit.go +++ b/node/expr/n_exit.go @@ -10,6 +10,7 @@ import ( // Exit node type Exit struct { Meta []meta.Meta + Die bool Position *position.Position Expr node.Node } @@ -41,7 +42,9 @@ func (n *Exit) GetMeta() []meta.Meta { // Attributes returns node attributes as map func (n *Exit) Attributes() map[string]interface{} { - return nil + return map[string]interface{}{ + "Die": n.Die, + } } // Walk traverses nodes diff --git a/node/expr/t_exit_test.go b/node/expr/t_exit_test.go index 9a12acf..5a71604 100644 --- a/node/expr/t_exit_test.go +++ b/node/expr/t_exit_test.go @@ -32,6 +32,7 @@ func TestExit(t *testing.T) { EndPos: 8, }, Expr: &expr.Exit{ + Die: false, Position: &position.Position{ StartLine: 1, EndLine: 1, @@ -54,6 +55,48 @@ func TestExit(t *testing.T) { assertEqual(t, expected, actual) } +func TestExitEmpty(t *testing.T) { + src := `