constant nodes

This commit is contained in:
z7zmey
2017-12-05 00:02:24 +02:00
parent e7ba0ca435
commit 347cb09386
12 changed files with 691 additions and 596 deletions

View File

@@ -1,27 +0,0 @@
package node
import (
"fmt"
"github.com/z7zmey/php-parser/token"
"io"
)
type NodeScalarEncapsedStringPart struct {
*SimpleNode
token token.Token
}
func NewNodeScalarEncapsedStringPart(t token.Token) Node {
return NodeScalarEncapsedStringPart{
&SimpleNode{Name: "NodeScalarEncapsedStringPart", Attributes: make(map[string]string)},
t,
}
}
func (n NodeScalarEncapsedStringPart) 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+" ")
}
}

View File

@@ -1,28 +0,0 @@
package node
import (
"fmt"
"github.com/z7zmey/php-parser/token"
"io"
)
type NodeScalarString struct {
*SimpleNode
token token.Token
}
func NewNodeScalarString(t token.Token) Node {
return NodeScalarString{
&SimpleNode{Name: "NodeScalarString", Attributes: make(map[string]string)},
t,
}
}
func (n NodeScalarString) 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+" ")
}
}

29
node/scalar/dnumber.go Normal file
View File

@@ -0,0 +1,29 @@
package scalar
import (
"fmt"
"github.com/z7zmey/php-parser/token"
"github.com/z7zmey/php-parser/node"
"io"
)
type Dnumber struct {
node.SimpleNode
token token.Token
}
func NewDnumber(token token.Token) node.Node {
return Dnumber{
node.SimpleNode{Name: "Dnumber", Attributes: make(map[string]string)},
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+" ")
}
}

View File

@@ -1,30 +1,31 @@
package node
package scalar
import (
"fmt"
"github.com/z7zmey/php-parser/token"
"github.com/z7zmey/php-parser/node"
"io"
)
type NodeScalarEncapsed struct {
*SimpleNode
type Encapsed struct {
node.SimpleNode
startToken token.Token
endToken token.Token
parts []Node
parts []node.Node
}
func NewNodeScalarEncapsed(startToken token.Token, parts []Node, endToken token.Token) Node {
return NodeScalarEncapsed{
&SimpleNode{Name: "NodeScalarEncapsed", Attributes: make(map[string]string)},
func NewEncapsed(startToken token.Token, parts []node.Node, endToken token.Token) node.Node {
return Encapsed{
node.SimpleNode{Name: "Encapsed", Attributes: make(map[string]string)},
startToken,
endToken,
parts,
}
}
func (n NodeScalarEncapsed) Print(out io.Writer, indent string) {
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 {

View File

@@ -0,0 +1,28 @@
package scalar
import (
"fmt"
"github.com/z7zmey/php-parser/token"
"github.com/z7zmey/php-parser/node"
"io"
)
type EncapsedStringPart struct {
node.SimpleNode
token token.Token
}
func NewEncapsedStringPart(t token.Token) node.Node {
return EncapsedStringPart{
node.SimpleNode{Name: "EncapsedStringPart", Attributes: make(map[string]string)},
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+" ")
}
}

29
node/scalar/lnumber.go Normal file
View File

@@ -0,0 +1,29 @@
package scalar
import (
"fmt"
"github.com/z7zmey/php-parser/token"
"github.com/z7zmey/php-parser/node"
"io"
)
type Lnumber struct {
node.SimpleNode
token token.Token
}
func NewLnumber(token token.Token) node.Node {
return Lnumber{
node.SimpleNode{Name: "Lnumber", Attributes: make(map[string]string)},
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+" ")
}
}

View File

@@ -0,0 +1,29 @@
package scalar
import (
"fmt"
"github.com/z7zmey/php-parser/token"
"github.com/z7zmey/php-parser/node"
"io"
)
type MagicConstant struct {
node.SimpleNode
token token.Token
}
func NewMagicConstant(token token.Token) node.Node {
return String{
node.SimpleNode{Name: "MagicConstant", Attributes: make(map[string]string)},
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+" ")
}
}

29
node/scalar/string.go Normal file
View File

@@ -0,0 +1,29 @@
package scalar
import (
"fmt"
"github.com/z7zmey/php-parser/token"
"github.com/z7zmey/php-parser/node"
"io"
)
type String struct {
node.SimpleNode
token token.Token
}
func NewString(token token.Token) node.Node {
return String{
node.SimpleNode{Name: "String", Attributes: make(map[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+" ")
}
}