function node
This commit is contained in:
parent
4394c3997d
commit
280ca04b50
54
node/stmt/function.go
Normal file
54
node/stmt/function.go
Normal file
@ -0,0 +1,54 @@
|
|||||||
|
package stmt
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"io"
|
||||||
|
|
||||||
|
"github.com/z7zmey/php-parser/node"
|
||||||
|
"github.com/z7zmey/php-parser/token"
|
||||||
|
)
|
||||||
|
|
||||||
|
type Function struct {
|
||||||
|
node.SimpleNode
|
||||||
|
token token.Token
|
||||||
|
isReturnRef bool
|
||||||
|
params []node.Node
|
||||||
|
returnType node.Node
|
||||||
|
stmts []node.Node
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewFunction(token token.Token, isReturnRef bool, params []node.Node, returnType node.Node, stmts []node.Node) node.Node {
|
||||||
|
return Function{
|
||||||
|
node.SimpleNode{Name: "Function", Attributes: make(map[string]string)},
|
||||||
|
token,
|
||||||
|
isReturnRef,
|
||||||
|
params,
|
||||||
|
returnType,
|
||||||
|
stmts,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (n Function) 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%vreturn ref: %t", indent+" ", n.isReturnRef)
|
||||||
|
|
||||||
|
if n.params != nil {
|
||||||
|
fmt.Fprintf(out, "\n%vparams:", indent+" ")
|
||||||
|
for _, nn := range n.params {
|
||||||
|
nn.Print(out, indent+" ")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if n.returnType != nil {
|
||||||
|
fmt.Fprintf(out, "\n%vreturn type:", indent+" ")
|
||||||
|
n.returnType.Print(out, indent+" ")
|
||||||
|
}
|
||||||
|
|
||||||
|
if n.stmts != nil {
|
||||||
|
fmt.Fprintf(out, "\n%vstmts:", indent+" ")
|
||||||
|
for _, nn := range n.stmts {
|
||||||
|
nn.Print(out, indent+" ")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
687
parser/parser.go
687
parser/parser.go
File diff suppressed because it is too large
Load Diff
@ -417,12 +417,7 @@ unset_variable:
|
|||||||
function_declaration_statement:
|
function_declaration_statement:
|
||||||
T_FUNCTION returns_ref T_STRING '(' parameter_list ')' return_type '{' inner_statement_list '}'
|
T_FUNCTION returns_ref T_STRING '(' parameter_list ')' return_type '{' inner_statement_list '}'
|
||||||
{
|
{
|
||||||
$$ = node.NewSimpleNode("Function").
|
$$ = stmt.NewFunction($3, $2 == "true", $5.(node.SimpleNode).Children, $7, $9.(node.SimpleNode).Children)
|
||||||
Attribute("name", $3.String()).
|
|
||||||
Attribute("returns_ref", $2).
|
|
||||||
Append($5).
|
|
||||||
Append($7).
|
|
||||||
Append($9);
|
|
||||||
}
|
}
|
||||||
;
|
;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user