-
Notifications
You must be signed in to change notification settings - Fork 0
/
token.go
33 lines (30 loc) · 823 Bytes
/
token.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
package lexer
// Token is a lexical token output by the lexical analyzer.
type Token struct {
// ID is index of the string slice of lexeme patterns used to
// create the lexer at which the lexeme pattern used to identify
// this token is located.
ID int
// Value is the actual string value of the lexeme found by the
// lexical analyzer.
Value string
// Index is the position of the input at which the lexeme was
// found.
Index int
}
// Equals tests if two tokens are equal.
func (t Token) Equals(other Token) bool {
return t.ID == other.ID &&
t.Value == other.Value &&
t.Index == other.Index
}
// Less tests if a token is less than another token.
func (t Token) Less(other Token) bool {
if t.Value < other.Value {
return true
}
if t.ID < other.ID {
return true
}
return t.Index < other.Index
}