-
Notifications
You must be signed in to change notification settings - Fork 6
/
goclj.go
87 lines (78 loc) · 1.59 KB
/
goclj.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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
package goclj
import "github.com/cespare/goclj/parse"
func FnFormSymbol(node parse.Node, sym ...string) bool {
list, ok := node.(*parse.ListNode)
if !ok {
return false
}
children := list.Children()
if len(children) == 0 {
return false
}
s, ok := children[0].(*parse.SymbolNode)
if !ok {
return false
}
if len(sym) == 0 {
return true
}
for _, name := range sym {
if s.Val == name {
return true
}
}
return false
}
func FnFormKeyword(node parse.Node, kw ...string) bool {
list, ok := node.(*parse.ListNode)
if !ok {
return false
}
children := list.Children()
if len(children) == 0 {
return false
}
k, ok := children[0].(*parse.KeywordNode)
if !ok {
return false
}
if len(kw) == 0 {
return true
}
for _, name := range kw {
if k.Val == name {
return true
}
}
return false
}
func Symbol(node parse.Node) bool {
_, ok := node.(*parse.SymbolNode)
return ok
}
func Newline(node parse.Node) bool {
_, ok := node.(*parse.NewlineNode)
return ok
}
func Vector(node parse.Node) bool {
_, ok := node.(*parse.VectorNode)
return ok
}
func Keyword(node parse.Node) bool {
_, ok := node.(*parse.KeywordNode)
return ok
}
func Comment(node parse.Node) bool {
_, ok := node.(*parse.CommentNode)
return ok
}
// Semantic returns whether a node changes the semantics of the code.
// NOTE: right now this is only used for let indenting.
// It might have to be adjusted if used for other purposes.
func Semantic(node parse.Node) bool {
switch node.(type) {
case *parse.NewlineNode, *parse.CommentNode, *parse.MetadataNode, *parse.TagNode:
return false
}
return true
}