create Root node

This commit is contained in:
z7zmey 2018-05-02 12:14:24 +03:00
parent d1b0cebf9a
commit 2abe1dfb84
82 changed files with 363 additions and 309 deletions

View File

@ -32,7 +32,7 @@ func assertEqual(t *testing.T, expected interface{}, actual interface{}) {
func TestReference(t *testing.T) {
src := `<? $a =& $b;`
expected := &stmt.StmtList{
expected := &node.Root{
Stmts: []node.Node{
&stmt.Expression{
Expr: &assign.Reference{
@ -57,7 +57,7 @@ func TestReference(t *testing.T) {
func TestReferenceNew(t *testing.T) {
src := `<? $a =& new Foo;`
expected := &stmt.StmtList{
expected := &node.Root{
Stmts: []node.Node{
&stmt.Expression{
Expr: &assign.Reference{
@ -88,7 +88,7 @@ func TestReferenceNew(t *testing.T) {
func TestReferenceArgs(t *testing.T) {
src := `<? $a =& new Foo($b);`
expected := &stmt.StmtList{
expected := &node.Root{
Stmts: []node.Node{
&stmt.Expression{
Expr: &assign.Reference{
@ -128,7 +128,7 @@ func TestReferenceArgs(t *testing.T) {
func TestAssign(t *testing.T) {
src := `<? $a = $b;`
expected := &stmt.StmtList{
expected := &node.Root{
Stmts: []node.Node{
&stmt.Expression{
Expr: &assign.Assign{
@ -153,7 +153,7 @@ func TestAssign(t *testing.T) {
func TestBitwiseAnd(t *testing.T) {
src := `<? $a &= $b;`
expected := &stmt.StmtList{
expected := &node.Root{
Stmts: []node.Node{
&stmt.Expression{
Expr: &assign.BitwiseAnd{
@ -178,7 +178,7 @@ func TestBitwiseAnd(t *testing.T) {
func TestBitwiseOr(t *testing.T) {
src := `<? $a |= $b;`
expected := &stmt.StmtList{
expected := &node.Root{
Stmts: []node.Node{
&stmt.Expression{
Expr: &assign.BitwiseOr{
@ -203,7 +203,7 @@ func TestBitwiseOr(t *testing.T) {
func TestBitwiseXor(t *testing.T) {
src := `<? $a ^= $b;`
expected := &stmt.StmtList{
expected := &node.Root{
Stmts: []node.Node{
&stmt.Expression{
Expr: &assign.BitwiseXor{
@ -228,7 +228,7 @@ func TestBitwiseXor(t *testing.T) {
func TestConcat(t *testing.T) {
src := `<? $a .= $b;`
expected := &stmt.StmtList{
expected := &node.Root{
Stmts: []node.Node{
&stmt.Expression{
Expr: &assign.Concat{
@ -253,7 +253,7 @@ func TestConcat(t *testing.T) {
func TestDiv(t *testing.T) {
src := `<? $a /= $b;`
expected := &stmt.StmtList{
expected := &node.Root{
Stmts: []node.Node{
&stmt.Expression{
Expr: &assign.Div{
@ -278,7 +278,7 @@ func TestDiv(t *testing.T) {
func TestMinus(t *testing.T) {
src := `<? $a -= $b;`
expected := &stmt.StmtList{
expected := &node.Root{
Stmts: []node.Node{
&stmt.Expression{
Expr: &assign.Minus{
@ -303,7 +303,7 @@ func TestMinus(t *testing.T) {
func TestMod(t *testing.T) {
src := `<? $a %= $b;`
expected := &stmt.StmtList{
expected := &node.Root{
Stmts: []node.Node{
&stmt.Expression{
Expr: &assign.Mod{
@ -328,7 +328,7 @@ func TestMod(t *testing.T) {
func TestMul(t *testing.T) {
src := `<? $a *= $b;`
expected := &stmt.StmtList{
expected := &node.Root{
Stmts: []node.Node{
&stmt.Expression{
Expr: &assign.Mul{
@ -353,7 +353,7 @@ func TestMul(t *testing.T) {
func TestPlus(t *testing.T) {
src := `<? $a += $b;`
expected := &stmt.StmtList{
expected := &node.Root{
Stmts: []node.Node{
&stmt.Expression{
Expr: &assign.Plus{
@ -378,7 +378,7 @@ func TestPlus(t *testing.T) {
func TestPow(t *testing.T) {
src := `<? $a **= $b;`
expected := &stmt.StmtList{
expected := &node.Root{
Stmts: []node.Node{
&stmt.Expression{
Expr: &assign.Pow{
@ -403,7 +403,7 @@ func TestPow(t *testing.T) {
func TestShiftLeft(t *testing.T) {
src := `<? $a <<= $b;`
expected := &stmt.StmtList{
expected := &node.Root{
Stmts: []node.Node{
&stmt.Expression{
Expr: &assign.ShiftLeft{
@ -428,7 +428,7 @@ func TestShiftLeft(t *testing.T) {
func TestShiftRight(t *testing.T) {
src := `<? $a >>= $b;`
expected := &stmt.StmtList{
expected := &node.Root{
Stmts: []node.Node{
&stmt.Expression{
Expr: &assign.ShiftRight{

View File

@ -30,7 +30,7 @@ func assertEqual(t *testing.T, expected interface{}, actual interface{}) {
func TestBitwiseAnd(t *testing.T) {
src := `<? $a & $b;`
expected := &stmt.StmtList{
expected := &node.Root{
Stmts: []node.Node{
&stmt.Expression{
Expr: &binary.BitwiseAnd{
@ -55,7 +55,7 @@ func TestBitwiseAnd(t *testing.T) {
func TestBitwiseOr(t *testing.T) {
src := `<? $a | $b;`
expected := &stmt.StmtList{
expected := &node.Root{
Stmts: []node.Node{
&stmt.Expression{
Expr: &binary.BitwiseOr{
@ -80,7 +80,7 @@ func TestBitwiseOr(t *testing.T) {
func TestBitwiseXor(t *testing.T) {
src := `<? $a ^ $b;`
expected := &stmt.StmtList{
expected := &node.Root{
Stmts: []node.Node{
&stmt.Expression{
Expr: &binary.BitwiseXor{
@ -105,7 +105,7 @@ func TestBitwiseXor(t *testing.T) {
func TestBooleanAnd(t *testing.T) {
src := `<? $a && $b;`
expected := &stmt.StmtList{
expected := &node.Root{
Stmts: []node.Node{
&stmt.Expression{
Expr: &binary.BooleanAnd{
@ -130,7 +130,7 @@ func TestBooleanAnd(t *testing.T) {
func TestBooleanOr(t *testing.T) {
src := `<? $a || $b;`
expected := &stmt.StmtList{
expected := &node.Root{
Stmts: []node.Node{
&stmt.Expression{
Expr: &binary.BooleanOr{
@ -155,7 +155,7 @@ func TestBooleanOr(t *testing.T) {
func TestCoalesce(t *testing.T) {
src := `<? $a ?? $b;`
expected := &stmt.StmtList{
expected := &node.Root{
Stmts: []node.Node{
&stmt.Expression{
Expr: &binary.Coalesce{
@ -175,7 +175,7 @@ func TestCoalesce(t *testing.T) {
func TestConcat(t *testing.T) {
src := `<? $a . $b;`
expected := &stmt.StmtList{
expected := &node.Root{
Stmts: []node.Node{
&stmt.Expression{
Expr: &binary.Concat{
@ -200,7 +200,7 @@ func TestConcat(t *testing.T) {
func TestDiv(t *testing.T) {
src := `<? $a / $b;`
expected := &stmt.StmtList{
expected := &node.Root{
Stmts: []node.Node{
&stmt.Expression{
Expr: &binary.Div{
@ -225,7 +225,7 @@ func TestDiv(t *testing.T) {
func TestEqual(t *testing.T) {
src := `<? $a == $b;`
expected := &stmt.StmtList{
expected := &node.Root{
Stmts: []node.Node{
&stmt.Expression{
Expr: &binary.Equal{
@ -250,7 +250,7 @@ func TestEqual(t *testing.T) {
func TestGreaterOrEqual(t *testing.T) {
src := `<? $a >= $b;`
expected := &stmt.StmtList{
expected := &node.Root{
Stmts: []node.Node{
&stmt.Expression{
Expr: &binary.GreaterOrEqual{
@ -275,7 +275,7 @@ func TestGreaterOrEqual(t *testing.T) {
func TestGreater(t *testing.T) {
src := `<? $a > $b;`
expected := &stmt.StmtList{
expected := &node.Root{
Stmts: []node.Node{
&stmt.Expression{
Expr: &binary.Greater{
@ -300,7 +300,7 @@ func TestGreater(t *testing.T) {
func TestIdentical(t *testing.T) {
src := `<? $a === $b;`
expected := &stmt.StmtList{
expected := &node.Root{
Stmts: []node.Node{
&stmt.Expression{
Expr: &binary.Identical{
@ -325,7 +325,7 @@ func TestIdentical(t *testing.T) {
func TestLogicalAnd(t *testing.T) {
src := `<? $a and $b;`
expected := &stmt.StmtList{
expected := &node.Root{
Stmts: []node.Node{
&stmt.Expression{
Expr: &binary.LogicalAnd{
@ -350,7 +350,7 @@ func TestLogicalAnd(t *testing.T) {
func TestLogicalOr(t *testing.T) {
src := `<? $a or $b;`
expected := &stmt.StmtList{
expected := &node.Root{
Stmts: []node.Node{
&stmt.Expression{
Expr: &binary.LogicalOr{
@ -375,7 +375,7 @@ func TestLogicalOr(t *testing.T) {
func TestLogicalXor(t *testing.T) {
src := `<? $a xor $b;`
expected := &stmt.StmtList{
expected := &node.Root{
Stmts: []node.Node{
&stmt.Expression{
Expr: &binary.LogicalXor{
@ -400,7 +400,7 @@ func TestLogicalXor(t *testing.T) {
func TestMinus(t *testing.T) {
src := `<? $a - $b;`
expected := &stmt.StmtList{
expected := &node.Root{
Stmts: []node.Node{
&stmt.Expression{
Expr: &binary.Minus{
@ -425,7 +425,7 @@ func TestMinus(t *testing.T) {
func TestMod(t *testing.T) {
src := `<? $a % $b;`
expected := &stmt.StmtList{
expected := &node.Root{
Stmts: []node.Node{
&stmt.Expression{
Expr: &binary.Mod{
@ -450,7 +450,7 @@ func TestMod(t *testing.T) {
func TestMul(t *testing.T) {
src := `<? $a * $b;`
expected := &stmt.StmtList{
expected := &node.Root{
Stmts: []node.Node{
&stmt.Expression{
Expr: &binary.Mul{
@ -475,7 +475,7 @@ func TestMul(t *testing.T) {
func TestNotEqual(t *testing.T) {
src := `<? $a != $b;`
expected := &stmt.StmtList{
expected := &node.Root{
Stmts: []node.Node{
&stmt.Expression{
Expr: &binary.NotEqual{
@ -500,7 +500,7 @@ func TestNotEqual(t *testing.T) {
func TestNotIdentical(t *testing.T) {
src := `<? $a !== $b;`
expected := &stmt.StmtList{
expected := &node.Root{
Stmts: []node.Node{
&stmt.Expression{
Expr: &binary.NotIdentical{
@ -525,7 +525,7 @@ func TestNotIdentical(t *testing.T) {
func TestPlus(t *testing.T) {
src := `<? $a + $b;`
expected := &stmt.StmtList{
expected := &node.Root{
Stmts: []node.Node{
&stmt.Expression{
Expr: &binary.Plus{
@ -550,7 +550,7 @@ func TestPlus(t *testing.T) {
func TestPow(t *testing.T) {
src := `<? $a ** $b;`
expected := &stmt.StmtList{
expected := &node.Root{
Stmts: []node.Node{
&stmt.Expression{
Expr: &binary.Pow{
@ -575,7 +575,7 @@ func TestPow(t *testing.T) {
func TestShiftLeft(t *testing.T) {
src := `<? $a << $b;`
expected := &stmt.StmtList{
expected := &node.Root{
Stmts: []node.Node{
&stmt.Expression{
Expr: &binary.ShiftLeft{
@ -600,7 +600,7 @@ func TestShiftLeft(t *testing.T) {
func TestShiftRight(t *testing.T) {
src := `<? $a >> $b;`
expected := &stmt.StmtList{
expected := &node.Root{
Stmts: []node.Node{
&stmt.Expression{
Expr: &binary.ShiftRight{
@ -625,7 +625,7 @@ func TestShiftRight(t *testing.T) {
func TestSmallerOrEqual(t *testing.T) {
src := `<? $a <= $b;`
expected := &stmt.StmtList{
expected := &node.Root{
Stmts: []node.Node{
&stmt.Expression{
Expr: &binary.SmallerOrEqual{
@ -650,7 +650,7 @@ func TestSmallerOrEqual(t *testing.T) {
func TestSmaller(t *testing.T) {
src := `<? $a < $b;`
expected := &stmt.StmtList{
expected := &node.Root{
Stmts: []node.Node{
&stmt.Expression{
Expr: &binary.Smaller{
@ -675,7 +675,7 @@ func TestSmaller(t *testing.T) {
func TestSpaceship(t *testing.T) {
src := `<? $a <=> $b;`
expected := &stmt.StmtList{
expected := &node.Root{
Stmts: []node.Node{
&stmt.Expression{
Expr: &binary.Spaceship{

View File

@ -30,7 +30,7 @@ func assertEqual(t *testing.T, expected interface{}, actual interface{}) {
func TestArray(t *testing.T) {
src := `<? (array)$a;`
expected := &stmt.StmtList{
expected := &node.Root{
Stmts: []node.Node{
&stmt.Expression{
Expr: &cast.Array{
@ -54,7 +54,7 @@ func TestArray(t *testing.T) {
func TestBool(t *testing.T) {
src := `<? (boolean)$a;`
expected := &stmt.StmtList{
expected := &node.Root{
Stmts: []node.Node{
&stmt.Expression{
Expr: &cast.Bool{
@ -78,7 +78,7 @@ func TestBool(t *testing.T) {
func TestBoolShort(t *testing.T) {
src := `<? (bool)$a;`
expected := &stmt.StmtList{
expected := &node.Root{
Stmts: []node.Node{
&stmt.Expression{
Expr: &cast.Bool{
@ -102,7 +102,7 @@ func TestBoolShort(t *testing.T) {
func TestDouble(t *testing.T) {
src := `<? (double)$a;`
expected := &stmt.StmtList{
expected := &node.Root{
Stmts: []node.Node{
&stmt.Expression{
Expr: &cast.Double{
@ -126,7 +126,7 @@ func TestDouble(t *testing.T) {
func TestCastFloat(t *testing.T) {
src := `<? (float)$a;`
expected := &stmt.StmtList{
expected := &node.Root{
Stmts: []node.Node{
&stmt.Expression{
Expr: &cast.Double{
@ -150,7 +150,7 @@ func TestCastFloat(t *testing.T) {
func TestInt(t *testing.T) {
src := `<? (integer)$a;`
expected := &stmt.StmtList{
expected := &node.Root{
Stmts: []node.Node{
&stmt.Expression{
Expr: &cast.Int{
@ -174,7 +174,7 @@ func TestInt(t *testing.T) {
func TestIntShort(t *testing.T) {
src := `<? (int)$a;`
expected := &stmt.StmtList{
expected := &node.Root{
Stmts: []node.Node{
&stmt.Expression{
Expr: &cast.Int{
@ -198,7 +198,7 @@ func TestIntShort(t *testing.T) {
func TestObject(t *testing.T) {
src := `<? (object)$a;`
expected := &stmt.StmtList{
expected := &node.Root{
Stmts: []node.Node{
&stmt.Expression{
Expr: &cast.Object{
@ -222,7 +222,7 @@ func TestObject(t *testing.T) {
func TestString(t *testing.T) {
src := `<? (string)$a;`
expected := &stmt.StmtList{
expected := &node.Root{
Stmts: []node.Node{
&stmt.Expression{
Expr: &cast.String{
@ -246,7 +246,7 @@ func TestString(t *testing.T) {
func TestUnset(t *testing.T) {
src := `<? (unset)$a;`
expected := &stmt.StmtList{
expected := &node.Root{
Stmts: []node.Node{
&stmt.Expression{
Expr: &cast.Unset{

View File

@ -31,7 +31,7 @@ func assertEqual(t *testing.T, expected interface{}, actual interface{}) {
func TestArrayDimFetch(t *testing.T) {
src := `<? $a[1];`
expected := &stmt.StmtList{
expected := &node.Root{
Stmts: []node.Node{
&stmt.Expression{
Expr: &expr.ArrayDimFetch{
@ -56,7 +56,7 @@ func TestArrayDimFetch(t *testing.T) {
func TestArrayDimFetchNested(t *testing.T) {
src := `<? $a[1][2];`
expected := &stmt.StmtList{
expected := &node.Root{
Stmts: []node.Node{
&stmt.Expression{
Expr: &expr.ArrayDimFetch{

View File

@ -17,7 +17,7 @@ import (
func TestArray(t *testing.T) {
src := `<? array();`
expected := &stmt.StmtList{
expected := &node.Root{
Stmts: []node.Node{
&stmt.Expression{
Expr: &expr.Array{
@ -41,7 +41,7 @@ func TestArray(t *testing.T) {
func TestArrayItem(t *testing.T) {
src := `<? array(1);`
expected := &stmt.StmtList{
expected := &node.Root{
Stmts: []node.Node{
&stmt.Expression{
Expr: &expr.Array{
@ -70,7 +70,7 @@ func TestArrayItem(t *testing.T) {
func TestArrayItems(t *testing.T) {
src := `<? array(1=>1, &$b,);`
expected := &stmt.StmtList{
expected := &node.Root{
Stmts: []node.Node{
&stmt.Expression{
Expr: &expr.Array{

View File

@ -15,7 +15,7 @@ import (
func TestBitwiseNot(t *testing.T) {
src := `<? ~$a;`
expected := &stmt.StmtList{
expected := &node.Root{
Stmts: []node.Node{
&stmt.Expression{
Expr: &expr.BitwiseNot{

View File

@ -15,7 +15,7 @@ import (
func TestBooleanNot(t *testing.T) {
src := `<? !$a;`
expected := &stmt.StmtList{
expected := &node.Root{
Stmts: []node.Node{
&stmt.Expression{
Expr: &expr.BooleanNot{

View File

@ -17,7 +17,7 @@ import (
func TestClassConstFetch(t *testing.T) {
src := `<? Foo::Bar;`
expected := &stmt.StmtList{
expected := &node.Root{
Stmts: []node.Node{
&stmt.Expression{
Expr: &expr.ClassConstFetch{
@ -46,7 +46,7 @@ func TestClassConstFetch(t *testing.T) {
func TestStaticClassConstFetch(t *testing.T) {
src := `<? static::bar;`
expected := &stmt.StmtList{
expected := &node.Root{
Stmts: []node.Node{
&stmt.Expression{
Expr: &expr.ClassConstFetch{

View File

@ -15,7 +15,7 @@ import (
func TestCloneBrackets(t *testing.T) {
src := `<? clone($a);`
expected := &stmt.StmtList{
expected := &node.Root{
Stmts: []node.Node{
&stmt.Expression{
Expr: &expr.Clone{
@ -39,7 +39,7 @@ func TestCloneBrackets(t *testing.T) {
func TestClone(t *testing.T) {
src := `<? clone $a;`
expected := &stmt.StmtList{
expected := &node.Root{
Stmts: []node.Node{
&stmt.Expression{
Expr: &expr.Clone{

View File

@ -17,7 +17,7 @@ import (
func TestClosure(t *testing.T) {
src := `<? function(){};`
expected := &stmt.StmtList{
expected := &node.Root{
Stmts: []node.Node{
&stmt.Expression{
Expr: &expr.Closure{
@ -45,7 +45,7 @@ func TestClosure(t *testing.T) {
func TestClosureUse(t *testing.T) {
src := `<? function($a, $b) use ($c, &$d) {};`
expected := &stmt.StmtList{
expected := &node.Root{
Stmts: []node.Node{
&stmt.Expression{
Expr: &expr.Closure{
@ -94,7 +94,7 @@ func TestClosureUse(t *testing.T) {
func TestClosureUse2(t *testing.T) {
src := `<? function($a, $b) use (&$c, $d) {};`
expected := &stmt.StmtList{
expected := &node.Root{
Stmts: []node.Node{
&stmt.Expression{
Expr: &expr.Closure{
@ -143,7 +143,7 @@ func TestClosureUse2(t *testing.T) {
func TestClosureReturnType(t *testing.T) {
src := `<? function(): void {};`
expected := &stmt.StmtList{
expected := &node.Root{
Stmts: []node.Node{
&stmt.Expression{
Expr: &expr.Closure{

View File

@ -17,7 +17,7 @@ import (
func TestConstFetch(t *testing.T) {
src := `<? foo;`
expected := &stmt.StmtList{
expected := &node.Root{
Stmts: []node.Node{
&stmt.Expression{
Expr: &expr.ConstFetch{
@ -41,7 +41,7 @@ func TestConstFetch(t *testing.T) {
func TestConstFetchRelative(t *testing.T) {
src := `<? namespace\foo;`
expected := &stmt.StmtList{
expected := &node.Root{
Stmts: []node.Node{
&stmt.Expression{
Expr: &expr.ConstFetch{
@ -65,7 +65,7 @@ func TestConstFetchRelative(t *testing.T) {
func TestConstFetchFullyQualified(t *testing.T) {
src := `<? \foo;`
expected := &stmt.StmtList{
expected := &node.Root{
Stmts: []node.Node{
&stmt.Expression{
Expr: &expr.ConstFetch{

View File

@ -15,7 +15,7 @@ import (
func TestEmpty(t *testing.T) {
src := `<? empty($a);`
expected := &stmt.StmtList{
expected := &node.Root{
Stmts: []node.Node{
&stmt.Expression{
Expr: &expr.Empty{

View File

@ -15,7 +15,7 @@ import (
func TestErrorSuppress(t *testing.T) {
src := `<? @$a;`
expected := &stmt.StmtList{
expected := &node.Root{
Stmts: []node.Node{
&stmt.Expression{
Expr: &expr.ErrorSuppress{

View File

@ -15,7 +15,7 @@ import (
func TestEval(t *testing.T) {
src := `<? eval($a);`
expected := &stmt.StmtList{
expected := &node.Root{
Stmts: []node.Node{
&stmt.Expression{
Expr: &expr.Eval{

View File

@ -15,7 +15,7 @@ import (
func TestExit(t *testing.T) {
src := `<? exit;`
expected := &stmt.StmtList{
expected := &node.Root{
Stmts: []node.Node{
&stmt.Expression{
Expr: &expr.Exit{},
@ -37,7 +37,7 @@ func TestExit(t *testing.T) {
func TestExitExpr(t *testing.T) {
src := `<? exit($a);`
expected := &stmt.StmtList{
expected := &node.Root{
Stmts: []node.Node{
&stmt.Expression{
Expr: &expr.Exit{
@ -61,7 +61,7 @@ func TestExitExpr(t *testing.T) {
func TestDie(t *testing.T) {
src := `<? die;`
expected := &stmt.StmtList{
expected := &node.Root{
Stmts: []node.Node{
&stmt.Expression{
Expr: &expr.Die{},
@ -83,7 +83,7 @@ func TestDie(t *testing.T) {
func TestDieExpr(t *testing.T) {
src := `<? die($a);`
expected := &stmt.StmtList{
expected := &node.Root{
Stmts: []node.Node{
&stmt.Expression{
Expr: &expr.Die{

View File

@ -20,7 +20,7 @@ import (
func TestFunctionCall(t *testing.T) {
src := `<? foo();`
expected := &stmt.StmtList{
expected := &node.Root{
Stmts: []node.Node{
&stmt.Expression{
Expr: &expr.FunctionCall{
@ -49,7 +49,7 @@ func TestFunctionCall(t *testing.T) {
func TestFunctionCallRelative(t *testing.T) {
src := `<? namespace\foo();`
expected := &stmt.StmtList{
expected := &node.Root{
Stmts: []node.Node{
&stmt.Expression{
Expr: &expr.FunctionCall{
@ -78,7 +78,7 @@ func TestFunctionCallRelative(t *testing.T) {
func TestFunctionFullyQualified(t *testing.T) {
src := `<? \foo([]);`
expected := &stmt.StmtList{
expected := &node.Root{
Stmts: []node.Node{
&stmt.Expression{
Expr: &expr.FunctionCall{
@ -117,7 +117,7 @@ func TestFunctionFullyQualified(t *testing.T) {
func TestFunctionCallVar(t *testing.T) {
src := `<? $foo(yield $a);`
expected := &stmt.StmtList{
expected := &node.Root{
Stmts: []node.Node{
&stmt.Expression{
Expr: &expr.FunctionCall{
@ -152,7 +152,7 @@ func TestFunctionCallVar(t *testing.T) {
func TestFunctionCallExprArg(t *testing.T) {
src := `<? ceil($foo/3);`
expected := &stmt.StmtList{
expected := &node.Root{
Stmts: []node.Node{
&stmt.Expression{
Expr: &expr.FunctionCall{

View File

@ -15,7 +15,7 @@ import (
func TestPostDec(t *testing.T) {
src := `<? $a--;`
expected := &stmt.StmtList{
expected := &node.Root{
Stmts: []node.Node{
&stmt.Expression{
Expr: &expr.PostDec{
@ -39,7 +39,7 @@ func TestPostDec(t *testing.T) {
func TestPostInc(t *testing.T) {
src := `<? $a++;`
expected := &stmt.StmtList{
expected := &node.Root{
Stmts: []node.Node{
&stmt.Expression{
Expr: &expr.PostInc{
@ -63,7 +63,7 @@ func TestPostInc(t *testing.T) {
func TestPreDec(t *testing.T) {
src := `<? --$a;`
expected := &stmt.StmtList{
expected := &node.Root{
Stmts: []node.Node{
&stmt.Expression{
Expr: &expr.PreDec{
@ -87,7 +87,7 @@ func TestPreDec(t *testing.T) {
func TestPreInc(t *testing.T) {
src := `<? ++$a;`
expected := &stmt.StmtList{
expected := &node.Root{
Stmts: []node.Node{
&stmt.Expression{
Expr: &expr.PreInc{

View File

@ -15,7 +15,7 @@ import (
func TestInclude(t *testing.T) {
src := `<? include $a;`
expected := &stmt.StmtList{
expected := &node.Root{
Stmts: []node.Node{
&stmt.Expression{
Expr: &expr.Include{
@ -39,7 +39,7 @@ func TestInclude(t *testing.T) {
func TestIncludeOnce(t *testing.T) {
src := `<? include_once $a;`
expected := &stmt.StmtList{
expected := &node.Root{
Stmts: []node.Node{
&stmt.Expression{
Expr: &expr.IncludeOnce{
@ -63,7 +63,7 @@ func TestIncludeOnce(t *testing.T) {
func TestRequire(t *testing.T) {
src := `<? require $a;`
expected := &stmt.StmtList{
expected := &node.Root{
Stmts: []node.Node{
&stmt.Expression{
Expr: &expr.Require{
@ -87,7 +87,7 @@ func TestRequire(t *testing.T) {
func TestRequireOnce(t *testing.T) {
src := `<? require_once $a;`
expected := &stmt.StmtList{
expected := &node.Root{
Stmts: []node.Node{
&stmt.Expression{
Expr: &expr.RequireOnce{

View File

@ -17,7 +17,7 @@ import (
func TestInstanceOf(t *testing.T) {
src := `<? $a instanceof Foo;`
expected := &stmt.StmtList{
expected := &node.Root{
Stmts: []node.Node{
&stmt.Expression{
Expr: &expr.InstanceOf{
@ -46,7 +46,7 @@ func TestInstanceOf(t *testing.T) {
func TestInstanceOfRelative(t *testing.T) {
src := `<? $a instanceof namespace\Foo;`
expected := &stmt.StmtList{
expected := &node.Root{
Stmts: []node.Node{
&stmt.Expression{
Expr: &expr.InstanceOf{
@ -75,7 +75,7 @@ func TestInstanceOfRelative(t *testing.T) {
func TestInstanceOfFullyQualified(t *testing.T) {
src := `<? $a instanceof \Foo;`
expected := &stmt.StmtList{
expected := &node.Root{
Stmts: []node.Node{
&stmt.Expression{
Expr: &expr.InstanceOf{

View File

@ -15,7 +15,7 @@ import (
func TestIsset(t *testing.T) {
src := `<? isset($a);`
expected := &stmt.StmtList{
expected := &node.Root{
Stmts: []node.Node{
&stmt.Expression{
Expr: &expr.Isset{
@ -41,7 +41,7 @@ func TestIsset(t *testing.T) {
func TestIssetVariables(t *testing.T) {
src := `<? isset($a, $b);`
expected := &stmt.StmtList{
expected := &node.Root{
Stmts: []node.Node{
&stmt.Expression{
Expr: &expr.Isset{

View File

@ -17,7 +17,7 @@ import (
func TestEmptyList(t *testing.T) {
src := `<? list() = $b;`
expected := &stmt.StmtList{
expected := &node.Root{
Stmts: []node.Node{
&stmt.Expression{
Expr: &assign.Assign{
@ -44,7 +44,7 @@ func TestEmptyList(t *testing.T) {
func TestList(t *testing.T) {
src := `<? list($a) = $b;`
expected := &stmt.StmtList{
expected := &node.Root{
Stmts: []node.Node{
&stmt.Expression{
Expr: &assign.Assign{
@ -76,7 +76,7 @@ func TestList(t *testing.T) {
func TestListArrayIndex(t *testing.T) {
src := `<? list($a[]) = $b;`
expected := &stmt.StmtList{
expected := &node.Root{
Stmts: []node.Node{
&stmt.Expression{
Expr: &assign.Assign{
@ -110,7 +110,7 @@ func TestListArrayIndex(t *testing.T) {
func TestListList(t *testing.T) {
src := `<? list(list($a)) = $b;`
expected := &stmt.StmtList{
expected := &node.Root{
Stmts: []node.Node{
&stmt.Expression{
Expr: &assign.Assign{

View File

@ -15,7 +15,7 @@ import (
func TestMethodCall(t *testing.T) {
src := `<? $a->foo();`
expected := &stmt.StmtList{
expected := &node.Root{
Stmts: []node.Node{
&stmt.Expression{
Expr: &expr.MethodCall{

View File

@ -17,7 +17,7 @@ import (
func TestNew(t *testing.T) {
src := `<? new Foo;`
expected := &stmt.StmtList{
expected := &node.Root{
Stmts: []node.Node{
&stmt.Expression{
Expr: &expr.New{
@ -45,7 +45,7 @@ func TestNew(t *testing.T) {
func TestNewRelative(t *testing.T) {
src := `<? new namespace\Foo();`
expected := &stmt.StmtList{
expected := &node.Root{
Stmts: []node.Node{
&stmt.Expression{
Expr: &expr.New{
@ -74,7 +74,7 @@ func TestNewRelative(t *testing.T) {
func TestNewFullyQualified(t *testing.T) {
src := `<? new \Foo();`
expected := &stmt.StmtList{
expected := &node.Root{
Stmts: []node.Node{
&stmt.Expression{
Expr: &expr.New{
@ -103,7 +103,7 @@ func TestNewFullyQualified(t *testing.T) {
func TestNewAnonymous(t *testing.T) {
src := `<? new class ($a, ...$b) {};`
expected := &stmt.StmtList{
expected := &node.Root{
Stmts: []node.Node{
&stmt.Expression{
Expr: &expr.New{

View File

@ -15,7 +15,7 @@ import (
func TestPrint(t *testing.T) {
src := `<? print($a);`
expected := &stmt.StmtList{
expected := &node.Root{
Stmts: []node.Node{
&stmt.Expression{
Expr: &expr.Print{

View File

@ -15,7 +15,7 @@ import (
func TestPropertyFetch(t *testing.T) {
src := `<? $a->foo;`
expected := &stmt.StmtList{
expected := &node.Root{
Stmts: []node.Node{
&stmt.Expression{
Expr: &expr.PropertyFetch{

View File

@ -17,7 +17,7 @@ import (
func TestShellExec(t *testing.T) {
src := "<? `cmd $a`;"
expected := &stmt.StmtList{
expected := &node.Root{
Stmts: []node.Node{
&stmt.Expression{
Expr: &expr.ShellExec{

View File

@ -17,7 +17,7 @@ import (
func TestShortArray(t *testing.T) {
src := `<? [];`
expected := &stmt.StmtList{
expected := &node.Root{
Stmts: []node.Node{
&stmt.Expression{
Expr: &expr.ShortArray{
@ -41,7 +41,7 @@ func TestShortArray(t *testing.T) {
func TestShortArrayItem(t *testing.T) {
src := `<? [1];`
expected := &stmt.StmtList{
expected := &node.Root{
Stmts: []node.Node{
&stmt.Expression{
Expr: &expr.ShortArray{
@ -70,7 +70,7 @@ func TestShortArrayItem(t *testing.T) {
func TestShortArrayItems(t *testing.T) {
src := `<? [1=>1, &$b,];`
expected := &stmt.StmtList{
expected := &node.Root{
Stmts: []node.Node{
&stmt.Expression{
Expr: &expr.ShortArray{

View File

@ -16,7 +16,7 @@ import (
func TestShortList(t *testing.T) {
src := `<? [$a] = $b;`
expected := &stmt.StmtList{
expected := &node.Root{
Stmts: []node.Node{
&stmt.Expression{
Expr: &assign.Assign{
@ -43,7 +43,7 @@ func TestShortList(t *testing.T) {
func TestShortListArrayIndex(t *testing.T) {
src := `<? [$a[]] = $b;`
expected := &stmt.StmtList{
expected := &node.Root{
Stmts: []node.Node{
&stmt.Expression{
Expr: &assign.Assign{
@ -72,7 +72,7 @@ func TestShortListArrayIndex(t *testing.T) {
func TestShortListList(t *testing.T) {
src := `<? [list($a)] = $b;`
expected := &stmt.StmtList{
expected := &node.Root{
Stmts: []node.Node{
&stmt.Expression{
Expr: &assign.Assign{

View File

@ -17,7 +17,7 @@ import (
func TestStaticCall(t *testing.T) {
src := `<? Foo::bar();`
expected := &stmt.StmtList{
expected := &node.Root{
Stmts: []node.Node{
&stmt.Expression{
Expr: &expr.StaticCall{
@ -47,7 +47,7 @@ func TestStaticCall(t *testing.T) {
func TestStaticCallRelative(t *testing.T) {
src := `<? namespace\Foo::bar();`
expected := &stmt.StmtList{
expected := &node.Root{
Stmts: []node.Node{
&stmt.Expression{
Expr: &expr.StaticCall{
@ -77,7 +77,7 @@ func TestStaticCallRelative(t *testing.T) {
func TestStaticCallFullyQualified(t *testing.T) {
src := `<? \Foo::bar();`
expected := &stmt.StmtList{
expected := &node.Root{
Stmts: []node.Node{
&stmt.Expression{
Expr: &expr.StaticCall{
@ -107,7 +107,7 @@ func TestStaticCallFullyQualified(t *testing.T) {
func TestStaticCallVar(t *testing.T) {
src := `<? Foo::$bar();`
expected := &stmt.StmtList{
expected := &node.Root{
Stmts: []node.Node{
&stmt.Expression{
Expr: &expr.StaticCall{
@ -137,7 +137,7 @@ func TestStaticCallVar(t *testing.T) {
func TestStaticCallVarVar(t *testing.T) {
src := `<? $foo::$bar();`
expected := &stmt.StmtList{
expected := &node.Root{
Stmts: []node.Node{
&stmt.Expression{
Expr: &expr.StaticCall{

View File

@ -16,7 +16,7 @@ import (
func TestStaticPropertyFetch(t *testing.T) {
src := `<? Foo::$bar;`
expected := &stmt.StmtList{
expected := &node.Root{
Stmts: []node.Node{
&stmt.Expression{
Expr: &expr.StaticPropertyFetch{
@ -45,7 +45,7 @@ func TestStaticPropertyFetch(t *testing.T) {
func TestStaticPropertyFetchRelative(t *testing.T) {
src := `<? namespace\Foo::$bar;`
expected := &stmt.StmtList{
expected := &node.Root{
Stmts: []node.Node{
&stmt.Expression{
Expr: &expr.StaticPropertyFetch{
@ -74,7 +74,7 @@ func TestStaticPropertyFetchRelative(t *testing.T) {
func TestStaticPropertyFetchFullyQualified(t *testing.T) {
src := `<? \Foo::$bar;`
expected := &stmt.StmtList{
expected := &node.Root{
Stmts: []node.Node{
&stmt.Expression{
Expr: &expr.StaticPropertyFetch{

View File

@ -15,7 +15,7 @@ import (
func TestTernary(t *testing.T) {
src := `<? $a ? $b : $c;`
expected := &stmt.StmtList{
expected := &node.Root{
Stmts: []node.Node{
&stmt.Expression{
Expr: &expr.Ternary{
@ -41,7 +41,7 @@ func TestTernary(t *testing.T) {
func TestTernarySimple(t *testing.T) {
src := `<? $a ? : $c;`
expected := &stmt.StmtList{
expected := &node.Root{
Stmts: []node.Node{
&stmt.Expression{
Expr: &expr.Ternary{
@ -66,7 +66,7 @@ func TestTernarySimple(t *testing.T) {
func TestTernaryNestedTrue(t *testing.T) {
src := `<? $a ? $b ? $c : $d : $e;`
expected := &stmt.StmtList{
expected := &node.Root{
Stmts: []node.Node{
&stmt.Expression{
Expr: &expr.Ternary{
@ -96,7 +96,7 @@ func TestTernaryNestedTrue(t *testing.T) {
func TestTernaryNestedCond(t *testing.T) {
src := `<? $a ? $b : $c ? $d : $e;`
expected := &stmt.StmtList{
expected := &node.Root{
Stmts: []node.Node{
&stmt.Expression{
Expr: &expr.Ternary{

View File

@ -15,7 +15,7 @@ import (
func TestUnaryMinus(t *testing.T) {
src := `<? -$a;`
expected := &stmt.StmtList{
expected := &node.Root{
Stmts: []node.Node{
&stmt.Expression{
Expr: &expr.UnaryMinus{
@ -39,7 +39,7 @@ func TestUnaryMinus(t *testing.T) {
func TestUnaryPlus(t *testing.T) {
src := `<? +$a;`
expected := &stmt.StmtList{
expected := &node.Root{
Stmts: []node.Node{
&stmt.Expression{
Expr: &expr.UnaryPlus{

View File

@ -15,7 +15,7 @@ import (
func TestVariable(t *testing.T) {
src := `<? $a;`
expected := &stmt.StmtList{
expected := &node.Root{
Stmts: []node.Node{
&stmt.Expression{
Expr: &expr.Variable{VarName: &node.Identifier{Value: "a"}},
@ -37,7 +37,7 @@ func TestVariable(t *testing.T) {
func TestVariableVariable(t *testing.T) {
src := `<? $$a;`
expected := &stmt.StmtList{
expected := &node.Root{
Stmts: []node.Node{
&stmt.Expression{
Expr: &expr.Variable{VarName: &expr.Variable{VarName: &node.Identifier{Value: "a"}}},

View File

@ -16,7 +16,7 @@ import (
func TestYield(t *testing.T) {
src := `<? yield;`
expected := &stmt.StmtList{
expected := &node.Root{
Stmts: []node.Node{
&stmt.Expression{
Expr: &expr.Yield{},
@ -38,7 +38,7 @@ func TestYield(t *testing.T) {
func TestYieldVal(t *testing.T) {
src := `<? yield $a;`
expected := &stmt.StmtList{
expected := &node.Root{
Stmts: []node.Node{
&stmt.Expression{
Expr: &expr.Yield{
@ -62,7 +62,7 @@ func TestYieldVal(t *testing.T) {
func TestYieldKeyVal(t *testing.T) {
src := `<? yield $a => $b;`
expected := &stmt.StmtList{
expected := &node.Root{
Stmts: []node.Node{
&stmt.Expression{
Expr: &expr.Yield{
@ -87,7 +87,7 @@ func TestYieldKeyVal(t *testing.T) {
func TestYieldExpr(t *testing.T) {
src := `<? yield 1;`
expected := &stmt.StmtList{
expected := &node.Root{
Stmts: []node.Node{
&stmt.Expression{
Expr: &expr.Yield{
@ -111,7 +111,7 @@ func TestYieldExpr(t *testing.T) {
func TestYieldKeyExpr(t *testing.T) {
src := `<? yield $a => 1;`
expected := &stmt.StmtList{
expected := &node.Root{
Stmts: []node.Node{
&stmt.Expression{
Expr: &expr.Yield{
@ -136,7 +136,7 @@ func TestYieldKeyExpr(t *testing.T) {
func TestYieldFrom(t *testing.T) {
src := `<? yield from $a;`
expected := &stmt.StmtList{
expected := &node.Root{
Stmts: []node.Node{
&stmt.Expression{
Expr: &expr.YieldFrom{

41
node/n_root.go Normal file
View File

@ -0,0 +1,41 @@
package node
import (
"github.com/z7zmey/php-parser/walker"
)
// Root node
type Root struct {
Stmts []Node
}
// NewRoot node constructor
func NewRoot(Stmts []Node) *Root {
return &Root{
Stmts,
}
}
// Attributes returns node attributes as map
func (n *Root) Attributes() map[string]interface{} {
return nil
}
// Walk traverses nodes
// Walk is invoked recursively until v.EnterNode returns true
func (n *Root) Walk(v walker.Visitor) {
if v.EnterNode(n) == false {
return
}
if n.Stmts != nil {
vv := v.GetChildrenVisitor("Stmts")
for _, nn := range n.Stmts {
if nn != nil {
nn.Walk(vv)
}
}
}
v.LeaveNode(n)
}

View File

@ -31,7 +31,7 @@ func assertEqual(t *testing.T, expected interface{}, actual interface{}) {
func TestName(t *testing.T) {
src := `<? foo();`
expected := &stmt.StmtList{
expected := &node.Root{
Stmts: []node.Node{
&stmt.Expression{
Expr: &expr.FunctionCall{
@ -58,7 +58,7 @@ func TestName(t *testing.T) {
func TestFullyQualified(t *testing.T) {
src := `<? \foo();`
expected := &stmt.StmtList{
expected := &node.Root{
Stmts: []node.Node{
&stmt.Expression{
Expr: &expr.FunctionCall{
@ -85,7 +85,7 @@ func TestFullyQualified(t *testing.T) {
func TestRelative(t *testing.T) {
src := `<? namespace\foo();`
expected := &stmt.StmtList{
expected := &node.Root{
Stmts: []node.Node{
&stmt.Expression{
Expr: &expr.FunctionCall{

View File

@ -16,7 +16,7 @@ import (
func TestSimpleVar(t *testing.T) {
src := `<? "test $var";`
expected := &stmt.StmtList{
expected := &node.Root{
Stmts: []node.Node{
&stmt.Expression{
Expr: &scalar.Encapsed{
@ -43,7 +43,7 @@ func TestSimpleVar(t *testing.T) {
func TestSimpleVarOneChar(t *testing.T) {
src := `<? "test $a";`
expected := &stmt.StmtList{
expected := &node.Root{
Stmts: []node.Node{
&stmt.Expression{
Expr: &scalar.Encapsed{
@ -70,7 +70,7 @@ func TestSimpleVarOneChar(t *testing.T) {
func TestSimpleVarEndsEcapsed(t *testing.T) {
src := `<? "test $var\"";`
expected := &stmt.StmtList{
expected := &node.Root{
Stmts: []node.Node{
&stmt.Expression{
Expr: &scalar.Encapsed{
@ -98,7 +98,7 @@ func TestSimpleVarEndsEcapsed(t *testing.T) {
func TestStringVarCurveOpen(t *testing.T) {
src := `<? "=$a{$b}";`
expected := &stmt.StmtList{
expected := &node.Root{
Stmts: []node.Node{
&stmt.Expression{
Expr: &scalar.Encapsed{
@ -126,7 +126,7 @@ func TestStringVarCurveOpen(t *testing.T) {
func TestSimpleVarPropertyFetch(t *testing.T) {
src := `<? "test $foo->bar()";`
expected := &stmt.StmtList{
expected := &node.Root{
Stmts: []node.Node{
&stmt.Expression{
Expr: &scalar.Encapsed{
@ -157,7 +157,7 @@ func TestSimpleVarPropertyFetch(t *testing.T) {
func TestDollarOpenCurlyBraces(t *testing.T) {
src := `<? "test ${foo}";`
expected := &stmt.StmtList{
expected := &node.Root{
Stmts: []node.Node{
&stmt.Expression{
Expr: &scalar.Encapsed{
@ -184,7 +184,7 @@ func TestDollarOpenCurlyBraces(t *testing.T) {
func TestDollarOpenCurlyBracesDimNumber(t *testing.T) {
src := `<? "test ${foo[0]}";`
expected := &stmt.StmtList{
expected := &node.Root{
Stmts: []node.Node{
&stmt.Expression{
Expr: &scalar.Encapsed{
@ -214,7 +214,7 @@ func TestDollarOpenCurlyBracesDimNumber(t *testing.T) {
func TestCurlyOpenMethodCall(t *testing.T) {
src := `<? "test {$foo->bar()}";`
expected := &stmt.StmtList{
expected := &node.Root{
Stmts: []node.Node{
&stmt.Expression{
Expr: &scalar.Encapsed{

View File

@ -19,7 +19,7 @@ test $var
LBL;
`
expected := &stmt.StmtList{
expected := &node.Root{
Stmts: []node.Node{
&stmt.Expression{
Expr: &scalar.Heredoc{
@ -51,7 +51,7 @@ test $var
LBL;
`
expected := &stmt.StmtList{
expected := &node.Root{
Stmts: []node.Node{
&stmt.Expression{
Expr: &scalar.Heredoc{
@ -83,7 +83,7 @@ test $var
LBL;
`
expected := &stmt.StmtList{
expected := &node.Root{
Stmts: []node.Node{
&stmt.Expression{
Expr: &scalar.Heredoc{
@ -112,7 +112,7 @@ func TestEmptyHeredoc(t *testing.T) {
CAD;
`
expected := &stmt.StmtList{
expected := &node.Root{
Stmts: []node.Node{
&stmt.Expression{
Expr: &scalar.Heredoc{
@ -139,7 +139,7 @@ func TestHeredocScalarString(t *testing.T) {
CAD;
`
expected := &stmt.StmtList{
expected := &node.Root{
Stmts: []node.Node{
&stmt.Expression{
Expr: &scalar.Heredoc{

View File

@ -15,7 +15,7 @@ func TestMagicConstant(t *testing.T) {
// TODO: test all magic constants
src := `<? __DIR__;`
expected := &stmt.StmtList{
expected := &node.Root{
Stmts: []node.Node{
&stmt.Expression{
Expr: &scalar.MagicConstant{Value: "__DIR__"},

View File

@ -29,7 +29,7 @@ func assertEqual(t *testing.T, expected interface{}, actual interface{}) {
func TestLNumber(t *testing.T) {
src := `<? 1234567890123456789;`
expected := &stmt.StmtList{
expected := &node.Root{
Stmts: []node.Node{
&stmt.Expression{
Expr: &scalar.Lnumber{Value: "1234567890123456789"},
@ -51,7 +51,7 @@ func TestLNumber(t *testing.T) {
func TestDNumber(t *testing.T) {
src := `<? 12345678901234567890;`
expected := &stmt.StmtList{
expected := &node.Root{
Stmts: []node.Node{
&stmt.Expression{
Expr: &scalar.Dnumber{Value: "12345678901234567890"},
@ -73,7 +73,7 @@ func TestDNumber(t *testing.T) {
func TestFloat(t *testing.T) {
src := `<? 0.;`
expected := &stmt.StmtList{
expected := &node.Root{
Stmts: []node.Node{
&stmt.Expression{
Expr: &scalar.Dnumber{Value: "0."},
@ -95,7 +95,7 @@ func TestFloat(t *testing.T) {
func TestBinaryLNumber(t *testing.T) {
src := `<? 0b0111111111111111111111111111111111111111111111111111111111111111;`
expected := &stmt.StmtList{
expected := &node.Root{
Stmts: []node.Node{
&stmt.Expression{
Expr: &scalar.Lnumber{Value: "0b0111111111111111111111111111111111111111111111111111111111111111"},
@ -117,7 +117,7 @@ func TestBinaryLNumber(t *testing.T) {
func TestBinaryDNumber(t *testing.T) {
src := `<? 0b1111111111111111111111111111111111111111111111111111111111111111;`
expected := &stmt.StmtList{
expected := &node.Root{
Stmts: []node.Node{
&stmt.Expression{
Expr: &scalar.Dnumber{Value: "0b1111111111111111111111111111111111111111111111111111111111111111"},
@ -139,7 +139,7 @@ func TestBinaryDNumber(t *testing.T) {
func TestHLNumber(t *testing.T) {
src := `<? 0x007111111111111111;`
expected := &stmt.StmtList{
expected := &node.Root{
Stmts: []node.Node{
&stmt.Expression{
Expr: &scalar.Lnumber{Value: "0x007111111111111111"},
@ -161,7 +161,7 @@ func TestHLNumber(t *testing.T) {
func TestHDNumber(t *testing.T) {
src := `<? 0x8111111111111111;`
expected := &stmt.StmtList{
expected := &node.Root{
Stmts: []node.Node{
&stmt.Expression{
Expr: &scalar.Dnumber{Value: "0x8111111111111111"},

View File

@ -14,7 +14,7 @@ import (
func TestDoubleQuotedScalarString(t *testing.T) {
src := `<? "test";`
expected := &stmt.StmtList{
expected := &node.Root{
Stmts: []node.Node{
&stmt.Expression{
Expr: &scalar.String{Value: "\"test\""},
@ -35,7 +35,7 @@ func TestDoubleQuotedScalarString(t *testing.T) {
func TestDoubleQuotedScalarStringWithEscapedVar(t *testing.T) {
src := `<? "\$test";`
expected := &stmt.StmtList{
expected := &node.Root{
Stmts: []node.Node{
&stmt.Expression{
Expr: &scalar.String{Value: "\"\\$test\""},
@ -59,7 +59,7 @@ func TestMultilineDoubleQuotedScalarString(t *testing.T) {
test
";`
expected := &stmt.StmtList{
expected := &node.Root{
Stmts: []node.Node{
&stmt.Expression{
Expr: &scalar.String{Value: "\"\n\ttest\n\t\""},
@ -81,7 +81,7 @@ func TestMultilineDoubleQuotedScalarString(t *testing.T) {
func TestSingleQuotedScalarString(t *testing.T) {
src := `<? '$test';`
expected := &stmt.StmtList{
expected := &node.Root{
Stmts: []node.Node{
&stmt.Expression{
Expr: &scalar.String{Value: "'$test'"},
@ -105,7 +105,7 @@ func TestMultilineSingleQuotedScalarString(t *testing.T) {
$test
';`
expected := &stmt.StmtList{
expected := &node.Root{
Stmts: []node.Node{
&stmt.Expression{
Expr: &scalar.String{Value: "'\n\t$test\n\t'"},

View File

@ -33,7 +33,7 @@ func TestAltIf(t *testing.T) {
endif;
`
expected := &stmt.StmtList{
expected := &node.Root{
Stmts: []node.Node{
&stmt.AltIf{
Cond: &expr.Variable{VarName: &node.Identifier{Value: "a"}},
@ -60,7 +60,7 @@ func TestAltElseIf(t *testing.T) {
endif;
`
expected := &stmt.StmtList{
expected := &node.Root{
Stmts: []node.Node{
&stmt.AltIf{
Cond: &expr.Variable{VarName: &node.Identifier{Value: "a"}},
@ -93,7 +93,7 @@ func TestAltElse(t *testing.T) {
endif;
`
expected := &stmt.StmtList{
expected := &node.Root{
Stmts: []node.Node{
&stmt.AltIf{
Cond: &expr.Variable{VarName: &node.Identifier{Value: "a"}},
@ -125,7 +125,7 @@ func TestAltElseElseIf(t *testing.T) {
endif;
`
expected := &stmt.StmtList{
expected := &node.Root{
Stmts: []node.Node{
&stmt.AltIf{
Cond: &expr.Variable{VarName: &node.Identifier{Value: "a"}},

View File

@ -15,7 +15,7 @@ import (
func TestClassConstList(t *testing.T) {
src := `<? class foo{ public const FOO = 1, BAR = 2; }`
expected := &stmt.StmtList{
expected := &node.Root{
Stmts: []node.Node{
&stmt.Class{
ClassName: &node.Identifier{Value: "foo"},
@ -51,7 +51,7 @@ func TestClassConstList(t *testing.T) {
func TestClassConstListWithoutModifiers(t *testing.T) {
src := `<? class foo{ const FOO = 1, BAR = 2; }`
expected := &stmt.StmtList{
expected := &node.Root{
Stmts: []node.Node{
&stmt.Class{
ClassName: &node.Identifier{Value: "foo"},

View File

@ -14,7 +14,7 @@ import (
func TestSimpleClassMethod(t *testing.T) {
src := `<? class foo{ function bar() {} }`
expected := &stmt.StmtList{
expected := &node.Root{
Stmts: []node.Node{
&stmt.Class{
ClassName: &node.Identifier{Value: "foo"},
@ -43,7 +43,7 @@ func TestSimpleClassMethod(t *testing.T) {
func TestPrivateProtectedClassMethod(t *testing.T) {
src := `<? class foo{ final private function bar() {} protected function baz() {} }`
expected := &stmt.StmtList{
expected := &node.Root{
Stmts: []node.Node{
&stmt.Class{
ClassName: &node.Identifier{Value: "foo"},
@ -86,7 +86,7 @@ func TestPrivateProtectedClassMethod(t *testing.T) {
func TestPhp5ClassMethod(t *testing.T) {
src := `<? class foo{ public static function &bar() {} }`
expected := &stmt.StmtList{
expected := &node.Root{
Stmts: []node.Node{
&stmt.Class{
ClassName: &node.Identifier{Value: "foo"},
@ -115,7 +115,7 @@ func TestPhp5ClassMethod(t *testing.T) {
func TestPhp7ClassMethod(t *testing.T) {
src := `<? class foo{ public static function &bar(): void {} }`
expected := &stmt.StmtList{
expected := &node.Root{
Stmts: []node.Node{
&stmt.Class{
ClassName: &node.Identifier{Value: "foo"},
@ -149,7 +149,7 @@ func TestPhp7ClassMethod(t *testing.T) {
func TestAbstractClassMethod(t *testing.T) {
src := `<? abstract class Foo{ abstract public function bar(); }`
expected := &stmt.StmtList{
expected := &node.Root{
Stmts: []node.Node{
&stmt.Class{
Modifiers: []node.Node{&node.Identifier{Value: "abstract"}},
@ -183,7 +183,7 @@ func TestAbstractClassMethod(t *testing.T) {
func TestPhp7AbstractClassMethod(t *testing.T) {
src := `<? abstract class Foo{ public function bar(): void; }`
expected := &stmt.StmtList{
expected := &node.Root{
Stmts: []node.Node{
&stmt.Class{
Modifiers: []node.Node{&node.Identifier{Value: "abstract"}},

View File

@ -16,7 +16,7 @@ import (
func TestSimpleClass(t *testing.T) {
src := `<? class foo{ }`
expected := &stmt.StmtList{
expected := &node.Root{
Stmts: []node.Node{
&stmt.Class{
ClassName: &node.Identifier{Value: "foo"},
@ -39,7 +39,7 @@ func TestSimpleClass(t *testing.T) {
func TestAbstractClass(t *testing.T) {
src := `<? abstract class foo{ }`
expected := &stmt.StmtList{
expected := &node.Root{
Stmts: []node.Node{
&stmt.Class{
ClassName: &node.Identifier{Value: "foo"},
@ -65,7 +65,7 @@ func TestAbstractClass(t *testing.T) {
func TestClassExtends(t *testing.T) {
src := `<? final class foo extends bar { }`
expected := &stmt.StmtList{
expected := &node.Root{
Stmts: []node.Node{
&stmt.Class{
ClassName: &node.Identifier{Value: "foo"},
@ -96,7 +96,7 @@ func TestClassExtends(t *testing.T) {
func TestClassImplement(t *testing.T) {
src := `<? final class foo implements bar { }`
expected := &stmt.StmtList{
expected := &node.Root{
Stmts: []node.Node{
&stmt.Class{
ClassName: &node.Identifier{Value: "foo"},
@ -129,7 +129,7 @@ func TestClassImplement(t *testing.T) {
func TestClassImplements(t *testing.T) {
src := `<? final class foo implements bar, baz { }`
expected := &stmt.StmtList{
expected := &node.Root{
Stmts: []node.Node{
&stmt.Class{
ClassName: &node.Identifier{Value: "foo"},
@ -167,7 +167,7 @@ func TestClassImplements(t *testing.T) {
func TestAnonimousClass(t *testing.T) {
src := `<? new class() extends foo implements bar, baz { };`
expected := &stmt.StmtList{
expected := &node.Root{
Stmts: []node.Node{
&stmt.Expression{
Expr: &expr.New{

View File

@ -15,7 +15,7 @@ import (
func TestConstList(t *testing.T) {
src := `<? const FOO = 1, BAR = 2;`
expected := &stmt.StmtList{
expected := &node.Root{
Stmts: []node.Node{
&stmt.ConstList{
Consts: []node.Node{

View File

@ -15,7 +15,7 @@ import (
func TestContinueEmpty(t *testing.T) {
src := `<? while (1) { continue; }`
expected := &stmt.StmtList{
expected := &node.Root{
Stmts: []node.Node{
&stmt.While{
Cond: &scalar.Lnumber{Value: "1"},
@ -42,7 +42,7 @@ func TestContinueEmpty(t *testing.T) {
func TestContinueLight(t *testing.T) {
src := `<? while (1) { continue 2; }`
expected := &stmt.StmtList{
expected := &node.Root{
Stmts: []node.Node{
&stmt.While{
Cond: &scalar.Lnumber{Value: "1"},
@ -71,7 +71,7 @@ func TestContinueLight(t *testing.T) {
func TestContinue(t *testing.T) {
src := `<? while (1) { continue(3); }`
expected := &stmt.StmtList{
expected := &node.Root{
Stmts: []node.Node{
&stmt.While{
Cond: &scalar.Lnumber{Value: "1"},

View File

@ -15,7 +15,7 @@ import (
func TestDeclare(t *testing.T) {
src := `<? declare(ticks=1);`
expected := &stmt.StmtList{
expected := &node.Root{
Stmts: []node.Node{
&stmt.Declare{
Consts: []node.Node{
@ -44,7 +44,7 @@ func TestDeclare(t *testing.T) {
func TestDeclareStmts(t *testing.T) {
src := `<? declare(ticks=1, strict_types=1) {}`
expected := &stmt.StmtList{
expected := &node.Root{
Stmts: []node.Node{
&stmt.Declare{
Consts: []node.Node{
@ -80,7 +80,7 @@ func TestDeclareStmts(t *testing.T) {
func TestAltDeclare(t *testing.T) {
src := `<? declare(ticks=1): enddeclare;`
expected := &stmt.StmtList{
expected := &node.Root{
Stmts: []node.Node{
&stmt.Declare{
Consts: []node.Node{

View File

@ -15,7 +15,7 @@ import (
func TestDo(t *testing.T) {
src := `<? do {} while(1);`
expected := &stmt.StmtList{
expected := &node.Root{
Stmts: []node.Node{
&stmt.Do{
Stmt: &stmt.StmtList{

View File

@ -17,7 +17,7 @@ import (
func TestSimpleEcho(t *testing.T) {
src := `<? echo $a, 1;`
expected := &stmt.StmtList{
expected := &node.Root{
Stmts: []node.Node{
&stmt.Echo{
Exprs: []node.Node{
@ -44,7 +44,7 @@ func TestSimpleEcho(t *testing.T) {
func TestEcho(t *testing.T) {
src := `<? echo($a);`
expected := &stmt.StmtList{
expected := &node.Root{
Stmts: []node.Node{
&stmt.Echo{
Exprs: []node.Node{

View File

@ -15,7 +15,7 @@ import (
func TestExpression(t *testing.T) {
src := `<? 1;`
expected := &stmt.StmtList{
expected := &node.Root{
Stmts: []node.Node{
&stmt.Expression{
Expr: &scalar.Lnumber{Value: "1"},

View File

@ -20,7 +20,7 @@ import (
func TestFor(t *testing.T) {
src := `<? for($i = 0; $i < 10; $i++, $i++) {}`
expected := &stmt.StmtList{
expected := &node.Root{
Stmts: []node.Node{
&stmt.For{
Init: []node.Node{
@ -62,7 +62,7 @@ func TestFor(t *testing.T) {
func TestAltFor(t *testing.T) {
src := `<? for(; $i < 10; $i++) : endfor;`
expected := &stmt.StmtList{
expected := &node.Root{
Stmts: []node.Node{
&stmt.AltFor{
Cond: []node.Node{

View File

@ -15,7 +15,7 @@ import (
func TestForeach(t *testing.T) {
src := `<? foreach ($a as $v) {}`
expected := &stmt.StmtList{
expected := &node.Root{
Stmts: []node.Node{
&stmt.Foreach{
Expr: &expr.Variable{VarName: &node.Identifier{Value: "a"}},
@ -39,7 +39,7 @@ func TestForeach(t *testing.T) {
func TestForeachExpr(t *testing.T) {
src := `<? foreach ([] as $v) {}`
expected := &stmt.StmtList{
expected := &node.Root{
Stmts: []node.Node{
&stmt.Foreach{
Expr: &expr.ShortArray{Items: []node.Node{}},
@ -63,7 +63,7 @@ func TestForeachExpr(t *testing.T) {
func TestAltForeach(t *testing.T) {
src := `<? foreach ($a as $v) : endforeach;`
expected := &stmt.StmtList{
expected := &node.Root{
Stmts: []node.Node{
&stmt.AltForeach{
Expr: &expr.Variable{VarName: &node.Identifier{Value: "a"}},
@ -87,7 +87,7 @@ func TestAltForeach(t *testing.T) {
func TestForeachWithKey(t *testing.T) {
src := `<? foreach ($a as $k => $v) {}`
expected := &stmt.StmtList{
expected := &node.Root{
Stmts: []node.Node{
&stmt.Foreach{
Expr: &expr.Variable{VarName: &node.Identifier{Value: "a"}},
@ -112,7 +112,7 @@ func TestForeachWithKey(t *testing.T) {
func TestForeachExprWithKey(t *testing.T) {
src := `<? foreach ([] as $k => $v) {}`
expected := &stmt.StmtList{
expected := &node.Root{
Stmts: []node.Node{
&stmt.Foreach{
Expr: &expr.ShortArray{Items: []node.Node{}},
@ -137,7 +137,7 @@ func TestForeachExprWithKey(t *testing.T) {
func TestForeachWithRef(t *testing.T) {
src := `<? foreach ($a as $k => &$v) {}`
expected := &stmt.StmtList{
expected := &node.Root{
Stmts: []node.Node{
&stmt.Foreach{
ByRef: true,
@ -163,7 +163,7 @@ func TestForeachWithRef(t *testing.T) {
func TestForeachWithList(t *testing.T) {
src := `<? foreach ($a as $k => list($v)) {}`
expected := &stmt.StmtList{
expected := &node.Root{
Stmts: []node.Node{
&stmt.Foreach{
ByRef: false,

View File

@ -17,7 +17,7 @@ import (
func TestSimpleFunction(t *testing.T) {
src := `<? function foo() {}`
expected := &stmt.StmtList{
expected := &node.Root{
Stmts: []node.Node{
&stmt.Function{
ReturnsRef: false,
@ -42,7 +42,7 @@ func TestSimpleFunction(t *testing.T) {
func TestFunctionReturn(t *testing.T) {
src := `<? function foo() {return;}`
expected := &stmt.StmtList{
expected := &node.Root{
Stmts: []node.Node{
&stmt.Function{
ReturnsRef: false,
@ -69,7 +69,7 @@ func TestFunctionReturn(t *testing.T) {
func TestFunctionReturnVar(t *testing.T) {
src := `<? function foo(array $a, callable $b) {return $a;}`
expected := &stmt.StmtList{
expected := &node.Root{
Stmts: []node.Node{
&stmt.Function{
ReturnsRef: false,
@ -112,7 +112,7 @@ func TestFunctionReturnVar(t *testing.T) {
func TestRefFunction(t *testing.T) {
src := `<? function &foo() {return 1;}`
expected := &stmt.StmtList{
expected := &node.Root{
Stmts: []node.Node{
&stmt.Function{
ReturnsRef: true,
@ -141,7 +141,7 @@ func TestRefFunction(t *testing.T) {
func TestReturnTypeFunction(t *testing.T) {
src := `<? function &foo(): void {}`
expected := &stmt.StmtList{
expected := &node.Root{
Stmts: []node.Node{
&stmt.Function{
ReturnsRef: true,

View File

@ -15,7 +15,7 @@ import (
func TestGlobal(t *testing.T) {
src := `<? global $a;`
expected := &stmt.StmtList{
expected := &node.Root{
Stmts: []node.Node{
&stmt.Global{
Vars: []node.Node{
@ -39,7 +39,7 @@ func TestGlobal(t *testing.T) {
func TestGlobalVars(t *testing.T) {
src := `<? global $a, $b, $$c, ${foo()};`
expected := &stmt.StmtList{
expected := &node.Root{
Stmts: []node.Node{
&stmt.Global{
Vars: []node.Node{

View File

@ -13,7 +13,7 @@ import (
func TestGotoLabel(t *testing.T) {
src := `<? a: goto a;`
expected := &stmt.StmtList{
expected := &node.Root{
Stmts: []node.Node{
&stmt.Label{
LabelName: &node.Identifier{Value: "a"},

View File

@ -13,7 +13,7 @@ import (
func TestHaltCompiler(t *testing.T) {
src := `<? __halt_compiler();`
expected := &stmt.StmtList{
expected := &node.Root{
Stmts: []node.Node{
&stmt.HaltCompiler{},
},

View File

@ -15,7 +15,7 @@ import (
func TestIf(t *testing.T) {
src := `<? if ($a) {}`
expected := &stmt.StmtList{
expected := &node.Root{
Stmts: []node.Node{
&stmt.If{
Cond: &expr.Variable{VarName: &node.Identifier{Value: "a"}},
@ -39,7 +39,7 @@ func TestElseIf(t *testing.T) {
src := `<? if ($a) {} elseif ($b) {}
`
expected := &stmt.StmtList{
expected := &node.Root{
Stmts: []node.Node{
&stmt.If{
Cond: &expr.Variable{VarName: &node.Identifier{Value: "a"}},
@ -68,7 +68,7 @@ func TestElseIf(t *testing.T) {
func TestElse(t *testing.T) {
src := `<? if ($a) {} else {}`
expected := &stmt.StmtList{
expected := &node.Root{
Stmts: []node.Node{
&stmt.If{
Cond: &expr.Variable{VarName: &node.Identifier{Value: "a"}},
@ -94,7 +94,7 @@ func TestElse(t *testing.T) {
func TestElseElseIf(t *testing.T) {
src := `<? if ($a) {} elseif ($b) {} elseif ($c) {} else {}`
expected := &stmt.StmtList{
expected := &node.Root{
Stmts: []node.Node{
&stmt.If{
Cond: &expr.Variable{VarName: &node.Identifier{Value: "a"}},
@ -130,7 +130,7 @@ func TestElseElseIf(t *testing.T) {
func TestElseIfElseIfElse(t *testing.T) {
src := `<? if ($a) {} elseif ($b) {} else if ($c) {} else {}`
expected := &stmt.StmtList{
expected := &node.Root{
Stmts: []node.Node{
&stmt.If{
Cond: &expr.Variable{VarName: &node.Identifier{Value: "a"}},

View File

@ -13,7 +13,7 @@ import (
func TestInlineHtml(t *testing.T) {
src := `<? ?> <div></div>`
expected := &stmt.StmtList{
expected := &node.Root{
Stmts: []node.Node{
&stmt.Nop{},
&stmt.InlineHtml{Value: "<div></div>"},

View File

@ -14,7 +14,7 @@ import (
func TestInterface(t *testing.T) {
src := `<? interface Foo {}`
expected := &stmt.StmtList{
expected := &node.Root{
Stmts: []node.Node{
&stmt.Interface{
PhpDocComment: "",
@ -38,7 +38,7 @@ func TestInterface(t *testing.T) {
func TestInterfaceExtend(t *testing.T) {
src := `<? interface Foo extends Bar {}`
expected := &stmt.StmtList{
expected := &node.Root{
Stmts: []node.Node{
&stmt.Interface{
PhpDocComment: "",
@ -69,7 +69,7 @@ func TestInterfaceExtend(t *testing.T) {
func TestInterfaceExtends(t *testing.T) {
src := `<? interface Foo extends Bar, Baz {}`
expected := &stmt.StmtList{
expected := &node.Root{
Stmts: []node.Node{
&stmt.Interface{
PhpDocComment: "",

View File

@ -14,7 +14,7 @@ import (
func TestNamespace(t *testing.T) {
src := `<? namespace Foo;`
expected := &stmt.StmtList{
expected := &node.Root{
Stmts: []node.Node{
&stmt.Namespace{
NamespaceName: &name.Name{
@ -40,7 +40,7 @@ func TestNamespace(t *testing.T) {
func TestNamespaceStmts(t *testing.T) {
src := `<? namespace Foo {}`
expected := &stmt.StmtList{
expected := &node.Root{
Stmts: []node.Node{
&stmt.Namespace{
NamespaceName: &name.Name{
@ -67,7 +67,7 @@ func TestNamespaceStmts(t *testing.T) {
func TestAnonymousNamespace(t *testing.T) {
src := `<? namespace {}`
expected := &stmt.StmtList{
expected := &node.Root{
Stmts: []node.Node{
&stmt.Namespace{
Stmts: []node.Node{},

View File

@ -15,7 +15,7 @@ import (
func TestProperty(t *testing.T) {
src := `<? class foo {var $a;}`
expected := &stmt.StmtList{
expected := &node.Root{
Stmts: []node.Node{
&stmt.Class{
ClassName: &node.Identifier{Value: "foo"},
@ -50,7 +50,7 @@ func TestProperty(t *testing.T) {
func TestProperties(t *testing.T) {
src := `<? class foo {public static $a, $b = 1;}`
expected := &stmt.StmtList{
expected := &node.Root{
Stmts: []node.Node{
&stmt.Class{
ClassName: &node.Identifier{Value: "foo"},
@ -91,7 +91,7 @@ func TestProperties(t *testing.T) {
func TestProperties2(t *testing.T) {
src := `<? class foo {public static $a = 1, $b;}`
expected := &stmt.StmtList{
expected := &node.Root{
Stmts: []node.Node{
&stmt.Class{
ClassName: &node.Identifier{Value: "foo"},

View File

@ -15,7 +15,7 @@ import (
func TestStaticVar(t *testing.T) {
src := `<? static $a;`
expected := &stmt.StmtList{
expected := &node.Root{
Stmts: []node.Node{
&stmt.Static{
Vars: []node.Node{
@ -41,7 +41,7 @@ func TestStaticVar(t *testing.T) {
func TestStaticVars(t *testing.T) {
src := `<? static $a, $b = 1;`
expected := &stmt.StmtList{
expected := &node.Root{
Stmts: []node.Node{
&stmt.Static{
Vars: []node.Node{
@ -71,7 +71,7 @@ func TestStaticVars(t *testing.T) {
func TestStaticVars2(t *testing.T) {
src := `<? static $a = 1, $b;`
expected := &stmt.StmtList{
expected := &node.Root{
Stmts: []node.Node{
&stmt.Static{
Vars: []node.Node{

View File

@ -21,7 +21,7 @@ func TestAltSwitch(t *testing.T) {
endswitch;
`
expected := &stmt.StmtList{
expected := &node.Root{
Stmts: []node.Node{
&stmt.AltSwitch{
Cond: &scalar.Lnumber{Value: "1"},
@ -63,7 +63,7 @@ func TestAltSwitchSemicolon(t *testing.T) {
endswitch;
`
expected := &stmt.StmtList{
expected := &node.Root{
Stmts: []node.Node{
&stmt.AltSwitch{
Cond: &scalar.Lnumber{Value: "1"},
@ -102,7 +102,7 @@ func TestSwitch(t *testing.T) {
}
`
expected := &stmt.StmtList{
expected := &node.Root{
Stmts: []node.Node{
&stmt.Switch{
Cond: &scalar.Lnumber{Value: "1"},
@ -145,7 +145,7 @@ func TestSwitchSemicolon(t *testing.T) {
}
`
expected := &stmt.StmtList{
expected := &node.Root{
Stmts: []node.Node{
&stmt.Switch{
Cond: &scalar.Lnumber{Value: "1"},

View File

@ -14,7 +14,7 @@ import (
func TestThrow(t *testing.T) {
src := `<? throw $e;`
expected := &stmt.StmtList{
expected := &node.Root{
Stmts: []node.Node{
&stmt.Throw{
Expr: &expr.Variable{VarName: &node.Identifier{Value: "e"}},

View File

@ -13,7 +13,7 @@ import (
func TestTrait(t *testing.T) {
src := `<? trait Foo {}`
expected := &stmt.StmtList{
expected := &node.Root{
Stmts: []node.Node{
&stmt.Trait{
PhpDocComment: "",

View File

@ -15,7 +15,7 @@ import (
func TestTraitUse(t *testing.T) {
src := `<? class Foo { use Bar; }`
expected := &stmt.StmtList{
expected := &node.Root{
Stmts: []node.Node{
&stmt.Class{
PhpDocComment: "",
@ -49,7 +49,7 @@ func TestTraitUse(t *testing.T) {
func TestTraitsUse(t *testing.T) {
src := `<? class Foo { use Bar, Baz; }`
expected := &stmt.StmtList{
expected := &node.Root{
Stmts: []node.Node{
&stmt.Class{
PhpDocComment: "",
@ -88,7 +88,7 @@ func TestTraitsUse(t *testing.T) {
func TestTraitsUseEmptyAdaptations(t *testing.T) {
src := `<? class Foo { use Bar, Baz {} }`
expected := &stmt.StmtList{
expected := &node.Root{
Stmts: []node.Node{
&stmt.Class{
PhpDocComment: "",
@ -128,7 +128,7 @@ func TestTraitsUseEmptyAdaptations(t *testing.T) {
func TestTraitsUseModifier(t *testing.T) {
src := `<? class Foo { use Bar, Baz { one as public; } }`
expected := &stmt.StmtList{
expected := &node.Root{
Stmts: []node.Node{
&stmt.Class{
PhpDocComment: "",
@ -177,7 +177,7 @@ func TestTraitsUseModifier(t *testing.T) {
func TestTraitsUseAliasModifier(t *testing.T) {
src := `<? class Foo { use Bar, Baz { one as public two; } }`
expected := &stmt.StmtList{
expected := &node.Root{
Stmts: []node.Node{
&stmt.Class{
PhpDocComment: "",
@ -227,7 +227,7 @@ func TestTraitsUseAliasModifier(t *testing.T) {
func TestTraitsUseAdaptions(t *testing.T) {
src := `<? class Foo { use Bar, Baz { Bar::one insteadof Baz, Quux; Baz::one as two; } }`
expected := &stmt.StmtList{
expected := &node.Root{
Stmts: []node.Node{
&stmt.Class{
PhpDocComment: "",

View File

@ -17,7 +17,7 @@ func TestTry(t *testing.T) {
try {}
`
expected := &stmt.StmtList{
expected := &node.Root{
Stmts: []node.Node{
&stmt.Try{
Stmts: []node.Node{},
@ -42,7 +42,7 @@ func TestTryCatch(t *testing.T) {
try {} catch (Exception $e) {}
`
expected := &stmt.StmtList{
expected := &node.Root{
Stmts: []node.Node{
&stmt.Try{
Stmts: []node.Node{},
@ -81,7 +81,7 @@ func TestPhp7TryCatch(t *testing.T) {
try {} catch (Exception|RuntimeException $e) {}
`
expected := &stmt.StmtList{
expected := &node.Root{
Stmts: []node.Node{
&stmt.Try{
Stmts: []node.Node{},
@ -120,7 +120,7 @@ func TestTryCatchCatch(t *testing.T) {
try {} catch (Exception $e) {} catch (RuntimeException $e) {}
`
expected := &stmt.StmtList{
expected := &node.Root{
Stmts: []node.Node{
&stmt.Try{
Stmts: []node.Node{},
@ -172,7 +172,7 @@ func TestTryCatchFinally(t *testing.T) {
try {} catch (Exception $e) {} finally {}
`
expected := &stmt.StmtList{
expected := &node.Root{
Stmts: []node.Node{
&stmt.Try{
Stmts: []node.Node{},
@ -212,7 +212,7 @@ func TestTryCatchFinally(t *testing.T) {
func TestTryCatchCatchCatch(t *testing.T) {
src := `<? try {} catch (Exception $e) {} catch (\RuntimeException $e) {} catch (namespace\AdditionException $e) {}`
expected := &stmt.StmtList{
expected := &node.Root{
Stmts: []node.Node{
&stmt.Try{
Stmts: []node.Node{},

View File

@ -14,7 +14,7 @@ import (
func TestUnset(t *testing.T) {
src := `<? unset($a);`
expected := &stmt.StmtList{
expected := &node.Root{
Stmts: []node.Node{
&stmt.Unset{
Vars: []node.Node{
@ -38,7 +38,7 @@ func TestUnset(t *testing.T) {
func TestUnsetVars(t *testing.T) {
src := `<? unset($a, $b);`
expected := &stmt.StmtList{
expected := &node.Root{
Stmts: []node.Node{
&stmt.Unset{
Vars: []node.Node{
@ -63,7 +63,7 @@ func TestUnsetVars(t *testing.T) {
func TestUnsetTrailingComma(t *testing.T) {
src := `<? unset($a, $b,);`
expected := &stmt.StmtList{
expected := &node.Root{
Stmts: []node.Node{
&stmt.Unset{
Vars: []node.Node{

View File

@ -14,7 +14,7 @@ import (
func TestSimpleUse(t *testing.T) {
src := `<? use Foo;`
expected := &stmt.StmtList{
expected := &node.Root{
Stmts: []node.Node{
&stmt.UseList{
Uses: []node.Node{
@ -44,7 +44,7 @@ func TestSimpleUse(t *testing.T) {
func TestUseFullyQualified(t *testing.T) {
src := `<? use \Foo;`
expected := &stmt.StmtList{
expected := &node.Root{
Stmts: []node.Node{
&stmt.UseList{
Uses: []node.Node{
@ -74,7 +74,7 @@ func TestUseFullyQualified(t *testing.T) {
func TestUseFullyQualifiedAlias(t *testing.T) {
src := `<? use \Foo as Bar;`
expected := &stmt.StmtList{
expected := &node.Root{
Stmts: []node.Node{
&stmt.UseList{
Uses: []node.Node{
@ -105,7 +105,7 @@ func TestUseFullyQualifiedAlias(t *testing.T) {
func TestUseList(t *testing.T) {
src := `<? use Foo, Bar;`
expected := &stmt.StmtList{
expected := &node.Root{
Stmts: []node.Node{
&stmt.UseList{
Uses: []node.Node{
@ -142,7 +142,7 @@ func TestUseList(t *testing.T) {
func TestUseListAlias(t *testing.T) {
src := `<? use Foo, Bar as Baz;`
expected := &stmt.StmtList{
expected := &node.Root{
Stmts: []node.Node{
&stmt.UseList{
Uses: []node.Node{
@ -180,7 +180,7 @@ func TestUseListAlias(t *testing.T) {
func TestUseListFunctionType(t *testing.T) {
src := `<? use function Foo, \Bar;`
expected := &stmt.StmtList{
expected := &node.Root{
Stmts: []node.Node{
&stmt.UseList{
UseType: &node.Identifier{Value: "function"},
@ -218,7 +218,7 @@ func TestUseListFunctionType(t *testing.T) {
func TestUseListFunctionTypeAliases(t *testing.T) {
src := `<? use function Foo as foo, \Bar as bar;`
expected := &stmt.StmtList{
expected := &node.Root{
Stmts: []node.Node{
&stmt.UseList{
UseType: &node.Identifier{Value: "function"},
@ -258,7 +258,7 @@ func TestUseListFunctionTypeAliases(t *testing.T) {
func TestUseListConstType(t *testing.T) {
src := `<? use const Foo, \Bar;`
expected := &stmt.StmtList{
expected := &node.Root{
Stmts: []node.Node{
&stmt.UseList{
UseType: &node.Identifier{Value: "const"},
@ -296,7 +296,7 @@ func TestUseListConstType(t *testing.T) {
func TestUseListConstTypeAliases(t *testing.T) {
src := `<? use const Foo as foo, \Bar as bar;`
expected := &stmt.StmtList{
expected := &node.Root{
Stmts: []node.Node{
&stmt.UseList{
UseType: &node.Identifier{Value: "const"},
@ -336,7 +336,7 @@ func TestUseListConstTypeAliases(t *testing.T) {
func TestGroupUse(t *testing.T) {
src := `<? use Foo\{Bar, Baz};`
expected := &stmt.StmtList{
expected := &node.Root{
Stmts: []node.Node{
&stmt.GroupUse{
Prefix: &name.Name{
@ -373,7 +373,7 @@ func TestGroupUse(t *testing.T) {
func TestGroupUseAlias(t *testing.T) {
src := `<? use Foo\{Bar, Baz as quux};`
expected := &stmt.StmtList{
expected := &node.Root{
Stmts: []node.Node{
&stmt.GroupUse{
Prefix: &name.Name{
@ -411,7 +411,7 @@ func TestGroupUseAlias(t *testing.T) {
func TestFunctionGroupUse(t *testing.T) {
src := `<? use function Foo\{Bar, Baz};`
expected := &stmt.StmtList{
expected := &node.Root{
Stmts: []node.Node{
&stmt.GroupUse{
UseType: &node.Identifier{Value: "function"},
@ -449,7 +449,7 @@ func TestFunctionGroupUse(t *testing.T) {
func TestConstGroupUse(t *testing.T) {
src := `<? use const Foo\{Bar, Baz};`
expected := &stmt.StmtList{
expected := &node.Root{
Stmts: []node.Node{
&stmt.GroupUse{
UseType: &node.Identifier{Value: "const"},
@ -487,7 +487,7 @@ func TestConstGroupUse(t *testing.T) {
func TestMixedGroupUse(t *testing.T) {
src := `<? use Foo\{const Bar, function Baz};`
expected := &stmt.StmtList{
expected := &node.Root{
Stmts: []node.Node{
&stmt.GroupUse{
Prefix: &name.Name{

View File

@ -15,7 +15,7 @@ import (
func TestBreakEmpty(t *testing.T) {
src := `<? while (1) { break; }`
expected := &stmt.StmtList{
expected := &node.Root{
Stmts: []node.Node{
&stmt.While{
Cond: &scalar.Lnumber{Value: "1"},
@ -42,7 +42,7 @@ func TestBreakEmpty(t *testing.T) {
func TestBreakLight(t *testing.T) {
src := `<? while (1) { break 2; }`
expected := &stmt.StmtList{
expected := &node.Root{
Stmts: []node.Node{
&stmt.While{
Cond: &scalar.Lnumber{Value: "1"},
@ -71,7 +71,7 @@ func TestBreakLight(t *testing.T) {
func TestBreak(t *testing.T) {
src := `<? while (1) : break(3); endwhile;`
expected := &stmt.StmtList{
expected := &node.Root{
Stmts: []node.Node{
&stmt.AltWhile{
Cond: &scalar.Lnumber{Value: "1"},

View File

@ -32,7 +32,7 @@ func assertEqual(t *testing.T, expected interface{}, actual interface{}) {
func TestIdentifier(t *testing.T) {
src := `<? $foo;`
expected := &stmt.StmtList{
expected := &node.Root{
Stmts: []node.Node{
&stmt.Expression{
Expr: &expr.Variable{
@ -65,7 +65,7 @@ func TestPhp7ArgumentNode(t *testing.T) {
new class ($a, ...$b) {};
`
expected := &stmt.StmtList{
expected := &node.Root{
Stmts: []node.Node{
&stmt.Expression{
Expr: &expr.FunctionCall{
@ -169,7 +169,7 @@ func TestPhp5ArgumentNode(t *testing.T) {
new foo($a, ...$b);
`
expected := &stmt.StmtList{
expected := &node.Root{
Stmts: []node.Node{
&stmt.Expression{
Expr: &expr.FunctionCall{
@ -273,7 +273,7 @@ func TestPhp7ParameterNode(t *testing.T) {
},
}
expected := &stmt.StmtList{
expected := &node.Root{
Stmts: []node.Node{
&stmt.Function{
ReturnsRef: false,
@ -341,7 +341,7 @@ func TestPhp5ParameterNode(t *testing.T) {
},
}
expected := &stmt.StmtList{
expected := &node.Root{
Stmts: []node.Node{
&stmt.Function{
ReturnsRef: false,
@ -388,7 +388,7 @@ func TestPhp5ParameterNode(t *testing.T) {
func TestCommentEndFile(t *testing.T) {
src := `<? //comment at the end)`
expected := &stmt.StmtList{
expected := &node.Root{
Stmts: []node.Node{},
}

View File

@ -4,6 +4,8 @@ import (
"reflect"
"testing"
"github.com/z7zmey/php-parser/node/stmt"
"github.com/z7zmey/php-parser/node/scalar"
"github.com/z7zmey/php-parser/walker"
@ -53,6 +55,13 @@ var nodesToTest = []struct {
[]string{"Arguments"},
map[string]interface{}{},
},
{
&node.Root{
Stmts: []node.Node{&stmt.Expression{}},
},
[]string{"Stmts"},
map[string]interface{}{},
},
}
type visitorMock struct {

View File

@ -2347,7 +2347,7 @@ yydefault:
yyDollar = yyS[yypt-1 : yypt+1]
//line php5/php5.y:272
{
yylex.(*Parser).rootNode = stmt.NewStmtList(yyDollar[1].list)
yylex.(*Parser).rootNode = node.NewRoot(yyDollar[1].list)
yylex.(*Parser).positions.AddPosition(yylex.(*Parser).rootNode, yylex.(*Parser).positionBuilder.NewNodeListPosition(yyDollar[1].list))
}
case 2:

View File

@ -270,7 +270,7 @@ import (
start:
top_statement_list
{
yylex.(*Parser).rootNode = stmt.NewStmtList($1)
yylex.(*Parser).rootNode = node.NewRoot($1)
yylex.(*Parser).positions.AddPosition(yylex.(*Parser).rootNode, yylex.(*Parser).positionBuilder.NewNodeListPosition($1))
}
;

View File

@ -429,7 +429,7 @@ func TestPhp5(t *testing.T) {
},
}
expected := &stmt.StmtList{
expected := &node.Root{
Stmts: []node.Node{
&stmt.Expression{
Expr: &expr.FunctionCall{
@ -3669,7 +3669,7 @@ func TestPhp5Strings(t *testing.T) {
';
`
expected := &stmt.StmtList{
expected := &node.Root{
Stmts: []node.Node{
&stmt.Expression{
Expr: &scalar.String{Value: "\"test\""},
@ -3713,7 +3713,7 @@ CAD;
CAD;
`
expected := &stmt.StmtList{
expected := &node.Root{
Stmts: []node.Node{
&stmt.Expression{
Expr: &scalar.Heredoc{

View File

@ -2135,7 +2135,7 @@ yydefault:
yyDollar = yyS[yypt-1 : yypt+1]
//line php7/php7.y:296
{
yylex.(*Parser).rootNode = stmt.NewStmtList(yyDollar[1].list)
yylex.(*Parser).rootNode = node.NewRoot(yyDollar[1].list)
// save position
yylex.(*Parser).positions.AddPosition(yylex.(*Parser).rootNode, yylex.(*Parser).positionBuilder.NewNodeListPosition(yyDollar[1].list))

View File

@ -294,7 +294,7 @@ import (
start:
top_statement_list
{
yylex.(*Parser).rootNode = stmt.NewStmtList($1)
yylex.(*Parser).rootNode = node.NewRoot($1)
// save position
yylex.(*Parser).positions.AddPosition(yylex.(*Parser).rootNode, yylex.(*Parser).positionBuilder.NewNodeListPosition($1))
@ -1950,7 +1950,7 @@ class_statement:
// save position
yylex.(*Parser).positions.AddPosition(name, yylex.(*Parser).positionBuilder.NewTokenPosition($4))
yylex.(*Parser).positions.AddPosition($$, yylex.(*Parser).positionBuilder.NewOptionalListTokensPosition($1, $2, $10.endToken))
// save comments
yylex.(*Parser).comments.AddFromToken($$, $2, comment.FunctionToken)
if $3.value {

View File

@ -397,7 +397,7 @@ func TestPhp7(t *testing.T) {
},
}
expected := &stmt.StmtList{
expected := &node.Root{
Stmts: []node.Node{
&stmt.Expression{
Expr: &expr.FunctionCall{
@ -3241,7 +3241,7 @@ func TestPhp5Strings(t *testing.T) {
';
`
expected := &stmt.StmtList{
expected := &node.Root{
Stmts: []node.Node{
&stmt.Expression{
Expr: &scalar.String{Value: "\"test\""},
@ -3285,7 +3285,7 @@ CAD;
CAD;
`
expected := &stmt.StmtList{
expected := &node.Root{
Stmts: []node.Node{
&stmt.Expression{
Expr: &scalar.Heredoc{

View File

@ -30,27 +30,6 @@ func NewPrinter(w io.Writer, indentStr string) *Printer {
}
}
func (p *Printer) PrintFile(n *stmt.StmtList) {
if len(n.Stmts) > 0 {
firstStmt := n.Stmts[0]
n.Stmts = n.Stmts[1:]
switch fs := firstStmt.(type) {
case *stmt.InlineHtml:
io.WriteString(p.w, fs.Value)
io.WriteString(p.w, "<?php\n")
default:
io.WriteString(p.w, "<?php\n")
p.printIndent()
p.Print(fs)
io.WriteString(p.w, "\n")
}
}
p.indentDepth--
p.printNodes(n.Stmts)
io.WriteString(p.w, "\n")
}
func (p *Printer) Print(n node.Node) {
p.printNode(n)
}
@ -89,6 +68,8 @@ func (p *Printer) printNode(n node.Node) {
// node
case *node.Root:
p.printNodeRoot(n)
case *node.Identifier:
p.printNodeIdentifier(n)
case *node.Parameter:
@ -433,6 +414,29 @@ func (p *Printer) printNode(n node.Node) {
// node
func (p *Printer) printNodeRoot(n node.Node) {
v := n.(*node.Root)
if len(v.Stmts) > 0 {
firstStmt := v.Stmts[0]
v.Stmts = v.Stmts[1:]
switch fs := firstStmt.(type) {
case *stmt.InlineHtml:
io.WriteString(p.w, fs.Value)
io.WriteString(p.w, "<?php\n")
default:
io.WriteString(p.w, "<?php\n")
p.printIndent()
p.Print(fs)
io.WriteString(p.w, "\n")
}
}
p.indentDepth--
p.printNodes(v.Stmts)
io.WriteString(p.w, "\n")
}
func (p *Printer) printNodeIdentifier(n node.Node) {
v := n.(*node.Identifier).Value
io.WriteString(p.w, v)

View File

@ -19,7 +19,7 @@ func TestPrintFile(t *testing.T) {
o := bytes.NewBufferString("")
p := printer.NewPrinter(o, "\t")
p.PrintFile(&stmt.StmtList{
p.Print(&node.Root{
Stmts: []node.Node{
&stmt.Namespace{
NamespaceName: &name.Name{
@ -78,7 +78,7 @@ func TestPrintFileInlineHtml(t *testing.T) {
o := bytes.NewBufferString("")
p := printer.NewPrinter(o, " ")
p.PrintFile(&stmt.StmtList{
p.Print(&node.Root{
Stmts: []node.Node{
&stmt.InlineHtml{Value: "<div>HTML</div>"},
&stmt.Expression{

View File

@ -39,7 +39,7 @@ func ExampleDumper() {
nodes.Walk(dumper)
// Unordered output:
//| [*stmt.StmtList]
//| [*node.Root]
//| "Position": Pos{Line: 3-11 Pos: 10-143};
//| "Stmts":
//| [*stmt.Namespace]