@thomasfosterau/effect-parse 0.1.0 → 0.2.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 +247 -230
- package/dist/Ascii.d.ts +32 -53
- package/dist/Ascii.d.ts.map +1 -1
- package/dist/Ascii.js +576 -571
- package/dist/Ascii.js.map +1 -1
- package/dist/Binary.d.ts +6 -29
- package/dist/Binary.d.ts.map +1 -1
- package/dist/Binary.js +129 -116
- package/dist/Binary.js.map +1 -1
- package/dist/Bits.d.ts +4 -2
- package/dist/Bits.d.ts.map +1 -1
- package/dist/Bits.js +121 -123
- package/dist/Bits.js.map +1 -1
- package/dist/Compiler.d.ts +39 -0
- package/dist/Compiler.d.ts.map +1 -0
- package/dist/Compiler.js +48 -0
- package/dist/Compiler.js.map +1 -0
- package/dist/Encoding.d.ts +29 -46
- package/dist/Encoding.d.ts.map +1 -1
- package/dist/Encoding.js +76 -75
- package/dist/Encoding.js.map +1 -1
- package/dist/Expression.d.ts +15 -49
- package/dist/Expression.d.ts.map +1 -1
- package/dist/Expression.js +143 -131
- package/dist/Expression.js.map +1 -1
- package/dist/Input.d.ts +206 -177
- package/dist/Input.d.ts.map +1 -1
- package/dist/Input.js +317 -299
- package/dist/Input.js.map +1 -1
- package/dist/Nom.d.ts +44 -84
- package/dist/Nom.d.ts.map +1 -1
- package/dist/Nom.js +423 -453
- package/dist/Nom.js.map +1 -1
- package/dist/ParseError.d.ts +54 -49
- package/dist/ParseError.d.ts.map +1 -1
- package/dist/ParseError.js +233 -275
- package/dist/ParseError.js.map +1 -1
- package/dist/Parser.d.ts +345 -313
- package/dist/Parser.d.ts.map +1 -1
- package/dist/Parser.js +2010 -1802
- package/dist/Parser.js.map +1 -1
- package/dist/ParserSchema.d.ts +8 -7
- package/dist/ParserSchema.d.ts.map +1 -1
- package/dist/ParserSchema.js +49 -49
- package/dist/ParserSchema.js.map +1 -1
- package/dist/ParserStream.d.ts +26 -20
- package/dist/ParserStream.d.ts.map +1 -1
- package/dist/ParserStream.js +267 -255
- package/dist/ParserStream.js.map +1 -1
- package/dist/Syntax.d.ts +401 -0
- package/dist/Syntax.d.ts.map +1 -0
- package/dist/Syntax.js +717 -0
- package/dist/Syntax.js.map +1 -0
- package/dist/Text.d.ts +98 -134
- package/dist/Text.d.ts.map +1 -1
- package/dist/Text.js +534 -496
- package/dist/Text.js.map +1 -1
- package/dist/Token.d.ts +60 -42
- package/dist/Token.d.ts.map +1 -1
- package/dist/Token.js +331 -265
- package/dist/Token.js.map +1 -1
- package/dist/index.d.ts +16 -17
- package/dist/index.js +16 -17
- package/dist/internal/compiler/closure.d.ts +14 -16
- package/dist/internal/compiler/closure.d.ts.map +1 -1
- package/dist/internal/compiler/closure.js +1458 -1637
- package/dist/internal/compiler/closure.js.map +1 -1
- package/dist/internal/compiler/entries.d.ts +11 -11
- package/dist/internal/compiler/entries.d.ts.map +1 -1
- package/dist/internal/compiler/entries.js +36 -26
- package/dist/internal/compiler/entries.js.map +1 -1
- package/dist/internal/compiler/first.d.ts +19 -19
- package/dist/internal/compiler/first.d.ts.map +1 -1
- package/dist/internal/compiler/first.js +251 -227
- package/dist/internal/compiler/first.js.map +1 -1
- package/dist/internal/compiler/jit.d.ts +6 -17
- package/dist/internal/compiler/jit.d.ts.map +1 -1
- package/dist/internal/compiler/jit.js +860 -988
- package/dist/internal/compiler/jit.js.map +1 -1
- package/dist/internal/compiler/registry.d.ts +20 -21
- package/dist/internal/compiler/registry.d.ts.map +1 -1
- package/dist/internal/compiler/registry.js +21 -41
- package/dist/internal/compiler/registry.js.map +1 -1
- package/dist/internal/compiler/sets.d.ts +9 -13
- package/dist/internal/compiler/sets.d.ts.map +1 -1
- package/dist/internal/compiler/sets.js +76 -73
- package/dist/internal/compiler/sets.js.map +1 -1
- package/dist/internal/entries.d.ts +3 -3
- package/dist/internal/entries.d.ts.map +1 -1
- package/dist/internal/entries.js +38 -30
- package/dist/internal/entries.js.map +1 -1
- package/dist/internal/node.d.ts +177 -173
- package/dist/internal/node.d.ts.map +1 -1
- package/dist/internal/node.js +77 -66
- package/dist/internal/node.js.map +1 -1
- package/dist/internal/numbers.d.ts +7 -8
- package/dist/internal/numbers.d.ts.map +1 -1
- package/dist/internal/numbers.js +246 -276
- package/dist/internal/numbers.js.map +1 -1
- package/dist/internal/resume.d.ts +6 -24
- package/dist/internal/resume.d.ts.map +1 -1
- package/dist/internal/resume.js +30 -29
- package/dist/internal/resume.js.map +1 -1
- package/dist/internal/run.d.ts +15 -0
- package/dist/internal/run.d.ts.map +1 -0
- package/dist/internal/run.js +36 -0
- package/dist/internal/run.js.map +1 -0
- package/dist/internal/stack.d.ts +16 -0
- package/dist/internal/stack.d.ts.map +1 -0
- package/dist/internal/stack.js +26 -0
- package/dist/internal/stack.js.map +1 -0
- package/dist/internal/syntax.d.ts +146 -0
- package/dist/internal/syntax.d.ts.map +1 -0
- package/dist/internal/syntax.js +305 -0
- package/dist/internal/syntax.js.map +1 -0
- package/dist/internal/text.d.ts +10 -2
- package/dist/internal/text.d.ts.map +1 -1
- package/dist/internal/text.js +295 -345
- package/dist/internal/text.js.map +1 -1
- package/dist/internal/tokens.d.ts +25 -30
- package/dist/internal/tokens.d.ts.map +1 -1
- package/dist/internal/tokens.js +369 -363
- package/dist/internal/tokens.js.map +1 -1
- package/package.json +42 -28
- package/src/Ascii.ts +278 -187
- package/src/Binary.ts +150 -44
- package/src/Bits.ts +6 -3
- package/src/Compiler.ts +98 -0
- package/src/Expression.ts +10 -5
- package/src/Input.ts +106 -28
- package/src/Nom.ts +4 -3
- package/src/ParseError.ts +48 -51
- package/src/Parser.ts +1163 -795
- package/src/ParserStream.ts +104 -80
- package/src/Syntax.ts +900 -0
- package/src/Text.ts +272 -187
- package/src/Token.ts +180 -87
- package/src/index.ts +2 -0
- package/src/internal/compiler/closure.ts +121 -88
- package/src/internal/compiler/entries.ts +21 -8
- package/src/internal/compiler/first.ts +17 -15
- package/src/internal/compiler/jit.ts +360 -157
- package/src/internal/compiler/registry.ts +12 -33
- package/src/internal/compiler/sets.ts +17 -11
- package/src/internal/entries.ts +4 -2
- package/src/internal/node.ts +51 -37
- package/src/internal/numbers.ts +22 -20
- package/src/internal/resume.ts +8 -4
- package/src/internal/run.ts +41 -0
- package/src/internal/stack.ts +36 -0
- package/src/internal/syntax.ts +421 -0
- package/src/internal/text.ts +32 -25
- package/src/internal/tokens.ts +96 -51
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js.map +0 -1
|
@@ -0,0 +1,305 @@
|
|
|
1
|
+
import * as Predicate from "effect/Predicate";
|
|
2
|
+
import { Fail, Failure, State } from "../Input.js";
|
|
3
|
+
//#region src/internal/syntax.ts
|
|
4
|
+
/**
|
|
5
|
+
* The tree builder behind the `Syntax` module (see `docs/DESIGN.md`,
|
|
6
|
+
* "Syntax trees").
|
|
7
|
+
*
|
|
8
|
+
* Trees are stored as *green* nodes, as in Roslyn and rust-analyzer: a green
|
|
9
|
+
* node knows its kind, its width and its children's offsets relative to its
|
|
10
|
+
* own start, but not where it is in the input or who its parent is. A subtree
|
|
11
|
+
* that an edit doesn't touch can therefore be shared, unchanged, by the tree
|
|
12
|
+
* before the edit and the tree after it. `Syntax.SyntaxNode` is the *red*
|
|
13
|
+
* view: a green node, its absolute start and its parent, built lazily while
|
|
14
|
+
* navigating.
|
|
15
|
+
*
|
|
16
|
+
* While parsing, completed nodes wait on a stack until the node around them
|
|
17
|
+
* completes and adopts them. Nodes built by an attempt that is later
|
|
18
|
+
* abandoned must not end up in the tree. Every combinator that abandons an
|
|
19
|
+
* attempt moves the cursor back to (or before) where the attempt started,
|
|
20
|
+
* and every node has a positive width, so the nodes of an abandoned attempt
|
|
21
|
+
* are exactly those that end after the position the cursor moves back to:
|
|
22
|
+
* the `pos` setter of {@link SyntaxState} drops them. This also covers
|
|
23
|
+
* lookahead (`peek`, `not`) and custom parsers written with `Parser.make`.
|
|
24
|
+
*
|
|
25
|
+
* For incremental parsing, every node records how far its parse looked: the
|
|
26
|
+
* furthest position the cursor reached and the furthest failure recorded
|
|
27
|
+
* while it was being parsed (its *lookahead*). A node from the previous tree
|
|
28
|
+
* is reused at a position when it was built by the same `Syntax.node`, and
|
|
29
|
+
* the input it looked at, plus a margin for the tokens that read a little
|
|
30
|
+
* past where they stop, is unchanged.
|
|
31
|
+
*/
|
|
32
|
+
/** A position-independent syntax tree node. */
|
|
33
|
+
var Green = class {
|
|
34
|
+
kind;
|
|
35
|
+
named;
|
|
36
|
+
key;
|
|
37
|
+
width;
|
|
38
|
+
lookahead;
|
|
39
|
+
children;
|
|
40
|
+
offsets;
|
|
41
|
+
fields;
|
|
42
|
+
value;
|
|
43
|
+
error;
|
|
44
|
+
hasError;
|
|
45
|
+
diagnostics;
|
|
46
|
+
constructor(kind, named, key, width, lookahead, children, offsets, fields, value, error, hasError, diagnostics) {
|
|
47
|
+
this.kind = kind;
|
|
48
|
+
this.named = named;
|
|
49
|
+
this.key = key;
|
|
50
|
+
this.width = width;
|
|
51
|
+
this.lookahead = lookahead;
|
|
52
|
+
this.children = children;
|
|
53
|
+
this.offsets = offsets;
|
|
54
|
+
this.fields = fields;
|
|
55
|
+
this.value = value;
|
|
56
|
+
this.error = error;
|
|
57
|
+
this.hasError = hasError;
|
|
58
|
+
this.diagnostics = diagnostics;
|
|
59
|
+
}
|
|
60
|
+
};
|
|
61
|
+
/** A completed node waiting for its parent, at an absolute position. */
|
|
62
|
+
var Child = class {
|
|
63
|
+
green;
|
|
64
|
+
start;
|
|
65
|
+
end;
|
|
66
|
+
field;
|
|
67
|
+
constructor(green, start, end, field) {
|
|
68
|
+
this.green = green;
|
|
69
|
+
this.start = start;
|
|
70
|
+
this.end = end;
|
|
71
|
+
this.field = field;
|
|
72
|
+
}
|
|
73
|
+
};
|
|
74
|
+
const errorKind = "ERROR";
|
|
75
|
+
const rebase = (f, start) => new Failure(f.offset - start, f.kind, f.expected, f.context, f.hasCause, f.cause, f.message, f.needed);
|
|
76
|
+
/** Moves a failure stored relative to a node back to absolute offsets. */
|
|
77
|
+
const absolute = (f, start) => rebase(f, -start);
|
|
78
|
+
/**
|
|
79
|
+
* Builds a green node over `[start, end)` from the children waiting on the
|
|
80
|
+
* stack.
|
|
81
|
+
*/
|
|
82
|
+
const build = (kind, named, key, start, end, lookahead, entries, value, error, diagnostics) => {
|
|
83
|
+
const n = entries.length;
|
|
84
|
+
const children = new Array(n);
|
|
85
|
+
const offsets = new Array(n);
|
|
86
|
+
let fields;
|
|
87
|
+
let hasError = error !== void 0;
|
|
88
|
+
for (let i = 0; i < n; i++) {
|
|
89
|
+
const e = entries[i];
|
|
90
|
+
children[i] = e.green;
|
|
91
|
+
offsets[i] = e.start - start;
|
|
92
|
+
if (e.green.hasError) hasError = true;
|
|
93
|
+
if (e.field !== void 0) (fields ??= new Array(n).fill(void 0))[i] = e.field;
|
|
94
|
+
}
|
|
95
|
+
return new Green(kind, named, key, end - start, Math.max(lookahead, end) - start, children, offsets, fields, value, error, hasError, diagnostics);
|
|
96
|
+
};
|
|
97
|
+
/** The parse state of a `Syntax` parse. */
|
|
98
|
+
var SyntaxState = class extends State {
|
|
99
|
+
static {
|
|
100
|
+
Object.defineProperty(this.prototype, "pos", {
|
|
101
|
+
get() {
|
|
102
|
+
return this.cursor;
|
|
103
|
+
},
|
|
104
|
+
set(p) {
|
|
105
|
+
if (p < this.cursor) {
|
|
106
|
+
const stack = this.stack;
|
|
107
|
+
while (stack.length > 0 && stack[stack.length - 1].end > p) stack.pop();
|
|
108
|
+
}
|
|
109
|
+
if (p > this.highWater) this.highWater = p;
|
|
110
|
+
this.cursor = p;
|
|
111
|
+
},
|
|
112
|
+
configurable: true,
|
|
113
|
+
enumerable: true
|
|
114
|
+
});
|
|
115
|
+
}
|
|
116
|
+
constructor(source, options, previous) {
|
|
117
|
+
super(source, { context: options.context });
|
|
118
|
+
this.highWater = this.cursor;
|
|
119
|
+
this.stack = [];
|
|
120
|
+
this.previous = previous;
|
|
121
|
+
this.reused = 0;
|
|
122
|
+
this.lastParent = void 0;
|
|
123
|
+
this.lastParentStart = 0;
|
|
124
|
+
this.syntax = this;
|
|
125
|
+
this.recovered = [];
|
|
126
|
+
}
|
|
127
|
+
failWith(mode, failure) {
|
|
128
|
+
if (failure.offset > this.highWater) this.highWater = failure.offset;
|
|
129
|
+
return super.failWith(mode, failure);
|
|
130
|
+
}
|
|
131
|
+
setHint(offset, expected) {
|
|
132
|
+
if (offset > this.highWater) this.highWater = offset;
|
|
133
|
+
super.setHint(offset, expected);
|
|
134
|
+
}
|
|
135
|
+
node(state, step, key, kind, named) {
|
|
136
|
+
const start = this.cursor;
|
|
137
|
+
const stack = this.stack;
|
|
138
|
+
if (this.previous !== void 0) {
|
|
139
|
+
const green = this.reusable(this.previous, key, start);
|
|
140
|
+
if (green !== void 0) {
|
|
141
|
+
this.reused++;
|
|
142
|
+
const end = start + green.width;
|
|
143
|
+
state.pos = end;
|
|
144
|
+
const looked = start + green.lookahead;
|
|
145
|
+
if (looked > this.highWater) this.highWater = looked;
|
|
146
|
+
const d = green.diagnostics;
|
|
147
|
+
if (d !== void 0) {
|
|
148
|
+
if (d.deepest !== void 0) this.deepen(start === d.base ? d.deepest : rebase(d.deepest, d.base - start));
|
|
149
|
+
if (d.hintExpected !== void 0) this.setHint(start + d.hintOffset, d.hintExpected);
|
|
150
|
+
}
|
|
151
|
+
stack.push(new Child(green, start, end, void 0));
|
|
152
|
+
return green.value;
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
const mark = stack.length;
|
|
156
|
+
const outer = this.highWater;
|
|
157
|
+
const outerDeepest = this.deepest;
|
|
158
|
+
const hintOffset = this.hintOffset;
|
|
159
|
+
const hintExpected = this.hintExpected;
|
|
160
|
+
this.highWater = start;
|
|
161
|
+
this.deepest = void 0;
|
|
162
|
+
const a = step(state);
|
|
163
|
+
const looked = this.highWater;
|
|
164
|
+
if (outer > looked) this.highWater = outer;
|
|
165
|
+
const deepest = this.deepest;
|
|
166
|
+
this.deepest = outerDeepest;
|
|
167
|
+
if (deepest !== void 0) this.deepen(deepest);
|
|
168
|
+
if (a === Fail) {
|
|
169
|
+
if (stack.length > mark) stack.length = mark;
|
|
170
|
+
return a;
|
|
171
|
+
}
|
|
172
|
+
const end = this.cursor;
|
|
173
|
+
if (end === start) return a;
|
|
174
|
+
const hinted = this.hintOffset !== hintOffset || this.hintExpected !== hintExpected;
|
|
175
|
+
const diagnostics = deepest === void 0 && !hinted ? void 0 : {
|
|
176
|
+
deepest,
|
|
177
|
+
base: start,
|
|
178
|
+
hintOffset: this.hintOffset - start,
|
|
179
|
+
hintExpected: hinted ? this.hintExpected : void 0
|
|
180
|
+
};
|
|
181
|
+
const entries = stack.splice(mark);
|
|
182
|
+
stack.push(new Child(build(kind, named, key, start, end, looked, entries, a, void 0, diagnostics), start, end, void 0));
|
|
183
|
+
return a;
|
|
184
|
+
}
|
|
185
|
+
read(end) {
|
|
186
|
+
if (end - 1 > this.highWater) this.highWater = end - 1;
|
|
187
|
+
}
|
|
188
|
+
/** Records `failure` as the furthest failure if it is, as `failWith` does. */
|
|
189
|
+
deepen(failure) {
|
|
190
|
+
if (this.deepest === void 0 || failure.offset >= this.deepest.offset) this.deepest = failure;
|
|
191
|
+
}
|
|
192
|
+
field(state, step, name) {
|
|
193
|
+
const stack = this.stack;
|
|
194
|
+
const mark = stack.length;
|
|
195
|
+
const a = step(state);
|
|
196
|
+
if (a !== Fail) for (let i = mark; i < stack.length; i++) stack[i].field = name;
|
|
197
|
+
return a;
|
|
198
|
+
}
|
|
199
|
+
skipped(start, failure, mode) {
|
|
200
|
+
const stack = this.stack;
|
|
201
|
+
let i = stack.length;
|
|
202
|
+
while (i > 0 && stack[i - 1].start >= start && stack[i - 1].end > start) i--;
|
|
203
|
+
const end = this.cursor;
|
|
204
|
+
const green = build(errorKind, true, void 0, start, end, this.highWater, stack.splice(i), void 0, {
|
|
205
|
+
failure: rebase(failure, start),
|
|
206
|
+
mode
|
|
207
|
+
});
|
|
208
|
+
stack.push(new Child(green, start, end, void 0));
|
|
209
|
+
}
|
|
210
|
+
/**
|
|
211
|
+
* Builds the root over the whole input from the nodes left on the stack.
|
|
212
|
+
* When the parse failed, or stopped before the end, the rest of the input
|
|
213
|
+
* becomes an `ERROR` node.
|
|
214
|
+
*/
|
|
215
|
+
finish(kind, value, fatal, errorStart) {
|
|
216
|
+
const entries = this.stack.splice(0);
|
|
217
|
+
const end = this.end;
|
|
218
|
+
if (fatal !== void 0) {
|
|
219
|
+
const last = entries.length > 0 ? entries[entries.length - 1].end : 0;
|
|
220
|
+
const start = Math.max(Math.min(errorStart, end), last);
|
|
221
|
+
const error = build(errorKind, true, void 0, start, end, end, [], void 0, {
|
|
222
|
+
failure: rebase(fatal.failure, start),
|
|
223
|
+
mode: fatal.mode
|
|
224
|
+
});
|
|
225
|
+
entries.push(new Child(error, start, end, void 0));
|
|
226
|
+
}
|
|
227
|
+
return build(kind, true, void 0, 0, end, Math.max(end, this.highWater), entries, value, void 0);
|
|
228
|
+
}
|
|
229
|
+
/**
|
|
230
|
+
* The outermost node of the previous tree built by `key` that starts at
|
|
231
|
+
* `offset`. Reused nodes are mostly siblings, found one after the other,
|
|
232
|
+
* so the search starts from the parent of the last one found when
|
|
233
|
+
* `offset` lies inside it: no ancestor of that parent can start there.
|
|
234
|
+
*/
|
|
235
|
+
find(root, offset, key) {
|
|
236
|
+
let node = root;
|
|
237
|
+
let start = 0;
|
|
238
|
+
const last = this.lastParent;
|
|
239
|
+
if (last !== void 0 && offset > this.lastParentStart && offset < this.lastParentStart + last.width) {
|
|
240
|
+
node = last;
|
|
241
|
+
start = this.lastParentStart;
|
|
242
|
+
}
|
|
243
|
+
while (true) {
|
|
244
|
+
const offsets = node.offsets;
|
|
245
|
+
let lo = 0;
|
|
246
|
+
let hi = offsets.length - 1;
|
|
247
|
+
let found = -1;
|
|
248
|
+
while (lo <= hi) {
|
|
249
|
+
const mid = lo + hi >> 1;
|
|
250
|
+
if (start + offsets[mid] <= offset) {
|
|
251
|
+
found = mid;
|
|
252
|
+
lo = mid + 1;
|
|
253
|
+
} else hi = mid - 1;
|
|
254
|
+
}
|
|
255
|
+
if (found < 0) return void 0;
|
|
256
|
+
const child = node.children[found];
|
|
257
|
+
const childStart = start + offsets[found];
|
|
258
|
+
if (offset >= childStart + child.width) return void 0;
|
|
259
|
+
if (childStart === offset && child.key === key) {
|
|
260
|
+
this.lastParent = node;
|
|
261
|
+
this.lastParentStart = start;
|
|
262
|
+
return child;
|
|
263
|
+
}
|
|
264
|
+
node = child;
|
|
265
|
+
start = childStart;
|
|
266
|
+
}
|
|
267
|
+
}
|
|
268
|
+
/** The node of the previous tree built by `key` at `pos` (in the new input), if it can be reused. */
|
|
269
|
+
reusable(previous, key, pos) {
|
|
270
|
+
const segments = previous.segments;
|
|
271
|
+
let lo = 0;
|
|
272
|
+
let hi = segments.length - 1;
|
|
273
|
+
while (lo <= hi) {
|
|
274
|
+
const mid = lo + hi >> 1;
|
|
275
|
+
const seg = segments[mid];
|
|
276
|
+
if (pos < seg.newStart) hi = mid - 1;
|
|
277
|
+
else if (pos >= seg.newStart + seg.length) lo = mid + 1;
|
|
278
|
+
else {
|
|
279
|
+
const old = seg.oldStart + (pos - seg.newStart);
|
|
280
|
+
const green = this.find(previous.root, old, key);
|
|
281
|
+
if (green === void 0) return void 0;
|
|
282
|
+
const segEnd = seg.oldStart + seg.length;
|
|
283
|
+
if (old + green.lookahead + tokenWidth(previous.input, old + green.lookahead) + previous.extra <= segEnd) return green;
|
|
284
|
+
if (segEnd === previous.oldLength && seg.newStart + seg.length === previous.newLength) return green;
|
|
285
|
+
return;
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
}
|
|
289
|
+
};
|
|
290
|
+
/**
|
|
291
|
+
* How many units a token parser may read at `offset`, where a parse
|
|
292
|
+
* stopped looking: one code point. Of a string, that is two units at a high
|
|
293
|
+
* surrogate. Of bytes in an unknown encoding, up to four.
|
|
294
|
+
*/
|
|
295
|
+
const tokenWidth = (input, offset) => {
|
|
296
|
+
if (Predicate.isString(input)) {
|
|
297
|
+
const c = input.charCodeAt(offset);
|
|
298
|
+
return c >= 55296 && c <= 56319 ? 2 : 1;
|
|
299
|
+
}
|
|
300
|
+
return input instanceof Uint8Array ? 4 : 1;
|
|
301
|
+
};
|
|
302
|
+
//#endregion
|
|
303
|
+
export { Green, SyntaxState, absolute, errorKind };
|
|
304
|
+
|
|
305
|
+
//# sourceMappingURL=syntax.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"syntax.js","names":[],"sources":["../../src/internal/syntax.ts"],"sourcesContent":["/**\n * The tree builder behind the `Syntax` module (see `docs/DESIGN.md`,\n * \"Syntax trees\").\n *\n * Trees are stored as *green* nodes, as in Roslyn and rust-analyzer: a green\n * node knows its kind, its width and its children's offsets relative to its\n * own start, but not where it is in the input or who its parent is. A subtree\n * that an edit doesn't touch can therefore be shared, unchanged, by the tree\n * before the edit and the tree after it. `Syntax.SyntaxNode` is the *red*\n * view: a green node, its absolute start and its parent, built lazily while\n * navigating.\n *\n * While parsing, completed nodes wait on a stack until the node around them\n * completes and adopts them. Nodes built by an attempt that is later\n * abandoned must not end up in the tree. Every combinator that abandons an\n * attempt moves the cursor back to (or before) where the attempt started,\n * and every node has a positive width, so the nodes of an abandoned attempt\n * are exactly those that end after the position the cursor moves back to:\n * the `pos` setter of {@link SyntaxState} drops them. This also covers\n * lookahead (`peek`, `not`) and custom parsers written with `Parser.make`.\n *\n * For incremental parsing, every node records how far its parse looked: the\n * furthest position the cursor reached and the furthest failure recorded\n * while it was being parsed (its *lookahead*). A node from the previous tree\n * is reused at a position when it was built by the same `Syntax.node`, and\n * the input it looked at, plus a margin for the tokens that read a little\n * past where they stop, is unchanged.\n */\nimport * as Predicate from \"effect/Predicate\"\nimport type * as Context from \"effect/Context\"\nimport type { Encoding } from \"../Encoding.js\"\nimport type { ErrMode, Input, Source } from \"../Input.js\"\nimport { Fail, Failure, State } from \"../Input.js\"\n\n/** What a failure inside an `ERROR` node was. Offsets are relative to the node. */\nexport interface ErrorInfo {\n readonly failure: Failure\n readonly mode: ErrMode\n}\n\n/** A position-independent syntax tree node. */\nexport class Green {\n constructor(\n readonly kind: string,\n readonly named: boolean,\n /** The `Syntax.node` that built it; `undefined` for roots and errors, which are never reused alone. */\n readonly key: object | undefined,\n readonly width: number,\n /** How far its parse looked, relative to its start (at least `width`). */\n readonly lookahead: number,\n readonly children: ReadonlyArray<Green>,\n /** The children's starts, relative to this node's start. */\n readonly offsets: ReadonlyArray<number>,\n /** The children's field names, when any child has one. */\n readonly fields: ReadonlyArray<string | undefined> | undefined,\n readonly value: unknown,\n /** Set on `ERROR` nodes. */\n readonly error: ErrorInfo | undefined,\n /** Whether this node or a descendant is an `ERROR` node. */\n readonly hasError: boolean,\n /** What its parse left behind for error reporting, replayed when it is reused. */\n readonly diagnostics: Diagnostics | undefined\n ) {}\n}\n\n/**\n * The error-reporting state a node's parse leaves behind (see\n * `State.deepest` and `State.setHint`). A reused node replays it, so that\n * a reparse reports the errors a fresh parse does.\n */\nexport interface Diagnostics {\n /** The furthest failure, at its offset in the parse that built the node... */\n readonly deepest: Failure | undefined\n /** ...which started the node at `base`. */\n readonly base: number\n /** Relative to the node's start. */\n readonly hintOffset: number\n readonly hintExpected: ReadonlyArray<string> | undefined\n}\n\n/** A completed node waiting for its parent, at an absolute position. */\nclass Child {\n constructor(\n readonly green: Green,\n readonly start: number,\n readonly end: number,\n public field: string | undefined\n ) {}\n}\n\nexport const errorKind = \"ERROR\"\n\nconst rebase = (f: Failure, start: number): Failure =>\n new Failure(f.offset - start, f.kind, f.expected, f.context, f.hasCause, f.cause, f.message, f.needed)\n\n/** Moves a failure stored relative to a node back to absolute offsets. */\nexport const absolute = (f: Failure, start: number): Failure => rebase(f, -start)\n\n/**\n * Builds a green node over `[start, end)` from the children waiting on the\n * stack.\n */\nconst build = (\n kind: string,\n named: boolean,\n key: object | undefined,\n start: number,\n end: number,\n lookahead: number,\n entries: ReadonlyArray<Child>,\n value: unknown,\n error: ErrorInfo | undefined,\n diagnostics?: Diagnostics\n): Green => {\n const n = entries.length\n const children = new Array<Green>(n)\n const offsets = new Array<number>(n)\n let fields: Array<string | undefined> | undefined\n let hasError = error !== undefined\n for (let i = 0; i < n; i++) {\n const e = entries[i]\n children[i] = e.green\n offsets[i] = e.start - start\n if (e.green.hasError) hasError = true\n if (e.field !== undefined) (fields ??= new Array(n).fill(undefined))[i] = e.field\n }\n const width = end - start\n const looked = Math.max(lookahead, end) - start\n return new Green(kind, named, key, width, looked, children, offsets, fields, value, error, hasError, diagnostics)\n}\n\n/**\n * A stretch of the new input copied unchanged from the previous one:\n * `[newStart, newStart + length)` is `[oldStart, oldStart + length)`.\n */\nexport interface Segment {\n readonly newStart: number\n readonly oldStart: number\n readonly length: number\n}\n\n/** What a reparse may reuse. */\nexport interface Previous {\n readonly root: Green\n readonly oldLength: number\n readonly newLength: number\n readonly segments: ReadonlyArray<Segment>\n readonly input: Input\n /** How far past its lookahead a parser may have read, besides a token at the lookahead. */\n readonly extra: number\n readonly encoding: Encoding<any> | undefined\n}\n\n/** The hooks that `Syntax` combinators and `Parser.resumeAfter`/`retryAfter` call. */\nexport interface Builder {\n node(state: State<any>, step: (state: State<any>) => unknown, key: object, kind: string, named: boolean): unknown\n field(state: State<any>, step: (state: State<any>) => unknown, name: string): unknown\n /** After error recovery: `[start, pos)` was skipped after `failure`. */\n skipped(start: number, failure: Failure, mode: ErrMode): void\n /**\n * Called by token parsers that read input up to `end` (exclusive) beyond\n * where they leave the cursor or record a failure.\n */\n read(end: number): void\n}\n\n/** The parse state of a `Syntax` parse. */\nexport class SyntaxState<I extends Input = Input> extends State<I> implements Builder {\n // Declared, not defined: `State`'s constructor sets `pos` through the\n // accessor below before these could be initialized\n declare cursor: number\n /** The furthest position the cursor reached, or failure recorded, since the innermost open node started. */\n declare highWater: number\n /** Completed nodes waiting for their parent, in input order. */\n declare stack: Array<Child>\n declare previous: Previous | undefined\n /** How many nodes were reused from the previous tree. */\n declare reused: number\n /** Where {@link find} found the last node it found. */\n declare lastParent: Green | undefined\n declare lastParentStart: number\n\n static {\n Object.defineProperty(this.prototype, \"pos\", {\n get(this: SyntaxState) {\n return this.cursor\n },\n set(this: SyntaxState, p: number) {\n if (p < this.cursor) {\n // An attempt was abandoned (or a lookahead finished): drop its nodes\n const stack = this.stack\n while (stack.length > 0 && stack[stack.length - 1].end > p) stack.pop()\n }\n if (p > this.highWater) this.highWater = p\n this.cursor = p\n },\n configurable: true,\n enumerable: true\n })\n }\n\n constructor(\n source: I | Source<I>,\n options: {\n readonly context?: Context.Context<never> | undefined\n },\n previous: Previous | undefined\n ) {\n super(source, { context: options.context })\n this.highWater = this.cursor\n this.stack = []\n this.previous = previous\n this.reused = 0\n this.lastParent = undefined\n this.lastParentStart = 0\n this.syntax = this\n // Error recovery is always on: like Tree-sitter, a syntax parse always produces a tree\n this.recovered = []\n }\n\n override failWith(mode: ErrMode, failure: Failure): Fail {\n if (failure.offset > this.highWater) this.highWater = failure.offset\n return super.failWith(mode, failure)\n }\n\n override setHint(offset: number, expected: ReadonlyArray<string>): void {\n if (offset > this.highWater) this.highWater = offset\n super.setHint(offset, expected)\n }\n\n node(state: State<any>, step: (state: State<any>) => unknown, key: object, kind: string, named: boolean): unknown {\n const start = this.cursor\n const stack = this.stack\n if (this.previous !== undefined) {\n const green = this.reusable(this.previous, key, start)\n if (green !== undefined) {\n this.reused++\n const end = start + green.width\n state.pos = end\n const looked = start + green.lookahead\n if (looked > this.highWater) this.highWater = looked\n const d = green.diagnostics\n if (d !== undefined) {\n if (d.deepest !== undefined) this.deepen(start === d.base ? d.deepest : rebase(d.deepest, d.base - start))\n if (d.hintExpected !== undefined) this.setHint(start + d.hintOffset, d.hintExpected)\n }\n stack.push(new Child(green, start, end, undefined))\n return green.value\n }\n }\n const mark = stack.length\n const outer = this.highWater\n const outerDeepest = this.deepest\n const hintOffset = this.hintOffset\n const hintExpected = this.hintExpected\n this.highWater = start\n // Collect the furthest failure of this node alone, then merge it as `failWith` would have\n this.deepest = undefined\n const a = step(state)\n const looked = this.highWater\n if (outer > looked) this.highWater = outer\n const deepest = this.deepest as Failure | undefined\n this.deepest = outerDeepest\n if (deepest !== undefined) this.deepen(deepest)\n if (a === Fail) {\n if (stack.length > mark) stack.length = mark\n return a\n }\n const end = this.cursor\n // Like Tree-sitter's rules, nodes are never empty: an empty match adds nothing to the tree\n if (end === start) return a\n const hinted = this.hintOffset !== hintOffset || this.hintExpected !== hintExpected\n const diagnostics: Diagnostics | undefined =\n deepest === undefined && !hinted\n ? undefined\n : {\n deepest,\n base: start,\n hintOffset: this.hintOffset - start,\n hintExpected: hinted ? this.hintExpected : undefined\n }\n const entries = stack.splice(mark)\n stack.push(\n new Child(build(kind, named, key, start, end, looked, entries, a, undefined, diagnostics), start, end, undefined)\n )\n return a\n }\n\n read(end: number): void {\n // `highWater` is the last position looked at, `end` is exclusive\n if (end - 1 > this.highWater) this.highWater = end - 1\n }\n\n /** Records `failure` as the furthest failure if it is, as `failWith` does. */\n private deepen(failure: Failure): void {\n if (this.deepest === undefined || failure.offset >= this.deepest.offset) this.deepest = failure\n }\n\n field(state: State<any>, step: (state: State<any>) => unknown, name: string): unknown {\n const stack = this.stack\n const mark = stack.length\n const a = step(state)\n if (a !== Fail) for (let i = mark; i < stack.length; i++) stack[i].field = name\n return a\n }\n\n skipped(start: number, failure: Failure, mode: ErrMode): void {\n const stack = this.stack\n let i = stack.length\n while (i > 0 && stack[i - 1].start >= start && stack[i - 1].end > start) i--\n const end = this.cursor\n const green = build(errorKind, true, undefined, start, end, this.highWater, stack.splice(i), undefined, {\n failure: rebase(failure, start),\n mode\n })\n stack.push(new Child(green, start, end, undefined))\n }\n\n /**\n * Builds the root over the whole input from the nodes left on the stack.\n * When the parse failed, or stopped before the end, the rest of the input\n * becomes an `ERROR` node.\n */\n finish(kind: string, value: unknown, fatal: ErrorInfo | undefined, errorStart: number): Green {\n const entries = this.stack.splice(0)\n const end = this.end\n if (fatal !== undefined) {\n const last = entries.length > 0 ? entries[entries.length - 1].end : 0\n const start = Math.max(Math.min(errorStart, end), last)\n const error = build(errorKind, true, undefined, start, end, end, [], undefined, {\n failure: rebase(fatal.failure, start),\n mode: fatal.mode\n })\n entries.push(new Child(error, start, end, undefined))\n }\n return build(kind, true, undefined, 0, end, Math.max(end, this.highWater), entries, value, undefined)\n }\n\n /**\n * The outermost node of the previous tree built by `key` that starts at\n * `offset`. Reused nodes are mostly siblings, found one after the other,\n * so the search starts from the parent of the last one found when\n * `offset` lies inside it: no ancestor of that parent can start there.\n */\n private find(root: Green, offset: number, key: object): Green | undefined {\n let node = root\n let start = 0\n const last = this.lastParent\n if (last !== undefined && offset > this.lastParentStart && offset < this.lastParentStart + last.width) {\n node = last\n start = this.lastParentStart\n }\n while (true) {\n const offsets = node.offsets\n // The last child starting at or before `offset`\n let lo = 0\n let hi = offsets.length - 1\n let found = -1\n while (lo <= hi) {\n const mid = (lo + hi) >> 1\n if (start + offsets[mid] <= offset) {\n found = mid\n lo = mid + 1\n } else {\n hi = mid - 1\n }\n }\n if (found < 0) return undefined\n const child = node.children[found]\n const childStart = start + offsets[found]\n if (offset >= childStart + child.width) return undefined\n if (childStart === offset && child.key === key) {\n this.lastParent = node\n this.lastParentStart = start\n return child\n }\n node = child\n start = childStart\n }\n }\n\n /** The node of the previous tree built by `key` at `pos` (in the new input), if it can be reused. */\n private reusable(previous: Previous, key: object, pos: number): Green | undefined {\n const segments = previous.segments\n // The segment containing `pos`\n let lo = 0\n let hi = segments.length - 1\n while (lo <= hi) {\n const mid = (lo + hi) >> 1\n const seg = segments[mid]\n if (pos < seg.newStart) hi = mid - 1\n else if (pos >= seg.newStart + seg.length) lo = mid + 1\n else {\n const old = seg.oldStart + (pos - seg.newStart)\n const green = this.find(previous.root, old, key)\n if (green === undefined) return undefined\n const segEnd = seg.oldStart + seg.length\n // The input it looked at must be unchanged; past the end of both inputs counts as unchanged\n if (old + green.lookahead + tokenWidth(previous.input, old + green.lookahead) + previous.extra <= segEnd) {\n return green\n }\n if (segEnd === previous.oldLength && seg.newStart + seg.length === previous.newLength) return green\n return undefined\n }\n }\n return undefined\n }\n}\n\n/**\n * How many units a token parser may read at `offset`, where a parse\n * stopped looking: one code point. Of a string, that is two units at a high\n * surrogate. Of bytes in an unknown encoding, up to four.\n */\nconst tokenWidth = (input: Input, offset: number): number => {\n if (Predicate.isString(input)) {\n const c = input.charCodeAt(offset)\n return c >= 0xd800 && c <= 0xdbff ? 2 : 1\n }\n return input instanceof Uint8Array ? 4 : 1\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAyCA,IAAa,QAAb,MAAmB;CAEN;CACA;CAEA;CACA;CAEA;CACA;CAEA;CAEA;CACA;CAEA;CAEA;CAEA;CAnBX,YACE,MACA,OAEA,KACA,OAEA,WACA,UAEA,SAEA,QACA,OAEA,OAEA,UAEA,aACA;EAnBS,KAAA,OAAA;EACA,KAAA,QAAA;EAEA,KAAA,MAAA;EACA,KAAA,QAAA;EAEA,KAAA,YAAA;EACA,KAAA,WAAA;EAEA,KAAA,UAAA;EAEA,KAAA,SAAA;EACA,KAAA,QAAA;EAEA,KAAA,QAAA;EAEA,KAAA,WAAA;EAEA,KAAA,cAAA;CACR;AACL;;AAkBA,IAAM,QAAN,MAAY;CAEC;CACA;CACA;CACF;CAJT,YACE,OACA,OACA,KACA,OACA;EAJS,KAAA,QAAA;EACA,KAAA,QAAA;EACA,KAAA,MAAA;EACF,KAAA,QAAA;CACN;AACL;AAEA,MAAa,YAAY;AAEzB,MAAM,UAAU,GAAY,UAC1B,IAAI,QAAQ,EAAE,SAAS,OAAO,EAAE,MAAM,EAAE,UAAU,EAAE,SAAS,EAAE,UAAU,EAAE,OAAO,EAAE,SAAS,EAAE,MAAM;;AAGvG,MAAa,YAAY,GAAY,UAA2B,OAAO,GAAG,CAAC,KAAK;;;;;AAMhF,MAAM,SACJ,MACA,OACA,KACA,OACA,KACA,WACA,SACA,OACA,OACA,gBACU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ANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
1
|
+
import { Fail, State } from "../Input.js";
|
|
2
|
+
import { Encoding } from "../Encoding.js";
|
|
3
|
+
//#region src/internal/text.d.ts
|
|
3
4
|
/** `Encoding.decode`: the input is malformed. */
|
|
4
5
|
export declare const Invalid = -1;
|
|
5
6
|
/** `Encoding.decode`: the input ends inside a sequence. */
|
|
@@ -8,6 +9,12 @@ export declare const Truncated = -2;
|
|
|
8
9
|
export declare const End = -3;
|
|
9
10
|
/** @internal */
|
|
10
11
|
export declare const fastLimit: (enc: Encoding<any>) => number;
|
|
12
|
+
/**
|
|
13
|
+
* The code point that starts `s`: for a string known to hold one, such as
|
|
14
|
+
* one element of `Array.from(string)`. On an empty string it is `NaN`, which,
|
|
15
|
+
* like the `undefined` of `codePointAt(0)`, matches no code point.
|
|
16
|
+
*/
|
|
17
|
+
export declare const firstCodePoint: (s: string) => number;
|
|
11
18
|
/** `String.fromCodePoint`, with the ASCII characters cached. */
|
|
12
19
|
export declare const charOf: (cp: number) => string;
|
|
13
20
|
/**
|
|
@@ -69,4 +76,5 @@ export declare const fold: (cp: number) => number;
|
|
|
69
76
|
export declare const walk: (enc: Encoding<any>, input: string | Uint8Array, start: number, end: number, f: (cp: number, offset: number, width: number) => boolean | void) => void;
|
|
70
77
|
/** Decodes `[start, end)`, replacing malformed sequences with U+FFFD. */
|
|
71
78
|
export declare const lenientText: (enc: Encoding<any>, input: string | Uint8Array, start: number, end: number) => string;
|
|
79
|
+
//#endregion
|
|
72
80
|
//# sourceMappingURL=text.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"text.d.ts","
|
|
1
|
+
{"version":3,"file":"text.d.ts","names":[],"sources":["../../src/internal/text.ts"],"mappings":";;;;qBAQa;;qBAEA;;qBAEA;;qBAaA,YAAa,KAAK;;;;;;qBAUlB,iBAAkB;;qBAGlB,SAAU;;;;;qBAkBV,QAAQ;;qBA6DR,MAAM,SAAS;;qBAkEf,SAAS,SAAS;;qBAGlB,SAAS,SAAS;;qBAGlB,QAAQ,SAAS;;mBA8BnB;;;;;;;qBAQE,OAAQ,KAAK,eAAe,OAAO,YAAY;;;;;qBAe/C,SACX,OAAO,YACP,YACA,MAAM,WAAW,wBACjB,UAAU,uBACV,oBACC;;mBAQQ;;mBAEA;;;;;mBAKA;;;;;qBAME,OACX,KAAK,eACL,OAAO,YACP,OAAO,wBACP,iBACA,aACA,cACA;;;;;qBA+DW,WAAY,KAAK,eAAe,OAAO,YAAY,eAAe;;;;;;qBA2BlE,OAAQ;;;;;qBAsBR,OACX,KAAK,eACL,gBAAgB,YAChB,eACA,aACA,IAAI,YAAY,gBAAgB;;qBAkBrB,cAAe,KAAK,eAAe,gBAAgB,YAAY,eAAe"}
|