-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathnode_types.go
64 lines (54 loc) · 1.26 KB
/
node_types.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
package astpatt
import (
"github.com/tehsphinx/astrav"
)
// FuncDecl node
type FuncDecl struct {
parentNode
Name string
}
// Populate populates the pattern node from a given ast node.
func (s *FuncDecl) Populate(ast astrav.Node) {
s.populateDefault(ast)
if named, ok := ast.(astrav.Named); ok {
s.Name = named.NodeName()
}
s.populateChildren(ast)
}
func (s *FuncDecl) fillNode(nodes []Node, ast astrav.Node) {
s.Nodes = nodes
s.populateDefault(ast)
if named, ok := ast.(astrav.Named); ok {
s.Name = named.NodeName()
}
}
// SelectorExpr node
type SelectorExpr struct {
parentNode
Name string
}
// Populate populates the pattern node from a given ast node.
func (s *SelectorExpr) Populate(ast astrav.Node) {
s.populateDefault(ast)
if named, ok := ast.(astrav.Named); ok {
s.Name = named.NodeName()
}
s.populateChildren(ast)
}
func (s *SelectorExpr) fillNode(nodes []Node, ast astrav.Node) {
s.Nodes = nodes
s.populateDefault(ast)
if named, ok := ast.(astrav.Named); ok {
s.Name = named.NodeName()
}
}
// Match checks if given node matches the criteria
func (s *SelectorExpr) Match(node Node) bool {
if !s.correctType(node) {
return false
}
if n, ok := node.(*SelectorExpr); ok && n.Name != s.Name {
return false
}
return s.Nodes.Match(node)
}