array and array_dim_fetch nodes

This commit is contained in:
z7zmey
2017-12-16 20:19:17 +02:00
parent d7a593ef3b
commit 9d17cc7477
4 changed files with 586 additions and 507 deletions

39
node/expr/array.go Normal file
View File

@@ -0,0 +1,39 @@
package expr
import (
"fmt"
"io"
"github.com/z7zmey/php-parser/node"
"github.com/z7zmey/php-parser/token"
)
type Array struct {
node.SimpleNode
opentToken token.Token
closeToken token.Token
items []node.Node
isShortSyntax bool
}
func NewArray(opentToken token.Token, closeToken token.Token, items []node.Node, isShortSyntax bool) node.Node {
return Array{
node.SimpleNode{Name: "Array", Attributes: make(map[string]string)},
opentToken,
closeToken,
items,
isShortSyntax,
}
}
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%visShortSyntax: %t", indent+" ", n.isShortSyntax)
if n.items != nil {
fmt.Fprintf(out, "\n%vitems:", indent+" ")
for _, nn := range n.items {
nn.Print(out, indent+" ")
}
}
}

View File

@@ -0,0 +1,36 @@
package expr
import (
"fmt"
"io"
"github.com/z7zmey/php-parser/node"
)
type ArrayDimFetch struct {
node.SimpleNode
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)},
variable,
dim,
}
}
func (n ArrayDimFetch) Print(out io.Writer, indent string) {
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.dim != nil {
fmt.Fprintf(out, "\n%vdim:", indent+" ")
n.dim.Print(out, indent+" ")
}
}