-
Notifications
You must be signed in to change notification settings - Fork 0
/
token.ts
82 lines (75 loc) · 1.69 KB
/
token.ts
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
import { Span } from "./spans.ts"
type Literal =
"Bool"
| "Float"
| "Int"
| "Null"
| "Str"
type Op =
"Add"
| "Sub"
| "Mult"
| "Div"
| "Rem"
| "Lt"
| "Lte"
| "Gt"
| "Gte"
| "Eq"
| "Neq"
type OpType =
"IntOp"
| "FloatOp"
| "StrOp"
| "IntOrFloatCmp"
| "AnyCmp"
type Token =
{type: "Op", op: Op, opType: OpType, span: Span}
| {type: "Literal", literalType: Literal, value: string, span: Span}
| {type: "Variable", value: string, span: Span}
| {type: "Constructor", value: string, span: Span}
| {type: "Keyword", value: string, span: Span}
| {type: "Newline", span: Span}
| {type: "Colon", span: Span}
| {type: "DoubleColon", span: Span}
| {type: "Dot", span: Span}
| {type: "Lambda", span: Span}
| {type: "Arrow", span: Span}
| {type: "At", span: Span}
| {type: "Assign", span: Span}
| {type: "Circumflex", span: Span}
| {type: "OpenParen", span: Span}
| {type: "CloseParen", span: Span}
| {type: "OpenBrace", span: Span}
| {type: "CloseBrace", span: Span}
| {type: "Or", span: Span}
| {type: "Comma", span: Span}
| {type: "Eof", span: Span}
type Keyword =
"if"
| "then"
| "else"
| "let"
| "in"
| "from"
| "with"
| "do"
| "match"
| "where"
| "so"
| "class"
| "import"
| "type"
| "alias"
| "export"
| "static"
| "end"
const keywords = new Set([
"if", "then", "else", "let",
"in", "from", "with", "do",
"match", "where", "so", "class",
"import", "type", "alias", "export",
"static", "end"
])
export type { Keyword, Token, Literal, Op, OpType }
export { keywords }