-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathtokens.go
46 lines (38 loc) · 948 Bytes
/
tokens.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
package octetcounting
import (
"strconv"
)
// Token represents a lexical token of the octetcounting.
type Token struct {
typ TokenType
lit []byte
}
// TokenType represents a lexical token type of the octetcounting.
type TokenType int
// Tokens
const (
ILLEGAL TokenType = iota
EOF
LF
WS
MSGLEN
SYSLOGMSG
)
// String outputs the string representation of the receiving Token.
func (t Token) String() string {
switch t.typ {
case WS, EOF:
return t.typ.String()
default:
return t.typ.String() + "(" + string(t.lit) + ")"
}
}
const tokentypename = "ILLEGALEOFLFWSMSGLENSYSLOGMSG"
var tokentypeindex = [...]uint8{0, 7, 10, 12, 14, 20, 29}
// String outputs the string representation of the receiving TokenType.
func (i TokenType) String() string {
if i < 0 || i >= TokenType(len(tokentypeindex)-1) {
return "TokenType(" + strconv.FormatInt(int64(i), 10) + ")"
}
return tokentypename[tokentypeindex[i]:tokentypeindex[i+1]]
}