property_list property nodes
This commit is contained in:
32
node/stmt/property.go
Normal file
32
node/stmt/property.go
Normal file
@@ -0,0 +1,32 @@
|
||||
package stmt
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io"
|
||||
|
||||
"github.com/z7zmey/php-parser/node"
|
||||
"github.com/z7zmey/php-parser/token"
|
||||
)
|
||||
|
||||
type Property struct {
|
||||
node.SimpleNode
|
||||
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)},
|
||||
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)
|
||||
|
||||
if n.expr != nil {
|
||||
fmt.Fprintf(out, "\n%vexpr:", indent+" ")
|
||||
n.expr.Print(out, indent+" ")
|
||||
}
|
||||
}
|
||||
38
node/stmt/property_list.go
Normal file
38
node/stmt/property_list.go
Normal file
@@ -0,0 +1,38 @@
|
||||
package stmt
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io"
|
||||
|
||||
"github.com/z7zmey/php-parser/node"
|
||||
)
|
||||
|
||||
type PropertyList struct {
|
||||
node.SimpleNode
|
||||
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)},
|
||||
modifiers,
|
||||
properties,
|
||||
}
|
||||
}
|
||||
|
||||
func (n PropertyList) Print(out io.Writer, indent string) {
|
||||
fmt.Fprintf(out, "\n%v%v [- -]", indent, n.Name)
|
||||
|
||||
if n.modifiers != nil {
|
||||
fmt.Fprintf(out, "\n%vmodifiers:", indent+" ")
|
||||
n.modifiers.Print(out, indent+" ")
|
||||
}
|
||||
|
||||
if n.properties != nil {
|
||||
fmt.Fprintf(out, "\n%vproperties:", indent+" ")
|
||||
for _, nn := range n.properties {
|
||||
nn.Print(out, indent+" ")
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user