-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtypes.ts
80 lines (67 loc) · 1.6 KB
/
types.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
export interface Token {
type: TokenType;
token: string;
}
export enum TokenType {
OPEN_PAREN = "(",
CLOSE_PAREN = ")",
QUOTE = "'",
SYMBOL = "symbol",
NUMBER = "number",
STRING = "string",
UNHANDLED = "unhandled",
}
export type Expression = UnaryOperation | BinaryOperation | TernaryOperation;
export interface UnaryOperation {
type: ExpressionType.UNARY_OPERATION;
param: ExpressionParam;
name: UnaryOperationNames;
}
export interface BinaryOperation {
type: ExpressionType.BINARY_OPERATION;
params: ExpressionParam[];
name: BinaryOperationNames;
}
export interface TernaryOperation {
type: ExpressionType.TERNARY_OPERATION;
params: ExpressionParam[];
name: TernaryOperationNames;
}
export enum ExpressionType {
BINARY_OPERATION = "binary expression",
UNARY_OPERATION = "unary expression",
TERNARY_OPERATION = "ternary expression",
}
export enum BinaryOperationNames {
ADD = "add",
SUBTRACT = "subtract",
MULTIPLY = "multiply",
DIVIDE = "divide",
EQUAL = "===",
NOT_EQUAL = "!==",
LESS_THAN_OR_EQUAL_TO = "<=",
LESS_THAN = "<",
MORE_THAN_OR_EQUAL_TO = ">=",
MORE_THAN = ">",
MAX = "max",
MIN = "min",
}
export enum UnaryOperationNames {
PRINT = "print",
}
export enum TernaryOperationNames {
IF = "if",
}
export type ExpressionParam = Expression | NumberLiteral | StringLiteral;
export interface NumberLiteral {
type: LiteralType.NUMBER_LITERAL;
value: string;
}
export interface StringLiteral {
type: LiteralType.STRING_LITERAL;
value: string;
}
export enum LiteralType {
NUMBER_LITERAL = "number literal",
STRING_LITERAL = "string literal",
}