@ohm-js/wasm 0.1.0 → 0.2.0
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/README.md +27 -0
- package/dist/cli.js +51 -0
- package/dist/index.js +2189 -0
- package/package.json +15 -8
- package/.mise.toml +0 -2
- package/AGENT.md +0 -25
- package/Makefile +0 -23
- package/TODO.md +0 -28
- package/runtime/ohmRuntime.ts +0 -252
- package/scripts/bundlewasm.ts +0 -49
- package/scripts/modparse.ts +0 -397
- package/src/cli.js +0 -36
- package/src/index.js +0 -1195
- package/test/data/_book-review.liquid +0 -257
- package/test/data/_es5.js +0 -1057
- package/test/data/_es5.wasm +0 -0
- package/test/data/_html5shiv-3.7.3.js +0 -326
- package/test/data/_liquid-html.ohm +0 -605
- package/test/go/README.md +0 -67
- package/test/go/cst.go +0 -164
- package/test/go/go.mod +0 -5
- package/test/go/go.sum +0 -2
- package/test/go/matcher.go +0 -370
- package/test/go/testmain.go +0 -161
- package/test/test-es5.js +0 -104
- package/test/test-liquid-html.js +0 -27
- package/test/test-wasm.js +0 -764
package/README.md
CHANGED
|
@@ -32,3 +32,30 @@ const g = ohm.grammar('MyGrammar { start = "blah" }');
|
|
|
32
32
|
// compile() returns the Wasm grammar blob as a Uint8Array.
|
|
33
33
|
const bytes = new Compiler(g).compile();
|
|
34
34
|
```
|
|
35
|
+
|
|
36
|
+
### Development
|
|
37
|
+
|
|
38
|
+
#### Prerequisites
|
|
39
|
+
|
|
40
|
+
- pnpm
|
|
41
|
+
- Node >= 24
|
|
42
|
+
- Make
|
|
43
|
+
|
|
44
|
+
#### Setup
|
|
45
|
+
|
|
46
|
+
From the repo root:
|
|
47
|
+
|
|
48
|
+
```
|
|
49
|
+
pnpm install
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
#### Testing etc.
|
|
53
|
+
|
|
54
|
+
From packages/wasm dir:
|
|
55
|
+
|
|
56
|
+
```
|
|
57
|
+
pnpm test # Run all tests
|
|
58
|
+
pnpm ava test/test-liquid-html.js # Run a specific test file
|
|
59
|
+
make bench # Run perf benchmarks
|
|
60
|
+
node scripts/parseLiquid.js '/Users/pdubroy/dev/third_party/Shopify/dawn/**/*.liquid'
|
|
61
|
+
```
|
package/dist/cli.js
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
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 { parseArgs } from "node:util";
|
|
8
|
+
import { Compiler } from "./index.js";
|
|
9
|
+
function main() {
|
|
10
|
+
const argsConfig = {
|
|
11
|
+
options: {
|
|
12
|
+
grammarName: { short: "g", type: "string" },
|
|
13
|
+
output: { short: "o", type: "string" }
|
|
14
|
+
},
|
|
15
|
+
allowPositionals: true
|
|
16
|
+
};
|
|
17
|
+
let args;
|
|
18
|
+
try {
|
|
19
|
+
args = parseArgs(argsConfig);
|
|
20
|
+
} catch (e) {
|
|
21
|
+
console.error(e.message);
|
|
22
|
+
printUsage();
|
|
23
|
+
process.exit(1);
|
|
24
|
+
}
|
|
25
|
+
if (args.positionals.length !== 1) {
|
|
26
|
+
printUsage();
|
|
27
|
+
process.exit(1);
|
|
28
|
+
}
|
|
29
|
+
const filename = args.positionals[0];
|
|
30
|
+
const ns = ohm.grammars(fs.readFileSync(filename, "utf8"));
|
|
31
|
+
let g = Object.values(ns).at(-1);
|
|
32
|
+
const { grammarName } = args.values;
|
|
33
|
+
if (grammarName) {
|
|
34
|
+
if (!ns[grammarName]) {
|
|
35
|
+
console.error(`Grammar '${grammarName}' not found in ${filename}`);
|
|
36
|
+
process.exit(1);
|
|
37
|
+
}
|
|
38
|
+
g = ns[grammarName];
|
|
39
|
+
}
|
|
40
|
+
const bytes = new Compiler(g).compile();
|
|
41
|
+
const outFilename = args.values.output ?? filename.replace(".ohm", ".wasm");
|
|
42
|
+
fs.writeFileSync(outFilename, bytes);
|
|
43
|
+
console.log(`Wrote Wasm to ${outFilename}`);
|
|
44
|
+
}
|
|
45
|
+
function printUsage() {
|
|
46
|
+
const exeName = basename(process.argv[1]);
|
|
47
|
+
console.log(
|
|
48
|
+
`usage: ${exeName} [(--grammarName|-g) <name>] [(--output|-o) <file>] <ohm-grammar-file>`
|
|
49
|
+
);
|
|
50
|
+
}
|
|
51
|
+
main();
|