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 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.table.json
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 table includes lexer token rules, skip rules, and the full ACTION/GOTO table. You can ship this file without the original grammar.
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.table.json
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
- When the grammar defines `ast` and `transform` sections, the CLI applies CST-to-AST transforms and returns the abstract tree.
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.table.json', 'utf8');
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.parse(context.lex(source));
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).