@ohm-js/wasm 0.6.0 → 0.6.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/src/compat.d.ts +6 -2
- package/dist/src/compat.js +9 -3
- package/package.json +13 -4
package/dist/src/compat.d.ts
CHANGED
|
@@ -1,4 +1,8 @@
|
|
|
1
|
+
import type { Grammar as GrammarJs } from 'ohm-js';
|
|
1
2
|
import { WasmGrammar } from './miniohm.ts';
|
|
2
|
-
export
|
|
3
|
-
|
|
3
|
+
export interface Grammar extends WasmGrammar {
|
|
4
|
+
rules: GrammarJs['rules'];
|
|
5
|
+
}
|
|
6
|
+
export declare function grammar(source: string): Grammar;
|
|
7
|
+
export declare function grammars(source: string): Record<string, Grammar>;
|
|
4
8
|
//# sourceMappingURL=compat.d.ts.map
|
package/dist/src/compat.js
CHANGED
|
@@ -1,17 +1,23 @@
|
|
|
1
1
|
import { grammars as grammarsJs, grammar as grammarJs } from 'ohm-js';
|
|
2
2
|
import { Compiler } from './Compiler.js';
|
|
3
3
|
import { WasmGrammar } from "./miniohm.js";
|
|
4
|
+
class CompatGrammar extends WasmGrammar {
|
|
5
|
+
rules;
|
|
6
|
+
constructor(wasmModule, rules) {
|
|
7
|
+
super(wasmModule);
|
|
8
|
+
this.rules = rules;
|
|
9
|
+
}
|
|
10
|
+
}
|
|
4
11
|
// TODO: Support a namespace parameter.
|
|
5
12
|
export function grammar(source) {
|
|
6
|
-
|
|
7
|
-
return new WasmGrammar(compiler.compile());
|
|
13
|
+
return Object.values(grammars(source))[0];
|
|
8
14
|
}
|
|
9
15
|
// TODO: Support a namespace parameter.
|
|
10
16
|
export function grammars(source) {
|
|
11
17
|
const ans = {};
|
|
12
18
|
for (const g of Object.values(grammarsJs(source))) {
|
|
13
19
|
const compiler = new Compiler(g);
|
|
14
|
-
ans[g.name] = new
|
|
20
|
+
ans[g.name] = new CompatGrammar(compiler.compile(), g.rules);
|
|
15
21
|
}
|
|
16
22
|
return ans;
|
|
17
23
|
}
|
package/package.json
CHANGED
|
@@ -1,12 +1,21 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ohm-js/wasm",
|
|
3
|
-
"version": "0.6.
|
|
3
|
+
"version": "0.6.2",
|
|
4
4
|
"description": "Compile Ohm.js grammars to WebAsssembly",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"exports": {
|
|
7
|
-
".":
|
|
8
|
-
|
|
9
|
-
|
|
7
|
+
".": {
|
|
8
|
+
"import": "./dist/index.js",
|
|
9
|
+
"types": "./dist/index.d.ts"
|
|
10
|
+
},
|
|
11
|
+
"./compat": {
|
|
12
|
+
"import": "./dist/src/compat.js",
|
|
13
|
+
"types": "./dist/src/compat.d.ts"
|
|
14
|
+
},
|
|
15
|
+
"./compiler": {
|
|
16
|
+
"import": "./dist/src/Compiler.js",
|
|
17
|
+
"types": "./dist/src/Compiler.d.ts"
|
|
18
|
+
}
|
|
10
19
|
},
|
|
11
20
|
"bin": {
|
|
12
21
|
"ohm2wasm": "dist/src/cli.js"
|