-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.ts
executable file
·89 lines (79 loc) · 1.99 KB
/
index.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
81
82
83
84
85
86
87
88
89
declare var require: any;
const wasmModule = require("../build/main");
import {
readStringFromHeap,
writeStringToHeap
} from "lys/dist/utils/execution";
export async function tokenizer() {
const instance = await wasmModule.default();
function eat(): string {
return readStringFromHeap(instance, instance.exports.eat());
}
function parseAst(source: string): string {
return readStringFromHeap(
instance,
instance.exports.parseAst(writeStringToHeap(instance, source))
);
}
function parseAstDesugar(source: string): string {
return readStringFromHeap(
instance,
instance.exports.parseAstDesugar(writeStringToHeap(instance, source))
);
}
function parseAndEmitAst(
moduleName: string,
path: string,
source: string
): string {
return readStringFromHeap(
instance,
instance.exports.parseAndEmitAst(
writeStringToHeap(instance, moduleName),
writeStringToHeap(instance, path),
writeStringToHeap(instance, source)
)
);
}
function parseAndEmitErrors(
moduleName: string,
path: string,
source: string
): string {
return readStringFromHeap(
instance,
instance.exports.parseAndEmitErrors(
writeStringToHeap(instance, moduleName),
writeStringToHeap(instance, path),
writeStringToHeap(instance, source)
)
);
}
function parseAndEmitDesugar(
moduleName: string,
path: string,
source: string
): string {
return readStringFromHeap(
instance,
instance.exports.parseAndEmitDesugar(
writeStringToHeap(instance, moduleName),
writeStringToHeap(instance, path),
writeStringToHeap(instance, source)
)
);
}
function startLexer(data: string) {
instance.exports.startLexer(writeStringToHeap(instance, data));
}
return {
startLexer,
parseAndEmitAst,
parseAndEmitErrors,
parseAndEmitDesugar,
parseAst,
parseAstDesugar,
eat
};
}
export default tokenizer;