summaryrefslogtreecommitdiff
path: root/src/lang/core/common.ts
blob: c1a1dc3b3206571f21e70ade1a7cbeae723b754c (plain)
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
export enum TokenType {
  OPEN_PAREN = "(",
  CLOSE_PAREN = ")",
  SPACE = " ",
  SEMICOLON = ";",
  COMMA = ",",
  NAME = "NAME",
}

export enum TokenSubType {
  NA = "NA",
  LITERAL = "LITERAL",
  REFERENCE = "REFERENCE",
}

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 {
  INT = "INT",
  EXT = "EXT",
  PARSER_ERROR = "PARSER_ERROR",
}

export type ASTNode<
  Type extends NodeType = NodeType,
  Name extends string = string,
  Value extends any = any,
  Children extends readonly ASTNode[] = readonly ASTNode<
    NodeType,
    string,
    any,
    any
  >[]
> = {
  type: Type;
  name: Name;
  value: Value;
  children: Children;
};

export type ParserCtx = {
  remainingTokens: readonly Token[];
  lastToken: Token | null;
  stack: readonly ASTNode[];
};