argument nullable parameter nodes
This commit is contained in:
parent
84887c66c3
commit
06a15be7a2
30
node/argument.go
Normal file
30
node/argument.go
Normal 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
27
node/nullable.go
Normal 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
48
node/parameter.go
Normal 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+" ")
|
||||
}
|
||||
|
||||
}
|
570
parser/parser.go
570
parser/parser.go
File diff suppressed because it is too large
Load Diff
@ -602,31 +602,22 @@ non_empty_parameter_list:
|
||||
parameter:
|
||||
optional_type is_reference is_variadic T_VARIABLE
|
||||
{
|
||||
$$ = node.NewSimpleNode("Parameter").
|
||||
Append($1).
|
||||
Attribute("is_reference", $2).
|
||||
Attribute("is_variadic", $3).
|
||||
Attribute("var", $4.String());
|
||||
$$ = node.NewParameter($1, expr.NewVariable(node.NewIdentifier($4)), nil, $2 == "true", $3 == "true")
|
||||
}
|
||||
| optional_type is_reference is_variadic T_VARIABLE '=' expr
|
||||
{
|
||||
$$ = node.NewSimpleNode("Parameter").
|
||||
Append($1).
|
||||
Attribute("is_reference", $2).
|
||||
Attribute("is_variadic", $3).
|
||||
Attribute("var", $4.String()).
|
||||
Append($6);
|
||||
$$ = node.NewParameter($1, expr.NewVariable(node.NewIdentifier($4)), $6, $2 == "true", $3 == "true")
|
||||
}
|
||||
;
|
||||
|
||||
optional_type:
|
||||
/* empty */ { $$ = node.NewSimpleNode("No type") }
|
||||
/* empty */ { $$ = nil }
|
||||
| type_expr { $$ = $1; }
|
||||
;
|
||||
|
||||
type_expr:
|
||||
type { $$ = $1; }
|
||||
| '?' type { $$ = $2; $$.Attribute("nullable", "true") }
|
||||
| '?' type { $$ = node.NewNullable($2) }
|
||||
;
|
||||
|
||||
type:
|
||||
@ -651,8 +642,8 @@ non_empty_argument_list:
|
||||
;
|
||||
|
||||
argument:
|
||||
expr { $$ = $1; }
|
||||
| T_ELLIPSIS expr { $$ = node.NewSimpleNode("Unpack").Append($2) }
|
||||
expr { $$ = node.NewArgument($1, false) }
|
||||
| T_ELLIPSIS expr { $$ = node.NewArgument($2, true) }
|
||||
;
|
||||
|
||||
global_var_list:
|
||||
|
Loading…
Reference in New Issue
Block a user