-
Notifications
You must be signed in to change notification settings - Fork 0
/
token.go
67 lines (54 loc) · 867 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
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
package bcl
import "fmt"
type tokenType int
type token struct {
typ tokenType
val string
err error // either val or err is set
pos int
}
const (
tFAIL tokenType = iota
tEOF // values <= tEOF are finalizers
tERR
tINT
tFLOAT
tSTR
tIDENT
tVAR
tDEF
tEVAL
tPRINT
tTRUE
tFALSE
tNIL
tEQ // single equal sign, not to be confused with tEE
tLCURLY
tRCURLY
tLPAREN
tRPAREN
//tLBRACKET
//tRBRACKET
tOR
tAND
tNOT
tEE // equal-equal
tBE // bang-equal
tLT // less-than
tLE // less-or-equal
tGT // greater-than
tGE // greater-or-equal
tPLUS
tMINUS
tSTAR
tSLASH
tSEMICOLON
tMAX // used only in the rules table
)
//go:generate stringer -type=tokenType
func (t token) String() string {
if t.typ == tERR {
return fmt.Sprintf("{%s %q %d}", t.typ, t.err, t.pos)
}
return fmt.Sprintf("{%s %q %d}", t.typ, t.val, t.pos)
}