parser-lr 0.8.1 → 0.8.2
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/bin/parser-lr.js +335 -167
- package/bin/parser-lr.js.map +1 -1
- package/dist/lib/grammar/grammar-from-cst.js +4 -2
- package/dist/lib/grammar/grammar-from-cst.js.map +1 -1
- package/dist/lib/grammar/grammar.json +330 -164
- package/docs/grammar.md +29 -0
- package/grammars/grammar.grammar +2 -1
- package/package.json +1 -1
package/docs/grammar.md
CHANGED
|
@@ -98,6 +98,19 @@ expr =
|
|
|
98
98
|
;
|
|
99
99
|
```
|
|
100
100
|
|
|
101
|
+
An explicitly labeled alternative may contain zero factors. It matches the
|
|
102
|
+
empty input while preserving its label as the CST variant:
|
|
103
|
+
|
|
104
|
+
```ebnf
|
|
105
|
+
optional_color =
|
|
106
|
+
#absent
|
|
107
|
+
| #present kw_with expression
|
|
108
|
+
;
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
Zero-factor alternatives must have a label; an unlabeled empty production such
|
|
112
|
+
as `optional_color = ;` is not valid.
|
|
113
|
+
|
|
101
114
|
### Production syntax
|
|
102
115
|
|
|
103
116
|
Each production ends with a semicolon:
|
|
@@ -158,6 +171,22 @@ transform
|
|
|
158
171
|
|
|
159
172
|
`type.#variant` refers to an AST type and variant from the `ast` section. Arguments are binding names from the parse production.
|
|
160
173
|
|
|
174
|
+
Use a build target without parentheses for a zero-argument transform:
|
|
175
|
+
|
|
176
|
+
```ebnf
|
|
177
|
+
ast
|
|
178
|
+
optional_color =
|
|
179
|
+
#absent
|
|
180
|
+
| #present expression
|
|
181
|
+
;
|
|
182
|
+
|
|
183
|
+
transform
|
|
184
|
+
optional_color ->
|
|
185
|
+
#absent optional_color.#absent
|
|
186
|
+
| #present optional_color.#present(expression)
|
|
187
|
+
;
|
|
188
|
+
```
|
|
189
|
+
|
|
161
190
|
Example (calculator):
|
|
162
191
|
|
|
163
192
|
```ebnf
|
package/grammars/grammar.grammar
CHANGED
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "parser-lr",
|
|
3
3
|
"author": "Adam R Moss <adamrmoss@gmail.com>",
|
|
4
|
-
"version": "0.8.
|
|
4
|
+
"version": "0.8.2",
|
|
5
5
|
"description": "Shift-reduce parser library for EBNF grammars with LR table generation, lexing, and CST-to-AST transforms",
|
|
6
6
|
"keywords": [
|
|
7
7
|
"ast",
|