@creationix/rex 0.1.0 → 0.1.3
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 +12 -0
- package/package.json +11 -7
- package/rex-cli.js +30 -0
- package/rex-compile.js +2340 -0
- package/rex-compile.ts +21 -11
- package/rex.js +2319 -0
- package/rex.ohm-bundle.cjs +1 -0
- package/rex.ts +5 -1
- package/rex-cli.ts +0 -3
package/README.md
CHANGED
|
@@ -35,6 +35,18 @@ rex --expr "a and b" --ir
|
|
|
35
35
|
rex --expr "x = method + path x" --minify-names --dedupe-values
|
|
36
36
|
```
|
|
37
37
|
|
|
38
|
+
Run without installing globally:
|
|
39
|
+
|
|
40
|
+
```sh
|
|
41
|
+
bunx @creationix/rex --help
|
|
42
|
+
bunx @creationix/rex --expr "when x do y end"
|
|
43
|
+
|
|
44
|
+
npx -y @creationix/rex -- --help
|
|
45
|
+
npx -y @creationix/rex -- --expr "when x do y end"
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
`npx` works with Node.js alone (v22.18+). `bunx` works with Bun alone.
|
|
49
|
+
|
|
38
50
|
## Programmatic API
|
|
39
51
|
|
|
40
52
|
```ts
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@creationix/rex",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.3",
|
|
4
4
|
"description": "Compiler and parser for the Rex language",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"rex",
|
|
@@ -11,31 +11,35 @@
|
|
|
11
11
|
],
|
|
12
12
|
"type": "module",
|
|
13
13
|
"bin": {
|
|
14
|
-
"rex": "./rex-cli.
|
|
14
|
+
"rex": "./rex-cli.js"
|
|
15
15
|
},
|
|
16
|
-
"main": "rex.
|
|
16
|
+
"main": "rex.js",
|
|
17
17
|
"types": "./rex.ts",
|
|
18
18
|
"exports": {
|
|
19
|
-
".": "./rex.
|
|
19
|
+
".": "./rex.js"
|
|
20
20
|
},
|
|
21
21
|
"files": [
|
|
22
22
|
"README.md",
|
|
23
23
|
"LICENSE",
|
|
24
|
+
"rex.js",
|
|
25
|
+
"rex-compile.js",
|
|
24
26
|
"rex.ts",
|
|
25
27
|
"rex-compile.ts",
|
|
26
|
-
"rex-cli.
|
|
28
|
+
"rex-cli.js",
|
|
27
29
|
"rex.ohm",
|
|
30
|
+
"rex.ohm-bundle.cjs",
|
|
28
31
|
"rex.ohm-bundle.js",
|
|
29
32
|
"rex.ohm-bundle.d.ts",
|
|
30
33
|
"rexc-interpreter.ts"
|
|
31
34
|
],
|
|
32
35
|
"scripts": {
|
|
33
36
|
"test": "bun test",
|
|
34
|
-
"build:grammar": "ohm generateBundles --withTypes rex.ohm",
|
|
37
|
+
"build:grammar": "ohm generateBundles --withTypes rex.ohm && node -e \"require('node:fs').copyFileSync('rex.ohm-bundle.js','rex.ohm-bundle.cjs')\"",
|
|
38
|
+
"build:js": "bun build rex.ts --outfile rex.js --format esm --target node && bun build rex-compile.ts --outfile rex-compile.js --format esm --target node",
|
|
35
39
|
"compile": "bun run rex-compile.ts",
|
|
36
40
|
"verify:docs": "bun run verify-doc-examples.ts",
|
|
37
41
|
"pack:dry-run": "npm pack --dry-run",
|
|
38
|
-
"prepublishOnly": "bun run build:grammar && bun test && npm run pack:dry-run"
|
|
42
|
+
"prepublishOnly": "bun run build:grammar && bun test && bun run build:js && npm run pack:dry-run"
|
|
39
43
|
},
|
|
40
44
|
"publishConfig": {
|
|
41
45
|
"access": "public"
|
package/rex-cli.js
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
import { spawn } from "node:child_process";
|
|
4
|
+
import { dirname, join } from "node:path";
|
|
5
|
+
import { fileURLToPath } from "node:url";
|
|
6
|
+
|
|
7
|
+
const here = dirname(fileURLToPath(import.meta.url));
|
|
8
|
+
const compileScript = join(here, "rex-compile.js");
|
|
9
|
+
const passthroughArgs = process.argv.slice(2);
|
|
10
|
+
|
|
11
|
+
const child = spawn(process.execPath, [compileScript, ...passthroughArgs], {
|
|
12
|
+
stdio: "inherit",
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
child.on("error", (error) => {
|
|
16
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
17
|
+
console.error("rex: failed to launch runtime.");
|
|
18
|
+
console.error("Use Node.js or Bun.");
|
|
19
|
+
console.error(`Details: ${message}`);
|
|
20
|
+
process.exit(1);
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
child.on("exit", (code, signal) => {
|
|
24
|
+
if (typeof code === "number") process.exit(code);
|
|
25
|
+
if (signal) {
|
|
26
|
+
console.error(`rex: process terminated by signal ${signal}`);
|
|
27
|
+
process.exit(1);
|
|
28
|
+
}
|
|
29
|
+
process.exit(1);
|
|
30
|
+
});
|