-
Notifications
You must be signed in to change notification settings - Fork 6
/
token.go
67 lines (59 loc) · 1.33 KB
/
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
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
// Copyright (c) HashiCorp, Inc.
// SPDX-License-Identifier: MPL-2.0
package mql
type token struct {
Type tokenType
Value string
}
type tokenType int
const eof rune = -1
const (
unknownToken tokenType = iota
eofToken
whitespaceToken
stringToken
startLogicalExprToken
endLogicalExprToken
greaterThanToken
greaterThanOrEqualToken
lessThanToken
lessThanOrEqualToken
equalToken
notEqualToken
containsToken
numberToken
symbolToken
// keywords
andToken
orToken
)
var tokenTypeToString = map[tokenType]string{
unknownToken: "unknown",
eofToken: "eof",
whitespaceToken: "ws",
stringToken: "str",
startLogicalExprToken: "lparen",
endLogicalExprToken: "rparen",
greaterThanToken: "gt",
greaterThanOrEqualToken: "gte",
lessThanToken: "lt",
lessThanOrEqualToken: "lte",
equalToken: "eq",
notEqualToken: "neq",
containsToken: "contains",
andToken: "and",
orToken: "or",
numberToken: "num",
symbolToken: "symbol",
}
// String returns a string of the tokenType and will return "Unknown" for
// invalid tokenTypes
func (t tokenType) String() string {
s, ok := tokenTypeToString[t]
switch ok {
case true:
return s
default:
return tokenTypeToString[unknownToken]
}
}