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
|
export enum TokenType {
OPEN_PAREN = "(",
CLOSE_PAREN = ")",
SPACE = " ",
SEMICOLON = ";",
COMMA = ",",
UNIQUE_SYMBOL = "UNIQUE_SYMBOL",
}
export type Token<
Type extends TokenType = TokenType,
Name extends string = string
> = {
type: Type;
name: Name;
};
export type LexerCtx = {
next: string;
nameCollection: string;
tokens: readonly Token[];
};
export enum NodeType {
ROOT = "ROOT",
LITERAL = "LITERAL",
CALL = "CALL",
PARSER_ERROR = "PARSER_ERROR",
}
export type ASTNode<
Type extends NodeType = NodeType,
Name extends string = string,
Children extends ASTNode[] = ASTNode<NodeType, string, any>[]
> = {
type: Type;
name: Name;
children: Children;
};
export type ParserCtx = {
remainingTokens: readonly Token[];
lastName: string | null;
stack: readonly ASTNode[];
};
|