-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathtoken.ts
More file actions
35 lines (31 loc) · 860 Bytes
/
token.ts
File metadata and controls
35 lines (31 loc) · 860 Bytes
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
export const TOKEN_TYPE = {
Id: "ID",
Number: "NUMBER",
Graph: "GRAPH",
Digraph: "DIGRAPH",
Subgraph: "SUBGRAPH",
DirectedEdge: "DIRECTED_EDGE",
Edge: "EDGE",
Semicolon: "SEMICOLON",
LBrace: "LBRACE",
RBrace: "RBRACE",
LBracket: "LBRACKET",
RBracket: "RBRACKET",
Eq: "EQ",
Illegal: "ILLEGAL",
EOF: "EOF",
String: "STRING",
} as const;
export type TokenType = (typeof TOKEN_TYPE)[keyof typeof TOKEN_TYPE];
const keywords: Record<string, TokenType> = {
graph: TOKEN_TYPE.Graph,
digraph: TOKEN_TYPE.Digraph,
subgraph: TOKEN_TYPE.Subgraph,
};
export function lookupIdentifier(literal: string): TokenType {
return keywords[literal.toLowerCase()] ?? TOKEN_TYPE.Id;
}
/** Represents a token produced by DOT lexer. */
export class Token {
constructor(public readonly type: TokenType, public readonly literal: string) {}
}