@ohm-js/wasm 0.1.0 → 0.1.1

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/cli.js ADDED
@@ -0,0 +1,24 @@
1
+ #!/usr/bin/env node
2
+
3
+ // src/cli.js
4
+ import * as ohm from "ohm-js";
5
+ import fs from "node:fs";
6
+ import { basename } from "node:path";
7
+ import { Compiler } from "./index.js";
8
+ function main() {
9
+ const args = process.argv.slice(2);
10
+ if (args.length !== 1) {
11
+ printUsage();
12
+ process.exit(1);
13
+ }
14
+ const filename = args[0];
15
+ const g = ohm.grammar(fs.readFileSync(filename, "utf8"));
16
+ const bytes = new Compiler(g).compile();
17
+ const outFilename = filename.replace(".ohm", ".wasm");
18
+ fs.writeFileSync(outFilename, bytes);
19
+ console.log(`Wrote Wasm to ${outFilename}`);
20
+ }
21
+ function printUsage() {
22
+ console.log(`usage: ${basename(process.argv[1])} <ohm-grammar-file>`);
23
+ }
24
+ main();