diff --git a/node/argument.go b/node/argument.go index 31056e7..6102d97 100644 --- a/node/argument.go +++ b/node/argument.go @@ -6,21 +6,25 @@ import ( ) type Argument struct { - SimpleNode + name string expr Node variadic bool } +func (n Argument) Name() string { + return "Argument" +} + func NewArgument(expression Node, variadic bool) Node { return Argument{ - SimpleNode{Name: "Argument", Attributes: make(map[string]string)}, + "Argument", expression, variadic, } } func (n Argument) Print(out io.Writer, indent string) { - fmt.Fprintf(out, "\n%v%v [- -]", indent, n.Name) + fmt.Fprintf(out, "\n%v%v [- -]", indent, n.name) fmt.Fprintf(out, "\n%vvariadic: %t", indent+" ", n.variadic) if n.expr != nil { diff --git a/node/expr/array.go b/node/expr/array.go index 9029fa1..883f487 100644 --- a/node/expr/array.go +++ b/node/expr/array.go @@ -8,8 +8,12 @@ import ( "github.com/z7zmey/php-parser/token" ) +func (n Array) Name() string { + return "Array" +} + type Array struct { - node.SimpleNode + name string opentToken token.Token closeToken token.Token items []node.Node @@ -17,7 +21,7 @@ type Array struct { func NewArray(opentToken token.Token, closeToken token.Token, items []node.Node) node.Node { return Array{ - node.SimpleNode{Name: "Array", Attributes: make(map[string]string)}, + "Array", opentToken, closeToken, items, @@ -25,7 +29,7 @@ func NewArray(opentToken token.Token, closeToken token.Token, items []node.Node) } func (n Array) Print(out io.Writer, indent string) { - fmt.Fprintf(out, "\n%v%v [%d %d]", indent, n.Name, n.opentToken.StartLine, n.closeToken.EndLine) + fmt.Fprintf(out, "\n%v%v [%d %d]", indent, n.name, n.opentToken.StartLine, n.closeToken.EndLine) if n.items != nil { fmt.Fprintf(out, "\n%vitems:", indent+" ") diff --git a/node/expr/array_dim_fetch.go b/node/expr/array_dim_fetch.go index 713fda3..e79f0cc 100644 --- a/node/expr/array_dim_fetch.go +++ b/node/expr/array_dim_fetch.go @@ -7,15 +7,19 @@ import ( "github.com/z7zmey/php-parser/node" ) +func (n ArrayDimFetch) Name() string { + return "ArrayDimFetch" +} + type ArrayDimFetch struct { - node.SimpleNode + name string variable node.Node dim node.Node } func NewArrayDimFetch(variable node.Node, dim node.Node) node.Node { return ArrayDimFetch{ - node.SimpleNode{Name: "ArrayDimFetch", Attributes: make(map[string]string)}, + "ArrayDimFetch", variable, dim, } diff --git a/node/expr/array_item.go b/node/expr/array_item.go index d1c3fb4..9b20b7e 100644 --- a/node/expr/array_item.go +++ b/node/expr/array_item.go @@ -7,16 +7,20 @@ import ( "github.com/z7zmey/php-parser/node" ) +func (n ArrayItem) Name() string { + return "ArrayItem" +} + type ArrayItem struct { - node.SimpleNode - key node.Node - val node.Node + name string + key node.Node + val node.Node byRef bool } func NewArrayItem(key node.Node, val node.Node, byRef bool) node.Node { return ArrayItem{ - node.SimpleNode{Name: "ArrayItem", Attributes: make(map[string]string)}, + "ArrayItem", key, val, byRef, @@ -24,7 +28,7 @@ func NewArrayItem(key node.Node, val node.Node, byRef bool) node.Node { } func (n ArrayItem) Print(out io.Writer, indent string) { - fmt.Fprintf(out, "\n%v%v [- -]", indent, n.Name) + fmt.Fprintf(out, "\n%v%v [- -]", indent, n.name) fmt.Fprintf(out, "\n%vbyRef: %t", indent+" ", n.byRef) if n.key != nil { diff --git a/node/expr/assign_op/assign.go b/node/expr/assign_op/assign.go index b673c4e..977a8d1 100644 --- a/node/expr/assign_op/assign.go +++ b/node/expr/assign_op/assign.go @@ -4,6 +4,10 @@ import ( "github.com/z7zmey/php-parser/node" ) +func (n Assign) Name() string { + return "Assign" +} + type Assign struct { AssignOp } @@ -11,7 +15,7 @@ type Assign struct { func NewAssign(variable node.Node, expression node.Node) node.Node { return Assign{ AssignOp{ - node.SimpleNode{Name: "Assign", Attributes: make(map[string]string)}, + "Assign", variable, expression, }, diff --git a/node/expr/assign_op/assign_op.go b/node/expr/assign_op/assign_op.go index 4cb819d..55d9629 100644 --- a/node/expr/assign_op/assign_op.go +++ b/node/expr/assign_op/assign_op.go @@ -8,13 +8,13 @@ import ( ) type AssignOp struct { - node.SimpleNode + name string variable node.Node expression node.Node } func (n AssignOp) Print(out io.Writer, indent string) { - fmt.Fprintf(out, "\n%v%v [- -]", indent, n.Name) + fmt.Fprintf(out, "\n%v%v [- -]", indent, n.name) if n.variable != nil { fmt.Fprintf(out, "\n%vvariable:", indent+" ") diff --git a/node/expr/assign_op/assign_ref.go b/node/expr/assign_op/assign_ref.go index 941a017..b719616 100644 --- a/node/expr/assign_op/assign_ref.go +++ b/node/expr/assign_op/assign_ref.go @@ -4,6 +4,10 @@ import ( "github.com/z7zmey/php-parser/node" ) +func (n AssignRef) Name() string { + return "AssignRef" +} + type AssignRef struct { AssignOp } @@ -11,7 +15,7 @@ type AssignRef struct { func NewAssignRef(variable node.Node, expression node.Node) node.Node { return AssignRef{ AssignOp{ - node.SimpleNode{Name: "AssignRef", Attributes: make(map[string]string)}, + "AssignRef", variable, expression, }, diff --git a/node/expr/assign_op/bitwise_and.go b/node/expr/assign_op/bitwise_and.go index 6a5a639..93ce1ca 100644 --- a/node/expr/assign_op/bitwise_and.go +++ b/node/expr/assign_op/bitwise_and.go @@ -4,14 +4,18 @@ import ( "github.com/z7zmey/php-parser/node" ) +func (n BitwiseAnd) Name() string { + return "BitwiseAnd" +} + type BitwiseAnd struct { AssignOp } -func NewBitwiseAnd(variable node.Node, expression node.Node) node.Node { +func NewBitwiseAnd(variable node.Node, expression node.Node) node.Node { return BitwiseAnd{ AssignOp{ - node.SimpleNode{Name: "AssignBitwiseAnd", Attributes: make(map[string]string)}, + "AssignBitwiseAnd", variable, expression, }, diff --git a/node/expr/assign_op/bitwise_or.go b/node/expr/assign_op/bitwise_or.go index 49e3f61..1901349 100644 --- a/node/expr/assign_op/bitwise_or.go +++ b/node/expr/assign_op/bitwise_or.go @@ -4,14 +4,18 @@ import ( "github.com/z7zmey/php-parser/node" ) +func (n BitwiseOr) Name() string { + return "BitwiseOr" +} + type BitwiseOr struct { AssignOp } -func NewBitwiseOr(variable node.Node, expression node.Node) node.Node { +func NewBitwiseOr(variable node.Node, expression node.Node) node.Node { return BitwiseOr{ AssignOp{ - node.SimpleNode{Name: "AssignBitwiseOr", Attributes: make(map[string]string)}, + "AssignBitwiseOr", variable, expression, }, diff --git a/node/expr/assign_op/bitwise_xor.go b/node/expr/assign_op/bitwise_xor.go index 9f2cdf3..71e48b5 100644 --- a/node/expr/assign_op/bitwise_xor.go +++ b/node/expr/assign_op/bitwise_xor.go @@ -8,12 +8,16 @@ type BitwiseXor struct { AssignOp } -func NewBitwiseXor(variable node.Node, expression node.Node) node.Node { +func NewBitwiseXor(variable node.Node, expression node.Node) node.Node { return BitwiseXor{ AssignOp{ - node.SimpleNode{Name: "AssignBitwiseXor", Attributes: make(map[string]string)}, + "AssignBitwiseXor", variable, expression, }, } } + +func (n BitwiseXor) Name() string { + return "BitwiseXor" +} diff --git a/node/expr/assign_op/concat.go b/node/expr/assign_op/concat.go index ddc7ddf..7b5c652 100644 --- a/node/expr/assign_op/concat.go +++ b/node/expr/assign_op/concat.go @@ -4,14 +4,18 @@ import ( "github.com/z7zmey/php-parser/node" ) +func (n Concat) Name() string { + return "Concat" +} + type Concat struct { AssignOp } -func NewConcat(variable node.Node, expression node.Node) node.Node { +func NewConcat(variable node.Node, expression node.Node) node.Node { return Concat{ AssignOp{ - node.SimpleNode{Name: "AssignConcat", Attributes: make(map[string]string)}, + "AssignConcat", variable, expression, }, diff --git a/node/expr/assign_op/div.go b/node/expr/assign_op/div.go index 228e902..8504fa3 100644 --- a/node/expr/assign_op/div.go +++ b/node/expr/assign_op/div.go @@ -4,14 +4,18 @@ import ( "github.com/z7zmey/php-parser/node" ) +func (n Div) Name() string { + return "Div" +} + type Div struct { AssignOp } -func NewDiv(variable node.Node, expression node.Node) node.Node { +func NewDiv(variable node.Node, expression node.Node) node.Node { return Div{ AssignOp{ - node.SimpleNode{Name: "AssignDiv", Attributes: make(map[string]string)}, + "AssignDiv", variable, expression, }, diff --git a/node/expr/assign_op/minus.go b/node/expr/assign_op/minus.go index b888666..fadbbc5 100644 --- a/node/expr/assign_op/minus.go +++ b/node/expr/assign_op/minus.go @@ -4,14 +4,18 @@ import ( "github.com/z7zmey/php-parser/node" ) +func (n Minus) Name() string { + return "Minus" +} + type Minus struct { AssignOp } -func NewMinus(variable node.Node, expression node.Node) node.Node { +func NewMinus(variable node.Node, expression node.Node) node.Node { return Minus{ AssignOp{ - node.SimpleNode{Name: "AssignMinus", Attributes: make(map[string]string)}, + "AssignMinus", variable, expression, }, diff --git a/node/expr/assign_op/mod.go b/node/expr/assign_op/mod.go index 6b2000e..a068144 100644 --- a/node/expr/assign_op/mod.go +++ b/node/expr/assign_op/mod.go @@ -4,14 +4,18 @@ import ( "github.com/z7zmey/php-parser/node" ) +func (n Mod) Name() string { + return "Mod" +} + type Mod struct { AssignOp } -func NewMod(variable node.Node, expression node.Node) node.Node { +func NewMod(variable node.Node, expression node.Node) node.Node { return Mod{ AssignOp{ - node.SimpleNode{Name: "AssignMod", Attributes: make(map[string]string)}, + "AssignMod", variable, expression, }, diff --git a/node/expr/assign_op/mul.go b/node/expr/assign_op/mul.go index d3fd6ee..6d400fa 100644 --- a/node/expr/assign_op/mul.go +++ b/node/expr/assign_op/mul.go @@ -4,14 +4,18 @@ import ( "github.com/z7zmey/php-parser/node" ) +func (n Mul) Name() string { + return "Mul" +} + type Mul struct { AssignOp } -func NewMul(variable node.Node, expression node.Node) node.Node { +func NewMul(variable node.Node, expression node.Node) node.Node { return Mul{ AssignOp{ - node.SimpleNode{Name: "AssignMul", Attributes: make(map[string]string)}, + "AssignMul", variable, expression, }, diff --git a/node/expr/assign_op/plus.go b/node/expr/assign_op/plus.go index c2f8ce7..7ab0e01 100644 --- a/node/expr/assign_op/plus.go +++ b/node/expr/assign_op/plus.go @@ -4,14 +4,18 @@ import ( "github.com/z7zmey/php-parser/node" ) +func (n Plus) Name() string { + return "Plus" +} + type Plus struct { AssignOp } -func NewPlus(variable node.Node, expression node.Node) node.Node { +func NewPlus(variable node.Node, expression node.Node) node.Node { return Plus{ AssignOp{ - node.SimpleNode{Name: "AssignPlus", Attributes: make(map[string]string)}, + "AssignPlus", variable, expression, }, diff --git a/node/expr/assign_op/pow.go b/node/expr/assign_op/pow.go index c9f88cc..47d606d 100644 --- a/node/expr/assign_op/pow.go +++ b/node/expr/assign_op/pow.go @@ -4,14 +4,18 @@ import ( "github.com/z7zmey/php-parser/node" ) +func (n Pow) Name() string { + return "Pow" +} + type Pow struct { AssignOp } -func NewPow(variable node.Node, expression node.Node) node.Node { +func NewPow(variable node.Node, expression node.Node) node.Node { return Pow{ AssignOp{ - node.SimpleNode{Name: "AssignPow", Attributes: make(map[string]string)}, + "AssignPow", variable, expression, }, diff --git a/node/expr/assign_op/shift_left.go b/node/expr/assign_op/shift_left.go index cdc15d7..1a25f58 100644 --- a/node/expr/assign_op/shift_left.go +++ b/node/expr/assign_op/shift_left.go @@ -4,14 +4,18 @@ import ( "github.com/z7zmey/php-parser/node" ) +func (n ShiftLeft) Name() string { + return "ShiftLeft" +} + type ShiftLeft struct { AssignOp } -func NewShiftLeft(variable node.Node, expression node.Node) node.Node { +func NewShiftLeft(variable node.Node, expression node.Node) node.Node { return ShiftLeft{ AssignOp{ - node.SimpleNode{Name: "AssignShiftLeft", Attributes: make(map[string]string)}, + "AssignShiftLeft", variable, expression, }, diff --git a/node/expr/assign_op/shift_right.go b/node/expr/assign_op/shift_right.go index 5c6c15e..16b2e4f 100644 --- a/node/expr/assign_op/shift_right.go +++ b/node/expr/assign_op/shift_right.go @@ -4,14 +4,18 @@ import ( "github.com/z7zmey/php-parser/node" ) +func (n ShiftRight) Name() string { + return "ShiftRight" +} + type ShiftRight struct { AssignOp } -func NewShiftRight(variable node.Node, expression node.Node) node.Node { +func NewShiftRight(variable node.Node, expression node.Node) node.Node { return ShiftRight{ AssignOp{ - node.SimpleNode{Name: "AssignShiftRight", Attributes: make(map[string]string)}, + "AssignShiftRight", variable, expression, }, diff --git a/node/expr/binary_op/binary_op.go b/node/expr/binary_op/binary_op.go index 2000752..7f2a9b0 100644 --- a/node/expr/binary_op/binary_op.go +++ b/node/expr/binary_op/binary_op.go @@ -8,27 +8,19 @@ import ( ) type BinaryOp struct { - node.SimpleNode - left node.Node + name string + left node.Node right node.Node } -func NewBinaryOp(left node.Node, right node.Node) node.Node { - return BinaryOp{ - node.SimpleNode{Name: "BinaryOp", Attributes: make(map[string]string)}, - left, - right, - } -} - func (n BinaryOp) Print(out io.Writer, indent string) { - fmt.Fprintf(out, "\n%v%v [- -]", indent, n.Name) + fmt.Fprintf(out, "\n%v%v [- -]", indent, n.name) if n.left != nil { fmt.Fprintf(out, "\n%vleft:", indent+" ") n.left.Print(out, indent+" ") } - + if n.right != nil { fmt.Fprintf(out, "\n%vright:", indent+" ") n.right.Print(out, indent+" ") diff --git a/node/expr/binary_op/bitwise_and.go b/node/expr/binary_op/bitwise_and.go index b76c335..194ac80 100644 --- a/node/expr/binary_op/bitwise_and.go +++ b/node/expr/binary_op/bitwise_and.go @@ -4,6 +4,10 @@ import ( "github.com/z7zmey/php-parser/node" ) +func (n BitwiseAnd) Name() string { + return "BitwiseAnd" +} + type BitwiseAnd struct { BinaryOp } @@ -11,7 +15,7 @@ type BitwiseAnd struct { func NewBitwiseAnd(variable node.Node, expression node.Node) node.Node { return BitwiseAnd{ BinaryOp{ - node.SimpleNode{Name: "BinaryBitwiseAnd", Attributes: make(map[string]string)}, + "BinaryBitwiseAnd", variable, expression, }, diff --git a/node/expr/binary_op/bitwise_or.go b/node/expr/binary_op/bitwise_or.go index 0db6f9b..00affb6 100644 --- a/node/expr/binary_op/bitwise_or.go +++ b/node/expr/binary_op/bitwise_or.go @@ -8,12 +8,16 @@ type BitwiseOr struct { BinaryOp } -func NewBitwiseOr(variable node.Node, expression node.Node) node.Node { +func NewBitwiseOr(variable node.Node, expression node.Node) node.Node { return BitwiseOr{ BinaryOp{ - node.SimpleNode{Name: "BinaryBitwiseOr", Attributes: make(map[string]string)}, + "BinaryBitwiseOr", variable, expression, }, } } + +func (n BitwiseOr) Name() string { + return "BitwiseOr" +} diff --git a/node/expr/binary_op/bitwise_xor.go b/node/expr/binary_op/bitwise_xor.go index a10925f..d5bc094 100644 --- a/node/expr/binary_op/bitwise_xor.go +++ b/node/expr/binary_op/bitwise_xor.go @@ -8,12 +8,16 @@ type BitwiseXor struct { BinaryOp } -func NewBitwiseXor(variable node.Node, expression node.Node) node.Node { +func NewBitwiseXor(variable node.Node, expression node.Node) node.Node { return BitwiseXor{ BinaryOp{ - node.SimpleNode{Name: "BinaryBitwiseXor", Attributes: make(map[string]string)}, + "BinaryBitwiseXor", variable, expression, }, } } + +func (n BitwiseXor) Name() string { + return "BitwiseXor" +} diff --git a/node/expr/binary_op/boolean_and.go b/node/expr/binary_op/boolean_and.go index d9a525c..b7eff32 100644 --- a/node/expr/binary_op/boolean_and.go +++ b/node/expr/binary_op/boolean_and.go @@ -4,6 +4,10 @@ import ( "github.com/z7zmey/php-parser/node" ) +func (n BooleanAnd) Name() string { + return "BooleanAnd" +} + type BooleanAnd struct { BinaryOp } @@ -11,7 +15,7 @@ type BooleanAnd struct { func NewBooleanAnd(variable node.Node, expression node.Node) node.Node { return BooleanAnd{ BinaryOp{ - node.SimpleNode{Name: "BinaryBooleanAnd", Attributes: make(map[string]string)}, + "BinaryBooleanAnd", variable, expression, }, diff --git a/node/expr/binary_op/boolean_or.go b/node/expr/binary_op/boolean_or.go index 71a4cbf..0e5885c 100644 --- a/node/expr/binary_op/boolean_or.go +++ b/node/expr/binary_op/boolean_or.go @@ -4,6 +4,10 @@ import ( "github.com/z7zmey/php-parser/node" ) +func (n BooleanOr) Name() string { + return "BooleanOr" +} + type BooleanOr struct { BinaryOp } @@ -11,7 +15,7 @@ type BooleanOr struct { func NewBooleanOr(variable node.Node, expression node.Node) node.Node { return BooleanOr{ BinaryOp{ - node.SimpleNode{Name: "BinaryBooleanOr", Attributes: make(map[string]string)}, + "BinaryBooleanOr", variable, expression, }, diff --git a/node/expr/binary_op/coalesce.go b/node/expr/binary_op/coalesce.go index 40f5220..180f9d1 100644 --- a/node/expr/binary_op/coalesce.go +++ b/node/expr/binary_op/coalesce.go @@ -4,6 +4,10 @@ import ( "github.com/z7zmey/php-parser/node" ) +func (n Coalesce) Name() string { + return "Coalesce" +} + type Coalesce struct { BinaryOp } @@ -11,7 +15,7 @@ type Coalesce struct { func NewCoalesce(variable node.Node, expression node.Node) node.Node { return Coalesce{ BinaryOp{ - node.SimpleNode{Name: "BinaryCoalesce", Attributes: make(map[string]string)}, + "BinaryCoalesce", variable, expression, }, diff --git a/node/expr/binary_op/concat.go b/node/expr/binary_op/concat.go index bc57390..4349778 100644 --- a/node/expr/binary_op/concat.go +++ b/node/expr/binary_op/concat.go @@ -4,14 +4,18 @@ import ( "github.com/z7zmey/php-parser/node" ) +func (n Concat) Name() string { + return "Concat" +} + type Concat struct { BinaryOp } -func NewConcat(variable node.Node, expression node.Node) node.Node { +func NewConcat(variable node.Node, expression node.Node) node.Node { return Concat{ BinaryOp{ - node.SimpleNode{Name: "BinaryConcat", Attributes: make(map[string]string)}, + "BinaryConcat", variable, expression, }, diff --git a/node/expr/binary_op/div.go b/node/expr/binary_op/div.go index ebbda63..a9785fc 100644 --- a/node/expr/binary_op/div.go +++ b/node/expr/binary_op/div.go @@ -4,14 +4,18 @@ import ( "github.com/z7zmey/php-parser/node" ) +func (n Div) Name() string { + return "Div" +} + type Div struct { BinaryOp } -func NewDiv(variable node.Node, expression node.Node) node.Node { +func NewDiv(variable node.Node, expression node.Node) node.Node { return Div{ BinaryOp{ - node.SimpleNode{Name: "BinaryDiv", Attributes: make(map[string]string)}, + "BinaryDiv", variable, expression, }, diff --git a/node/expr/binary_op/equal.go b/node/expr/binary_op/equal.go index fd1ba13..d9346f6 100644 --- a/node/expr/binary_op/equal.go +++ b/node/expr/binary_op/equal.go @@ -4,6 +4,10 @@ import ( "github.com/z7zmey/php-parser/node" ) +func (n Equal) Name() string { + return "Equal" +} + type Equal struct { BinaryOp } @@ -11,7 +15,7 @@ type Equal struct { func NewEqual(variable node.Node, expression node.Node) node.Node { return Equal{ BinaryOp{ - node.SimpleNode{Name: "BinaryEqual", Attributes: make(map[string]string)}, + "BinaryEqual", variable, expression, }, diff --git a/node/expr/binary_op/greater.go b/node/expr/binary_op/greater.go index 6b1cef3..2e4276f 100644 --- a/node/expr/binary_op/greater.go +++ b/node/expr/binary_op/greater.go @@ -4,6 +4,10 @@ import ( "github.com/z7zmey/php-parser/node" ) +func (n Greater) Name() string { + return "Greater" +} + type Greater struct { BinaryOp } @@ -11,7 +15,7 @@ type Greater struct { func NewGreater(variable node.Node, expression node.Node) node.Node { return Greater{ BinaryOp{ - node.SimpleNode{Name: "BinaryGreater", Attributes: make(map[string]string)}, + "BinaryGreater", variable, expression, }, diff --git a/node/expr/binary_op/greater_or_equal.go b/node/expr/binary_op/greater_or_equal.go index 4735190..689ebdf 100644 --- a/node/expr/binary_op/greater_or_equal.go +++ b/node/expr/binary_op/greater_or_equal.go @@ -4,6 +4,10 @@ import ( "github.com/z7zmey/php-parser/node" ) +func (n GreaterOrEqual) Name() string { + return "GreaterOrEqual" +} + type GreaterOrEqual struct { BinaryOp } @@ -11,7 +15,7 @@ type GreaterOrEqual struct { func NewGreaterOrEqual(variable node.Node, expression node.Node) node.Node { return GreaterOrEqual{ BinaryOp{ - node.SimpleNode{Name: "BinaryGreaterOrEqual", Attributes: make(map[string]string)}, + "BinaryGreaterOrEqual", variable, expression, }, diff --git a/node/expr/binary_op/identical.go b/node/expr/binary_op/identical.go index c3ef0df..f566423 100644 --- a/node/expr/binary_op/identical.go +++ b/node/expr/binary_op/identical.go @@ -4,6 +4,10 @@ import ( "github.com/z7zmey/php-parser/node" ) +func (n Identical) Name() string { + return "Identical" +} + type Identical struct { BinaryOp } @@ -11,7 +15,7 @@ type Identical struct { func NewIdentical(variable node.Node, expression node.Node) node.Node { return Identical{ BinaryOp{ - node.SimpleNode{Name: "BinaryIdentical", Attributes: make(map[string]string)}, + "BinaryIdentical", variable, expression, }, diff --git a/node/expr/binary_op/logical_and.go b/node/expr/binary_op/logical_and.go index 774d608..59341d7 100644 --- a/node/expr/binary_op/logical_and.go +++ b/node/expr/binary_op/logical_and.go @@ -4,6 +4,10 @@ import ( "github.com/z7zmey/php-parser/node" ) +func (n LogicalAnd) Name() string { + return "LogicalAnd" +} + type LogicalAnd struct { BinaryOp } @@ -11,7 +15,7 @@ type LogicalAnd struct { func NewLogicalAnd(variable node.Node, expression node.Node) node.Node { return LogicalAnd{ BinaryOp{ - node.SimpleNode{Name: "BinaryLogicalAnd", Attributes: make(map[string]string)}, + "BinaryLogicalAnd", variable, expression, }, diff --git a/node/expr/binary_op/logical_or.go b/node/expr/binary_op/logical_or.go index 3b5b5df..e9c4a0a 100644 --- a/node/expr/binary_op/logical_or.go +++ b/node/expr/binary_op/logical_or.go @@ -4,6 +4,10 @@ import ( "github.com/z7zmey/php-parser/node" ) +func (n LogicalOr) Name() string { + return "LogicalOr" +} + type LogicalOr struct { BinaryOp } @@ -11,7 +15,7 @@ type LogicalOr struct { func NewLogicalOr(variable node.Node, expression node.Node) node.Node { return LogicalOr{ BinaryOp{ - node.SimpleNode{Name: "BinaryLogicalOr", Attributes: make(map[string]string)}, + "BinaryLogicalOr", variable, expression, }, diff --git a/node/expr/binary_op/logical_xor.go b/node/expr/binary_op/logical_xor.go index 9372ade..e0213d6 100644 --- a/node/expr/binary_op/logical_xor.go +++ b/node/expr/binary_op/logical_xor.go @@ -4,6 +4,10 @@ import ( "github.com/z7zmey/php-parser/node" ) +func (n LogicalXor) Name() string { + return "LogicalXor" +} + type LogicalXor struct { BinaryOp } @@ -11,7 +15,7 @@ type LogicalXor struct { func NewLogicalXor(variable node.Node, expression node.Node) node.Node { return LogicalXor{ BinaryOp{ - node.SimpleNode{Name: "BinaryLogicalXor", Attributes: make(map[string]string)}, + "BinaryLogicalXor", variable, expression, }, diff --git a/node/expr/binary_op/minus.go b/node/expr/binary_op/minus.go index 6bbd79a..00cfedc 100644 --- a/node/expr/binary_op/minus.go +++ b/node/expr/binary_op/minus.go @@ -4,14 +4,18 @@ import ( "github.com/z7zmey/php-parser/node" ) +func (n Minus) Name() string { + return "Minus" +} + type Minus struct { BinaryOp } -func NewMinus(variable node.Node, expression node.Node) node.Node { +func NewMinus(variable node.Node, expression node.Node) node.Node { return Minus{ BinaryOp{ - node.SimpleNode{Name: "BinaryMinus", Attributes: make(map[string]string)}, + "BinaryMinus", variable, expression, }, diff --git a/node/expr/binary_op/mod.go b/node/expr/binary_op/mod.go index b0843b0..a99409a 100644 --- a/node/expr/binary_op/mod.go +++ b/node/expr/binary_op/mod.go @@ -4,14 +4,18 @@ import ( "github.com/z7zmey/php-parser/node" ) +func(n Mod) Name() string { + return "Mod" +} + type Mod struct { BinaryOp } -func NewMod(variable node.Node, expression node.Node) node.Node { +func NewMod(variable node.Node, expression node.Node) node.Node { return Mod{ BinaryOp{ - node.SimpleNode{Name: "BinaryMod", Attributes: make(map[string]string)}, + "BinaryMod", variable, expression, }, diff --git a/node/expr/binary_op/mul.go b/node/expr/binary_op/mul.go index 008d979..8b6dff0 100644 --- a/node/expr/binary_op/mul.go +++ b/node/expr/binary_op/mul.go @@ -4,14 +4,18 @@ import ( "github.com/z7zmey/php-parser/node" ) +func(n Mul) Name() string { + return "Mul" +} + type Mul struct { BinaryOp } -func NewMul(variable node.Node, expression node.Node) node.Node { +func NewMul(variable node.Node, expression node.Node) node.Node { return Mul{ BinaryOp{ - node.SimpleNode{Name: "BinaryMul", Attributes: make(map[string]string)}, + "BinaryMul", variable, expression, }, diff --git a/node/expr/binary_op/not_equal.go b/node/expr/binary_op/not_equal.go index 724eb19..a5c3271 100644 --- a/node/expr/binary_op/not_equal.go +++ b/node/expr/binary_op/not_equal.go @@ -4,6 +4,10 @@ import ( "github.com/z7zmey/php-parser/node" ) +func(n NotEqual) Name() string { + return "NotEqual" +} + type NotEqual struct { BinaryOp } @@ -11,7 +15,7 @@ type NotEqual struct { func NewNotEqual(variable node.Node, expression node.Node) node.Node { return NotEqual{ BinaryOp{ - node.SimpleNode{Name: "BinaryNotEqual", Attributes: make(map[string]string)}, + "BinaryNotEqual", variable, expression, }, diff --git a/node/expr/binary_op/not_identical.go b/node/expr/binary_op/not_identical.go index 0d6abe2..f9ee000 100644 --- a/node/expr/binary_op/not_identical.go +++ b/node/expr/binary_op/not_identical.go @@ -4,6 +4,10 @@ import ( "github.com/z7zmey/php-parser/node" ) +func(n NotIdentical) Name() string { + return "NotIdentical" +} + type NotIdentical struct { BinaryOp } @@ -11,7 +15,7 @@ type NotIdentical struct { func NewNotIdentical(variable node.Node, expression node.Node) node.Node { return NotIdentical{ BinaryOp{ - node.SimpleNode{Name: "BinaryNotIdentical", Attributes: make(map[string]string)}, + "BinaryNotIdentical", variable, expression, }, diff --git a/node/expr/binary_op/plus.go b/node/expr/binary_op/plus.go index ae55ea0..ab9a967 100644 --- a/node/expr/binary_op/plus.go +++ b/node/expr/binary_op/plus.go @@ -4,14 +4,18 @@ import ( "github.com/z7zmey/php-parser/node" ) +func(n Plus) Name() string { + return "Plus" +} + type Plus struct { BinaryOp } -func NewPlus(variable node.Node, expression node.Node) node.Node { +func NewPlus(variable node.Node, expression node.Node) node.Node { return Plus{ BinaryOp{ - node.SimpleNode{Name: "BinaryPlus", Attributes: make(map[string]string)}, + "BinaryPlus", variable, expression, }, diff --git a/node/expr/binary_op/pow.go b/node/expr/binary_op/pow.go index 469fded..9a6fdbb 100644 --- a/node/expr/binary_op/pow.go +++ b/node/expr/binary_op/pow.go @@ -4,14 +4,18 @@ import ( "github.com/z7zmey/php-parser/node" ) +func(n Pow) Name() string { + return "Pow" +} + type Pow struct { BinaryOp } -func NewPow(variable node.Node, expression node.Node) node.Node { +func NewPow(variable node.Node, expression node.Node) node.Node { return Pow{ BinaryOp{ - node.SimpleNode{Name: "BinaryPow", Attributes: make(map[string]string)}, + "BinaryPow", variable, expression, }, diff --git a/node/expr/binary_op/shift_left.go b/node/expr/binary_op/shift_left.go index aaf4bcb..4638f0f 100644 --- a/node/expr/binary_op/shift_left.go +++ b/node/expr/binary_op/shift_left.go @@ -4,14 +4,18 @@ import ( "github.com/z7zmey/php-parser/node" ) +func(n ShiftLeft) Name() string { + return "ShiftLeft" +} + type ShiftLeft struct { BinaryOp } -func NewShiftLeft(variable node.Node, expression node.Node) node.Node { +func NewShiftLeft(variable node.Node, expression node.Node) node.Node { return ShiftLeft{ BinaryOp{ - node.SimpleNode{Name: "BinaryShiftLeft", Attributes: make(map[string]string)}, + "BinaryShiftLeft", variable, expression, }, diff --git a/node/expr/binary_op/shift_right.go b/node/expr/binary_op/shift_right.go index 8d673b3..d078d41 100644 --- a/node/expr/binary_op/shift_right.go +++ b/node/expr/binary_op/shift_right.go @@ -4,14 +4,18 @@ import ( "github.com/z7zmey/php-parser/node" ) +func(n ShiftRight) Name() string { + return "ShiftRight" +} + type ShiftRight struct { BinaryOp } -func NewShiftRight(variable node.Node, expression node.Node) node.Node { +func NewShiftRight(variable node.Node, expression node.Node) node.Node { return ShiftRight{ BinaryOp{ - node.SimpleNode{Name: "BinaryShiftRight", Attributes: make(map[string]string)}, + "BinaryShiftRight", variable, expression, }, diff --git a/node/expr/binary_op/smaller.go b/node/expr/binary_op/smaller.go index 4b46687..8557506 100644 --- a/node/expr/binary_op/smaller.go +++ b/node/expr/binary_op/smaller.go @@ -4,6 +4,10 @@ import ( "github.com/z7zmey/php-parser/node" ) +func(n Smaller) Name() string { + return "Smaller" +} + type Smaller struct { BinaryOp } @@ -11,7 +15,7 @@ type Smaller struct { func NewSmaller(variable node.Node, expression node.Node) node.Node { return Smaller{ BinaryOp{ - node.SimpleNode{Name: "BinarySmaller", Attributes: make(map[string]string)}, + "BinarySmaller", variable, expression, }, diff --git a/node/expr/binary_op/smaller_or_equal.go b/node/expr/binary_op/smaller_or_equal.go index 26e0f80..f390416 100644 --- a/node/expr/binary_op/smaller_or_equal.go +++ b/node/expr/binary_op/smaller_or_equal.go @@ -4,6 +4,10 @@ import ( "github.com/z7zmey/php-parser/node" ) +func(n SmallerOrEqual) Name() string { + return "SmallerOrEqual" +} + type SmallerOrEqual struct { BinaryOp } @@ -11,7 +15,7 @@ type SmallerOrEqual struct { func NewSmallerOrEqual(variable node.Node, expression node.Node) node.Node { return SmallerOrEqual{ BinaryOp{ - node.SimpleNode{Name: "BinarySmallerOrEqual", Attributes: make(map[string]string)}, + "BinarySmallerOrEqual", variable, expression, }, diff --git a/node/expr/binary_op/spaceship.go b/node/expr/binary_op/spaceship.go index b6ca54c..0799d7c 100644 --- a/node/expr/binary_op/spaceship.go +++ b/node/expr/binary_op/spaceship.go @@ -4,6 +4,10 @@ import ( "github.com/z7zmey/php-parser/node" ) +func(n Spaceship) Name() string { + return "Spaceship" +} + type Spaceship struct { BinaryOp } @@ -11,7 +15,7 @@ type Spaceship struct { func NewSpaceship(variable node.Node, expression node.Node) node.Node { return Spaceship{ BinaryOp{ - node.SimpleNode{Name: "BinarySpaceship", Attributes: make(map[string]string)}, + "BinarySpaceship", variable, expression, }, diff --git a/node/expr/bitwise_not.go b/node/expr/bitwise_not.go index 748a81d..a1ac956 100644 --- a/node/expr/bitwise_not.go +++ b/node/expr/bitwise_not.go @@ -7,20 +7,24 @@ import ( "github.com/z7zmey/php-parser/node" ) +func (n BitwiseNot) Name() string { + return "BitwiseNot" +} + type BitwiseNot struct { - node.SimpleNode + name string expr node.Node } func NewBitwiseNot(expression node.Node) node.Node { return BitwiseNot{ - node.SimpleNode{Name: "BitwiseNot", Attributes: make(map[string]string)}, + "BitwiseNot", expression, } } func (n BitwiseNot) Print(out io.Writer, indent string) { - fmt.Fprintf(out, "\n%v%v [- -]", indent, n.Name) + fmt.Fprintf(out, "\n%v%v [- -]", indent, n.name) if n.expr != nil { fmt.Fprintf(out, "\n%vexpr:", indent+" ") diff --git a/node/expr/boolean_not.go b/node/expr/boolean_not.go index ebfe163..1de96dd 100644 --- a/node/expr/boolean_not.go +++ b/node/expr/boolean_not.go @@ -7,20 +7,24 @@ import ( "github.com/z7zmey/php-parser/node" ) +func (n BooleanNot) Name() string { + return "BooleanNot" +} + type BooleanNot struct { - node.SimpleNode + name string expr node.Node } func NewBooleanNot(expression node.Node) node.Node { return BooleanNot{ - node.SimpleNode{Name: "BooleanNot", Attributes: make(map[string]string)}, + "BooleanNot", expression, } } func (n BooleanNot) Print(out io.Writer, indent string) { - fmt.Fprintf(out, "\n%v%v [- -]", indent, n.Name) + fmt.Fprintf(out, "\n%v%v [- -]", indent, n.name) if n.expr != nil { fmt.Fprintf(out, "\n%vexpr:", indent+" ") diff --git a/node/expr/cast/cast.go b/node/expr/cast/cast.go index 2c5f88f..75853f7 100644 --- a/node/expr/cast/cast.go +++ b/node/expr/cast/cast.go @@ -8,19 +8,12 @@ import ( ) type Cast struct { - node.SimpleNode + name string expr node.Node } -func NewCast(expr node.Node) node.Node { - return Cast{ - node.SimpleNode{Name: "Cast", Attributes: make(map[string]string)}, - expr, - } -} - func (n Cast) Print(out io.Writer, indent string) { - fmt.Fprintf(out, "\n%v%v [- -]", indent, n.Name) + fmt.Fprintf(out, "\n%v%v [- -]", indent, n.name) if n.expr != nil { fmt.Fprintf(out, "\n%vexpr:", indent+" ") diff --git a/node/expr/cast/cast_array.go b/node/expr/cast/cast_array.go index efe7297..01d6375 100644 --- a/node/expr/cast/cast_array.go +++ b/node/expr/cast/cast_array.go @@ -4,6 +4,10 @@ import ( "github.com/z7zmey/php-parser/node" ) +func (n CastArray) Name() string { + return "CastArray" +} + type CastArray struct { Cast } @@ -11,7 +15,7 @@ type CastArray struct { func NewCastArray(expr node.Node) node.Node { return CastArray{ Cast{ - node.SimpleNode{Name: "CastArray", Attributes: make(map[string]string)}, + "CastArray", expr, }, } diff --git a/node/expr/cast/cast_bool.go b/node/expr/cast/cast_bool.go index 8c95f32..48468d1 100644 --- a/node/expr/cast/cast_bool.go +++ b/node/expr/cast/cast_bool.go @@ -4,6 +4,10 @@ import ( "github.com/z7zmey/php-parser/node" ) +func (n CastBool) Name() string { + return "CastBool" +} + type CastBool struct { Cast } @@ -11,7 +15,7 @@ type CastBool struct { func NewCastBool(expr node.Node) node.Node { return CastBool{ Cast{ - node.SimpleNode{Name: "CastBool", Attributes: make(map[string]string)}, + "CastBool", expr, }, } diff --git a/node/expr/cast/cast_double.go b/node/expr/cast/cast_double.go index 7f09f57..044dbd8 100644 --- a/node/expr/cast/cast_double.go +++ b/node/expr/cast/cast_double.go @@ -4,6 +4,10 @@ import ( "github.com/z7zmey/php-parser/node" ) +func (n CastDouble) Name() string { + return "CastDouble" +} + type CastDouble struct { Cast } @@ -11,7 +15,7 @@ type CastDouble struct { func NewCastDouble(expr node.Node) node.Node { return CastDouble{ Cast{ - node.SimpleNode{Name: "CastDouble", Attributes: make(map[string]string)}, + "CastDouble", expr, }, } diff --git a/node/expr/cast/cast_int.go b/node/expr/cast/cast_int.go index 7ca7ad4..7690e00 100644 --- a/node/expr/cast/cast_int.go +++ b/node/expr/cast/cast_int.go @@ -4,6 +4,10 @@ import ( "github.com/z7zmey/php-parser/node" ) +func (n CastInt) Name() string { + return "CastInt" +} + type CastInt struct { Cast } @@ -11,7 +15,7 @@ type CastInt struct { func NewCastInt(expr node.Node) node.Node { return CastInt{ Cast{ - node.SimpleNode{Name: "CastInt", Attributes: make(map[string]string)}, + "CastInt", expr, }, } diff --git a/node/expr/cast/cast_object.go b/node/expr/cast/cast_object.go index caafe96..dad301f 100644 --- a/node/expr/cast/cast_object.go +++ b/node/expr/cast/cast_object.go @@ -4,6 +4,10 @@ import ( "github.com/z7zmey/php-parser/node" ) +func (n CastObject) Name() string { + return "CastObject" +} + type CastObject struct { Cast } @@ -11,7 +15,7 @@ type CastObject struct { func NewCastObject(expr node.Node) node.Node { return CastObject{ Cast{ - node.SimpleNode{Name: "CastObject", Attributes: make(map[string]string)}, + "CastObject", expr, }, } diff --git a/node/expr/cast/cast_string.go b/node/expr/cast/cast_string.go index d88d108..915357c 100644 --- a/node/expr/cast/cast_string.go +++ b/node/expr/cast/cast_string.go @@ -4,6 +4,10 @@ import ( "github.com/z7zmey/php-parser/node" ) +func (n CastString) Name() string { + return "CastString" +} + type CastString struct { Cast } @@ -11,7 +15,7 @@ type CastString struct { func NewCastString(expr node.Node) node.Node { return CastString{ Cast{ - node.SimpleNode{Name: "CastString", Attributes: make(map[string]string)}, + "CastString", expr, }, } diff --git a/node/expr/cast/cast_unset.go b/node/expr/cast/cast_unset.go index 31c2a3b..a1f8e01 100644 --- a/node/expr/cast/cast_unset.go +++ b/node/expr/cast/cast_unset.go @@ -4,6 +4,10 @@ import ( "github.com/z7zmey/php-parser/node" ) +func (n CastUnset) Name() string { + return "CastUnset" +} + type CastUnset struct { Cast } @@ -11,7 +15,7 @@ type CastUnset struct { func NewCastUnset(expr node.Node) node.Node { return CastUnset{ Cast{ - node.SimpleNode{Name: "CastUnset", Attributes: make(map[string]string)}, + "CastUnset", expr, }, } diff --git a/node/expr/class_const_fetch.go b/node/expr/class_const_fetch.go index 9028a24..ad7e778 100644 --- a/node/expr/class_const_fetch.go +++ b/node/expr/class_const_fetch.go @@ -8,23 +8,27 @@ import ( "github.com/z7zmey/php-parser/token" ) -type ClassConstFetch struct { - node.SimpleNode - class node.Node - name token.Token +func (n ClassConstFetch) Name() string { + return "ClassConstFetch" } -func NewClassConstFetch(class node.Node, name token.Token) node.Node { +type ClassConstFetch struct { + name string + class node.Node + constant token.Token +} + +func NewClassConstFetch(class node.Node, constant token.Token) node.Node { return ClassConstFetch{ - node.SimpleNode{Name: "ClassConstFetch", Attributes: make(map[string]string)}, + "ClassConstFetch", class, - name, + constant, } } func (n ClassConstFetch) Print(out io.Writer, indent string) { - fmt.Fprintf(out, "\n%v%v [- -]", indent, n.Name) - fmt.Fprintf(out, "\n%vname: %q", indent+" ", n.name) + fmt.Fprintf(out, "\n%v%v [- -]", indent, n.name) + fmt.Fprintf(out, "\n%vname: %q", indent+" ", n.constant.Value) if n.class != nil { fmt.Fprintf(out, "\n%vclass:", indent+" ") diff --git a/node/expr/clone.go b/node/expr/clone.go index b155c0a..027892d 100644 --- a/node/expr/clone.go +++ b/node/expr/clone.go @@ -7,20 +7,24 @@ import ( "github.com/z7zmey/php-parser/node" ) +func (n Clone) Name() string { + return "Clone" +} + type Clone struct { - node.SimpleNode + name string expr node.Node } func NewClone(expression node.Node) node.Node { return Clone{ - node.SimpleNode{Name: "Clone", Attributes: make(map[string]string)}, + "Clone", expression, } } func (n Clone) Print(out io.Writer, indent string) { - fmt.Fprintf(out, "\n%v%v [- -]", indent, n.Name) + fmt.Fprintf(out, "\n%v%v [- -]", indent, n.name) if n.expr != nil { fmt.Fprintf(out, "\n%vexpr:", indent+" ") diff --git a/node/expr/closure.go b/node/expr/closure.go index d79c979..fd31671 100644 --- a/node/expr/closure.go +++ b/node/expr/closure.go @@ -7,8 +7,12 @@ import ( "github.com/z7zmey/php-parser/node" ) +func (n Closure) Name() string { + return "Closure" +} + type Closure struct { - node.SimpleNode + name string params []node.Node uses []node.Node returnType node.Node @@ -19,7 +23,7 @@ type Closure struct { func NewClosure(params []node.Node, uses []node.Node, returnType node.Node, stmts []node.Node, isStatic bool, isReturnRef bool) node.Node { return Closure{ - node.SimpleNode{Name: "Closure", Attributes: make(map[string]string)}, + "Closure", params, uses, returnType, @@ -30,7 +34,7 @@ func NewClosure(params []node.Node, uses []node.Node, returnType node.Node, stmt } func (n Closure) Print(out io.Writer, indent string) { - fmt.Fprintf(out, "\n%v%v [- -]", indent, n.Name) + fmt.Fprintf(out, "\n%v%v [- -]", indent, n.name) fmt.Fprintf(out, "\n%vis static: %t", indent+" ", n.isStatic) fmt.Fprintf(out, "\n%vis return ref: %t", indent+" ", n.isReturnRef) diff --git a/node/expr/closure_use.go b/node/expr/closure_use.go index 6cc33e1..b05ed2f 100644 --- a/node/expr/closure_use.go +++ b/node/expr/closure_use.go @@ -7,22 +7,26 @@ import ( "github.com/z7zmey/php-parser/node" ) +func (n ClusureUse) Name() string { + return "ClusureUse" +} + type ClusureUse struct { - node.SimpleNode + name string variable node.Node byRef bool } func NewClusureUse(variable node.Node, byRef bool) node.Node { return ClusureUse{ - node.SimpleNode{Name: "ClusureUse", Attributes: make(map[string]string)}, + "ClusureUse", variable, byRef, } } func (n ClusureUse) Print(out io.Writer, indent string) { - fmt.Fprintf(out, "\n%v%v [- -]", indent, n.Name) + fmt.Fprintf(out, "\n%v%v [- -]", indent, n.name) fmt.Fprintf(out, "\n%vby ref: %t", indent+" ", n.byRef) if n.variable != nil { diff --git a/node/expr/const_fetch.go b/node/expr/const_fetch.go index 06e9d08..1b2b7ec 100644 --- a/node/expr/const_fetch.go +++ b/node/expr/const_fetch.go @@ -7,23 +7,27 @@ import ( "github.com/z7zmey/php-parser/node" ) -type ConstFetch struct { - node.SimpleNode - name node.Node +func (n ConstFetch) Name() string { + return "ConstFetch" } -func NewConstFetch(name node.Node) node.Node { +type ConstFetch struct { + name string + constant node.Node +} + +func NewConstFetch(constant node.Node) node.Node { return ConstFetch{ - node.SimpleNode{Name: "ConstFetch", Attributes: make(map[string]string)}, - name, + "ConstFetch", + constant, } } func (n ConstFetch) Print(out io.Writer, indent string) { - fmt.Fprintf(out, "\n%v%v [- -]", indent, n.Name) + fmt.Fprintf(out, "\n%v%v [- -]", indent, n.name) - if n.name != nil { - fmt.Fprintf(out, "\n%vname:", indent+" ") - n.name.Print(out, indent+" ") + if n.constant != nil { + fmt.Fprintf(out, "\n%vconstant:", indent+" ") + n.constant.Print(out, indent+" ") } } diff --git a/node/expr/empty.go b/node/expr/empty.go index 4cd4638..f07ac29 100644 --- a/node/expr/empty.go +++ b/node/expr/empty.go @@ -7,20 +7,24 @@ import ( "github.com/z7zmey/php-parser/node" ) +func (n Empty) Name() string { + return "Empty" +} + type Empty struct { - node.SimpleNode + name string expr node.Node } func NewEmpty(expression node.Node) node.Node { return Empty{ - node.SimpleNode{Name: "Empty", Attributes: make(map[string]string)}, + "Empty", expression, } } func (n Empty) Print(out io.Writer, indent string) { - fmt.Fprintf(out, "\n%v%v [- -]", indent, n.Name) + fmt.Fprintf(out, "\n%v%v [- -]", indent, n.name) if n.expr != nil { fmt.Fprintf(out, "\n%vexpr:", indent+" ") diff --git a/node/expr/error_suppress.go b/node/expr/error_suppress.go index 8a81862..0484eec 100644 --- a/node/expr/error_suppress.go +++ b/node/expr/error_suppress.go @@ -7,20 +7,24 @@ import ( "github.com/z7zmey/php-parser/node" ) +func (n ErrorSuppress) Name() string { + return "ErrorSuppress" +} + type ErrorSuppress struct { - node.SimpleNode + name string expr node.Node } func NewErrorSuppress(expression node.Node) node.Node { return ErrorSuppress{ - node.SimpleNode{Name: "ErrorSuppress", Attributes: make(map[string]string)}, + "ErrorSuppress", expression, } } func (n ErrorSuppress) Print(out io.Writer, indent string) { - fmt.Fprintf(out, "\n%v%v [- -]", indent, n.Name) + fmt.Fprintf(out, "\n%v%v [- -]", indent, n.name) if n.expr != nil { fmt.Fprintf(out, "\n%vexpr:", indent+" ") diff --git a/node/expr/eval.go b/node/expr/eval.go index a119fb9..a7c50d1 100644 --- a/node/expr/eval.go +++ b/node/expr/eval.go @@ -7,20 +7,24 @@ import ( "github.com/z7zmey/php-parser/node" ) +func (n Eval) Name() string { + return "Eval" +} + type Eval struct { - node.SimpleNode + name string expr node.Node } func NewEval(expression node.Node) node.Node { return Eval{ - node.SimpleNode{Name: "Eval", Attributes: make(map[string]string)}, + "Eval", expression, } } func (n Eval) Print(out io.Writer, indent string) { - fmt.Fprintf(out, "\n%v%v [- -]", indent, n.Name) + fmt.Fprintf(out, "\n%v%v [- -]", indent, n.name) if n.expr != nil { fmt.Fprintf(out, "\n%vexpr:", indent+" ") diff --git a/node/expr/exit.go b/node/expr/exit.go index 8c2fc13..238770c 100644 --- a/node/expr/exit.go +++ b/node/expr/exit.go @@ -7,22 +7,26 @@ import ( "github.com/z7zmey/php-parser/node" ) +func (n Exit) Name() string { + return "Exit" +} + type Exit struct { - node.SimpleNode + name string expr node.Node isDie bool } func NewExit(expr node.Node, isDie bool) node.Node { return Exit{ - node.SimpleNode{Name: "Exit", Attributes: make(map[string]string)}, + "Exit", expr, isDie, } } func (n Exit) Print(out io.Writer, indent string) { - fmt.Fprintf(out, "\n%v%v [- -]", indent, n.Name) + fmt.Fprintf(out, "\n%v%v [- -]", indent, n.name) fmt.Fprintf(out, "\n%vis die: %t", indent+" ", n.isDie) if n.expr != nil { diff --git a/node/expr/function_call.go b/node/expr/function_call.go index edc8c06..77878f4 100644 --- a/node/expr/function_call.go +++ b/node/expr/function_call.go @@ -7,22 +7,26 @@ import ( "github.com/z7zmey/php-parser/node" ) +func (n FunctionCall) Name() string { + return "FunctionCall" +} + type FunctionCall struct { - node.SimpleNode + name string function node.Node arguments []node.Node } func NewFunctionCall(function node.Node, arguments []node.Node) node.Node { return FunctionCall{ - node.SimpleNode{Name: "FunctionCall", Attributes: make(map[string]string)}, + "FunctionCall", function, arguments, } } func (n FunctionCall) Print(out io.Writer, indent string) { - fmt.Fprintf(out, "\n%v%v [- -]", indent, n.Name) + fmt.Fprintf(out, "\n%v%v [- -]", indent, n.name) if n.function != nil { fmt.Fprintf(out, "\n%vfunction:", indent+" ") diff --git a/node/expr/include.go b/node/expr/include.go index 19a34c8..9987af7 100644 --- a/node/expr/include.go +++ b/node/expr/include.go @@ -7,20 +7,24 @@ import ( "github.com/z7zmey/php-parser/node" ) +func (n Include) Name() string { + return "Include" +} + type Include struct { - node.SimpleNode + name string expr node.Node } func NewInclude(expression node.Node) node.Node { return Include{ - node.SimpleNode{Name: "Include", Attributes: make(map[string]string)}, + "Include", expression, } } func (n Include) Print(out io.Writer, indent string) { - fmt.Fprintf(out, "\n%v%v [- -]", indent, n.Name) + fmt.Fprintf(out, "\n%v%v [- -]", indent, n.name) if n.expr != nil { fmt.Fprintf(out, "\n%vexpr:", indent+" ") diff --git a/node/expr/include_once.go b/node/expr/include_once.go index a4efa5d..47962b2 100644 --- a/node/expr/include_once.go +++ b/node/expr/include_once.go @@ -7,20 +7,24 @@ import ( "github.com/z7zmey/php-parser/node" ) +func (n IncludeOnce) Name() string { + return "IncludeOnce" +} + type IncludeOnce struct { - node.SimpleNode + name string expr node.Node } func NewIncludeOnce(expression node.Node) node.Node { return IncludeOnce{ - node.SimpleNode{Name: "IncludeOnce", Attributes: make(map[string]string)}, + "IncludeOnce", expression, } } func (n IncludeOnce) Print(out io.Writer, indent string) { - fmt.Fprintf(out, "\n%v%v [- -]", indent, n.Name) + fmt.Fprintf(out, "\n%v%v [- -]", indent, n.name) if n.expr != nil { fmt.Fprintf(out, "\n%vexpr:", indent+" ") diff --git a/node/expr/instance_of.go b/node/expr/instance_of.go index 2346221..324ddb3 100644 --- a/node/expr/instance_of.go +++ b/node/expr/instance_of.go @@ -7,22 +7,26 @@ import ( "github.com/z7zmey/php-parser/node" ) +func (n InstanceOf) Name() string { + return "InstanceOf" +} + type InstanceOf struct { - node.SimpleNode + name string expr node.Node class node.Node } func NewInstanceOf(expr node.Node, class node.Node) node.Node { return InstanceOf{ - node.SimpleNode{Name: "InstanceOf", Attributes: make(map[string]string)}, + "InstanceOf", expr, class, } } func (n InstanceOf) Print(out io.Writer, indent string) { - fmt.Fprintf(out, "\n%v%v [- -]", indent, n.Name) + fmt.Fprintf(out, "\n%v%v [- -]", indent, n.name) if n.expr != nil { fmt.Fprintf(out, "\n%vexpr:", indent+" ") diff --git a/node/expr/isset.go b/node/expr/isset.go index 9fec3a6..5df82d4 100644 --- a/node/expr/isset.go +++ b/node/expr/isset.go @@ -7,20 +7,24 @@ import ( "github.com/z7zmey/php-parser/node" ) +func (n Isset) Name() string { + return "Isset" +} + type Isset struct { - node.SimpleNode + name string variables []node.Node } func NewIsset(variables []node.Node) node.Node { return Isset{ - node.SimpleNode{Name: "Isset", Attributes: make(map[string]string)}, + "Isset", variables, } } func (n Isset) Print(out io.Writer, indent string) { - fmt.Fprintf(out, "\n%v%v [- -]", indent, n.Name) + fmt.Fprintf(out, "\n%v%v [- -]", indent, n.name) if n.variables != nil { fmt.Fprintf(out, "\n%vvariables:", indent+" ") diff --git a/node/expr/list.go b/node/expr/list.go index 26b1fb4..733e6bc 100644 --- a/node/expr/list.go +++ b/node/expr/list.go @@ -7,20 +7,24 @@ import ( "github.com/z7zmey/php-parser/node" ) +func (n List) Name() string { + return "List" +} + type List struct { - node.SimpleNode + name string items []node.Node } func NewList(items []node.Node) node.Node { return List{ - node.SimpleNode{Name: "List", Attributes: make(map[string]string)}, + "List", items, } } func (n List) Print(out io.Writer, indent string) { - fmt.Fprintf(out, "\n%v%v [- -]", indent, n.Name) + fmt.Fprintf(out, "\n%v%v [- -]", indent, n.name) if n.items != nil { fmt.Fprintf(out, "\n%vitems:", indent+" ") diff --git a/node/expr/method_call.go b/node/expr/method_call.go index e2def24..cb3ff6d 100644 --- a/node/expr/method_call.go +++ b/node/expr/method_call.go @@ -7,33 +7,37 @@ import ( "github.com/z7zmey/php-parser/node" ) +func (n MethodCall) Name() string { + return "MethodCall" +} + type MethodCall struct { - node.SimpleNode + name string variable node.Node - name node.Node + method node.Node arguments []node.Node } -func NewMethodCall(variable node.Node, name node.Node, arguments []node.Node) node.Node { +func NewMethodCall(variable node.Node, method node.Node, arguments []node.Node) node.Node { return MethodCall{ - node.SimpleNode{Name: "MethodCall", Attributes: make(map[string]string)}, + "MethodCall", variable, - name, + method, arguments, } } func (n MethodCall) Print(out io.Writer, indent string) { - fmt.Fprintf(out, "\n%v%v [- -]", indent, n.Name) + fmt.Fprintf(out, "\n%v%v [- -]", indent, n.name) if n.variable != nil { fmt.Fprintf(out, "\n%vvariable:", indent+" ") n.variable.Print(out, indent+" ") } - if n.name != nil { - fmt.Fprintf(out, "\n%vname:", indent+" ") - n.name.Print(out, indent+" ") + if n.method != nil { + fmt.Fprintf(out, "\n%vmethod:", indent+" ") + n.method.Print(out, indent+" ") } if n.arguments != nil { diff --git a/node/expr/new.go b/node/expr/new.go index 31767e4..ecd1b56 100644 --- a/node/expr/new.go +++ b/node/expr/new.go @@ -7,22 +7,26 @@ import ( "github.com/z7zmey/php-parser/node" ) +func (n New) Name() string { + return "New" +} + type New struct { - node.SimpleNode + name string class node.Node arguments []node.Node } func NewNew(class node.Node, arguments []node.Node) node.Node { return New{ - node.SimpleNode{Name: "New", Attributes: make(map[string]string)}, + "New", class, arguments, } } func (n New) Print(out io.Writer, indent string) { - fmt.Fprintf(out, "\n%v%v [- -]", indent, n.Name) + fmt.Fprintf(out, "\n%v%v [- -]", indent, n.name) if n.class != nil { fmt.Fprintf(out, "\n%vclass:", indent+" ") diff --git a/node/expr/post_dec.go b/node/expr/post_dec.go index eb217fa..deb27d1 100644 --- a/node/expr/post_dec.go +++ b/node/expr/post_dec.go @@ -7,20 +7,24 @@ import ( "github.com/z7zmey/php-parser/node" ) +func (n PostDec) Name() string { + return "PostDec" +} + type PostDec struct { - node.SimpleNode + name string variable node.Node } func NewPostDec(variableession node.Node) node.Node { return PostDec{ - node.SimpleNode{Name: "PostDec", Attributes: make(map[string]string)}, + "PostDec", variableession, } } func (n PostDec) Print(out io.Writer, indent string) { - fmt.Fprintf(out, "\n%v%v [- -]", indent, n.Name) + fmt.Fprintf(out, "\n%v%v [- -]", indent, n.name) if n.variable != nil { fmt.Fprintf(out, "\n%vvariable:", indent+" ") diff --git a/node/expr/post_inc.go b/node/expr/post_inc.go index 89652b7..d036f4e 100644 --- a/node/expr/post_inc.go +++ b/node/expr/post_inc.go @@ -7,20 +7,24 @@ import ( "github.com/z7zmey/php-parser/node" ) +func (n PostInc) Name() string { + return "PostInc" +} + type PostInc struct { - node.SimpleNode + name string variable node.Node } func NewPostInc(variableession node.Node) node.Node { return PostInc{ - node.SimpleNode{Name: "PostInc", Attributes: make(map[string]string)}, + "PostInc", variableession, } } func (n PostInc) Print(out io.Writer, indent string) { - fmt.Fprintf(out, "\n%v%v [- -]", indent, n.Name) + fmt.Fprintf(out, "\n%v%v [- -]", indent, n.name) if n.variable != nil { fmt.Fprintf(out, "\n%vvariable:", indent+" ") diff --git a/node/expr/pre_dec.go b/node/expr/pre_dec.go index ff2f3fd..0b3d89d 100644 --- a/node/expr/pre_dec.go +++ b/node/expr/pre_dec.go @@ -7,20 +7,24 @@ import ( "github.com/z7zmey/php-parser/node" ) +func (n PreDec) Name() string { + return "PreDec" +} + type PreDec struct { - node.SimpleNode + name string variable node.Node } func NewPreDec(variableession node.Node) node.Node { return PreDec{ - node.SimpleNode{Name: "PreDec", Attributes: make(map[string]string)}, + "PreDec", variableession, } } func (n PreDec) Print(out io.Writer, indent string) { - fmt.Fprintf(out, "\n%v%v [- -]", indent, n.Name) + fmt.Fprintf(out, "\n%v%v [- -]", indent, n.name) if n.variable != nil { fmt.Fprintf(out, "\n%vvariable:", indent+" ") diff --git a/node/expr/pre_inc.go b/node/expr/pre_inc.go index 735575a..ca048da 100644 --- a/node/expr/pre_inc.go +++ b/node/expr/pre_inc.go @@ -7,20 +7,24 @@ import ( "github.com/z7zmey/php-parser/node" ) +func (n PreInc) Name() string { + return "PreInc" +} + type PreInc struct { - node.SimpleNode + name string variable node.Node } func NewPreInc(variableession node.Node) node.Node { return PreInc{ - node.SimpleNode{Name: "PreInc", Attributes: make(map[string]string)}, + "PreInc", variableession, } } func (n PreInc) Print(out io.Writer, indent string) { - fmt.Fprintf(out, "\n%v%v [- -]", indent, n.Name) + fmt.Fprintf(out, "\n%v%v [- -]", indent, n.name) if n.variable != nil { fmt.Fprintf(out, "\n%vvariable:", indent+" ") diff --git a/node/expr/print.go b/node/expr/print.go index 5bea117..ab2438f 100644 --- a/node/expr/print.go +++ b/node/expr/print.go @@ -7,20 +7,24 @@ import ( "github.com/z7zmey/php-parser/node" ) +func (n Print) Name() string { + return "Print" +} + type Print struct { - node.SimpleNode + name string expr node.Node } func NewPrint(expression node.Node) node.Node { return Print{ - node.SimpleNode{Name: "Print", Attributes: make(map[string]string)}, + "Print", expression, } } func (n Print) Print(out io.Writer, indent string) { - fmt.Fprintf(out, "\n%v%v [- -]", indent, n.Name) + fmt.Fprintf(out, "\n%v%v [- -]", indent, n.name) if n.expr != nil { fmt.Fprintf(out, "\n%vexpr:", indent+" ") diff --git a/node/expr/property_fetch.go b/node/expr/property_fetch.go index 6cad6db..774823d 100644 --- a/node/expr/property_fetch.go +++ b/node/expr/property_fetch.go @@ -7,30 +7,34 @@ import ( "github.com/z7zmey/php-parser/node" ) -type PropertyFetch struct { - node.SimpleNode - variable node.Node - name node.Node +func (n PropertyFetch) Name() string { + return "PropertyFetch" } -func NewPropertyFetch(variable node.Node, name node.Node) node.Node { +type PropertyFetch struct { + name string + variable node.Node + property node.Node +} + +func NewPropertyFetch(variable node.Node, property node.Node) node.Node { return PropertyFetch{ - node.SimpleNode{Name: "PropertyFetch", Attributes: make(map[string]string)}, + "PropertyFetch", variable, - name, + property, } } func (n PropertyFetch) Print(out io.Writer, indent string) { - fmt.Fprintf(out, "\n%v%v [- -]", indent, n.Name) + fmt.Fprintf(out, "\n%v%v [- -]", indent, n.name) if n.variable != nil { fmt.Fprintf(out, "\n%vvariable:", indent+" ") n.variable.Print(out, indent+" ") } - if n.name != nil { - fmt.Fprintf(out, "\n%vname:", indent+" ") - n.name.Print(out, indent+" ") + if n.property != nil { + fmt.Fprintf(out, "\n%vproperty:", indent+" ") + n.property.Print(out, indent+" ") } } diff --git a/node/expr/require.go b/node/expr/require.go index a862851..2d13a17 100644 --- a/node/expr/require.go +++ b/node/expr/require.go @@ -7,20 +7,24 @@ import ( "github.com/z7zmey/php-parser/node" ) +func(n Require) Name() string { + return "Require" +} + type Require struct { - node.SimpleNode + name string expr node.Node } func NewRequire(expression node.Node) node.Node { return Require{ - node.SimpleNode{Name: "Require", Attributes: make(map[string]string)}, + "Require", expression, } } func (n Require) Print(out io.Writer, indent string) { - fmt.Fprintf(out, "\n%v%v [- -]", indent, n.Name) + fmt.Fprintf(out, "\n%v%v [- -]", indent, n.name) if n.expr != nil { fmt.Fprintf(out, "\n%vexpr:", indent+" ") diff --git a/node/expr/require_once.go b/node/expr/require_once.go index f8649b8..af2bf4d 100644 --- a/node/expr/require_once.go +++ b/node/expr/require_once.go @@ -7,20 +7,24 @@ import ( "github.com/z7zmey/php-parser/node" ) +func (n RequireOnce) Name() string { + return "RequireOnce" +} + type RequireOnce struct { - node.SimpleNode + name string expr node.Node } func NewRequireOnce(expression node.Node) node.Node { return RequireOnce{ - node.SimpleNode{Name: "RequireOnce", Attributes: make(map[string]string)}, + "RequireOnce", expression, } } func (n RequireOnce) Print(out io.Writer, indent string) { - fmt.Fprintf(out, "\n%v%v [- -]", indent, n.Name) + fmt.Fprintf(out, "\n%v%v [- -]", indent, n.name) if n.expr != nil { fmt.Fprintf(out, "\n%vexpr:", indent+" ") diff --git a/node/expr/shell_exec.go b/node/expr/shell_exec.go index 402dcee..69b31a2 100644 --- a/node/expr/shell_exec.go +++ b/node/expr/shell_exec.go @@ -7,20 +7,24 @@ import ( "github.com/z7zmey/php-parser/node" ) +func (n ShellExec) Name() string { + return "ShellExec" +} + type ShellExec struct { - node.SimpleNode + name string parts []node.Node } func NewShellExec(parts []node.Node) node.Node { return ShellExec{ - node.SimpleNode{Name: "ShellExec", Attributes: make(map[string]string)}, + "ShellExec", parts, } } func (n ShellExec) Print(out io.Writer, indent string) { - fmt.Fprintf(out, "\n%v%v [- -]", indent, n.Name) + fmt.Fprintf(out, "\n%v%v [- -]", indent, n.name) if n.parts != nil { fmt.Fprintf(out, "\n%vparts:", indent+" ") diff --git a/node/expr/short_array.go b/node/expr/short_array.go index abb8133..2d73efe 100644 --- a/node/expr/short_array.go +++ b/node/expr/short_array.go @@ -8,8 +8,12 @@ import ( "github.com/z7zmey/php-parser/token" ) +func (n ShortArray) Name() string { + return "ShortArray" +} + type ShortArray struct { - node.SimpleNode + name string opentToken token.Token closeToken token.Token items []node.Node @@ -17,7 +21,7 @@ type ShortArray struct { func NewShortArray(opentToken token.Token, closeToken token.Token, items []node.Node) node.Node { return ShortArray{ - node.SimpleNode{Name: "ShortArray", Attributes: make(map[string]string)}, + "ShortArray", opentToken, closeToken, items, @@ -25,7 +29,7 @@ func NewShortArray(opentToken token.Token, closeToken token.Token, items []node. } func (n ShortArray) Print(out io.Writer, indent string) { - fmt.Fprintf(out, "\n%v%v [%d %d]", indent, n.Name, n.opentToken.StartLine, n.closeToken.EndLine) + fmt.Fprintf(out, "\n%v%v [%d %d]", indent, n.name, n.opentToken.StartLine, n.closeToken.EndLine) if n.items != nil { fmt.Fprintf(out, "\n%vitems:", indent+" ") diff --git a/node/expr/short_list.go b/node/expr/short_list.go index cbda290..3efbe46 100644 --- a/node/expr/short_list.go +++ b/node/expr/short_list.go @@ -7,20 +7,24 @@ import ( "github.com/z7zmey/php-parser/node" ) +func (n ShortList) Name() string { + return "ShortList" +} + type ShortList struct { - node.SimpleNode + name string items []node.Node } func NewShortList(items []node.Node) node.Node { return ShortList{ - node.SimpleNode{Name: "ShortList", Attributes: make(map[string]string)}, + "ShortList", items, } } func (n ShortList) Print(out io.Writer, indent string) { - fmt.Fprintf(out, "\n%v%v [- -]", indent, n.Name) + fmt.Fprintf(out, "\n%v%v [- -]", indent, n.name) if n.items != nil { fmt.Fprintf(out, "\n%vitems:", indent+" ") diff --git a/node/expr/static_call.go b/node/expr/static_call.go index 6a37277..b21f657 100644 --- a/node/expr/static_call.go +++ b/node/expr/static_call.go @@ -7,33 +7,37 @@ import ( "github.com/z7zmey/php-parser/node" ) +func (n StaticCall) Name() string { + return "StaticCall" +} + type StaticCall struct { - node.SimpleNode + name string class node.Node - name node.Node + call node.Node arguments []node.Node } -func NewStaticCall(class node.Node, name node.Node, arguments []node.Node) node.Node { +func NewStaticCall(class node.Node, call node.Node, arguments []node.Node) node.Node { return StaticCall{ - node.SimpleNode{Name: "StaticCall", Attributes: make(map[string]string)}, + "StaticCall", class, - name, + call, arguments, } } func (n StaticCall) Print(out io.Writer, indent string) { - fmt.Fprintf(out, "\n%v%v [- -]", indent, n.Name) + fmt.Fprintf(out, "\n%v%v [- -]", indent, n.name) if n.class != nil { fmt.Fprintf(out, "\n%vclass:", indent+" ") n.class.Print(out, indent+" ") } - if n.name != nil { - fmt.Fprintf(out, "\n%vname:", indent+" ") - n.name.Print(out, indent+" ") + if n.call != nil { + fmt.Fprintf(out, "\n%vcall:", indent+" ") + n.call.Print(out, indent+" ") } if n.arguments != nil { diff --git a/node/expr/static_property_fetch.go b/node/expr/static_property_fetch.go index 3387ab9..7163c3e 100644 --- a/node/expr/static_property_fetch.go +++ b/node/expr/static_property_fetch.go @@ -7,30 +7,34 @@ import ( "github.com/z7zmey/php-parser/node" ) -type StaticPropertyFetch struct { - node.SimpleNode - class node.Node - name node.Node +func (n StaticPropertyFetch) Name() string { + return "StaticPropertyFetch" } -func NewStaticPropertyFetch(class node.Node, name node.Node) node.Node { +type StaticPropertyFetch struct { + name string + class node.Node + property node.Node +} + +func NewStaticPropertyFetch(class node.Node, property node.Node) node.Node { return StaticPropertyFetch{ - node.SimpleNode{Name: "StaticPropertyFetch", Attributes: make(map[string]string)}, + "StaticPropertyFetch", class, - name, + property, } } func (n StaticPropertyFetch) Print(out io.Writer, indent string) { - fmt.Fprintf(out, "\n%v%v [- -]", indent, n.Name) + fmt.Fprintf(out, "\n%v%v [- -]", indent, n.name) if n.class != nil { fmt.Fprintf(out, "\n%vclass:", indent+" ") n.class.Print(out, indent+" ") } - if n.name != nil { - fmt.Fprintf(out, "\n%vname:", indent+" ") - n.name.Print(out, indent+" ") + if n.property != nil { + fmt.Fprintf(out, "\n%vproperty:", indent+" ") + n.property.Print(out, indent+" ") } } diff --git a/node/expr/ternary.go b/node/expr/ternary.go index a0ed375..8b6768e 100644 --- a/node/expr/ternary.go +++ b/node/expr/ternary.go @@ -7,8 +7,12 @@ import ( "github.com/z7zmey/php-parser/node" ) +func (n Ternary) Name() string { + return "Ternary" +} + type Ternary struct { - node.SimpleNode + name string condition node.Node ifTrue node.Node ifFalse node.Node @@ -16,7 +20,7 @@ type Ternary struct { func NewTernary(condition node.Node, ifTrue node.Node, ifFalse node.Node) node.Node { return Ternary{ - node.SimpleNode{Name: "Ternary", Attributes: make(map[string]string)}, + "Ternary", condition, ifTrue, ifFalse, @@ -24,7 +28,7 @@ func NewTernary(condition node.Node, ifTrue node.Node, ifFalse node.Node) node.N } func (n Ternary) Print(out io.Writer, indent string) { - fmt.Fprintf(out, "\n%v%v [- -]", indent, n.Name) + fmt.Fprintf(out, "\n%v%v [- -]", indent, n.name) if n.condition != nil { fmt.Fprintf(out, "\n%vcondition:", indent+" ") diff --git a/node/expr/unary_minus.go b/node/expr/unary_minus.go index 5cdd14a..f0cdc7c 100644 --- a/node/expr/unary_minus.go +++ b/node/expr/unary_minus.go @@ -7,20 +7,24 @@ import ( "github.com/z7zmey/php-parser/node" ) +func (n UnaryMinus) Name() string { + return "UnaryMinus" +} + type UnaryMinus struct { - node.SimpleNode + name string expr node.Node } func NewUnaryMinus(expression node.Node) node.Node { return UnaryMinus{ - node.SimpleNode{Name: "UnaryMinus", Attributes: make(map[string]string)}, + "UnaryMinus", expression, } } func (n UnaryMinus) Print(out io.Writer, indent string) { - fmt.Fprintf(out, "\n%v%v [- -]", indent, n.Name) + fmt.Fprintf(out, "\n%v%v [- -]", indent, n.name) if n.expr != nil { fmt.Fprintf(out, "\n%vexpr:", indent+" ") diff --git a/node/expr/unary_plus.go b/node/expr/unary_plus.go index c21367a..aff43d3 100644 --- a/node/expr/unary_plus.go +++ b/node/expr/unary_plus.go @@ -7,20 +7,24 @@ import ( "github.com/z7zmey/php-parser/node" ) +func (n UnaryPlus) Name() string { + return "UnaryPlus" +} + type UnaryPlus struct { - node.SimpleNode + name string expr node.Node } func NewUnaryPlus(expression node.Node) node.Node { return UnaryPlus{ - node.SimpleNode{Name: "UnaryPlus", Attributes: make(map[string]string)}, + "UnaryPlus", expression, } } func (n UnaryPlus) Print(out io.Writer, indent string) { - fmt.Fprintf(out, "\n%v%v [- -]", indent, n.Name) + fmt.Fprintf(out, "\n%v%v [- -]", indent, n.name) if n.expr != nil { fmt.Fprintf(out, "\n%vexpr:", indent+" ") diff --git a/node/expr/variable.go b/node/expr/variable.go index 94fafef..3213d05 100644 --- a/node/expr/variable.go +++ b/node/expr/variable.go @@ -7,23 +7,27 @@ import ( "github.com/z7zmey/php-parser/node" ) -type Variable struct { - node.SimpleNode - name node.Node +func (n Variable) Name() string { + return "Variable" } -func NewVariable(name node.Node) node.Node { +type Variable struct { + name string + variable node.Node +} + +func NewVariable(variable node.Node) node.Node { return Variable{ - node.SimpleNode{Name: "Variable", Attributes: make(map[string]string)}, - name, + "Variable", + variable, } } func (n Variable) Print(out io.Writer, indent string) { - fmt.Fprintf(out, "\n%v%v [- -]", indent, n.Name) + fmt.Fprintf(out, "\n%v%v [- -]", indent, n.name) - if n.name != nil { - fmt.Fprintf(out, "\n%vname:", indent+" ") - n.name.Print(out, indent+" ") + if n.variable != nil { + fmt.Fprintf(out, "\n%vvariable:", indent+" ") + n.variable.Print(out, indent+" ") } } diff --git a/node/expr/yield.go b/node/expr/yield.go index b4882c6..4de1c01 100644 --- a/node/expr/yield.go +++ b/node/expr/yield.go @@ -7,22 +7,26 @@ import ( "github.com/z7zmey/php-parser/node" ) +func (n Yield) Name() string { + return "Yield" +} + type Yield struct { - node.SimpleNode + name string key node.Node value node.Node } func NewYield(key node.Node, value node.Node) node.Node { return Yield{ - node.SimpleNode{Name: "Yield", Attributes: make(map[string]string)}, + "Yield", key, value, } } func (n Yield) Print(out io.Writer, indent string) { - fmt.Fprintf(out, "\n%v%v [- -]", indent, n.Name) + fmt.Fprintf(out, "\n%v%v [- -]", indent, n.name) if n.key != nil { fmt.Fprintf(out, "\n%vkey:", indent+" ") diff --git a/node/expr/yield_from.go b/node/expr/yield_from.go index 368c252..95006a0 100644 --- a/node/expr/yield_from.go +++ b/node/expr/yield_from.go @@ -7,20 +7,24 @@ import ( "github.com/z7zmey/php-parser/node" ) +func (n YieldFrom) Name() string { + return "YieldFrom" +} + type YieldFrom struct { - node.SimpleNode + name string expr node.Node } func NewYieldFrom(expression node.Node) node.Node { return YieldFrom{ - node.SimpleNode{Name: "YieldFrom", Attributes: make(map[string]string)}, + "YieldFrom", expression, } } func (n YieldFrom) Print(out io.Writer, indent string) { - fmt.Fprintf(out, "\n%v%v [- -]", indent, n.Name) + fmt.Fprintf(out, "\n%v%v [- -]", indent, n.name) if n.expr != nil { fmt.Fprintf(out, "\n%vexpr:", indent+" ") diff --git a/node/identifier.go b/node/identifier.go index 8dddacc..45b6b15 100644 --- a/node/identifier.go +++ b/node/identifier.go @@ -8,18 +8,22 @@ import ( ) type Identifier struct { - SimpleNode - name token.Token + name string + token token.Token } -func NewIdentifier(name token.Token) Node { +func (n Identifier) Name() string { + return "Identifier" +} + +func NewIdentifier(token token.Token) Node { return Identifier{ - SimpleNode{Name: "Identifier", Attributes: make(map[string]string)}, - name, + "Identifier", + token, } } func (n Identifier) Print(out io.Writer, indent string) { - fmt.Fprintf(out, "\n%v%v [- -]", indent, n.Name) - fmt.Fprintf(out, "\n%vname: %q", indent+" ", n.name.Value) + fmt.Fprintf(out, "\n%v%v [- -]", indent, n.name) + fmt.Fprintf(out, "\n%vname: %q", indent+" ", n.token.Value) } diff --git a/node/name/fully_qualified.go b/node/name/fully_qualified.go index 8400b38..ef1f216 100644 --- a/node/name/fully_qualified.go +++ b/node/name/fully_qualified.go @@ -5,14 +5,18 @@ import ( ) type FullyQualified struct { - Name + NameNode } func NewFullyQualified(parts []node.Node) node.Node { return FullyQualified{ - Name{ - node.SimpleNode{Name: "FullyQualifiedName", Attributes: make(map[string]string)}, + NameNode{ + "FullyQualifiedName", parts, }, } } + +func (n FullyQualified) Name() string { + return "FullyQualified" +} diff --git a/node/name/name.go b/node/name/name.go index 11fcc23..bd2dcbd 100644 --- a/node/name/name.go +++ b/node/name/name.go @@ -2,26 +2,34 @@ package name import ( "fmt" - "github.com/z7zmey/php-parser/node" "io" + + "github.com/z7zmey/php-parser/node" ) -type Name struct { - node.SimpleNode +func (n NameNode) Name() string { + return "Name" +} + +type NameNode struct { + name string parts []node.Node } func NewName(parts []node.Node) node.Node { - return Name{ - node.SimpleNode{Name: "Name", Attributes: make(map[string]string)}, + return NameNode{ + "Name", parts, } } -func (n Name) Print(out io.Writer, indent string) { - fmt.Fprintf(out, "\n%v%v", indent, n.Name) - fmt.Fprintf(out, "\n%vparts:", indent+" ",) - for _, nn := range n.parts { - nn.Print(out, indent+" ") +func (n NameNode) Print(out io.Writer, indent string) { + fmt.Fprintf(out, "\n%v%v", indent, n.name) + + if n.parts != nil { + fmt.Fprintf(out, "\n%vparts:", indent+" ") + for _, nn := range n.parts { + nn.Print(out, indent+" ") + } } -} \ No newline at end of file +} diff --git a/node/name/name_part.go b/node/name/name_part.go index b431d31..e5c59c5 100644 --- a/node/name/name_part.go +++ b/node/name/name_part.go @@ -2,26 +2,28 @@ package name import ( "fmt" - "github.com/z7zmey/php-parser/token" - "github.com/z7zmey/php-parser/node" "io" + + "github.com/z7zmey/php-parser/node" + "github.com/z7zmey/php-parser/token" ) +func(n NamePart) Name() string { + return "NamePart" +} + type NamePart struct { - node.SimpleNode + name string token token.Token } func NewNamePart(token token.Token) node.Node { return NamePart{ - node.SimpleNode{Name: "NamePart", Attributes: make(map[string]string)}, + "NamePart", token, } } func (n NamePart) Print(out io.Writer, indent string) { - fmt.Fprintf(out, "\n%v%v [%d %d] %q", indent, n.Name, n.token.StartLine, n.token.EndLine, n.token.Value) - for _, nn := range n.Children { - nn.Print(out, indent+" ") - } + fmt.Fprintf(out, "\n%v%v [%d %d] %q", indent, n.name, n.token.StartLine, n.token.EndLine, n.token.Value) } diff --git a/node/name/relative.go b/node/name/relative.go index ad25745..4647462 100644 --- a/node/name/relative.go +++ b/node/name/relative.go @@ -5,15 +5,18 @@ import ( ) type Relative struct { - Name + NameNode } func NewRelative(parts []node.Node) node.Node { return Relative{ - Name{ - node.SimpleNode{Name: "RelativeName", Attributes: make(map[string]string)}, + NameNode{ + "RelativeName", parts, }, } } +func (n Relative) Name() string { + return "Relative" +} diff --git a/node/node.go b/node/node.go index 0998c33..6be4d59 100644 --- a/node/node.go +++ b/node/node.go @@ -1,50 +1,10 @@ package node import ( - "bytes" - "fmt" "io" ) type Node interface { + Name() string Print(out io.Writer, indent string) - Append(nn ...Node) Node - Attribute(key string, value string) Node -} - -type SimpleNode struct { - Name string - Children []Node - Attributes map[string]string -} - -func (n SimpleNode) String() string { - buf := new(bytes.Buffer) - n.Print(buf, " ") - return buf.String() -} - -func (n SimpleNode) Print(out io.Writer, indent string) { - if len(n.Attributes) > 0 { - fmt.Fprintf(out, "\n%v%v %s", indent, n.Name, n.Attributes) - } else { - fmt.Fprintf(out, "\n%v%v", indent, n.Name) - } - for _, nn := range n.Children { - nn.Print(out, indent+" ") - } -} - -func NewSimpleNode(name string) Node { - return SimpleNode{Name: name, Attributes: make(map[string]string)} -} - -func (n SimpleNode) Append(nn ...Node) Node { - n.Children = append(n.Children, nn...) - return n -} - -func (n SimpleNode) Attribute(key string, value string) Node { - n.Attributes[key] = value - return n } diff --git a/node/node_expr_shellexec.go b/node/node_expr_shellexec.go deleted file mode 100644 index a5147d7..0000000 --- a/node/node_expr_shellexec.go +++ /dev/null @@ -1,33 +0,0 @@ -package node - -import ( - "fmt" - "github.com/z7zmey/php-parser/token" - "io" -) - - -type NodeExprShellExec struct { - *SimpleNode - startToken token.Token - endToken token.Token - parts []Node -} - - -func NewNodeExprShellExec(startToken token.Token, parts []Node, endToken token.Token) Node { - return NodeExprShellExec{ - &SimpleNode{Name: "NodeExprShellExec", Attributes: make(map[string]string)}, - startToken, - endToken, - parts, - } -} - -func (n NodeExprShellExec) Print(out io.Writer, indent string) { - fmt.Fprintf(out, "\n%v%v [%d %d]", indent, n.Name, n.startToken.StartLine, n.endToken.EndLine) - fmt.Fprintf(out, "\n%vparts:", indent+" ",) - for _, nn := range n.parts { - nn.Print(out, indent+" ") - } -} diff --git a/node/nullable.go b/node/nullable.go index a12df90..e08e787 100644 --- a/node/nullable.go +++ b/node/nullable.go @@ -6,19 +6,23 @@ import ( ) type Nullable struct { - SimpleNode + name string expr Node } +func (n Nullable) Name() string { + return "Nullable" +} + func NewNullable(expression Node) Node { return Nullable{ - SimpleNode{Name: "Nullable", Attributes: make(map[string]string)}, + "Nullable", expression, } } func (n Nullable) Print(out io.Writer, indent string) { - fmt.Fprintf(out, "\n%v%v [- -]", indent, n.Name) + fmt.Fprintf(out, "\n%v%v [- -]", indent, n.name) if n.expr != nil { fmt.Fprintf(out, "\n%vexpr:", indent+" ") diff --git a/node/parameter.go b/node/parameter.go index b4f1e98..2c0514f 100644 --- a/node/parameter.go +++ b/node/parameter.go @@ -6,7 +6,7 @@ import ( ) type Parameter struct { - SimpleNode + name string variableType Node variable Node defaultValue Node @@ -14,9 +14,13 @@ type Parameter struct { variadic bool } +func (n Parameter) Name() string { + return "Parameter" +} + func NewParameter(variableType Node, variable Node, defaultValue Node, byRef bool, variadic bool) Node { return Parameter{ - SimpleNode{Name: "Parameter", Attributes: make(map[string]string)}, + "Parameter", variableType, variable, defaultValue, @@ -26,7 +30,7 @@ func NewParameter(variableType Node, variable Node, defaultValue Node, byRef boo } func (n Parameter) Print(out io.Writer, indent string) { - fmt.Fprintf(out, "\n%v%v [- -]", indent, n.Name) + fmt.Fprintf(out, "\n%v%v [- -]", indent, n.name) fmt.Fprintf(out, "\n%vbyRef: %t", indent+" ", n.byRef) fmt.Fprintf(out, "\n%vvariadic: %t", indent+" ", n.variadic) diff --git a/node/scalar/dnumber.go b/node/scalar/dnumber.go index 3f06fdd..1169782 100644 --- a/node/scalar/dnumber.go +++ b/node/scalar/dnumber.go @@ -2,28 +2,28 @@ package scalar import ( "fmt" - "github.com/z7zmey/php-parser/token" - "github.com/z7zmey/php-parser/node" "io" + + "github.com/z7zmey/php-parser/node" + "github.com/z7zmey/php-parser/token" ) +func(n Dnumber) Name() string { + return "Dnumber" +} type Dnumber struct { - node.SimpleNode + name string token token.Token } - func NewDnumber(token token.Token) node.Node { return Dnumber{ - node.SimpleNode{Name: "Dnumber", Attributes: make(map[string]string)}, + "Dnumber", token, } } func (n Dnumber) Print(out io.Writer, indent string) { - fmt.Fprintf(out, "\n%v%v [%d %d] %q", indent, n.Name, n.token.StartLine, n.token.EndLine, n.token.Value) - for _, nn := range n.Children { - nn.Print(out, indent+" ") - } + fmt.Fprintf(out, "\n%v%v [%d %d] %q", indent, n.name, n.token.StartLine, n.token.EndLine, n.token.Value) } diff --git a/node/scalar/encapsed.go b/node/scalar/encapsed.go index f1cc609..26c3361 100644 --- a/node/scalar/encapsed.go +++ b/node/scalar/encapsed.go @@ -2,23 +2,26 @@ package scalar import ( "fmt" - "github.com/z7zmey/php-parser/token" - "github.com/z7zmey/php-parser/node" "io" + + "github.com/z7zmey/php-parser/node" + "github.com/z7zmey/php-parser/token" ) - -type Encapsed struct { - node.SimpleNode - startToken token.Token - endToken token.Token - parts []node.Node +func(n Encapsed) Name() string { + return "Encapsed" } +type Encapsed struct { + name string + startToken token.Token + endToken token.Token + parts []node.Node +} func NewEncapsed(startToken token.Token, parts []node.Node, endToken token.Token) node.Node { return Encapsed{ - node.SimpleNode{Name: "Encapsed", Attributes: make(map[string]string)}, + "Encapsed", startToken, endToken, parts, @@ -26,9 +29,12 @@ func NewEncapsed(startToken token.Token, parts []node.Node, endToken token.Token } func (n Encapsed) Print(out io.Writer, indent string) { - fmt.Fprintf(out, "\n%v%v [%d %d]", indent, n.Name, n.startToken.StartLine, n.endToken.EndLine) - fmt.Fprintf(out, "\n%vparts:", indent+" ",) - for _, nn := range n.parts { - nn.Print(out, indent+" ") + fmt.Fprintf(out, "\n%v%v [%d %d]", indent, n.name, n.startToken.StartLine, n.endToken.EndLine) + + if n.parts != nil { + fmt.Fprintf(out, "\n%vparts:", indent+" ") + for _, nn := range n.parts { + nn.Print(out, indent+" ") + } } } diff --git a/node/scalar/encapsed_string_part.go b/node/scalar/encapsed_string_part.go index 9fa7bd0..0c8f77b 100644 --- a/node/scalar/encapsed_string_part.go +++ b/node/scalar/encapsed_string_part.go @@ -2,27 +2,28 @@ package scalar import ( "fmt" - "github.com/z7zmey/php-parser/token" - "github.com/z7zmey/php-parser/node" "io" + + "github.com/z7zmey/php-parser/node" + "github.com/z7zmey/php-parser/token" ) +func(n EncapsedStringPart) Name() string { + return "EncapsedStringPart" +} + type EncapsedStringPart struct { - node.SimpleNode + name string token token.Token } - func NewEncapsedStringPart(t token.Token) node.Node { return EncapsedStringPart{ - node.SimpleNode{Name: "EncapsedStringPart", Attributes: make(map[string]string)}, + "EncapsedStringPart", t, } } func (n EncapsedStringPart) Print(out io.Writer, indent string) { - fmt.Fprintf(out, "\n%v%v [%d %d] %q", indent, n.Name, n.token.StartLine, n.token.EndLine, n.token.Value) - for _, nn := range n.Children { - nn.Print(out, indent+" ") - } + fmt.Fprintf(out, "\n%v%v [%d %d] %q", indent, n.name, n.token.StartLine, n.token.EndLine, n.token.Value) } diff --git a/node/scalar/lnumber.go b/node/scalar/lnumber.go index 0106852..47c65df 100644 --- a/node/scalar/lnumber.go +++ b/node/scalar/lnumber.go @@ -2,28 +2,28 @@ package scalar import ( "fmt" - "github.com/z7zmey/php-parser/token" - "github.com/z7zmey/php-parser/node" "io" + + "github.com/z7zmey/php-parser/node" + "github.com/z7zmey/php-parser/token" ) +func(n Lnumber) Name() string { + return "Lnumber" +} type Lnumber struct { - node.SimpleNode + name string token token.Token } - func NewLnumber(token token.Token) node.Node { return Lnumber{ - node.SimpleNode{Name: "Lnumber", Attributes: make(map[string]string)}, + "Lnumber", token, } } func (n Lnumber) Print(out io.Writer, indent string) { - fmt.Fprintf(out, "\n%v%v [%d %d] %q", indent, n.Name, n.token.StartLine, n.token.EndLine, n.token.Value) - for _, nn := range n.Children { - nn.Print(out, indent+" ") - } + fmt.Fprintf(out, "\n%v%v [%d %d] %q", indent, n.name, n.token.StartLine, n.token.EndLine, n.token.Value) } diff --git a/node/scalar/magic_constant.go b/node/scalar/magic_constant.go index 3f8a4c9..6dfaf9c 100644 --- a/node/scalar/magic_constant.go +++ b/node/scalar/magic_constant.go @@ -2,28 +2,28 @@ package scalar import ( "fmt" - "github.com/z7zmey/php-parser/token" - "github.com/z7zmey/php-parser/node" "io" + + "github.com/z7zmey/php-parser/node" + "github.com/z7zmey/php-parser/token" ) +func(n MagicConstant) Name() string { + return "MagicConstant" +} type MagicConstant struct { - node.SimpleNode + name string token token.Token } - func NewMagicConstant(token token.Token) node.Node { - return String{ - node.SimpleNode{Name: "MagicConstant", Attributes: make(map[string]string)}, + return MagicConstant{ + "MagicConstant", token, } } func (n MagicConstant) Print(out io.Writer, indent string) { - fmt.Fprintf(out, "\n%v%v [%d %d] %q", indent, n.Name, n.token.StartLine, n.token.EndLine, n.token.Value) - for _, nn := range n.Children { - nn.Print(out, indent+" ") - } + fmt.Fprintf(out, "\n%v%v [%d %d] %q", indent, n.name, n.token.StartLine, n.token.EndLine, n.token.Value) } diff --git a/node/scalar/string.go b/node/scalar/string.go index 12b6d12..400825a 100644 --- a/node/scalar/string.go +++ b/node/scalar/string.go @@ -2,28 +2,28 @@ package scalar import ( "fmt" - "github.com/z7zmey/php-parser/token" - "github.com/z7zmey/php-parser/node" "io" + + "github.com/z7zmey/php-parser/node" + "github.com/z7zmey/php-parser/token" ) +func(n String) Name() string { + return "String" +} type String struct { - node.SimpleNode + name string token token.Token } - func NewString(token token.Token) node.Node { return String{ - node.SimpleNode{Name: "String", Attributes: make(map[string]string)}, + "String", token, } } func (n String) Print(out io.Writer, indent string) { - fmt.Fprintf(out, "\n%v%v [%d %d] %q", indent, n.Name, n.token.StartLine, n.token.EndLine, n.token.Value) - for _, nn := range n.Children { - nn.Print(out, indent+" ") - } + fmt.Fprintf(out, "\n%v%v [%d %d] %q", indent, n.name, n.token.StartLine, n.token.EndLine, n.token.Value) } diff --git a/node/stmt/alt_else.go b/node/stmt/alt_else.go index 20c7ad7..65bce03 100644 --- a/node/stmt/alt_else.go +++ b/node/stmt/alt_else.go @@ -1,20 +1,36 @@ package stmt import ( + "fmt" + "io" + "github.com/z7zmey/php-parser/node" "github.com/z7zmey/php-parser/token" ) +func(n AltElse) Name() string { + return "AltElse" +} + type AltElse struct { - Else + name string + token token.Token + stmt node.Node } func NewAltElse(token token.Token, stmt node.Node) node.Node { return AltElse{ - Else{ - node.SimpleNode{Name: "AltElse", Attributes: make(map[string]string)}, - token, - stmt, - }, + "AltElse", + token, + stmt, + } +} + +func (n AltElse) Print(out io.Writer, indent string) { + fmt.Fprintf(out, "\n%v%v [%d %d] %q", indent, n.name, n.token.StartLine, n.token.EndLine, n.token.Value) + + if n.stmt != nil { + fmt.Fprintf(out, "\n%vstmt:", indent+" ") + n.stmt.Print(out, indent+" ") } } diff --git a/node/stmt/alt_else_if.go b/node/stmt/alt_else_if.go index 63a87c7..9826698 100644 --- a/node/stmt/alt_else_if.go +++ b/node/stmt/alt_else_if.go @@ -1,21 +1,43 @@ package stmt import ( + "fmt" + "io" + "github.com/z7zmey/php-parser/node" "github.com/z7zmey/php-parser/token" ) +func(n AltElseIf) Name() string { + return "AltElseIf" +} + type AltElseIf struct { - ElseIf + name string + token token.Token + cond node.Node + stmt node.Node } func NewAltElseIf(token token.Token, cond node.Node, stmt node.Node) node.Node { return AltElseIf{ - ElseIf{ - node.SimpleNode{Name: "AltElseIf", Attributes: make(map[string]string)}, - token, - cond, - stmt, - }, + "AltElseIf", + token, + cond, + stmt, + } +} + +func (n AltElseIf) Print(out io.Writer, indent string) { + fmt.Fprintf(out, "\n%v%v [%d %d] %q", indent, n.name, n.token.StartLine, n.token.EndLine, n.token.Value) + + if n.cond != nil { + fmt.Fprintf(out, "\n%vcond:", indent+" ") + n.cond.Print(out, indent+" ") + } + + if n.stmt != nil { + fmt.Fprintf(out, "\n%vstmt:", indent+" ") + n.stmt.Print(out, indent+" ") } } diff --git a/node/stmt/alt_if.go b/node/stmt/alt_if.go index 26763c0..ab58dd5 100644 --- a/node/stmt/alt_if.go +++ b/node/stmt/alt_if.go @@ -1,33 +1,43 @@ package stmt import ( + "fmt" + "io" + "github.com/z7zmey/php-parser/node" "github.com/z7zmey/php-parser/token" ) +func(n AltIf) Name() string { + return "AltIf" +} + type AltIf struct { - If + name string + token token.Token + cond node.Node + stmt node.Node + elseAltIf []node.Node + _else node.Node } func NewAltIf(token token.Token, cond node.Node, stmt node.Node) node.Node { return AltIf{ - If{ - node.SimpleNode{Name: "AltIf", Attributes: make(map[string]string)}, - token, - cond, - stmt, - nil, - nil, - }, + "AltIf", + token, + cond, + stmt, + nil, + nil, } } -func (n AltIf) AddElseIf(elseIf node.Node) node.Node { - if n.elseIf == nil { - n.elseIf = make([]node.Node, 0) +func (n AltIf) AddElseIf(elseAltIf node.Node) node.Node { + if n.elseAltIf == nil { + n.elseAltIf = make([]node.Node, 0) } - n.elseIf = append(n.elseIf, elseIf) + n.elseAltIf = append(n.elseAltIf, elseAltIf) return n } @@ -37,3 +47,28 @@ func (n AltIf) SetElse(_else node.Node) node.Node { return n } + +func (n AltIf) Print(out io.Writer, indent string) { + fmt.Fprintf(out, "\n%v%v [%d %d] %q", indent, n.name, n.token.StartLine, n.token.EndLine, n.token.Value) + + if n.cond != nil { + fmt.Fprintf(out, "\n%vcond:", indent+" ") + n.cond.Print(out, indent+" ") + } + + if n.stmt != nil { + fmt.Fprintf(out, "\n%vstmt:", indent+" ") + n.stmt.Print(out, indent+" ") + } + + if n.elseAltIf != nil { + fmt.Fprintf(out, "\n%velseAltIfs:", indent+" ") + for _, nn := range n.elseAltIf { + nn.Print(out, indent+" ") + } + } + if n._else != nil { + fmt.Fprintf(out, "\n%velse:", indent+" ") + n._else.Print(out, indent+" ") + } +} diff --git a/node/stmt/break.go b/node/stmt/break.go index bdec67d..1a72f55 100644 --- a/node/stmt/break.go +++ b/node/stmt/break.go @@ -8,22 +8,26 @@ import ( "github.com/z7zmey/php-parser/token" ) +func(n Break) Name() string { + return "Break" +} + type Break struct { - node.SimpleNode + name string token token.Token expr node.Node } func NewBreak(token token.Token, expr node.Node) node.Node { return Break{ - node.SimpleNode{Name: "Break", Attributes: make(map[string]string)}, + "Break", token, expr, } } func (n Break) Print(out io.Writer, indent string) { - fmt.Fprintf(out, "\n%v%v [%d %d] %q", indent, n.Name, n.token.StartLine, n.token.EndLine, n.token.Value) + fmt.Fprintf(out, "\n%v%v [%d %d] %q", indent, n.name, n.token.StartLine, n.token.EndLine, n.token.Value) if n.expr != nil { fmt.Fprintf(out, "\n%vexpr:", indent+" ") diff --git a/node/stmt/case.go b/node/stmt/case.go index 35754e2..ca1069e 100644 --- a/node/stmt/case.go +++ b/node/stmt/case.go @@ -8,8 +8,12 @@ import ( "github.com/z7zmey/php-parser/token" ) +func(n Case) Name() string { + return "Case" +} + type Case struct { - node.SimpleNode + name string token token.Token cond node.Node stmts []node.Node @@ -17,7 +21,7 @@ type Case struct { func NewCase(token token.Token, cond node.Node, stmts []node.Node) node.Node { return Case{ - node.SimpleNode{Name: "Case", Attributes: make(map[string]string)}, + "Case", token, cond, stmts, @@ -25,7 +29,7 @@ func NewCase(token token.Token, cond node.Node, stmts []node.Node) node.Node { } func (n Case) Print(out io.Writer, indent string) { - fmt.Fprintf(out, "\n%v%v [%d %d] %q", indent, n.Name, n.token.StartLine, n.token.EndLine, n.token.Value) + fmt.Fprintf(out, "\n%v%v [%d %d] %q", indent, n.name, n.token.StartLine, n.token.EndLine, n.token.Value) fmt.Fprintf(out, "\n%vcond:", indent+" ") n.cond.Print(out, indent+" ") diff --git a/node/stmt/catch.go b/node/stmt/catch.go index 0b891b1..d4d541f 100644 --- a/node/stmt/catch.go +++ b/node/stmt/catch.go @@ -8,8 +8,12 @@ import ( "github.com/z7zmey/php-parser/token" ) +func(n Catch) Name() string { + return "Catch" +} + type Catch struct { - node.SimpleNode + name string token token.Token types []node.Node variable node.Node @@ -18,7 +22,7 @@ type Catch struct { func NewCatch(token token.Token, types []node.Node, variable node.Node, stmts []node.Node) node.Node { return Catch{ - node.SimpleNode{Name: "Catch", Attributes: make(map[string]string)}, + "Catch", token, types, variable, @@ -27,7 +31,7 @@ func NewCatch(token token.Token, types []node.Node, variable node.Node, stmts [] } func (n Catch) Print(out io.Writer, indent string) { - fmt.Fprintf(out, "\n%v%v [%d %d] %q", indent, n.Name, n.token.StartLine, n.token.EndLine, n.token.Value) + fmt.Fprintf(out, "\n%v%v [%d %d] %q", indent, n.name, n.token.StartLine, n.token.EndLine, n.token.Value) fmt.Fprintf(out, "\n%vtypes:", indent+" ") for _, nn := range n.types { diff --git a/node/stmt/class.go b/node/stmt/class.go index 90bacb3..4f4ba53 100644 --- a/node/stmt/class.go +++ b/node/stmt/class.go @@ -8,8 +8,12 @@ import ( "github.com/z7zmey/php-parser/token" ) +func(n Class) Name() string { + return "Class" +} + type Class struct { - node.SimpleNode + name string token token.Token modifiers []node.Node args []node.Node @@ -20,7 +24,7 @@ type Class struct { func NewClass(token token.Token, modifiers []node.Node, args []node.Node, extends node.Node, implements []node.Node, stmts []node.Node) node.Node { return Class{ - node.SimpleNode{Name: "Class", Attributes: make(map[string]string)}, + "Class", token, modifiers, args, @@ -31,7 +35,7 @@ func NewClass(token token.Token, modifiers []node.Node, args []node.Node, extend } func (n Class) Print(out io.Writer, indent string) { - fmt.Fprintf(out, "\n%v%v [%d %d] %q", indent, n.Name, n.token.StartLine, n.token.EndLine, n.token.Value) + fmt.Fprintf(out, "\n%v%v [%d %d] %q", indent, n.name, n.token.StartLine, n.token.EndLine, n.token.Value) if n.modifiers != nil { fmt.Fprintf(out, "\n%vmotifiers:", indent+" ") diff --git a/node/stmt/class_const_list.go b/node/stmt/class_const_list.go index bcf2fef..91e7153 100644 --- a/node/stmt/class_const_list.go +++ b/node/stmt/class_const_list.go @@ -8,8 +8,12 @@ import ( "github.com/z7zmey/php-parser/token" ) +func(n ClassConstList) Name() string { + return "ClassConstList" +} + type ClassConstList struct { - node.SimpleNode + name string token token.Token modifiers []node.Node consts []node.Node @@ -17,7 +21,7 @@ type ClassConstList struct { func NewClassConstList(token token.Token, modifiers []node.Node, consts []node.Node) node.Node { return ClassConstList{ - node.SimpleNode{Name: "ClassConstList", Attributes: make(map[string]string)}, + "ClassConstList", token, modifiers, consts, @@ -25,7 +29,7 @@ func NewClassConstList(token token.Token, modifiers []node.Node, consts []node.N } func (n ClassConstList) Print(out io.Writer, indent string) { - fmt.Fprintf(out, "\n%v%v [%d %d] %q", indent, n.Name, n.token.StartLine, n.token.EndLine, n.token.Value) + fmt.Fprintf(out, "\n%v%v [%d %d] %q", indent, n.name, n.token.StartLine, n.token.EndLine, n.token.Value) if n.modifiers != nil { fmt.Fprintf(out, "\n%vmotifiers:", indent+" ") diff --git a/node/stmt/class_method.go b/node/stmt/class_method.go index d2bf12f..3f1dca3 100644 --- a/node/stmt/class_method.go +++ b/node/stmt/class_method.go @@ -8,8 +8,12 @@ import ( "github.com/z7zmey/php-parser/token" ) +func(n ClassMethod) Name() string { + return "ClassMethod" +} + type ClassMethod struct { - node.SimpleNode + name string token token.Token modifiers []node.Node isReturnRef bool @@ -20,7 +24,7 @@ type ClassMethod struct { func NewClassMethod(token token.Token, modifiers []node.Node, isReturnRef bool, params []node.Node, returnType node.Node, stmts []node.Node) node.Node { return ClassMethod{ - node.SimpleNode{Name: "ClassMethod", Attributes: make(map[string]string)}, + "ClassMethod", token, modifiers, isReturnRef, @@ -31,7 +35,7 @@ func NewClassMethod(token token.Token, modifiers []node.Node, isReturnRef bool, } func (n ClassMethod) Print(out io.Writer, indent string) { - fmt.Fprintf(out, "\n%v%v [%d %d] %q", indent, n.Name, n.token.StartLine, n.token.EndLine, n.token.Value) + fmt.Fprintf(out, "\n%v%v [%d %d] %q", indent, n.name, n.token.StartLine, n.token.EndLine, n.token.Value) if n.modifiers != nil { fmt.Fprintf(out, "\n%vmodifiers:", indent+" ") diff --git a/node/stmt/const_list.go b/node/stmt/const_list.go index dd1f337..bf6cec3 100644 --- a/node/stmt/const_list.go +++ b/node/stmt/const_list.go @@ -8,22 +8,26 @@ import ( "github.com/z7zmey/php-parser/token" ) +func(n ConstList) Name() string { + return "ConstList" +} + type ConstList struct { - node.SimpleNode + name string token token.Token consts []node.Node } func NewConstList(token token.Token, consts []node.Node) node.Node { return ConstList{ - node.SimpleNode{Name: "ConstList", Attributes: make(map[string]string)}, + "ConstList", token, consts, } } func (n ConstList) Print(out io.Writer, indent string) { - fmt.Fprintf(out, "\n%v%v [%d %d] %q", indent, n.Name, n.token.StartLine, n.token.EndLine, n.token.Value) + fmt.Fprintf(out, "\n%v%v [%d %d] %q", indent, n.name, n.token.StartLine, n.token.EndLine, n.token.Value) if n.consts != nil { fmt.Fprintf(out, "\n%vconsts:", indent+" ") diff --git a/node/stmt/constant.go b/node/stmt/constant.go index e7d298c..9567040 100644 --- a/node/stmt/constant.go +++ b/node/stmt/constant.go @@ -8,22 +8,26 @@ import ( "github.com/z7zmey/php-parser/token" ) +func(n Constant) Name() string { + return "Constant" +} + type Constant struct { - node.SimpleNode + name string token token.Token expr node.Node } func NewConstant(token token.Token, expr node.Node) node.Node { return Constant{ - node.SimpleNode{Name: "Constant", Attributes: make(map[string]string)}, + "Constant", token, expr, } } func (n Constant) Print(out io.Writer, indent string) { - fmt.Fprintf(out, "\n%v%v [%d %d] %q", indent, n.Name, n.token.StartLine, n.token.EndLine, n.token.Value) + fmt.Fprintf(out, "\n%v%v [%d %d] %q", indent, n.name, n.token.StartLine, n.token.EndLine, n.token.Value) fmt.Fprintf(out, "\n%vexpr:", indent+" ") n.expr.Print(out, indent+" ") diff --git a/node/stmt/continue.go b/node/stmt/continue.go index b9c4fe2..e5a02fc 100644 --- a/node/stmt/continue.go +++ b/node/stmt/continue.go @@ -8,22 +8,26 @@ import ( "github.com/z7zmey/php-parser/token" ) +func(n Continue) Name() string { + return "Continue" +} + type Continue struct { - node.SimpleNode + name string token token.Token - expr node.Node + expr node.Node } func NewContinue(token token.Token, expr node.Node) node.Node { return Continue{ - node.SimpleNode{Name: "Continue", Attributes: make(map[string]string)}, + "Continue", token, expr, } } func (n Continue) Print(out io.Writer, indent string) { - fmt.Fprintf(out, "\n%v%v [%d %d] %q", indent, n.Name, n.token.StartLine, n.token.EndLine, n.token.Value) + fmt.Fprintf(out, "\n%v%v [%d %d] %q", indent, n.name, n.token.StartLine, n.token.EndLine, n.token.Value) if n.expr != nil { fmt.Fprintf(out, "\n%vexpr:", indent+" ") diff --git a/node/stmt/declare.go b/node/stmt/declare.go index de33a23..9d453e4 100644 --- a/node/stmt/declare.go +++ b/node/stmt/declare.go @@ -8,8 +8,12 @@ import ( "github.com/z7zmey/php-parser/token" ) +func(n Declare) Name() string { + return "Declare" +} + type Declare struct { - node.SimpleNode + name string token token.Token consts []node.Node stmt node.Node @@ -17,7 +21,7 @@ type Declare struct { func NewDeclare(token token.Token, consts []node.Node, stmt node.Node) node.Node { return Declare{ - node.SimpleNode{Name: "Declare", Attributes: make(map[string]string)}, + "Declare", token, consts, stmt, @@ -25,7 +29,7 @@ func NewDeclare(token token.Token, consts []node.Node, stmt node.Node) node.Node } func (n Declare) Print(out io.Writer, indent string) { - fmt.Fprintf(out, "\n%v%v [%d %d] %q", indent, n.Name, n.token.StartLine, n.token.EndLine, n.token.Value) + fmt.Fprintf(out, "\n%v%v [%d %d] %q", indent, n.name, n.token.StartLine, n.token.EndLine, n.token.Value) if n.consts != nil { fmt.Fprintf(out, "\n%vconsts:", indent+" ") diff --git a/node/stmt/default.go b/node/stmt/default.go index 2f71abe..6e3fb47 100644 --- a/node/stmt/default.go +++ b/node/stmt/default.go @@ -8,22 +8,26 @@ import ( "github.com/z7zmey/php-parser/token" ) +func(n Default) Name() string { + return "Default" +} + type Default struct { - node.SimpleNode + name string token token.Token stmts []node.Node } func NewDefault(token token.Token, stmts []node.Node) node.Node { return Default{ - node.SimpleNode{Name: "Default", Attributes: make(map[string]string)}, + "Default", token, stmts, } } func (n Default) Print(out io.Writer, indent string) { - fmt.Fprintf(out, "\n%v%v [%d %d] %q", indent, n.Name, n.token.StartLine, n.token.EndLine, n.token.Value) + fmt.Fprintf(out, "\n%v%v [%d %d] %q", indent, n.name, n.token.StartLine, n.token.EndLine, n.token.Value) if n.stmts != nil { fmt.Fprintf(out, "\n%vstmts:", indent+" ") diff --git a/node/stmt/do.go b/node/stmt/do.go index 47d1668..3fd920b 100644 --- a/node/stmt/do.go +++ b/node/stmt/do.go @@ -8,8 +8,12 @@ import ( "github.com/z7zmey/php-parser/token" ) +func(n Do) Name() string { + return "Do" +} + type Do struct { - node.SimpleNode + name string token token.Token stmt node.Node cond node.Node @@ -17,7 +21,7 @@ type Do struct { func NewDo(token token.Token, stmt node.Node, cond node.Node) node.Node { return Do{ - node.SimpleNode{Name: "Do", Attributes: make(map[string]string)}, + "Do", token, stmt, cond, @@ -25,7 +29,7 @@ func NewDo(token token.Token, stmt node.Node, cond node.Node) node.Node { } func (n Do) Print(out io.Writer, indent string) { - fmt.Fprintf(out, "\n%v%v [%d %d] %q", indent, n.Name, n.token.StartLine, n.token.EndLine, n.token.Value) + fmt.Fprintf(out, "\n%v%v [%d %d] %q", indent, n.name, n.token.StartLine, n.token.EndLine, n.token.Value) if n.cond != nil { fmt.Fprintf(out, "\n%vcond:", indent+" ") diff --git a/node/stmt/echo.go b/node/stmt/echo.go index 80c3d50..9c8b097 100644 --- a/node/stmt/echo.go +++ b/node/stmt/echo.go @@ -8,22 +8,26 @@ import ( "github.com/z7zmey/php-parser/token" ) +func(n Echo) Name() string { + return "Echo" +} + type Echo struct { - node.SimpleNode + name string token token.Token exprs []node.Node } func NewEcho(token token.Token, exprs []node.Node) node.Node { return Echo{ - node.SimpleNode{Name: "Echo", Attributes: make(map[string]string)}, + "Echo", token, exprs, } } func (n Echo) Print(out io.Writer, indent string) { - fmt.Fprintf(out, "\n%v%v [%d %d] %q", indent, n.Name, n.token.StartLine, n.token.EndLine, n.token.Value) + fmt.Fprintf(out, "\n%v%v [%d %d] %q", indent, n.name, n.token.StartLine, n.token.EndLine, n.token.Value) if n.exprs != nil { fmt.Fprintf(out, "\n%vexprs:", indent+" ") diff --git a/node/stmt/else.go b/node/stmt/else.go index 8359691..71d5a49 100644 --- a/node/stmt/else.go +++ b/node/stmt/else.go @@ -8,22 +8,26 @@ import ( "github.com/z7zmey/php-parser/token" ) +func(n Else) Name() string { + return "Else" +} + type Else struct { - node.SimpleNode + name string token token.Token stmt node.Node } func NewElse(token token.Token, stmt node.Node) node.Node { return Else{ - node.SimpleNode{Name: "Else", Attributes: make(map[string]string)}, + "Else", token, stmt, } } func (n Else) Print(out io.Writer, indent string) { - fmt.Fprintf(out, "\n%v%v [%d %d] %q", indent, n.Name, n.token.StartLine, n.token.EndLine, n.token.Value) + fmt.Fprintf(out, "\n%v%v [%d %d] %q", indent, n.name, n.token.StartLine, n.token.EndLine, n.token.Value) if n.stmt != nil { fmt.Fprintf(out, "\n%vstmt:", indent+" ") diff --git a/node/stmt/else_if.go b/node/stmt/else_if.go index 002f1ed..56b12a4 100644 --- a/node/stmt/else_if.go +++ b/node/stmt/else_if.go @@ -8,8 +8,12 @@ import ( "github.com/z7zmey/php-parser/token" ) +func(n ElseIf) Name() string { + return "ElseIf" +} + type ElseIf struct { - node.SimpleNode + name string token token.Token cond node.Node stmt node.Node @@ -17,7 +21,7 @@ type ElseIf struct { func NewElseIf(token token.Token, cond node.Node, stmt node.Node) node.Node { return ElseIf{ - node.SimpleNode{Name: "ElseIf", Attributes: make(map[string]string)}, + "ElseIf", token, cond, stmt, @@ -25,7 +29,7 @@ func NewElseIf(token token.Token, cond node.Node, stmt node.Node) node.Node { } func (n ElseIf) Print(out io.Writer, indent string) { - fmt.Fprintf(out, "\n%v%v [%d %d] %q", indent, n.Name, n.token.StartLine, n.token.EndLine, n.token.Value) + fmt.Fprintf(out, "\n%v%v [%d %d] %q", indent, n.name, n.token.StartLine, n.token.EndLine, n.token.Value) if n.cond != nil { fmt.Fprintf(out, "\n%vcond:", indent+" ") diff --git a/node/stmt/expression.go b/node/stmt/expression.go index 784ffdd..1876636 100644 --- a/node/stmt/expression.go +++ b/node/stmt/expression.go @@ -7,20 +7,24 @@ import ( "github.com/z7zmey/php-parser/node" ) +func(n Expression) Name() string { + return "Expression" +} + type Expression struct { - node.SimpleNode + name string expr node.Node } func NewExpression(expr node.Node) node.Node { return Expression{ - node.SimpleNode{Name: "Expression", Attributes: make(map[string]string)}, + "Expression", expr, } } func (n Expression) Print(out io.Writer, indent string) { - fmt.Fprintf(out, "\n%v%v [- -]", indent, n.Name) + fmt.Fprintf(out, "\n%v%v [- -]", indent, n.name) if n.expr != nil { fmt.Fprintf(out, "\n%vexpr:", indent+" ") diff --git a/node/stmt/finally.go b/node/stmt/finally.go index 90f380b..7823205 100644 --- a/node/stmt/finally.go +++ b/node/stmt/finally.go @@ -8,22 +8,26 @@ import ( "github.com/z7zmey/php-parser/token" ) +func(n Finally) Name() string { + return "Finally" +} + type Finally struct { - node.SimpleNode + name string token token.Token stmts []node.Node } func NewFinally(token token.Token, stmts []node.Node) node.Node { return Finally{ - node.SimpleNode{Name: "Finally", Attributes: make(map[string]string)}, + "Finally", token, stmts, } } func (n Finally) Print(out io.Writer, indent string) { - fmt.Fprintf(out, "\n%v%v [%d %d] %q", indent, n.Name, n.token.StartLine, n.token.EndLine, n.token.Value) + fmt.Fprintf(out, "\n%v%v [%d %d] %q", indent, n.name, n.token.StartLine, n.token.EndLine, n.token.Value) if n.stmts != nil { fmt.Fprintf(out, "\n%vstmts:", indent+" ") diff --git a/node/stmt/for.go b/node/stmt/for.go index bd4bf61..f572931 100644 --- a/node/stmt/for.go +++ b/node/stmt/for.go @@ -8,8 +8,12 @@ import ( "github.com/z7zmey/php-parser/token" ) +func(n For) Name() string { + return "For" +} + type For struct { - node.SimpleNode + name string token token.Token init []node.Node cond []node.Node @@ -19,7 +23,7 @@ type For struct { func NewFor(token token.Token, init []node.Node, cond []node.Node, loop []node.Node, stmt node.Node) node.Node { return For{ - node.SimpleNode{Name: "For", Attributes: make(map[string]string)}, + "For", token, init, cond, @@ -29,7 +33,7 @@ func NewFor(token token.Token, init []node.Node, cond []node.Node, loop []node.N } func (n For) Print(out io.Writer, indent string) { - fmt.Fprintf(out, "\n%v%v [%d %d] %q", indent, n.Name, n.token.StartLine, n.token.EndLine, n.token.Value) + fmt.Fprintf(out, "\n%v%v [%d %d] %q", indent, n.name, n.token.StartLine, n.token.EndLine, n.token.Value) if n.init != nil { fmt.Fprintf(out, "\n%vinit:", indent+" ") diff --git a/node/stmt/foreach.go b/node/stmt/foreach.go index 79f5281..a1ef5c9 100644 --- a/node/stmt/foreach.go +++ b/node/stmt/foreach.go @@ -8,8 +8,12 @@ import ( "github.com/z7zmey/php-parser/token" ) +func(n Foreach) Name() string { + return "Foreach" +} + type Foreach struct { - node.SimpleNode + name string token token.Token expr node.Node key node.Node @@ -20,7 +24,7 @@ type Foreach struct { func NewForeach(token token.Token, expr node.Node, key node.Node, variable node.Node, stmt node.Node, byRef bool) node.Node { return Foreach{ - node.SimpleNode{Name: "Foreach", Attributes: make(map[string]string)}, + "Foreach", token, expr, key, @@ -31,7 +35,7 @@ func NewForeach(token token.Token, expr node.Node, key node.Node, variable node. } func (n Foreach) Print(out io.Writer, indent string) { - fmt.Fprintf(out, "\n%v%v [%d %d] %q", indent, n.Name, n.token.StartLine, n.token.EndLine, n.token.Value) + fmt.Fprintf(out, "\n%v%v [%d %d] %q", indent, n.name, n.token.StartLine, n.token.EndLine, n.token.Value) if n.expr != nil { fmt.Fprintf(out, "\n%vexpr:", indent+" ") diff --git a/node/stmt/function.go b/node/stmt/function.go index db97658..83b1a7f 100644 --- a/node/stmt/function.go +++ b/node/stmt/function.go @@ -8,8 +8,12 @@ import ( "github.com/z7zmey/php-parser/token" ) +func(n Function) Name() string { + return "Function" +} + type Function struct { - node.SimpleNode + name string token token.Token isReturnRef bool params []node.Node @@ -19,7 +23,7 @@ type Function struct { func NewFunction(token token.Token, isReturnRef bool, params []node.Node, returnType node.Node, stmts []node.Node) node.Node { return Function{ - node.SimpleNode{Name: "Function", Attributes: make(map[string]string)}, + "Function", token, isReturnRef, params, @@ -29,7 +33,7 @@ func NewFunction(token token.Token, isReturnRef bool, params []node.Node, return } func (n Function) Print(out io.Writer, indent string) { - fmt.Fprintf(out, "\n%v%v [%d %d] %q", indent, n.Name, n.token.StartLine, n.token.EndLine, n.token.Value) + fmt.Fprintf(out, "\n%v%v [%d %d] %q", indent, n.name, n.token.StartLine, n.token.EndLine, n.token.Value) fmt.Fprintf(out, "\n%vreturn ref: %t", indent+" ", n.isReturnRef) diff --git a/node/stmt/global.go b/node/stmt/global.go index f208603..84c25bb 100644 --- a/node/stmt/global.go +++ b/node/stmt/global.go @@ -8,22 +8,26 @@ import ( "github.com/z7zmey/php-parser/token" ) +func(n Global) Name() string { + return "Global" +} + type Global struct { - node.SimpleNode + name string token token.Token vars []node.Node } func NewGlobal(token token.Token, vars []node.Node) node.Node { return Global{ - node.SimpleNode{Name: "Global", Attributes: make(map[string]string)}, + "Global", token, vars, } } func (n Global) Print(out io.Writer, indent string) { - fmt.Fprintf(out, "\n%v%v [%d %d] %q", indent, n.Name, n.token.StartLine, n.token.EndLine, n.token.Value) + fmt.Fprintf(out, "\n%v%v [%d %d] %q", indent, n.name, n.token.StartLine, n.token.EndLine, n.token.Value) if n.vars != nil { fmt.Fprintf(out, "\n%vvars:", indent+" ") diff --git a/node/stmt/goto.go b/node/stmt/goto.go index 9bbca90..c3311f2 100644 --- a/node/stmt/goto.go +++ b/node/stmt/goto.go @@ -8,20 +8,24 @@ import ( "github.com/z7zmey/php-parser/token" ) +func(n Goto) Name() string { + return "Goto" +} + type Goto struct { - node.SimpleNode + name string token token.Token - name token.Token + label token.Token } func NewGoto(token token.Token, name token.Token) node.Node { return Goto{ - node.SimpleNode{Name: "Goto", Attributes: make(map[string]string)}, + "Goto", token, name, } } func (n Goto) Print(out io.Writer, indent string) { - fmt.Fprintf(out, "\n%v%v [%d %d] %q", indent, n.Name, n.token.StartLine, n.name.EndLine, n.name.Value) + fmt.Fprintf(out, "\n%v%v [%d %d] %q", indent, n.name, n.token.StartLine, n.label.EndLine, n.label.Value) } diff --git a/node/stmt/group_use.go b/node/stmt/group_use.go index 9bcb0bb..745cb85 100644 --- a/node/stmt/group_use.go +++ b/node/stmt/group_use.go @@ -8,8 +8,12 @@ import ( "github.com/z7zmey/php-parser/token" ) +func(n GroupUse) Name() string { + return "GroupUse" +} + type GroupUse struct { - node.SimpleNode + name string token token.TokenInterface useType node.Node prefix node.Node @@ -19,7 +23,7 @@ type GroupUse struct { //TODO: stmts myst be []node.Node func NewGroupUse(token token.TokenInterface, useType node.Node, prefix node.Node, useList []node.Node) node.Node { return GroupUse{ - node.SimpleNode{Name: "GroupUse", Attributes: make(map[string]string)}, + "GroupUse", token, useType, prefix, @@ -38,7 +42,7 @@ func (n GroupUse) SetUseType(useType node.Node) node.Node { } func (n GroupUse) Print(out io.Writer, indent string) { - fmt.Fprintf(out, "\n%v%v [%d %d] %q", indent, n.Name, n.token.GetStartLine(), n.token.GetEndLine(), n.token.GetValue()) + fmt.Fprintf(out, "\n%v%v [%d %d] %q", indent, n.name, n.token.GetStartLine(), n.token.GetEndLine(), n.token.GetValue()) if n.useType != nil { fmt.Fprintf(out, "\n%vuse type:", indent+" ") diff --git a/node/stmt/halt_compiler.go b/node/stmt/halt_compiler.go index 78444f6..7636ead 100644 --- a/node/stmt/halt_compiler.go +++ b/node/stmt/halt_compiler.go @@ -8,18 +8,22 @@ import ( "github.com/z7zmey/php-parser/token" ) +func(n HaltCompiler) Name() string { + return "HaltCompiler" +} + type HaltCompiler struct { - node.SimpleNode + name string token token.Token } func NewHaltCompiler(token token.Token) node.Node { return HaltCompiler{ - node.SimpleNode{Name: "HaltCompiler", Attributes: make(map[string]string)}, + "HaltCompiler", token, } } func (n HaltCompiler) Print(out io.Writer, indent string) { - fmt.Fprintf(out, "\n%v%v [%d %d] %q", indent, n.Name, n.token.StartLine, n.token.EndLine, n.token.Value) + fmt.Fprintf(out, "\n%v%v [%d %d] %q", indent, n.name, n.token.StartLine, n.token.EndLine, n.token.Value) } diff --git a/node/stmt/if.go b/node/stmt/if.go index 2ba4a5f..aeca4ff 100644 --- a/node/stmt/if.go +++ b/node/stmt/if.go @@ -8,8 +8,12 @@ import ( "github.com/z7zmey/php-parser/token" ) +func(n If) Name() string { + return "If" +} + type If struct { - node.SimpleNode + name string token token.Token cond node.Node stmt node.Node @@ -19,7 +23,7 @@ type If struct { func NewIf(token token.Token, cond node.Node, stmt node.Node) node.Node { return If{ - node.SimpleNode{Name: "If", Attributes: make(map[string]string)}, + "If", token, cond, stmt, @@ -45,7 +49,7 @@ func (n If) SetElse(_else node.Node) node.Node { } func (n If) Print(out io.Writer, indent string) { - fmt.Fprintf(out, "\n%v%v [%d %d] %q", indent, n.Name, n.token.StartLine, n.token.EndLine, n.token.Value) + fmt.Fprintf(out, "\n%v%v [%d %d] %q", indent, n.name, n.token.StartLine, n.token.EndLine, n.token.Value) if n.cond != nil { fmt.Fprintf(out, "\n%vcond:", indent+" ") diff --git a/node/stmt/inline_html.go b/node/stmt/inline_html.go index fea8a22..55e25aa 100644 --- a/node/stmt/inline_html.go +++ b/node/stmt/inline_html.go @@ -8,18 +8,22 @@ import ( "github.com/z7zmey/php-parser/token" ) +func(n InlineHtml) Name() string { + return "InlineHtml" +} + type InlineHtml struct { - node.SimpleNode + name string token token.Token } func NewInlineHtml(token token.Token) node.Node { return InlineHtml{ - node.SimpleNode{Name: "InlineHtml", Attributes: make(map[string]string)}, + "InlineHtml", token, } } func (n InlineHtml) Print(out io.Writer, indent string) { - fmt.Fprintf(out, "\n%v%v [%d %d] %q", indent, n.Name, n.token.StartLine, n.token.EndLine, n.token.Value) + fmt.Fprintf(out, "\n%v%v [%d %d] %q", indent, n.name, n.token.StartLine, n.token.EndLine, n.token.Value) } diff --git a/node/stmt/interface.go b/node/stmt/interface.go index fbd7020..79e253d 100644 --- a/node/stmt/interface.go +++ b/node/stmt/interface.go @@ -8,17 +8,21 @@ import ( "github.com/z7zmey/php-parser/token" ) +func(n Interface) Name() string { + return "Interface" +} + type Interface struct { - node.SimpleNode + name string token token.Token - name token.Token + iName token.Token extends []node.Node stmts []node.Node } func NewInterface(token token.Token, name token.Token, extends []node.Node, stmts []node.Node) node.Node { return Interface{ - node.SimpleNode{Name: "Interface", Attributes: make(map[string]string)}, + "Interface", token, name, extends, @@ -27,7 +31,7 @@ func NewInterface(token token.Token, name token.Token, extends []node.Node, stmt } func (n Interface) Print(out io.Writer, indent string) { - fmt.Fprintf(out, "\n%v%v [%d %d] %q", indent, n.Name, n.token.StartLine, n.token.EndLine, n.name.Value) + fmt.Fprintf(out, "\n%v%v [%d %d] %q", indent, n.name, n.token.StartLine, n.token.EndLine, n.iName.Value) if n.extends != nil { fmt.Fprintf(out, "\n%vextends:", indent+" ") diff --git a/node/stmt/label.go b/node/stmt/label.go index 14f1db3..a51741a 100644 --- a/node/stmt/label.go +++ b/node/stmt/label.go @@ -8,18 +8,22 @@ import ( "github.com/z7zmey/php-parser/token" ) +func(n Label) Name() string { + return "Label" +} + type Label struct { - node.SimpleNode + name string token token.Token } func NewLabel(token token.Token) node.Node { return Label{ - node.SimpleNode{Name: "Label", Attributes: make(map[string]string)}, + "Label", token, } } func (n Label) Print(out io.Writer, indent string) { - fmt.Fprintf(out, "\n%v%v [%d %d] %q", indent, n.Name, n.token.StartLine, n.token.EndLine, n.token.Value) + fmt.Fprintf(out, "\n%v%v [%d %d] %q", indent, n.name, n.token.StartLine, n.token.EndLine, n.token.Value) } diff --git a/node/stmt/namespace.go b/node/stmt/namespace.go index a3598e2..017454f 100644 --- a/node/stmt/namespace.go +++ b/node/stmt/namespace.go @@ -8,16 +8,20 @@ import ( "github.com/z7zmey/php-parser/token" ) +func(n Namespace) Name() string { + return "Namespace" +} + type Namespace struct { - node.SimpleNode + name string token token.Token - name node.Node + nName node.Node stmts []node.Node } func NewNamespace(token token.Token, name node.Node, stmts []node.Node) node.Node { return Namespace{ - node.SimpleNode{Name: "Namespace", Attributes: make(map[string]string)}, + "Namespace", token, name, stmts, @@ -25,11 +29,11 @@ func NewNamespace(token token.Token, name node.Node, stmts []node.Node) node.Nod } func (n Namespace) Print(out io.Writer, indent string) { - fmt.Fprintf(out, "\n%v%v [%d %d] %q", indent, n.Name, n.token.StartLine, n.token.EndLine, n.token.Value) + fmt.Fprintf(out, "\n%v%v [%d %d] %q", indent, n.name, n.token.StartLine, n.token.EndLine, n.token.Value) - if n.name != nil { + if n.nName != nil { fmt.Fprintf(out, "\n%vname:", indent+" ") - n.name.Print(out, indent+" ") + n.nName.Print(out, indent+" ") } if n.stmts != nil { diff --git a/node/stmt/nop.go b/node/stmt/nop.go index 1dc93ab..c6f3210 100644 --- a/node/stmt/nop.go +++ b/node/stmt/nop.go @@ -8,18 +8,22 @@ import ( "github.com/z7zmey/php-parser/token" ) +func(n Nop) Name() string { + return "Nop" +} + type Nop struct { - node.SimpleNode + name string token token.Token } func NewNop(token token.Token) node.Node { return Nop{ - node.SimpleNode{Name: "Nop", Attributes: make(map[string]string)}, + "Nop", token, } } func (n Nop) Print(out io.Writer, indent string) { - fmt.Fprintf(out, "\n%v%v [%d %d] %q", indent, n.Name, n.token.StartLine, n.token.EndLine, n.token.Value) + fmt.Fprintf(out, "\n%v%v [%d %d] %q", indent, n.name, n.token.StartLine, n.token.EndLine, n.token.Value) } diff --git a/node/stmt/property.go b/node/stmt/property.go index ddbd7d2..30529c5 100644 --- a/node/stmt/property.go +++ b/node/stmt/property.go @@ -8,22 +8,26 @@ import ( "github.com/z7zmey/php-parser/token" ) +func(n Property) Name() string { + return "Property" +} + type Property struct { - node.SimpleNode + name string token token.Token expr node.Node } func NewProperty(token token.Token, expr node.Node) node.Node { return Property{ - node.SimpleNode{Name: "Property", Attributes: make(map[string]string)}, + "Property", token, expr, } } func (n Property) Print(out io.Writer, indent string) { - fmt.Fprintf(out, "\n%v%v [%d %d] %q", indent, n.Name, n.token.StartLine, n.token.EndLine, n.token.Value) + fmt.Fprintf(out, "\n%v%v [%d %d] %q", indent, n.name, n.token.StartLine, n.token.EndLine, n.token.Value) if n.expr != nil { fmt.Fprintf(out, "\n%vexpr:", indent+" ") diff --git a/node/stmt/property_list.go b/node/stmt/property_list.go index 7dfed3f..2864c54 100644 --- a/node/stmt/property_list.go +++ b/node/stmt/property_list.go @@ -7,22 +7,26 @@ import ( "github.com/z7zmey/php-parser/node" ) +func(n PropertyList) Name() string { + return "PropertyList" +} + type PropertyList struct { - node.SimpleNode + name string modifiers []node.Node properties []node.Node } func NewPropertyList(modifiers []node.Node, properties []node.Node) node.Node { return PropertyList{ - node.SimpleNode{Name: "PropertyList", Attributes: make(map[string]string)}, + "PropertyList", modifiers, properties, } } func (n PropertyList) Print(out io.Writer, indent string) { - fmt.Fprintf(out, "\n%v%v [- -]", indent, n.Name) + fmt.Fprintf(out, "\n%v%v [- -]", indent, n.name) if n.modifiers != nil { fmt.Fprintf(out, "\n%vmodifiers:", indent+" ") diff --git a/node/stmt/return.go b/node/stmt/return.go index 99f0afa..aed2d3e 100644 --- a/node/stmt/return.go +++ b/node/stmt/return.go @@ -8,22 +8,26 @@ import ( "github.com/z7zmey/php-parser/token" ) +func(n Return) Name() string { + return "Return" +} + type Return struct { - node.SimpleNode + name string token token.Token expr node.Node } func NewReturn(token token.Token, expr node.Node) node.Node { return Return{ - node.SimpleNode{Name: "Return", Attributes: make(map[string]string)}, + "Return", token, expr, } } func (n Return) Print(out io.Writer, indent string) { - fmt.Fprintf(out, "\n%v%v [%d %d] %q", indent, n.Name, n.token.StartLine, n.token.EndLine, n.token.Value) + fmt.Fprintf(out, "\n%v%v [%d %d] %q", indent, n.name, n.token.StartLine, n.token.EndLine, n.token.Value) if n.expr != nil { fmt.Fprintf(out, "\n%vexpr:", indent+" ") diff --git a/node/stmt/static.go b/node/stmt/static.go index 047cfcc..37a3207 100644 --- a/node/stmt/static.go +++ b/node/stmt/static.go @@ -8,22 +8,26 @@ import ( "github.com/z7zmey/php-parser/token" ) +func(n Static) Name() string { + return "Static" +} + type Static struct { - node.SimpleNode + name string token token.Token vars []node.Node } func NewStatic(token token.Token, vars []node.Node) node.Node { return Static{ - node.SimpleNode{Name: "Static", Attributes: make(map[string]string)}, + "Static", token, vars, } } func (n Static) Print(out io.Writer, indent string) { - fmt.Fprintf(out, "\n%v%v [%d %d] %q", indent, n.Name, n.token.StartLine, n.token.EndLine, n.token.Value) + fmt.Fprintf(out, "\n%v%v [%d %d] %q", indent, n.name, n.token.StartLine, n.token.EndLine, n.token.Value) if n.vars != nil { fmt.Fprintf(out, "\n%vvars:", indent+" ") diff --git a/node/stmt/static_var.go b/node/stmt/static_var.go index 9c07ac5..17ab3ba 100644 --- a/node/stmt/static_var.go +++ b/node/stmt/static_var.go @@ -8,22 +8,26 @@ import ( "github.com/z7zmey/php-parser/token" ) +func(n StaticVar) Name() string { + return "StaticVar" +} + type StaticVar struct { - node.SimpleNode + name string token token.Token expr node.Node } func NewStaticVar(token token.Token, expr node.Node) node.Node { return StaticVar{ - node.SimpleNode{Name: "StaticVar", Attributes: make(map[string]string)}, + "StaticVar", token, expr, } } func (n StaticVar) Print(out io.Writer, indent string) { - fmt.Fprintf(out, "\n%v%v [%d %d] %q", indent, n.Name, n.token.StartLine, n.token.EndLine, n.token.Value) + fmt.Fprintf(out, "\n%v%v [%d %d] %q", indent, n.name, n.token.StartLine, n.token.EndLine, n.token.Value) if n.expr != nil { fmt.Fprintf(out, "\n%vexpr:", indent+" ") diff --git a/node/stmt/stmt_list.go b/node/stmt/stmt_list.go index 1a7f156..d2d0dcb 100644 --- a/node/stmt/stmt_list.go +++ b/node/stmt/stmt_list.go @@ -7,20 +7,24 @@ import ( "github.com/z7zmey/php-parser/node" ) +func(n StmtList) Name() string { + return "StmtList" +} + type StmtList struct { - node.SimpleNode + name string stmts []node.Node } func NewStmtList(stmts []node.Node) node.Node { return StmtList{ - node.SimpleNode{Name: "StmtList", Attributes: make(map[string]string)}, + "StmtList", stmts, } } func (n StmtList) Print(out io.Writer, indent string) { - fmt.Fprintf(out, "\n%v%v [- -]", indent, n.Name) + fmt.Fprintf(out, "\n%v%v [- -]", indent, n.name) if n.stmts != nil { fmt.Fprintf(out, "\n%vstmts:", indent+" ") diff --git a/node/stmt/switch.go b/node/stmt/switch.go index 0dea9c4..7e82755 100644 --- a/node/stmt/switch.go +++ b/node/stmt/switch.go @@ -8,8 +8,12 @@ import ( "github.com/z7zmey/php-parser/token" ) +func(n Switch) Name() string { + return "Switch" +} + type Switch struct { - node.SimpleNode + name string token token.Token cond node.Node cases []node.Node @@ -17,7 +21,7 @@ type Switch struct { func NewSwitch(token token.Token, cond node.Node, cases []node.Node) node.Node { return Switch{ - node.SimpleNode{Name: "Switch", Attributes: make(map[string]string)}, + "Switch", token, cond, cases, @@ -25,7 +29,7 @@ func NewSwitch(token token.Token, cond node.Node, cases []node.Node) node.Node { } func (n Switch) Print(out io.Writer, indent string) { - fmt.Fprintf(out, "\n%v%v [%d %d] %q", indent, n.Name, n.token.StartLine, n.token.EndLine, n.token.Value) + fmt.Fprintf(out, "\n%v%v [%d %d] %q", indent, n.name, n.token.StartLine, n.token.EndLine, n.token.Value) if n.cond != nil { fmt.Fprintf(out, "\n%vcond:", indent+" ") diff --git a/node/stmt/throw.go b/node/stmt/throw.go index f5fb452..1da2d8d 100644 --- a/node/stmt/throw.go +++ b/node/stmt/throw.go @@ -8,22 +8,26 @@ import ( "github.com/z7zmey/php-parser/token" ) +func(n Throw) Name() string { + return "Throw" +} + type Throw struct { - node.SimpleNode + name string token token.Token expr node.Node } func NewThrow(token token.Token, expr node.Node) node.Node { return Throw{ - node.SimpleNode{Name: "Throw", Attributes: make(map[string]string)}, + "Throw", token, expr, } } func (n Throw) Print(out io.Writer, indent string) { - fmt.Fprintf(out, "\n%v%v [%d %d] %q", indent, n.Name, n.token.StartLine, n.token.EndLine, n.token.Value) + fmt.Fprintf(out, "\n%v%v [%d %d] %q", indent, n.name, n.token.StartLine, n.token.EndLine, n.token.Value) if n.expr != nil { fmt.Fprintf(out, "\n%vexpr:", indent+" ") diff --git a/node/stmt/trait.go b/node/stmt/trait.go index d5f71d8..25e036f 100644 --- a/node/stmt/trait.go +++ b/node/stmt/trait.go @@ -8,8 +8,12 @@ import ( "github.com/z7zmey/php-parser/token" ) +func(n Trait) Name() string { + return "Trait" +} + type Trait struct { - node.SimpleNode + name string token token.Token stmts []node.Node } @@ -17,14 +21,14 @@ type Trait struct { //TODO: stmts myst be []node.Node func NewTrait(token token.Token, stmts []node.Node) node.Node { return Trait{ - node.SimpleNode{Name: "Trait", Attributes: make(map[string]string)}, + "Trait", token, stmts, } } func (n Trait) Print(out io.Writer, indent string) { - fmt.Fprintf(out, "\n%v%v [%d %d] %q", indent, n.Name, n.token.StartLine, n.token.EndLine, n.token.Value) + fmt.Fprintf(out, "\n%v%v [%d %d] %q", indent, n.name, n.token.StartLine, n.token.EndLine, n.token.Value) if n.stmts != nil { fmt.Fprintf(out, "\n%vstmts:", indent+" ") diff --git a/node/stmt/trait_method_ref.go b/node/stmt/trait_method_ref.go index 13b668e..d694410 100644 --- a/node/stmt/trait_method_ref.go +++ b/node/stmt/trait_method_ref.go @@ -8,22 +8,26 @@ import ( "github.com/z7zmey/php-parser/token" ) +func(n TraitMethodRef) Name() string { + return "TraitMethodRef" +} + type TraitMethodRef struct { - node.SimpleNode + name string trait node.Node method token.Token } func NewTraitMethodRef(trait node.Node, method token.Token) node.Node { return TraitMethodRef{ - node.SimpleNode{Name: "TraitMethodRef", Attributes: make(map[string]string)}, + "TraitMethodRef", trait, method, } } func (n TraitMethodRef) Print(out io.Writer, indent string) { - fmt.Fprintf(out, "\n%v%v [- -] %q", indent, n.Name, n.method.Value) + fmt.Fprintf(out, "\n%v%v [- -] %q", indent, n.name, n.method.Value) if n.trait != nil { fmt.Fprintf(out, "\n%vtrait", indent+" ") diff --git a/node/stmt/trait_use.go b/node/stmt/trait_use.go index 7fe753b..fcad08e 100644 --- a/node/stmt/trait_use.go +++ b/node/stmt/trait_use.go @@ -8,8 +8,12 @@ import ( "github.com/z7zmey/php-parser/token" ) +func(n TraitUse) Name() string { + return "TraitUse" +} + type TraitUse struct { - node.SimpleNode + name string token token.Token traits []node.Node adaptations []node.Node @@ -18,7 +22,7 @@ type TraitUse struct { //TODO: traits myst be []node.Node func NewTraitUse(token token.Token, traits []node.Node, adaptations []node.Node) node.Node { return TraitUse{ - node.SimpleNode{Name: "TraitUse", Attributes: make(map[string]string)}, + "TraitUse", token, traits, adaptations, @@ -26,7 +30,7 @@ func NewTraitUse(token token.Token, traits []node.Node, adaptations []node.Node) } func (n TraitUse) Print(out io.Writer, indent string) { - fmt.Fprintf(out, "\n%v%v [%d %d] %q", indent, n.Name, n.token.StartLine, n.token.EndLine, n.token.Value) + fmt.Fprintf(out, "\n%v%v [%d %d] %q", indent, n.name, n.token.StartLine, n.token.EndLine, n.token.Value) if n.traits != nil { fmt.Fprintf(out, "\n%vtraits:", indent+" ") diff --git a/node/stmt/trait_use_alias.go b/node/stmt/trait_use_alias.go index f62412d..4c67e37 100644 --- a/node/stmt/trait_use_alias.go +++ b/node/stmt/trait_use_alias.go @@ -8,8 +8,12 @@ import ( "github.com/z7zmey/php-parser/token" ) +func(n TraitUseAlias) Name() string { + return "TraitUseAlias" +} + type TraitUseAlias struct { - node.SimpleNode + name string ref node.Node modifier node.Node alias token.TokenInterface @@ -17,7 +21,7 @@ type TraitUseAlias struct { func NewTraitUseAlias(ref node.Node, modifier node.Node, alias token.TokenInterface) node.Node { return TraitUseAlias{ - node.SimpleNode{Name: "TraitUseAlias", Attributes: make(map[string]string)}, + "TraitUseAlias", ref, modifier, alias, @@ -25,7 +29,7 @@ func NewTraitUseAlias(ref node.Node, modifier node.Node, alias token.TokenInterf } func (n TraitUseAlias) Print(out io.Writer, indent string) { - fmt.Fprintf(out, "\n%v%v [- -]", indent, n.Name) + fmt.Fprintf(out, "\n%v%v [- -]", indent, n.name) if n.alias != nil { fmt.Fprintf(out, "\n%valias: %q", indent+" ", n.alias.GetValue()) diff --git a/node/stmt/trait_use_precedence.go b/node/stmt/trait_use_precedence.go index f80b188..a711192 100644 --- a/node/stmt/trait_use_precedence.go +++ b/node/stmt/trait_use_precedence.go @@ -7,22 +7,26 @@ import ( "github.com/z7zmey/php-parser/node" ) +func(n TraitUsePrecedence) Name() string { + return "TraitUsePrecedence" +} + type TraitUsePrecedence struct { - node.SimpleNode + name string ref node.Node insteadof node.Node } func NewTraitUsePrecedence(ref node.Node, insteadof node.Node) node.Node { return TraitUsePrecedence{ - node.SimpleNode{Name: "TraitUsePrecedence", Attributes: make(map[string]string)}, + "TraitUsePrecedence", ref, insteadof, } } func (n TraitUsePrecedence) Print(out io.Writer, indent string) { - fmt.Fprintf(out, "\n%v%v [- -]", indent, n.Name) + fmt.Fprintf(out, "\n%v%v [- -]", indent, n.name) if n.ref != nil { fmt.Fprintf(out, "\n%vmethod", indent+" ") diff --git a/node/stmt/try.go b/node/stmt/try.go index 7e38253..34cb02f 100644 --- a/node/stmt/try.go +++ b/node/stmt/try.go @@ -8,8 +8,12 @@ import ( "github.com/z7zmey/php-parser/token" ) +func(n Try) Name() string { + return "Try" +} + type Try struct { - node.SimpleNode + name string token token.Token stmts []node.Node catches []node.Node @@ -18,7 +22,7 @@ type Try struct { func NewTry(token token.Token, stmts []node.Node, catches []node.Node, finally node.Node) node.Node { return Try{ - node.SimpleNode{Name: "Try", Attributes: make(map[string]string)}, + "Try", token, stmts, catches, @@ -27,7 +31,7 @@ func NewTry(token token.Token, stmts []node.Node, catches []node.Node, finally n } func (n Try) Print(out io.Writer, indent string) { - fmt.Fprintf(out, "\n%v%v [%d %d] %q", indent, n.Name, n.token.StartLine, n.token.EndLine, n.token.Value) + fmt.Fprintf(out, "\n%v%v [%d %d] %q", indent, n.name, n.token.StartLine, n.token.EndLine, n.token.Value) if n.stmts != nil { fmt.Fprintf(out, "\n%vstmts:", indent+" ") diff --git a/node/stmt/unset.go b/node/stmt/unset.go index 470d5e5..54e878c 100644 --- a/node/stmt/unset.go +++ b/node/stmt/unset.go @@ -8,22 +8,26 @@ import ( "github.com/z7zmey/php-parser/token" ) +func(n Unset) Name() string { + return "Unset" +} + type Unset struct { - node.SimpleNode + name string token token.Token vars []node.Node } func NewUnset(token token.Token, vars []node.Node) node.Node { return Unset{ - node.SimpleNode{Name: "Unset", Attributes: make(map[string]string)}, + "Unset", token, vars, } } func (n Unset) Print(out io.Writer, indent string) { - fmt.Fprintf(out, "\n%v%v [%d %d] %q", indent, n.Name, n.token.StartLine, n.token.EndLine, n.token.Value) + fmt.Fprintf(out, "\n%v%v [%d %d] %q", indent, n.name, n.token.StartLine, n.token.EndLine, n.token.Value) if n.vars != nil { fmt.Fprintf(out, "\n%vvars:", indent+" ") diff --git a/node/stmt/use.go b/node/stmt/use.go index 5390ee7..c571aef 100644 --- a/node/stmt/use.go +++ b/node/stmt/use.go @@ -8,18 +8,22 @@ import ( "github.com/z7zmey/php-parser/token" ) +func(n Use) Name() string { + return "Use" +} + type Use struct { - node.SimpleNode + name string useType node.Node - name node.Node + use node.Node alias token.TokenInterface } -func NewUse(useType node.Node, name node.Node, alias token.TokenInterface) node.Node { +func NewUse(useType node.Node, use node.Node, alias token.TokenInterface) node.Node { return Use{ - node.SimpleNode{Name: "Use", Attributes: make(map[string]string)}, + "Use", useType, - name, + use, alias, } } @@ -30,16 +34,16 @@ func (n Use) SetType(useType node.Node) node.Node { } func (n Use) Print(out io.Writer, indent string) { - fmt.Fprintf(out, "\n%v%v [- -]", indent, n.Name) + fmt.Fprintf(out, "\n%v%v [- -]", indent, n.name) if n.useType != nil { fmt.Fprintf(out, "\n%vtype:", indent+" ") n.useType.Print(out, indent+" ") } - if n.name != nil { - fmt.Fprintf(out, "\n%vname:", indent+" ") - n.name.Print(out, indent+" ") + if n.use != nil { + fmt.Fprintf(out, "\n%vuse:", indent+" ") + n.use.Print(out, indent+" ") } if n.alias != nil { diff --git a/node/stmt/use_list.go b/node/stmt/use_list.go index 4057454..7a5adc9 100644 --- a/node/stmt/use_list.go +++ b/node/stmt/use_list.go @@ -8,8 +8,12 @@ import ( "github.com/z7zmey/php-parser/token" ) +func(n UseList) Name() string { + return "UseList" +} + type UseList struct { - node.SimpleNode + name string token token.Token useType node.Node uses []node.Node @@ -17,7 +21,7 @@ type UseList struct { func NewUseList(token token.Token, useType node.Node, uses []node.Node) node.Node { return UseList{ - node.SimpleNode{Name: "UseList", Attributes: make(map[string]string)}, + "UseList", token, useType, uses, @@ -25,7 +29,7 @@ func NewUseList(token token.Token, useType node.Node, uses []node.Node) node.Nod } func (n UseList) Print(out io.Writer, indent string) { - fmt.Fprintf(out, "\n%v%v [%d %d] %q", indent, n.Name, n.token.StartLine, n.token.EndLine, n.token.Value) + fmt.Fprintf(out, "\n%v%v [%d %d] %q", indent, n.name, n.token.StartLine, n.token.EndLine, n.token.Value) if n.useType != nil { fmt.Fprintf(out, "\n%vtype:", indent+" ") diff --git a/node/stmt/while.go b/node/stmt/while.go index 8578207..259df64 100644 --- a/node/stmt/while.go +++ b/node/stmt/while.go @@ -8,8 +8,12 @@ import ( "github.com/z7zmey/php-parser/token" ) +func(n While) Name() string { + return "While" +} + type While struct { - node.SimpleNode + name string token token.Token cond node.Node stmt node.Node @@ -17,7 +21,7 @@ type While struct { func NewWhile(token token.Token, cond node.Node, stmt node.Node) node.Node { return While{ - node.SimpleNode{Name: "While", Attributes: make(map[string]string)}, + "While", token, cond, stmt, @@ -25,7 +29,7 @@ func NewWhile(token token.Token, cond node.Node, stmt node.Node) node.Node { } func (n While) Print(out io.Writer, indent string) { - fmt.Fprintf(out, "\n%v%v [%d %d] %q", indent, n.Name, n.token.StartLine, n.token.EndLine, n.token.Value) + fmt.Fprintf(out, "\n%v%v [%d %d] %q", indent, n.name, n.token.StartLine, n.token.EndLine, n.token.Value) if n.cond != nil { fmt.Fprintf(out, "\n%vcond:", indent+" ")