-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconstants.ts
More file actions
22 lines (19 loc) · 834 Bytes
/
Copy pathconstants.ts
File metadata and controls
22 lines (19 loc) · 834 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
import { TokenType } from "../../schemas/token-types/union";
export const OPERATOR_TO_FUNCTION_MAP = {
[TokenType.PLUS]: (a: number, b: number) => a + b,
[TokenType.MINUS]: (a: number, b: number) => a - b,
[TokenType.ASTERISK]: (a: number, b: number) => a * b,
[TokenType.SLASH]: (a: number, b: number) => a / b,
[TokenType.EXPONENT]: (a: number, b: number) => a ** b,
[TokenType.LT]: (a: number, b: number) => a < b,
[TokenType.GT]: (a: number, b: number) => a > b,
[TokenType.EQ]: <T>(a: T, b: T) => a === b,
[TokenType.NOT_EQ]: <T>(a: T, b: T) => a !== b,
} as const;
export const PREFIX_OPERATOR_TO_FUNCTION_MAP = {
[TokenType.BANG]: (a: number) => !a,
[TokenType.MINUS]: (a: number) => -a,
} as const;
export const STRING_OPERATOR_TO_FUNCTION_MAP = {
[TokenType.PLUS]: (a: string, b: string) => a + b,
} as const;