-
Notifications
You must be signed in to change notification settings - Fork 0
/
tokens.go
41 lines (37 loc) · 834 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
package clo
// this set of constants enumerates all distinct token types
const (
command = iota
argument
value
)
// tokenString converts token type to a human readable string
func tokenString(tokenType int) string {
switch tokenType {
case command:
return "command"
case argument:
return "argument"
case value:
return "value"
}
return "unknown"
}
// next defines possible token types that can follow a given type of token.
// Order below assumes the following sequence of token types:
// app command [<arguments> [<values>]]
func next(tokenType int) []int {
switch tokenType {
case command:
return []int{argument, value}
case argument:
return []int{value, argument}
case value:
return []int{argument, value}
default:
return []int{}
}
}
func initial() []int {
return []int{command, argument, value}
}