interface node
This commit is contained in:
parent
02ce2bec9a
commit
c25748d7db
44
node/stmt/interface.go
Normal file
44
node/stmt/interface.go
Normal file
@ -0,0 +1,44 @@
|
|||||||
|
package stmt
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"io"
|
||||||
|
|
||||||
|
"github.com/z7zmey/php-parser/node"
|
||||||
|
"github.com/z7zmey/php-parser/token"
|
||||||
|
)
|
||||||
|
|
||||||
|
type Interface struct {
|
||||||
|
node.SimpleNode
|
||||||
|
token token.Token
|
||||||
|
name token.Token
|
||||||
|
extends node.Node
|
||||||
|
stmts []node.Node
|
||||||
|
}
|
||||||
|
|
||||||
|
//TODO: stmts myst be []node.Node
|
||||||
|
func NewInterface(token token.Token, name token.Token, extends node.Node, stmts []node.Node) node.Node {
|
||||||
|
return Interface{
|
||||||
|
node.SimpleNode{Name: "Interface", Attributes: make(map[string]string)},
|
||||||
|
token,
|
||||||
|
name,
|
||||||
|
extends,
|
||||||
|
stmts,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (n Interface) 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.name.Value)
|
||||||
|
|
||||||
|
if n.extends != nil {
|
||||||
|
fmt.Fprintf(out, "\n%vextends:", indent+" ")
|
||||||
|
n.extends.Print(out, indent+" ")
|
||||||
|
}
|
||||||
|
|
||||||
|
if n.stmts != nil {
|
||||||
|
fmt.Fprintf(out, "\n%vstmts:", indent+" ")
|
||||||
|
for _, nn := range n.stmts {
|
||||||
|
nn.Print(out, indent+" ")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
629
parser/parser.go
629
parser/parser.go
File diff suppressed because it is too large
Load Diff
@ -466,12 +466,7 @@ trait_declaration_statement:
|
|||||||
|
|
||||||
interface_declaration_statement:
|
interface_declaration_statement:
|
||||||
T_INTERFACE T_STRING interface_extends_list '{' class_statement_list '}'
|
T_INTERFACE T_STRING interface_extends_list '{' class_statement_list '}'
|
||||||
{
|
{ $$ = stmt.NewInterface($1, $2, $3, $5.(node.SimpleNode).Children) }
|
||||||
$$ = node.NewSimpleNode("Interface").
|
|
||||||
Attribute("name", $2.String()).
|
|
||||||
Append(node.NewSimpleNode("Extends").Append($3)).
|
|
||||||
Append($5);
|
|
||||||
}
|
|
||||||
;
|
;
|
||||||
|
|
||||||
extends_from:
|
extends_from:
|
||||||
@ -480,7 +475,7 @@ extends_from:
|
|||||||
;
|
;
|
||||||
|
|
||||||
interface_extends_list:
|
interface_extends_list:
|
||||||
/* empty */ { $$ = node.NewSimpleNode("") }
|
/* empty */ { $$ = nil }
|
||||||
| T_EXTENDS name_list { $$ = $2; }
|
| T_EXTENDS name_list { $$ = $2; }
|
||||||
;
|
;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user