constant and declare nodes
This commit is contained in:
30
node/stmt/constant.go
Normal file
30
node/stmt/constant.go
Normal file
@@ -0,0 +1,30 @@
|
||||
package stmt
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io"
|
||||
|
||||
"github.com/z7zmey/php-parser/node"
|
||||
"github.com/z7zmey/php-parser/token"
|
||||
)
|
||||
|
||||
type Constant struct {
|
||||
node.SimpleNode
|
||||
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)},
|
||||
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%vexpr:", indent+" ")
|
||||
n.expr.Print(out, indent+" ")
|
||||
}
|
||||
43
node/stmt/declare.go
Normal file
43
node/stmt/declare.go
Normal file
@@ -0,0 +1,43 @@
|
||||
package stmt
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io"
|
||||
|
||||
"github.com/z7zmey/php-parser/node"
|
||||
"github.com/z7zmey/php-parser/token"
|
||||
)
|
||||
|
||||
type Declare struct {
|
||||
node.SimpleNode
|
||||
token token.Token
|
||||
consts []node.Node
|
||||
stmts []node.Node
|
||||
}
|
||||
|
||||
func NewDeclare(token token.Token, consts []node.Node, stmts []node.Node) node.Node {
|
||||
return Declare{
|
||||
node.SimpleNode{Name: "Declare", Attributes: make(map[string]string)},
|
||||
token,
|
||||
consts,
|
||||
stmts,
|
||||
}
|
||||
}
|
||||
|
||||
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)
|
||||
|
||||
if n.consts != nil {
|
||||
fmt.Fprintf(out, "\n%vconsts:", indent+" ")
|
||||
for _, nn := range n.consts {
|
||||
nn.Print(out, indent+" ")
|
||||
}
|
||||
}
|
||||
|
||||
if n.stmts != nil {
|
||||
fmt.Fprintf(out, "\n%vstmts:", indent+" ")
|
||||
for _, nn := range n.stmts {
|
||||
nn.Print(out, indent+" ")
|
||||
}
|
||||
}
|
||||
}
|
||||
34
node/stmt/stmt_const.go
Normal file
34
node/stmt/stmt_const.go
Normal file
@@ -0,0 +1,34 @@
|
||||
package stmt
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io"
|
||||
|
||||
"github.com/z7zmey/php-parser/node"
|
||||
"github.com/z7zmey/php-parser/token"
|
||||
)
|
||||
|
||||
type StmtConst struct {
|
||||
node.SimpleNode
|
||||
token token.Token
|
||||
consts []node.Node
|
||||
}
|
||||
|
||||
func NewStmtConst(token token.Token, consts []node.Node) node.Node {
|
||||
return StmtConst{
|
||||
node.SimpleNode{Name: "StmtConst", Attributes: make(map[string]string)},
|
||||
token,
|
||||
consts,
|
||||
}
|
||||
}
|
||||
|
||||
func (n StmtConst) 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.consts != nil {
|
||||
fmt.Fprintf(out, "\n%vconsts:", indent+" ")
|
||||
for _, nn := range n.consts {
|
||||
nn.Print(out, indent+" ")
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user