@creationix/rex 0.1.4 → 0.3.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/README.md +62 -62
- package/package.json +9 -7
- package/rex-cli.js +4077 -30
- package/rex-cli.ts +200 -0
- package/{rex-compile.js → rex-repl.js} +1679 -214
- package/rex-repl.ts +578 -0
- package/rex.js +214 -59
- package/rex.ohm +34 -3
- package/rex.ohm-bundle.cjs +1 -1
- package/rex.ohm-bundle.d.ts +8 -0
- package/rex.ohm-bundle.js +1 -1
- package/rex.ts +2579 -2422
- package/rexc-interpreter.ts +926 -848
- package/rex-compile.ts +0 -224
package/README.md
CHANGED
|
@@ -1,62 +1,62 @@
|
|
|
1
|
-
# @creationix/rex
|
|
2
|
-
|
|
3
|
-
Rex compiler and parser package.
|
|
4
|
-
|
|
5
|
-
## Install
|
|
6
|
-
|
|
7
|
-
```sh
|
|
8
|
-
bun add -g @creationix/rex
|
|
9
|
-
```
|
|
10
|
-
|
|
11
|
-
## Publish to npm
|
|
12
|
-
|
|
13
|
-
From `packages/rex-lang`:
|
|
14
|
-
|
|
15
|
-
```sh
|
|
16
|
-
npm whoami
|
|
17
|
-
bun run prepublishOnly
|
|
18
|
-
npm publish --access public
|
|
19
|
-
```
|
|
20
|
-
|
|
21
|
-
Or one-off dry run:
|
|
22
|
-
|
|
23
|
-
```sh
|
|
24
|
-
bun run pack:dry-run
|
|
25
|
-
```
|
|
26
|
-
|
|
27
|
-
## CLI
|
|
28
|
-
|
|
29
|
-
```sh
|
|
30
|
-
rex --help
|
|
31
|
-
rex --expr "when x do y end"
|
|
32
|
-
rex --file input.rex
|
|
33
|
-
cat input.rex | rex
|
|
34
|
-
rex --expr "a and b" --ir
|
|
35
|
-
rex --expr "x = method + path x" --minify-names --dedupe-values
|
|
36
|
-
```
|
|
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
|
-
|
|
50
|
-
## Programmatic API
|
|
51
|
-
|
|
52
|
-
```ts
|
|
53
|
-
import { compile, parseToIR, optimizeIR, encodeIR } from "@creationix/rex";
|
|
54
|
-
|
|
55
|
-
const source = "when x do y else z end";
|
|
56
|
-
const encoded = compile(source);
|
|
57
|
-
const optimized = compile(source, { optimize: true, minifyNames: true, dedupeValues: true });
|
|
58
|
-
|
|
59
|
-
const ir = parseToIR(source);
|
|
60
|
-
const optimizedIR = optimizeIR(ir);
|
|
61
|
-
const reEncoded = encodeIR(optimizedIR);
|
|
62
|
-
```
|
|
1
|
+
# @creationix/rex
|
|
2
|
+
|
|
3
|
+
Rex compiler and parser package.
|
|
4
|
+
|
|
5
|
+
## Install
|
|
6
|
+
|
|
7
|
+
```sh
|
|
8
|
+
bun add -g @creationix/rex
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Publish to npm
|
|
12
|
+
|
|
13
|
+
From `packages/rex-lang`:
|
|
14
|
+
|
|
15
|
+
```sh
|
|
16
|
+
npm whoami
|
|
17
|
+
bun run prepublishOnly
|
|
18
|
+
npm publish --access public
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
Or one-off dry run:
|
|
22
|
+
|
|
23
|
+
```sh
|
|
24
|
+
bun run pack:dry-run
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
## CLI
|
|
28
|
+
|
|
29
|
+
```sh
|
|
30
|
+
rex --help
|
|
31
|
+
rex --expr "when x do y end"
|
|
32
|
+
rex --file input.rex
|
|
33
|
+
cat input.rex | rex
|
|
34
|
+
rex --expr "a and b" --ir
|
|
35
|
+
rex --expr "x = method + path x" --minify-names --dedupe-values
|
|
36
|
+
```
|
|
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
|
+
|
|
50
|
+
## Programmatic API
|
|
51
|
+
|
|
52
|
+
```ts
|
|
53
|
+
import { compile, parseToIR, optimizeIR, encodeIR } from "@creationix/rex";
|
|
54
|
+
|
|
55
|
+
const source = "when x do y else z end";
|
|
56
|
+
const encoded = compile(source);
|
|
57
|
+
const optimized = compile(source, { optimize: true, minifyNames: true, dedupeValues: true });
|
|
58
|
+
|
|
59
|
+
const ir = parseToIR(source);
|
|
60
|
+
const optimizedIR = optimizeIR(ir);
|
|
61
|
+
const reEncoded = encodeIR(optimizedIR);
|
|
62
|
+
```
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@creationix/rex",
|
|
3
|
-
"version": "0.1
|
|
3
|
+
"version": "0.3.1",
|
|
4
4
|
"description": "Compiler and parser for the Rex language",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"rex",
|
|
@@ -22,24 +22,26 @@
|
|
|
22
22
|
"README.md",
|
|
23
23
|
"LICENSE",
|
|
24
24
|
"rex.js",
|
|
25
|
-
"rex-compile.js",
|
|
26
25
|
"rex.ts",
|
|
27
|
-
"rex-
|
|
26
|
+
"rex-cli.ts",
|
|
28
27
|
"rex-cli.js",
|
|
29
28
|
"rex.ohm",
|
|
30
29
|
"rex.ohm-bundle.cjs",
|
|
31
30
|
"rex.ohm-bundle.js",
|
|
32
31
|
"rex.ohm-bundle.d.ts",
|
|
33
|
-
"rexc-interpreter.ts"
|
|
32
|
+
"rexc-interpreter.ts",
|
|
33
|
+
"rex-repl.ts",
|
|
34
|
+
"rex-repl.js"
|
|
34
35
|
],
|
|
35
36
|
"scripts": {
|
|
36
37
|
"test": "bun test",
|
|
37
38
|
"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-
|
|
39
|
-
"compile": "bun run rex-
|
|
39
|
+
"build:js": "bun build rex.ts --outfile rex.js --format esm --target node && bun build rex-repl.ts --outfile rex-repl.js --format esm --target node && bun build rex-cli.ts --outfile rex-cli.js --format esm --target node && node -e \"const fs=require('fs'),f='rex-cli.js';fs.writeFileSync(f,'#!/usr/bin/env node\\n'+fs.readFileSync(f,'utf8'))\"",
|
|
40
|
+
"compile": "bun run rex-cli.ts",
|
|
40
41
|
"verify:docs": "bun run verify-doc-examples.ts",
|
|
41
42
|
"pack:dry-run": "npm pack --dry-run",
|
|
42
|
-
"prepublishOnly": "bun run build:grammar && bun test && bun run build:js && npm run pack:dry-run"
|
|
43
|
+
"prepublishOnly": "bun run build:grammar && bun test && bun run build:js && npm run pack:dry-run",
|
|
44
|
+
"release": "npm publish"
|
|
43
45
|
},
|
|
44
46
|
"publishConfig": {
|
|
45
47
|
"access": "public"
|