@thomasfosterau/effect-parse 0.1.0 → 0.3.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.
Files changed (161) hide show
  1. package/README.md +291 -231
  2. package/dist/Ascii.d.ts +32 -53
  3. package/dist/Ascii.d.ts.map +1 -1
  4. package/dist/Ascii.js +576 -571
  5. package/dist/Ascii.js.map +1 -1
  6. package/dist/Binary.d.ts +6 -29
  7. package/dist/Binary.d.ts.map +1 -1
  8. package/dist/Binary.js +129 -116
  9. package/dist/Binary.js.map +1 -1
  10. package/dist/Bits.d.ts +4 -2
  11. package/dist/Bits.d.ts.map +1 -1
  12. package/dist/Bits.js +121 -123
  13. package/dist/Bits.js.map +1 -1
  14. package/dist/Compiler.d.ts +39 -0
  15. package/dist/Compiler.d.ts.map +1 -0
  16. package/dist/Compiler.js +48 -0
  17. package/dist/Compiler.js.map +1 -0
  18. package/dist/Encoding.d.ts +29 -46
  19. package/dist/Encoding.d.ts.map +1 -1
  20. package/dist/Encoding.js +76 -75
  21. package/dist/Encoding.js.map +1 -1
  22. package/dist/Expression.d.ts +15 -49
  23. package/dist/Expression.d.ts.map +1 -1
  24. package/dist/Expression.js +151 -132
  25. package/dist/Expression.js.map +1 -1
  26. package/dist/Input.d.ts +251 -177
  27. package/dist/Input.d.ts.map +1 -1
  28. package/dist/Input.js +409 -299
  29. package/dist/Input.js.map +1 -1
  30. package/dist/Nom.d.ts +45 -85
  31. package/dist/Nom.d.ts.map +1 -1
  32. package/dist/Nom.js +423 -453
  33. package/dist/Nom.js.map +1 -1
  34. package/dist/ParseError.d.ts +54 -49
  35. package/dist/ParseError.d.ts.map +1 -1
  36. package/dist/ParseError.js +232 -275
  37. package/dist/ParseError.js.map +1 -1
  38. package/dist/Parser.d.ts +345 -313
  39. package/dist/Parser.d.ts.map +1 -1
  40. package/dist/Parser.js +2034 -1802
  41. package/dist/Parser.js.map +1 -1
  42. package/dist/ParserSchema.d.ts +206 -7
  43. package/dist/ParserSchema.d.ts.map +1 -1
  44. package/dist/ParserSchema.js +678 -49
  45. package/dist/ParserSchema.js.map +1 -1
  46. package/dist/ParserStream.d.ts +26 -20
  47. package/dist/ParserStream.d.ts.map +1 -1
  48. package/dist/ParserStream.js +267 -255
  49. package/dist/ParserStream.js.map +1 -1
  50. package/dist/Syntax.d.ts +401 -0
  51. package/dist/Syntax.d.ts.map +1 -0
  52. package/dist/Syntax.js +717 -0
  53. package/dist/Syntax.js.map +1 -0
  54. package/dist/Text.d.ts +98 -134
  55. package/dist/Text.d.ts.map +1 -1
  56. package/dist/Text.js +534 -496
  57. package/dist/Text.js.map +1 -1
  58. package/dist/Token.d.ts +60 -42
  59. package/dist/Token.d.ts.map +1 -1
  60. package/dist/Token.js +331 -265
  61. package/dist/Token.js.map +1 -1
  62. package/dist/index.d.ts +16 -17
  63. package/dist/index.js +16 -17
  64. package/dist/internal/compiler/closure.d.ts +14 -16
  65. package/dist/internal/compiler/closure.d.ts.map +1 -1
  66. package/dist/internal/compiler/closure.js +1458 -1637
  67. package/dist/internal/compiler/closure.js.map +1 -1
  68. package/dist/internal/compiler/entries.d.ts +11 -11
  69. package/dist/internal/compiler/entries.d.ts.map +1 -1
  70. package/dist/internal/compiler/entries.js +36 -26
  71. package/dist/internal/compiler/entries.js.map +1 -1
  72. package/dist/internal/compiler/first.d.ts +19 -19
  73. package/dist/internal/compiler/first.d.ts.map +1 -1
  74. package/dist/internal/compiler/first.js +251 -227
  75. package/dist/internal/compiler/first.js.map +1 -1
  76. package/dist/internal/compiler/jit.d.ts +6 -17
  77. package/dist/internal/compiler/jit.d.ts.map +1 -1
  78. package/dist/internal/compiler/jit.js +860 -988
  79. package/dist/internal/compiler/jit.js.map +1 -1
  80. package/dist/internal/compiler/registry.d.ts +20 -21
  81. package/dist/internal/compiler/registry.d.ts.map +1 -1
  82. package/dist/internal/compiler/registry.js +21 -41
  83. package/dist/internal/compiler/registry.js.map +1 -1
  84. package/dist/internal/compiler/sets.d.ts +9 -13
  85. package/dist/internal/compiler/sets.d.ts.map +1 -1
  86. package/dist/internal/compiler/sets.js +76 -73
  87. package/dist/internal/compiler/sets.js.map +1 -1
  88. package/dist/internal/entries.d.ts +3 -3
  89. package/dist/internal/entries.d.ts.map +1 -1
  90. package/dist/internal/entries.js +38 -30
  91. package/dist/internal/entries.js.map +1 -1
  92. package/dist/internal/node.d.ts +177 -173
  93. package/dist/internal/node.d.ts.map +1 -1
  94. package/dist/internal/node.js +77 -66
  95. package/dist/internal/node.js.map +1 -1
  96. package/dist/internal/numbers.d.ts +7 -8
  97. package/dist/internal/numbers.d.ts.map +1 -1
  98. package/dist/internal/numbers.js +246 -276
  99. package/dist/internal/numbers.js.map +1 -1
  100. package/dist/internal/resume.d.ts +6 -24
  101. package/dist/internal/resume.d.ts.map +1 -1
  102. package/dist/internal/resume.js +30 -29
  103. package/dist/internal/resume.js.map +1 -1
  104. package/dist/internal/run.d.ts +15 -0
  105. package/dist/internal/run.d.ts.map +1 -0
  106. package/dist/internal/run.js +36 -0
  107. package/dist/internal/run.js.map +1 -0
  108. package/dist/internal/stack.d.ts +16 -0
  109. package/dist/internal/stack.d.ts.map +1 -0
  110. package/dist/internal/stack.js +36 -0
  111. package/dist/internal/stack.js.map +1 -0
  112. package/dist/internal/syntax.d.ts +147 -0
  113. package/dist/internal/syntax.d.ts.map +1 -0
  114. package/dist/internal/syntax.js +309 -0
  115. package/dist/internal/syntax.js.map +1 -0
  116. package/dist/internal/text.d.ts +10 -2
  117. package/dist/internal/text.d.ts.map +1 -1
  118. package/dist/internal/text.js +295 -345
  119. package/dist/internal/text.js.map +1 -1
  120. package/dist/internal/ties.d.ts +30 -0
  121. package/dist/internal/ties.d.ts.map +1 -0
  122. package/dist/internal/ties.js +67 -0
  123. package/dist/internal/ties.js.map +1 -0
  124. package/dist/internal/tokens.d.ts +25 -30
  125. package/dist/internal/tokens.d.ts.map +1 -1
  126. package/dist/internal/tokens.js +369 -363
  127. package/dist/internal/tokens.js.map +1 -1
  128. package/package.json +42 -28
  129. package/src/Ascii.ts +278 -187
  130. package/src/Binary.ts +150 -44
  131. package/src/Bits.ts +6 -3
  132. package/src/Compiler.ts +98 -0
  133. package/src/Expression.ts +24 -16
  134. package/src/Input.ts +210 -35
  135. package/src/Nom.ts +4 -3
  136. package/src/ParseError.ts +49 -52
  137. package/src/Parser.ts +1199 -799
  138. package/src/ParserSchema.ts +982 -23
  139. package/src/ParserStream.ts +104 -80
  140. package/src/Syntax.ts +900 -0
  141. package/src/Text.ts +272 -187
  142. package/src/Token.ts +180 -87
  143. package/src/index.ts +2 -0
  144. package/src/internal/compiler/closure.ts +121 -88
  145. package/src/internal/compiler/entries.ts +21 -8
  146. package/src/internal/compiler/first.ts +17 -15
  147. package/src/internal/compiler/jit.ts +360 -157
  148. package/src/internal/compiler/registry.ts +12 -33
  149. package/src/internal/compiler/sets.ts +17 -11
  150. package/src/internal/entries.ts +4 -2
  151. package/src/internal/node.ts +51 -37
  152. package/src/internal/numbers.ts +22 -20
  153. package/src/internal/resume.ts +8 -4
  154. package/src/internal/run.ts +41 -0
  155. package/src/internal/stack.ts +41 -0
  156. package/src/internal/syntax.ts +426 -0
  157. package/src/internal/text.ts +32 -25
  158. package/src/internal/ties.ts +83 -0
  159. package/src/internal/tokens.ts +96 -51
  160. package/dist/index.d.ts.map +0 -1
  161. package/dist/index.js.map +0 -1
@@ -0,0 +1,401 @@
1
+ import { Input, Slice, Source } from "./Input.js";
2
+ import { Parser } from "./Parser.js";
3
+ import * as Option from "effect/Option";
4
+ import * as Context from "effect/Context";
5
+ import * as ParseError from "./ParseError.js";
6
+ import { ErrorInfo, Green } from "./internal/syntax.js";
7
+ //#region src/Syntax.d.ts
8
+ /**
9
+ * Marks a parser as a rule of the syntax tree: in a {@link parse}, each
10
+ * match becomes a named node of the given kind, spanning the input it
11
+ * consumed, with the nodes built inside it as children and its output as
12
+ * its `value`. Outside {@link parse}, the parser is unchanged.
13
+ *
14
+ * A match that consumes nothing adds no node (as in Tree-sitter, where rules
15
+ * can't match the empty string).
16
+ *
17
+ * For {@link reparse} to reuse a node, its parser's output must depend only
18
+ * on the input from where the node starts: not on services, on state kept
19
+ * in closures, or on absolute offsets (`Parser.location`, `Parser.span`),
20
+ * which are not updated when the node moves. Use the node's `start` and
21
+ * `end` instead.
22
+ *
23
+ * @since 0.2.0
24
+ * @category annotations
25
+ */
26
+ export declare const node: {
27
+ (kind: string): <A, E, R, I extends Input>(self: Parser<A, E, R, I>) => Parser<A, E, R, I>;
28
+ <A, E, R, I extends Input>(self: Parser<A, E, R, I>, kind: string): Parser<A, E, R, I>;
29
+ };
30
+ /**
31
+ * Like {@link node}, but builds an *anonymous* node, Tree-sitter's name for
32
+ * punctuation and keywords: anonymous nodes are left out of
33
+ * `namedChildren` and of the tree's printed form. The kind defaults to the
34
+ * literal for a `Token.literal` of a string, and to the parser's name
35
+ * otherwise.
36
+ *
37
+ * @example
38
+ * ```ts
39
+ * import { Syntax, Token } from "@thomasfosterau/effect-parse"
40
+ *
41
+ * const comma = Syntax.token(Token.literal(",")) // kind ","
42
+ * ```
43
+ *
44
+ * @since 0.2.0
45
+ * @category annotations
46
+ */
47
+ export declare const token: {
48
+ (kind?: string): <A, E, R, I extends Input>(self: Parser<A, E, R, I>) => Parser<A, E, R, I>;
49
+ <A, E, R, I extends Input>(self: Parser<A, E, R, I>, kind?: string): Parser<A, E, R, I>;
50
+ };
51
+ /**
52
+ * Gives the nodes built by a parser a field name in their parent, like
53
+ * Tree-sitter's `field(name, rule)`: find them with `childByField` and
54
+ * `childrenByField`. Outside {@link parse}, the parser is unchanged.
55
+ *
56
+ * @example
57
+ * ```ts
58
+ * import { Ascii, Parser, Syntax, Token } from "@thomasfosterau/effect-parse"
59
+ *
60
+ * const name = Syntax.node(Ascii.alpha1, "name")
61
+ * const number = Syntax.node(Ascii.decInt, "number")
62
+ * const pair = Syntax.node(
63
+ * Parser.separatedPair(Syntax.field(name, "key"), Token.literal("="), Syntax.field(number, "value")),
64
+ * "pair"
65
+ * )
66
+ * Syntax.parse(pair, "x=1").root.childByField("value")?.value // 1
67
+ * ```
68
+ *
69
+ * @since 0.2.0
70
+ * @category annotations
71
+ */
72
+ export declare const field: {
73
+ (name: string): <A, E, R, I extends Input>(self: Parser<A, E, R, I>) => Parser<A, E, R, I>;
74
+ <A, E, R, I extends Input>(self: Parser<A, E, R, I>, name: string): Parser<A, E, R, I>;
75
+ };
76
+ /**
77
+ * The kind of the nodes that stand for input that could not be parsed.
78
+ *
79
+ * @since 0.2.0
80
+ * @category models
81
+ */
82
+ export declare const ERROR: "ERROR";
83
+ /**
84
+ * An edit to an input, as Tree-sitter's `TSInputEdit`: the input
85
+ * `[start, oldEnd)` was replaced by `[start, newEnd)`. Offsets are in the
86
+ * input's units (UTF-16 code units for strings, bytes, elements).
87
+ *
88
+ * @since 0.2.0
89
+ * @category models
90
+ */
91
+ export interface Edit {
92
+ readonly start: number;
93
+ readonly oldEnd: number;
94
+ readonly newEnd: number;
95
+ }
96
+ /**
97
+ * Options for {@link parse}.
98
+ *
99
+ * @since 0.2.0
100
+ * @category models
101
+ */
102
+ export interface ParseOptions {
103
+ /**
104
+ * The kind of the root node, when the grammar itself is not a
105
+ * {@link node}. Defaults to `"document"`.
106
+ */
107
+ readonly kind?: string | undefined;
108
+ /**
109
+ * For {@link reparse}: how many input units custom parsers may read past
110
+ * the furthest position they move the cursor to or record a failure at,
111
+ * besides one token there. Defaults to 0, which is right for the built-in
112
+ * parsers, and for custom parsers (`Parser.make`) that only read past
113
+ * where they stop to see that the token there doesn't match.
114
+ *
115
+ * A node is reused only when the input its parse looked at is unchanged.
116
+ * Built-in parsers that read further, such as a literal that fails part
117
+ * way or `Token.takeUntil`, record how far they read.
118
+ */
119
+ readonly lookahead?: number | undefined;
120
+ }
121
+ /**
122
+ * Options for {@link parse} with a parser that requires services.
123
+ *
124
+ * @since 0.2.0
125
+ * @category models
126
+ */
127
+ export interface ParseOptionsWithContext<R> extends ParseOptions {
128
+ readonly context: Context.Context<R>;
129
+ }
130
+ interface Config {
131
+ readonly kind: string;
132
+ readonly inner: Parser.Any;
133
+ readonly lookahead: number;
134
+ readonly context: Context.Context<never> | undefined;
135
+ }
136
+ /**
137
+ * The result of a {@link parse}: a syntax tree over the whole input, the
138
+ * grammar's output, and the errors met on the way.
139
+ *
140
+ * @since 0.2.0
141
+ * @category models
142
+ */
143
+ export declare class Tree<out A, out E = never, I extends Input = string> {
144
+ /** The input the tree was parsed from. */
145
+ readonly input: I;
146
+ /** The grammar's output: `none` when the parse failed. */
147
+ readonly value: Option.Option<A>;
148
+ /** How many nodes were reused from the previous tree by {@link reparse}. */
149
+ readonly reused: number;
150
+ /** @internal */
151
+ readonly green: Green;
152
+ /** @internal */
153
+ readonly config: Config;
154
+ /** @internal */
155
+ readonly encoding: ParseError.ParseError<never>["encoding"];
156
+ /** The root node. It always spans the whole input. */
157
+ readonly root: SyntaxNode<I>;
158
+ private lines;
159
+ private errorList;
160
+ /** @internal */
161
+ constructor(
162
+ /** The input the tree was parsed from. */
163
+ input: I,
164
+ /** The grammar's output: `none` when the parse failed. */
165
+ value: Option.Option<A>,
166
+ /** How many nodes were reused from the previous tree by {@link reparse}. */
167
+ reused: number,
168
+ /** @internal */
169
+ green: Green,
170
+ /** @internal */
171
+ config: Config,
172
+ /** @internal */
173
+ encoding: ParseError.ParseError<never>["encoding"]);
174
+ /**
175
+ * Every error of the parse, in input order: the failures recovered by
176
+ * `Parser.resumeAfter` and `Parser.retryAfter`, then the fatal one, if
177
+ * the parse failed. Each one belongs to an `ERROR` node.
178
+ */
179
+ get errors(): ReadonlyArray<ParseError.ParseError<E>>;
180
+ /** Whether the tree has any `ERROR` node. */
181
+ get hasErrors(): boolean;
182
+ /** The smallest node containing `[start, end)` (see {@link SyntaxNode.descendantAt}). */
183
+ descendantAt(start: number, end?: number): SyntaxNode<I>;
184
+ /** A cursor at the root. */
185
+ walk(): TreeCursor<I>;
186
+ /**
187
+ * The 1-based line and column (in code points) of an offset, as in
188
+ * `ParseError`. Lines of a string input are indexed once, so lookups take
189
+ * logarithmic time.
190
+ */
191
+ lineColumn(offset: number): ParseError.LineColumn;
192
+ /** The root's S-expression (see {@link SyntaxNode.toString}). */
193
+ toString(): string;
194
+ /** @internal */
195
+ toError(error: ErrorInfo, start: number): ParseError.ParseError<E>;
196
+ }
197
+ /**
198
+ * A node of a syntax tree: its kind, span and value, and its place in the
199
+ * tree. Nodes are views built on demand; two views of the same node are
200
+ * different objects but have the same `start`, `end` and `kind`.
201
+ *
202
+ * @since 0.2.0
203
+ * @category models
204
+ */
205
+ export declare class SyntaxNode<I extends Input = string> {
206
+ /** The tree this node belongs to. */
207
+ readonly tree: Tree<unknown, unknown, I>;
208
+ /** @internal */
209
+ readonly green: Green;
210
+ /** The offset where the node starts. */
211
+ readonly start: number;
212
+ /** The parent node; `undefined` for the root. */
213
+ readonly parent: SyntaxNode<I> | undefined;
214
+ /** The node's index among its parent's children. */
215
+ readonly index: number;
216
+ private childList;
217
+ /** @internal */
218
+ constructor(
219
+ /** The tree this node belongs to. */
220
+ tree: Tree<unknown, unknown, I>,
221
+ /** @internal */
222
+ green: Green,
223
+ /** The offset where the node starts. */
224
+ start: number,
225
+ /** The parent node; `undefined` for the root. */
226
+ parent: SyntaxNode<I> | undefined,
227
+ /** The node's index among its parent's children. */
228
+ index: number);
229
+ /** The node's kind: the name given to {@link node} or {@link token}, or `"ERROR"`. */
230
+ get kind(): string;
231
+ /** `false` for the anonymous nodes built by {@link token}. */
232
+ get named(): boolean;
233
+ /** The field name given by {@link field}, if any. */
234
+ get field(): string | undefined;
235
+ /** The offset where the node ends (exclusive). */
236
+ get end(): number;
237
+ /** The number of input units the node spans. */
238
+ get length(): number;
239
+ /** The output of the node's parser (`undefined` for `ERROR` nodes, and for a root that failed). */
240
+ get value(): unknown;
241
+ /** The input the node spans. */
242
+ get text(): Slice<I>;
243
+ /** Whether this is an `ERROR` node. */
244
+ get isError(): boolean;
245
+ /** Whether this node or a descendant is an `ERROR` node. */
246
+ get hasError(): boolean;
247
+ /** For an `ERROR` node, the error it stands for. */
248
+ get error(): ParseError.ParseError<unknown> | undefined;
249
+ /** The child nodes, named and anonymous, in input order. */
250
+ get children(): ReadonlyArray<SyntaxNode<I>>;
251
+ /** The number of children. */
252
+ get childCount(): number;
253
+ /** The child at `index` (negative indices count from the end). */
254
+ child(index: number): SyntaxNode<I> | undefined;
255
+ /** The named children. */
256
+ get namedChildren(): ReadonlyArray<SyntaxNode<I>>;
257
+ /** The named child at `index`. */
258
+ namedChild(index: number): SyntaxNode<I> | undefined;
259
+ /** The first child with the given field name. */
260
+ childByField(name: string): SyntaxNode<I> | undefined;
261
+ /** The children with the given field name. */
262
+ childrenByField(name: string): ReadonlyArray<SyntaxNode<I>>;
263
+ /** The next sibling, named or anonymous. */
264
+ get nextSibling(): SyntaxNode<I> | undefined;
265
+ /** The previous sibling, named or anonymous. */
266
+ get previousSibling(): SyntaxNode<I> | undefined;
267
+ /** The next named sibling. */
268
+ get nextNamedSibling(): SyntaxNode<I> | undefined;
269
+ /** The previous named sibling. */
270
+ get previousNamedSibling(): SyntaxNode<I> | undefined;
271
+ /**
272
+ * The index of the child containing the input unit at `offset`, or -1.
273
+ * Takes logarithmic time.
274
+ */
275
+ childIndexAt(offset: number): number;
276
+ /** The child containing the input unit at `offset`. */
277
+ childAt(offset: number): SyntaxNode<I> | undefined;
278
+ /**
279
+ * The smallest node, this one or a descendant, that contains
280
+ * `[start, end)` (Tree-sitter's `descendant_for_byte_range`). With only
281
+ * `start`, the deepest node containing the input unit at `start`. Takes
282
+ * time proportional to the depth of the tree times the logarithm of the
283
+ * number of children.
284
+ */
285
+ descendantAt(start: number, end?: number): SyntaxNode<I>;
286
+ /** Like {@link descendantAt}, but only stops at named nodes. */
287
+ namedDescendantAt(start: number, end?: number): SyntaxNode<I>;
288
+ /** This node and its descendants, in pre-order. */
289
+ descendants(): Generator<SyntaxNode<I>, void, undefined>;
290
+ /** The descendants of the given kind, in pre-order. */
291
+ descendantsOfKind(kind: string): Generator<SyntaxNode<I>, void, undefined>;
292
+ /** A cursor at this node, which cannot move above it. */
293
+ walk(): TreeCursor<I>;
294
+ /**
295
+ * The node as an S-expression of its named descendants, with field
296
+ * names, as Tree-sitter prints it: `(pair key: (name) value: (number))`.
297
+ */
298
+ toString(): string;
299
+ toJSON(): unknown;
300
+ private makeChild;
301
+ }
302
+ /**
303
+ * A cursor for walking a tree, as Tree-sitter's `TreeCursor`. It starts at
304
+ * a node and cannot move above it.
305
+ *
306
+ * @since 0.2.0
307
+ * @category models
308
+ */
309
+ export declare class TreeCursor<I extends Input = string> {
310
+ private current;
311
+ private depth;
312
+ /** @internal */
313
+ constructor(node: SyntaxNode<I>);
314
+ /** The node at the cursor. */
315
+ get node(): SyntaxNode<I>;
316
+ /** The field name of the node at the cursor, if any. */
317
+ get field(): string | undefined;
318
+ /** Moves to the first child; `false` if there is none. */
319
+ gotoFirstChild(): boolean;
320
+ /** Moves to the last child; `false` if there is none. */
321
+ gotoLastChild(): boolean;
322
+ /** Moves to the child containing the input unit at `offset`; `false` if there is none. */
323
+ gotoFirstChildForOffset(offset: number): boolean;
324
+ /** Moves to the next sibling; `false` if there is none. */
325
+ gotoNextSibling(): boolean;
326
+ /** Moves to the previous sibling; `false` if there is none. */
327
+ gotoPreviousSibling(): boolean;
328
+ /** Moves to the parent; `false` at the node the cursor started at. */
329
+ gotoParent(): boolean;
330
+ /** Moves to the deepest node containing the input unit at `offset`. */
331
+ gotoDescendantAt(offset: number): void;
332
+ /** Starts again at `node`. */
333
+ reset(node: SyntaxNode<I>): void;
334
+ private goto;
335
+ }
336
+ /**
337
+ * Parses an input into a syntax {@link Tree}. The grammar's output is the
338
+ * tree's `value`, and its {@link node}s are the tree's nodes. When the
339
+ * grammar is itself a {@link node}, that node is the root; otherwise the
340
+ * root is a node of kind `options.kind` (by default `"document"`).
341
+ *
342
+ * The parse never fails: recovered failures (see `Parser.resumeAfter`), a
343
+ * fatal failure and unparsed input at the end all become `ERROR` nodes, and
344
+ * are listed in `tree.errors`. The parse is interpreted, never compiled.
345
+ *
346
+ * @since 0.2.0
347
+ * @category parsing
348
+ */
349
+ export declare const parse: {
350
+ <A, E, I extends Input>(grammar: Parser<A, E, never, I>, input: NoInfer<Source<I>>, options?: ParseOptions): Tree<A, E, I>;
351
+ <A, E, R, I extends Input>(grammar: Parser<A, E, R, I>, input: NoInfer<Source<I>>, options: ParseOptionsWithContext<R>): Tree<A, E, I>;
352
+ };
353
+ /**
354
+ * Parses the new version of a tree's input, reusing the nodes of the tree
355
+ * that the edits leave unchanged (Tree-sitter's `ts_tree_edit` followed by
356
+ * `ts_parser_parse` with the old tree). The result is the tree a fresh
357
+ * {@link parse} of `input` would build, but only the parts of the tree
358
+ * around the edits are parsed again. `tree.reused` says how many nodes were
359
+ * reused.
360
+ *
361
+ * `edits` describe how the old input became the new one, applied in order,
362
+ * each in the coordinates of the input as the previous edits left it. When
363
+ * they are omitted, the edit is found by comparing the inputs (their common
364
+ * prefix and suffix), which takes time linear in their length but much less
365
+ * than parsing.
366
+ *
367
+ * Errors in the new tree are those a fresh parse reports, except that an
368
+ * error just after a reused node may list fewer expected alternatives.
369
+ *
370
+ * @example
371
+ * ```ts
372
+ * import { Ascii, Syntax } from "@thomasfosterau/effect-parse"
373
+ *
374
+ * const number = Syntax.node(Ascii.decInt, "number")
375
+ * const tree = Syntax.parse(number, "12")
376
+ * Syntax.reparse(tree, "123", [{ start: 2, oldEnd: 2, newEnd: 3 }]).root.value // 123
377
+ * ```
378
+ *
379
+ * @since 0.2.0
380
+ * @category parsing
381
+ */
382
+ export declare const reparse: <A, E, I extends Input>(tree: Tree<A, E, I>, input: NoInfer<Source<I>>, edits?: Edit | ReadonlyArray<Edit>) => Tree<A, E, I>;
383
+ /**
384
+ * Replaces `[start, end)` of a tree's string input with `text` and parses
385
+ * the result incrementally (see {@link reparse}).
386
+ *
387
+ * @since 0.2.0
388
+ * @category parsing
389
+ */
390
+ export declare const replace: <A, E>(tree: Tree<A, E, string>, start: number, end: number, text: string) => Tree<A, E, string>;
391
+ /**
392
+ * Finds the edit that turns `before` into `after`: the part between their
393
+ * longest common prefix and suffix. `undefined` when they are equal.
394
+ *
395
+ * @since 0.2.0
396
+ * @category parsing
397
+ */
398
+ export declare const diff: <I extends Input>(before: I, after: I) => Edit | undefined;
399
+ //#endregion
400
+ export {};
401
+ //# sourceMappingURL=Syntax.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Syntax.d.ts","names":[],"sources":["../src/Syntax.ts"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;qBAkGa;GACV,gBAAgB,GAAG,GAAG,GAAG,UAAU,OAAO,MAAM,OAAO,GAAG,GAAG,GAAG,OAAO,OAAO,GAAG,GAAG,GAAG;GACvF,GAAG,GAAG,GAAG,UAAU,OAAO,MAAM,OAAO,GAAG,GAAG,GAAG,IAAI,eAAe,OAAO,GAAG,GAAG,GAAG;;;;;;;;;;;;;;;;;;;qBAwBzE;GACV,iBAAiB,GAAG,GAAG,GAAG,UAAU,OAAO,MAAM,OAAO,GAAG,GAAG,GAAG,OAAO,OAAO,GAAG,GAAG,GAAG;GACxF,GAAG,GAAG,GAAG,UAAU,OAAO,MAAM,OAAO,GAAG,GAAG,GAAG,IAAI,gBAAgB,OAAO,GAAG,GAAG,GAAG;;;;;;;;;;;;;;;;;;;;;;;qBAkC1E;GACV,gBAAgB,GAAG,GAAG,GAAG,UAAU,OAAO,MAAM,OAAO,GAAG,GAAG,GAAG,OAAO,OAAO,GAAG,GAAG,GAAG;GACvF,GAAG,GAAG,GAAG,UAAU,OAAO,MAAM,OAAO,GAAG,GAAG,GAAG,IAAI,eAAe,OAAO,GAAG,GAAG,GAAG;;;;;;;;qBAuBzE;;;;;;;;;iBAUI;WACN;WACA;WACA;;;;;;;;iBASM;;;;;WAKN;;;;;;;;;;;;WAYA;;;;;;;;iBASM,wBAAwB,WAAW;WACzC,SAAS,QAAQ,QAAQ;;UAG1B;WACC;WACA,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