-
Notifications
You must be signed in to change notification settings - Fork 171
/
token.go
117 lines (104 loc) · 1.97 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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
package token
// Type is used to determite token type
type Type string
// Token is structure for identifying input stream of characters
type Token struct {
Type Type
Literal string
Line int
}
// Literals
const (
Illegal = "ILLEGAL"
EOF = "EOF"
Constant = "CONSTANT"
Ident = "IDENT"
InstanceVariable = "INSTANCE_VAR"
Int = "INT"
Float = "FLOAT"
String = "STRING"
Comment = "COMMENT"
Assign = "="
Plus = "+"
PlusEq = "+="
Minus = "-"
MinusEq = "-="
Bang = "!"
Asterisk = "*"
Pow = "**"
Slash = "/"
Dot = "."
And = "&&"
Or = "||"
OrEq = "||="
Modulo = "%"
Match = "=~"
LT = "<"
LTE = "<="
GT = ">"
GTE = ">="
COMP = "<=>"
Comma = ","
Semicolon = ";"
Colon = ":"
Bar = "|"
LParen = "("
RParen = ")"
LBrace = "{"
RBrace = "}"
LBracket = "["
RBracket = "]"
Eq = "=="
NotEq = "!="
Range = ".."
True = "TRUE"
False = "FALSE"
Null = "Null"
If = "IF"
ElsIf = "ELSIF"
Else = "ELSE"
Case = "CASE"
When = "WHEN"
Return = "RETURN"
Next = "NEXT"
Break = "BREAK"
Def = "DEF"
Self = "SELF"
End = "END"
While = "WHILE"
Do = "DO"
Yield = "YIELD"
GetBlock = "GET_BLOCK"
Class = "CLASS"
Module = "MODULE"
ResolutionOperator = "::"
)
var keywords = map[string]Type{
"def": Def,
"true": True,
"false": False,
"nil": Null,
"if": If,
"elsif": ElsIf,
"else": Else,
"case": Case,
"when": When,
"return": Return,
"self": Self,
"end": End,
"while": While,
"do": Do,
"yield": Yield,
"next": Next,
"class": Class,
"module": Module,
"break": Break,
"get_block": GetBlock,
}
// LookupIdent is used for keyword identification
func LookupIdent(ident string) Type {
if tok, ok := keywords[ident]; ok {
return tok
}
return Ident
}