forked from metarhia/metalisp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmetalisp.d.ts
40 lines (32 loc) · 1.24 KB
/
metalisp.d.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
export type List = Array<unknown>;
export type Value = number | string;
export type Result = List | Value;
export type Operator = (...list: List) => Result;
export type LispContext = Record<string, unknown>;
export type Clause = { condition: Expression; consequent: Expression[] };
export function listp(list: unknown): boolean;
export function head(list: List): Result;
export function tail(list: List): List;
export const OPERATORS: Record<string, Operator>;
export interface Expression {
interpret(context: LispContext): Value;
}
export class NumberExpression implements Expression {
constructor(value: number | string);
interpret(context: LispContext): number;
}
export class VariableExpression implements Expression {
constructor(name: string);
interpret(context: LispContext): Value;
}
export class OperationExpression implements Expression {
constructor(operator: string, operands: List);
interpret(context: LispContext): Value;
}
export class ConditionExpression implements Expression {
constructor(clauses: Clause[]);
interpret(context: LispContext): Value;
}
export function parse(tokens: string | List): Expression;
export function tokenize(source: string): List;
export function evaluate(input: string, context?: LispContext): Value;