parser-lr 0.3.0 → 0.4.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 +6 -6
- package/bin/parser-lr.js +4255 -3171
- package/bin/parser-lr.js.map +1 -1
- package/dist/lib/grammar/grammar.json +4410 -3342
- package/dist/lib/parse-context.d.ts +6 -6
- package/dist/lib/parse-context.js +6 -6
- package/dist/lib/parse-table/parse-table-json.d.ts +4 -0
- package/dist/lib/parse-table/parse-table-json.d.ts.map +1 -1
- package/dist/lib/parse-table/parse-table-json.js.map +1 -1
- package/dist/lib/parse-table/parse-table.d.ts +13 -3
- package/dist/lib/parse-table/parse-table.d.ts.map +1 -1
- package/dist/lib/parse-table/parse-table.js +22 -6
- package/dist/lib/parse-table/parse-table.js.map +1 -1
- package/dist/lib/parser-lr.d.ts +2 -2
- package/dist/lib/parser-lr.js +2 -2
- package/docs/grammar.md +2 -2
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -34,7 +34,7 @@ You can then run `parser-lr` from any directory. Without linking, use `npx parse
|
|
|
34
34
|
Generate a serialized LR table from a grammar file:
|
|
35
35
|
|
|
36
36
|
```bash
|
|
37
|
-
parser-lr table generate -g mylang.grammar -o mylang.
|
|
37
|
+
parser-lr table generate -g mylang.grammar -o mylang.json
|
|
38
38
|
```
|
|
39
39
|
|
|
40
40
|
Options:
|
|
@@ -45,7 +45,7 @@ Options:
|
|
|
45
45
|
| `-o, --output <path>` | Output path (default: stdout) |
|
|
46
46
|
| `-a, --algorithm <name>` | `lr0`, `slr`, `lalr`, or `lr1` (default: `lr1`) |
|
|
47
47
|
|
|
48
|
-
The JSON
|
|
48
|
+
The JSON file is self-contained: lexer rules, skip rules, the full ACTION/GOTO table, and when the grammar defines them, `ast` and `transform` sections for CST-to-AST mapping. Ship this file without the original `.grammar`.
|
|
49
49
|
|
|
50
50
|
### Parse a source file
|
|
51
51
|
|
|
@@ -53,7 +53,7 @@ Parse input using either the grammar (table built in memory) or a saved table:
|
|
|
53
53
|
|
|
54
54
|
```bash
|
|
55
55
|
parser-lr parse -i program.txt -g mylang.grammar
|
|
56
|
-
parser-lr parse -i program.txt -t mylang.
|
|
56
|
+
parser-lr parse -i program.txt -t mylang.json
|
|
57
57
|
```
|
|
58
58
|
|
|
59
59
|
Options:
|
|
@@ -68,7 +68,7 @@ Options:
|
|
|
68
68
|
|
|
69
69
|
Output is a JSON object `{ "ast": … }`. On a syntax error, `ast` is `null`.
|
|
70
70
|
|
|
71
|
-
|
|
71
|
+
`parse` applies CST-to-AST transforms when the grammar or table JSON defines `transform` rules.
|
|
72
72
|
|
|
73
73
|
## Library
|
|
74
74
|
|
|
@@ -91,11 +91,11 @@ Load a pre-built table instead of a grammar file:
|
|
|
91
91
|
import { readFile } from 'node:fs/promises';
|
|
92
92
|
import { ParseContext } from 'parser-lr';
|
|
93
93
|
|
|
94
|
-
const tableJson = await readFile('mylang.
|
|
94
|
+
const tableJson = await readFile('mylang.json', 'utf8');
|
|
95
95
|
const context = ParseContext.fromTableJson(tableJson);
|
|
96
96
|
|
|
97
97
|
const source = await readFile('program.txt', 'utf8');
|
|
98
|
-
const ast = context.
|
|
98
|
+
const ast = context.parseSource(source);
|
|
99
99
|
```
|
|
100
100
|
|
|
101
101
|
`ParseContext` exposes `lex`, `parse`, and `createLexer` for finer control. See the [library API overview](https://github.com/adamrmoss/parser-lr/blob/main/src/lib/README.md).
|