Merge pull request #100 from z7zmey/issue-82

Merge issue-82 to dev
This commit is contained in:
Vadym Slizov
2019-12-30 00:31:45 +02:00
committed by GitHub
113 changed files with 15826 additions and 14263 deletions

View File

@@ -4,9 +4,9 @@ package freefloating
import "strconv"
const _Position_name = "StartEndSlashColonSemiColonAltEndDollarAmpersandNamePrefixKeyVarUseTypeReturnTypeOptionalTypeCaseSeparatorLexicalVarsParamsRefCastExprInitExprCondExprIncExprTrueCondHaltCompillerNamespaceStaticClassUseWhileForSwitchBreakForeachDeclareLabelFinallyListDefaultIfElseIfElseVariadicFunctionAliasAsEqualExitArrayIssetEmptyEvalEchoTryCatchUnsetStmtsVarListConstListNameListParamListModifierListArrayPairListCaseListStartCaseListEndArgumentListPropertyListParameterListAdaptationListLexicalVarListUseDeclarationListOpenParenthesisTokenCloseParenthesisToken"
const _Position_name = "StartEndSlashColonSemiColonAltEndDollarAmpersandNamePrefixKeyVarUseTypeReturnTypeOptionalTypeCaseSeparatorLexicalVarsParamsRefCastExprInitExprCondExprIncExprTrueCondHaltCompillerNamespaceStaticClassUseWhileForSwitchBreakForeachDeclareLabelFinallyListDefaultIfElseIfElseVariadicFunctionDoubleArrowAliasAsEqualExitArrayIssetEmptyEvalEchoTryCatchUnsetStmtsVarListConstListNameListParamListModifierListArrayPairListCaseListStartCaseListEndArgumentListPropertyListParameterListAdaptationListLexicalVarListUseDeclarationListOpenParenthesisTokenCloseParenthesisToken"
var _Position_index = [...]uint16{0, 5, 8, 13, 18, 27, 33, 39, 48, 52, 58, 61, 64, 71, 81, 93, 106, 117, 123, 126, 130, 134, 142, 150, 157, 161, 165, 178, 187, 193, 198, 201, 206, 209, 215, 220, 227, 234, 239, 246, 250, 257, 259, 265, 269, 277, 285, 290, 292, 297, 301, 306, 311, 316, 320, 324, 327, 332, 337, 342, 349, 358, 366, 375, 387, 400, 413, 424, 436, 448, 461, 475, 489, 507, 527, 548}
var _Position_index = [...]uint16{0, 5, 8, 13, 18, 27, 33, 39, 48, 52, 58, 61, 64, 71, 81, 93, 106, 117, 123, 126, 130, 134, 142, 150, 157, 161, 165, 178, 187, 193, 198, 201, 206, 209, 215, 220, 227, 234, 239, 246, 250, 257, 259, 265, 269, 277, 285, 296, 301, 303, 308, 312, 317, 322, 327, 331, 335, 338, 343, 348, 353, 360, 369, 377, 386, 398, 411, 424, 435, 447, 459, 472, 486, 500, 518, 538, 559}
func (i Position) String() string {
if i < 0 || i >= Position(len(_Position_index)-1) {

View File

@@ -61,6 +61,7 @@ const (
Else
Variadic
Function
DoubleArrow
Alias
As
Equal

15
main.go
View File

@@ -15,14 +15,12 @@ import (
"github.com/pkg/profile"
"github.com/yookoala/realpath"
"github.com/z7zmey/php-parser/parser"
"github.com/z7zmey/php-parser/php5"
"github.com/z7zmey/php-parser/php7"
"github.com/z7zmey/php-parser/printer"
"github.com/z7zmey/php-parser/visitor"
)
var wg sync.WaitGroup
var usePhp5 *bool
var phpVersion string
var dumpType string
var profiler string
var withFreeFloating *bool
@@ -40,12 +38,12 @@ type result struct {
}
func main() {
usePhp5 = flag.Bool("php5", false, "parse as PHP5")
withFreeFloating = flag.Bool("ff", false, "parse and show free floating strings")
showResolvedNs = flag.Bool("r", false, "resolve names")
printBack = flag.Bool("pb", false, "print AST back into the parsed file")
flag.StringVar(&dumpType, "d", "", "dump format: [custom, go, json, pretty_json]")
flag.StringVar(&profiler, "prof", "", "start profiler: [cpu, mem, trace]")
flag.StringVar(&phpVersion, "phpver", "7.4", "php version")
flag.Parse()
@@ -104,18 +102,15 @@ func processPath(pathList []string, fileCh chan<- *file) {
}
func parserWorker(fileCh <-chan *file, r chan<- result) {
var parserWorker parser.Parser
for {
f, ok := <-fileCh
if !ok {
return
}
if *usePhp5 {
parserWorker = php5.NewParser(f.content)
} else {
parserWorker = php7.NewParser(f.content)
parserWorker, err := parser.NewParser(f.content, phpVersion)
if err != nil {
panic(err.Error())
}
if *withFreeFloating {

View File

@@ -0,0 +1,66 @@
package assign
import (
"github.com/z7zmey/php-parser/freefloating"
"github.com/z7zmey/php-parser/node"
"github.com/z7zmey/php-parser/position"
"github.com/z7zmey/php-parser/walker"
)
// Coalesce node
type Coalesce struct {
FreeFloating freefloating.Collection
Position *position.Position
Variable node.Node
Expression node.Node
}
// NewCoalesce node constructor
func NewCoalesce(Variable node.Node, Expression node.Node) *Coalesce {
return &Coalesce{
FreeFloating: nil,
Variable: Variable,
Expression: Expression,
}
}
// SetPosition sets node position
func (n *Coalesce) SetPosition(p *position.Position) {
n.Position = p
}
// GetPosition returns node positions
func (n *Coalesce) GetPosition() *position.Position {
return n.Position
}
func (n *Coalesce) GetFreeFloating() *freefloating.Collection {
return &n.FreeFloating
}
// Attributes returns node attributes as map
func (n *Coalesce) Attributes() map[string]interface{} {
return nil
}
// Walk traverses nodes
// Walk is invoked recursively until v.EnterNode returns true
func (n *Coalesce) Walk(v walker.Visitor) {
if v.EnterNode(n) == false {
return
}
if n.Variable != nil {
v.EnterChildNode("Variable", n)
n.Variable.Walk(v)
v.LeaveChildNode("Variable", n)
}
if n.Expression != nil {
v.EnterChildNode("Expression", n)
n.Expression.Walk(v)
v.LeaveChildNode("Expression", n)
}
v.LeaveNode(n)
}

View File

@@ -80,12 +80,12 @@ func TestReference(t *testing.T) {
},
}
php7parser := php7.NewParser([]byte(src))
php7parser := php7.NewParser([]byte(src), "7.4")
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser([]byte(src))
php5parser := php5.NewParser([]byte(src), "5.6")
php5parser.Parse()
actual = php5parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
@@ -165,12 +165,12 @@ func TestReferenceNew(t *testing.T) {
},
}
php7parser := php7.NewParser([]byte(src))
php7parser := php7.NewParser([]byte(src), "7.4")
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser([]byte(src))
php5parser := php5.NewParser([]byte(src), "5.6")
php5parser.Parse()
actual = php5parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
@@ -287,12 +287,12 @@ func TestReferenceArgs(t *testing.T) {
},
}
php7parser := php7.NewParser([]byte(src))
php7parser := php7.NewParser([]byte(src), "7.4")
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser([]byte(src))
php5parser := php5.NewParser([]byte(src), "5.6")
php5parser.Parse()
actual = php5parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
@@ -362,12 +362,12 @@ func TestAssign(t *testing.T) {
},
}
php7parser := php7.NewParser([]byte(src))
php7parser := php7.NewParser([]byte(src), "7.4")
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser([]byte(src))
php5parser := php5.NewParser([]byte(src), "5.6")
php5parser.Parse()
actual = php5parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
@@ -437,12 +437,12 @@ func TestBitwiseAnd(t *testing.T) {
},
}
php7parser := php7.NewParser([]byte(src))
php7parser := php7.NewParser([]byte(src), "7.4")
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser([]byte(src))
php5parser := php5.NewParser([]byte(src), "5.6")
php5parser.Parse()
actual = php5parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
@@ -512,12 +512,12 @@ func TestBitwiseOr(t *testing.T) {
},
}
php7parser := php7.NewParser([]byte(src))
php7parser := php7.NewParser([]byte(src), "7.4")
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser([]byte(src))
php5parser := php5.NewParser([]byte(src), "5.6")
php5parser.Parse()
actual = php5parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
@@ -587,12 +587,12 @@ func TestBitwiseXor(t *testing.T) {
},
}
php7parser := php7.NewParser([]byte(src))
php7parser := php7.NewParser([]byte(src), "7.4")
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser([]byte(src))
php5parser := php5.NewParser([]byte(src), "5.6")
php5parser.Parse()
actual = php5parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
@@ -662,12 +662,12 @@ func TestConcat(t *testing.T) {
},
}
php7parser := php7.NewParser([]byte(src))
php7parser := php7.NewParser([]byte(src), "7.4")
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser([]byte(src))
php5parser := php5.NewParser([]byte(src), "5.6")
php5parser.Parse()
actual = php5parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
@@ -737,12 +737,12 @@ func TestDiv(t *testing.T) {
},
}
php7parser := php7.NewParser([]byte(src))
php7parser := php7.NewParser([]byte(src), "7.4")
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser([]byte(src))
php5parser := php5.NewParser([]byte(src), "5.6")
php5parser.Parse()
actual = php5parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
@@ -812,12 +812,12 @@ func TestMinus(t *testing.T) {
},
}
php7parser := php7.NewParser([]byte(src))
php7parser := php7.NewParser([]byte(src), "7.4")
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser([]byte(src))
php5parser := php5.NewParser([]byte(src), "5.6")
php5parser.Parse()
actual = php5parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
@@ -887,12 +887,12 @@ func TestMod(t *testing.T) {
},
}
php7parser := php7.NewParser([]byte(src))
php7parser := php7.NewParser([]byte(src), "7.4")
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser([]byte(src))
php5parser := php5.NewParser([]byte(src), "5.6")
php5parser.Parse()
actual = php5parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
@@ -962,12 +962,12 @@ func TestMul(t *testing.T) {
},
}
php7parser := php7.NewParser([]byte(src))
php7parser := php7.NewParser([]byte(src), "7.4")
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser([]byte(src))
php5parser := php5.NewParser([]byte(src), "5.6")
php5parser.Parse()
actual = php5parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
@@ -1037,12 +1037,12 @@ func TestPlus(t *testing.T) {
},
}
php7parser := php7.NewParser([]byte(src))
php7parser := php7.NewParser([]byte(src), "7.4")
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser([]byte(src))
php5parser := php5.NewParser([]byte(src), "5.6")
php5parser.Parse()
actual = php5parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
@@ -1112,12 +1112,12 @@ func TestPow(t *testing.T) {
},
}
php7parser := php7.NewParser([]byte(src))
php7parser := php7.NewParser([]byte(src), "7.4")
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser([]byte(src))
php5parser := php5.NewParser([]byte(src), "5.6")
php5parser.Parse()
actual = php5parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
@@ -1187,12 +1187,12 @@ func TestShiftLeft(t *testing.T) {
},
}
php7parser := php7.NewParser([]byte(src))
php7parser := php7.NewParser([]byte(src), "7.4")
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser([]byte(src))
php5parser := php5.NewParser([]byte(src), "5.6")
php5parser.Parse()
actual = php5parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
@@ -1262,13 +1262,83 @@ func TestShiftRight(t *testing.T) {
},
}
php7parser := php7.NewParser([]byte(src))
php7parser := php7.NewParser([]byte(src), "7.4")
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser([]byte(src))
php5parser := php5.NewParser([]byte(src), "5.6")
php5parser.Parse()
actual = php5parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
}
func TestCoalesce(t *testing.T) {
src := `<? $a ??= $b;`
expected := &node.Root{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 3,
EndPos: 13,
},
Stmts: []node.Node{
&stmt.Expression{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 3,
EndPos: 13,
},
Expr: &assign.Coalesce{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 3,
EndPos: 12,
},
Variable: &expr.Variable{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 3,
EndPos: 5,
},
VarName: &node.Identifier{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 3,
EndPos: 5,
},
Value: "a",
},
},
Expression: &expr.Variable{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 10,
EndPos: 12,
},
VarName: &node.Identifier{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 10,
EndPos: 12,
},
Value: "b",
},
},
},
},
},
}
php7parser := php7.NewParser([]byte(src), "7.4")
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
}

View File

@@ -41,6 +41,9 @@ var nodes = []node.Node{
&assign.BitwiseXor{
FreeFloating: expected,
},
&assign.Coalesce{
FreeFloating: expected,
},
&assign.Concat{
FreeFloating: expected,
},

View File

@@ -56,6 +56,14 @@ var nodesToTest = []struct {
[]string{"Variable", "Expression"},
nil,
},
{
&assign.Coalesce{
Variable: &expr.Variable{},
Expression: &expr.Variable{},
},
[]string{"Variable", "Expression"},
nil,
},
{
&assign.Concat{
Variable: &expr.Variable{},

View File

@@ -78,12 +78,12 @@ func TestBitwiseAnd(t *testing.T) {
},
}
php7parser := php7.NewParser([]byte(src))
php7parser := php7.NewParser([]byte(src), "7.4")
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser([]byte(src))
php5parser := php5.NewParser([]byte(src), "5.6")
php5parser.Parse()
actual = php5parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
@@ -153,12 +153,12 @@ func TestBitwiseOr(t *testing.T) {
},
}
php7parser := php7.NewParser([]byte(src))
php7parser := php7.NewParser([]byte(src), "7.4")
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser([]byte(src))
php5parser := php5.NewParser([]byte(src), "5.6")
php5parser.Parse()
actual = php5parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
@@ -228,12 +228,12 @@ func TestBitwiseXor(t *testing.T) {
},
}
php7parser := php7.NewParser([]byte(src))
php7parser := php7.NewParser([]byte(src), "7.4")
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser([]byte(src))
php5parser := php5.NewParser([]byte(src), "5.6")
php5parser.Parse()
actual = php5parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
@@ -303,12 +303,12 @@ func TestBooleanAnd(t *testing.T) {
},
}
php7parser := php7.NewParser([]byte(src))
php7parser := php7.NewParser([]byte(src), "7.4")
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser([]byte(src))
php5parser := php5.NewParser([]byte(src), "5.6")
php5parser.Parse()
actual = php5parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
@@ -378,12 +378,12 @@ func TestBooleanOr(t *testing.T) {
},
}
php7parser := php7.NewParser([]byte(src))
php7parser := php7.NewParser([]byte(src), "7.4")
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser([]byte(src))
php5parser := php5.NewParser([]byte(src), "5.6")
php5parser.Parse()
actual = php5parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
@@ -453,7 +453,7 @@ func TestCoalesce(t *testing.T) {
},
}
php7parser := php7.NewParser([]byte(src))
php7parser := php7.NewParser([]byte(src), "7.4")
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
@@ -523,12 +523,12 @@ func TestConcat(t *testing.T) {
},
}
php7parser := php7.NewParser([]byte(src))
php7parser := php7.NewParser([]byte(src), "7.4")
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser([]byte(src))
php5parser := php5.NewParser([]byte(src), "5.6")
php5parser.Parse()
actual = php5parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
@@ -598,12 +598,12 @@ func TestDiv(t *testing.T) {
},
}
php7parser := php7.NewParser([]byte(src))
php7parser := php7.NewParser([]byte(src), "7.4")
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser([]byte(src))
php5parser := php5.NewParser([]byte(src), "5.6")
php5parser.Parse()
actual = php5parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
@@ -673,12 +673,12 @@ func TestEqual(t *testing.T) {
},
}
php7parser := php7.NewParser([]byte(src))
php7parser := php7.NewParser([]byte(src), "7.4")
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser([]byte(src))
php5parser := php5.NewParser([]byte(src), "5.6")
php5parser.Parse()
actual = php5parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
@@ -748,12 +748,12 @@ func TestGreaterOrEqual(t *testing.T) {
},
}
php7parser := php7.NewParser([]byte(src))
php7parser := php7.NewParser([]byte(src), "7.4")
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser([]byte(src))
php5parser := php5.NewParser([]byte(src), "5.6")
php5parser.Parse()
actual = php5parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
@@ -823,12 +823,12 @@ func TestGreater(t *testing.T) {
},
}
php7parser := php7.NewParser([]byte(src))
php7parser := php7.NewParser([]byte(src), "7.4")
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser([]byte(src))
php5parser := php5.NewParser([]byte(src), "5.6")
php5parser.Parse()
actual = php5parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
@@ -898,12 +898,12 @@ func TestIdentical(t *testing.T) {
},
}
php7parser := php7.NewParser([]byte(src))
php7parser := php7.NewParser([]byte(src), "7.4")
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser([]byte(src))
php5parser := php5.NewParser([]byte(src), "5.6")
php5parser.Parse()
actual = php5parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
@@ -973,12 +973,12 @@ func TestLogicalAnd(t *testing.T) {
},
}
php7parser := php7.NewParser([]byte(src))
php7parser := php7.NewParser([]byte(src), "7.4")
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser([]byte(src))
php5parser := php5.NewParser([]byte(src), "5.6")
php5parser.Parse()
actual = php5parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
@@ -1048,12 +1048,12 @@ func TestLogicalOr(t *testing.T) {
},
}
php7parser := php7.NewParser([]byte(src))
php7parser := php7.NewParser([]byte(src), "7.4")
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser([]byte(src))
php5parser := php5.NewParser([]byte(src), "5.6")
php5parser.Parse()
actual = php5parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
@@ -1123,12 +1123,12 @@ func TestLogicalXor(t *testing.T) {
},
}
php7parser := php7.NewParser([]byte(src))
php7parser := php7.NewParser([]byte(src), "7.4")
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser([]byte(src))
php5parser := php5.NewParser([]byte(src), "5.6")
php5parser.Parse()
actual = php5parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
@@ -1198,12 +1198,12 @@ func TestMinus(t *testing.T) {
},
}
php7parser := php7.NewParser([]byte(src))
php7parser := php7.NewParser([]byte(src), "7.4")
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser([]byte(src))
php5parser := php5.NewParser([]byte(src), "5.6")
php5parser.Parse()
actual = php5parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
@@ -1273,12 +1273,12 @@ func TestMod(t *testing.T) {
},
}
php7parser := php7.NewParser([]byte(src))
php7parser := php7.NewParser([]byte(src), "7.4")
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser([]byte(src))
php5parser := php5.NewParser([]byte(src), "5.6")
php5parser.Parse()
actual = php5parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
@@ -1348,12 +1348,12 @@ func TestMul(t *testing.T) {
},
}
php7parser := php7.NewParser([]byte(src))
php7parser := php7.NewParser([]byte(src), "7.4")
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser([]byte(src))
php5parser := php5.NewParser([]byte(src), "5.6")
php5parser.Parse()
actual = php5parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
@@ -1423,12 +1423,12 @@ func TestNotEqual(t *testing.T) {
},
}
php7parser := php7.NewParser([]byte(src))
php7parser := php7.NewParser([]byte(src), "7.4")
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser([]byte(src))
php5parser := php5.NewParser([]byte(src), "5.6")
php5parser.Parse()
actual = php5parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
@@ -1498,12 +1498,12 @@ func TestNotIdentical(t *testing.T) {
},
}
php7parser := php7.NewParser([]byte(src))
php7parser := php7.NewParser([]byte(src), "7.4")
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser([]byte(src))
php5parser := php5.NewParser([]byte(src), "5.6")
php5parser.Parse()
actual = php5parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
@@ -1573,12 +1573,12 @@ func TestPlus(t *testing.T) {
},
}
php7parser := php7.NewParser([]byte(src))
php7parser := php7.NewParser([]byte(src), "7.4")
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser([]byte(src))
php5parser := php5.NewParser([]byte(src), "5.6")
php5parser.Parse()
actual = php5parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
@@ -1648,12 +1648,12 @@ func TestPow(t *testing.T) {
},
}
php7parser := php7.NewParser([]byte(src))
php7parser := php7.NewParser([]byte(src), "7.4")
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser([]byte(src))
php5parser := php5.NewParser([]byte(src), "5.6")
php5parser.Parse()
actual = php5parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
@@ -1723,12 +1723,12 @@ func TestShiftLeft(t *testing.T) {
},
}
php7parser := php7.NewParser([]byte(src))
php7parser := php7.NewParser([]byte(src), "7.4")
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser([]byte(src))
php5parser := php5.NewParser([]byte(src), "5.6")
php5parser.Parse()
actual = php5parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
@@ -1798,12 +1798,12 @@ func TestShiftRight(t *testing.T) {
},
}
php7parser := php7.NewParser([]byte(src))
php7parser := php7.NewParser([]byte(src), "7.4")
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser([]byte(src))
php5parser := php5.NewParser([]byte(src), "5.6")
php5parser.Parse()
actual = php5parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
@@ -1873,12 +1873,12 @@ func TestSmallerOrEqual(t *testing.T) {
},
}
php7parser := php7.NewParser([]byte(src))
php7parser := php7.NewParser([]byte(src), "7.4")
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser([]byte(src))
php5parser := php5.NewParser([]byte(src), "5.6")
php5parser.Parse()
actual = php5parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
@@ -1948,12 +1948,12 @@ func TestSmaller(t *testing.T) {
},
}
php7parser := php7.NewParser([]byte(src))
php7parser := php7.NewParser([]byte(src), "7.4")
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser([]byte(src))
php5parser := php5.NewParser([]byte(src), "5.6")
php5parser.Parse()
actual = php5parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
@@ -2023,7 +2023,7 @@ func TestSpaceship(t *testing.T) {
},
}
php7parser := php7.NewParser([]byte(src))
php7parser := php7.NewParser([]byte(src), "7.4")
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)

View File

@@ -61,12 +61,12 @@ func TestArray(t *testing.T) {
},
}
php7parser := php7.NewParser([]byte(src))
php7parser := php7.NewParser([]byte(src), "7.4")
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser([]byte(src))
php5parser := php5.NewParser([]byte(src), "5.6")
php5parser.Parse()
actual = php5parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
@@ -119,12 +119,12 @@ func TestBool(t *testing.T) {
},
}
php7parser := php7.NewParser([]byte(src))
php7parser := php7.NewParser([]byte(src), "7.4")
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser([]byte(src))
php5parser := php5.NewParser([]byte(src), "5.6")
php5parser.Parse()
actual = php5parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
@@ -177,12 +177,12 @@ func TestBoolShort(t *testing.T) {
},
}
php7parser := php7.NewParser([]byte(src))
php7parser := php7.NewParser([]byte(src), "7.4")
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser([]byte(src))
php5parser := php5.NewParser([]byte(src), "5.6")
php5parser.Parse()
actual = php5parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
@@ -235,12 +235,12 @@ func TestDouble(t *testing.T) {
},
}
php7parser := php7.NewParser([]byte(src))
php7parser := php7.NewParser([]byte(src), "7.4")
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser([]byte(src))
php5parser := php5.NewParser([]byte(src), "5.6")
php5parser.Parse()
actual = php5parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
@@ -293,12 +293,12 @@ func TestCastFloat(t *testing.T) {
},
}
php7parser := php7.NewParser([]byte(src))
php7parser := php7.NewParser([]byte(src), "7.4")
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser([]byte(src))
php5parser := php5.NewParser([]byte(src), "5.6")
php5parser.Parse()
actual = php5parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
@@ -351,12 +351,12 @@ func TestInt(t *testing.T) {
},
}
php7parser := php7.NewParser([]byte(src))
php7parser := php7.NewParser([]byte(src), "7.4")
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser([]byte(src))
php5parser := php5.NewParser([]byte(src), "5.6")
php5parser.Parse()
actual = php5parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
@@ -409,12 +409,12 @@ func TestIntShort(t *testing.T) {
},
}
php7parser := php7.NewParser([]byte(src))
php7parser := php7.NewParser([]byte(src), "7.4")
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser([]byte(src))
php5parser := php5.NewParser([]byte(src), "5.6")
php5parser.Parse()
actual = php5parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
@@ -467,12 +467,12 @@ func TestObject(t *testing.T) {
},
}
php7parser := php7.NewParser([]byte(src))
php7parser := php7.NewParser([]byte(src), "7.4")
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser([]byte(src))
php5parser := php5.NewParser([]byte(src), "5.6")
php5parser.Parse()
actual = php5parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
@@ -525,12 +525,12 @@ func TestString(t *testing.T) {
},
}
php7parser := php7.NewParser([]byte(src))
php7parser := php7.NewParser([]byte(src), "7.4")
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser([]byte(src))
php5parser := php5.NewParser([]byte(src), "5.6")
php5parser.Parse()
actual = php5parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
@@ -583,12 +583,12 @@ func TestBinaryString(t *testing.T) {
},
}
php7parser := php7.NewParser([]byte(src))
php7parser := php7.NewParser([]byte(src), "7.4")
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser([]byte(src))
php5parser := php5.NewParser([]byte(src), "5.6")
php5parser.Parse()
actual = php5parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
@@ -641,12 +641,12 @@ func TestUnset(t *testing.T) {
},
}
php7parser := php7.NewParser([]byte(src))
php7parser := php7.NewParser([]byte(src), "7.4")
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser([]byte(src))
php5parser := php5.NewParser([]byte(src), "5.6")
php5parser.Parse()
actual = php5parser.GetRootNode()
assert.DeepEqual(t, expected, actual)

View File

@@ -13,14 +13,16 @@ type ArrayItem struct {
Position *position.Position
Key node.Node
Val node.Node
Unpack bool
}
// NewArrayItem node constructor
func NewArrayItem(Key node.Node, Val node.Node) *ArrayItem {
func NewArrayItem(Key node.Node, Val node.Node, Unpack bool) *ArrayItem {
return &ArrayItem{
FreeFloating: nil,
Key: Key,
Val: Val,
Unpack: Unpack,
}
}
@@ -40,7 +42,9 @@ func (n *ArrayItem) GetFreeFloating() *freefloating.Collection {
// Attributes returns node attributes as map
func (n *ArrayItem) Attributes() map[string]interface{} {
return nil
return map[string]interface{}{
"Unpack": n.Unpack,
}
}
// Walk traverses nodes

View File

@@ -0,0 +1,88 @@
package expr
import (
"github.com/z7zmey/php-parser/freefloating"
"github.com/z7zmey/php-parser/node"
"github.com/z7zmey/php-parser/position"
"github.com/z7zmey/php-parser/walker"
)
// ArrowFunction node
type ArrowFunction struct {
FreeFloating freefloating.Collection
Position *position.Position
ReturnsRef bool
Static bool
PhpDocComment string
Params []node.Node
ReturnType node.Node
Expr node.Node
}
// NewArrowFunction node constructor
func NewArrowFunction(Params []node.Node, ReturnType node.Node, Stmt node.Node, Static bool, ReturnsRef bool, PhpDocComment string) *ArrowFunction {
return &ArrowFunction{
FreeFloating: nil,
ReturnsRef: ReturnsRef,
Static: Static,
PhpDocComment: PhpDocComment,
Params: Params,
ReturnType: ReturnType,
Expr: Stmt,
}
}
// SetPosition sets node position
func (n *ArrowFunction) SetPosition(p *position.Position) {
n.Position = p
}
// GetPosition returns node positions
func (n *ArrowFunction) GetPosition() *position.Position {
return n.Position
}
func (n *ArrowFunction) GetFreeFloating() *freefloating.Collection {
return &n.FreeFloating
}
// Attributes returns node attributes as map
func (n *ArrowFunction) Attributes() map[string]interface{} {
return map[string]interface{}{
"ReturnsRef": n.ReturnsRef,
"Static": n.Static,
"PhpDocComment": n.PhpDocComment,
}
}
// Walk traverses nodes
// Walk is invoked recursively until v.EnterNode returns true
func (n *ArrowFunction) Walk(v walker.Visitor) {
if v.EnterNode(n) == false {
return
}
if n.Params != nil {
v.EnterChildList("Params", n)
for _, nn := range n.Params {
if nn != nil {
nn.Walk(v)
}
}
v.LeaveChildList("Params", n)
}
if n.ReturnType != nil {
v.EnterChildNode("ReturnType", n)
n.ReturnType.Walk(v)
v.LeaveChildNode("ReturnType", n)
}
if n.Expr != nil {
v.EnterChildNode("Expr", n)
n.Expr.Walk(v)
v.LeaveChildNode("Expr", n)
}
v.LeaveNode(n)
}

View File

@@ -70,12 +70,12 @@ func TestArrayDimFetch(t *testing.T) {
},
}
php7parser := php7.NewParser([]byte(src))
php7parser := php7.NewParser([]byte(src), "7.4")
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser([]byte(src))
php5parser := php5.NewParser([]byte(src), "5.6")
php5parser.Parse()
actual = php5parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
@@ -154,12 +154,12 @@ func TestArrayDimFetchNested(t *testing.T) {
},
}
php7parser := php7.NewParser([]byte(src))
php7parser := php7.NewParser([]byte(src), "7.4")
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser([]byte(src))
php5parser := php5.NewParser([]byte(src), "5.6")
php5parser.Parse()
actual = php5parser.GetRootNode()
assert.DeepEqual(t, expected, actual)

View File

@@ -45,12 +45,12 @@ func TestArray(t *testing.T) {
},
}
php7parser := php7.NewParser([]byte(src))
php7parser := php7.NewParser([]byte(src), "7.4")
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser([]byte(src))
php5parser := php5.NewParser([]byte(src), "5.6")
php5parser.Parse()
actual = php5parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
@@ -105,12 +105,12 @@ func TestArrayItem(t *testing.T) {
},
}
php7parser := php7.NewParser([]byte(src))
php7parser := php7.NewParser([]byte(src), "7.4")
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser([]byte(src))
php5parser := php5.NewParser([]byte(src), "5.6")
php5parser.Parse()
actual = php5parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
@@ -208,13 +208,77 @@ func TestArrayItems(t *testing.T) {
},
}
php7parser := php7.NewParser([]byte(src))
php7parser := php7.NewParser([]byte(src), "7.4")
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser([]byte(src))
php5parser := php5.NewParser([]byte(src), "5.6")
php5parser.Parse()
actual = php5parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
}
func TestArrayItemUnpack(t *testing.T) {
src := `<? array(...$b);`
expected := &node.Root{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 3,
EndPos: 16,
},
Stmts: []node.Node{
&stmt.Expression{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 3,
EndPos: 16,
},
Expr: &expr.Array{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 3,
EndPos: 15,
},
Items: []node.Node{
&expr.ArrayItem{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 9,
EndPos: 14,
},
Unpack: true,
Val: &expr.Variable{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 12,
EndPos: 14,
},
VarName: &node.Identifier{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 12,
EndPos: 14,
},
Value: "b",
},
},
},
},
},
},
},
}
php7parser := php7.NewParser([]byte(src), "7.4")
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
}

View File

@@ -0,0 +1,144 @@
package expr_test
import (
"testing"
"github.com/z7zmey/php-parser/node"
"github.com/z7zmey/php-parser/node/expr"
"github.com/z7zmey/php-parser/node/name"
"github.com/z7zmey/php-parser/node/stmt"
"github.com/z7zmey/php-parser/php7"
"github.com/z7zmey/php-parser/position"
"gotest.tools/assert"
)
func TestArrowFunction(t *testing.T) {
src := `<? fn() => $a;`
expected := &node.Root{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 3,
EndPos: 14,
},
Stmts: []node.Node{
&stmt.Expression{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 3,
EndPos: 14,
},
Expr: &expr.ArrowFunction{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 3,
EndPos: 13,
},
ReturnsRef: false,
Static: false,
PhpDocComment: "",
Expr: &expr.Variable{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 11,
EndPos: 13,
},
VarName: &node.Identifier{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 11,
EndPos: 13,
},
Value: "a",
},
},
},
},
},
}
php7parser := php7.NewParser([]byte(src), "7.4")
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
}
func TestArrowFunctionReturnType(t *testing.T) {
src := `<? fn & () : foo => $a;`
expected := &node.Root{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 3,
EndPos: 23,
},
Stmts: []node.Node{
&stmt.Expression{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 3,
EndPos: 23,
},
Expr: &expr.ArrowFunction{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 3,
EndPos: 22,
},
Static: false,
PhpDocComment: "",
ReturnsRef: true,
ReturnType: &name.Name{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 13,
EndPos: 16,
},
Parts: []node.Node{
&name.NamePart{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 13,
EndPos: 16,
},
Value: "foo",
},
},
},
Expr: &expr.Variable{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 20,
EndPos: 22,
},
VarName: &node.Identifier{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 20,
EndPos: 22,
},
Value: "a",
},
},
},
},
},
}
php7parser := php7.NewParser([]byte(src), "7.4")
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
}

View File

@@ -61,12 +61,12 @@ func TestBitwiseNot(t *testing.T) {
},
}
php7parser := php7.NewParser([]byte(src))
php7parser := php7.NewParser([]byte(src), "7.4")
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser([]byte(src))
php5parser := php5.NewParser([]byte(src), "5.6")
php5parser.Parse()
actual = php5parser.GetRootNode()
assert.DeepEqual(t, expected, actual)

View File

@@ -61,12 +61,12 @@ func TestBooleanNot(t *testing.T) {
},
}
php7parser := php7.NewParser([]byte(src))
php7parser := php7.NewParser([]byte(src), "7.4")
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser([]byte(src))
php5parser := php5.NewParser([]byte(src), "5.6")
php5parser.Parse()
actual = php5parser.GetRootNode()
assert.DeepEqual(t, expected, actual)

View File

@@ -74,12 +74,12 @@ func TestClassConstFetch(t *testing.T) {
},
}
php7parser := php7.NewParser([]byte(src))
php7parser := php7.NewParser([]byte(src), "7.4")
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser([]byte(src))
php5parser := php5.NewParser([]byte(src), "5.6")
php5parser.Parse()
actual = php5parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
@@ -133,12 +133,12 @@ func TestStaticClassConstFetch(t *testing.T) {
},
}
php7parser := php7.NewParser([]byte(src))
php7parser := php7.NewParser([]byte(src), "7.4")
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser([]byte(src))
php5parser := php5.NewParser([]byte(src), "5.6")
php5parser.Parse()
actual = php5parser.GetRootNode()
assert.DeepEqual(t, expected, actual)

View File

@@ -61,12 +61,12 @@ func TestCloneBrackets(t *testing.T) {
},
}
php7parser := php7.NewParser([]byte(src))
php7parser := php7.NewParser([]byte(src), "7.4")
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser([]byte(src))
php5parser := php5.NewParser([]byte(src), "5.6")
php5parser.Parse()
actual = php5parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
@@ -119,12 +119,12 @@ func TestClone(t *testing.T) {
},
}
php7parser := php7.NewParser([]byte(src))
php7parser := php7.NewParser([]byte(src), "7.4")
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser([]byte(src))
php5parser := php5.NewParser([]byte(src), "5.6")
php5parser.Parse()
actual = php5parser.GetRootNode()
assert.DeepEqual(t, expected, actual)

View File

@@ -50,12 +50,12 @@ func TestClosure(t *testing.T) {
},
}
php7parser := php7.NewParser([]byte(src))
php7parser := php7.NewParser([]byte(src), "7.4")
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser([]byte(src))
php5parser := php5.NewParser([]byte(src), "5.6")
php5parser.Parse()
actual = php5parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
@@ -203,12 +203,12 @@ func TestClosureUse(t *testing.T) {
},
}
php7parser := php7.NewParser([]byte(src))
php7parser := php7.NewParser([]byte(src), "7.4")
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser([]byte(src))
php5parser := php5.NewParser([]byte(src), "5.6")
php5parser.Parse()
actual = php5parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
@@ -356,12 +356,12 @@ func TestClosureUse2(t *testing.T) {
},
}
php7parser := php7.NewParser([]byte(src))
php7parser := php7.NewParser([]byte(src), "7.4")
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser([]byte(src))
php5parser := php5.NewParser([]byte(src), "5.6")
php5parser.Parse()
actual = php5parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
@@ -420,7 +420,7 @@ func TestClosureReturnType(t *testing.T) {
},
}
php7parser := php7.NewParser([]byte(src))
php7parser := php7.NewParser([]byte(src), "7.4")
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)

View File

@@ -65,12 +65,12 @@ func TestConstFetch(t *testing.T) {
},
}
php7parser := php7.NewParser([]byte(src))
php7parser := php7.NewParser([]byte(src), "7.4")
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser([]byte(src))
php5parser := php5.NewParser([]byte(src), "5.6")
php5parser.Parse()
actual = php5parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
@@ -125,12 +125,12 @@ func TestConstFetchRelative(t *testing.T) {
},
}
php7parser := php7.NewParser([]byte(src))
php7parser := php7.NewParser([]byte(src), "7.4")
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser([]byte(src))
php5parser := php5.NewParser([]byte(src), "5.6")
php5parser.Parse()
actual = php5parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
@@ -185,12 +185,12 @@ func TestConstFetchFullyQualified(t *testing.T) {
},
}
php7parser := php7.NewParser([]byte(src))
php7parser := php7.NewParser([]byte(src), "7.4")
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser([]byte(src))
php5parser := php5.NewParser([]byte(src), "5.6")
php5parser.Parse()
actual = php5parser.GetRootNode()
assert.DeepEqual(t, expected, actual)

View File

@@ -61,12 +61,12 @@ func TestEmpty(t *testing.T) {
},
}
php7parser := php7.NewParser([]byte(src))
php7parser := php7.NewParser([]byte(src), "7.4")
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser([]byte(src))
php5parser := php5.NewParser([]byte(src), "5.6")
php5parser.Parse()
actual = php5parser.GetRootNode()
assert.DeepEqual(t, expected, actual)

View File

@@ -61,12 +61,12 @@ func TestErrorSuppress(t *testing.T) {
},
}
php7parser := php7.NewParser([]byte(src))
php7parser := php7.NewParser([]byte(src), "7.4")
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser([]byte(src))
php5parser := php5.NewParser([]byte(src), "5.6")
php5parser.Parse()
actual = php5parser.GetRootNode()
assert.DeepEqual(t, expected, actual)

View File

@@ -61,12 +61,12 @@ func TestEval(t *testing.T) {
},
}
php7parser := php7.NewParser([]byte(src))
php7parser := php7.NewParser([]byte(src), "7.4")
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser([]byte(src))
php5parser := php5.NewParser([]byte(src), "5.6")
php5parser.Parse()
actual = php5parser.GetRootNode()
assert.DeepEqual(t, expected, actual)

View File

@@ -45,12 +45,12 @@ func TestExit(t *testing.T) {
},
}
php7parser := php7.NewParser([]byte(src))
php7parser := php7.NewParser([]byte(src), "7.4")
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser([]byte(src))
php5parser := php5.NewParser([]byte(src), "5.6")
php5parser.Parse()
actual = php5parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
@@ -87,12 +87,12 @@ func TestExitEmpty(t *testing.T) {
},
}
php7parser := php7.NewParser([]byte(src))
php7parser := php7.NewParser([]byte(src), "7.4")
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser([]byte(src))
php5parser := php5.NewParser([]byte(src), "5.6")
php5parser.Parse()
actual = php5parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
@@ -146,12 +146,12 @@ func TestExitExpr(t *testing.T) {
},
}
php7parser := php7.NewParser([]byte(src))
php7parser := php7.NewParser([]byte(src), "7.4")
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser([]byte(src))
php5parser := php5.NewParser([]byte(src), "5.6")
php5parser.Parse()
actual = php5parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
@@ -188,12 +188,12 @@ func TestDie(t *testing.T) {
},
}
php7parser := php7.NewParser([]byte(src))
php7parser := php7.NewParser([]byte(src), "7.4")
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser([]byte(src))
php5parser := php5.NewParser([]byte(src), "5.6")
php5parser.Parse()
actual = php5parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
@@ -230,12 +230,12 @@ func TestDieEmpty(t *testing.T) {
},
}
php7parser := php7.NewParser([]byte(src))
php7parser := php7.NewParser([]byte(src), "7.4")
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser([]byte(src))
php5parser := php5.NewParser([]byte(src), "5.6")
php5parser.Parse()
actual = php5parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
@@ -289,12 +289,12 @@ func TestDieExpr(t *testing.T) {
},
}
php7parser := php7.NewParser([]byte(src))
php7parser := php7.NewParser([]byte(src), "7.4")
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser([]byte(src))
php5parser := php5.NewParser([]byte(src), "5.6")
php5parser.Parse()
actual = php5parser.GetRootNode()
assert.DeepEqual(t, expected, actual)

View File

@@ -35,6 +35,9 @@ var nodes = []node.Node{
&expr.Array{
FreeFloating: expected,
},
&expr.ArrowFunction{
FreeFloating: expected,
},
&expr.BitwiseNot{
FreeFloating: expected,
},

View File

@@ -76,12 +76,12 @@ func TestFunctionCall(t *testing.T) {
},
}
php7parser := php7.NewParser([]byte(src))
php7parser := php7.NewParser([]byte(src), "7.4")
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser([]byte(src))
php5parser := php5.NewParser([]byte(src), "5.6")
php5parser.Parse()
actual = php5parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
@@ -144,12 +144,12 @@ func TestFunctionCallRelative(t *testing.T) {
},
}
php7parser := php7.NewParser([]byte(src))
php7parser := php7.NewParser([]byte(src), "7.4")
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser([]byte(src))
php5parser := php5.NewParser([]byte(src), "5.6")
php5parser.Parse()
actual = php5parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
@@ -233,12 +233,12 @@ func TestFunctionFullyQualified(t *testing.T) {
},
}
php7parser := php7.NewParser([]byte(src))
php7parser := php7.NewParser([]byte(src), "7.4")
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser([]byte(src))
php5parser := php5.NewParser([]byte(src), "5.6")
php5parser.Parse()
actual = php5parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
@@ -336,12 +336,12 @@ func TestFunctionCallVar(t *testing.T) {
},
}
php7parser := php7.NewParser([]byte(src))
php7parser := php7.NewParser([]byte(src), "7.4")
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser([]byte(src))
php5parser := php5.NewParser([]byte(src), "5.6")
php5parser.Parse()
actual = php5parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
@@ -450,12 +450,12 @@ func TestFunctionCallExprArg(t *testing.T) {
},
}
php7parser := php7.NewParser([]byte(src))
php7parser := php7.NewParser([]byte(src), "7.4")
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser([]byte(src))
php5parser := php5.NewParser([]byte(src), "5.6")
php5parser.Parse()
actual = php5parser.GetRootNode()
assert.DeepEqual(t, expected, actual)

View File

@@ -61,12 +61,12 @@ func TestPostDec(t *testing.T) {
},
}
php7parser := php7.NewParser([]byte(src))
php7parser := php7.NewParser([]byte(src), "7.4")
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser([]byte(src))
php5parser := php5.NewParser([]byte(src), "5.6")
php5parser.Parse()
actual = php5parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
@@ -119,12 +119,12 @@ func TestPostInc(t *testing.T) {
},
}
php7parser := php7.NewParser([]byte(src))
php7parser := php7.NewParser([]byte(src), "7.4")
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser([]byte(src))
php5parser := php5.NewParser([]byte(src), "5.6")
php5parser.Parse()
actual = php5parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
@@ -177,12 +177,12 @@ func TestPreDec(t *testing.T) {
},
}
php7parser := php7.NewParser([]byte(src))
php7parser := php7.NewParser([]byte(src), "7.4")
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser([]byte(src))
php5parser := php5.NewParser([]byte(src), "5.6")
php5parser.Parse()
actual = php5parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
@@ -235,12 +235,12 @@ func TestPreInc(t *testing.T) {
},
}
php7parser := php7.NewParser([]byte(src))
php7parser := php7.NewParser([]byte(src), "7.4")
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser([]byte(src))
php5parser := php5.NewParser([]byte(src), "5.6")
php5parser.Parse()
actual = php5parser.GetRootNode()
assert.DeepEqual(t, expected, actual)

View File

@@ -61,12 +61,12 @@ func TestInclude(t *testing.T) {
},
}
php7parser := php7.NewParser([]byte(src))
php7parser := php7.NewParser([]byte(src), "7.4")
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser([]byte(src))
php5parser := php5.NewParser([]byte(src), "5.6")
php5parser.Parse()
actual = php5parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
@@ -119,12 +119,12 @@ func TestIncludeOnce(t *testing.T) {
},
}
php7parser := php7.NewParser([]byte(src))
php7parser := php7.NewParser([]byte(src), "7.4")
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser([]byte(src))
php5parser := php5.NewParser([]byte(src), "5.6")
php5parser.Parse()
actual = php5parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
@@ -177,12 +177,12 @@ func TestRequire(t *testing.T) {
},
}
php7parser := php7.NewParser([]byte(src))
php7parser := php7.NewParser([]byte(src), "7.4")
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser([]byte(src))
php5parser := php5.NewParser([]byte(src), "5.6")
php5parser.Parse()
actual = php5parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
@@ -235,12 +235,12 @@ func TestRequireOnce(t *testing.T) {
},
}
php7parser := php7.NewParser([]byte(src))
php7parser := php7.NewParser([]byte(src), "7.4")
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser([]byte(src))
php5parser := php5.NewParser([]byte(src), "5.6")
php5parser.Parse()
actual = php5parser.GetRootNode()
assert.DeepEqual(t, expected, actual)

View File

@@ -82,12 +82,12 @@ func TestInstanceOf(t *testing.T) {
},
}
php7parser := php7.NewParser([]byte(src))
php7parser := php7.NewParser([]byte(src), "7.4")
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser([]byte(src))
php5parser := php5.NewParser([]byte(src), "5.6")
php5parser.Parse()
actual = php5parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
@@ -159,12 +159,12 @@ func TestInstanceOfRelative(t *testing.T) {
},
}
php7parser := php7.NewParser([]byte(src))
php7parser := php7.NewParser([]byte(src), "7.4")
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser([]byte(src))
php5parser := php5.NewParser([]byte(src), "5.6")
php5parser.Parse()
actual = php5parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
@@ -236,12 +236,12 @@ func TestInstanceOfFullyQualified(t *testing.T) {
},
}
php7parser := php7.NewParser([]byte(src))
php7parser := php7.NewParser([]byte(src), "7.4")
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser([]byte(src))
php5parser := php5.NewParser([]byte(src), "5.6")
php5parser.Parse()
actual = php5parser.GetRootNode()
assert.DeepEqual(t, expected, actual)

View File

@@ -63,12 +63,12 @@ func TestIsset(t *testing.T) {
},
}
php7parser := php7.NewParser([]byte(src))
php7parser := php7.NewParser([]byte(src), "7.4")
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser([]byte(src))
php5parser := php5.NewParser([]byte(src), "5.6")
php5parser.Parse()
actual = php5parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
@@ -140,12 +140,12 @@ func TestIssetVariables(t *testing.T) {
},
}
php7parser := php7.NewParser([]byte(src))
php7parser := php7.NewParser([]byte(src), "7.4")
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser([]byte(src))
php5parser := php5.NewParser([]byte(src), "5.6")
php5parser.Parse()
actual = php5parser.GetRootNode()
assert.DeepEqual(t, expected, actual)

View File

@@ -70,12 +70,12 @@ func TestEmptyList(t *testing.T) {
},
}
php7parser := php7.NewParser([]byte(src))
php7parser := php7.NewParser([]byte(src), "7.4")
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser([]byte(src))
php5parser := php5.NewParser([]byte(src), "5.6")
php5parser.Parse()
actual = php5parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
@@ -163,12 +163,12 @@ func TestList(t *testing.T) {
},
}
php7parser := php7.NewParser([]byte(src))
php7parser := php7.NewParser([]byte(src), "7.4")
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser([]byte(src))
php5parser := php5.NewParser([]byte(src), "5.6")
php5parser.Parse()
actual = php5parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
@@ -264,12 +264,12 @@ func TestListArrayIndex(t *testing.T) {
},
}
php7parser := php7.NewParser([]byte(src))
php7parser := php7.NewParser([]byte(src), "7.4")
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser([]byte(src))
php5parser := php5.NewParser([]byte(src), "5.6")
php5parser.Parse()
actual = php5parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
@@ -375,12 +375,12 @@ func TestListList(t *testing.T) {
},
}
php7parser := php7.NewParser([]byte(src))
php7parser := php7.NewParser([]byte(src), "7.4")
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser([]byte(src))
php5parser := php5.NewParser([]byte(src), "5.6")
php5parser.Parse()
actual = php5parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
@@ -469,12 +469,12 @@ func TestListEmptyItem(t *testing.T) {
},
}
php7parser := php7.NewParser([]byte(src))
php7parser := php7.NewParser([]byte(src), "7.4")
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser([]byte(src))
php5parser := php5.NewParser([]byte(src), "5.6")
php5parser.Parse()
actual = php5parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
@@ -565,12 +565,12 @@ func TestListEmptyItems(t *testing.T) {
},
}
php7parser := php7.NewParser([]byte(src))
php7parser := php7.NewParser([]byte(src), "7.4")
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser([]byte(src))
php5parser := php5.NewParser([]byte(src), "5.6")
php5parser.Parse()
actual = php5parser.GetRootNode()
assert.DeepEqual(t, expected, actual)

View File

@@ -78,12 +78,12 @@ func TestMethodCall(t *testing.T) {
},
}
php7parser := php7.NewParser([]byte(src))
php7parser := php7.NewParser([]byte(src), "7.4")
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser([]byte(src))
php5parser := php5.NewParser([]byte(src), "5.6")
php5parser.Parse()
actual = php5parser.GetRootNode()
assert.DeepEqual(t, expected, actual)

View File

@@ -65,12 +65,12 @@ func TestNew(t *testing.T) {
},
}
php7parser := php7.NewParser([]byte(src))
php7parser := php7.NewParser([]byte(src), "7.4")
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser([]byte(src))
php5parser := php5.NewParser([]byte(src), "5.6")
php5parser.Parse()
actual = php5parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
@@ -133,12 +133,12 @@ func TestNewRelative(t *testing.T) {
},
}
php7parser := php7.NewParser([]byte(src))
php7parser := php7.NewParser([]byte(src), "7.4")
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser([]byte(src))
php5parser := php5.NewParser([]byte(src), "5.6")
php5parser.Parse()
actual = php5parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
@@ -201,12 +201,12 @@ func TestNewFullyQualified(t *testing.T) {
},
}
php7parser := php7.NewParser([]byte(src))
php7parser := php7.NewParser([]byte(src), "7.4")
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser([]byte(src))
php5parser := php5.NewParser([]byte(src), "5.6")
php5parser.Parse()
actual = php5parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
@@ -316,7 +316,7 @@ func TestNewAnonymous(t *testing.T) {
},
}
php7parser := php7.NewParser([]byte(src))
php7parser := php7.NewParser([]byte(src), "7.4")
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)

View File

@@ -61,12 +61,12 @@ func TestPrint(t *testing.T) {
},
}
php7parser := php7.NewParser([]byte(src))
php7parser := php7.NewParser([]byte(src), "7.4")
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser([]byte(src))
php5parser := php5.NewParser([]byte(src), "5.6")
php5parser.Parse()
actual = php5parser.GetRootNode()
assert.DeepEqual(t, expected, actual)

View File

@@ -70,12 +70,12 @@ func TestPropertyFetch(t *testing.T) {
},
}
php7parser := php7.NewParser([]byte(src))
php7parser := php7.NewParser([]byte(src), "7.4")
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser([]byte(src))
php5parser := php5.NewParser([]byte(src), "5.6")
php5parser.Parse()
actual = php5parser.GetRootNode()
assert.DeepEqual(t, expected, actual)

View File

@@ -105,12 +105,12 @@ func TestForeachWithRef(t *testing.T) {
},
}
php7parser := php7.NewParser([]byte(src))
php7parser := php7.NewParser([]byte(src), "7.4")
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser([]byte(src))
php5parser := php5.NewParser([]byte(src), "5.6")
php5parser.Parse()
actual = php5parser.GetRootNode()
assert.DeepEqual(t, expected, actual)

View File

@@ -74,12 +74,12 @@ func TestShellExec(t *testing.T) {
},
}
php7parser := php7.NewParser([]byte(src))
php7parser := php7.NewParser([]byte(src), "7.4")
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser([]byte(src))
php5parser := php5.NewParser([]byte(src), "5.6")
php5parser.Parse()
actual = php5parser.GetRootNode()
assert.DeepEqual(t, expected, actual)

View File

@@ -45,12 +45,12 @@ func TestShortArray(t *testing.T) {
},
}
php7parser := php7.NewParser([]byte(src))
php7parser := php7.NewParser([]byte(src), "7.4")
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser([]byte(src))
php5parser := php5.NewParser([]byte(src), "5.6")
php5parser.Parse()
actual = php5parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
@@ -105,12 +105,12 @@ func TestShortArrayItem(t *testing.T) {
},
}
php7parser := php7.NewParser([]byte(src))
php7parser := php7.NewParser([]byte(src), "7.4")
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser([]byte(src))
php5parser := php5.NewParser([]byte(src), "5.6")
php5parser.Parse()
actual = php5parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
@@ -208,12 +208,12 @@ func TestShortArrayItems(t *testing.T) {
},
}
php7parser := php7.NewParser([]byte(src))
php7parser := php7.NewParser([]byte(src), "7.4")
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser([]byte(src))
php5parser := php5.NewParser([]byte(src), "5.6")
php5parser.Parse()
actual = php5parser.GetRootNode()
assert.DeepEqual(t, expected, actual)

View File

@@ -95,7 +95,7 @@ func TestShortList(t *testing.T) {
},
}
php7parser := php7.NewParser([]byte(src))
php7parser := php7.NewParser([]byte(src), "7.4")
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
@@ -191,7 +191,7 @@ func TestShortListArrayIndex(t *testing.T) {
},
}
php7parser := php7.NewParser([]byte(src))
php7parser := php7.NewParser([]byte(src), "7.4")
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
@@ -297,7 +297,7 @@ func TestShortListList(t *testing.T) {
},
}
php7parser := php7.NewParser([]byte(src))
php7parser := php7.NewParser([]byte(src), "7.4")
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)

View File

@@ -82,12 +82,12 @@ func TestStaticCall(t *testing.T) {
},
}
php7parser := php7.NewParser([]byte(src))
php7parser := php7.NewParser([]byte(src), "7.4")
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser([]byte(src))
php5parser := php5.NewParser([]byte(src), "5.6")
php5parser.Parse()
actual = php5parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
@@ -159,12 +159,12 @@ func TestStaticCallRelative(t *testing.T) {
},
}
php7parser := php7.NewParser([]byte(src))
php7parser := php7.NewParser([]byte(src), "7.4")
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser([]byte(src))
php5parser := php5.NewParser([]byte(src), "5.6")
php5parser.Parse()
actual = php5parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
@@ -236,12 +236,12 @@ func TestStaticCallFullyQualified(t *testing.T) {
},
}
php7parser := php7.NewParser([]byte(src))
php7parser := php7.NewParser([]byte(src), "7.4")
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser([]byte(src))
php5parser := php5.NewParser([]byte(src), "5.6")
php5parser.Parse()
actual = php5parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
@@ -321,12 +321,12 @@ func TestStaticCallVar(t *testing.T) {
},
}
php7parser := php7.NewParser([]byte(src))
php7parser := php7.NewParser([]byte(src), "7.4")
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser([]byte(src))
php5parser := php5.NewParser([]byte(src), "5.6")
php5parser.Parse()
actual = php5parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
@@ -404,12 +404,12 @@ func TestStaticCallVarVar(t *testing.T) {
},
}
php7parser := php7.NewParser([]byte(src))
php7parser := php7.NewParser([]byte(src), "7.4")
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser([]byte(src))
php5parser := php5.NewParser([]byte(src), "5.6")
php5parser.Parse()
actual = php5parser.GetRootNode()
assert.DeepEqual(t, expected, actual)

View File

@@ -81,12 +81,12 @@ func TestStaticPropertyFetch(t *testing.T) {
},
}
php7parser := php7.NewParser([]byte(src))
php7parser := php7.NewParser([]byte(src), "7.4")
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser([]byte(src))
php5parser := php5.NewParser([]byte(src), "5.6")
php5parser.Parse()
actual = php5parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
@@ -158,12 +158,12 @@ func TestStaticPropertyFetchRelative(t *testing.T) {
},
}
php7parser := php7.NewParser([]byte(src))
php7parser := php7.NewParser([]byte(src), "7.4")
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser([]byte(src))
php5parser := php5.NewParser([]byte(src), "5.6")
php5parser.Parse()
actual = php5parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
@@ -235,12 +235,12 @@ func TestStaticPropertyFetchFullyQualified(t *testing.T) {
},
}
php7parser := php7.NewParser([]byte(src))
php7parser := php7.NewParser([]byte(src), "7.4")
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser([]byte(src))
php5parser := php5.NewParser([]byte(src), "5.6")
php5parser.Parse()
actual = php5parser.GetRootNode()
assert.DeepEqual(t, expected, actual)

View File

@@ -95,12 +95,12 @@ func TestTernary(t *testing.T) {
},
}
php7parser := php7.NewParser([]byte(src))
php7parser := php7.NewParser([]byte(src), "7.4")
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser([]byte(src))
php5parser := php5.NewParser([]byte(src), "5.6")
php5parser.Parse()
actual = php5parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
@@ -170,12 +170,12 @@ func TestTernarySimple(t *testing.T) {
},
}
php7parser := php7.NewParser([]byte(src))
php7parser := php7.NewParser([]byte(src), "7.4")
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser([]byte(src))
php5parser := php5.NewParser([]byte(src), "5.6")
php5parser.Parse()
actual = php5parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
@@ -304,12 +304,12 @@ func TestTernaryNestedTrue(t *testing.T) {
},
}
php7parser := php7.NewParser([]byte(src))
php7parser := php7.NewParser([]byte(src), "7.4")
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser([]byte(src))
php5parser := php5.NewParser([]byte(src), "5.6")
php5parser.Parse()
actual = php5parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
@@ -438,12 +438,12 @@ func TestTernaryNestedCond(t *testing.T) {
},
}
php7parser := php7.NewParser([]byte(src))
php7parser := php7.NewParser([]byte(src), "7.4")
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser([]byte(src))
php5parser := php5.NewParser([]byte(src), "5.6")
php5parser.Parse()
actual = php5parser.GetRootNode()
assert.DeepEqual(t, expected, actual)

View File

@@ -61,12 +61,12 @@ func TestUnaryMinus(t *testing.T) {
},
}
php7parser := php7.NewParser([]byte(src))
php7parser := php7.NewParser([]byte(src), "7.4")
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser([]byte(src))
php5parser := php5.NewParser([]byte(src), "5.6")
php5parser.Parse()
actual = php5parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
@@ -119,12 +119,12 @@ func TestUnaryPlus(t *testing.T) {
},
}
php7parser := php7.NewParser([]byte(src))
php7parser := php7.NewParser([]byte(src), "7.4")
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser([]byte(src))
php5parser := php5.NewParser([]byte(src), "5.6")
php5parser.Parse()
actual = php5parser.GetRootNode()
assert.DeepEqual(t, expected, actual)

View File

@@ -53,12 +53,12 @@ func TestVariable(t *testing.T) {
},
}
php7parser := php7.NewParser([]byte(src))
php7parser := php7.NewParser([]byte(src), "7.4")
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser([]byte(src))
php5parser := php5.NewParser([]byte(src), "5.6")
php5parser.Parse()
actual = php5parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
@@ -111,12 +111,12 @@ func TestVariableVariable(t *testing.T) {
},
}
php7parser := php7.NewParser([]byte(src))
php7parser := php7.NewParser([]byte(src), "7.4")
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser([]byte(src))
php5parser := php5.NewParser([]byte(src), "5.6")
php5parser.Parse()
actual = php5parser.GetRootNode()
assert.DeepEqual(t, expected, actual)

View File

@@ -31,11 +31,12 @@ var nodesToTest = []struct {
},
{
&expr.ArrayItem{
Key: &scalar.String{Value: "key"},
Val: &scalar.Lnumber{Value: "1"},
Key: &scalar.String{Value: "key"},
Val: &scalar.Lnumber{Value: "1"},
Unpack: true,
},
[]string{"Key", "Val"},
nil,
map[string]interface{}{"Unpack": true},
},
{
&expr.Array{
@@ -97,6 +98,18 @@ var nodesToTest = []struct {
[]string{"Params", "ClosureUse", "ReturnType", "Stmts"},
map[string]interface{}{"ReturnsRef": true, "Static": false, "PhpDocComment": ""},
},
{
&expr.ArrowFunction{
ReturnsRef: true,
Static: false,
PhpDocComment: "",
Params: []node.Node{&node.Parameter{}},
ReturnType: &name.Name{},
Expr: &expr.Variable{},
},
[]string{"Params", "ReturnType", "Expr"},
map[string]interface{}{"ReturnsRef": true, "Static": false, "PhpDocComment": ""},
},
{
&expr.ConstFetch{
Constant: &node.Identifier{Value: "foo"},

View File

@@ -45,12 +45,12 @@ func TestYield(t *testing.T) {
},
}
php7parser := php7.NewParser([]byte(src))
php7parser := php7.NewParser([]byte(src), "7.4")
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser([]byte(src))
php5parser := php5.NewParser([]byte(src), "5.6")
php5parser.Parse()
actual = php5parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
@@ -103,12 +103,12 @@ func TestYieldVal(t *testing.T) {
},
}
php7parser := php7.NewParser([]byte(src))
php7parser := php7.NewParser([]byte(src), "7.4")
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser([]byte(src))
php5parser := php5.NewParser([]byte(src), "5.6")
php5parser.Parse()
actual = php5parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
@@ -178,12 +178,12 @@ func TestYieldKeyVal(t *testing.T) {
},
}
php7parser := php7.NewParser([]byte(src))
php7parser := php7.NewParser([]byte(src), "7.4")
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser([]byte(src))
php5parser := php5.NewParser([]byte(src), "5.6")
php5parser.Parse()
actual = php5parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
@@ -228,12 +228,12 @@ func TestYieldExpr(t *testing.T) {
},
}
php7parser := php7.NewParser([]byte(src))
php7parser := php7.NewParser([]byte(src), "7.4")
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser([]byte(src))
php5parser := php5.NewParser([]byte(src), "5.6")
php5parser.Parse()
actual = php5parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
@@ -295,12 +295,12 @@ func TestYieldKeyExpr(t *testing.T) {
},
}
php7parser := php7.NewParser([]byte(src))
php7parser := php7.NewParser([]byte(src), "7.4")
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser([]byte(src))
php5parser := php5.NewParser([]byte(src), "5.6")
php5parser.Parse()
actual = php5parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
@@ -353,7 +353,7 @@ func TestYieldFrom(t *testing.T) {
},
}
php7parser := php7.NewParser([]byte(src))
php7parser := php7.NewParser([]byte(src), "7.4")
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)

View File

@@ -72,12 +72,12 @@ func TestName(t *testing.T) {
},
}
php7parser := php7.NewParser([]byte(src))
php7parser := php7.NewParser([]byte(src), "7.4")
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser([]byte(src))
php5parser := php5.NewParser([]byte(src), "5.6")
php5parser.Parse()
actual = php5parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
@@ -140,12 +140,12 @@ func TestFullyQualified(t *testing.T) {
},
}
php7parser := php7.NewParser([]byte(src))
php7parser := php7.NewParser([]byte(src), "7.4")
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser([]byte(src))
php5parser := php5.NewParser([]byte(src), "5.6")
php5parser.Parse()
actual = php5parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
@@ -208,12 +208,12 @@ func TestRelative(t *testing.T) {
},
}
php7parser := php7.NewParser([]byte(src))
php7parser := php7.NewParser([]byte(src), "7.4")
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser([]byte(src))
php5parser := php5.NewParser([]byte(src), "5.6")
php5parser.Parse()
actual = php5parser.GetRootNode()
assert.DeepEqual(t, expected, actual)

View File

@@ -73,12 +73,12 @@ func TestSimpleVar(t *testing.T) {
},
}
php7parser := php7.NewParser([]byte(src))
php7parser := php7.NewParser([]byte(src), "7.4")
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser([]byte(src))
php5parser := php5.NewParser([]byte(src), "5.6")
php5parser.Parse()
actual = php5parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
@@ -142,12 +142,12 @@ func TestSimpleVarOneChar(t *testing.T) {
},
}
php7parser := php7.NewParser([]byte(src))
php7parser := php7.NewParser([]byte(src), "7.4")
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser([]byte(src))
php5parser := php5.NewParser([]byte(src), "5.6")
php5parser.Parse()
actual = php5parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
@@ -220,12 +220,12 @@ func TestSimpleVarEndsEcapsed(t *testing.T) {
},
}
php7parser := php7.NewParser([]byte(src))
php7parser := php7.NewParser([]byte(src), "7.4")
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser([]byte(src))
php5parser := php5.NewParser([]byte(src), "5.6")
php5parser.Parse()
actual = php5parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
@@ -306,12 +306,12 @@ func TestStringVarCurveOpen(t *testing.T) {
},
}
php7parser := php7.NewParser([]byte(src))
php7parser := php7.NewParser([]byte(src), "7.4")
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser([]byte(src))
php5parser := php5.NewParser([]byte(src), "5.6")
php5parser.Parse()
actual = php5parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
@@ -401,12 +401,12 @@ func TestSimpleVarPropertyFetch(t *testing.T) {
},
}
php7parser := php7.NewParser([]byte(src))
php7parser := php7.NewParser([]byte(src), "7.4")
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser([]byte(src))
php5parser := php5.NewParser([]byte(src), "5.6")
php5parser.Parse()
actual = php5parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
@@ -470,12 +470,12 @@ func TestDollarOpenCurlyBraces(t *testing.T) {
},
}
php7parser := php7.NewParser([]byte(src))
php7parser := php7.NewParser([]byte(src), "7.4")
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser([]byte(src))
php5parser := php5.NewParser([]byte(src), "5.6")
php5parser.Parse()
actual = php5parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
@@ -556,12 +556,12 @@ func TestDollarOpenCurlyBracesDimNumber(t *testing.T) {
},
}
php7parser := php7.NewParser([]byte(src))
php7parser := php7.NewParser([]byte(src), "7.4")
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser([]byte(src))
php5parser := php5.NewParser([]byte(src), "5.6")
php5parser.Parse()
actual = php5parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
@@ -650,12 +650,12 @@ func TestCurlyOpenMethodCall(t *testing.T) {
},
}
php7parser := php7.NewParser([]byte(src))
php7parser := php7.NewParser([]byte(src), "7.4")
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser([]byte(src))
php5parser := php5.NewParser([]byte(src), "5.6")
php5parser.Parse()
actual = php5parser.GetRootNode()
assert.DeepEqual(t, expected, actual)

View File

@@ -86,12 +86,12 @@ LBL;
},
}
php7parser := php7.NewParser([]byte(src))
php7parser := php7.NewParser([]byte(src), "7.4")
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser([]byte(src))
php5parser := php5.NewParser([]byte(src), "5.6")
php5parser.Parse()
actual = php5parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
@@ -168,12 +168,12 @@ LBL;
},
}
php7parser := php7.NewParser([]byte(src))
php7parser := php7.NewParser([]byte(src), "7.4")
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser([]byte(src))
php5parser := php5.NewParser([]byte(src), "5.6")
php5parser.Parse()
actual = php5parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
@@ -224,12 +224,12 @@ LBL;
},
}
php7parser := php7.NewParser([]byte(src))
php7parser := php7.NewParser([]byte(src), "7.4")
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser([]byte(src))
php5parser := php5.NewParser([]byte(src), "5.6")
php5parser.Parse()
actual = php5parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
@@ -268,12 +268,12 @@ CAD;
},
}
php7parser := php7.NewParser([]byte(src))
php7parser := php7.NewParser([]byte(src), "7.4")
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser([]byte(src))
php5parser := php5.NewParser([]byte(src), "5.6")
php5parser.Parse()
actual = php5parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
@@ -324,12 +324,12 @@ CAD;
},
}
php7parser := php7.NewParser([]byte(src))
php7parser := php7.NewParser([]byte(src), "7.4")
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser([]byte(src))
php5parser := php5.NewParser([]byte(src), "5.6")
php5parser.Parse()
actual = php5parser.GetRootNode()
assert.DeepEqual(t, expected, actual)

View File

@@ -45,12 +45,12 @@ func TestMagicConstant(t *testing.T) {
},
}
php7parser := php7.NewParser([]byte(src))
php7parser := php7.NewParser([]byte(src), "7.4")
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser([]byte(src))
php5parser := php5.NewParser([]byte(src), "5.6")
php5parser.Parse()
actual = php5parser.GetRootNode()
assert.DeepEqual(t, expected, actual)

View File

@@ -44,12 +44,12 @@ func TestLNumber(t *testing.T) {
},
}
php7parser := php7.NewParser([]byte(src))
php7parser := php7.NewParser([]byte(src), "7.4")
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser([]byte(src))
php5parser := php5.NewParser([]byte(src), "5.6")
php5parser.Parse()
actual = php5parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
@@ -86,12 +86,12 @@ func TestDNumber(t *testing.T) {
},
}
php7parser := php7.NewParser([]byte(src))
php7parser := php7.NewParser([]byte(src), "7.4")
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser([]byte(src))
php5parser := php5.NewParser([]byte(src), "5.6")
php5parser.Parse()
actual = php5parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
@@ -128,12 +128,12 @@ func TestFloat(t *testing.T) {
},
}
php7parser := php7.NewParser([]byte(src))
php7parser := php7.NewParser([]byte(src), "7.4")
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser([]byte(src))
php5parser := php5.NewParser([]byte(src), "5.6")
php5parser.Parse()
actual = php5parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
@@ -170,12 +170,12 @@ func TestBinaryLNumber(t *testing.T) {
},
}
php7parser := php7.NewParser([]byte(src))
php7parser := php7.NewParser([]byte(src), "7.4")
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser([]byte(src))
php5parser := php5.NewParser([]byte(src), "5.6")
php5parser.Parse()
actual = php5parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
@@ -212,12 +212,12 @@ func TestBinaryDNumber(t *testing.T) {
},
}
php7parser := php7.NewParser([]byte(src))
php7parser := php7.NewParser([]byte(src), "7.4")
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser([]byte(src))
php5parser := php5.NewParser([]byte(src), "5.6")
php5parser.Parse()
actual = php5parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
@@ -254,12 +254,12 @@ func TestHLNumber(t *testing.T) {
},
}
php7parser := php7.NewParser([]byte(src))
php7parser := php7.NewParser([]byte(src), "7.4")
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser([]byte(src))
php5parser := php5.NewParser([]byte(src), "5.6")
php5parser.Parse()
actual = php5parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
@@ -296,12 +296,12 @@ func TestHDNumber(t *testing.T) {
},
}
php7parser := php7.NewParser([]byte(src))
php7parser := php7.NewParser([]byte(src), "7.4")
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser([]byte(src))
php5parser := php5.NewParser([]byte(src), "5.6")
php5parser.Parse()
actual = php5parser.GetRootNode()
assert.DeepEqual(t, expected, actual)

View File

@@ -44,12 +44,12 @@ func TestDoubleQuotedScalarString(t *testing.T) {
},
}
php7parser := php7.NewParser([]byte(src))
php7parser := php7.NewParser([]byte(src), "7.4")
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser([]byte(src))
php5parser := php5.NewParser([]byte(src), "5.6")
php5parser.Parse()
actual = php5parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
@@ -86,12 +86,12 @@ func TestDoubleQuotedScalarStringWithEscapedVar(t *testing.T) {
},
}
php7parser := php7.NewParser([]byte(src))
php7parser := php7.NewParser([]byte(src), "7.4")
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser([]byte(src))
php5parser := php5.NewParser([]byte(src), "5.6")
php5parser.Parse()
actual = php5parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
@@ -130,12 +130,12 @@ func TestMultilineDoubleQuotedScalarString(t *testing.T) {
},
}
php7parser := php7.NewParser([]byte(src))
php7parser := php7.NewParser([]byte(src), "7.4")
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser([]byte(src))
php5parser := php5.NewParser([]byte(src), "5.6")
php5parser.Parse()
actual = php5parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
@@ -172,12 +172,12 @@ func TestSingleQuotedScalarString(t *testing.T) {
},
}
php7parser := php7.NewParser([]byte(src))
php7parser := php7.NewParser([]byte(src), "7.4")
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser([]byte(src))
php5parser := php5.NewParser([]byte(src), "5.6")
php5parser.Parse()
actual = php5parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
@@ -216,12 +216,12 @@ func TestMultilineSingleQuotedScalarString(t *testing.T) {
},
}
php7parser := php7.NewParser([]byte(src))
php7parser := php7.NewParser([]byte(src), "7.4")
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser([]byte(src))
php5parser := php5.NewParser([]byte(src), "5.6")
php5parser.Parse()
actual = php5parser.GetRootNode()
assert.DeepEqual(t, expected, actual)

View File

@@ -12,14 +12,16 @@ type PropertyList struct {
FreeFloating freefloating.Collection
Position *position.Position
Modifiers []node.Node
Type node.Node
Properties []node.Node
}
// NewPropertyList node constructor
func NewPropertyList(Modifiers []node.Node, Properties []node.Node) *PropertyList {
func NewPropertyList(Modifiers []node.Node, Type node.Node, Properties []node.Node) *PropertyList {
return &PropertyList{
FreeFloating: nil,
Modifiers: Modifiers,
Type: Type,
Properties: Properties,
}
}
@@ -60,6 +62,12 @@ func (n *PropertyList) Walk(v walker.Visitor) {
v.LeaveChildList("Modifiers", n)
}
if n.Type != nil {
v.EnterChildNode("Type", n)
n.Type.Walk(v)
v.LeaveChildNode("Type", n)
}
if n.Properties != nil {
v.EnterChildList("Properties", n)
for _, nn := range n.Properties {

View File

@@ -64,12 +64,12 @@ func TestAltIf(t *testing.T) {
},
}
php7parser := php7.NewParser([]byte(src))
php7parser := php7.NewParser([]byte(src), "7.4")
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser([]byte(src))
php5parser := php5.NewParser([]byte(src), "5.6")
php5parser.Parse()
actual = php5parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
@@ -163,12 +163,12 @@ func TestAltElseIf(t *testing.T) {
},
}
php7parser := php7.NewParser([]byte(src))
php7parser := php7.NewParser([]byte(src), "7.4")
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser([]byte(src))
php5parser := php5.NewParser([]byte(src), "5.6")
php5parser.Parse()
actual = php5parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
@@ -243,12 +243,12 @@ func TestAltElse(t *testing.T) {
},
}
php7parser := php7.NewParser([]byte(src))
php7parser := php7.NewParser([]byte(src), "7.4")
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser([]byte(src))
php5parser := php5.NewParser([]byte(src), "5.6")
php5parser.Parse()
actual = php5parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
@@ -395,12 +395,12 @@ func TestAltElseElseIf(t *testing.T) {
},
}
php7parser := php7.NewParser([]byte(src))
php7parser := php7.NewParser([]byte(src), "7.4")
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser([]byte(src))
php5parser := php5.NewParser([]byte(src), "5.6")
php5parser.Parse()
actual = php5parser.GetRootNode()
assert.DeepEqual(t, expected, actual)

View File

@@ -123,7 +123,7 @@ func TestClassConstList(t *testing.T) {
},
}
php7parser := php7.NewParser([]byte(src))
php7parser := php7.NewParser([]byte(src), "7.4")
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
@@ -227,12 +227,12 @@ func TestClassConstListWithoutModifiers(t *testing.T) {
},
}
php7parser := php7.NewParser([]byte(src))
php7parser := php7.NewParser([]byte(src), "7.4")
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser([]byte(src))
php5parser := php5.NewParser([]byte(src), "5.6")
php5parser.Parse()
actual = php5parser.GetRootNode()
assert.DeepEqual(t, expected, actual)

View File

@@ -76,12 +76,12 @@ func TestSimpleClassMethod(t *testing.T) {
},
}
php7parser := php7.NewParser([]byte(src))
php7parser := php7.NewParser([]byte(src), "7.4")
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser([]byte(src))
php5parser := php5.NewParser([]byte(src), "5.6")
php5parser.Parse()
actual = php5parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
@@ -208,12 +208,12 @@ func TestPrivateProtectedClassMethod(t *testing.T) {
},
}
php7parser := php7.NewParser([]byte(src))
php7parser := php7.NewParser([]byte(src), "7.4")
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser([]byte(src))
php5parser := php5.NewParser([]byte(src), "5.6")
php5parser.Parse()
actual = php5parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
@@ -301,7 +301,7 @@ func TestPhp5ClassMethod(t *testing.T) {
},
}
php5parser := php5.NewParser([]byte(src))
php5parser := php5.NewParser([]byte(src), "5.6")
php5parser.Parse()
actual := php5parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
@@ -408,7 +408,7 @@ func TestPhp7ClassMethod(t *testing.T) {
},
}
php7parser := php7.NewParser([]byte(src))
php7parser := php7.NewParser([]byte(src), "7.4")
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
@@ -506,12 +506,12 @@ func TestAbstractClassMethod(t *testing.T) {
},
}
php7parser := php7.NewParser([]byte(src))
php7parser := php7.NewParser([]byte(src), "7.4")
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser([]byte(src))
php5parser := php5.NewParser([]byte(src), "5.6")
php5parser.Parse()
actual = php5parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
@@ -619,7 +619,7 @@ func TestPhp7AbstractClassMethod(t *testing.T) {
},
}
php7parser := php7.NewParser([]byte(src))
php7parser := php7.NewParser([]byte(src), "7.4")
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)

View File

@@ -48,12 +48,12 @@ func TestSimpleClass(t *testing.T) {
},
}
php7parser := php7.NewParser([]byte(src))
php7parser := php7.NewParser([]byte(src), "7.4")
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser([]byte(src))
php5parser := php5.NewParser([]byte(src), "5.6")
php5parser.Parse()
actual = php5parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
@@ -103,12 +103,12 @@ func TestAbstractClass(t *testing.T) {
},
}
php7parser := php7.NewParser([]byte(src))
php7parser := php7.NewParser([]byte(src), "7.4")
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser([]byte(src))
php5parser := php5.NewParser([]byte(src), "5.6")
php5parser.Parse()
actual = php5parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
@@ -185,12 +185,12 @@ func TestClassExtends(t *testing.T) {
},
}
php7parser := php7.NewParser([]byte(src))
php7parser := php7.NewParser([]byte(src), "7.4")
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser([]byte(src))
php5parser := php5.NewParser([]byte(src), "5.6")
php5parser.Parse()
actual = php5parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
@@ -269,12 +269,12 @@ func TestClassImplement(t *testing.T) {
},
}
php7parser := php7.NewParser([]byte(src))
php7parser := php7.NewParser([]byte(src), "7.4")
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser([]byte(src))
php5parser := php5.NewParser([]byte(src), "5.6")
php5parser.Parse()
actual = php5parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
@@ -372,12 +372,12 @@ func TestClassImplements(t *testing.T) {
},
}
php7parser := php7.NewParser([]byte(src))
php7parser := php7.NewParser([]byte(src), "7.4")
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser([]byte(src))
php5parser := php5.NewParser([]byte(src), "5.6")
php5parser.Parse()
actual = php5parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
@@ -506,7 +506,7 @@ func TestAnonimousClass(t *testing.T) {
},
}
php7parser := php7.NewParser([]byte(src))
php7parser := php7.NewParser([]byte(src), "7.4")
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)

View File

@@ -92,12 +92,12 @@ func TestConstList(t *testing.T) {
},
}
php7parser := php7.NewParser([]byte(src))
php7parser := php7.NewParser([]byte(src), "7.4")
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser([]byte(src))
php5parser := php5.NewParser([]byte(src), "5.6")
php5parser.Parse()
actual = php5parser.GetRootNode()
assert.DeepEqual(t, expected, actual)

View File

@@ -63,12 +63,12 @@ func TestContinueEmpty(t *testing.T) {
},
}
php7parser := php7.NewParser([]byte(src))
php7parser := php7.NewParser([]byte(src), "7.4")
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser([]byte(src))
php5parser := php5.NewParser([]byte(src), "5.6")
php5parser.Parse()
actual = php5parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
@@ -132,12 +132,12 @@ func TestContinueLight(t *testing.T) {
},
}
php7parser := php7.NewParser([]byte(src))
php7parser := php7.NewParser([]byte(src), "7.4")
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser([]byte(src))
php5parser := php5.NewParser([]byte(src), "5.6")
php5parser.Parse()
actual = php5parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
@@ -201,12 +201,12 @@ func TestContinue(t *testing.T) {
},
}
php7parser := php7.NewParser([]byte(src))
php7parser := php7.NewParser([]byte(src), "7.4")
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser([]byte(src))
php5parser := php5.NewParser([]byte(src), "5.6")
php5parser.Parse()
actual = php5parser.GetRootNode()
assert.DeepEqual(t, expected, actual)

View File

@@ -73,12 +73,12 @@ func TestDeclare(t *testing.T) {
},
}
php7parser := php7.NewParser([]byte(src))
php7parser := php7.NewParser([]byte(src), "7.4")
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser([]byte(src))
php5parser := php5.NewParser([]byte(src), "5.6")
php5parser.Parse()
actual = php5parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
@@ -171,12 +171,12 @@ func TestDeclareStmts(t *testing.T) {
},
}
php7parser := php7.NewParser([]byte(src))
php7parser := php7.NewParser([]byte(src), "7.4")
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser([]byte(src))
php5parser := php5.NewParser([]byte(src), "5.6")
php5parser.Parse()
actual = php5parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
@@ -243,12 +243,12 @@ func TestAltDeclare(t *testing.T) {
},
}
php7parser := php7.NewParser([]byte(src))
php7parser := php7.NewParser([]byte(src), "7.4")
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser([]byte(src))
php5parser := php5.NewParser([]byte(src), "5.6")
php5parser.Parse()
actual = php5parser.GetRootNode()
assert.DeepEqual(t, expected, actual)

View File

@@ -54,12 +54,12 @@ func TestDo(t *testing.T) {
},
}
php7parser := php7.NewParser([]byte(src))
php7parser := php7.NewParser([]byte(src), "7.4")
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser([]byte(src))
php5parser := php5.NewParser([]byte(src), "5.6")
php5parser.Parse()
actual = php5parser.GetRootNode()
assert.DeepEqual(t, expected, actual)

View File

@@ -66,12 +66,12 @@ func TestSimpleEcho(t *testing.T) {
},
}
php7parser := php7.NewParser([]byte(src))
php7parser := php7.NewParser([]byte(src), "7.4")
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser([]byte(src))
php5parser := php5.NewParser([]byte(src), "5.6")
php5parser.Parse()
actual = php5parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
@@ -118,12 +118,12 @@ func TestEcho(t *testing.T) {
},
}
php7parser := php7.NewParser([]byte(src))
php7parser := php7.NewParser([]byte(src), "7.4")
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser([]byte(src))
php5parser := php5.NewParser([]byte(src), "5.6")
php5parser.Parse()
actual = php5parser.GetRootNode()
assert.DeepEqual(t, expected, actual)

View File

@@ -45,12 +45,12 @@ func TestExpression(t *testing.T) {
},
}
php7parser := php7.NewParser([]byte(src))
php7parser := php7.NewParser([]byte(src), "7.4")
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser([]byte(src))
php5parser := php5.NewParser([]byte(src), "5.6")
php5parser.Parse()
actual = php5parser.GetRootNode()
assert.DeepEqual(t, expected, actual)

View File

@@ -174,12 +174,12 @@ func TestFor(t *testing.T) {
},
}
php7parser := php7.NewParser([]byte(src))
php7parser := php7.NewParser([]byte(src), "7.4")
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser([]byte(src))
php5parser := php5.NewParser([]byte(src), "5.6")
php5parser.Parse()
actual = php5parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
@@ -279,12 +279,12 @@ func TestAltFor(t *testing.T) {
},
}
php7parser := php7.NewParser([]byte(src))
php7parser := php7.NewParser([]byte(src), "7.4")
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser([]byte(src))
php5parser := php5.NewParser([]byte(src), "5.6")
php5parser.Parse()
actual = php5parser.GetRootNode()
assert.DeepEqual(t, expected, actual)

View File

@@ -79,12 +79,12 @@ func TestForeach(t *testing.T) {
},
}
php7parser := php7.NewParser([]byte(src))
php7parser := php7.NewParser([]byte(src), "7.4")
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser([]byte(src))
php5parser := php5.NewParser([]byte(src), "5.6")
php5parser.Parse()
actual = php5parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
@@ -147,12 +147,12 @@ func TestForeachExpr(t *testing.T) {
},
}
php7parser := php7.NewParser([]byte(src))
php7parser := php7.NewParser([]byte(src), "7.4")
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser([]byte(src))
php5parser := php5.NewParser([]byte(src), "5.6")
php5parser.Parse()
actual = php5parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
@@ -223,12 +223,12 @@ func TestAltForeach(t *testing.T) {
},
}
php7parser := php7.NewParser([]byte(src))
php7parser := php7.NewParser([]byte(src), "7.4")
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser([]byte(src))
php5parser := php5.NewParser([]byte(src), "5.6")
php5parser.Parse()
actual = php5parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
@@ -316,12 +316,12 @@ func TestForeachWithKey(t *testing.T) {
},
}
php7parser := php7.NewParser([]byte(src))
php7parser := php7.NewParser([]byte(src), "7.4")
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser([]byte(src))
php5parser := php5.NewParser([]byte(src), "5.6")
php5parser.Parse()
actual = php5parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
@@ -401,12 +401,12 @@ func TestForeachExprWithKey(t *testing.T) {
},
}
php7parser := php7.NewParser([]byte(src))
php7parser := php7.NewParser([]byte(src), "7.4")
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser([]byte(src))
php5parser := php5.NewParser([]byte(src), "5.6")
php5parser.Parse()
actual = php5parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
@@ -502,12 +502,12 @@ func TestForeachWithRef(t *testing.T) {
},
}
php7parser := php7.NewParser([]byte(src))
php7parser := php7.NewParser([]byte(src), "7.4")
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser([]byte(src))
php5parser := php5.NewParser([]byte(src), "5.6")
php5parser.Parse()
actual = php5parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
@@ -613,12 +613,12 @@ func TestForeachWithList(t *testing.T) {
},
}
php7parser := php7.NewParser([]byte(src))
php7parser := php7.NewParser([]byte(src), "7.4")
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser([]byte(src))
php5parser := php5.NewParser([]byte(src), "5.6")
php5parser.Parse()
actual = php5parser.GetRootNode()
assert.DeepEqual(t, expected, actual)

View File

@@ -50,12 +50,12 @@ func TestSimpleFunction(t *testing.T) {
},
}
php7parser := php7.NewParser([]byte(src))
php7parser := php7.NewParser([]byte(src), "7.4")
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser([]byte(src))
php5parser := php5.NewParser([]byte(src), "5.6")
php5parser.Parse()
actual = php5parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
@@ -104,12 +104,12 @@ func TestFunctionReturn(t *testing.T) {
},
}
php7parser := php7.NewParser([]byte(src))
php7parser := php7.NewParser([]byte(src), "7.4")
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser([]byte(src))
php5parser := php5.NewParser([]byte(src), "5.6")
php5parser.Parse()
actual = php5parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
@@ -249,12 +249,12 @@ func TestFunctionReturnVar(t *testing.T) {
},
}
php7parser := php7.NewParser([]byte(src))
php7parser := php7.NewParser([]byte(src), "7.4")
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser([]byte(src))
php5parser := php5.NewParser([]byte(src), "5.6")
php5parser.Parse()
actual = php5parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
@@ -312,12 +312,12 @@ func TestRefFunction(t *testing.T) {
},
}
php7parser := php7.NewParser([]byte(src))
php7parser := php7.NewParser([]byte(src), "7.4")
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser([]byte(src))
php5parser := php5.NewParser([]byte(src), "5.6")
php5parser.Parse()
actual = php5parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
@@ -376,7 +376,7 @@ func TestReturnTypeFunction(t *testing.T) {
},
}
php7parser := php7.NewParser([]byte(src))
php7parser := php7.NewParser([]byte(src), "7.4")
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)

View File

@@ -55,12 +55,12 @@ func TestGlobal(t *testing.T) {
},
}
php7parser := php7.NewParser([]byte(src))
php7parser := php7.NewParser([]byte(src), "7.4")
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser([]byte(src))
php5parser := php5.NewParser([]byte(src), "5.6")
php5parser.Parse()
actual = php5parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
@@ -192,12 +192,12 @@ func TestGlobalVars(t *testing.T) {
},
}
php7parser := php7.NewParser([]byte(src))
php7parser := php7.NewParser([]byte(src), "7.4")
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser([]byte(src))
php5parser := php5.NewParser([]byte(src), "5.6")
php5parser.Parse()
actual = php5parser.GetRootNode()
assert.DeepEqual(t, expected, actual)

View File

@@ -60,12 +60,12 @@ func TestGotoLabel(t *testing.T) {
},
}
php7parser := php7.NewParser([]byte(src))
php7parser := php7.NewParser([]byte(src), "7.4")
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser([]byte(src))
php5parser := php5.NewParser([]byte(src), "5.6")
php5parser.Parse()
actual = php5parser.GetRootNode()
assert.DeepEqual(t, expected, actual)

View File

@@ -34,12 +34,12 @@ func TestHaltCompiler(t *testing.T) {
},
}
php7parser := php7.NewParser([]byte(src))
php7parser := php7.NewParser([]byte(src), "7.4")
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser([]byte(src))
php5parser := php5.NewParser([]byte(src), "5.6")
php5parser.Parse()
actual = php5parser.GetRootNode()
assert.DeepEqual(t, expected, actual)

View File

@@ -62,12 +62,12 @@ func TestIf(t *testing.T) {
},
}
php7parser := php7.NewParser([]byte(src))
php7parser := php7.NewParser([]byte(src), "7.4")
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser([]byte(src))
php5parser := php5.NewParser([]byte(src), "5.6")
php5parser.Parse()
actual = php5parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
@@ -157,12 +157,12 @@ func TestElseIf(t *testing.T) {
},
}
php7parser := php7.NewParser([]byte(src))
php7parser := php7.NewParser([]byte(src), "7.4")
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser([]byte(src))
php5parser := php5.NewParser([]byte(src), "5.6")
php5parser.Parse()
actual = php5parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
@@ -233,12 +233,12 @@ func TestElse(t *testing.T) {
},
}
php7parser := php7.NewParser([]byte(src))
php7parser := php7.NewParser([]byte(src), "7.4")
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser([]byte(src))
php5parser := php5.NewParser([]byte(src), "5.6")
php5parser.Parse()
actual = php5parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
@@ -379,12 +379,12 @@ func TestElseElseIf(t *testing.T) {
},
}
php7parser := php7.NewParser([]byte(src))
php7parser := php7.NewParser([]byte(src), "7.4")
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser([]byte(src))
php5parser := php5.NewParser([]byte(src), "5.6")
php5parser.Parse()
actual = php5parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
@@ -533,12 +533,12 @@ func TestElseIfElseIfElse(t *testing.T) {
},
}
php7parser := php7.NewParser([]byte(src))
php7parser := php7.NewParser([]byte(src), "7.4")
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser([]byte(src))
php5parser := php5.NewParser([]byte(src), "5.6")
php5parser.Parse()
actual = php5parser.GetRootNode()
assert.DeepEqual(t, expected, actual)

View File

@@ -43,12 +43,12 @@ func TestInlineHtml(t *testing.T) {
},
}
php7parser := php7.NewParser([]byte(src))
php7parser := php7.NewParser([]byte(src), "7.4")
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser([]byte(src))
php5parser := php5.NewParser([]byte(src), "5.6")
php5parser.Parse()
actual = php5parser.GetRootNode()
assert.DeepEqual(t, expected, actual)

View File

@@ -47,12 +47,12 @@ func TestInterface(t *testing.T) {
},
}
php7parser := php7.NewParser([]byte(src))
php7parser := php7.NewParser([]byte(src), "7.4")
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser([]byte(src))
php5parser := php5.NewParser([]byte(src), "5.6")
php5parser.Parse()
actual = php5parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
@@ -120,12 +120,12 @@ func TestInterfaceExtend(t *testing.T) {
},
}
php7parser := php7.NewParser([]byte(src))
php7parser := php7.NewParser([]byte(src), "7.4")
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser([]byte(src))
php5parser := php5.NewParser([]byte(src), "5.6")
php5parser.Parse()
actual = php5parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
@@ -212,12 +212,12 @@ func TestInterfaceExtends(t *testing.T) {
},
}
php7parser := php7.NewParser([]byte(src))
php7parser := php7.NewParser([]byte(src), "7.4")
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser([]byte(src))
php5parser := php5.NewParser([]byte(src), "5.6")
php5parser.Parse()
actual = php5parser.GetRootNode()
assert.DeepEqual(t, expected, actual)

View File

@@ -55,12 +55,12 @@ func TestNamespace(t *testing.T) {
},
}
php7parser := php7.NewParser([]byte(src))
php7parser := php7.NewParser([]byte(src), "7.4")
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser([]byte(src))
php5parser := php5.NewParser([]byte(src), "5.6")
php5parser.Parse()
actual = php5parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
@@ -108,12 +108,12 @@ func TestNamespaceStmts(t *testing.T) {
},
}
php7parser := php7.NewParser([]byte(src))
php7parser := php7.NewParser([]byte(src), "7.4")
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser([]byte(src))
php5parser := php5.NewParser([]byte(src), "5.6")
php5parser.Parse()
actual = php5parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
@@ -142,12 +142,12 @@ func TestAnonymousNamespace(t *testing.T) {
},
}
php7parser := php7.NewParser([]byte(src))
php7parser := php7.NewParser([]byte(src), "7.4")
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser([]byte(src))
php5parser := php5.NewParser([]byte(src), "5.6")
php5parser.Parse()
actual = php5parser.GetRootNode()
assert.DeepEqual(t, expected, actual)

View File

@@ -6,6 +6,7 @@ import (
"gotest.tools/assert"
"github.com/z7zmey/php-parser/node/expr"
"github.com/z7zmey/php-parser/node/name"
"github.com/z7zmey/php-parser/node/scalar"
"github.com/z7zmey/php-parser/position"
@@ -96,12 +97,12 @@ func TestProperty(t *testing.T) {
},
}
php7parser := php7.NewParser([]byte(src))
php7parser := php7.NewParser([]byte(src), "7.4")
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser([]byte(src))
php5parser := php5.NewParser([]byte(src), "5.6")
php5parser.Parse()
actual = php5parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
@@ -232,12 +233,12 @@ func TestProperties(t *testing.T) {
},
}
php7parser := php7.NewParser([]byte(src))
php7parser := php7.NewParser([]byte(src), "7.4")
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser([]byte(src))
php5parser := php5.NewParser([]byte(src), "5.6")
php5parser.Parse()
actual = php5parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
@@ -368,13 +369,119 @@ func TestProperties2(t *testing.T) {
},
}
php7parser := php7.NewParser([]byte(src))
php7parser := php7.NewParser([]byte(src), "7.4")
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser([]byte(src))
php5parser := php5.NewParser([]byte(src), "5.6")
php5parser.Parse()
actual = php5parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
}
func TestPropertyType(t *testing.T) {
src := `<? class foo {var bar $a;}`
expected := &node.Root{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 3,
EndPos: 26,
},
Stmts: []node.Node{
&stmt.Class{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 3,
EndPos: 26,
},
PhpDocComment: "",
ClassName: &node.Identifier{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 9,
EndPos: 12,
},
Value: "foo",
},
Stmts: []node.Node{
&stmt.PropertyList{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 14,
EndPos: 25,
},
Modifiers: []node.Node{
&node.Identifier{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 14,
EndPos: 17,
},
Value: "var",
},
},
Type: &name.Name{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 18,
EndPos: 21,
},
Parts: []node.Node{
&name.NamePart{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 18,
EndPos: 21,
},
Value: "bar",
},
},
},
Properties: []node.Node{
&stmt.Property{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 22,
EndPos: 24,
},
PhpDocComment: "",
Variable: &expr.Variable{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 22,
EndPos: 24,
},
VarName: &node.Identifier{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 22,
EndPos: 24,
},
Value: "a",
},
},
},
},
},
},
},
},
}
php7parser := php7.NewParser([]byte(src), "7.4")
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
}

View File

@@ -63,12 +63,12 @@ func TestStaticVar(t *testing.T) {
},
}
php7parser := php7.NewParser([]byte(src))
php7parser := php7.NewParser([]byte(src), "7.4")
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser([]byte(src))
php5parser := php5.NewParser([]byte(src), "5.6")
php5parser.Parse()
actual = php5parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
@@ -157,12 +157,12 @@ func TestStaticVars(t *testing.T) {
},
}
php7parser := php7.NewParser([]byte(src))
php7parser := php7.NewParser([]byte(src), "7.4")
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser([]byte(src))
php5parser := php5.NewParser([]byte(src), "5.6")
php5parser.Parse()
actual = php5parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
@@ -251,12 +251,12 @@ func TestStaticVars2(t *testing.T) {
},
}
php7parser := php7.NewParser([]byte(src))
php7parser := php7.NewParser([]byte(src), "7.4")
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser([]byte(src))
php5parser := php5.NewParser([]byte(src), "5.6")
php5parser.Parse()
actual = php5parser.GetRootNode()
assert.DeepEqual(t, expected, actual)

View File

@@ -106,12 +106,12 @@ func TestAltSwitch(t *testing.T) {
},
}
php7parser := php7.NewParser([]byte(src))
php7parser := php7.NewParser([]byte(src), "7.4")
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser([]byte(src))
php5parser := php5.NewParser([]byte(src), "5.6")
php5parser.Parse()
actual = php5parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
@@ -199,12 +199,12 @@ func TestAltSwitchSemicolon(t *testing.T) {
},
}
php7parser := php7.NewParser([]byte(src))
php7parser := php7.NewParser([]byte(src), "7.4")
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser([]byte(src))
php5parser := php5.NewParser([]byte(src), "5.6")
php5parser.Parse()
actual = php5parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
@@ -310,12 +310,12 @@ func TestSwitch(t *testing.T) {
},
}
php7parser := php7.NewParser([]byte(src))
php7parser := php7.NewParser([]byte(src), "7.4")
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser([]byte(src))
php5parser := php5.NewParser([]byte(src), "5.6")
php5parser.Parse()
actual = php5parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
@@ -421,12 +421,12 @@ func TestSwitchSemicolon(t *testing.T) {
},
}
php7parser := php7.NewParser([]byte(src))
php7parser := php7.NewParser([]byte(src), "7.4")
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser([]byte(src))
php5parser := php5.NewParser([]byte(src), "5.6")
php5parser.Parse()
actual = php5parser.GetRootNode()
assert.DeepEqual(t, expected, actual)

View File

@@ -52,12 +52,12 @@ func TestThrow(t *testing.T) {
},
}
php7parser := php7.NewParser([]byte(src))
php7parser := php7.NewParser([]byte(src), "7.4")
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser([]byte(src))
php5parser := php5.NewParser([]byte(src), "5.6")
php5parser.Parse()
actual = php5parser.GetRootNode()
assert.DeepEqual(t, expected, actual)

View File

@@ -45,12 +45,12 @@ func TestTrait(t *testing.T) {
},
}
php7parser := php7.NewParser([]byte(src))
php7parser := php7.NewParser([]byte(src), "7.4")
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser([]byte(src))
php5parser := php5.NewParser([]byte(src), "5.6")
php5parser.Parse()
actual = php5parser.GetRootNode()
assert.DeepEqual(t, expected, actual)

View File

@@ -85,12 +85,12 @@ func TestTraitUse(t *testing.T) {
},
}
php7parser := php7.NewParser([]byte(src))
php7parser := php7.NewParser([]byte(src), "7.4")
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser([]byte(src))
php5parser := php5.NewParser([]byte(src), "5.6")
php5parser.Parse()
actual = php5parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
@@ -186,12 +186,12 @@ func TestTraitsUse(t *testing.T) {
},
}
php7parser := php7.NewParser([]byte(src))
php7parser := php7.NewParser([]byte(src), "7.4")
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser([]byte(src))
php5parser := php5.NewParser([]byte(src), "5.6")
php5parser.Parse()
actual = php5parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
@@ -287,12 +287,12 @@ func TestTraitsUseEmptyAdaptations(t *testing.T) {
},
}
php7parser := php7.NewParser([]byte(src))
php7parser := php7.NewParser([]byte(src), "7.4")
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser([]byte(src))
php5parser := php5.NewParser([]byte(src), "5.6")
php5parser.Parse()
actual = php5parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
@@ -424,12 +424,12 @@ func TestTraitsUseModifier(t *testing.T) {
},
}
php7parser := php7.NewParser([]byte(src))
php7parser := php7.NewParser([]byte(src), "7.4")
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser([]byte(src))
php5parser := php5.NewParser([]byte(src), "5.6")
php5parser.Parse()
actual = php5parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
@@ -570,12 +570,12 @@ func TestTraitsUseAliasModifier(t *testing.T) {
},
}
php7parser := php7.NewParser([]byte(src))
php7parser := php7.NewParser([]byte(src), "7.4")
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser([]byte(src))
php5parser := php5.NewParser([]byte(src), "5.6")
php5parser.Parse()
actual = php5parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
@@ -810,12 +810,12 @@ func TestTraitsUseAdaptions(t *testing.T) {
},
}
php7parser := php7.NewParser([]byte(src))
php7parser := php7.NewParser([]byte(src), "7.4")
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser([]byte(src))
php5parser := php5.NewParser([]byte(src), "5.6")
php5parser.Parse()
actual = php5parser.GetRootNode()
assert.DeepEqual(t, expected, actual)

View File

@@ -41,12 +41,12 @@ func TestTry(t *testing.T) {
},
}
php7parser := php7.NewParser([]byte(src))
php7parser := php7.NewParser([]byte(src), "7.4")
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser([]byte(src))
php5parser := php5.NewParser([]byte(src), "5.6")
php5parser.Parse()
actual = php5parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
@@ -126,12 +126,12 @@ func TestTryCatch(t *testing.T) {
},
}
php7parser := php7.NewParser([]byte(src))
php7parser := php7.NewParser([]byte(src), "7.4")
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser([]byte(src))
php5parser := php5.NewParser([]byte(src), "5.6")
php5parser.Parse()
actual = php5parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
@@ -230,7 +230,7 @@ func TestPhp7TryCatch(t *testing.T) {
},
}
php7parser := php7.NewParser([]byte(src))
php7parser := php7.NewParser([]byte(src), "7.4")
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
@@ -357,12 +357,12 @@ func TestTryCatchCatch(t *testing.T) {
},
}
php7parser := php7.NewParser([]byte(src))
php7parser := php7.NewParser([]byte(src), "7.4")
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser([]byte(src))
php5parser := php5.NewParser([]byte(src), "5.6")
php5parser.Parse()
actual = php5parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
@@ -451,12 +451,12 @@ func TestTryCatchFinally(t *testing.T) {
},
}
php7parser := php7.NewParser([]byte(src))
php7parser := php7.NewParser([]byte(src), "7.4")
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser([]byte(src))
php5parser := php5.NewParser([]byte(src), "5.6")
php5parser.Parse()
actual = php5parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
@@ -628,12 +628,12 @@ func TestTryCatchCatchCatch(t *testing.T) {
},
}
php7parser := php7.NewParser([]byte(src))
php7parser := php7.NewParser([]byte(src), "7.4")
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser([]byte(src))
php5parser := php5.NewParser([]byte(src), "5.6")
php5parser.Parse()
actual = php5parser.GetRootNode()
assert.DeepEqual(t, expected, actual)

View File

@@ -54,12 +54,12 @@ func TestUnset(t *testing.T) {
},
}
php7parser := php7.NewParser([]byte(src))
php7parser := php7.NewParser([]byte(src), "7.4")
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser([]byte(src))
php5parser := php5.NewParser([]byte(src), "5.6")
php5parser.Parse()
actual = php5parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
@@ -123,12 +123,12 @@ func TestUnsetVars(t *testing.T) {
},
}
php7parser := php7.NewParser([]byte(src))
php7parser := php7.NewParser([]byte(src), "7.4")
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser([]byte(src))
php5parser := php5.NewParser([]byte(src), "5.6")
php5parser.Parse()
actual = php5parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
@@ -192,7 +192,7 @@ func TestUnsetTrailingComma(t *testing.T) {
},
}
php7parser := php7.NewParser([]byte(src))
php7parser := php7.NewParser([]byte(src), "7.4")
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)

View File

@@ -65,12 +65,12 @@ func TestSimpleUse(t *testing.T) {
},
}
php7parser := php7.NewParser([]byte(src))
php7parser := php7.NewParser([]byte(src), "7.4")
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser([]byte(src))
php5parser := php5.NewParser([]byte(src), "5.6")
php5parser.Parse()
actual = php5parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
@@ -127,12 +127,12 @@ func TestUseFullyQualified(t *testing.T) {
},
}
php7parser := php7.NewParser([]byte(src))
php7parser := php7.NewParser([]byte(src), "7.4")
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser([]byte(src))
php5parser := php5.NewParser([]byte(src), "5.6")
php5parser.Parse()
actual = php5parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
@@ -198,12 +198,12 @@ func TestUseFullyQualifiedAlias(t *testing.T) {
},
}
php7parser := php7.NewParser([]byte(src))
php7parser := php7.NewParser([]byte(src), "7.4")
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser([]byte(src))
php5parser := php5.NewParser([]byte(src), "5.6")
php5parser.Parse()
actual = php5parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
@@ -287,12 +287,12 @@ func TestUseList(t *testing.T) {
},
}
php7parser := php7.NewParser([]byte(src))
php7parser := php7.NewParser([]byte(src), "7.4")
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser([]byte(src))
php5parser := php5.NewParser([]byte(src), "5.6")
php5parser.Parse()
actual = php5parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
@@ -385,12 +385,12 @@ func TestUseListAlias(t *testing.T) {
},
}
php7parser := php7.NewParser([]byte(src))
php7parser := php7.NewParser([]byte(src), "7.4")
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser([]byte(src))
php5parser := php5.NewParser([]byte(src), "5.6")
php5parser.Parse()
actual = php5parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
@@ -483,12 +483,12 @@ func TestUseListFunctionType(t *testing.T) {
},
}
php7parser := php7.NewParser([]byte(src))
php7parser := php7.NewParser([]byte(src), "7.4")
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser([]byte(src))
php5parser := php5.NewParser([]byte(src), "5.6")
php5parser.Parse()
actual = php5parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
@@ -599,12 +599,12 @@ func TestUseListFunctionTypeAliases(t *testing.T) {
},
}
php7parser := php7.NewParser([]byte(src))
php7parser := php7.NewParser([]byte(src), "7.4")
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser([]byte(src))
php5parser := php5.NewParser([]byte(src), "5.6")
php5parser.Parse()
actual = php5parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
@@ -697,12 +697,12 @@ func TestUseListConstType(t *testing.T) {
},
}
php7parser := php7.NewParser([]byte(src))
php7parser := php7.NewParser([]byte(src), "7.4")
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser([]byte(src))
php5parser := php5.NewParser([]byte(src), "5.6")
php5parser.Parse()
actual = php5parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
@@ -813,12 +813,12 @@ func TestUseListConstTypeAliases(t *testing.T) {
},
}
php7parser := php7.NewParser([]byte(src))
php7parser := php7.NewParser([]byte(src), "7.4")
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser([]byte(src))
php5parser := php5.NewParser([]byte(src), "5.6")
php5parser.Parse()
actual = php5parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
@@ -921,7 +921,7 @@ func TestGroupUse(t *testing.T) {
},
}
php7parser := php7.NewParser([]byte(src))
php7parser := php7.NewParser([]byte(src), "7.4")
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
@@ -1033,7 +1033,7 @@ func TestGroupUseAlias(t *testing.T) {
},
}
php7parser := php7.NewParser([]byte(src))
php7parser := php7.NewParser([]byte(src), "7.4")
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
@@ -1145,7 +1145,7 @@ func TestFunctionGroupUse(t *testing.T) {
},
}
php7parser := php7.NewParser([]byte(src))
php7parser := php7.NewParser([]byte(src), "7.4")
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
@@ -1257,7 +1257,7 @@ func TestConstGroupUse(t *testing.T) {
},
}
php7parser := php7.NewParser([]byte(src))
php7parser := php7.NewParser([]byte(src), "7.4")
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
@@ -1378,7 +1378,7 @@ func TestMixedGroupUse(t *testing.T) {
},
}
php7parser := php7.NewParser([]byte(src))
php7parser := php7.NewParser([]byte(src), "7.4")
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)

View File

@@ -323,9 +323,10 @@ var nodesToTest = []struct {
{
&stmt.PropertyList{
Modifiers: []node.Node{&stmt.Expression{}},
Type: &name.Name{},
Properties: []node.Node{&stmt.Expression{}},
},
[]string{"Modifiers", "Properties"},
[]string{"Modifiers", "Type", "Properties"},
nil,
},
{

View File

@@ -63,12 +63,12 @@ func TestBreakEmpty(t *testing.T) {
},
}
php7parser := php7.NewParser([]byte(src))
php7parser := php7.NewParser([]byte(src), "7.4")
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser([]byte(src))
php5parser := php5.NewParser([]byte(src), "5.6")
php5parser.Parse()
actual = php5parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
@@ -132,12 +132,12 @@ func TestBreakLight(t *testing.T) {
},
}
php7parser := php7.NewParser([]byte(src))
php7parser := php7.NewParser([]byte(src), "7.4")
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser([]byte(src))
php5parser := php5.NewParser([]byte(src), "5.6")
php5parser.Parse()
actual = php5parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
@@ -201,12 +201,12 @@ func TestBreak(t *testing.T) {
},
}
php7parser := php7.NewParser([]byte(src))
php7parser := php7.NewParser([]byte(src), "7.4")
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser([]byte(src))
php5parser := php5.NewParser([]byte(src), "5.6")
php5parser.Parse()
actual = php5parser.GetRootNode()
assert.DeepEqual(t, expected, actual)

View File

@@ -55,12 +55,12 @@ func TestIdentifier(t *testing.T) {
},
}
php7parser := php7.NewParser([]byte(src))
php7parser := php7.NewParser([]byte(src), "7.4")
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser([]byte(src))
php5parser := php5.NewParser([]byte(src), "5.6")
php5parser.Parse()
actual = php5parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
@@ -794,7 +794,7 @@ func TestPhp7ArgumentNode(t *testing.T) {
},
}
php7parser := php7.NewParser([]byte(src))
php7parser := php7.NewParser([]byte(src), "7.4")
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
@@ -1436,7 +1436,7 @@ func TestPhp5ArgumentNode(t *testing.T) {
},
}
php5parser := php5.NewParser([]byte(src))
php5parser := php5.NewParser([]byte(src), "5.6")
php5parser.Parse()
actual := php5parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
@@ -2096,7 +2096,7 @@ func TestPhp7ParameterNode(t *testing.T) {
},
}
php7parser := php7.NewParser([]byte(src))
php7parser := php7.NewParser([]byte(src), "7.4")
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
@@ -2724,7 +2724,7 @@ func TestPhp5ParameterNode(t *testing.T) {
},
}
php5parser := php5.NewParser([]byte(src))
php5parser := php5.NewParser([]byte(src), "5.6")
php5parser.Parse()
actual := php5parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
@@ -2743,12 +2743,12 @@ func TestCommentEndFile(t *testing.T) {
Stmts: []node.Node{},
}
php7parser := php7.NewParser([]byte(src))
php7parser := php7.NewParser([]byte(src), "7.4")
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser([]byte(src))
php5parser := php5.NewParser([]byte(src), "5.6")
php5parser.Parse()
actual = php5parser.GetRootNode()
assert.DeepEqual(t, expected, actual)

View File

@@ -3,6 +3,9 @@ package parser
import (
"github.com/z7zmey/php-parser/errors"
"github.com/z7zmey/php-parser/node"
"github.com/z7zmey/php-parser/php5"
"github.com/z7zmey/php-parser/php7"
"github.com/z7zmey/php-parser/version"
)
// Parser interface
@@ -12,3 +15,20 @@ type Parser interface {
GetErrors() []*errors.Error
WithFreeFloating()
}
func NewParser(src []byte, v string) (Parser, error) {
var parser Parser
r, err := version.Compare(v, "7.0")
if err != nil {
return nil, err
}
if r == -1 {
parser = php5.NewParser(src, v)
} else {
parser = php7.NewParser(src, v)
}
return parser, nil
}

View File

@@ -6,8 +6,8 @@ import (
"github.com/z7zmey/php-parser/errors"
"github.com/z7zmey/php-parser/freefloating"
"github.com/z7zmey/php-parser/node"
"github.com/z7zmey/php-parser/parser"
"github.com/z7zmey/php-parser/position"
"github.com/z7zmey/php-parser/positionbuilder"
"github.com/z7zmey/php-parser/scanner"
)
@@ -19,13 +19,14 @@ func (lval *yySymType) Token(t *scanner.Token) {
type Parser struct {
Lexer scanner.Scanner
currentToken *scanner.Token
positionBuilder *parser.PositionBuilder
positionBuilder *positionbuilder.PositionBuilder
rootNode node.Node
}
// NewParser creates and returns new Parser
func NewParser(src []byte) *Parser {
func NewParser(src []byte, v string) *Parser {
lexer := scanner.NewLexer(src)
lexer.PHPVersion = v
return &Parser{
lexer,
@@ -62,7 +63,7 @@ func (l *Parser) Parse() int {
// init
l.Lexer.SetErrors(nil)
l.rootNode = nil
l.positionBuilder = &parser.PositionBuilder{}
l.positionBuilder = &positionbuilder.PositionBuilder{}
// parse

File diff suppressed because it is too large Load Diff

View File

@@ -66,6 +66,7 @@ import (
%token <token> T_CONTINUE
%token <token> T_GOTO
%token <token> T_FUNCTION
%token <token> T_FN
%token <token> T_CONST
%token <token> T_RETURN
%token <token> T_TRY
@@ -157,6 +158,7 @@ import (
%token <token> T_XOR_EQUAL
%token <token> T_SL_EQUAL
%token <token> T_SR_EQUAL
%token <token> T_COALESCE_EQUAL
%token <token> T_BOOLEAN_OR
%token <token> T_BOOLEAN_AND
%token <token> T_POW
@@ -2699,7 +2701,7 @@ class_statement_list:
class_statement:
variable_modifiers class_variable_declaration ';'
{
$$ = stmt.NewPropertyList($1, $2)
$$ = stmt.NewPropertyList($1, nil, $2)
// save position
$$.SetPosition(yylex.(*Parser).positionBuilder.NewNodeListTokenPosition($1, $3))
@@ -5915,7 +5917,7 @@ possible_comma:
non_empty_static_array_pair_list:
non_empty_static_array_pair_list ',' static_scalar_value T_DOUBLE_ARROW static_scalar_value
{
arrayItem := expr.NewArrayItem($3, $5)
arrayItem := expr.NewArrayItem($3, $5, false)
$$ = append($1, arrayItem)
// save position
@@ -5930,7 +5932,7 @@ non_empty_static_array_pair_list:
}
| non_empty_static_array_pair_list ',' static_scalar_value
{
arrayItem := expr.NewArrayItem(nil, $3)
arrayItem := expr.NewArrayItem(nil, $3, false)
$$ = append($1, arrayItem)
// save position
@@ -5944,7 +5946,7 @@ non_empty_static_array_pair_list:
}
| static_scalar_value T_DOUBLE_ARROW static_scalar_value
{
arrayItem := expr.NewArrayItem($1, $3)
arrayItem := expr.NewArrayItem($1, $3, false)
$$ = []node.Node{arrayItem}
// save position
@@ -5958,7 +5960,7 @@ non_empty_static_array_pair_list:
}
| static_scalar_value
{
arrayItem := expr.NewArrayItem(nil, $1)
arrayItem := expr.NewArrayItem(nil, $1, false)
$$ = []node.Node{arrayItem}
// save position
@@ -6567,7 +6569,7 @@ assignment_list:
assignment_list ',' assignment_list_element
{
if len($1) == 0 {
$1 = []node.Node{expr.NewArrayItem(nil, nil)}
$1 = []node.Node{expr.NewArrayItem(nil, nil, false)}
}
$$ = append($1, $3)
@@ -6593,7 +6595,7 @@ assignment_list:
assignment_list_element:
variable
{
$$ = expr.NewArrayItem(nil, $1)
$$ = expr.NewArrayItem(nil, $1, false)
// save position
$$.SetPosition(yylex.(*Parser).positionBuilder.NewNodePosition($1))
@@ -6606,7 +6608,7 @@ assignment_list_element:
| T_LIST '(' assignment_list ')'
{
listNode := expr.NewList($3)
$$ = expr.NewArrayItem(nil, listNode)
$$ = expr.NewArrayItem(nil, listNode, false)
// save position
listNode.SetPosition(yylex.(*Parser).positionBuilder.NewTokensPosition($1, $4))
@@ -6621,7 +6623,7 @@ assignment_list_element:
}
| /* empty */
{
$$ = expr.NewArrayItem(nil, nil)
$$ = expr.NewArrayItem(nil, nil, false)
yylex.(*Parser).returnTokenToPool(yyDollar, &yyVAL)
}
@@ -6640,7 +6642,7 @@ array_pair_list:
$$ = $1
if $2 != nil {
$$ = append($1, expr.NewArrayItem(nil, nil))
$$ = append($1, expr.NewArrayItem(nil, nil, false))
}
// save comments
@@ -6655,7 +6657,7 @@ array_pair_list:
non_empty_array_pair_list:
non_empty_array_pair_list ',' expr T_DOUBLE_ARROW expr
{
arrayItem := expr.NewArrayItem($3, $5)
arrayItem := expr.NewArrayItem($3, $5, false)
$$ = append($1, arrayItem)
// save position
@@ -6670,7 +6672,7 @@ non_empty_array_pair_list:
}
| non_empty_array_pair_list ',' expr
{
arrayItem := expr.NewArrayItem(nil, $3)
arrayItem := expr.NewArrayItem(nil, $3, false)
$$ = append($1, arrayItem)
// save position
@@ -6684,7 +6686,7 @@ non_empty_array_pair_list:
}
| expr T_DOUBLE_ARROW expr
{
arrayItem := expr.NewArrayItem($1, $3)
arrayItem := expr.NewArrayItem($1, $3, false)
$$ = []node.Node{arrayItem}
// save position
@@ -6698,7 +6700,7 @@ non_empty_array_pair_list:
}
| expr
{
arrayItem := expr.NewArrayItem(nil, $1)
arrayItem := expr.NewArrayItem(nil, $1, false)
$$ = []node.Node{arrayItem}
// save position
@@ -6712,7 +6714,7 @@ non_empty_array_pair_list:
| non_empty_array_pair_list ',' expr T_DOUBLE_ARROW '&' w_variable
{
reference := expr.NewReference($6)
arrayItem := expr.NewArrayItem($3, reference)
arrayItem := expr.NewArrayItem($3, reference, false)
$$ = append($1, arrayItem)
// save position
@@ -6730,7 +6732,7 @@ non_empty_array_pair_list:
| non_empty_array_pair_list ',' '&' w_variable
{
reference := expr.NewReference($4)
arrayItem := expr.NewArrayItem(nil, reference)
arrayItem := expr.NewArrayItem(nil, reference, false)
$$ = append($1, arrayItem)
// save position
@@ -6746,7 +6748,7 @@ non_empty_array_pair_list:
| expr T_DOUBLE_ARROW '&' w_variable
{
reference := expr.NewReference($4)
arrayItem := expr.NewArrayItem($1, reference)
arrayItem := expr.NewArrayItem($1, reference, false)
$$ = []node.Node{arrayItem}
// save position
@@ -6763,7 +6765,7 @@ non_empty_array_pair_list:
| '&' w_variable
{
reference := expr.NewReference($2)
arrayItem := expr.NewArrayItem(nil, reference)
arrayItem := expr.NewArrayItem(nil, reference, false)
$$ = []node.Node{arrayItem}
// save position

View File

@@ -413,7 +413,7 @@ CAD;
`
for n := 0; n < b.N; n++ {
php5parser := php5.NewParser([]byte(src))
php5parser := php5.NewParser([]byte(src), "5.6")
php5parser.Parse()
}
}

View File

@@ -18401,7 +18401,7 @@ func TestPhp5(t *testing.T) {
},
}
php5parser := php5.NewParser([]byte(src))
php5parser := php5.NewParser([]byte(src), "5.6")
php5parser.Parse()
actual := php5parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
@@ -18516,7 +18516,7 @@ func TestPhp5Strings(t *testing.T) {
},
}
php5parser := php5.NewParser([]byte(src))
php5parser := php5.NewParser([]byte(src), "5.6")
php5parser.Parse()
actual := php5parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
@@ -18706,7 +18706,7 @@ CAD;
},
}
php5parser := php5.NewParser([]byte(src))
php5parser := php5.NewParser([]byte(src), "5.6")
php5parser.Parse()
actual := php5parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
@@ -18726,7 +18726,7 @@ func TestPhp5ControlCharsErrors(t *testing.T) {
},
}
php5parser := php5.NewParser([]byte(src))
php5parser := php5.NewParser([]byte(src), "5.6")
php5parser.Parse()
actual := php5parser.GetErrors()
assert.DeepEqual(t, expected, actual)

View File

@@ -6,8 +6,8 @@ import (
"github.com/z7zmey/php-parser/errors"
"github.com/z7zmey/php-parser/freefloating"
"github.com/z7zmey/php-parser/node"
"github.com/z7zmey/php-parser/parser"
"github.com/z7zmey/php-parser/position"
"github.com/z7zmey/php-parser/positionbuilder"
"github.com/z7zmey/php-parser/scanner"
)
@@ -19,13 +19,14 @@ func (lval *yySymType) Token(t *scanner.Token) {
type Parser struct {
Lexer scanner.Scanner
currentToken *scanner.Token
positionBuilder *parser.PositionBuilder
positionBuilder *positionbuilder.PositionBuilder
rootNode node.Node
}
// NewParser creates and returns new Parser
func NewParser(src []byte) *Parser {
func NewParser(src []byte, v string) *Parser {
lexer := scanner.NewLexer(src)
lexer.PHPVersion = v
return &Parser{
lexer,
@@ -61,7 +62,7 @@ func (l *Parser) Parse() int {
// init
l.Lexer.SetErrors(nil)
l.rootNode = nil
l.positionBuilder = &parser.PositionBuilder{}
l.positionBuilder = &positionbuilder.PositionBuilder{}
// parse

File diff suppressed because it is too large Load Diff

View File

@@ -66,6 +66,7 @@ import (
%token <token> T_CONTINUE
%token <token> T_GOTO
%token <token> T_FUNCTION
%token <token> T_FN
%token <token> T_CONST
%token <token> T_RETURN
%token <token> T_TRY
@@ -157,6 +158,7 @@ import (
%token <token> T_XOR_EQUAL
%token <token> T_SL_EQUAL
%token <token> T_SR_EQUAL
%token <token> T_COALESCE_EQUAL
%token <token> T_BOOLEAN_OR
%token <token> T_BOOLEAN_AND
%token <token> T_POW
@@ -206,7 +208,7 @@ import (
%right T_YIELD
%right T_DOUBLE_ARROW
%right T_YIELD_FROM
%left '=' T_PLUS_EQUAL T_MINUS_EQUAL T_MUL_EQUAL T_DIV_EQUAL T_CONCAT_EQUAL T_MOD_EQUAL T_AND_EQUAL T_OR_EQUAL T_XOR_EQUAL T_SL_EQUAL T_SR_EQUAL T_POW_EQUAL
%left '=' T_PLUS_EQUAL T_MINUS_EQUAL T_MUL_EQUAL T_DIV_EQUAL T_CONCAT_EQUAL T_MOD_EQUAL T_AND_EQUAL T_OR_EQUAL T_XOR_EQUAL T_SL_EQUAL T_SR_EQUAL T_POW_EQUAL T_COALESCE_EQUAL
%left '?' ':'
%right T_COALESCE
%left T_BOOLEAN_OR
@@ -269,6 +271,7 @@ import (
%type <node> switch_case_list
%type <node> method_body
%type <node> foreach_statement for_statement while_statement
%type <node> inline_function
%type <ClassExtends> extends_from
%type <ClassImplements> implements_list
%type <InterfaceExtends> interface_extends_list
@@ -316,7 +319,7 @@ reserved_non_modifiers:
| T_THROW {$$=$1} | T_USE {$$=$1} | T_INSTEADOF {$$=$1} | T_GLOBAL {$$=$1} | T_VAR {$$=$1} | T_UNSET {$$=$1} | T_ISSET {$$=$1} | T_EMPTY {$$=$1} | T_CONTINUE {$$=$1} | T_GOTO {$$=$1}
| T_FUNCTION {$$=$1} | T_CONST {$$=$1} | T_RETURN {$$=$1} | T_PRINT {$$=$1} | T_YIELD {$$=$1} | T_LIST {$$=$1} | T_SWITCH {$$=$1} | T_ENDSWITCH {$$=$1} | T_CASE {$$=$1} | T_DEFAULT {$$=$1} | T_BREAK {$$=$1}
| T_ARRAY {$$=$1} | T_CALLABLE {$$=$1} | T_EXTENDS {$$=$1} | T_IMPLEMENTS {$$=$1} | T_NAMESPACE {$$=$1} | T_TRAIT {$$=$1} | T_INTERFACE {$$=$1} | T_CLASS {$$=$1}
| T_CLASS_C {$$=$1} | T_TRAIT_C {$$=$1} | T_FUNC_C {$$=$1} | T_METHOD_C {$$=$1} | T_LINE {$$=$1} | T_FILE {$$=$1} | T_DIR {$$=$1} | T_NS_C {$$=$1}
| T_CLASS_C {$$=$1} | T_TRAIT_C {$$=$1} | T_FUNC_C {$$=$1} | T_METHOD_C {$$=$1} | T_LINE {$$=$1} | T_FILE {$$=$1} | T_DIR {$$=$1} | T_NS_C {$$=$1} | T_FN {$$=$1}
;
semi_reserved:
@@ -2493,17 +2496,17 @@ class_statement_list:
;
class_statement:
variable_modifiers property_list ';'
variable_modifiers optional_type property_list ';'
{
$$ = stmt.NewPropertyList($1, $2)
$$ = stmt.NewPropertyList($1, $2, $3)
// save position
$$.SetPosition(yylex.(*Parser).positionBuilder.NewNodeListTokenPosition($1, $3))
$$.SetPosition(yylex.(*Parser).positionBuilder.NewNodeListTokenPosition($1, $4))
// save comments
yylex.(*Parser).MoveFreeFloating($1[0], $$)
yylex.(*Parser).setFreeFloating($$, freefloating.PropertyList, $3.FreeFloating)
yylex.(*Parser).setFreeFloating($$, freefloating.SemiColon, yylex.(*Parser).GetFreeFloatingToken($3))
yylex.(*Parser).setFreeFloating($$, freefloating.PropertyList, $4.FreeFloating)
yylex.(*Parser).setFreeFloating($$, freefloating.SemiColon, yylex.(*Parser).GetFreeFloatingToken($4))
yylex.(*Parser).returnTokenToPool(yyDollar, &yyVAL)
}
@@ -3396,6 +3399,19 @@ expr_without_variable:
yylex.(*Parser).MoveFreeFloating($1, $$)
yylex.(*Parser).setFreeFloating($$, freefloating.Var, $2.FreeFloating)
yylex.(*Parser).returnTokenToPool(yyDollar, &yyVAL)
}
| variable T_COALESCE_EQUAL expr
{
$$ = assign.NewCoalesce($1, $3)
// save position
$$.SetPosition(yylex.(*Parser).positionBuilder.NewNodesPosition($1, $3))
// save comments
yylex.(*Parser).MoveFreeFloating($1, $$)
yylex.(*Parser).setFreeFloating($$, freefloating.Var, $2.FreeFloating)
yylex.(*Parser).returnTokenToPool(yyDollar, &yyVAL)
}
| variable T_INC
@@ -4120,7 +4136,36 @@ expr_without_variable:
yylex.(*Parser).returnTokenToPool(yyDollar, &yyVAL)
}
| T_FUNCTION returns_ref backup_doc_comment '(' parameter_list ')' lexical_vars return_type '{' inner_statement_list '}'
| inline_function
{
$$ = $1;
yylex.(*Parser).returnTokenToPool(yyDollar, &yyVAL)
}
| T_STATIC inline_function
{
$$ = $2;
switch n := $$.(type) {
case *expr.Closure :
n.Static = true;
case *expr.ArrowFunction :
n.Static = true;
};
// save position
$$.SetPosition(yylex.(*Parser).positionBuilder.NewTokenNodePosition($1, $2))
// save comments
yylex.(*Parser).setFreeFloating($$, freefloating.Static, (*$$.GetFreeFloating())[freefloating.Start]); delete((*$$.GetFreeFloating()), freefloating.Start)
yylex.(*Parser).setFreeFloating($$, freefloating.Start, $1.FreeFloating);
yylex.(*Parser).returnTokenToPool(yyDollar, &yyVAL)
}
;
inline_function:
T_FUNCTION returns_ref backup_doc_comment '(' parameter_list ')' lexical_vars return_type '{' inner_statement_list '}'
{
$$ = expr.NewClosure($5, $7, $8, $10, false, $2 != nil, $3)
@@ -4152,36 +4197,31 @@ expr_without_variable:
yylex.(*Parser).returnTokenToPool(yyDollar, &yyVAL)
}
| T_STATIC T_FUNCTION returns_ref backup_doc_comment '(' parameter_list ')' lexical_vars return_type '{' inner_statement_list '}'
| T_FN returns_ref '(' parameter_list ')' return_type backup_doc_comment T_DOUBLE_ARROW expr
{
$$ = expr.NewClosure($6, $8, $9, $11, true, $3 != nil, $4)
$$ = expr.NewArrowFunction($4, $6, $9, false, $2 != nil, $7)
// save position
$$.SetPosition(yylex.(*Parser).positionBuilder.NewTokensPosition($1, $12))
$$.SetPosition(yylex.(*Parser).positionBuilder.NewTokenNodePosition($1, $9))
// save comments
yylex.(*Parser).setFreeFloating($$, freefloating.Start, $1.FreeFloating)
yylex.(*Parser).setFreeFloating($$, freefloating.Static, $2.FreeFloating)
if $3 == nil {
yylex.(*Parser).setFreeFloating($$, freefloating.Function, $5.FreeFloating)
} else {
if $2 == nil {
yylex.(*Parser).setFreeFloating($$, freefloating.Function, $3.FreeFloating)
yylex.(*Parser).setFreeFloating($$, freefloating.Ampersand, $5.FreeFloating)
}
yylex.(*Parser).setFreeFloating($$, freefloating.ParameterList, $7.FreeFloating)
if $9 != nil {
yylex.(*Parser).setFreeFloating($$, freefloating.LexicalVars, (*$9.GetFreeFloating())[freefloating.Colon]); delete((*$9.GetFreeFloating()), freefloating.Colon)
}
yylex.(*Parser).setFreeFloating($$, freefloating.ReturnType, $10.FreeFloating)
yylex.(*Parser).setFreeFloating($$, freefloating.Stmts, $12.FreeFloating)
} else {
yylex.(*Parser).setFreeFloating($$, freefloating.Function, $2.FreeFloating)
yylex.(*Parser).setFreeFloating($$, freefloating.Ampersand, $3.FreeFloating)
};
yylex.(*Parser).setFreeFloating($$, freefloating.ParameterList, $5.FreeFloating)
if $6 != nil {
yylex.(*Parser).setFreeFloating($$, freefloating.Params, (*$6.GetFreeFloating())[freefloating.Colon]); delete((*$6.GetFreeFloating()), freefloating.Colon)
};
yylex.(*Parser).setFreeFloating($$, freefloating.ReturnType, $8.FreeFloating)
// normalize
if $9 == nil {
yylex.(*Parser).setFreeFloating($$, freefloating.LexicalVars, (*$$.GetFreeFloating())[freefloating.ReturnType]); delete((*$$.GetFreeFloating()), freefloating.ReturnType)
}
if $8 == nil {
yylex.(*Parser).setFreeFloating($$, freefloating.Params, (*$$.GetFreeFloating())[freefloating.LexicalVarList]); delete((*$$.GetFreeFloating()), freefloating.LexicalVarList)
}
if $6 == nil {
yylex.(*Parser).setFreeFloating($$, freefloating.Params, (*$$.GetFreeFloating())[freefloating.ReturnType]); delete((*$$.GetFreeFloating()), freefloating.ReturnType)
};
yylex.(*Parser).returnTokenToPool(yyDollar, &yyVAL)
}
@@ -5122,7 +5162,7 @@ array_pair_list:
possible_array_pair:
/* empty */
{
$$ = expr.NewArrayItem(nil, nil)
$$ = expr.NewArrayItem(nil, nil, false)
yylex.(*Parser).returnTokenToPool(yyDollar, &yyVAL)
}
@@ -5138,7 +5178,7 @@ non_empty_array_pair_list:
non_empty_array_pair_list ',' possible_array_pair
{
if len($1) == 0 {
$1 = []node.Node{expr.NewArrayItem(nil, nil)}
$1 = []node.Node{expr.NewArrayItem(nil, nil, false)}
}
$$ = append($1, $3)
@@ -5163,7 +5203,7 @@ non_empty_array_pair_list:
array_pair:
expr T_DOUBLE_ARROW expr
{
$$ = expr.NewArrayItem($1, $3)
$$ = expr.NewArrayItem($1, $3, false)
// save position
$$.SetPosition(yylex.(*Parser).positionBuilder.NewNodesPosition($1, $3))
@@ -5176,7 +5216,7 @@ array_pair:
}
| expr
{
$$ = expr.NewArrayItem(nil, $1)
$$ = expr.NewArrayItem(nil, $1, false)
// save position
$$.SetPosition(yylex.(*Parser).positionBuilder.NewNodePosition($1))
@@ -5189,7 +5229,7 @@ array_pair:
| expr T_DOUBLE_ARROW '&' variable
{
reference := expr.NewReference($4)
$$ = expr.NewArrayItem($1, reference)
$$ = expr.NewArrayItem($1, reference, false)
// save position
$$.SetPosition(yylex.(*Parser).positionBuilder.NewNodesPosition($1, $4))
@@ -5205,7 +5245,7 @@ array_pair:
| '&' variable
{
reference := expr.NewReference($2)
$$ = expr.NewArrayItem(nil, reference)
$$ = expr.NewArrayItem(nil, reference, false)
// save position
$$.SetPosition(yylex.(*Parser).positionBuilder.NewTokenNodePosition($1, $2))
@@ -5214,13 +5254,25 @@ array_pair:
// save comments
yylex.(*Parser).setFreeFloating($$, freefloating.Start, $1.FreeFloating)
yylex.(*Parser).returnTokenToPool(yyDollar, &yyVAL)
}
| T_ELLIPSIS expr
{
$$ = expr.NewArrayItem(nil, $2, true)
// save position
$$.SetPosition(yylex.(*Parser).positionBuilder.NewTokenNodePosition($1, $2))
// save comments
yylex.(*Parser).setFreeFloating($$, freefloating.Start, $1.FreeFloating)
yylex.(*Parser).returnTokenToPool(yyDollar, &yyVAL)
}
| expr T_DOUBLE_ARROW T_LIST '(' array_pair_list ')'
{
// TODO: Cannot use list() as standalone expression
listNode := expr.NewList($5)
$$ = expr.NewArrayItem($1, listNode)
$$ = expr.NewArrayItem($1, listNode, false)
// save position
listNode.SetPosition(yylex.(*Parser).positionBuilder.NewTokensPosition($3, $6))
@@ -5239,7 +5291,7 @@ array_pair:
{
// TODO: Cannot use list() as standalone expression
listNode := expr.NewList($3)
$$ = expr.NewArrayItem(nil, listNode)
$$ = expr.NewArrayItem(nil, listNode, false)
// save position
listNode.SetPosition(yylex.(*Parser).positionBuilder.NewTokensPosition($1, $4))

View File

@@ -381,7 +381,7 @@ CAD;
`
for n := 0; n < b.N; n++ {
php7parser := php7.NewParser([]byte(src))
php7parser := php7.NewParser([]byte(src), "7.4")
php7parser.Parse()
}
}

View File

@@ -16118,7 +16118,7 @@ func TestPhp7(t *testing.T) {
},
}
php7parser := php7.NewParser([]byte(src))
php7parser := php7.NewParser([]byte(src), "7.4")
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
@@ -16233,7 +16233,7 @@ func TestPhp5Strings(t *testing.T) {
},
}
php7parser := php7.NewParser([]byte(src))
php7parser := php7.NewParser([]byte(src), "7.4")
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
@@ -16423,7 +16423,7 @@ CAD;
},
}
php7parser := php7.NewParser([]byte(src))
php7parser := php7.NewParser([]byte(src), "7.4")
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
@@ -16443,7 +16443,7 @@ func TestPhp7ControlCharsErrors(t *testing.T) {
},
}
php7parser := php7.NewParser([]byte(src))
php7parser := php7.NewParser([]byte(src), "7.4")
php7parser.Parse()
actual := php7parser.GetErrors()
assert.DeepEqual(t, expected, actual)

View File

@@ -1,4 +1,4 @@
package parser
package positionbuilder
import (
"github.com/z7zmey/php-parser/node"

View File

@@ -1,17 +1,17 @@
package parser_test
package positionbuilder_test
import (
"testing"
"github.com/z7zmey/php-parser/node"
"github.com/z7zmey/php-parser/parser"
"github.com/z7zmey/php-parser/position"
"github.com/z7zmey/php-parser/positionbuilder"
"github.com/z7zmey/php-parser/scanner"
)
func TestNewTokenPosition(t *testing.T) {
builder := parser.PositionBuilder{}
builder := positionbuilder.PositionBuilder{}
tkn := &scanner.Token{
Value: `foo`,
@@ -29,7 +29,7 @@ func TestNewTokenPosition(t *testing.T) {
}
func TestNewTokensPosition(t *testing.T) {
builder := parser.PositionBuilder{}
builder := positionbuilder.PositionBuilder{}
token1 := &scanner.Token{
Value: `foo`,
@@ -62,7 +62,7 @@ func TestNewNodePosition(t *testing.T) {
EndPos: 3,
})
builder := parser.PositionBuilder{}
builder := positionbuilder.PositionBuilder{}
pos := builder.NewNodePosition(n)
@@ -87,7 +87,7 @@ func TestNewTokenNodePosition(t *testing.T) {
EndPos: 12,
})
builder := parser.PositionBuilder{}
builder := positionbuilder.PositionBuilder{}
pos := builder.NewTokenNodePosition(tkn, n)
@@ -113,7 +113,7 @@ func TestNewNodeTokenPosition(t *testing.T) {
EndPos: 12,
}
builder := parser.PositionBuilder{}
builder := positionbuilder.PositionBuilder{}
pos := builder.NewNodeTokenPosition(n, tkn)
@@ -139,7 +139,7 @@ func TestNewNodeListPosition(t *testing.T) {
EndPos: 19,
})
builder := parser.PositionBuilder{}
builder := positionbuilder.PositionBuilder{}
pos := builder.NewNodeListPosition([]node.Node{n1, n2})
@@ -165,7 +165,7 @@ func TestNewNodesPosition(t *testing.T) {
EndPos: 19,
})
builder := parser.PositionBuilder{}
builder := positionbuilder.PositionBuilder{}
pos := builder.NewNodesPosition(n1, n2)
@@ -199,7 +199,7 @@ func TestNewNodeListTokenPosition(t *testing.T) {
EndPos: 22,
}
builder := parser.PositionBuilder{}
builder := positionbuilder.PositionBuilder{}
pos := builder.NewNodeListTokenPosition([]node.Node{n1, n2}, tkn)
@@ -233,7 +233,7 @@ func TestNewTokenNodeListPosition(t *testing.T) {
EndPos: 20,
})
builder := parser.PositionBuilder{}
builder := positionbuilder.PositionBuilder{}
pos := builder.NewTokenNodeListPosition(tkn, []node.Node{n1, n2})
@@ -267,7 +267,7 @@ func TestNewNodeNodeListPosition(t *testing.T) {
EndPos: 26,
})
builder := parser.PositionBuilder{}
builder := positionbuilder.PositionBuilder{}
pos := builder.NewNodeNodeListPosition(n1, []node.Node{n2, n3})
@@ -299,7 +299,7 @@ func TestNewNodeListNodePosition(t *testing.T) {
EndPos: 26,
})
builder := parser.PositionBuilder{}
builder := positionbuilder.PositionBuilder{}
pos := builder.NewNodeListNodePosition([]node.Node{n1, n2}, n3)
@@ -309,7 +309,7 @@ func TestNewNodeListNodePosition(t *testing.T) {
}
func TestNewOptionalListTokensPosition(t *testing.T) {
builder := parser.PositionBuilder{}
builder := positionbuilder.PositionBuilder{}
token1 := &scanner.Token{
Value: `foo`,
@@ -356,7 +356,7 @@ func TestNewOptionalListTokensPosition2(t *testing.T) {
EndPos: 26,
})
builder := parser.PositionBuilder{}
builder := positionbuilder.PositionBuilder{}
token1 := &scanner.Token{
Value: `foo`,
@@ -381,7 +381,7 @@ func TestNewOptionalListTokensPosition2(t *testing.T) {
}
func TestNilNodePos(t *testing.T) {
builder := parser.PositionBuilder{}
builder := positionbuilder.PositionBuilder{}
pos := builder.NewNodesPosition(nil, nil)
@@ -399,7 +399,7 @@ func TestNilNodeListPos(t *testing.T) {
EndPos: 8,
})
builder := parser.PositionBuilder{}
builder := positionbuilder.PositionBuilder{}
pos := builder.NewNodeNodeListPosition(n1, nil)
@@ -417,7 +417,7 @@ func TestNilNodeListTokenPos(t *testing.T) {
EndPos: 3,
}
builder := parser.PositionBuilder{}
builder := positionbuilder.PositionBuilder{}
pos := builder.NewNodeListTokenPosition(nil, token)
@@ -435,7 +435,7 @@ func TestEmptyNodeListPos(t *testing.T) {
EndPos: 8,
})
builder := parser.PositionBuilder{}
builder := positionbuilder.PositionBuilder{}
pos := builder.NewNodeNodeListPosition(n1, []node.Node{})
@@ -453,7 +453,7 @@ func TestEmptyNodeListTokenPos(t *testing.T) {
EndPos: 3,
}
builder := parser.PositionBuilder{}
builder := positionbuilder.PositionBuilder{}
pos := builder.NewNodeListTokenPosition([]node.Node{}, token)

View File

@@ -135,6 +135,8 @@ func (p *Printer) printNode(n node.Node) {
p.printAssignBitwiseOr(n)
case *assign.BitwiseXor:
p.printAssignBitwiseXor(n)
case *assign.Coalesce:
p.printAssignCoalesce(n)
case *assign.Concat:
p.printAssignConcat(n)
case *assign.Div:
@@ -236,6 +238,8 @@ func (p *Printer) printNode(n node.Node) {
p.printExprArrayItem(n)
case *expr.Array:
p.printExprArray(n)
case *expr.ArrowFunction:
p.printExprArrowFunction(n)
case *expr.BitwiseNot:
p.printExprBitwiseNot(n)
case *expr.BooleanNot:
@@ -712,6 +716,17 @@ func (p *Printer) printAssignBitwiseXor(n node.Node) {
p.printFreeFloating(nn, freefloating.End)
}
func (p *Printer) printAssignCoalesce(n node.Node) {
nn := n.(*assign.Coalesce)
p.printFreeFloating(nn, freefloating.Start)
p.Print(nn.Variable)
p.printFreeFloating(nn, freefloating.Var)
io.WriteString(p.w, "??=")
p.Print(nn.Expression)
p.printFreeFloating(nn, freefloating.End)
}
func (p *Printer) printAssignConcat(n node.Node) {
nn := n.(*assign.Concat)
p.printFreeFloating(nn, freefloating.Start)
@@ -1289,6 +1304,10 @@ func (p *Printer) printExprArrayItem(n node.Node) {
nn := n.(*expr.ArrayItem)
p.printFreeFloating(nn, freefloating.Start)
if nn.Unpack {
io.WriteString(p.w, "...")
}
if nn.Key != nil {
p.Print(nn.Key)
p.printFreeFloating(nn, freefloating.Expr)
@@ -1313,6 +1332,45 @@ func (p *Printer) printExprArray(n node.Node) {
p.printFreeFloating(nn, freefloating.End)
}
func (p *Printer) printExprArrowFunction(n node.Node) {
nn := n.(*expr.ArrowFunction)
p.printFreeFloating(nn, freefloating.Start)
if nn.Static {
io.WriteString(p.w, "static")
}
p.printFreeFloating(nn, freefloating.Static)
if nn.Static && n.GetFreeFloating().IsEmpty() {
io.WriteString(p.w, " ")
}
io.WriteString(p.w, "fn")
p.printFreeFloating(nn, freefloating.Function)
if nn.ReturnsRef {
io.WriteString(p.w, "&")
}
p.printFreeFloating(nn, freefloating.Ampersand)
io.WriteString(p.w, "(")
p.joinPrint(",", nn.Params)
p.printFreeFloating(nn, freefloating.ParameterList)
io.WriteString(p.w, ")")
p.printFreeFloating(nn, freefloating.Params)
if nn.ReturnType != nil {
io.WriteString(p.w, ":")
p.Print(nn.ReturnType)
}
p.printFreeFloating(nn, freefloating.ReturnType)
io.WriteString(p.w, "=>")
p.printNode(nn.Expr)
p.printFreeFloating(nn, freefloating.End)
}
func (p *Printer) printExprBitwiseNot(n node.Node) {
nn := n.(*expr.BitwiseNot)
p.printFreeFloating(nn, freefloating.Start)
@@ -2834,6 +2892,12 @@ func (p *Printer) printStmtPropertyList(n node.Node) {
p.Print(m)
}
if nn.Type != nil && nn.Type.GetFreeFloating().IsEmpty() {
io.WriteString(p.w, " ")
}
p.Print(nn.Type)
if nn.Properties[0].GetFreeFloating().IsEmpty() {
io.WriteString(p.w, " ")
}

View File

@@ -10,7 +10,7 @@ import (
)
func parsePhp5(src string) node.Node {
php5parser := php5.NewParser([]byte(src))
php5parser := php5.NewParser([]byte(src), "5.6")
php5parser.WithFreeFloating()
php5parser.Parse()
@@ -1077,6 +1077,18 @@ func TestParseAndPrintPhp5InlineHtml(t *testing.T) {
}
}
func TestParseAndPrintPhp5Shebang(t *testing.T) {
src := `#!/usr/bin/env php
<?php
$a;?>test<? `
actual := print(parse(src))
if src != actual {
t.Errorf("\nexpected: %s\ngot: %s\n", src, actual)
}
}
func TestParseAndPrintPhp5Interface(t *testing.T) {
src := `<?php
interface Foo extends Bar , Baz {

Some files were not shown because too many files have changed in this diff Show More