parseman 0.50.5 → 0.50.7
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/dist/analysis/diagnostics.js +49 -46
- package/dist/analysis/diagnostics.js.map +2 -2
- package/dist/cli/index.js +49 -46
- package/dist/cli/index.js.map +2 -2
- package/dist/combinators/first-set.d.ts +2 -26
- package/dist/combinators/first-set.d.ts.map +1 -1
- package/dist/compiler/token-capability.js +38 -27
- package/dist/compiler/token-capability.js.map +1 -1
- package/dist/index.js +50 -47
- package/dist/index.js.map +2 -2
- package/dist/plugin/evaluator.d.ts.map +1 -1
- package/dist/plugin/index.js +53 -47
- package/dist/plugin/index.js.map +2 -2
- package/dist/spec/index.js +37 -36
- package/dist/spec/index.js.map +2 -2
- package/dist/table/encode.d.ts.map +1 -1
- package/dist/table/index.js +49 -46
- package/dist/table/index.js.map +2 -2
- package/dist/version.d.ts +1 -1
- package/package.json +1 -1
- package/src/combinators/first-set.ts +58 -36
- package/src/plugin/evaluator.ts +13 -0
- package/src/table/encode.ts +10 -8
- package/src/version.ts +1 -1
package/dist/spec/index.js
CHANGED
|
@@ -31,7 +31,7 @@ function intersects(a, b) {
|
|
|
31
31
|
return false;
|
|
32
32
|
}
|
|
33
33
|
function fromChar(code) {
|
|
34
|
-
return
|
|
34
|
+
return fromRange(code, code);
|
|
35
35
|
}
|
|
36
36
|
function startsFirstSet(combinator, input, pos) {
|
|
37
37
|
const fs = combinator._meta.firstSet;
|
|
@@ -124,11 +124,10 @@ function matchesEmptyBody(p, seen, resolve) {
|
|
|
124
124
|
}
|
|
125
125
|
}
|
|
126
126
|
function isZeroWidthAssertion(p) {
|
|
127
|
-
|
|
128
|
-
return tag === "not" || tag === "adjacency";
|
|
127
|
+
return p._tag === "not" || p._tag === "adjacency";
|
|
129
128
|
}
|
|
130
129
|
function isPositiveLookahead(p) {
|
|
131
|
-
return p.
|
|
130
|
+
return p._tag === "peek";
|
|
132
131
|
}
|
|
133
132
|
function narrowBy(acc, constraint) {
|
|
134
133
|
if (constraint.kind === "any") return acc;
|
|
@@ -144,34 +143,42 @@ function narrowBy(acc, constraint) {
|
|
|
144
143
|
return ranges.length === 0 ? { kind: "empty" } : { kind: "ranges", ranges };
|
|
145
144
|
}
|
|
146
145
|
function applyAssertion(fs, assertion) {
|
|
147
|
-
|
|
148
|
-
if (fs.kind === "empty") return assertion;
|
|
149
|
-
return narrowBy(fs, assertion) ?? fs;
|
|
146
|
+
return assertion === null ? fs : fs.kind === "empty" ? assertion : narrowBy(fs, assertion);
|
|
150
147
|
}
|
|
151
|
-
function
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
148
|
+
function sequenceSet(parsers, fs, empties, trivia2) {
|
|
149
|
+
const afterBoundary = (i) => {
|
|
150
|
+
const rest = at(i);
|
|
151
|
+
return trivia2 ? union(rest, fs(trivia2)) : rest;
|
|
152
|
+
};
|
|
153
|
+
const at = (i) => {
|
|
154
|
+
const p = parsers[i];
|
|
155
155
|
if (isPositiveLookahead(p)) {
|
|
156
|
-
|
|
157
|
-
|
|
156
|
+
const constraint = fs(p);
|
|
157
|
+
return i + 1 === parsers.length ? constraint : applyAssertion(afterBoundary(i + 1), constraint);
|
|
158
158
|
}
|
|
159
|
-
if (
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
159
|
+
if (isZeroWidthAssertion(p)) {
|
|
160
|
+
return i + 1 === parsers.length ? empty() : afterBoundary(i + 1);
|
|
161
|
+
}
|
|
162
|
+
const first = fs(p);
|
|
163
|
+
if (!empties(p) || i + 1 === parsers.length) return first;
|
|
164
|
+
return union(first, afterBoundary(i + 1));
|
|
165
|
+
};
|
|
166
|
+
return at(0);
|
|
163
167
|
}
|
|
164
|
-
function
|
|
168
|
+
function sequenceFirstSet(parsers) {
|
|
169
|
+
return sequenceSet(parsers, (p) => p._meta.firstSet, matchesEmpty);
|
|
170
|
+
}
|
|
171
|
+
function firstSetOf(p, seen = /* @__PURE__ */ new Set(), resolve, activeTrivia) {
|
|
165
172
|
if (seen.has(p)) return any();
|
|
166
173
|
seen.add(p);
|
|
167
174
|
try {
|
|
168
|
-
return firstSetBody(p, seen, resolve);
|
|
175
|
+
return firstSetBody(p, seen, resolve, activeTrivia);
|
|
169
176
|
} finally {
|
|
170
177
|
seen.delete(p);
|
|
171
178
|
}
|
|
172
179
|
}
|
|
173
|
-
function firstSetBody(p, seen, resolve) {
|
|
174
|
-
const fs = (c) => firstSetOf(c, seen, resolve);
|
|
180
|
+
function firstSetBody(p, seen, resolve, activeTrivia) {
|
|
181
|
+
const fs = (c) => firstSetOf(c, seen, resolve, activeTrivia);
|
|
175
182
|
const empties = (c) => matchesEmpty(c, /* @__PURE__ */ new Set(), resolve);
|
|
176
183
|
const d = p._def;
|
|
177
184
|
switch (d.tag) {
|
|
@@ -197,17 +204,7 @@ function firstSetBody(p, seen, resolve) {
|
|
|
197
204
|
return out;
|
|
198
205
|
}
|
|
199
206
|
case "sequence": {
|
|
200
|
-
|
|
201
|
-
let assertion = null;
|
|
202
|
-
for (const term of d.parsers) {
|
|
203
|
-
if (isPositiveLookahead(term)) {
|
|
204
|
-
assertion = narrowBy(assertion, fs(term));
|
|
205
|
-
continue;
|
|
206
|
-
}
|
|
207
|
-
if (!isZeroWidthAssertion(term)) out = union(out, fs(term));
|
|
208
|
-
if (!empties(term)) return applyAssertion(out, assertion);
|
|
209
|
-
}
|
|
210
|
-
return applyAssertion(out, assertion);
|
|
207
|
+
return sequenceSet(d.parsers, fs, empties, activeTrivia);
|
|
211
208
|
}
|
|
212
209
|
case "peek": {
|
|
213
210
|
const inner = d.parser;
|
|
@@ -222,12 +219,16 @@ function firstSetBody(p, seen, resolve) {
|
|
|
222
219
|
case "token":
|
|
223
220
|
case "leaf":
|
|
224
221
|
case "node":
|
|
225
|
-
case "grammar":
|
|
226
|
-
case "expect":
|
|
227
|
-
return fs(d.parser);
|
|
228
222
|
case "sepBy":
|
|
223
|
+
case "expect":
|
|
229
224
|
return fs(d.parser);
|
|
230
|
-
|
|
225
|
+
case "grammar":
|
|
226
|
+
return firstSetOf(
|
|
227
|
+
d.parser,
|
|
228
|
+
seen,
|
|
229
|
+
resolve,
|
|
230
|
+
d.clearTrivia ? null : d.triviaParser ?? activeTrivia
|
|
231
|
+
);
|
|
231
232
|
default:
|
|
232
233
|
return p._meta.firstSet;
|
|
233
234
|
}
|