-
Notifications
You must be signed in to change notification settings - Fork 16
/
tokenblocks.go
61 lines (50 loc) · 1.11 KB
/
tokenblocks.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
package grammar
type tokenBlocks struct {
blocks []TokenBlock
}
func createTokenBlocks(blocks []TokenBlock) TokenBlocks {
out := tokenBlocks{
blocks: blocks,
}
return &out
}
// Get returns the tokenBlocks
func (obj *tokenBlocks) Get() []TokenBlock {
return obj.blocks
}
// SubTokenNames returns the subToken names
func (obj *tokenBlocks) SubTokenNames() []string {
names := []string{}
for _, oneBlock := range obj.blocks {
section := oneBlock.Section()
if section.HasToken() {
isUnique := true
val := section.Token().Name()
for _, oneName := range names {
if oneName == val {
isUnique = false
break
}
}
if isUnique {
names = append(names, section.Token().Name())
}
}
}
return names
}
// RuleTokenAtIndex returns the RuleSection or Token name at index
func (obj *tokenBlocks) RulesToken() ([]Rule, string) {
out := []Rule{}
for _, oneTokenBlock := range obj.blocks {
rule, tokenName := oneTokenBlock.Section().NextRuleToken()
if tokenName != "" {
if len(out) > 0 {
return out, ""
}
return nil, tokenName
}
out = append(out, rule)
}
return out, ""
}