-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtypes.ts
60 lines (49 loc) · 1.53 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
import { MiniscriptParseContext } from "./parse/parser";
// Represents a class literal implementing MiniscriptFragmentStatic
export type MiniscriptFragmentClass = {
tokenType: string;
parse: (m: MiniscriptParseContext) => MiniscriptFragment;
new (...args: any[]): MiniscriptFragmentStatic;
};
// Represents a class literal implementing MiniscriptWrapper
export type MiniscriptWrapperClass = {
tokenType: string;
parseWrapper: (m: MiniscriptParseContext) => MiniscriptFragment;
new (...args: any[]): MiniscriptWrapper;
};
export interface MiniscriptModule {
wrappers: MiniscriptWrapperClass[];
expressions: MiniscriptFragmentClass[];
}
export interface MiniscriptFragment {
type: number;
getSize: () => number;
getType: () => number;
toScript: (verify?: boolean) => string;
}
export abstract class MiniscriptWrapper {
static tokenType: string;
}
export interface LexState {
cursor: number;
}
export interface ParseState {}
export abstract class Token {
tokenType: string | undefined;
position: number;
value?: string | number;
skipWrapper?: boolean;
constructor() {
throw new Error("Constructor should always be overloaded");
}
}
export type TokenClass = {
lex: (s: string, state: LexState) => Token | undefined;
};
export abstract class MiniscriptFragmentStatic {
static tokenType: string;
static lex: (s: string, state: LexState) => Token | undefined;
static parse(parseContext: MiniscriptParseContext): MiniscriptFragment {
throw new Error(`Parse not implemented for token ${this.tokenType}`);
}
}