argument nullable parameter nodes

This commit is contained in:
vadim
2017-12-27 16:26:36 +02:00
parent 84887c66c3
commit 06a15be7a2
5 changed files with 392 additions and 304 deletions

30
node/argument.go Normal file
View File

@@ -0,0 +1,30 @@
package node
import (
"fmt"
"io"
)
type Argument struct {
SimpleNode
expr Node
variadic bool
}
func NewArgument(expression Node, variadic bool) Node {
return Argument{
SimpleNode{Name: "Argument", Attributes: make(map[string]string)},
expression,
variadic,
}
}
func (n Argument) Print(out io.Writer, indent string) {
fmt.Fprintf(out, "\n%v%v [- -]", indent, n.Name)
fmt.Fprintf(out, "\n%vvariadic: %t", indent+" ", n.variadic)
if n.expr != nil {
fmt.Fprintf(out, "\n%vexpr:", indent+" ")
n.expr.Print(out, indent+" ")
}
}

27
node/nullable.go Normal file
View File

@@ -0,0 +1,27 @@
package node
import (
"fmt"
"io"
)
type Nullable struct {
SimpleNode
expr Node
}
func NewNullable(expression Node) Node {
return Nullable{
SimpleNode{Name: "Nullable", Attributes: make(map[string]string)},
expression,
}
}
func (n Nullable) Print(out io.Writer, indent string) {
fmt.Fprintf(out, "\n%v%v [- -]", indent, n.Name)
if n.expr != nil {
fmt.Fprintf(out, "\n%vexpr:", indent+" ")
n.expr.Print(out, indent+" ")
}
}

48
node/parameter.go Normal file
View File

@@ -0,0 +1,48 @@
package node
import (
"fmt"
"io"
)
type Parameter struct {
SimpleNode
variableType Node
variable Node
defaultValue Node
byRef bool
variadic bool
}
func NewParameter(variableType Node, variable Node, defaultValue Node, byRef bool, variadic bool) Node {
return Parameter{
SimpleNode{Name: "Parameter", Attributes: make(map[string]string)},
variableType,
variable,
defaultValue,
byRef,
variadic,
}
}
func (n Parameter) Print(out io.Writer, indent string) {
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)
if n.variableType != nil {
fmt.Fprintf(out, "\n%vvariableType:", indent+" ")
n.variableType.Print(out, indent+" ")
}
if n.variable != nil {
fmt.Fprintf(out, "\n%vvariable:", indent+" ")
n.variable.Print(out, indent+" ")
}
if n.defaultValue != nil {
fmt.Fprintf(out, "\n%vdefaultValue:", indent+" ")
n.defaultValue.Print(out, indent+" ")
}
}