Merge branch 'php5syntax'
This commit is contained in:
@@ -4,14 +4,16 @@ import "github.com/z7zmey/php-parser/walker"
|
||||
|
||||
// Argument node
|
||||
type Argument struct {
|
||||
Variadic bool // if ... before variable
|
||||
Expr Node // Exression
|
||||
Variadic bool // if ... before variable
|
||||
IsReference bool // if & before variable
|
||||
Expr Node // Exression
|
||||
}
|
||||
|
||||
// NewArgument node constuctor
|
||||
func NewArgument(Expression Node, Variadic bool) *Argument {
|
||||
func NewArgument(Expression Node, Variadic bool, IsReference bool) *Argument {
|
||||
return &Argument{
|
||||
Variadic,
|
||||
IsReference,
|
||||
Expression,
|
||||
}
|
||||
}
|
||||
@@ -19,7 +21,8 @@ func NewArgument(Expression Node, Variadic bool) *Argument {
|
||||
// Attributes returns node attributes as map
|
||||
func (n *Argument) Attributes() map[string]interface{} {
|
||||
return map[string]interface{}{
|
||||
"Variadic": n.Variadic,
|
||||
"Variadic": n.Variadic,
|
||||
"IsReference": n.IsReference,
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -22,6 +22,11 @@ func (n *Variable) Attributes() map[string]interface{} {
|
||||
return nil
|
||||
}
|
||||
|
||||
// SetVarName reset var name
|
||||
func (n *Variable) SetVarName(VarName node.Node) {
|
||||
n.VarName = VarName
|
||||
}
|
||||
|
||||
// Walk traverses nodes
|
||||
// Walk is invoked recursively until v.EnterNode returns true
|
||||
func (n *Variable) Walk(v walker.Visitor) {
|
||||
|
||||
@@ -12,7 +12,7 @@ import (
|
||||
"github.com/kylelemons/godebug/pretty"
|
||||
"github.com/z7zmey/php-parser/node"
|
||||
"github.com/z7zmey/php-parser/node/stmt"
|
||||
"github.com/z7zmey/php-parser/parser"
|
||||
"github.com/z7zmey/php-parser/php7"
|
||||
)
|
||||
|
||||
func assertEqual(t *testing.T, expected interface{}, actual interface{}) {
|
||||
@@ -44,7 +44,7 @@ func TestName(t *testing.T) {
|
||||
},
|
||||
}
|
||||
|
||||
actual, _, _ := parser.ParsePhp7(bytes.NewBufferString(src), "test.php")
|
||||
actual, _, _ := php7.Parse(bytes.NewBufferString(src), "test.php")
|
||||
|
||||
assertEqual(t, expected, actual)
|
||||
}
|
||||
@@ -65,7 +65,7 @@ func TestFullyQualified(t *testing.T) {
|
||||
},
|
||||
}
|
||||
|
||||
actual, _, _ := parser.ParsePhp7(bytes.NewBufferString(src), "test.php")
|
||||
actual, _, _ := php7.Parse(bytes.NewBufferString(src), "test.php")
|
||||
|
||||
assertEqual(t, expected, actual)
|
||||
}
|
||||
@@ -86,7 +86,7 @@ func TestRelative(t *testing.T) {
|
||||
},
|
||||
}
|
||||
|
||||
actual, _, _ := parser.ParsePhp7(bytes.NewBufferString(src), "test.php")
|
||||
actual, _, _ := php7.Parse(bytes.NewBufferString(src), "test.php")
|
||||
|
||||
assertEqual(t, expected, actual)
|
||||
}
|
||||
|
||||
@@ -12,7 +12,7 @@ import (
|
||||
"github.com/kylelemons/godebug/pretty"
|
||||
"github.com/z7zmey/php-parser/node"
|
||||
"github.com/z7zmey/php-parser/node/stmt"
|
||||
"github.com/z7zmey/php-parser/parser"
|
||||
"github.com/z7zmey/php-parser/php7"
|
||||
)
|
||||
|
||||
func assertEqual(t *testing.T, expected interface{}, actual interface{}) {
|
||||
@@ -41,7 +41,7 @@ func TestIdentifier(t *testing.T) {
|
||||
},
|
||||
}
|
||||
|
||||
actual, _, _ := parser.ParsePhp7(bytes.NewBufferString(src), "test.php")
|
||||
actual, _, _ := php7.Parse(bytes.NewBufferString(src), "test.php")
|
||||
|
||||
assertEqual(t, expected, actual)
|
||||
}
|
||||
@@ -132,7 +132,7 @@ func TestArgumentNode(t *testing.T) {
|
||||
},
|
||||
}
|
||||
|
||||
actual, _, _ := parser.ParsePhp7(bytes.NewBufferString(src), "test.php")
|
||||
actual, _, _ := php7.Parse(bytes.NewBufferString(src), "test.php")
|
||||
|
||||
assertEqual(t, expected, actual)
|
||||
}
|
||||
@@ -198,7 +198,7 @@ func TestParameterNode(t *testing.T) {
|
||||
},
|
||||
}
|
||||
|
||||
actual, _, _ := parser.ParsePhp7(bytes.NewBufferString(src), "test.php")
|
||||
actual, _, _ := php7.Parse(bytes.NewBufferString(src), "test.php")
|
||||
|
||||
assertEqual(t, expected, actual)
|
||||
}
|
||||
|
||||
@@ -10,7 +10,7 @@ import (
|
||||
"github.com/z7zmey/php-parser/node"
|
||||
"github.com/z7zmey/php-parser/node/scalar"
|
||||
"github.com/z7zmey/php-parser/node/stmt"
|
||||
"github.com/z7zmey/php-parser/parser"
|
||||
"github.com/z7zmey/php-parser/php7"
|
||||
)
|
||||
|
||||
func TestSimpleVar(t *testing.T) {
|
||||
@@ -29,7 +29,7 @@ func TestSimpleVar(t *testing.T) {
|
||||
},
|
||||
}
|
||||
|
||||
actual, _, _ := parser.ParsePhp7(bytes.NewBufferString(src), "test.php")
|
||||
actual, _, _ := php7.Parse(bytes.NewBufferString(src), "test.php")
|
||||
|
||||
if diff := pretty.Compare(expected, actual); diff != "" {
|
||||
t.Errorf("diff: (-expected +actual)\n%s", diff)
|
||||
@@ -56,7 +56,7 @@ func TestSimpleVarPropertyFetch(t *testing.T) {
|
||||
},
|
||||
}
|
||||
|
||||
actual, _, _ := parser.ParsePhp7(bytes.NewBufferString(src), "test.php")
|
||||
actual, _, _ := php7.Parse(bytes.NewBufferString(src), "test.php")
|
||||
|
||||
if diff := pretty.Compare(expected, actual); diff != "" {
|
||||
t.Errorf("diff: (-expected +actual)\n%s", diff)
|
||||
@@ -79,7 +79,7 @@ func TestDollarOpenCurlyBraces(t *testing.T) {
|
||||
},
|
||||
}
|
||||
|
||||
actual, _, _ := parser.ParsePhp7(bytes.NewBufferString(src), "test.php")
|
||||
actual, _, _ := php7.Parse(bytes.NewBufferString(src), "test.php")
|
||||
|
||||
if diff := pretty.Compare(expected, actual); diff != "" {
|
||||
t.Errorf("diff: (-expected +actual)\n%s", diff)
|
||||
@@ -105,7 +105,7 @@ func TestDollarOpenCurlyBracesDimNumber(t *testing.T) {
|
||||
},
|
||||
}
|
||||
|
||||
actual, _, _ := parser.ParsePhp7(bytes.NewBufferString(src), "test.php")
|
||||
actual, _, _ := php7.Parse(bytes.NewBufferString(src), "test.php")
|
||||
|
||||
if diff := pretty.Compare(expected, actual); diff != "" {
|
||||
t.Errorf("diff: (-expected +actual)\n%s", diff)
|
||||
@@ -131,7 +131,7 @@ func TestCurlyOpenMethodCall(t *testing.T) {
|
||||
},
|
||||
}
|
||||
|
||||
actual, _, _ := parser.ParsePhp7(bytes.NewBufferString(src), "test.php")
|
||||
actual, _, _ := php7.Parse(bytes.NewBufferString(src), "test.php")
|
||||
|
||||
if diff := pretty.Compare(expected, actual); diff != "" {
|
||||
t.Errorf("diff: (-expected +actual)\n%s", diff)
|
||||
|
||||
@@ -8,7 +8,7 @@ import (
|
||||
"github.com/z7zmey/php-parser/node"
|
||||
"github.com/z7zmey/php-parser/node/scalar"
|
||||
"github.com/z7zmey/php-parser/node/stmt"
|
||||
"github.com/z7zmey/php-parser/parser"
|
||||
"github.com/z7zmey/php-parser/php7"
|
||||
)
|
||||
|
||||
func TestMagicConstant(t *testing.T) {
|
||||
@@ -22,7 +22,7 @@ func TestMagicConstant(t *testing.T) {
|
||||
},
|
||||
}
|
||||
|
||||
actual, _, _ := parser.ParsePhp7(bytes.NewBufferString(src), "test.php")
|
||||
actual, _, _ := php7.Parse(bytes.NewBufferString(src), "test.php")
|
||||
|
||||
if diff := pretty.Compare(expected, actual); diff != "" {
|
||||
t.Errorf("diff: (-expected +actual)\n%s", diff)
|
||||
|
||||
@@ -9,7 +9,7 @@ import (
|
||||
"github.com/z7zmey/php-parser/node"
|
||||
"github.com/z7zmey/php-parser/node/scalar"
|
||||
"github.com/z7zmey/php-parser/node/stmt"
|
||||
"github.com/z7zmey/php-parser/parser"
|
||||
"github.com/z7zmey/php-parser/php7"
|
||||
)
|
||||
|
||||
func assertEqual(t *testing.T, expected interface{}, actual interface{}) {
|
||||
@@ -36,7 +36,7 @@ func TestLNumber(t *testing.T) {
|
||||
},
|
||||
}
|
||||
|
||||
actual, _, _ := parser.ParsePhp7(bytes.NewBufferString(src), "test.php")
|
||||
actual, _, _ := php7.Parse(bytes.NewBufferString(src), "test.php")
|
||||
|
||||
assertEqual(t, expected, actual)
|
||||
}
|
||||
@@ -52,7 +52,7 @@ func TestDNumber(t *testing.T) {
|
||||
},
|
||||
}
|
||||
|
||||
actual, _, _ := parser.ParsePhp7(bytes.NewBufferString(src), "test.php")
|
||||
actual, _, _ := php7.Parse(bytes.NewBufferString(src), "test.php")
|
||||
|
||||
assertEqual(t, expected, actual)
|
||||
}
|
||||
@@ -68,7 +68,7 @@ func TestFloat(t *testing.T) {
|
||||
},
|
||||
}
|
||||
|
||||
actual, _, _ := parser.ParsePhp7(bytes.NewBufferString(src), "test.php")
|
||||
actual, _, _ := php7.Parse(bytes.NewBufferString(src), "test.php")
|
||||
|
||||
assertEqual(t, expected, actual)
|
||||
}
|
||||
@@ -84,7 +84,7 @@ func TestBinaryLNumber(t *testing.T) {
|
||||
},
|
||||
}
|
||||
|
||||
actual, _, _ := parser.ParsePhp7(bytes.NewBufferString(src), "test.php")
|
||||
actual, _, _ := php7.Parse(bytes.NewBufferString(src), "test.php")
|
||||
|
||||
assertEqual(t, expected, actual)
|
||||
}
|
||||
@@ -100,7 +100,7 @@ func TestBinaryDNumber(t *testing.T) {
|
||||
},
|
||||
}
|
||||
|
||||
actual, _, _ := parser.ParsePhp7(bytes.NewBufferString(src), "test.php")
|
||||
actual, _, _ := php7.Parse(bytes.NewBufferString(src), "test.php")
|
||||
|
||||
assertEqual(t, expected, actual)
|
||||
}
|
||||
@@ -116,7 +116,7 @@ func TestHLNumber(t *testing.T) {
|
||||
},
|
||||
}
|
||||
|
||||
actual, _, _ := parser.ParsePhp7(bytes.NewBufferString(src), "test.php")
|
||||
actual, _, _ := php7.Parse(bytes.NewBufferString(src), "test.php")
|
||||
|
||||
assertEqual(t, expected, actual)
|
||||
}
|
||||
@@ -132,7 +132,7 @@ func TestHDNumber(t *testing.T) {
|
||||
},
|
||||
}
|
||||
|
||||
actual, _, _ := parser.ParsePhp7(bytes.NewBufferString(src), "test.php")
|
||||
actual, _, _ := php7.Parse(bytes.NewBufferString(src), "test.php")
|
||||
|
||||
assertEqual(t, expected, actual)
|
||||
}
|
||||
|
||||
@@ -8,7 +8,7 @@ import (
|
||||
"github.com/z7zmey/php-parser/node"
|
||||
"github.com/z7zmey/php-parser/node/scalar"
|
||||
"github.com/z7zmey/php-parser/node/stmt"
|
||||
"github.com/z7zmey/php-parser/parser"
|
||||
"github.com/z7zmey/php-parser/php7"
|
||||
)
|
||||
|
||||
func TestDoubleQuotedScalarString(t *testing.T) {
|
||||
@@ -22,7 +22,7 @@ func TestDoubleQuotedScalarString(t *testing.T) {
|
||||
},
|
||||
}
|
||||
|
||||
actual, _, _ := parser.ParsePhp7(bytes.NewBufferString(src), "test.php")
|
||||
actual, _, _ := php7.Parse(bytes.NewBufferString(src), "test.php")
|
||||
|
||||
if diff := pretty.Compare(expected, actual); diff != "" {
|
||||
t.Errorf("diff: (-expected +actual)\n%s", diff)
|
||||
@@ -39,7 +39,7 @@ func TestDoubleQuotedScalarStringWithEscapedVar(t *testing.T) {
|
||||
},
|
||||
}
|
||||
|
||||
actual, _, _ := parser.ParsePhp7(bytes.NewBufferString(src), "test.php")
|
||||
actual, _, _ := php7.Parse(bytes.NewBufferString(src), "test.php")
|
||||
|
||||
if diff := pretty.Compare(expected, actual); diff != "" {
|
||||
t.Errorf("diff: (-expected +actual)\n%s", diff)
|
||||
@@ -59,7 +59,7 @@ func TestMultilineDoubleQuotedScalarString(t *testing.T) {
|
||||
},
|
||||
}
|
||||
|
||||
actual, _, _ := parser.ParsePhp7(bytes.NewBufferString(src), "test.php")
|
||||
actual, _, _ := php7.Parse(bytes.NewBufferString(src), "test.php")
|
||||
|
||||
if diff := pretty.Compare(expected, actual); diff != "" {
|
||||
t.Errorf("diff: (-expected +actual)\n%s", diff)
|
||||
@@ -77,7 +77,7 @@ func TestSingleQuotedScalarString(t *testing.T) {
|
||||
},
|
||||
}
|
||||
|
||||
actual, _, _ := parser.ParsePhp7(bytes.NewBufferString(src), "test.php")
|
||||
actual, _, _ := php7.Parse(bytes.NewBufferString(src), "test.php")
|
||||
|
||||
if diff := pretty.Compare(expected, actual); diff != "" {
|
||||
t.Errorf("diff: (-expected +actual)\n%s", diff)
|
||||
@@ -97,7 +97,7 @@ func TestMultilineSingleQuotedScalarString(t *testing.T) {
|
||||
},
|
||||
}
|
||||
|
||||
actual, _, _ := parser.ParsePhp7(bytes.NewBufferString(src), "test.php")
|
||||
actual, _, _ := php7.Parse(bytes.NewBufferString(src), "test.php")
|
||||
|
||||
if diff := pretty.Compare(expected, actual); diff != "" {
|
||||
t.Errorf("diff: (-expected +actual)\n%s", diff)
|
||||
@@ -118,7 +118,7 @@ CAD;
|
||||
},
|
||||
}
|
||||
|
||||
actual, _, _ := parser.ParsePhp7(bytes.NewBufferString(src), "test.php")
|
||||
actual, _, _ := php7.Parse(bytes.NewBufferString(src), "test.php")
|
||||
|
||||
if diff := pretty.Compare(expected, actual); diff != "" {
|
||||
t.Errorf("diff: (-expected +actual)\n%s", diff)
|
||||
@@ -139,7 +139,7 @@ CAD;
|
||||
},
|
||||
}
|
||||
|
||||
actual, _, _ := parser.ParsePhp7(bytes.NewBufferString(src), "test.php")
|
||||
actual, _, _ := php7.Parse(bytes.NewBufferString(src), "test.php")
|
||||
|
||||
if diff := pretty.Compare(expected, actual); diff != "" {
|
||||
t.Errorf("diff: (-expected +actual)\n%s", diff)
|
||||
@@ -160,7 +160,7 @@ CAD;
|
||||
},
|
||||
}
|
||||
|
||||
actual, _, _ := parser.ParsePhp7(bytes.NewBufferString(src), "test.php")
|
||||
actual, _, _ := php7.Parse(bytes.NewBufferString(src), "test.php")
|
||||
|
||||
if diff := pretty.Compare(expected, actual); diff != "" {
|
||||
t.Errorf("diff: (-expected +actual)\n%s", diff)
|
||||
|
||||
@@ -14,12 +14,12 @@ type AltIf struct {
|
||||
}
|
||||
|
||||
// NewAltIf node constuctor
|
||||
func NewAltIf(Cond node.Node, Stmt node.Node) *AltIf {
|
||||
func NewAltIf(Cond node.Node, Stmt node.Node, ElseIf []node.Node, Else node.Node) *AltIf {
|
||||
return &AltIf{
|
||||
Cond,
|
||||
Stmt,
|
||||
nil,
|
||||
nil,
|
||||
ElseIf,
|
||||
Else,
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -10,7 +10,7 @@ import (
|
||||
"github.com/kylelemons/godebug/pretty"
|
||||
"github.com/z7zmey/php-parser/node"
|
||||
"github.com/z7zmey/php-parser/node/stmt"
|
||||
"github.com/z7zmey/php-parser/parser"
|
||||
"github.com/z7zmey/php-parser/php7"
|
||||
)
|
||||
|
||||
func assertEqual(t *testing.T, expected interface{}, actual interface{}) {
|
||||
@@ -41,7 +41,7 @@ func TestAltIf(t *testing.T) {
|
||||
},
|
||||
}
|
||||
|
||||
actual, _, _ := parser.ParsePhp7(bytes.NewBufferString(src), "test.php")
|
||||
actual, _, _ := php7.Parse(bytes.NewBufferString(src), "test.php")
|
||||
|
||||
assertEqual(t, expected, actual)
|
||||
}
|
||||
@@ -68,7 +68,7 @@ func TestAltElseIf(t *testing.T) {
|
||||
},
|
||||
}
|
||||
|
||||
actual, _, _ := parser.ParsePhp7(bytes.NewBufferString(src), "test.php")
|
||||
actual, _, _ := php7.Parse(bytes.NewBufferString(src), "test.php")
|
||||
|
||||
assertEqual(t, expected, actual)
|
||||
}
|
||||
@@ -92,7 +92,7 @@ func TestAltElse(t *testing.T) {
|
||||
},
|
||||
}
|
||||
|
||||
actual, _, _ := parser.ParsePhp7(bytes.NewBufferString(src), "test.php")
|
||||
actual, _, _ := php7.Parse(bytes.NewBufferString(src), "test.php")
|
||||
|
||||
assertEqual(t, expected, actual)
|
||||
}
|
||||
@@ -128,7 +128,7 @@ func TestAltElseElseIf(t *testing.T) {
|
||||
},
|
||||
}
|
||||
|
||||
actual, _, _ := parser.ParsePhp7(bytes.NewBufferString(src), "test.php")
|
||||
actual, _, _ := php7.Parse(bytes.NewBufferString(src), "test.php")
|
||||
|
||||
assertEqual(t, expected, actual)
|
||||
}
|
||||
|
||||
@@ -10,16 +10,16 @@ type If struct {
|
||||
Cond node.Node
|
||||
Stmt node.Node
|
||||
ElseIf []node.Node
|
||||
_else node.Node
|
||||
Else node.Node
|
||||
}
|
||||
|
||||
// NewIf node constuctor
|
||||
func NewIf(Cond node.Node, Stmt node.Node) *If {
|
||||
func NewIf(Cond node.Node, Stmt node.Node, ElseIf []node.Node, Else node.Node) *If {
|
||||
return &If{
|
||||
Cond,
|
||||
Stmt,
|
||||
nil,
|
||||
nil,
|
||||
ElseIf,
|
||||
Else,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -38,8 +38,8 @@ func (n *If) AddElseIf(ElseIf node.Node) node.Node {
|
||||
return n
|
||||
}
|
||||
|
||||
func (n *If) SetElse(_else node.Node) node.Node {
|
||||
n._else = _else
|
||||
func (n *If) SetElse(Else node.Node) node.Node {
|
||||
n.Else = Else
|
||||
|
||||
return n
|
||||
}
|
||||
@@ -70,9 +70,9 @@ func (n *If) Walk(v walker.Visitor) {
|
||||
}
|
||||
}
|
||||
|
||||
if n._else != nil {
|
||||
if n.Else != nil {
|
||||
vv := v.GetChildrenVisitor("else")
|
||||
n._else.Walk(vv)
|
||||
n.Else.Walk(vv)
|
||||
}
|
||||
|
||||
v.LeaveNode(n)
|
||||
|
||||
@@ -31,7 +31,7 @@ var nodesToTest = []struct {
|
||||
{
|
||||
&node.Argument{Variadic: true, Expr: &expr.Variable{VarName: &node.Identifier{Value: "foo"}}},
|
||||
[]string{"Expr"},
|
||||
map[string]interface{}{"Variadic": true},
|
||||
map[string]interface{}{"IsReference": false, "Variadic": true},
|
||||
},
|
||||
{
|
||||
&node.Parameter{
|
||||
|
||||
Reference in New Issue
Block a user