-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtoken_list.go
More file actions
40 lines (34 loc) · 767 Bytes
/
token_list.go
File metadata and controls
40 lines (34 loc) · 767 Bytes
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
package lexer
// TokenList is a list of lexical tokens.
type TokenList []Token
// Len returns the number of tokens in the list.
func (t TokenList) Len() int {
return len(t)
}
// IsEmpty checks if the list is empty.
func (t TokenList) IsEmpty() bool {
return len(t) == 0
}
// Equals tests if two token lists are equal.
func (t TokenList) Equals(other TokenList) bool {
if len(t) != len(other) {
return false
}
for n := range t {
if t[n] != other[n] {
return false
}
}
return true
}
// Less returns true if list[i] < list[j].
func (t TokenList) Less(i, j int) bool {
if t[i].Value < t[j].Value {
return true
}
return t[i].ID < t[j].ID
}
// Swap swaps tokens i and j in the list.
func (t TokenList) Swap(i, j int) {
t[i], t[j] = t[j], t[i]
}