2018-01-13 01:40:08 +00:00
|
|
|
package node_test
|
|
|
|
|
|
|
|
import (
|
|
|
|
"bytes"
|
|
|
|
"reflect"
|
|
|
|
"testing"
|
|
|
|
|
2018-06-25 12:38:31 +00:00
|
|
|
"github.com/z7zmey/php-parser/comment"
|
2018-01-13 01:40:08 +00:00
|
|
|
"github.com/z7zmey/php-parser/node/name"
|
2018-06-24 07:19:44 +00:00
|
|
|
"github.com/z7zmey/php-parser/position"
|
2018-01-13 01:40:08 +00:00
|
|
|
|
|
|
|
"github.com/z7zmey/php-parser/node/expr"
|
|
|
|
|
|
|
|
"github.com/kylelemons/godebug/pretty"
|
|
|
|
"github.com/z7zmey/php-parser/node"
|
|
|
|
"github.com/z7zmey/php-parser/node/stmt"
|
2018-02-08 10:48:38 +00:00
|
|
|
"github.com/z7zmey/php-parser/php5"
|
2018-02-04 19:44:58 +00:00
|
|
|
"github.com/z7zmey/php-parser/php7"
|
2018-01-13 01:40:08 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func assertEqual(t *testing.T, expected interface{}, actual interface{}) {
|
|
|
|
if !reflect.DeepEqual(expected, actual) {
|
|
|
|
diff := pretty.Compare(expected, actual)
|
|
|
|
|
|
|
|
if diff != "" {
|
|
|
|
t.Errorf("diff: (-expected +actual)\n%s", diff)
|
|
|
|
} else {
|
|
|
|
t.Errorf("expected and actual are not equal\n")
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestIdentifier(t *testing.T) {
|
|
|
|
src := `<? $foo;`
|
|
|
|
|
2018-05-02 09:14:24 +00:00
|
|
|
expected := &node.Root{
|
2018-06-24 07:19:44 +00:00
|
|
|
Position: &position.Position{
|
|
|
|
StartLine: 1,
|
|
|
|
EndLine: 1,
|
|
|
|
StartPos: 4,
|
|
|
|
EndPos: 8,
|
|
|
|
},
|
2018-01-13 01:40:08 +00:00
|
|
|
Stmts: []node.Node{
|
|
|
|
&stmt.Expression{
|
2018-06-24 07:19:44 +00:00
|
|
|
Position: &position.Position{
|
|
|
|
StartLine: 1,
|
|
|
|
EndLine: 1,
|
|
|
|
StartPos: 4,
|
|
|
|
EndPos: 8,
|
|
|
|
},
|
2018-01-13 01:40:08 +00:00
|
|
|
Expr: &expr.Variable{
|
2018-06-24 07:19:44 +00:00
|
|
|
Position: &position.Position{
|
|
|
|
StartLine: 1,
|
|
|
|
EndLine: 1,
|
|
|
|
StartPos: 4,
|
|
|
|
EndPos: 7,
|
|
|
|
},
|
|
|
|
VarName: &node.Identifier{
|
|
|
|
Position: &position.Position{
|
|
|
|
StartLine: 1,
|
|
|
|
EndLine: 1,
|
|
|
|
StartPos: 4,
|
|
|
|
EndPos: 7,
|
|
|
|
},
|
|
|
|
Value: "foo",
|
|
|
|
},
|
2018-01-13 01:40:08 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
2018-04-10 12:23:13 +00:00
|
|
|
php7parser := php7.NewParser(bytes.NewBufferString(src), "test.php")
|
|
|
|
php7parser.Parse()
|
|
|
|
actual := php7parser.GetRootNode()
|
2018-02-08 10:48:38 +00:00
|
|
|
assertEqual(t, expected, actual)
|
2018-01-13 01:40:08 +00:00
|
|
|
|
2018-04-10 12:23:13 +00:00
|
|
|
php5parser := php5.NewParser(bytes.NewBufferString(src), "test.php")
|
|
|
|
php5parser.Parse()
|
|
|
|
actual = php5parser.GetRootNode()
|
2018-01-13 01:40:08 +00:00
|
|
|
assertEqual(t, expected, actual)
|
|
|
|
}
|
|
|
|
|
2018-02-08 10:48:38 +00:00
|
|
|
func TestPhp7ArgumentNode(t *testing.T) {
|
2018-01-13 01:40:08 +00:00
|
|
|
src := `<?
|
|
|
|
foo($a, ...$b);
|
|
|
|
$foo($a, ...$b);
|
|
|
|
$foo->bar($a, ...$b);
|
|
|
|
foo::bar($a, ...$b);
|
|
|
|
$foo::bar($a, ...$b);
|
|
|
|
new foo($a, ...$b);
|
|
|
|
/** anonymous class */
|
|
|
|
new class ($a, ...$b) {};
|
|
|
|
`
|
|
|
|
|
2018-05-02 09:14:24 +00:00
|
|
|
expected := &node.Root{
|
2018-06-24 07:19:44 +00:00
|
|
|
Position: &position.Position{
|
|
|
|
StartLine: 2,
|
|
|
|
EndLine: 9,
|
|
|
|
StartPos: 7,
|
|
|
|
EndPos: 186,
|
|
|
|
},
|
2018-01-13 01:40:08 +00:00
|
|
|
Stmts: []node.Node{
|
|
|
|
&stmt.Expression{
|
2018-06-24 07:19:44 +00:00
|
|
|
Position: &position.Position{
|
|
|
|
StartLine: 2,
|
|
|
|
EndLine: 2,
|
|
|
|
StartPos: 7,
|
|
|
|
EndPos: 21,
|
|
|
|
},
|
2018-01-13 01:40:08 +00:00
|
|
|
Expr: &expr.FunctionCall{
|
2018-06-24 07:19:44 +00:00
|
|
|
Position: &position.Position{
|
|
|
|
StartLine: 2,
|
|
|
|
EndLine: 2,
|
|
|
|
StartPos: 7,
|
|
|
|
EndPos: 20,
|
|
|
|
},
|
|
|
|
Function: &name.Name{
|
|
|
|
Position: &position.Position{
|
|
|
|
StartLine: 2,
|
|
|
|
EndLine: 2,
|
|
|
|
StartPos: 7,
|
|
|
|
EndPos: 9,
|
|
|
|
},
|
|
|
|
Parts: []node.Node{
|
|
|
|
&name.NamePart{
|
|
|
|
Position: &position.Position{
|
|
|
|
StartLine: 2,
|
|
|
|
EndLine: 2,
|
|
|
|
StartPos: 7,
|
|
|
|
EndPos: 9,
|
|
|
|
},
|
|
|
|
Value: "foo",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2018-04-29 16:58:49 +00:00
|
|
|
ArgumentList: &node.ArgumentList{
|
2018-06-24 07:19:44 +00:00
|
|
|
Position: &position.Position{
|
|
|
|
StartLine: 2,
|
|
|
|
EndLine: 2,
|
|
|
|
StartPos: 10,
|
|
|
|
EndPos: 20,
|
|
|
|
},
|
2018-04-29 16:58:49 +00:00
|
|
|
Arguments: []node.Node{
|
2018-06-24 07:19:44 +00:00
|
|
|
&node.Argument{
|
|
|
|
Position: &position.Position{
|
|
|
|
StartLine: 2,
|
|
|
|
EndLine: 2,
|
|
|
|
StartPos: 11,
|
|
|
|
EndPos: 12,
|
|
|
|
},
|
|
|
|
Variadic: false,
|
2018-06-25 12:38:31 +00:00
|
|
|
IsReference: false,
|
2018-06-24 07:19:44 +00:00
|
|
|
Expr: &expr.Variable{
|
|
|
|
Position: &position.Position{
|
|
|
|
StartLine: 2,
|
|
|
|
EndLine: 2,
|
|
|
|
StartPos: 11,
|
|
|
|
EndPos: 12,
|
|
|
|
},
|
|
|
|
VarName: &node.Identifier{
|
|
|
|
Position: &position.Position{
|
|
|
|
StartLine: 2,
|
|
|
|
EndLine: 2,
|
|
|
|
StartPos: 11,
|
|
|
|
EndPos: 12,
|
|
|
|
},
|
|
|
|
Value: "a",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
&node.Argument{
|
|
|
|
Position: &position.Position{
|
|
|
|
StartLine: 2,
|
|
|
|
EndLine: 2,
|
|
|
|
StartPos: 15,
|
|
|
|
EndPos: 19,
|
|
|
|
},
|
|
|
|
Variadic: true,
|
|
|
|
IsReference: false,
|
|
|
|
Expr: &expr.Variable{
|
|
|
|
Position: &position.Position{
|
|
|
|
StartLine: 2,
|
|
|
|
EndLine: 2,
|
|
|
|
StartPos: 18,
|
|
|
|
EndPos: 19,
|
|
|
|
},
|
|
|
|
VarName: &node.Identifier{
|
|
|
|
Position: &position.Position{
|
|
|
|
StartLine: 2,
|
|
|
|
EndLine: 2,
|
|
|
|
StartPos: 18,
|
|
|
|
EndPos: 19,
|
|
|
|
},
|
|
|
|
Value: "b",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2018-04-29 16:58:49 +00:00
|
|
|
},
|
2018-01-13 01:40:08 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
&stmt.Expression{
|
2018-06-24 07:19:44 +00:00
|
|
|
Position: &position.Position{
|
|
|
|
StartLine: 3,
|
|
|
|
EndLine: 3,
|
|
|
|
StartPos: 25,
|
|
|
|
EndPos: 40,
|
|
|
|
},
|
2018-01-13 01:40:08 +00:00
|
|
|
Expr: &expr.FunctionCall{
|
2018-06-24 07:19:44 +00:00
|
|
|
Position: &position.Position{
|
|
|
|
StartLine: 3,
|
|
|
|
EndLine: 3,
|
|
|
|
StartPos: 25,
|
|
|
|
EndPos: 39,
|
|
|
|
},
|
|
|
|
Function: &expr.Variable{
|
|
|
|
Position: &position.Position{
|
|
|
|
StartLine: 3,
|
|
|
|
EndLine: 3,
|
|
|
|
StartPos: 25,
|
|
|
|
EndPos: 28,
|
|
|
|
},
|
|
|
|
VarName: &node.Identifier{
|
|
|
|
Position: &position.Position{
|
|
|
|
StartLine: 3,
|
|
|
|
EndLine: 3,
|
|
|
|
StartPos: 25,
|
|
|
|
EndPos: 28,
|
|
|
|
},
|
|
|
|
Value: "foo",
|
|
|
|
},
|
|
|
|
},
|
2018-04-29 16:58:49 +00:00
|
|
|
ArgumentList: &node.ArgumentList{
|
2018-06-24 07:19:44 +00:00
|
|
|
Position: &position.Position{
|
|
|
|
StartLine: 3,
|
|
|
|
EndLine: 3,
|
|
|
|
StartPos: 29,
|
|
|
|
EndPos: 39,
|
|
|
|
},
|
2018-04-29 16:58:49 +00:00
|
|
|
Arguments: []node.Node{
|
2018-06-24 07:19:44 +00:00
|
|
|
&node.Argument{
|
|
|
|
Position: &position.Position{
|
|
|
|
StartLine: 3,
|
|
|
|
EndLine: 3,
|
|
|
|
StartPos: 30,
|
|
|
|
EndPos: 31,
|
|
|
|
},
|
|
|
|
Variadic: false,
|
|
|
|
IsReference: false,
|
|
|
|
Expr: &expr.Variable{
|
|
|
|
Position: &position.Position{
|
|
|
|
StartLine: 3,
|
|
|
|
EndLine: 3,
|
|
|
|
StartPos: 30,
|
|
|
|
EndPos: 31,
|
|
|
|
},
|
|
|
|
VarName: &node.Identifier{
|
|
|
|
Position: &position.Position{
|
|
|
|
StartLine: 3,
|
|
|
|
EndLine: 3,
|
|
|
|
StartPos: 30,
|
|
|
|
EndPos: 31,
|
|
|
|
},
|
|
|
|
Value: "a",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
&node.Argument{
|
|
|
|
Position: &position.Position{
|
|
|
|
StartLine: 3,
|
|
|
|
EndLine: 3,
|
|
|
|
StartPos: 34,
|
|
|
|
EndPos: 38,
|
|
|
|
},
|
|
|
|
Variadic: true,
|
|
|
|
IsReference: false,
|
|
|
|
Expr: &expr.Variable{
|
|
|
|
Position: &position.Position{
|
|
|
|
StartLine: 3,
|
|
|
|
EndLine: 3,
|
|
|
|
StartPos: 37,
|
|
|
|
EndPos: 38,
|
|
|
|
},
|
|
|
|
VarName: &node.Identifier{
|
|
|
|
Position: &position.Position{
|
|
|
|
StartLine: 3,
|
|
|
|
EndLine: 3,
|
|
|
|
StartPos: 37,
|
|
|
|
EndPos: 38,
|
|
|
|
},
|
|
|
|
Value: "b",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2018-04-29 16:58:49 +00:00
|
|
|
},
|
2018-01-13 01:40:08 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
&stmt.Expression{
|
2018-06-24 07:19:44 +00:00
|
|
|
Position: &position.Position{
|
|
|
|
StartLine: 4,
|
|
|
|
EndLine: 4,
|
|
|
|
StartPos: 44,
|
|
|
|
EndPos: 64,
|
|
|
|
},
|
2018-01-13 01:40:08 +00:00
|
|
|
Expr: &expr.MethodCall{
|
2018-06-24 07:19:44 +00:00
|
|
|
Position: &position.Position{
|
|
|
|
StartLine: 4,
|
|
|
|
EndLine: 4,
|
|
|
|
StartPos: 44,
|
|
|
|
EndPos: 63,
|
|
|
|
},
|
|
|
|
Variable: &expr.Variable{
|
|
|
|
Position: &position.Position{
|
|
|
|
StartLine: 4,
|
|
|
|
EndLine: 4,
|
|
|
|
StartPos: 44,
|
|
|
|
EndPos: 47,
|
|
|
|
},
|
|
|
|
VarName: &node.Identifier{
|
|
|
|
Position: &position.Position{
|
|
|
|
StartLine: 4,
|
|
|
|
EndLine: 4,
|
|
|
|
StartPos: 44,
|
|
|
|
EndPos: 47,
|
|
|
|
},
|
|
|
|
Value: "foo",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Method: &node.Identifier{
|
|
|
|
Position: &position.Position{
|
|
|
|
StartLine: 4,
|
|
|
|
EndLine: 4,
|
|
|
|
StartPos: 50,
|
|
|
|
EndPos: 52,
|
|
|
|
},
|
|
|
|
Value: "bar",
|
|
|
|
},
|
2018-04-29 16:58:49 +00:00
|
|
|
ArgumentList: &node.ArgumentList{
|
2018-06-24 07:19:44 +00:00
|
|
|
Position: &position.Position{
|
|
|
|
StartLine: 4,
|
|
|
|
EndLine: 4,
|
|
|
|
StartPos: 53,
|
|
|
|
EndPos: 63,
|
|
|
|
},
|
2018-04-29 16:58:49 +00:00
|
|
|
Arguments: []node.Node{
|
2018-06-24 07:19:44 +00:00
|
|
|
&node.Argument{
|
|
|
|
Position: &position.Position{
|
|
|
|
StartLine: 4,
|
|
|
|
EndLine: 4,
|
|
|
|
StartPos: 54,
|
|
|
|
EndPos: 55,
|
|
|
|
},
|
|
|
|
IsReference: false,
|
2018-06-25 12:38:31 +00:00
|
|
|
Variadic: false,
|
2018-06-24 07:19:44 +00:00
|
|
|
Expr: &expr.Variable{
|
|
|
|
Position: &position.Position{
|
|
|
|
StartLine: 4,
|
|
|
|
EndLine: 4,
|
|
|
|
StartPos: 54,
|
|
|
|
EndPos: 55,
|
|
|
|
},
|
|
|
|
VarName: &node.Identifier{
|
|
|
|
Position: &position.Position{
|
|
|
|
StartLine: 4,
|
|
|
|
EndLine: 4,
|
|
|
|
StartPos: 54,
|
|
|
|
EndPos: 55,
|
|
|
|
},
|
|
|
|
Value: "a",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
&node.Argument{
|
|
|
|
Position: &position.Position{
|
|
|
|
StartLine: 4,
|
|
|
|
EndLine: 4,
|
|
|
|
StartPos: 58,
|
|
|
|
EndPos: 62,
|
|
|
|
},
|
|
|
|
Variadic: true,
|
|
|
|
IsReference: false,
|
|
|
|
Expr: &expr.Variable{
|
|
|
|
Position: &position.Position{
|
|
|
|
StartLine: 4,
|
|
|
|
EndLine: 4,
|
|
|
|
StartPos: 61,
|
|
|
|
EndPos: 62,
|
|
|
|
},
|
|
|
|
VarName: &node.Identifier{
|
|
|
|
Position: &position.Position{
|
|
|
|
StartLine: 4,
|
|
|
|
EndLine: 4,
|
|
|
|
StartPos: 61,
|
|
|
|
EndPos: 62,
|
|
|
|
},
|
|
|
|
Value: "b",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2018-04-29 16:58:49 +00:00
|
|
|
},
|
2018-01-13 01:40:08 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
&stmt.Expression{
|
2018-06-24 07:19:44 +00:00
|
|
|
Position: &position.Position{
|
|
|
|
StartLine: 5,
|
|
|
|
EndLine: 5,
|
|
|
|
StartPos: 68,
|
|
|
|
EndPos: 87,
|
|
|
|
},
|
2018-01-13 01:40:08 +00:00
|
|
|
Expr: &expr.StaticCall{
|
2018-06-24 07:19:44 +00:00
|
|
|
Position: &position.Position{
|
|
|
|
StartLine: 5,
|
|
|
|
EndLine: 5,
|
|
|
|
StartPos: 68,
|
|
|
|
EndPos: 86,
|
|
|
|
},
|
|
|
|
Class: &name.Name{
|
|
|
|
Position: &position.Position{
|
|
|
|
StartLine: 5,
|
|
|
|
EndLine: 5,
|
|
|
|
StartPos: 68,
|
|
|
|
EndPos: 70,
|
|
|
|
},
|
|
|
|
Parts: []node.Node{
|
|
|
|
&name.NamePart{
|
|
|
|
Position: &position.Position{
|
|
|
|
StartLine: 5,
|
|
|
|
EndLine: 5,
|
|
|
|
StartPos: 68,
|
|
|
|
EndPos: 70,
|
|
|
|
},
|
|
|
|
Value: "foo",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Call: &node.Identifier{
|
|
|
|
Position: &position.Position{
|
|
|
|
StartLine: 5,
|
|
|
|
EndLine: 5,
|
|
|
|
StartPos: 73,
|
|
|
|
EndPos: 75,
|
|
|
|
},
|
|
|
|
Value: "bar",
|
|
|
|
},
|
2018-04-29 16:58:49 +00:00
|
|
|
ArgumentList: &node.ArgumentList{
|
2018-06-24 07:19:44 +00:00
|
|
|
Position: &position.Position{
|
|
|
|
StartLine: 5,
|
|
|
|
EndLine: 5,
|
|
|
|
StartPos: 76,
|
|
|
|
EndPos: 86,
|
|
|
|
},
|
2018-04-29 16:58:49 +00:00
|
|
|
Arguments: []node.Node{
|
2018-06-24 07:19:44 +00:00
|
|
|
&node.Argument{
|
|
|
|
Position: &position.Position{
|
|
|
|
StartLine: 5,
|
|
|
|
EndLine: 5,
|
|
|
|
StartPos: 77,
|
|
|
|
EndPos: 78,
|
|
|
|
},
|
|
|
|
Variadic: false,
|
|
|
|
IsReference: false,
|
|
|
|
Expr: &expr.Variable{
|
|
|
|
Position: &position.Position{
|
|
|
|
StartLine: 5,
|
|
|
|
EndLine: 5,
|
|
|
|
StartPos: 77,
|
|
|
|
EndPos: 78,
|
|
|
|
},
|
|
|
|
VarName: &node.Identifier{
|
|
|
|
Position: &position.Position{
|
|
|
|
StartLine: 5,
|
|
|
|
EndLine: 5,
|
|
|
|
StartPos: 77,
|
|
|
|
EndPos: 78,
|
|
|
|
},
|
|
|
|
Value: "a",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
&node.Argument{
|
|
|
|
Position: &position.Position{
|
|
|
|
StartLine: 5,
|
|
|
|
EndLine: 5,
|
|
|
|
StartPos: 81,
|
|
|
|
EndPos: 85,
|
|
|
|
},
|
|
|
|
Variadic: true,
|
2018-06-25 12:38:31 +00:00
|
|
|
IsReference: false,
|
2018-06-24 07:19:44 +00:00
|
|
|
Expr: &expr.Variable{
|
|
|
|
Position: &position.Position{
|
|
|
|
StartLine: 5,
|
|
|
|
EndLine: 5,
|
|
|
|
StartPos: 84,
|
|
|
|
EndPos: 85,
|
|
|
|
},
|
|
|
|
VarName: &node.Identifier{
|
|
|
|
Position: &position.Position{
|
|
|
|
StartLine: 5,
|
|
|
|
EndLine: 5,
|
|
|
|
StartPos: 84,
|
|
|
|
EndPos: 85,
|
|
|
|
},
|
|
|
|
Value: "b",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2018-04-29 16:58:49 +00:00
|
|
|
},
|
2018-01-13 01:40:08 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
&stmt.Expression{
|
2018-06-24 07:19:44 +00:00
|
|
|
Position: &position.Position{
|
|
|
|
StartLine: 6,
|
|
|
|
EndLine: 6,
|
|
|
|
StartPos: 91,
|
|
|
|
EndPos: 111,
|
|
|
|
},
|
2018-01-13 01:40:08 +00:00
|
|
|
Expr: &expr.StaticCall{
|
2018-06-24 07:19:44 +00:00
|
|
|
Position: &position.Position{
|
|
|
|
StartLine: 6,
|
|
|
|
EndLine: 6,
|
|
|
|
StartPos: 91,
|
|
|
|
EndPos: 110,
|
|
|
|
},
|
|
|
|
Class: &expr.Variable{
|
|
|
|
Position: &position.Position{
|
|
|
|
StartLine: 6,
|
|
|
|
EndLine: 6,
|
|
|
|
StartPos: 91,
|
|
|
|
EndPos: 94,
|
|
|
|
},
|
|
|
|
VarName: &node.Identifier{
|
|
|
|
Position: &position.Position{
|
|
|
|
StartLine: 6,
|
|
|
|
EndLine: 6,
|
|
|
|
StartPos: 91,
|
|
|
|
EndPos: 94,
|
|
|
|
},
|
|
|
|
Value: "foo",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Call: &node.Identifier{
|
|
|
|
Position: &position.Position{
|
|
|
|
StartLine: 6,
|
|
|
|
EndLine: 6,
|
|
|
|
StartPos: 97,
|
|
|
|
EndPos: 99,
|
|
|
|
},
|
|
|
|
Value: "bar",
|
|
|
|
},
|
2018-04-29 16:58:49 +00:00
|
|
|
ArgumentList: &node.ArgumentList{
|
2018-06-24 07:19:44 +00:00
|
|
|
Position: &position.Position{
|
|
|
|
StartLine: 6,
|
|
|
|
EndLine: 6,
|
|
|
|
StartPos: 100,
|
|
|
|
EndPos: 110,
|
|
|
|
},
|
2018-04-29 16:58:49 +00:00
|
|
|
Arguments: []node.Node{
|
2018-06-24 07:19:44 +00:00
|
|
|
&node.Argument{
|
|
|
|
Position: &position.Position{
|
|
|
|
StartLine: 6,
|
|
|
|
EndLine: 6,
|
|
|
|
StartPos: 101,
|
|
|
|
EndPos: 102,
|
|
|
|
},
|
|
|
|
Variadic: false,
|
2018-06-25 12:38:31 +00:00
|
|
|
IsReference: false,
|
2018-06-24 07:19:44 +00:00
|
|
|
Expr: &expr.Variable{
|
|
|
|
Position: &position.Position{
|
|
|
|
StartLine: 6,
|
|
|
|
EndLine: 6,
|
|
|
|
StartPos: 101,
|
|
|
|
EndPos: 102,
|
|
|
|
},
|
|
|
|
VarName: &node.Identifier{
|
|
|
|
Position: &position.Position{
|
|
|
|
StartLine: 6,
|
|
|
|
EndLine: 6,
|
|
|
|
StartPos: 101,
|
|
|
|
EndPos: 102,
|
|
|
|
},
|
|
|
|
Value: "a",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
&node.Argument{
|
|
|
|
Position: &position.Position{
|
|
|
|
StartLine: 6,
|
|
|
|
EndLine: 6,
|
|
|
|
StartPos: 105,
|
|
|
|
EndPos: 109,
|
|
|
|
},
|
|
|
|
Variadic: true,
|
|
|
|
IsReference: false,
|
|
|
|
Expr: &expr.Variable{
|
|
|
|
Position: &position.Position{
|
|
|
|
StartLine: 6,
|
|
|
|
EndLine: 6,
|
|
|
|
StartPos: 108,
|
|
|
|
EndPos: 109,
|
|
|
|
},
|
|
|
|
VarName: &node.Identifier{
|
|
|
|
Position: &position.Position{
|
|
|
|
StartLine: 6,
|
|
|
|
EndLine: 6,
|
|
|
|
StartPos: 108,
|
|
|
|
EndPos: 109,
|
|
|
|
},
|
|
|
|
Value: "b",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2018-04-29 16:58:49 +00:00
|
|
|
},
|
2018-01-13 01:40:08 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
&stmt.Expression{
|
2018-06-24 07:19:44 +00:00
|
|
|
Position: &position.Position{
|
|
|
|
StartLine: 7,
|
|
|
|
EndLine: 7,
|
|
|
|
StartPos: 115,
|
|
|
|
EndPos: 133,
|
|
|
|
},
|
2018-01-13 01:40:08 +00:00
|
|
|
Expr: &expr.New{
|
2018-06-24 07:19:44 +00:00
|
|
|
Position: &position.Position{
|
|
|
|
StartLine: 7,
|
|
|
|
EndLine: 7,
|
|
|
|
StartPos: 115,
|
|
|
|
EndPos: 132,
|
|
|
|
},
|
|
|
|
Class: &name.Name{
|
|
|
|
Position: &position.Position{
|
|
|
|
StartLine: 7,
|
|
|
|
EndLine: 7,
|
|
|
|
StartPos: 119,
|
|
|
|
EndPos: 121,
|
|
|
|
},
|
|
|
|
Parts: []node.Node{
|
|
|
|
&name.NamePart{
|
|
|
|
Position: &position.Position{
|
|
|
|
StartLine: 7,
|
|
|
|
EndLine: 7,
|
|
|
|
StartPos: 119,
|
|
|
|
EndPos: 121,
|
|
|
|
},
|
|
|
|
Value: "foo",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2018-04-29 16:58:49 +00:00
|
|
|
ArgumentList: &node.ArgumentList{
|
2018-06-24 07:19:44 +00:00
|
|
|
Position: &position.Position{
|
|
|
|
StartLine: 7,
|
|
|
|
EndLine: 7,
|
|
|
|
StartPos: 122,
|
|
|
|
EndPos: 132,
|
|
|
|
},
|
2018-04-29 16:58:49 +00:00
|
|
|
Arguments: []node.Node{
|
2018-06-24 07:19:44 +00:00
|
|
|
&node.Argument{
|
|
|
|
Position: &position.Position{
|
|
|
|
StartLine: 7,
|
|
|
|
EndLine: 7,
|
|
|
|
StartPos: 123,
|
|
|
|
EndPos: 124,
|
|
|
|
},
|
|
|
|
Variadic: false,
|
|
|
|
IsReference: false,
|
|
|
|
Expr: &expr.Variable{
|
|
|
|
Position: &position.Position{
|
|
|
|
StartLine: 7,
|
|
|
|
EndLine: 7,
|
|
|
|
StartPos: 123,
|
|
|
|
EndPos: 124,
|
|
|
|
},
|
|
|
|
VarName: &node.Identifier{
|
|
|
|
Position: &position.Position{
|
|
|
|
StartLine: 7,
|
|
|
|
EndLine: 7,
|
|
|
|
StartPos: 123,
|
|
|
|
EndPos: 124,
|
|
|
|
},
|
|
|
|
Value: "a",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
&node.Argument{
|
|
|
|
Position: &position.Position{
|
|
|
|
StartLine: 7,
|
|
|
|
EndLine: 7,
|
|
|
|
StartPos: 127,
|
|
|
|
EndPos: 131,
|
|
|
|
},
|
|
|
|
Variadic: true,
|
|
|
|
IsReference: false,
|
|
|
|
Expr: &expr.Variable{
|
|
|
|
Position: &position.Position{
|
|
|
|
StartLine: 7,
|
|
|
|
EndLine: 7,
|
|
|
|
StartPos: 130,
|
|
|
|
EndPos: 131,
|
|
|
|
},
|
|
|
|
VarName: &node.Identifier{
|
|
|
|
Position: &position.Position{
|
|
|
|
StartLine: 7,
|
|
|
|
EndLine: 7,
|
|
|
|
StartPos: 130,
|
|
|
|
EndPos: 131,
|
|
|
|
},
|
|
|
|
Value: "b",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2018-04-29 16:58:49 +00:00
|
|
|
},
|
2018-01-13 01:40:08 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
&stmt.Expression{
|
2018-06-24 07:19:44 +00:00
|
|
|
Position: &position.Position{
|
|
|
|
StartLine: 9,
|
|
|
|
EndLine: 9,
|
|
|
|
StartPos: 162,
|
|
|
|
EndPos: 186,
|
|
|
|
},
|
2018-01-13 01:40:08 +00:00
|
|
|
Expr: &expr.New{
|
2018-06-24 07:19:44 +00:00
|
|
|
Position: &position.Position{
|
|
|
|
StartLine: 9,
|
|
|
|
EndLine: 9,
|
|
|
|
StartPos: 162,
|
|
|
|
EndPos: 185,
|
|
|
|
},
|
2018-06-25 12:38:31 +00:00
|
|
|
Comments: []*comment.Comment{
|
|
|
|
{
|
|
|
|
Position: &position.Position{
|
|
|
|
StartLine: 8,
|
|
|
|
EndLine: 8,
|
|
|
|
StartPos: 137,
|
|
|
|
EndPos: 158,
|
|
|
|
},
|
|
|
|
Value: "/** anonymous class */",
|
|
|
|
TokenName: 'O',
|
|
|
|
},
|
|
|
|
},
|
2018-01-13 01:40:08 +00:00
|
|
|
Class: &stmt.Class{
|
2018-06-24 07:19:44 +00:00
|
|
|
Position: &position.Position{
|
|
|
|
StartLine: 9,
|
|
|
|
EndLine: 9,
|
|
|
|
StartPos: 166,
|
|
|
|
EndPos: 185,
|
|
|
|
},
|
2018-01-13 01:40:08 +00:00
|
|
|
PhpDocComment: "/** anonymous class */",
|
2018-04-29 16:58:49 +00:00
|
|
|
ArgumentList: &node.ArgumentList{
|
2018-06-24 07:19:44 +00:00
|
|
|
Position: &position.Position{
|
|
|
|
StartLine: 9,
|
|
|
|
EndLine: 9,
|
|
|
|
StartPos: 172,
|
|
|
|
EndPos: 182,
|
|
|
|
},
|
2018-04-29 16:58:49 +00:00
|
|
|
Arguments: []node.Node{
|
2018-06-24 07:19:44 +00:00
|
|
|
&node.Argument{
|
|
|
|
Position: &position.Position{
|
|
|
|
StartLine: 9,
|
|
|
|
EndLine: 9,
|
|
|
|
StartPos: 173,
|
|
|
|
EndPos: 174,
|
|
|
|
},
|
|
|
|
Variadic: false,
|
|
|
|
IsReference: false,
|
|
|
|
Expr: &expr.Variable{
|
|
|
|
Position: &position.Position{
|
|
|
|
StartLine: 9,
|
|
|
|
EndLine: 9,
|
|
|
|
StartPos: 173,
|
|
|
|
EndPos: 174,
|
|
|
|
},
|
|
|
|
VarName: &node.Identifier{
|
|
|
|
Position: &position.Position{
|
|
|
|
StartLine: 9,
|
|
|
|
EndLine: 9,
|
|
|
|
StartPos: 173,
|
|
|
|
EndPos: 174,
|
|
|
|
},
|
|
|
|
Value: "a",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
&node.Argument{
|
|
|
|
Position: &position.Position{
|
|
|
|
StartLine: 9,
|
|
|
|
EndLine: 9,
|
|
|
|
StartPos: 177,
|
|
|
|
EndPos: 181,
|
|
|
|
},
|
|
|
|
Variadic: true,
|
|
|
|
IsReference: false,
|
|
|
|
Expr: &expr.Variable{
|
|
|
|
Position: &position.Position{
|
|
|
|
StartLine: 9,
|
|
|
|
EndLine: 9,
|
|
|
|
StartPos: 180,
|
|
|
|
EndPos: 181,
|
|
|
|
},
|
|
|
|
VarName: &node.Identifier{
|
|
|
|
Position: &position.Position{
|
|
|
|
StartLine: 9,
|
|
|
|
EndLine: 9,
|
|
|
|
StartPos: 180,
|
|
|
|
EndPos: 181,
|
|
|
|
},
|
|
|
|
Value: "b",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2018-04-29 16:58:49 +00:00
|
|
|
},
|
2018-01-13 01:40:08 +00:00
|
|
|
},
|
|
|
|
Stmts: []node.Node{},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
2018-04-10 12:23:13 +00:00
|
|
|
php7parser := php7.NewParser(bytes.NewBufferString(src), "test.php")
|
|
|
|
php7parser.Parse()
|
|
|
|
actual := php7parser.GetRootNode()
|
2018-02-08 10:48:38 +00:00
|
|
|
assertEqual(t, expected, actual)
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestPhp5ArgumentNode(t *testing.T) {
|
|
|
|
src := `<?
|
|
|
|
foo($a, ...$b);
|
|
|
|
$foo($a, ...$b);
|
|
|
|
$foo->bar($a, ...$b);
|
|
|
|
foo::bar($a, ...$b);
|
|
|
|
$foo::bar($a, ...$b);
|
|
|
|
new foo($a, ...$b);
|
|
|
|
`
|
|
|
|
|
2018-05-02 09:14:24 +00:00
|
|
|
expected := &node.Root{
|
2018-06-24 07:19:44 +00:00
|
|
|
Position: &position.Position{
|
|
|
|
StartLine: 2,
|
|
|
|
EndLine: 7,
|
|
|
|
StartPos: 7,
|
|
|
|
EndPos: 133,
|
|
|
|
},
|
2018-02-08 10:48:38 +00:00
|
|
|
Stmts: []node.Node{
|
|
|
|
&stmt.Expression{
|
2018-06-24 07:19:44 +00:00
|
|
|
Position: &position.Position{
|
|
|
|
StartLine: 2,
|
|
|
|
EndLine: 2,
|
|
|
|
StartPos: 7,
|
|
|
|
EndPos: 21,
|
|
|
|
},
|
2018-02-08 10:48:38 +00:00
|
|
|
Expr: &expr.FunctionCall{
|
2018-06-24 07:19:44 +00:00
|
|
|
Position: &position.Position{
|
|
|
|
StartLine: 2,
|
|
|
|
EndLine: 2,
|
|
|
|
StartPos: 7,
|
|
|
|
EndPos: 20,
|
|
|
|
},
|
|
|
|
Function: &name.Name{
|
|
|
|
Position: &position.Position{
|
|
|
|
StartLine: 2,
|
|
|
|
EndLine: 2,
|
|
|
|
StartPos: 7,
|
|
|
|
EndPos: 9,
|
|
|
|
},
|
|
|
|
Parts: []node.Node{
|
|
|
|
&name.NamePart{
|
|
|
|
Position: &position.Position{
|
|
|
|
StartLine: 2,
|
|
|
|
EndLine: 2,
|
|
|
|
StartPos: 7,
|
|
|
|
EndPos: 9,
|
|
|
|
},
|
|
|
|
Value: "foo",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2018-04-29 16:58:49 +00:00
|
|
|
ArgumentList: &node.ArgumentList{
|
2018-06-24 07:19:44 +00:00
|
|
|
Position: &position.Position{
|
|
|
|
StartLine: 2,
|
|
|
|
EndLine: 2,
|
|
|
|
StartPos: 10,
|
|
|
|
EndPos: 20,
|
|
|
|
},
|
2018-04-29 16:58:49 +00:00
|
|
|
Arguments: []node.Node{
|
2018-06-24 07:19:44 +00:00
|
|
|
&node.Argument{
|
|
|
|
Position: &position.Position{
|
|
|
|
StartLine: 2,
|
|
|
|
EndLine: 2,
|
|
|
|
StartPos: 11,
|
|
|
|
EndPos: 12,
|
|
|
|
},
|
|
|
|
Variadic: false,
|
|
|
|
IsReference: false,
|
|
|
|
Expr: &expr.Variable{
|
|
|
|
Position: &position.Position{
|
|
|
|
StartLine: 2,
|
|
|
|
EndLine: 2,
|
|
|
|
StartPos: 11,
|
|
|
|
EndPos: 12,
|
|
|
|
},
|
|
|
|
VarName: &node.Identifier{
|
|
|
|
Position: &position.Position{
|
|
|
|
StartLine: 2,
|
|
|
|
EndLine: 2,
|
|
|
|
StartPos: 11,
|
|
|
|
EndPos: 12,
|
|
|
|
},
|
|
|
|
Value: "a",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
&node.Argument{
|
|
|
|
Position: &position.Position{
|
|
|
|
StartLine: 2,
|
|
|
|
EndLine: 2,
|
|
|
|
StartPos: 15,
|
|
|
|
EndPos: 19,
|
|
|
|
},
|
|
|
|
Variadic: true,
|
|
|
|
IsReference: false,
|
|
|
|
Expr: &expr.Variable{
|
|
|
|
Position: &position.Position{
|
|
|
|
StartLine: 2,
|
|
|
|
EndLine: 2,
|
|
|
|
StartPos: 18,
|
|
|
|
EndPos: 19,
|
|
|
|
},
|
|
|
|
VarName: &node.Identifier{
|
|
|
|
Position: &position.Position{
|
|
|
|
StartLine: 2,
|
|
|
|
EndLine: 2,
|
|
|
|
StartPos: 18,
|
|
|
|
EndPos: 19,
|
|
|
|
},
|
|
|
|
Value: "b",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2018-04-29 16:58:49 +00:00
|
|
|
},
|
2018-02-08 10:48:38 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
&stmt.Expression{
|
2018-06-24 07:19:44 +00:00
|
|
|
Position: &position.Position{
|
|
|
|
StartLine: 3,
|
|
|
|
EndLine: 3,
|
|
|
|
StartPos: 25,
|
|
|
|
EndPos: 40,
|
|
|
|
},
|
2018-02-08 10:48:38 +00:00
|
|
|
Expr: &expr.FunctionCall{
|
2018-06-24 07:19:44 +00:00
|
|
|
Position: &position.Position{
|
|
|
|
StartLine: 3,
|
|
|
|
EndLine: 3,
|
|
|
|
StartPos: 25,
|
|
|
|
EndPos: 39,
|
|
|
|
},
|
|
|
|
Function: &expr.Variable{
|
|
|
|
Position: &position.Position{
|
|
|
|
StartLine: 3,
|
|
|
|
EndLine: 3,
|
|
|
|
StartPos: 25,
|
|
|
|
EndPos: 28,
|
|
|
|
},
|
|
|
|
VarName: &node.Identifier{
|
|
|
|
Position: &position.Position{
|
|
|
|
StartLine: 3,
|
|
|
|
EndLine: 3,
|
|
|
|
StartPos: 25,
|
|
|
|
EndPos: 28,
|
|
|
|
},
|
|
|
|
Value: "foo",
|
|
|
|
},
|
|
|
|
},
|
2018-04-29 16:58:49 +00:00
|
|
|
ArgumentList: &node.ArgumentList{
|
2018-06-24 07:19:44 +00:00
|
|
|
Position: &position.Position{
|
|
|
|
StartLine: 3,
|
|
|
|
EndLine: 3,
|
|
|
|
StartPos: 29,
|
|
|
|
EndPos: 39,
|
|
|
|
},
|
2018-04-29 16:58:49 +00:00
|
|
|
Arguments: []node.Node{
|
2018-06-24 07:19:44 +00:00
|
|
|
&node.Argument{
|
|
|
|
Position: &position.Position{
|
|
|
|
StartLine: 3,
|
|
|
|
EndLine: 3,
|
|
|
|
StartPos: 30,
|
|
|
|
EndPos: 31,
|
|
|
|
},
|
|
|
|
Variadic: false,
|
|
|
|
IsReference: false,
|
|
|
|
Expr: &expr.Variable{
|
|
|
|
Position: &position.Position{
|
|
|
|
StartLine: 3,
|
|
|
|
EndLine: 3,
|
|
|
|
StartPos: 30,
|
|
|
|
EndPos: 31,
|
|
|
|
},
|
|
|
|
VarName: &node.Identifier{
|
|
|
|
Position: &position.Position{
|
|
|
|
StartLine: 3,
|
|
|
|
EndLine: 3,
|
|
|
|
StartPos: 30,
|
|
|
|
EndPos: 31,
|
|
|
|
},
|
|
|
|
Value: "a",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
&node.Argument{
|
|
|
|
Position: &position.Position{
|
|
|
|
StartLine: 3,
|
|
|
|
EndLine: 3,
|
|
|
|
StartPos: 34,
|
|
|
|
EndPos: 38,
|
|
|
|
},
|
|
|
|
Variadic: true,
|
|
|
|
IsReference: false,
|
|
|
|
Expr: &expr.Variable{
|
|
|
|
Position: &position.Position{
|
|
|
|
StartLine: 3,
|
|
|
|
EndLine: 3,
|
|
|
|
StartPos: 37,
|
|
|
|
EndPos: 38,
|
|
|
|
},
|
|
|
|
VarName: &node.Identifier{
|
|
|
|
Position: &position.Position{
|
|
|
|
StartLine: 3,
|
|
|
|
EndLine: 3,
|
|
|
|
StartPos: 37,
|
|
|
|
EndPos: 38,
|
|
|
|
},
|
|
|
|
Value: "b",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2018-04-29 16:58:49 +00:00
|
|
|
},
|
2018-02-08 10:48:38 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
&stmt.Expression{
|
2018-06-24 07:19:44 +00:00
|
|
|
Position: &position.Position{
|
|
|
|
StartLine: 4,
|
|
|
|
EndLine: 4,
|
|
|
|
StartPos: 44,
|
|
|
|
EndPos: 64,
|
|
|
|
},
|
2018-02-08 10:48:38 +00:00
|
|
|
Expr: &expr.MethodCall{
|
2018-06-24 07:19:44 +00:00
|
|
|
Position: &position.Position{
|
|
|
|
StartLine: 4,
|
|
|
|
EndLine: 4,
|
|
|
|
StartPos: 44,
|
|
|
|
EndPos: 63,
|
|
|
|
},
|
|
|
|
Variable: &expr.Variable{
|
|
|
|
Position: &position.Position{
|
|
|
|
StartLine: 4,
|
|
|
|
EndLine: 4,
|
|
|
|
StartPos: 44,
|
|
|
|
EndPos: 47,
|
|
|
|
},
|
|
|
|
VarName: &node.Identifier{
|
|
|
|
Position: &position.Position{
|
|
|
|
StartLine: 4,
|
|
|
|
EndLine: 4,
|
|
|
|
StartPos: 44,
|
|
|
|
EndPos: 47,
|
|
|
|
},
|
|
|
|
Value: "foo",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Method: &node.Identifier{
|
|
|
|
Position: &position.Position{
|
|
|
|
StartLine: 4,
|
|
|
|
EndLine: 4,
|
|
|
|
StartPos: 50,
|
|
|
|
EndPos: 52,
|
|
|
|
},
|
|
|
|
Value: "bar",
|
|
|
|
},
|
2018-04-29 16:58:49 +00:00
|
|
|
ArgumentList: &node.ArgumentList{
|
2018-06-24 07:19:44 +00:00
|
|
|
Position: &position.Position{
|
|
|
|
StartLine: 4,
|
|
|
|
EndLine: 4,
|
|
|
|
StartPos: 53,
|
|
|
|
EndPos: 63,
|
|
|
|
},
|
2018-04-29 16:58:49 +00:00
|
|
|
Arguments: []node.Node{
|
2018-06-24 07:19:44 +00:00
|
|
|
&node.Argument{
|
|
|
|
Position: &position.Position{
|
|
|
|
StartLine: 4,
|
|
|
|
EndLine: 4,
|
|
|
|
StartPos: 54,
|
|
|
|
EndPos: 55,
|
|
|
|
},
|
|
|
|
Variadic: false,
|
|
|
|
IsReference: false,
|
|
|
|
Expr: &expr.Variable{
|
|
|
|
Position: &position.Position{
|
|
|
|
StartLine: 4,
|
|
|
|
EndLine: 4,
|
|
|
|
StartPos: 54,
|
|
|
|
EndPos: 55,
|
|
|
|
},
|
|
|
|
VarName: &node.Identifier{
|
|
|
|
Position: &position.Position{
|
|
|
|
StartLine: 4,
|
|
|
|
EndLine: 4,
|
|
|
|
StartPos: 54,
|
|
|
|
EndPos: 55,
|
|
|
|
},
|
|
|
|
Value: "a",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
&node.Argument{
|
|
|
|
Position: &position.Position{
|
|
|
|
StartLine: 4,
|
|
|
|
EndLine: 4,
|
|
|
|
StartPos: 58,
|
|
|
|
EndPos: 62,
|
|
|
|
},
|
|
|
|
IsReference: false,
|
|
|
|
Variadic: true,
|
|
|
|
Expr: &expr.Variable{
|
|
|
|
Position: &position.Position{
|
|
|
|
StartLine: 4,
|
|
|
|
EndLine: 4,
|
|
|
|
StartPos: 61,
|
|
|
|
EndPos: 62,
|
|
|
|
},
|
|
|
|
VarName: &node.Identifier{
|
|
|
|
Position: &position.Position{
|
|
|
|
StartLine: 4,
|
|
|
|
EndLine: 4,
|
|
|
|
StartPos: 61,
|
|
|
|
EndPos: 62,
|
|
|
|
},
|
|
|
|
Value: "b",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2018-04-29 16:58:49 +00:00
|
|
|
},
|
2018-02-08 10:48:38 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
&stmt.Expression{
|
2018-06-24 07:19:44 +00:00
|
|
|
Position: &position.Position{
|
|
|
|
StartLine: 5,
|
|
|
|
EndLine: 5,
|
|
|
|
StartPos: 68,
|
|
|
|
EndPos: 87,
|
|
|
|
},
|
2018-02-08 10:48:38 +00:00
|
|
|
Expr: &expr.StaticCall{
|
2018-06-24 07:19:44 +00:00
|
|
|
Position: &position.Position{
|
|
|
|
StartLine: 5,
|
|
|
|
EndLine: 5,
|
|
|
|
StartPos: 68,
|
|
|
|
EndPos: 86,
|
|
|
|
},
|
|
|
|
Class: &name.Name{
|
|
|
|
Position: &position.Position{
|
|
|
|
StartLine: 5,
|
|
|
|
EndLine: 5,
|
|
|
|
StartPos: 68,
|
|
|
|
EndPos: 70,
|
|
|
|
},
|
|
|
|
Parts: []node.Node{
|
|
|
|
&name.NamePart{
|
|
|
|
Position: &position.Position{
|
|
|
|
StartLine: 5,
|
|
|
|
EndLine: 5,
|
|
|
|
StartPos: 68,
|
|
|
|
EndPos: 70,
|
|
|
|
},
|
|
|
|
Value: "foo",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Call: &node.Identifier{
|
|
|
|
Position: &position.Position{
|
|
|
|
StartLine: 5,
|
|
|
|
EndLine: 5,
|
|
|
|
StartPos: 73,
|
|
|
|
EndPos: 75,
|
|
|
|
},
|
|
|
|
Value: "bar",
|
|
|
|
},
|
2018-04-29 16:58:49 +00:00
|
|
|
ArgumentList: &node.ArgumentList{
|
2018-06-24 07:19:44 +00:00
|
|
|
Position: &position.Position{
|
|
|
|
StartLine: 5,
|
|
|
|
EndLine: 5,
|
|
|
|
StartPos: 76,
|
|
|
|
EndPos: 86,
|
|
|
|
},
|
2018-04-29 16:58:49 +00:00
|
|
|
Arguments: []node.Node{
|
2018-06-24 07:19:44 +00:00
|
|
|
&node.Argument{
|
|
|
|
Position: &position.Position{
|
|
|
|
StartLine: 5,
|
|
|
|
EndLine: 5,
|
|
|
|
StartPos: 77,
|
|
|
|
EndPos: 78,
|
|
|
|
},
|
|
|
|
Variadic: false,
|
|
|
|
IsReference: false,
|
|
|
|
Expr: &expr.Variable{
|
|
|
|
Position: &position.Position{
|
|
|
|
StartLine: 5,
|
|
|
|
EndLine: 5,
|
|
|
|
StartPos: 77,
|
|
|
|
EndPos: 78,
|
|
|
|
},
|
|
|
|
VarName: &node.Identifier{
|
|
|
|
Position: &position.Position{
|
|
|
|
StartLine: 5,
|
|
|
|
EndLine: 5,
|
|
|
|
StartPos: 77,
|
|
|
|
EndPos: 78,
|
|
|
|
},
|
|
|
|
Value: "a",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
&node.Argument{
|
|
|
|
Position: &position.Position{
|
|
|
|
StartLine: 5,
|
|
|
|
EndLine: 5,
|
|
|
|
StartPos: 81,
|
|
|
|
EndPos: 85,
|
|
|
|
},
|
|
|
|
Variadic: true,
|
|
|
|
IsReference: false,
|
|
|
|
Expr: &expr.Variable{
|
|
|
|
Position: &position.Position{
|
|
|
|
StartLine: 5,
|
|
|
|
EndLine: 5,
|
|
|
|
StartPos: 84,
|
|
|
|
EndPos: 85,
|
|
|
|
},
|
|
|
|
VarName: &node.Identifier{
|
|
|
|
Position: &position.Position{
|
|
|
|
StartLine: 5,
|
|
|
|
EndLine: 5,
|
|
|
|
StartPos: 84,
|
|
|
|
EndPos: 85,
|
|
|
|
},
|
|
|
|
Value: "b",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2018-04-29 16:58:49 +00:00
|
|
|
},
|
2018-02-08 10:48:38 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
&stmt.Expression{
|
2018-06-24 07:19:44 +00:00
|
|
|
Position: &position.Position{
|
|
|
|
StartLine: 6,
|
|
|
|
EndLine: 6,
|
|
|
|
StartPos: 91,
|
|
|
|
EndPos: 111,
|
|
|
|
},
|
2018-02-08 10:48:38 +00:00
|
|
|
Expr: &expr.StaticCall{
|
2018-06-24 07:19:44 +00:00
|
|
|
Position: &position.Position{
|
|
|
|
StartLine: 6,
|
|
|
|
EndLine: 6,
|
|
|
|
StartPos: 91,
|
|
|
|
EndPos: 110,
|
|
|
|
},
|
|
|
|
Class: &expr.Variable{
|
|
|
|
Position: &position.Position{
|
|
|
|
StartLine: 6,
|
|
|
|
EndLine: 6,
|
|
|
|
StartPos: 91,
|
|
|
|
EndPos: 94,
|
|
|
|
},
|
|
|
|
VarName: &node.Identifier{
|
|
|
|
Position: &position.Position{
|
|
|
|
StartLine: 6,
|
|
|
|
EndLine: 6,
|
|
|
|
StartPos: 91,
|
|
|
|
EndPos: 94,
|
|
|
|
},
|
|
|
|
Value: "foo",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Call: &node.Identifier{
|
|
|
|
Position: &position.Position{
|
|
|
|
StartLine: 6,
|
|
|
|
EndLine: 6,
|
|
|
|
StartPos: 97,
|
|
|
|
EndPos: 99,
|
|
|
|
},
|
|
|
|
Value: "bar",
|
|
|
|
},
|
2018-04-29 16:58:49 +00:00
|
|
|
ArgumentList: &node.ArgumentList{
|
2018-06-24 07:19:44 +00:00
|
|
|
Position: &position.Position{
|
|
|
|
StartLine: 6,
|
|
|
|
EndLine: 6,
|
|
|
|
StartPos: 100,
|
|
|
|
EndPos: 110,
|
|
|
|
},
|
2018-04-29 16:58:49 +00:00
|
|
|
Arguments: []node.Node{
|
2018-06-24 07:19:44 +00:00
|
|
|
&node.Argument{
|
|
|
|
Position: &position.Position{
|
|
|
|
StartLine: 6,
|
|
|
|
EndLine: 6,
|
|
|
|
StartPos: 101,
|
|
|
|
EndPos: 102,
|
|
|
|
},
|
|
|
|
Variadic: false,
|
|
|
|
IsReference: false,
|
|
|
|
Expr: &expr.Variable{
|
|
|
|
Position: &position.Position{
|
|
|
|
StartLine: 6,
|
|
|
|
EndLine: 6,
|
|
|
|
StartPos: 101,
|
|
|
|
EndPos: 102,
|
|
|
|
},
|
|
|
|
VarName: &node.Identifier{
|
|
|
|
Position: &position.Position{
|
|
|
|
StartLine: 6,
|
|
|
|
EndLine: 6,
|
|
|
|
StartPos: 101,
|
|
|
|
EndPos: 102,
|
|
|
|
},
|
|
|
|
Value: "a",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
&node.Argument{
|
|
|
|
Position: &position.Position{
|
|
|
|
StartLine: 6,
|
|
|
|
EndLine: 6,
|
|
|
|
StartPos: 105,
|
|
|
|
EndPos: 109,
|
|
|
|
},
|
|
|
|
Variadic: true,
|
|
|
|
IsReference: false,
|
|
|
|
Expr: &expr.Variable{
|
|
|
|
Position: &position.Position{
|
|
|
|
StartLine: 6,
|
|
|
|
EndLine: 6,
|
|
|
|
StartPos: 108,
|
|
|
|
EndPos: 109,
|
|
|
|
},
|
|
|
|
VarName: &node.Identifier{
|
|
|
|
Position: &position.Position{
|
|
|
|
StartLine: 6,
|
|
|
|
EndLine: 6,
|
|
|
|
StartPos: 108,
|
|
|
|
EndPos: 109,
|
|
|
|
},
|
|
|
|
Value: "b",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2018-04-29 16:58:49 +00:00
|
|
|
},
|
2018-02-08 10:48:38 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
&stmt.Expression{
|
2018-06-24 07:19:44 +00:00
|
|
|
Position: &position.Position{
|
|
|
|
StartLine: 7,
|
|
|
|
EndLine: 7,
|
|
|
|
StartPos: 115,
|
|
|
|
EndPos: 133,
|
|
|
|
},
|
2018-02-08 10:48:38 +00:00
|
|
|
Expr: &expr.New{
|
2018-06-24 07:19:44 +00:00
|
|
|
Position: &position.Position{
|
|
|
|
StartLine: 7,
|
|
|
|
EndLine: 7,
|
|
|
|
StartPos: 115,
|
|
|
|
EndPos: 132,
|
|
|
|
},
|
|
|
|
Class: &name.Name{
|
|
|
|
Position: &position.Position{
|
|
|
|
StartLine: 7,
|
|
|
|
EndLine: 7,
|
|
|
|
StartPos: 119,
|
|
|
|
EndPos: 121,
|
|
|
|
},
|
|
|
|
Parts: []node.Node{
|
|
|
|
&name.NamePart{
|
|
|
|
Position: &position.Position{
|
|
|
|
StartLine: 7,
|
|
|
|
EndLine: 7,
|
|
|
|
StartPos: 119,
|
|
|
|
EndPos: 121,
|
|
|
|
},
|
|
|
|
Value: "foo",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2018-04-29 16:58:49 +00:00
|
|
|
ArgumentList: &node.ArgumentList{
|
2018-06-24 07:19:44 +00:00
|
|
|
Position: &position.Position{
|
|
|
|
StartLine: 7,
|
|
|
|
EndLine: 7,
|
|
|
|
StartPos: 122,
|
|
|
|
EndPos: 132,
|
|
|
|
},
|
2018-04-29 16:58:49 +00:00
|
|
|
Arguments: []node.Node{
|
2018-06-24 07:19:44 +00:00
|
|
|
&node.Argument{
|
|
|
|
Position: &position.Position{
|
|
|
|
StartLine: 7,
|
|
|
|
EndLine: 7,
|
|
|
|
StartPos: 123,
|
|
|
|
EndPos: 124,
|
|
|
|
},
|
|
|
|
Variadic: false,
|
|
|
|
IsReference: false,
|
|
|
|
Expr: &expr.Variable{
|
|
|
|
Position: &position.Position{
|
|
|
|
StartLine: 7,
|
|
|
|
EndLine: 7,
|
|
|
|
StartPos: 123,
|
|
|
|
EndPos: 124,
|
|
|
|
},
|
|
|
|
VarName: &node.Identifier{
|
|
|
|
Position: &position.Position{
|
|
|
|
StartLine: 7,
|
|
|
|
EndLine: 7,
|
|
|
|
StartPos: 123,
|
|
|
|
EndPos: 124,
|
|
|
|
},
|
|
|
|
Value: "a",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
&node.Argument{
|
|
|
|
Position: &position.Position{
|
|
|
|
StartLine: 7,
|
|
|
|
EndLine: 7,
|
|
|
|
StartPos: 127,
|
|
|
|
EndPos: 131,
|
|
|
|
},
|
|
|
|
Variadic: true,
|
|
|
|
IsReference: false,
|
|
|
|
Expr: &expr.Variable{
|
|
|
|
Position: &position.Position{
|
|
|
|
StartLine: 7,
|
|
|
|
EndLine: 7,
|
|
|
|
StartPos: 130,
|
|
|
|
EndPos: 131,
|
|
|
|
},
|
|
|
|
VarName: &node.Identifier{
|
|
|
|
Position: &position.Position{
|
|
|
|
StartLine: 7,
|
|
|
|
EndLine: 7,
|
|
|
|
StartPos: 130,
|
|
|
|
EndPos: 131,
|
|
|
|
},
|
|
|
|
Value: "b",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2018-04-29 16:58:49 +00:00
|
|
|
},
|
2018-02-08 10:48:38 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
2018-01-13 01:40:08 +00:00
|
|
|
|
2018-04-10 12:23:13 +00:00
|
|
|
php5parser := php5.NewParser(bytes.NewBufferString(src), "test.php")
|
|
|
|
php5parser.Parse()
|
|
|
|
actual := php5parser.GetRootNode()
|
2018-01-13 01:40:08 +00:00
|
|
|
assertEqual(t, expected, actual)
|
|
|
|
}
|
2018-02-08 10:48:38 +00:00
|
|
|
|
|
|
|
func TestPhp7ParameterNode(t *testing.T) {
|
2018-01-13 01:40:08 +00:00
|
|
|
src := `<?
|
|
|
|
function foo(?bar $bar=null, baz &...$baz) {}
|
|
|
|
class foo {public function foo(?bar $bar=null, baz &...$baz) {}}
|
|
|
|
function(?bar $bar=null, baz &...$baz) {};
|
|
|
|
static function(?bar $bar=null, baz &...$baz) {};
|
|
|
|
`
|
|
|
|
|
2018-05-02 09:14:24 +00:00
|
|
|
expected := &node.Root{
|
2018-06-24 07:19:44 +00:00
|
|
|
Position: &position.Position{
|
|
|
|
StartLine: 2,
|
|
|
|
EndLine: 5,
|
|
|
|
StartPos: 7,
|
|
|
|
EndPos: 215,
|
|
|
|
},
|
2018-01-13 01:40:08 +00:00
|
|
|
Stmts: []node.Node{
|
|
|
|
&stmt.Function{
|
2018-06-24 07:19:44 +00:00
|
|
|
Position: &position.Position{
|
|
|
|
StartLine: 2,
|
|
|
|
EndLine: 2,
|
|
|
|
StartPos: 7,
|
|
|
|
EndPos: 51,
|
|
|
|
},
|
2018-01-13 01:40:08 +00:00
|
|
|
ReturnsRef: false,
|
|
|
|
PhpDocComment: "",
|
2018-06-24 07:19:44 +00:00
|
|
|
FunctionName: &node.Identifier{
|
|
|
|
Position: &position.Position{
|
|
|
|
StartLine: 2,
|
|
|
|
EndLine: 2,
|
|
|
|
StartPos: 16,
|
|
|
|
EndPos: 18,
|
|
|
|
},
|
|
|
|
Value: "foo",
|
|
|
|
},
|
|
|
|
Params: []node.Node{
|
|
|
|
&node.Parameter{
|
|
|
|
Position: &position.Position{
|
|
|
|
StartLine: 2,
|
|
|
|
EndLine: 2,
|
|
|
|
StartPos: 20,
|
|
|
|
EndPos: 33,
|
|
|
|
},
|
|
|
|
ByRef: false,
|
|
|
|
Variadic: false,
|
|
|
|
VariableType: &node.Nullable{
|
|
|
|
Position: &position.Position{
|
|
|
|
StartLine: 2,
|
|
|
|
EndLine: 2,
|
|
|
|
StartPos: 20,
|
|
|
|
EndPos: 23,
|
|
|
|
},
|
|
|
|
Expr: &name.Name{
|
|
|
|
Position: &position.Position{
|
|
|
|
StartLine: 2,
|
|
|
|
EndLine: 2,
|
|
|
|
StartPos: 21,
|
|
|
|
EndPos: 23,
|
|
|
|
},
|
|
|
|
Parts: []node.Node{
|
|
|
|
&name.NamePart{
|
|
|
|
Position: &position.Position{
|
|
|
|
StartLine: 2,
|
|
|
|
EndLine: 2,
|
|
|
|
StartPos: 21,
|
|
|
|
EndPos: 23,
|
|
|
|
},
|
|
|
|
Value: "bar",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Variable: &expr.Variable{
|
|
|
|
Position: &position.Position{
|
|
|
|
StartLine: 2,
|
|
|
|
EndLine: 2,
|
|
|
|
StartPos: 25,
|
|
|
|
EndPos: 28,
|
|
|
|
},
|
|
|
|
VarName: &node.Identifier{
|
|
|
|
Position: &position.Position{
|
|
|
|
StartLine: 2,
|
|
|
|
EndLine: 2,
|
|
|
|
StartPos: 25,
|
|
|
|
EndPos: 28,
|
|
|
|
},
|
|
|
|
Value: "bar",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
DefaultValue: &expr.ConstFetch{
|
|
|
|
Position: &position.Position{
|
|
|
|
StartLine: 2,
|
|
|
|
EndLine: 2,
|
|
|
|
StartPos: 30,
|
|
|
|
EndPos: 33,
|
|
|
|
},
|
|
|
|
Constant: &name.Name{
|
|
|
|
Position: &position.Position{
|
|
|
|
StartLine: 2,
|
|
|
|
EndLine: 2,
|
|
|
|
StartPos: 30,
|
|
|
|
EndPos: 33,
|
|
|
|
},
|
|
|
|
Parts: []node.Node{
|
|
|
|
&name.NamePart{
|
|
|
|
Position: &position.Position{
|
|
|
|
StartLine: 2,
|
|
|
|
EndLine: 2,
|
|
|
|
StartPos: 30,
|
|
|
|
EndPos: 33,
|
|
|
|
},
|
|
|
|
Value: "null",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
&node.Parameter{
|
|
|
|
Position: &position.Position{
|
|
|
|
StartLine: 2,
|
|
|
|
EndLine: 2,
|
|
|
|
StartPos: 36,
|
|
|
|
EndPos: 47,
|
|
|
|
},
|
|
|
|
ByRef: true,
|
|
|
|
Variadic: true,
|
|
|
|
VariableType: &name.Name{
|
|
|
|
Position: &position.Position{
|
|
|
|
StartLine: 2,
|
|
|
|
EndLine: 2,
|
|
|
|
StartPos: 36,
|
|
|
|
EndPos: 38,
|
|
|
|
},
|
|
|
|
Parts: []node.Node{
|
|
|
|
&name.NamePart{
|
|
|
|
Position: &position.Position{
|
|
|
|
StartLine: 2,
|
|
|
|
EndLine: 2,
|
|
|
|
StartPos: 36,
|
|
|
|
EndPos: 38,
|
|
|
|
},
|
|
|
|
Value: "baz",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Variable: &expr.Variable{
|
|
|
|
Position: &position.Position{
|
|
|
|
StartLine: 2,
|
|
|
|
EndLine: 2,
|
|
|
|
StartPos: 44,
|
|
|
|
EndPos: 47,
|
|
|
|
},
|
|
|
|
VarName: &node.Identifier{
|
|
|
|
Position: &position.Position{
|
|
|
|
StartLine: 2,
|
|
|
|
EndLine: 2,
|
|
|
|
StartPos: 44,
|
|
|
|
EndPos: 47,
|
|
|
|
},
|
|
|
|
Value: "baz",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Stmts: []node.Node{},
|
2018-01-13 01:40:08 +00:00
|
|
|
},
|
|
|
|
&stmt.Class{
|
2018-06-24 07:19:44 +00:00
|
|
|
Position: &position.Position{
|
|
|
|
StartLine: 3,
|
|
|
|
EndLine: 3,
|
|
|
|
StartPos: 55,
|
|
|
|
EndPos: 118,
|
|
|
|
},
|
|
|
|
PhpDocComment: "",
|
|
|
|
ClassName: &node.Identifier{
|
|
|
|
Position: &position.Position{
|
|
|
|
StartLine: 3,
|
|
|
|
EndLine: 3,
|
|
|
|
StartPos: 61,
|
|
|
|
EndPos: 63,
|
|
|
|
},
|
|
|
|
Value: "foo",
|
|
|
|
},
|
2018-01-13 01:40:08 +00:00
|
|
|
Stmts: []node.Node{
|
|
|
|
&stmt.ClassMethod{
|
2018-06-24 07:19:44 +00:00
|
|
|
Position: &position.Position{
|
|
|
|
StartLine: 3,
|
|
|
|
EndLine: 3,
|
|
|
|
StartPos: 66,
|
|
|
|
EndPos: 117,
|
|
|
|
},
|
|
|
|
PhpDocComment: "",
|
|
|
|
ReturnsRef: false,
|
|
|
|
MethodName: &node.Identifier{
|
|
|
|
Position: &position.Position{
|
|
|
|
StartLine: 3,
|
|
|
|
EndLine: 3,
|
|
|
|
StartPos: 82,
|
|
|
|
EndPos: 84,
|
|
|
|
},
|
|
|
|
Value: "foo",
|
|
|
|
},
|
|
|
|
Modifiers: []node.Node{
|
|
|
|
&node.Identifier{
|
|
|
|
Position: &position.Position{
|
|
|
|
StartLine: 3,
|
|
|
|
EndLine: 3,
|
|
|
|
StartPos: 66,
|
|
|
|
EndPos: 71,
|
|
|
|
},
|
|
|
|
Value: "public",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Params: []node.Node{
|
|
|
|
&node.Parameter{
|
|
|
|
Position: &position.Position{
|
|
|
|
StartLine: 3,
|
|
|
|
EndLine: 3,
|
|
|
|
StartPos: 86,
|
|
|
|
EndPos: 99,
|
|
|
|
},
|
|
|
|
ByRef: false,
|
|
|
|
Variadic: false,
|
|
|
|
VariableType: &node.Nullable{
|
|
|
|
Position: &position.Position{
|
|
|
|
StartLine: 3,
|
|
|
|
EndLine: 3,
|
|
|
|
StartPos: 86,
|
|
|
|
EndPos: 89,
|
|
|
|
},
|
|
|
|
Expr: &name.Name{
|
|
|
|
Position: &position.Position{
|
|
|
|
StartLine: 3,
|
|
|
|
EndLine: 3,
|
|
|
|
StartPos: 87,
|
|
|
|
EndPos: 89,
|
|
|
|
},
|
|
|
|
Parts: []node.Node{
|
|
|
|
&name.NamePart{
|
|
|
|
Position: &position.Position{
|
|
|
|
StartLine: 3,
|
|
|
|
EndLine: 3,
|
|
|
|
StartPos: 87,
|
|
|
|
EndPos: 89,
|
|
|
|
},
|
|
|
|
Value: "bar",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Variable: &expr.Variable{
|
|
|
|
Position: &position.Position{
|
|
|
|
StartLine: 3,
|
|
|
|
EndLine: 3,
|
|
|
|
StartPos: 91,
|
|
|
|
EndPos: 94,
|
|
|
|
},
|
|
|
|
VarName: &node.Identifier{
|
|
|
|
Position: &position.Position{
|
|
|
|
StartLine: 3,
|
|
|
|
EndLine: 3,
|
|
|
|
StartPos: 91,
|
|
|
|
EndPos: 94,
|
|
|
|
},
|
|
|
|
Value: "bar",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
DefaultValue: &expr.ConstFetch{
|
|
|
|
Position: &position.Position{
|
|
|
|
StartLine: 3,
|
|
|
|
EndLine: 3,
|
|
|
|
StartPos: 96,
|
|
|
|
EndPos: 99,
|
|
|
|
},
|
|
|
|
Constant: &name.Name{
|
|
|
|
Position: &position.Position{
|
|
|
|
StartLine: 3,
|
|
|
|
EndLine: 3,
|
|
|
|
StartPos: 96,
|
|
|
|
EndPos: 99,
|
|
|
|
},
|
|
|
|
Parts: []node.Node{
|
|
|
|
&name.NamePart{
|
|
|
|
Position: &position.Position{
|
|
|
|
StartLine: 3,
|
|
|
|
EndLine: 3,
|
|
|
|
StartPos: 96,
|
|
|
|
EndPos: 99,
|
|
|
|
},
|
|
|
|
Value: "null",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
&node.Parameter{
|
|
|
|
Position: &position.Position{
|
|
|
|
StartLine: 3,
|
|
|
|
EndLine: 3,
|
|
|
|
StartPos: 102,
|
|
|
|
EndPos: 113,
|
|
|
|
},
|
|
|
|
ByRef: true,
|
|
|
|
Variadic: true,
|
|
|
|
VariableType: &name.Name{
|
|
|
|
Position: &position.Position{
|
|
|
|
StartLine: 3,
|
|
|
|
EndLine: 3,
|
|
|
|
StartPos: 102,
|
|
|
|
EndPos: 104,
|
|
|
|
},
|
|
|
|
Parts: []node.Node{
|
|
|
|
&name.NamePart{
|
|
|
|
Position: &position.Position{
|
|
|
|
StartLine: 3,
|
|
|
|
EndLine: 3,
|
|
|
|
StartPos: 102,
|
|
|
|
EndPos: 104,
|
|
|
|
},
|
|
|
|
Value: "baz",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Variable: &expr.Variable{
|
|
|
|
Position: &position.Position{
|
|
|
|
StartLine: 3,
|
|
|
|
EndLine: 3,
|
|
|
|
StartPos: 110,
|
|
|
|
EndPos: 113,
|
|
|
|
},
|
|
|
|
VarName: &node.Identifier{
|
|
|
|
Position: &position.Position{
|
|
|
|
StartLine: 3,
|
|
|
|
EndLine: 3,
|
|
|
|
StartPos: 110,
|
|
|
|
EndPos: 113,
|
|
|
|
},
|
|
|
|
Value: "baz",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2018-06-03 06:35:44 +00:00
|
|
|
Stmt: &stmt.StmtList{
|
2018-06-24 07:19:44 +00:00
|
|
|
Position: &position.Position{
|
|
|
|
StartLine: 3,
|
|
|
|
EndLine: 3,
|
|
|
|
StartPos: 116,
|
|
|
|
EndPos: 117,
|
|
|
|
},
|
2018-06-03 06:35:44 +00:00
|
|
|
Stmts: []node.Node{},
|
|
|
|
},
|
2018-01-13 01:40:08 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
&stmt.Expression{
|
2018-06-24 07:19:44 +00:00
|
|
|
Position: &position.Position{
|
|
|
|
StartLine: 4,
|
|
|
|
EndLine: 4,
|
|
|
|
StartPos: 122,
|
|
|
|
EndPos: 163,
|
|
|
|
},
|
2018-01-13 01:40:08 +00:00
|
|
|
Expr: &expr.Closure{
|
2018-06-24 07:19:44 +00:00
|
|
|
Position: &position.Position{
|
|
|
|
StartLine: 4,
|
|
|
|
EndLine: 4,
|
|
|
|
StartPos: 122,
|
|
|
|
EndPos: 162,
|
|
|
|
},
|
|
|
|
ReturnsRef: false,
|
|
|
|
Static: false,
|
|
|
|
PhpDocComment: "",
|
|
|
|
Params: []node.Node{
|
|
|
|
&node.Parameter{
|
|
|
|
Position: &position.Position{
|
|
|
|
StartLine: 4,
|
|
|
|
EndLine: 4,
|
|
|
|
StartPos: 131,
|
|
|
|
EndPos: 144,
|
|
|
|
},
|
|
|
|
ByRef: false,
|
|
|
|
Variadic: false,
|
|
|
|
VariableType: &node.Nullable{
|
|
|
|
Position: &position.Position{
|
|
|
|
StartLine: 4,
|
|
|
|
EndLine: 4,
|
|
|
|
StartPos: 131,
|
|
|
|
EndPos: 134,
|
|
|
|
},
|
|
|
|
Expr: &name.Name{
|
|
|
|
Position: &position.Position{
|
|
|
|
StartLine: 4,
|
|
|
|
EndLine: 4,
|
|
|
|
StartPos: 132,
|
|
|
|
EndPos: 134,
|
|
|
|
},
|
|
|
|
Parts: []node.Node{
|
|
|
|
&name.NamePart{
|
|
|
|
Position: &position.Position{
|
|
|
|
StartLine: 4,
|
|
|
|
EndLine: 4,
|
|
|
|
StartPos: 132,
|
|
|
|
EndPos: 134,
|
|
|
|
},
|
|
|
|
Value: "bar",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Variable: &expr.Variable{
|
|
|
|
Position: &position.Position{
|
|
|
|
StartLine: 4,
|
|
|
|
EndLine: 4,
|
|
|
|
StartPos: 136,
|
|
|
|
EndPos: 139,
|
|
|
|
},
|
|
|
|
VarName: &node.Identifier{
|
|
|
|
Position: &position.Position{
|
|
|
|
StartLine: 4,
|
|
|
|
EndLine: 4,
|
|
|
|
StartPos: 136,
|
|
|
|
EndPos: 139,
|
|
|
|
},
|
|
|
|
Value: "bar",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
DefaultValue: &expr.ConstFetch{
|
|
|
|
Position: &position.Position{
|
|
|
|
StartLine: 4,
|
|
|
|
EndLine: 4,
|
|
|
|
StartPos: 141,
|
|
|
|
EndPos: 144,
|
|
|
|
},
|
|
|
|
Constant: &name.Name{
|
|
|
|
Position: &position.Position{
|
|
|
|
StartLine: 4,
|
|
|
|
EndLine: 4,
|
|
|
|
StartPos: 141,
|
|
|
|
EndPos: 144,
|
|
|
|
},
|
|
|
|
Parts: []node.Node{
|
|
|
|
&name.NamePart{
|
|
|
|
Position: &position.Position{
|
|
|
|
StartLine: 4,
|
|
|
|
EndLine: 4,
|
|
|
|
StartPos: 141,
|
|
|
|
EndPos: 144,
|
|
|
|
},
|
|
|
|
Value: "null",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
&node.Parameter{
|
|
|
|
Position: &position.Position{
|
|
|
|
StartLine: 4,
|
|
|
|
EndLine: 4,
|
|
|
|
StartPos: 147,
|
|
|
|
EndPos: 158,
|
|
|
|
},
|
|
|
|
Variadic: true,
|
|
|
|
ByRef: true,
|
|
|
|
VariableType: &name.Name{
|
|
|
|
Position: &position.Position{
|
|
|
|
StartLine: 4,
|
|
|
|
EndLine: 4,
|
|
|
|
StartPos: 147,
|
|
|
|
EndPos: 149,
|
|
|
|
},
|
|
|
|
Parts: []node.Node{
|
|
|
|
&name.NamePart{
|
|
|
|
Position: &position.Position{
|
|
|
|
StartLine: 4,
|
|
|
|
EndLine: 4,
|
|
|
|
StartPos: 147,
|
|
|
|
EndPos: 149,
|
|
|
|
},
|
|
|
|
Value: "baz",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Variable: &expr.Variable{
|
|
|
|
Position: &position.Position{
|
|
|
|
StartLine: 4,
|
|
|
|
EndLine: 4,
|
|
|
|
StartPos: 155,
|
|
|
|
EndPos: 158,
|
|
|
|
},
|
|
|
|
VarName: &node.Identifier{
|
|
|
|
Position: &position.Position{
|
|
|
|
StartLine: 4,
|
|
|
|
EndLine: 4,
|
|
|
|
StartPos: 155,
|
|
|
|
EndPos: 158,
|
|
|
|
},
|
|
|
|
Value: "baz",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Stmts: []node.Node{},
|
2018-01-13 01:40:08 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
&stmt.Expression{
|
2018-06-24 07:19:44 +00:00
|
|
|
Position: &position.Position{
|
|
|
|
StartLine: 5,
|
|
|
|
EndLine: 5,
|
|
|
|
StartPos: 167,
|
|
|
|
EndPos: 215,
|
|
|
|
},
|
2018-01-13 01:40:08 +00:00
|
|
|
Expr: &expr.Closure{
|
2018-06-24 07:19:44 +00:00
|
|
|
Position: &position.Position{
|
|
|
|
StartLine: 5,
|
|
|
|
EndLine: 5,
|
|
|
|
StartPos: 167,
|
|
|
|
EndPos: 214,
|
|
|
|
},
|
|
|
|
Static: true,
|
|
|
|
PhpDocComment: "",
|
|
|
|
ReturnsRef: false,
|
|
|
|
Params: []node.Node{
|
|
|
|
&node.Parameter{
|
|
|
|
Position: &position.Position{
|
|
|
|
StartLine: 5,
|
|
|
|
EndLine: 5,
|
|
|
|
StartPos: 183,
|
|
|
|
EndPos: 196,
|
|
|
|
},
|
|
|
|
ByRef: false,
|
|
|
|
Variadic: false,
|
|
|
|
VariableType: &node.Nullable{
|
|
|
|
Position: &position.Position{
|
|
|
|
StartLine: 5,
|
|
|
|
EndLine: 5,
|
|
|
|
StartPos: 183,
|
|
|
|
EndPos: 186,
|
|
|
|
},
|
|
|
|
Expr: &name.Name{
|
|
|
|
Position: &position.Position{
|
|
|
|
StartLine: 5,
|
|
|
|
EndLine: 5,
|
|
|
|
StartPos: 184,
|
|
|
|
EndPos: 186,
|
|
|
|
},
|
|
|
|
Parts: []node.Node{
|
|
|
|
&name.NamePart{
|
|
|
|
Position: &position.Position{
|
|
|
|
StartLine: 5,
|
|
|
|
EndLine: 5,
|
|
|
|
StartPos: 184,
|
|
|
|
EndPos: 186,
|
|
|
|
},
|
|
|
|
Value: "bar",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Variable: &expr.Variable{
|
|
|
|
Position: &position.Position{
|
|
|
|
StartLine: 5,
|
|
|
|
EndLine: 5,
|
|
|
|
StartPos: 188,
|
|
|
|
EndPos: 191,
|
|
|
|
},
|
|
|
|
VarName: &node.Identifier{
|
|
|
|
Position: &position.Position{
|
|
|
|
StartLine: 5,
|
|
|
|
EndLine: 5,
|
|
|
|
StartPos: 188,
|
|
|
|
EndPos: 191,
|
|
|
|
},
|
|
|
|
Value: "bar",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
DefaultValue: &expr.ConstFetch{
|
|
|
|
Position: &position.Position{
|
|
|
|
StartLine: 5,
|
|
|
|
EndLine: 5,
|
|
|
|
StartPos: 193,
|
|
|
|
EndPos: 196,
|
|
|
|
},
|
|
|
|
Constant: &name.Name{
|
|
|
|
Position: &position.Position{
|
|
|
|
StartLine: 5,
|
|
|
|
EndLine: 5,
|
|
|
|
StartPos: 193,
|
|
|
|
EndPos: 196,
|
|
|
|
},
|
|
|
|
Parts: []node.Node{
|
|
|
|
&name.NamePart{
|
|
|
|
Position: &position.Position{
|
|
|
|
StartLine: 5,
|
|
|
|
EndLine: 5,
|
|
|
|
StartPos: 193,
|
|
|
|
EndPos: 196,
|
|
|
|
},
|
|
|
|
Value: "null",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
&node.Parameter{
|
|
|
|
Position: &position.Position{
|
|
|
|
StartLine: 5,
|
|
|
|
EndLine: 5,
|
|
|
|
StartPos: 199,
|
|
|
|
EndPos: 210,
|
|
|
|
},
|
|
|
|
Variadic: true,
|
|
|
|
ByRef: true,
|
|
|
|
VariableType: &name.Name{
|
|
|
|
Position: &position.Position{
|
|
|
|
StartLine: 5,
|
|
|
|
EndLine: 5,
|
|
|
|
StartPos: 199,
|
|
|
|
EndPos: 201,
|
|
|
|
},
|
|
|
|
Parts: []node.Node{
|
|
|
|
&name.NamePart{
|
|
|
|
Position: &position.Position{
|
|
|
|
StartLine: 5,
|
|
|
|
EndLine: 5,
|
|
|
|
StartPos: 199,
|
|
|
|
EndPos: 201,
|
|
|
|
},
|
|
|
|
Value: "baz",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Variable: &expr.Variable{
|
|
|
|
Position: &position.Position{
|
|
|
|
StartLine: 5,
|
|
|
|
EndLine: 5,
|
|
|
|
StartPos: 207,
|
|
|
|
EndPos: 210,
|
|
|
|
},
|
|
|
|
VarName: &node.Identifier{
|
|
|
|
Position: &position.Position{
|
|
|
|
StartLine: 5,
|
|
|
|
EndLine: 5,
|
|
|
|
StartPos: 207,
|
|
|
|
EndPos: 210,
|
|
|
|
},
|
|
|
|
Value: "baz",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Stmts: []node.Node{},
|
2018-01-13 01:40:08 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
2018-04-10 12:23:13 +00:00
|
|
|
php7parser := php7.NewParser(bytes.NewBufferString(src), "test.php")
|
|
|
|
php7parser.Parse()
|
|
|
|
actual := php7parser.GetRootNode()
|
2018-02-08 10:48:38 +00:00
|
|
|
assertEqual(t, expected, actual)
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestPhp5ParameterNode(t *testing.T) {
|
|
|
|
src := `<?
|
|
|
|
function foo(bar $bar=null, baz &...$baz) {}
|
|
|
|
class foo {public function foo(bar $bar=null, baz &...$baz) {}}
|
|
|
|
function(bar $bar=null, baz &...$baz) {};
|
|
|
|
static function(bar $bar=null, baz &...$baz) {};
|
|
|
|
`
|
|
|
|
|
2018-05-02 09:14:24 +00:00
|
|
|
expected := &node.Root{
|
2018-06-24 07:19:44 +00:00
|
|
|
Position: &position.Position{
|
|
|
|
StartLine: 2,
|
|
|
|
EndLine: 5,
|
|
|
|
StartPos: 7,
|
|
|
|
EndPos: 211,
|
|
|
|
},
|
2018-02-08 10:48:38 +00:00
|
|
|
Stmts: []node.Node{
|
|
|
|
&stmt.Function{
|
2018-06-24 07:19:44 +00:00
|
|
|
Position: &position.Position{
|
|
|
|
StartLine: 2,
|
|
|
|
EndLine: 2,
|
|
|
|
StartPos: 7,
|
|
|
|
EndPos: 50,
|
|
|
|
},
|
2018-02-08 10:48:38 +00:00
|
|
|
ReturnsRef: false,
|
|
|
|
PhpDocComment: "",
|
2018-06-24 07:19:44 +00:00
|
|
|
FunctionName: &node.Identifier{
|
|
|
|
Position: &position.Position{
|
|
|
|
StartLine: 2,
|
|
|
|
EndLine: 2,
|
|
|
|
StartPos: 16,
|
|
|
|
EndPos: 18,
|
|
|
|
},
|
|
|
|
Value: "foo",
|
|
|
|
},
|
|
|
|
Params: []node.Node{
|
|
|
|
&node.Parameter{
|
|
|
|
Position: &position.Position{
|
|
|
|
StartLine: 2,
|
|
|
|
EndLine: 2,
|
|
|
|
StartPos: 20,
|
|
|
|
EndPos: 32,
|
|
|
|
},
|
|
|
|
ByRef: false,
|
|
|
|
Variadic: false,
|
|
|
|
VariableType: &name.Name{
|
|
|
|
Position: &position.Position{
|
|
|
|
StartLine: 2,
|
|
|
|
EndLine: 2,
|
|
|
|
StartPos: 20,
|
|
|
|
EndPos: 22,
|
|
|
|
},
|
|
|
|
Parts: []node.Node{
|
|
|
|
&name.NamePart{
|
|
|
|
Position: &position.Position{
|
|
|
|
StartLine: 2,
|
|
|
|
EndLine: 2,
|
|
|
|
StartPos: 20,
|
|
|
|
EndPos: 22,
|
|
|
|
},
|
|
|
|
Value: "bar",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Variable: &expr.Variable{
|
|
|
|
Position: &position.Position{
|
|
|
|
StartLine: 2,
|
|
|
|
EndLine: 2,
|
|
|
|
StartPos: 24,
|
|
|
|
EndPos: 27,
|
|
|
|
},
|
|
|
|
VarName: &node.Identifier{
|
|
|
|
Position: &position.Position{
|
|
|
|
StartLine: 2,
|
|
|
|
EndLine: 2,
|
|
|
|
StartPos: 24,
|
|
|
|
EndPos: 27,
|
|
|
|
},
|
|
|
|
Value: "bar",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
DefaultValue: &expr.ConstFetch{
|
|
|
|
Position: &position.Position{
|
|
|
|
StartLine: 2,
|
|
|
|
EndLine: 2,
|
|
|
|
StartPos: 29,
|
|
|
|
EndPos: 32,
|
|
|
|
},
|
|
|
|
Constant: &name.Name{
|
|
|
|
Position: &position.Position{
|
|
|
|
StartLine: 2,
|
|
|
|
EndLine: 2,
|
|
|
|
StartPos: 29,
|
|
|
|
EndPos: 32,
|
|
|
|
},
|
|
|
|
Parts: []node.Node{
|
|
|
|
&name.NamePart{
|
|
|
|
Position: &position.Position{
|
|
|
|
StartLine: 2,
|
|
|
|
EndLine: 2,
|
|
|
|
StartPos: 29,
|
|
|
|
EndPos: 32,
|
|
|
|
},
|
|
|
|
Value: "null",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
&node.Parameter{
|
|
|
|
Position: &position.Position{
|
|
|
|
StartLine: 2,
|
|
|
|
EndLine: 2,
|
|
|
|
StartPos: 35,
|
|
|
|
EndPos: 46,
|
|
|
|
},
|
|
|
|
ByRef: true,
|
|
|
|
Variadic: true,
|
|
|
|
VariableType: &name.Name{
|
|
|
|
Position: &position.Position{
|
|
|
|
StartLine: 2,
|
|
|
|
EndLine: 2,
|
|
|
|
StartPos: 35,
|
|
|
|
EndPos: 37,
|
|
|
|
},
|
|
|
|
Parts: []node.Node{
|
|
|
|
&name.NamePart{
|
|
|
|
Position: &position.Position{
|
|
|
|
StartLine: 2,
|
|
|
|
EndLine: 2,
|
|
|
|
StartPos: 35,
|
|
|
|
EndPos: 37,
|
|
|
|
},
|
|
|
|
Value: "baz",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Variable: &expr.Variable{
|
|
|
|
Position: &position.Position{
|
|
|
|
StartLine: 2,
|
|
|
|
EndLine: 2,
|
|
|
|
StartPos: 43,
|
|
|
|
EndPos: 46,
|
|
|
|
},
|
|
|
|
VarName: &node.Identifier{
|
|
|
|
Position: &position.Position{
|
|
|
|
StartLine: 2,
|
|
|
|
EndLine: 2,
|
|
|
|
StartPos: 43,
|
|
|
|
EndPos: 46,
|
|
|
|
},
|
|
|
|
Value: "baz",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Stmts: []node.Node{},
|
2018-02-08 10:48:38 +00:00
|
|
|
},
|
|
|
|
&stmt.Class{
|
2018-06-24 07:19:44 +00:00
|
|
|
Position: &position.Position{
|
|
|
|
StartLine: 3,
|
|
|
|
EndLine: 3,
|
|
|
|
StartPos: 54,
|
|
|
|
EndPos: 116,
|
|
|
|
},
|
|
|
|
PhpDocComment: "",
|
|
|
|
ClassName: &node.Identifier{
|
|
|
|
Position: &position.Position{
|
|
|
|
StartLine: 3,
|
|
|
|
EndLine: 3,
|
|
|
|
StartPos: 60,
|
|
|
|
EndPos: 62,
|
|
|
|
},
|
|
|
|
Value: "foo",
|
|
|
|
},
|
2018-02-08 10:48:38 +00:00
|
|
|
Stmts: []node.Node{
|
|
|
|
&stmt.ClassMethod{
|
2018-06-24 07:19:44 +00:00
|
|
|
Position: &position.Position{
|
|
|
|
StartLine: 3,
|
|
|
|
EndLine: 3,
|
|
|
|
StartPos: 65,
|
|
|
|
EndPos: 115,
|
|
|
|
},
|
|
|
|
ReturnsRef: false,
|
|
|
|
PhpDocComment: "",
|
|
|
|
MethodName: &node.Identifier{
|
|
|
|
Position: &position.Position{
|
|
|
|
StartLine: 3,
|
|
|
|
EndLine: 3,
|
|
|
|
StartPos: 81,
|
|
|
|
EndPos: 83,
|
|
|
|
},
|
|
|
|
Value: "foo",
|
|
|
|
},
|
|
|
|
Modifiers: []node.Node{
|
|
|
|
&node.Identifier{
|
|
|
|
Position: &position.Position{
|
|
|
|
StartLine: 3,
|
|
|
|
EndLine: 3,
|
|
|
|
StartPos: 65,
|
|
|
|
EndPos: 70,
|
|
|
|
},
|
|
|
|
Value: "public",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Params: []node.Node{
|
|
|
|
&node.Parameter{
|
|
|
|
Position: &position.Position{
|
|
|
|
StartLine: 3,
|
|
|
|
EndLine: 3,
|
|
|
|
StartPos: 85,
|
|
|
|
EndPos: 97,
|
|
|
|
},
|
|
|
|
ByRef: false,
|
|
|
|
Variadic: false,
|
|
|
|
VariableType: &name.Name{
|
|
|
|
Position: &position.Position{
|
|
|
|
StartLine: 3,
|
|
|
|
EndLine: 3,
|
|
|
|
StartPos: 85,
|
|
|
|
EndPos: 87,
|
|
|
|
},
|
|
|
|
Parts: []node.Node{
|
|
|
|
&name.NamePart{
|
|
|
|
Position: &position.Position{
|
|
|
|
StartLine: 3,
|
|
|
|
EndLine: 3,
|
|
|
|
StartPos: 85,
|
|
|
|
EndPos: 87,
|
|
|
|
},
|
|
|
|
Value: "bar",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Variable: &expr.Variable{
|
|
|
|
Position: &position.Position{
|
|
|
|
StartLine: 3,
|
|
|
|
EndLine: 3,
|
|
|
|
StartPos: 89,
|
|
|
|
EndPos: 92,
|
|
|
|
},
|
|
|
|
VarName: &node.Identifier{
|
|
|
|
Position: &position.Position{
|
|
|
|
StartLine: 3,
|
|
|
|
EndLine: 3,
|
|
|
|
StartPos: 89,
|
|
|
|
EndPos: 92,
|
|
|
|
},
|
|
|
|
Value: "bar",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
DefaultValue: &expr.ConstFetch{
|
|
|
|
Position: &position.Position{
|
|
|
|
StartLine: 3,
|
|
|
|
EndLine: 3,
|
|
|
|
StartPos: 94,
|
|
|
|
EndPos: 97,
|
|
|
|
},
|
|
|
|
Constant: &name.Name{
|
|
|
|
Position: &position.Position{
|
|
|
|
StartLine: 3,
|
|
|
|
EndLine: 3,
|
|
|
|
StartPos: 94,
|
|
|
|
EndPos: 97,
|
|
|
|
},
|
|
|
|
Parts: []node.Node{
|
|
|
|
&name.NamePart{
|
|
|
|
Position: &position.Position{
|
|
|
|
StartLine: 3,
|
|
|
|
EndLine: 3,
|
|
|
|
StartPos: 94,
|
|
|
|
EndPos: 97,
|
|
|
|
},
|
|
|
|
Value: "null",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
&node.Parameter{
|
|
|
|
Position: &position.Position{
|
|
|
|
StartLine: 3,
|
|
|
|
EndLine: 3,
|
|
|
|
StartPos: 100,
|
|
|
|
EndPos: 111,
|
|
|
|
},
|
|
|
|
ByRef: true,
|
|
|
|
Variadic: true,
|
|
|
|
VariableType: &name.Name{
|
|
|
|
Position: &position.Position{
|
|
|
|
StartLine: 3,
|
|
|
|
EndLine: 3,
|
|
|
|
StartPos: 100,
|
|
|
|
EndPos: 102,
|
|
|
|
},
|
|
|
|
Parts: []node.Node{
|
|
|
|
&name.NamePart{
|
|
|
|
Position: &position.Position{
|
|
|
|
StartLine: 3,
|
|
|
|
EndLine: 3,
|
|
|
|
StartPos: 100,
|
|
|
|
EndPos: 102,
|
|
|
|
},
|
|
|
|
Value: "baz",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Variable: &expr.Variable{
|
|
|
|
Position: &position.Position{
|
|
|
|
StartLine: 3,
|
|
|
|
EndLine: 3,
|
|
|
|
StartPos: 108,
|
|
|
|
EndPos: 111,
|
|
|
|
},
|
|
|
|
VarName: &node.Identifier{
|
|
|
|
Position: &position.Position{
|
|
|
|
StartLine: 3,
|
|
|
|
EndLine: 3,
|
|
|
|
StartPos: 108,
|
|
|
|
EndPos: 111,
|
|
|
|
},
|
|
|
|
Value: "baz",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2018-06-03 06:35:44 +00:00
|
|
|
Stmt: &stmt.StmtList{
|
2018-06-24 07:19:44 +00:00
|
|
|
Position: &position.Position{
|
|
|
|
StartLine: 3,
|
|
|
|
EndLine: 3,
|
|
|
|
StartPos: 114,
|
|
|
|
EndPos: 115,
|
|
|
|
},
|
2018-06-03 06:35:44 +00:00
|
|
|
Stmts: []node.Node{},
|
|
|
|
},
|
2018-02-08 10:48:38 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
&stmt.Expression{
|
2018-06-24 07:19:44 +00:00
|
|
|
Position: &position.Position{
|
|
|
|
StartLine: 4,
|
|
|
|
EndLine: 4,
|
|
|
|
StartPos: 120,
|
|
|
|
EndPos: 160,
|
|
|
|
},
|
2018-02-08 10:48:38 +00:00
|
|
|
Expr: &expr.Closure{
|
2018-06-24 07:19:44 +00:00
|
|
|
Position: &position.Position{
|
|
|
|
StartLine: 4,
|
|
|
|
EndLine: 4,
|
|
|
|
StartPos: 120,
|
|
|
|
EndPos: 159,
|
|
|
|
},
|
|
|
|
ReturnsRef: false,
|
|
|
|
Static: false,
|
|
|
|
PhpDocComment: "",
|
|
|
|
Params: []node.Node{
|
|
|
|
&node.Parameter{
|
|
|
|
Position: &position.Position{
|
|
|
|
StartLine: 4,
|
|
|
|
EndLine: 4,
|
|
|
|
StartPos: 129,
|
|
|
|
EndPos: 141,
|
|
|
|
},
|
|
|
|
Variadic: false,
|
|
|
|
ByRef: false,
|
|
|
|
VariableType: &name.Name{
|
|
|
|
Position: &position.Position{
|
|
|
|
StartLine: 4,
|
|
|
|
EndLine: 4,
|
|
|
|
StartPos: 129,
|
|
|
|
EndPos: 131,
|
|
|
|
},
|
|
|
|
Parts: []node.Node{
|
|
|
|
&name.NamePart{
|
|
|
|
Position: &position.Position{
|
|
|
|
StartLine: 4,
|
|
|
|
EndLine: 4,
|
|
|
|
StartPos: 129,
|
|
|
|
EndPos: 131,
|
|
|
|
},
|
|
|
|
Value: "bar",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Variable: &expr.Variable{
|
|
|
|
Position: &position.Position{
|
|
|
|
StartLine: 4,
|
|
|
|
EndLine: 4,
|
|
|
|
StartPos: 133,
|
|
|
|
EndPos: 136,
|
|
|
|
},
|
|
|
|
VarName: &node.Identifier{
|
|
|
|
Position: &position.Position{
|
|
|
|
StartLine: 4,
|
|
|
|
EndLine: 4,
|
|
|
|
StartPos: 133,
|
|
|
|
EndPos: 136,
|
|
|
|
},
|
|
|
|
Value: "bar",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
DefaultValue: &expr.ConstFetch{
|
|
|
|
Position: &position.Position{
|
|
|
|
StartLine: 4,
|
|
|
|
EndLine: 4,
|
|
|
|
StartPos: 138,
|
|
|
|
EndPos: 141,
|
|
|
|
},
|
|
|
|
Constant: &name.Name{
|
|
|
|
Position: &position.Position{
|
|
|
|
StartLine: 4,
|
|
|
|
EndLine: 4,
|
|
|
|
StartPos: 138,
|
|
|
|
EndPos: 141,
|
|
|
|
},
|
|
|
|
Parts: []node.Node{
|
|
|
|
&name.NamePart{
|
|
|
|
Position: &position.Position{
|
|
|
|
StartLine: 4,
|
|
|
|
EndLine: 4,
|
|
|
|
StartPos: 138,
|
|
|
|
EndPos: 141,
|
|
|
|
},
|
|
|
|
Value: "null",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
&node.Parameter{
|
|
|
|
Position: &position.Position{
|
|
|
|
StartLine: 4,
|
|
|
|
EndLine: 4,
|
|
|
|
StartPos: 144,
|
|
|
|
EndPos: 155,
|
|
|
|
},
|
|
|
|
ByRef: true,
|
|
|
|
Variadic: true,
|
|
|
|
VariableType: &name.Name{
|
|
|
|
Position: &position.Position{
|
|
|
|
StartLine: 4,
|
|
|
|
EndLine: 4,
|
|
|
|
StartPos: 144,
|
|
|
|
EndPos: 146,
|
|
|
|
},
|
|
|
|
Parts: []node.Node{
|
|
|
|
&name.NamePart{
|
|
|
|
Position: &position.Position{
|
|
|
|
StartLine: 4,
|
|
|
|
EndLine: 4,
|
|
|
|
StartPos: 144,
|
|
|
|
EndPos: 146,
|
|
|
|
},
|
|
|
|
Value: "baz",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Variable: &expr.Variable{
|
|
|
|
Position: &position.Position{
|
|
|
|
StartLine: 4,
|
|
|
|
EndLine: 4,
|
|
|
|
StartPos: 152,
|
|
|
|
EndPos: 155,
|
|
|
|
},
|
|
|
|
VarName: &node.Identifier{
|
|
|
|
Position: &position.Position{
|
|
|
|
StartLine: 4,
|
|
|
|
EndLine: 4,
|
|
|
|
StartPos: 152,
|
|
|
|
EndPos: 155,
|
|
|
|
},
|
|
|
|
Value: "baz",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Stmts: []node.Node{},
|
2018-02-08 10:48:38 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
&stmt.Expression{
|
2018-06-24 07:19:44 +00:00
|
|
|
Position: &position.Position{
|
|
|
|
StartLine: 5,
|
|
|
|
EndLine: 5,
|
|
|
|
StartPos: 164,
|
|
|
|
EndPos: 211,
|
|
|
|
},
|
2018-02-08 10:48:38 +00:00
|
|
|
Expr: &expr.Closure{
|
2018-06-24 07:19:44 +00:00
|
|
|
Position: &position.Position{
|
|
|
|
StartLine: 5,
|
|
|
|
EndLine: 5,
|
|
|
|
StartPos: 164,
|
|
|
|
EndPos: 210,
|
|
|
|
},
|
|
|
|
PhpDocComment: "",
|
|
|
|
ReturnsRef: false,
|
|
|
|
Static: true,
|
|
|
|
Params: []node.Node{
|
|
|
|
&node.Parameter{
|
|
|
|
Position: &position.Position{
|
|
|
|
StartLine: 5,
|
|
|
|
EndLine: 5,
|
|
|
|
StartPos: 180,
|
|
|
|
EndPos: 192,
|
|
|
|
},
|
|
|
|
ByRef: false,
|
|
|
|
Variadic: false,
|
|
|
|
VariableType: &name.Name{
|
|
|
|
Position: &position.Position{
|
|
|
|
StartLine: 5,
|
|
|
|
EndLine: 5,
|
|
|
|
StartPos: 180,
|
|
|
|
EndPos: 182,
|
|
|
|
},
|
|
|
|
Parts: []node.Node{
|
|
|
|
&name.NamePart{
|
|
|
|
Position: &position.Position{
|
|
|
|
StartLine: 5,
|
|
|
|
EndLine: 5,
|
|
|
|
StartPos: 180,
|
|
|
|
EndPos: 182,
|
|
|
|
},
|
|
|
|
Value: "bar",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Variable: &expr.Variable{
|
|
|
|
Position: &position.Position{
|
|
|
|
StartLine: 5,
|
|
|
|
EndLine: 5,
|
|
|
|
StartPos: 184,
|
|
|
|
EndPos: 187,
|
|
|
|
},
|
|
|
|
VarName: &node.Identifier{
|
|
|
|
Position: &position.Position{
|
|
|
|
StartLine: 5,
|
|
|
|
EndLine: 5,
|
|
|
|
StartPos: 184,
|
|
|
|
EndPos: 187,
|
|
|
|
},
|
|
|
|
Value: "bar",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
DefaultValue: &expr.ConstFetch{
|
|
|
|
Position: &position.Position{
|
|
|
|
StartLine: 5,
|
|
|
|
EndLine: 5,
|
|
|
|
StartPos: 189,
|
|
|
|
EndPos: 192,
|
|
|
|
},
|
|
|
|
Constant: &name.Name{
|
|
|
|
Position: &position.Position{
|
|
|
|
StartLine: 5,
|
|
|
|
EndLine: 5,
|
|
|
|
StartPos: 189,
|
|
|
|
EndPos: 192,
|
|
|
|
},
|
|
|
|
Parts: []node.Node{
|
|
|
|
&name.NamePart{
|
|
|
|
Position: &position.Position{
|
|
|
|
StartLine: 5,
|
|
|
|
EndLine: 5,
|
|
|
|
StartPos: 189,
|
|
|
|
EndPos: 192,
|
|
|
|
},
|
|
|
|
Value: "null",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
&node.Parameter{
|
|
|
|
Position: &position.Position{
|
|
|
|
StartLine: 5,
|
|
|
|
EndLine: 5,
|
|
|
|
StartPos: 195,
|
|
|
|
EndPos: 206,
|
|
|
|
},
|
|
|
|
ByRef: true,
|
|
|
|
Variadic: true,
|
|
|
|
VariableType: &name.Name{
|
|
|
|
Position: &position.Position{
|
|
|
|
StartLine: 5,
|
|
|
|
EndLine: 5,
|
|
|
|
StartPos: 195,
|
|
|
|
EndPos: 197,
|
|
|
|
},
|
|
|
|
Parts: []node.Node{
|
|
|
|
&name.NamePart{
|
|
|
|
Position: &position.Position{
|
|
|
|
StartLine: 5,
|
|
|
|
EndLine: 5,
|
|
|
|
StartPos: 195,
|
|
|
|
EndPos: 197,
|
|
|
|
},
|
|
|
|
Value: "baz",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Variable: &expr.Variable{
|
|
|
|
Position: &position.Position{
|
|
|
|
StartLine: 5,
|
|
|
|
EndLine: 5,
|
|
|
|
StartPos: 203,
|
|
|
|
EndPos: 206,
|
|
|
|
},
|
|
|
|
VarName: &node.Identifier{
|
|
|
|
Position: &position.Position{
|
|
|
|
StartLine: 5,
|
|
|
|
EndLine: 5,
|
|
|
|
StartPos: 203,
|
|
|
|
EndPos: 206,
|
|
|
|
},
|
|
|
|
Value: "baz",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Stmts: []node.Node{},
|
2018-02-08 10:48:38 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
2018-04-10 12:23:13 +00:00
|
|
|
php5parser := php5.NewParser(bytes.NewBufferString(src), "test.php")
|
|
|
|
php5parser.Parse()
|
|
|
|
actual := php5parser.GetRootNode()
|
2018-01-13 01:40:08 +00:00
|
|
|
assertEqual(t, expected, actual)
|
|
|
|
}
|
2018-03-30 14:15:26 +00:00
|
|
|
|
|
|
|
func TestCommentEndFile(t *testing.T) {
|
|
|
|
src := `<? //comment at the end)`
|
|
|
|
|
2018-05-02 09:14:24 +00:00
|
|
|
expected := &node.Root{
|
2018-06-24 07:19:44 +00:00
|
|
|
Position: &position.Position{
|
|
|
|
StartLine: -1,
|
|
|
|
EndLine: -1,
|
|
|
|
StartPos: -1,
|
|
|
|
EndPos: -1,
|
|
|
|
},
|
2018-03-30 14:15:26 +00:00
|
|
|
Stmts: []node.Node{},
|
|
|
|
}
|
|
|
|
|
2018-04-10 12:23:13 +00:00
|
|
|
php7parser := php7.NewParser(bytes.NewBufferString(src), "test.php")
|
|
|
|
php7parser.Parse()
|
|
|
|
actual := php7parser.GetRootNode()
|
2018-03-30 14:15:26 +00:00
|
|
|
assertEqual(t, expected, actual)
|
|
|
|
|
2018-04-10 12:23:13 +00:00
|
|
|
php5parser := php5.NewParser(bytes.NewBufferString(src), "test.php")
|
|
|
|
php5parser.Parse()
|
|
|
|
actual = php5parser.GetRootNode()
|
2018-03-30 14:15:26 +00:00
|
|
|
assertEqual(t, expected, actual)
|
|
|
|
}
|