class_method node
This commit is contained in:
parent
25b8add282
commit
36709bdfae
63
node/stmt/class_method.go
Normal file
63
node/stmt/class_method.go
Normal file
@ -0,0 +1,63 @@
|
|||||||
|
package stmt
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"io"
|
||||||
|
|
||||||
|
"github.com/z7zmey/php-parser/node"
|
||||||
|
"github.com/z7zmey/php-parser/token"
|
||||||
|
)
|
||||||
|
|
||||||
|
type ClassMethod struct {
|
||||||
|
node.SimpleNode
|
||||||
|
token token.Token
|
||||||
|
modifiers []node.Node
|
||||||
|
isReturnRef bool
|
||||||
|
params []node.Node
|
||||||
|
returnType node.Node
|
||||||
|
stmts []node.Node
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewClassMethod(token token.Token, modifiers []node.Node, isReturnRef bool, params []node.Node, returnType node.Node, stmts []node.Node) node.Node {
|
||||||
|
return ClassMethod{
|
||||||
|
node.SimpleNode{Name: "ClassMethod", Attributes: make(map[string]string)},
|
||||||
|
token,
|
||||||
|
modifiers,
|
||||||
|
isReturnRef,
|
||||||
|
params,
|
||||||
|
returnType,
|
||||||
|
stmts,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (n ClassMethod) 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.modifiers != nil {
|
||||||
|
fmt.Fprintf(out, "\n%vmotifiers:", indent+" ")
|
||||||
|
for _, nn := range n.modifiers {
|
||||||
|
fmt.Fprintf(out, "\n%v%q", indent+" ", nn)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
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+" ")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
498
parser/parser.go
498
parser/parser.go
File diff suppressed because it is too large
Load Diff
@ -685,16 +685,9 @@ class_statement:
|
|||||||
variable_modifiers property_list ';' { $$ = $2.Append($1) }
|
variable_modifiers property_list ';' { $$ = $2.Append($1) }
|
||||||
| method_modifiers T_CONST class_const_list ';' { $$ = stmt.NewClassConst($2, $1.(node.SimpleNode).Children, $3); }
|
| method_modifiers T_CONST class_const_list ';' { $$ = stmt.NewClassConst($2, $1.(node.SimpleNode).Children, $3); }
|
||||||
| T_USE name_list trait_adaptations { $$ = node.NewSimpleNode("Use").Append($2).Append($3); }
|
| T_USE name_list trait_adaptations { $$ = node.NewSimpleNode("Use").Append($2).Append($3); }
|
||||||
| method_modifiers T_FUNCTION returns_ref identifier '(' parameter_list ')'
|
| method_modifiers T_FUNCTION returns_ref identifier '(' parameter_list ')' return_type method_body
|
||||||
return_type method_body
|
|
||||||
{
|
{
|
||||||
$$ = node.NewSimpleNode("Function").
|
$$ = stmt.NewClassMethod($4, $1.(node.SimpleNode).Children, $3 == "true", $6.(node.SimpleNode).Children, $8, $9.(node.SimpleNode).Children)
|
||||||
Append($1).
|
|
||||||
Attribute("name", $4.Value).
|
|
||||||
Attribute("returns_ref", $3).
|
|
||||||
Append($6).
|
|
||||||
Append($8).
|
|
||||||
Append($9);
|
|
||||||
}
|
}
|
||||||
;
|
;
|
||||||
|
|
||||||
@ -743,7 +736,7 @@ absolute_trait_method_reference:
|
|||||||
;
|
;
|
||||||
|
|
||||||
method_body:
|
method_body:
|
||||||
';' /* abstract method */ { $$ = node.NewSimpleNode(""); }
|
';' /* abstract method */ { $$ = node.NewSimpleNode("") }
|
||||||
| '{' inner_statement_list '}' { $$ = $2; }
|
| '{' inner_statement_list '}' { $$ = $2; }
|
||||||
;
|
;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user