@thomasfosterau/effect-parse 0.2.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 +44 -1
- package/dist/Ascii.d.ts +0 -2
- package/dist/Ascii.d.ts.map +1 -1
- package/dist/Ascii.js +6 -6
- package/dist/Ascii.js.map +1 -1
- package/dist/Binary.d.ts +0 -2
- package/dist/Binary.d.ts.map +1 -1
- package/dist/Binary.js +1 -2
- package/dist/Bits.d.ts +0 -2
- package/dist/Bits.d.ts.map +1 -1
- package/dist/Bits.js +2 -3
- package/dist/Bits.js.map +1 -1
- package/dist/Compiler.d.ts +0 -2
- package/dist/Compiler.d.ts.map +1 -1
- package/dist/Compiler.js +1 -2
- package/dist/Encoding.d.ts +0 -2
- package/dist/Encoding.d.ts.map +1 -1
- package/dist/Encoding.js +1 -2
- package/dist/Expression.d.ts +0 -2
- package/dist/Expression.d.ts.map +1 -1
- package/dist/Expression.js +61 -18
- package/dist/Expression.js.map +1 -1
- package/dist/Input.d.ts +80 -7
- package/dist/Input.d.ts.map +1 -1
- package/dist/Input.js +149 -18
- package/dist/Input.js.map +1 -1
- package/dist/Nom.d.ts +1 -3
- package/dist/Nom.d.ts.map +1 -1
- package/dist/Nom.js +1 -2
- package/dist/ParseError.d.ts +0 -2
- package/dist/ParseError.d.ts.map +1 -1
- package/dist/ParseError.js +6 -10
- package/dist/ParseError.js.map +1 -1
- package/dist/Parser.d.ts +2 -2
- package/dist/Parser.d.ts.map +1 -1
- package/dist/Parser.js +58 -32
- package/dist/Parser.js.map +1 -1
- package/dist/ParserSchema.d.ts +198 -2
- package/dist/ParserSchema.d.ts.map +1 -1
- package/dist/ParserSchema.js +646 -18
- package/dist/ParserSchema.js.map +1 -1
- package/dist/ParserStream.d.ts +0 -2
- package/dist/ParserStream.d.ts.map +1 -1
- package/dist/ParserStream.js +15 -9
- package/dist/ParserStream.js.map +1 -1
- package/dist/Syntax.d.ts +0 -2
- package/dist/Syntax.d.ts.map +1 -1
- package/dist/Syntax.js +13 -11
- package/dist/Syntax.js.map +1 -1
- package/dist/Text.d.ts +0 -2
- package/dist/Text.d.ts.map +1 -1
- package/dist/Text.js +1 -2
- package/dist/Token.d.ts +0 -2
- package/dist/Token.d.ts.map +1 -1
- package/dist/Token.js +1 -2
- package/dist/internal/compiler/closure.d.ts +5 -2
- package/dist/internal/compiler/closure.d.ts.map +1 -1
- package/dist/internal/compiler/closure.js +160 -92
- package/dist/internal/compiler/closure.js.map +1 -1
- package/dist/internal/compiler/entries.d.ts +0 -2
- package/dist/internal/compiler/entries.d.ts.map +1 -1
- package/dist/internal/compiler/entries.js +6 -7
- package/dist/internal/compiler/entries.js.map +1 -1
- package/dist/internal/compiler/first.d.ts +0 -2
- package/dist/internal/compiler/first.d.ts.map +1 -1
- package/dist/internal/compiler/first.js +10 -10
- package/dist/internal/compiler/first.js.map +1 -1
- package/dist/internal/compiler/jit.d.ts +0 -2
- package/dist/internal/compiler/jit.d.ts.map +1 -1
- package/dist/internal/compiler/jit.js +52 -51
- package/dist/internal/compiler/jit.js.map +1 -1
- package/dist/internal/compiler/registry.d.ts +0 -2
- package/dist/internal/compiler/registry.d.ts.map +1 -1
- package/dist/internal/compiler/registry.js +1 -2
- package/dist/internal/compiler/sets.d.ts +2 -2
- package/dist/internal/compiler/sets.d.ts.map +1 -1
- package/dist/internal/compiler/sets.js +8 -3
- package/dist/internal/compiler/sets.js.map +1 -1
- package/dist/internal/entries.d.ts +0 -2
- package/dist/internal/entries.d.ts.map +1 -1
- package/dist/internal/entries.js +1 -2
- package/dist/internal/key.d.ts +10 -0
- package/dist/internal/key.d.ts.map +1 -0
- package/dist/internal/key.js +11 -0
- package/dist/internal/key.js.map +1 -0
- package/dist/internal/node.d.ts +11 -4
- package/dist/internal/node.d.ts.map +1 -1
- package/dist/internal/node.js +15 -3
- package/dist/internal/node.js.map +1 -1
- package/dist/internal/numbers.d.ts +0 -2
- package/dist/internal/numbers.d.ts.map +1 -1
- package/dist/internal/numbers.js +1 -2
- package/dist/internal/resume.d.ts +5 -6
- package/dist/internal/resume.d.ts.map +1 -1
- package/dist/internal/resume.js +1 -2
- package/dist/internal/resume.js.map +1 -1
- package/dist/internal/run.d.ts +0 -2
- package/dist/internal/run.d.ts.map +1 -1
- package/dist/internal/run.js +2 -3
- package/dist/internal/run.js.map +1 -1
- package/dist/internal/stack.d.ts +0 -2
- package/dist/internal/stack.d.ts.map +1 -1
- package/dist/internal/stack.js +12 -3
- package/dist/internal/stack.js.map +1 -1
- package/dist/internal/syntax.d.ts +30 -19
- package/dist/internal/syntax.d.ts.map +1 -1
- package/dist/internal/syntax.js +74 -63
- package/dist/internal/syntax.js.map +1 -1
- package/dist/internal/text.d.ts +5 -2
- package/dist/internal/text.d.ts.map +1 -1
- package/dist/internal/text.js +14 -5
- package/dist/internal/text.js.map +1 -1
- package/dist/internal/ties.d.ts +28 -0
- package/dist/internal/ties.d.ts.map +1 -0
- package/dist/internal/ties.js +66 -0
- package/dist/internal/ties.js.map +1 -0
- package/dist/internal/tokens.d.ts +10 -9
- package/dist/internal/tokens.d.ts.map +1 -1
- package/dist/internal/tokens.js +4 -8
- package/dist/internal/tokens.js.map +1 -1
- package/package.json +6 -6
- package/src/Ascii.ts +6 -5
- package/src/Bits.ts +1 -1
- package/src/Expression.ts +27 -23
- package/src/Input.ts +157 -21
- package/src/ParseError.ts +10 -8
- package/src/Parser.ts +67 -32
- package/src/ParserSchema.ts +982 -23
- package/src/ParserStream.ts +20 -8
- package/src/Syntax.ts +12 -9
- package/src/internal/compiler/closure.ts +202 -90
- package/src/internal/compiler/entries.ts +14 -11
- package/src/internal/compiler/first.ts +9 -8
- package/src/internal/compiler/jit.ts +95 -74
- package/src/internal/compiler/sets.ts +7 -0
- package/src/internal/key.ts +11 -0
- package/src/internal/node.ts +19 -2
- package/src/internal/resume.ts +5 -4
- package/src/internal/run.ts +1 -1
- package/src/internal/stack.ts +6 -1
- package/src/internal/syntax.ts +80 -84
- package/src/internal/text.ts +24 -4
- package/src/internal/ties.ts +83 -0
- package/src/internal/tokens.ts +20 -13
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Identity keys: a parser that keeps state across parses (resume
|
|
3
|
+
* checkpoints, reusable syntax nodes) creates one `Key` when it is built and
|
|
4
|
+
* looks its state up by that key's reference.
|
|
5
|
+
*/
|
|
6
|
+
/** A per-parser identity, compared by reference. */
|
|
7
|
+
export declare class Key {
|
|
8
|
+
private readonly brand;
|
|
9
|
+
}
|
|
10
|
+
//# sourceMappingURL=key.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"key.d.ts","names":[],"sources":["../../src/internal/key.ts"],"mappings":";;;;;;qBAOa;mBAEc"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
// src/internal/key.ts
|
|
2
|
+
/**
|
|
3
|
+
* Identity keys: a parser that keeps state across parses (resume
|
|
4
|
+
* checkpoints, reusable syntax nodes) creates one `Key` when it is built and
|
|
5
|
+
* looks its state up by that key's reference.
|
|
6
|
+
*/
|
|
7
|
+
/** A per-parser identity, compared by reference. */
|
|
8
|
+
var Key = class {};
|
|
9
|
+
export { Key };
|
|
10
|
+
|
|
11
|
+
//# sourceMappingURL=key.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"key.js","names":[],"sources":["../../src/internal/key.ts"],"sourcesContent":["/**\n * Identity keys: a parser that keeps state across parses (resume\n * checkpoints, reusable syntax nodes) creates one `Key` when it is built and\n * looks its state up by that key's reference.\n */\n\n/** A per-parser identity, compared by reference. */\nexport class Key {\n // Nominal: an empty class would accept any object\n declare private readonly brand: void\n}\n"],"mappings":";;;;;;;AAOA,IAAa,MAAb,MAAiB,CAGjB"}
|
package/dist/internal/node.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
|
+
import * as Result from "effect/Result";
|
|
1
2
|
import { ErrMode, Input, State } from "../Input.js";
|
|
3
|
+
import * as Option from "effect/Option";
|
|
2
4
|
import { Encoding } from "../Encoding.js";
|
|
3
|
-
//#region src/internal/node.d.ts
|
|
4
5
|
/** The parts of a parser the compiler needs. */
|
|
5
6
|
export interface ParserLike {
|
|
6
7
|
readonly step: (state: State<any>) => unknown;
|
|
@@ -102,11 +103,11 @@ export type Node = {
|
|
|
102
103
|
} | {
|
|
103
104
|
readonly _tag: "TryMap";
|
|
104
105
|
readonly self: P;
|
|
105
|
-
readonly f: (a: any) => unknown
|
|
106
|
+
readonly f: (a: any) => Result.Result<unknown, unknown>;
|
|
106
107
|
} | {
|
|
107
108
|
readonly _tag: "FilterMap";
|
|
108
109
|
readonly self: P;
|
|
109
|
-
readonly f: (a: any) => unknown
|
|
110
|
+
readonly f: (a: any) => Option.Option<unknown>;
|
|
110
111
|
} | {
|
|
111
112
|
readonly _tag: "Filter";
|
|
112
113
|
readonly self: P;
|
|
@@ -248,8 +249,14 @@ export declare const bounds: (range: number | {
|
|
|
248
249
|
readonly min?: number | undefined;
|
|
249
250
|
readonly max?: number | undefined;
|
|
250
251
|
} | undefined) => Bounds;
|
|
252
|
+
/**
|
|
253
|
+
* Whether the compilers' one-pass float scan applies to `p`, the text
|
|
254
|
+
* parser of `Ascii.float` / `Text.float`: a `taken` (under any `expected`
|
|
255
|
+
* labels) in an encoding that `native` accepts, reading one ASCII-compatible
|
|
256
|
+
* unit at a time, or in no encoding at all.
|
|
257
|
+
*/
|
|
258
|
+
export declare const scansFloat: (p: ParserLike, native: (enc: Encoding<any>) => boolean) => boolean;
|
|
251
259
|
/** The child parsers of a node, in evaluation order. */
|
|
252
260
|
export declare const children: (node: Node) => ReadonlyArray<P>;
|
|
253
|
-
//#endregion
|
|
254
261
|
export {};
|
|
255
262
|
//# sourceMappingURL=node.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"node.d.ts","names":[],"sources":["../../src/internal/node.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"node.d.ts","names":[],"sources":["../../src/internal/node.ts"],"mappings":";;;;;iBAeiB;WACN,OAAO,OAAO;WACd;;KAGN,IAAI;KACJ,QAAQ,OAAO;;UAGV;WACC;WACA;;;;;;;KAQN,MAAM;YAEC;WAEG;WAAyB,MAAM;;WAC/B;WAA0B;;WAC1B;WAAuB;;WACvB;WAAuB,MAAM;;WAC7B;;WACA;;WACA;WAA0B,eAAe;;WAEzC;WAAsB,UAAU;;WAChC;WAA0B,SAAS;WAAgB;WAA4B,UAAU;;WACzF;WAAwB;WAAuB;WAA0B,UAAU;;WACnF;WAAuB;WAAwB,UAAU;;WACxD;WAA4B;WAAuB;WAA0B,UAAU;IAAQ;WAC/F;WAA4B,SAAS;WAAgB,UAAU;IAAQ;WACxE;WAAuB,UAAU;;WACjC;;WACA;WAAiC,UAAU;;WAC3C;WAA6B,UAAU;;WACvC;WAAsB,UAAU;;WAEhC;WACA,QAAQ;;WAER;WACA,QAAQ;;WAER;WACA,UAAU;;WAGV;WAAsB,MAAM;WAAY,IAAI;;WAC5C;WAAqB,MAAM;WAAY;;WACvC;WAAsB,MAAM;WAAY,IAAI;;WAC5C;WAAyB,MAAM;WAAY,IAAI,WAAW,OAAO;;WACjE;WAA4B,MAAM;WAAY,IAAI,WAAW,OAAO;;WACpE;WAAyB,MAAM;WAAY,YAAY;;WACvD;WAA0B,MAAM;WAAY,IAAI,WAAW;;WAE3D;WAAwB,MAAM;WAAY,UAAU;;WACpD;WAA4B,MAAM;;WAClC;WAAuB,MAAM;;WAC7B;WAA2B,MAAM;;WAEjC;WAAuB,MAAM;WAAY,MAAM;WAAkB,IAAI;;WACrE;WAA0B,MAAM;WAAY;;WAC5C;WAA2B,MAAM;WAAY;;WAC7C;WAA2B,MAAM;;WACjC;WAAyB,MAAM;;WAE/B;WAAsB,MAAM;;WAC5B;WAAgC,MAAM;WAAY;;WAClD;WAAuB,MAAM;;WAC7B;WAAsB,MAAM;;WAG5B;WACA,SAAS,cAAc;;WAEvB;;WAEA;WAAyB,MAAM;WAAgC,SAAS,cAAc;;WACtF;WAA0B,MAAM;WAAY,MAAM;WAAY,IAAI,QAAQ;;WAE1E;WAAsB,SAAS,cAAc;;WAE7C;WACA,UAAU;;WAEV,OAAO,SAAS,OAAO,aAAa;WACpC,WAAW;WACX,SAAS,aAAa;;WAGrB;WAAyB,MAAM;IAAM;WAEtC;WACA,MAAM;WACN;WACA,IAAI,UAAU;;WAEd,SAAS;WACT;IACP;WACQ;WAA6B,MAAM;WAAY,KAAK;IAAM;WAC1D;WAA4B,MAAM;WAAY,WAAW;IAAM;WAEhE;WACA,MAAM;WACN,WAAW;WACX,KAAK,QAAQ,QAAQ;WACrB;;WAGA;;WACA;WAA0B,MAAM;;WAChC;WAA8B,MAAM;WAAY,SAAS;;WACzD;WAA6B,MAAM;WAAY,SAAS;;WACxD;WAAwB,MAAM;WAAY;;;;WAG1C;WACA,MAAM;;WAEN;WACA;;YAGH,MAAM;YAEN,OAAO,UAAU,OAAO,QAAQ;WAAiB,MAAM;;;qBAGtD;;qBAGA,SAAU,GAAG,eAAa;;qBAG1B,SACX;WAA2B;WAAmC;kBAC7D;;;;;;;qBAYU,aAAc,GAAG,YAAY,SAAS,KAAK;;qBAU3C,WAAY,MAAM,SAAO,cAAc"}
|
package/dist/internal/node.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as Predicate from "effect/Predicate";
|
|
2
|
-
|
|
2
|
+
// src/internal/node.ts
|
|
3
3
|
/**
|
|
4
4
|
* Descriptions of parsers, recorded next to their steps so that parsers can
|
|
5
5
|
* be compiled (see `docs/DESIGN.md`, "Compiled parsers").
|
|
@@ -30,6 +30,19 @@ const bounds = (range) => {
|
|
|
30
30
|
max: range.max ?? Infinity
|
|
31
31
|
};
|
|
32
32
|
};
|
|
33
|
+
/**
|
|
34
|
+
* Whether the compilers' one-pass float scan applies to `p`, the text
|
|
35
|
+
* parser of `Ascii.float` / `Text.float`: a `taken` (under any `expected`
|
|
36
|
+
* labels) in an encoding that `native` accepts, reading one ASCII-compatible
|
|
37
|
+
* unit at a time, or in no encoding at all.
|
|
38
|
+
*/
|
|
39
|
+
const scansFloat = (p, native) => {
|
|
40
|
+
let taken = nodeOf(p);
|
|
41
|
+
while (Predicate.isTagged(taken, "Expected")) taken = nodeOf(taken.self);
|
|
42
|
+
if (!Predicate.isTagged(taken, "Taken")) return false;
|
|
43
|
+
const enc = taken.encoding;
|
|
44
|
+
return enc === void 0 || native(enc) && enc.unit === 1 && enc.asciiCompatible;
|
|
45
|
+
};
|
|
33
46
|
/** The child parsers of a node, in evaluation order. */
|
|
34
47
|
const children = (node) => {
|
|
35
48
|
switch (node._tag) {
|
|
@@ -78,7 +91,6 @@ const children = (node) => {
|
|
|
78
91
|
default: return [];
|
|
79
92
|
}
|
|
80
93
|
};
|
|
81
|
-
|
|
82
|
-
export { NodeId, bounds, children, nodeOf };
|
|
94
|
+
export { NodeId, bounds, children, nodeOf, scansFloat };
|
|
83
95
|
|
|
84
96
|
//# sourceMappingURL=node.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"node.js","names":[],"sources":["../../src/internal/node.ts"],"sourcesContent":["/**\n * Descriptions of parsers, recorded next to their steps so that parsers can\n * be compiled (see `docs/DESIGN.md`, \"Compiled parsers\").\n *\n * Nodes refer to their child parsers rather than to child nodes, so a\n * child's own step is always at hand for fallback, and recursion through\n * `Suspend` is just a reference.\n */\nimport * as Predicate from \"effect/Predicate\"\nimport type { Encoding } from \"../Encoding.js\"\nimport type { ErrMode, Input, State } from \"../Input.js\"\n\n/** The parts of a parser the compiler needs. */\nexport interface ParserLike {\n readonly step: (state: State<any>) => unknown\n readonly name: string | undefined\n}\n\ntype P = ParserLike\ntype Step = (state: State<any>) => unknown\n\n/** A repetition range, normalized: `max` may be `Infinity`. */\ninterface Bounds {\n readonly min: number\n readonly max: number\n}\n\n/**\n * For token nodes: `undefined` for the `Token`/`Ascii` parsers (code points\n * of strings with lenient surrogates, bytes, or array elements), or the\n * encoding of a `Text` parser.\n */\ntype Enc = Encoding<any> | undefined\n\nexport type Node =\n // Constants\n | { readonly _tag: \"Opaque\"; readonly step: Step }\n | { readonly _tag: \"Succeed\"; readonly value: unknown }\n | { readonly _tag: \"Sync\"; readonly evaluate: () => unknown }\n | { readonly _tag: \"Fail\"; readonly mode: ErrMode }\n | { readonly _tag: \"Eof\" }\n | { readonly _tag: \"Location\" }\n | { readonly _tag: \"Suspend\"; readonly resolve: () => P }\n // Tokens\n | { readonly _tag: \"Any\"; readonly encoding: Enc }\n | { readonly _tag: \"Literal\"; readonly literal: Input; readonly caseless: boolean; readonly encoding: Enc }\n | { readonly _tag: \"OneOf\"; readonly set: unknown; readonly negate: boolean; readonly encoding: Enc }\n | { readonly _tag: \"Take\"; readonly count: number; readonly encoding: Enc }\n | ({ readonly _tag: \"TakeWhile\"; readonly set: unknown; readonly negate: boolean; readonly encoding: Enc } & Bounds)\n | ({ readonly _tag: \"TakeUntil\"; readonly literal: Input; readonly encoding: Enc } & Bounds)\n | { readonly _tag: \"Rest\"; readonly encoding: Enc }\n | { readonly _tag: \"RestLen\" }\n | { readonly _tag: \"TillLineEnding\"; readonly encoding: Enc }\n | { readonly _tag: \"Identifier\"; readonly encoding: Enc }\n | { readonly _tag: \"Bom\"; readonly encoding: Enc }\n | {\n readonly _tag: \"Escaped\"\n readonly normal: P\n /** The control character, as a code point (or a byte / unit for `Ascii`). */\n readonly control: number\n readonly escape: P\n /** `takeEscaped`: return the raw slice instead of the unescaped text. */\n readonly raw: boolean\n readonly encoding: Enc\n }\n // Mapping\n | { readonly _tag: \"Map\"; readonly self: P; readonly f: (a: any) => unknown }\n | { readonly _tag: \"As\"; readonly self: P; readonly value: unknown }\n | { readonly _tag: \"Tap\"; readonly self: P; readonly f: (a: any) => void }\n | { readonly _tag: \"TryMap\"; readonly self: P; readonly f: (a: any) => unknown }\n | { readonly _tag: \"FilterMap\"; readonly self: P; readonly f: (a: any) => unknown }\n | { readonly _tag: \"Filter\"; readonly self: P; readonly predicate: (a: any) => boolean }\n | { readonly _tag: \"FlatMap\"; readonly self: P; readonly f: (a: any) => P }\n // Consumed input\n | { readonly _tag: \"Taken\"; readonly self: P; readonly encoding: Enc }\n | { readonly _tag: \"WithTaken\"; readonly self: P }\n | { readonly _tag: \"Span\"; readonly self: P }\n | { readonly _tag: \"WithSpan\"; readonly self: P }\n // Errors\n | { readonly _tag: \"Mode\"; readonly self: P; readonly from: ErrMode; readonly to: ErrMode }\n | { readonly _tag: \"Context\"; readonly self: P; readonly label: string }\n | { readonly _tag: \"Expected\"; readonly self: P; readonly description: string }\n | { readonly _tag: \"MapError\"; readonly self: P }\n | { readonly _tag: \"OrFail\"; readonly self: P }\n // Control\n | { readonly _tag: \"Opt\"; readonly self: P }\n | { readonly _tag: \"OrElseSucceed\"; readonly self: P; readonly value: () => unknown }\n | { readonly _tag: \"Peek\"; readonly self: P }\n | { readonly _tag: \"Not\"; readonly self: P }\n // Sequencing\n | {\n readonly _tag: \"Seq\"\n readonly parsers: ReadonlyArray<P>\n /** Which outputs are kept: all (a tuple), one index, or a pair of indices. */\n readonly output: \"tuple\" | number | readonly [number, number]\n }\n | { readonly _tag: \"Struct\"; readonly keys: ReadonlyArray<string>; readonly parsers: ReadonlyArray<P> }\n | { readonly _tag: \"ZipWith\"; readonly self: P; readonly that: P; readonly f: (a: any, b: any) => unknown }\n // Choice\n | { readonly _tag: \"Alt\"; readonly parsers: ReadonlyArray<P> }\n | {\n readonly _tag: \"Dispatch\"\n readonly selector: P\n /** A record of cases, when `dispatch` was given one. */\n readonly cases: Readonly<Record<PropertyKey, P>> | undefined\n readonly otherwise: P | undefined\n readonly choose: (key: any) => P | undefined\n }\n // Repetition\n | ({ readonly _tag: \"Repeat\"; readonly self: P } & Bounds)\n | ({\n readonly _tag: \"Fold\"\n readonly self: P\n readonly init: () => unknown\n readonly f: (acc: any, a: any) => unknown\n /** Stops the repetition once false of the accumulator (after `min` elements). */\n readonly while: ((acc: any) => boolean) | undefined\n readonly name: string\n } & Bounds)\n | ({ readonly _tag: \"RepeatTill\"; readonly self: P; readonly end: P } & Bounds)\n | ({ readonly _tag: \"Separated\"; readonly self: P; readonly separator: P } & Bounds)\n | {\n readonly _tag: \"SeparatedFold\"\n readonly self: P\n readonly separator: P\n readonly op: (l: any, s: any, r: any) => unknown\n readonly right: boolean\n }\n // Services, recovery, debugging\n | { readonly _tag: \"Service\" }\n | { readonly _tag: \"Provide\"; readonly self: P }\n | { readonly _tag: \"ResumeAfter\"; readonly self: P; readonly recover: P }\n | { readonly _tag: \"RetryAfter\"; readonly self: P; readonly recover: P }\n | { readonly _tag: \"Trace\"; readonly self: P; readonly name: string }\n /** `Syntax.node`, `Syntax.token` and `Syntax.field`: identities outside `Syntax` parses. */\n | {\n readonly _tag: \"Syntax\"\n readonly self: P\n /** The node kind, or `undefined` for a field. */\n readonly kind: string | undefined\n readonly named: boolean\n }\n\nexport type Tag = Node[\"_tag\"]\n\nexport type NodeOf<T extends Tag> = Extract<Node, { readonly _tag: T }>\n\n/** Where a parser's description is stored. */\nexport const NodeId: unique symbol = /*#__PURE__*/ Symbol.for(\"effect-parse/Parser/node\")\n\n/** The description of a parser: `Opaque` when it has none. */\nexport const nodeOf = (p: ParserLike): Node => (p as any)[NodeId] ?? { _tag: \"Opaque\", step: p.step }\n\n/** Normalizes a range, as `repeat`, `takeWhile`, ... do. */\nexport const bounds = (\n range: number | { readonly min?: number | undefined; readonly max?: number | undefined } | undefined\n): Bounds => {\n if (range === undefined) return { min: 0, max: Infinity }\n if (Predicate.isNumber(range)) return { min: range, max: range }\n return { min: range.min ?? 0, max: range.max ?? Infinity }\n}\n\n/** The child parsers of a node, in evaluation order. */\nexport const children = (node: Node): ReadonlyArray<P> => {\n switch (node._tag) {\n case \"Escaped\":\n return [node.normal, node.escape]\n case \"Map\":\n case \"As\":\n case \"Tap\":\n case \"TryMap\":\n case \"FilterMap\":\n case \"Filter\":\n case \"FlatMap\":\n case \"Taken\":\n case \"WithTaken\":\n case \"Span\":\n case \"WithSpan\":\n case \"Mode\":\n case \"Context\":\n case \"Expected\":\n case \"MapError\":\n case \"OrFail\":\n case \"Opt\":\n case \"OrElseSucceed\":\n case \"Peek\":\n case \"Not\":\n case \"Repeat\":\n case \"Fold\":\n case \"Provide\":\n case \"Trace\":\n case \"Syntax\":\n return [node.self]\n case \"ResumeAfter\":\n case \"RetryAfter\":\n return [node.self, node.recover]\n case \"Seq\":\n case \"Struct\":\n case \"Alt\":\n return node.parsers\n case \"ZipWith\":\n return [node.self, node.that]\n case \"Dispatch\": {\n const out: Array<P> = [node.selector]\n if (node.cases !== undefined) {\n for (const key of Reflect.ownKeys(node.cases)) out.push(node.cases[key as any])\n }\n if (node.otherwise !== undefined) out.push(node.otherwise)\n return out\n }\n case \"RepeatTill\":\n return [node.self, node.end]\n case \"Separated\":\n case \"SeparatedFold\":\n return [node.self, node.separator]\n case \"Suspend\":\n return [node.resolve()]\n default:\n return []\n }\n}\n"],"mappings":";;;;;;;;;;;AAoJA,MAAa,SAAsC,qBAAO,IAAI,0BAA0B;;AAGxF,MAAa,UAAU,MAAyB,EAAU,WAAW;CAAE,MAAM;CAAU,MAAM,EAAE;AAAK;;AAGpG,MAAa,UACX,UACW;CACX,IAAI,UAAU,KAAA,GAAW,OAAO;EAAE,KAAK;EAAG,KAAK;CAAS;CACxD,IAAI,UAAU,SAAS,KAAK,GAAG,OAAO;EAAE,KAAK;EAAO,KAAK;CAAM;CAC/D,OAAO;EAAE,KAAK,MAAM,OAAO;EAAG,KAAK,MAAM,OAAO;CAAS;AAC3D;;AAGA,MAAa,YAAY,SAAiC;CACxD,QAAQ,KAAK,MAAb;EACE,KAAK,WACH,OAAO,CAAC,KAAK,QAAQ,KAAK,MAAM;EAClC,KAAK;EACL,KAAK;EACL,KAAK;EACL,KAAK;EACL,KAAK;EACL,KAAK;EACL,KAAK;EACL,KAAK;EACL,KAAK;EACL,KAAK;EACL,KAAK;EACL,KAAK;EACL,KAAK;EACL,KAAK;EACL,KAAK;EACL,KAAK;EACL,KAAK;EACL,KAAK;EACL,KAAK;EACL,KAAK;EACL,KAAK;EACL,KAAK;EACL,KAAK;EACL,KAAK;EACL,KAAK,UACH,OAAO,CAAC,KAAK,IAAI;EACnB,KAAK;EACL,KAAK,cACH,OAAO,CAAC,KAAK,MAAM,KAAK,OAAO;EACjC,KAAK;EACL,KAAK;EACL,KAAK,OACH,OAAO,KAAK;EACd,KAAK,WACH,OAAO,CAAC,KAAK,MAAM,KAAK,IAAI;EAC9B,KAAK,YAAY;GACf,MAAM,MAAgB,CAAC,KAAK,QAAQ;GACpC,IAAI,KAAK,UAAU,KAAA,GACjB,KAAK,MAAM,OAAO,QAAQ,QAAQ,KAAK,KAAK,GAAG,IAAI,KAAK,KAAK,MAAM,IAAW;GAEhF,IAAI,KAAK,cAAc,KAAA,GAAW,IAAI,KAAK,KAAK,SAAS;GACzD,OAAO;EACT;EACA,KAAK,cACH,OAAO,CAAC,KAAK,MAAM,KAAK,GAAG;EAC7B,KAAK;EACL,KAAK,iBACH,OAAO,CAAC,KAAK,MAAM,KAAK,SAAS;EACnC,KAAK,WACH,OAAO,CAAC,KAAK,QAAQ,CAAC;EACxB,SACE,OAAO,CAAC;CACZ;AACF"}
|
|
1
|
+
{"version":3,"file":"node.js","names":[],"sources":["../../src/internal/node.ts"],"sourcesContent":["/**\n * Descriptions of parsers, recorded next to their steps so that parsers can\n * be compiled (see `docs/DESIGN.md`, \"Compiled parsers\").\n *\n * Nodes refer to their child parsers rather than to child nodes, so a\n * child's own step is always at hand for fallback, and recursion through\n * `Suspend` is just a reference.\n */\nimport * as Predicate from \"effect/Predicate\"\nimport type * as Option from \"effect/Option\"\nimport type * as Result from \"effect/Result\"\nimport type { Encoding } from \"../Encoding.js\"\nimport type { ErrMode, Input, State } from \"../Input.js\"\n\n/** The parts of a parser the compiler needs. */\nexport interface ParserLike {\n readonly step: (state: State<any>) => unknown\n readonly name: string | undefined\n}\n\ntype P = ParserLike\ntype Step = (state: State<any>) => unknown\n\n/** A repetition range, normalized: `max` may be `Infinity`. */\ninterface Bounds {\n readonly min: number\n readonly max: number\n}\n\n/**\n * For token nodes: `undefined` for the `Token`/`Ascii` parsers (code points\n * of strings with lenient surrogates, bytes, or array elements), or the\n * encoding of a `Text` parser.\n */\ntype Enc = Encoding<any> | undefined\n\nexport type Node =\n // Constants\n | { readonly _tag: \"Opaque\"; readonly step: Step }\n | { readonly _tag: \"Succeed\"; readonly value: unknown }\n | { readonly _tag: \"Sync\"; readonly evaluate: () => unknown }\n | { readonly _tag: \"Fail\"; readonly mode: ErrMode }\n | { readonly _tag: \"Eof\" }\n | { readonly _tag: \"Location\" }\n | { readonly _tag: \"Suspend\"; readonly resolve: () => P }\n // Tokens\n | { readonly _tag: \"Any\"; readonly encoding: Enc }\n | { readonly _tag: \"Literal\"; readonly literal: Input; readonly caseless: boolean; readonly encoding: Enc }\n | { readonly _tag: \"OneOf\"; readonly set: unknown; readonly negate: boolean; readonly encoding: Enc }\n | { readonly _tag: \"Take\"; readonly count: number; readonly encoding: Enc }\n | ({ readonly _tag: \"TakeWhile\"; readonly set: unknown; readonly negate: boolean; readonly encoding: Enc } & Bounds)\n | ({ readonly _tag: \"TakeUntil\"; readonly literal: Input; readonly encoding: Enc } & Bounds)\n | { readonly _tag: \"Rest\"; readonly encoding: Enc }\n | { readonly _tag: \"RestLen\" }\n | { readonly _tag: \"TillLineEnding\"; readonly encoding: Enc }\n | { readonly _tag: \"Identifier\"; readonly encoding: Enc }\n | { readonly _tag: \"Bom\"; readonly encoding: Enc }\n | {\n readonly _tag: \"Escaped\"\n readonly normal: P\n /** The control character, as a code point (or a byte / unit for `Ascii`). */\n readonly control: number\n readonly escape: P\n /** `takeEscaped`: return the raw slice instead of the unescaped text. */\n readonly raw: boolean\n readonly encoding: Enc\n }\n // Mapping\n | { readonly _tag: \"Map\"; readonly self: P; readonly f: (a: any) => unknown }\n | { readonly _tag: \"As\"; readonly self: P; readonly value: unknown }\n | { readonly _tag: \"Tap\"; readonly self: P; readonly f: (a: any) => void }\n | { readonly _tag: \"TryMap\"; readonly self: P; readonly f: (a: any) => Result.Result<unknown, unknown> }\n | { readonly _tag: \"FilterMap\"; readonly self: P; readonly f: (a: any) => Option.Option<unknown> }\n | { readonly _tag: \"Filter\"; readonly self: P; readonly predicate: (a: any) => boolean }\n | { readonly _tag: \"FlatMap\"; readonly self: P; readonly f: (a: any) => P }\n // Consumed input\n | { readonly _tag: \"Taken\"; readonly self: P; readonly encoding: Enc }\n | { readonly _tag: \"WithTaken\"; readonly self: P }\n | { readonly _tag: \"Span\"; readonly self: P }\n | { readonly _tag: \"WithSpan\"; readonly self: P }\n // Errors\n | { readonly _tag: \"Mode\"; readonly self: P; readonly from: ErrMode; readonly to: ErrMode }\n | { readonly _tag: \"Context\"; readonly self: P; readonly label: string }\n | { readonly _tag: \"Expected\"; readonly self: P; readonly description: string }\n | { readonly _tag: \"MapError\"; readonly self: P }\n | { readonly _tag: \"OrFail\"; readonly self: P }\n // Control\n | { readonly _tag: \"Opt\"; readonly self: P }\n | { readonly _tag: \"OrElseSucceed\"; readonly self: P; readonly value: () => unknown }\n | { readonly _tag: \"Peek\"; readonly self: P }\n | { readonly _tag: \"Not\"; readonly self: P }\n // Sequencing\n | {\n readonly _tag: \"Seq\"\n readonly parsers: ReadonlyArray<P>\n /** Which outputs are kept: all (a tuple), one index, or a pair of indices. */\n readonly output: \"tuple\" | number | readonly [number, number]\n }\n | { readonly _tag: \"Struct\"; readonly keys: ReadonlyArray<string>; readonly parsers: ReadonlyArray<P> }\n | { readonly _tag: \"ZipWith\"; readonly self: P; readonly that: P; readonly f: (a: any, b: any) => unknown }\n // Choice\n | { readonly _tag: \"Alt\"; readonly parsers: ReadonlyArray<P> }\n | {\n readonly _tag: \"Dispatch\"\n readonly selector: P\n /** A record of cases, when `dispatch` was given one. */\n readonly cases: Readonly<Record<PropertyKey, P>> | undefined\n readonly otherwise: P | undefined\n readonly choose: (key: any) => P | undefined\n }\n // Repetition\n | ({ readonly _tag: \"Repeat\"; readonly self: P } & Bounds)\n | ({\n readonly _tag: \"Fold\"\n readonly self: P\n readonly init: () => unknown\n readonly f: (acc: any, a: any) => unknown\n /** Stops the repetition once false of the accumulator (after `min` elements). */\n readonly while: ((acc: any) => boolean) | undefined\n readonly name: string\n } & Bounds)\n | ({ readonly _tag: \"RepeatTill\"; readonly self: P; readonly end: P } & Bounds)\n | ({ readonly _tag: \"Separated\"; readonly self: P; readonly separator: P } & Bounds)\n | {\n readonly _tag: \"SeparatedFold\"\n readonly self: P\n readonly separator: P\n readonly op: (l: any, s: any, r: any) => unknown\n readonly right: boolean\n }\n // Services, recovery, debugging\n | { readonly _tag: \"Service\" }\n | { readonly _tag: \"Provide\"; readonly self: P }\n | { readonly _tag: \"ResumeAfter\"; readonly self: P; readonly recover: P }\n | { readonly _tag: \"RetryAfter\"; readonly self: P; readonly recover: P }\n | { readonly _tag: \"Trace\"; readonly self: P; readonly name: string }\n /** `Syntax.node`, `Syntax.token` and `Syntax.field`: identities outside `Syntax` parses. */\n | {\n readonly _tag: \"Syntax\"\n readonly self: P\n /** The node kind, or `undefined` for a field. */\n readonly kind: string | undefined\n readonly named: boolean\n }\n\nexport type Tag = Node[\"_tag\"]\n\nexport type NodeOf<T extends Tag> = Extract<Node, { readonly _tag: T }>\n\n/** Where a parser's description is stored. */\nexport const NodeId: unique symbol = /*#__PURE__*/ Symbol.for(\"effect-parse/Parser/node\")\n\n/** The description of a parser: `Opaque` when it has none. */\nexport const nodeOf = (p: ParserLike): Node => (p as any)[NodeId] ?? { _tag: \"Opaque\", step: p.step }\n\n/** Normalizes a range, as `repeat`, `takeWhile`, ... do. */\nexport const bounds = (\n range: number | { readonly min?: number | undefined; readonly max?: number | undefined } | undefined\n): Bounds => {\n if (range === undefined) return { min: 0, max: Infinity }\n if (Predicate.isNumber(range)) return { min: range, max: range }\n return { min: range.min ?? 0, max: range.max ?? Infinity }\n}\n\n/**\n * Whether the compilers' one-pass float scan applies to `p`, the text\n * parser of `Ascii.float` / `Text.float`: a `taken` (under any `expected`\n * labels) in an encoding that `native` accepts, reading one ASCII-compatible\n * unit at a time, or in no encoding at all.\n */\nexport const scansFloat = (p: ParserLike, native: (enc: Encoding<any>) => boolean): boolean => {\n let taken = nodeOf(p)\n while (Predicate.isTagged(taken, \"Expected\")) taken = nodeOf(taken.self)\n if (!Predicate.isTagged(taken, \"Taken\")) return false\n const enc = taken.encoding\n // Decimal notation is ASCII, which these encodings read unit by unit\n return enc === undefined || (native(enc) && enc.unit === 1 && enc.asciiCompatible)\n}\n\n/** The child parsers of a node, in evaluation order. */\nexport const children = (node: Node): ReadonlyArray<P> => {\n switch (node._tag) {\n case \"Escaped\":\n return [node.normal, node.escape]\n case \"Map\":\n case \"As\":\n case \"Tap\":\n case \"TryMap\":\n case \"FilterMap\":\n case \"Filter\":\n case \"FlatMap\":\n case \"Taken\":\n case \"WithTaken\":\n case \"Span\":\n case \"WithSpan\":\n case \"Mode\":\n case \"Context\":\n case \"Expected\":\n case \"MapError\":\n case \"OrFail\":\n case \"Opt\":\n case \"OrElseSucceed\":\n case \"Peek\":\n case \"Not\":\n case \"Repeat\":\n case \"Fold\":\n case \"Provide\":\n case \"Trace\":\n case \"Syntax\":\n return [node.self]\n case \"ResumeAfter\":\n case \"RetryAfter\":\n return [node.self, node.recover]\n case \"Seq\":\n case \"Struct\":\n case \"Alt\":\n return node.parsers\n case \"ZipWith\":\n return [node.self, node.that]\n case \"Dispatch\": {\n const out: Array<P> = [node.selector]\n if (node.cases !== undefined) {\n for (const key of Reflect.ownKeys(node.cases)) out.push(node.cases[key as any])\n }\n if (node.otherwise !== undefined) out.push(node.otherwise)\n return out\n }\n case \"RepeatTill\":\n return [node.self, node.end]\n case \"Separated\":\n case \"SeparatedFold\":\n return [node.self, node.separator]\n case \"Suspend\":\n return [node.resolve()]\n default:\n return []\n }\n}\n"],"mappings":";;;;;;;;;;;AAsJA,MAAa,SAAsC,qBAAO,IAAI,0BAA0B;;AAGxF,MAAa,UAAU,MAAyB,EAAU,WAAW;CAAE,MAAM;CAAU,MAAM,EAAE;AAAK;;AAGpG,MAAa,UACX,UACW;CACX,IAAI,UAAU,KAAA,GAAW,OAAO;EAAE,KAAK;EAAG,KAAK;CAAS;CACxD,IAAI,UAAU,SAAS,KAAK,GAAG,OAAO;EAAE,KAAK;EAAO,KAAK;CAAM;CAC/D,OAAO;EAAE,KAAK,MAAM,OAAO;EAAG,KAAK,MAAM,OAAO;CAAS;AAC3D;;;;;;;AAQA,MAAa,cAAc,GAAe,WAAqD;CAC7F,IAAI,QAAQ,OAAO,CAAC;CACpB,OAAO,UAAU,SAAS,OAAO,UAAU,GAAG,QAAQ,OAAO,MAAM,IAAI;CACvE,IAAI,CAAC,UAAU,SAAS,OAAO,OAAO,GAAG,OAAO;CAChD,MAAM,MAAM,MAAM;CAElB,OAAO,QAAQ,KAAA,KAAc,OAAO,GAAG,KAAK,IAAI,SAAS,KAAK,IAAI;AACpE;;AAGA,MAAa,YAAY,SAAiC;CACxD,QAAQ,KAAK,MAAb;EACE,KAAK,WACH,OAAO,CAAC,KAAK,QAAQ,KAAK,MAAM;EAClC,KAAK;EACL,KAAK;EACL,KAAK;EACL,KAAK;EACL,KAAK;EACL,KAAK;EACL,KAAK;EACL,KAAK;EACL,KAAK;EACL,KAAK;EACL,KAAK;EACL,KAAK;EACL,KAAK;EACL,KAAK;EACL,KAAK;EACL,KAAK;EACL,KAAK;EACL,KAAK;EACL,KAAK;EACL,KAAK;EACL,KAAK;EACL,KAAK;EACL,KAAK;EACL,KAAK;EACL,KAAK,UACH,OAAO,CAAC,KAAK,IAAI;EACnB,KAAK;EACL,KAAK,cACH,OAAO,CAAC,KAAK,MAAM,KAAK,OAAO;EACjC,KAAK;EACL,KAAK;EACL,KAAK,OACH,OAAO,KAAK;EACd,KAAK,WACH,OAAO,CAAC,KAAK,MAAM,KAAK,IAAI;EAC9B,KAAK,YAAY;GACf,MAAM,MAAgB,CAAC,KAAK,QAAQ;GACpC,IAAI,KAAK,UAAU,KAAA,GACjB,KAAK,MAAM,OAAO,QAAQ,QAAQ,KAAK,KAAK,GAAG,IAAI,KAAK,KAAK,MAAM,IAAW;GAEhF,IAAI,KAAK,cAAc,KAAA,GAAW,IAAI,KAAK,KAAK,SAAS;GACzD,OAAO;EACT;EACA,KAAK,cACH,OAAO,CAAC,KAAK,MAAM,KAAK,GAAG;EAC7B,KAAK;EACL,KAAK,iBACH,OAAO,CAAC,KAAK,MAAM,KAAK,SAAS;EACnC,KAAK,WACH,OAAO,CAAC,KAAK,QAAQ,CAAC;EACxB,SACE,OAAO,CAAC;CACZ;AACF"}
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { Fail, Input } from "../Input.js";
|
|
2
|
-
//#region src/internal/numbers.d.ts
|
|
3
2
|
/** The text of an input slice: as is for a string, Latin-1 for bytes, joined for tokens. */
|
|
4
3
|
export declare const toText: (s: Input) => string;
|
|
5
4
|
/** The value of the text matched by `Ascii.float` and `Text.float`. */
|
|
@@ -36,5 +35,4 @@ export declare const floatScan: {
|
|
|
36
35
|
export declare const scanFloatString: (s: string, i: number, end: number) => number | Fail | undefined;
|
|
37
36
|
/** {@link scanFloatString} on bytes, or the units of an ASCII compatible encoding. */
|
|
38
37
|
export declare const scanFloatBytes: (b: Uint8Array, i: number, end: number) => number | Fail | undefined;
|
|
39
|
-
//#endregion
|
|
40
38
|
//# sourceMappingURL=numbers.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"numbers.d.ts","names":[],"sources":["../../src/internal/numbers.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"numbers.d.ts","names":[],"sources":["../../src/internal/numbers.ts"],"mappings":";;qBAUa,SAAU,GAAG;;qBAIb,UAAW,GAAG;;;;;;qBAmBd,YAAU;;qBAGV,YAAa,kBAAkB,GAAG,MAAI;;;;;;qBAatC;;;;;;;;;;;;;;;;qBAiFA,kBAAmB,WAAW,WAAW,yBAAuB;;qBAmFhE,iBAAkB,GAAG,YAAY,WAAW,yBAAuB"}
|
package/dist/internal/numbers.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import * as Predicate from "effect/Predicate";
|
|
2
2
|
import { Fail } from "../Input.js";
|
|
3
3
|
import { latin1 } from "./text.js";
|
|
4
|
-
|
|
4
|
+
// src/internal/numbers.ts
|
|
5
5
|
/**
|
|
6
6
|
* Number conversions shared by the `Ascii` and `Text` parsers and the
|
|
7
7
|
* compilers.
|
|
@@ -266,7 +266,6 @@ const scanFloatBytes = (b, i, end) => {
|
|
|
266
266
|
};
|
|
267
267
|
/** The text of ASCII bytes. */
|
|
268
268
|
const asciiText = (b, start, end) => String.fromCharCode.apply(null, b.subarray(start, end));
|
|
269
|
-
//#endregion
|
|
270
269
|
export { floatScan, floatText, floatTexts, scanFloatBytes, scanFloatString, toFloat, toText };
|
|
271
270
|
|
|
272
271
|
//# sourceMappingURL=numbers.js.map
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { State } from "../Input.js";
|
|
2
|
-
|
|
2
|
+
import { Key } from "./key.js";
|
|
3
3
|
/** The checkpoints of a resumable parse. */
|
|
4
|
-
export type Checkpoints = Map<
|
|
4
|
+
export type Checkpoints = Map<Key, Map<number, unknown>>;
|
|
5
5
|
/** Takes (and removes) the checkpoint of `key` entered at `offset`, if any. */
|
|
6
|
-
export declare const take: (state: State<any>, key:
|
|
6
|
+
export declare const take: (state: State<any>, key: Key, offset: number) => unknown;
|
|
7
7
|
/** The result of a repetition that completed, and where it ended. */
|
|
8
8
|
export declare class Done {
|
|
9
9
|
readonly value: unknown;
|
|
@@ -14,8 +14,7 @@ export declare class Done {
|
|
|
14
14
|
* Returns `value`, the result of a repetition entered at `entry`; when the
|
|
15
15
|
* repetition was resumed from a checkpoint, records it as {@link Done}.
|
|
16
16
|
*/
|
|
17
|
-
export declare const done: <A>(state: State<any>, key:
|
|
17
|
+
export declare const done: <A>(state: State<any>, key: Key, entry: number, resumed: boolean, value: A) => A;
|
|
18
18
|
/** Records the checkpoint of `key` entered at `offset`. */
|
|
19
|
-
export declare const save: (state: State<any>, key:
|
|
20
|
-
//#endregion
|
|
19
|
+
export declare const save: (state: State<any>, key: Key, offset: number, checkpoint: unknown) => void;
|
|
21
20
|
//# sourceMappingURL=resume.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"resume.d.ts","names":[],"sources":["../../src/internal/resume.ts"],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"resume.d.ts","names":[],"sources":["../../src/internal/resume.ts"],"mappings":";;;YAwBY,cAAc,IAAI,KAAK;;qBAGtB,OAAQ,OAAO,YAAY,KAAK,KAAK;;qBASrC;WAEA;WACA;EADA,YAAA,gBACA;;;;;;qBAQA,OAAQ,GAAG,OAAO,YAAY,KAAK,KAAK,eAAe,kBAAkB,OAAO,MAAI;;qBAMpF,OAAQ,OAAO,YAAY,KAAK,KAAK,gBAAgB"}
|
package/dist/internal/resume.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
// src/internal/resume.ts
|
|
2
2
|
/** Takes (and removes) the checkpoint of `key` entered at `offset`, if any. */
|
|
3
3
|
const take = (state, key, offset) => {
|
|
4
4
|
const byKey = state.resume?.get(key);
|
|
@@ -32,7 +32,6 @@ const save = (state, key, offset, checkpoint) => {
|
|
|
32
32
|
if (byKey === void 0) resume.set(key, byKey = /* @__PURE__ */ new Map());
|
|
33
33
|
byKey.set(offset, checkpoint);
|
|
34
34
|
};
|
|
35
|
-
//#endregion
|
|
36
35
|
export { Done, done, save, take };
|
|
37
36
|
|
|
38
37
|
//# sourceMappingURL=resume.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"resume.js","names":[],"sources":["../../src/internal/resume.ts"],"sourcesContent":["/**\n * Checkpoints for resumable (streaming) parses.\n *\n * In partial mode a parser only succeeds on what it has seen, so a value\n * parsed from a prefix of the input stays the same when more input\n * arrives. A repetition that runs out of input mid-way can therefore record\n * how far it got (its accumulator and position) before the failure\n * propagates. When the parse is attempted again with more input, the same\n * repetition, entered at the same offset, takes its checkpoint and carries\n * on from there instead of re-parsing every element.\n *\n * Checkpoints are keyed by a per-parser key and the offset the repetition\n * started at. Taking a checkpoint removes it, so its accumulator has a\n * single owner; the repetition saves a new one if it runs out again.\n *\n * A resumed repetition that then completes leaves a {@link Done}\n * checkpoint with its result, since the input may still run out after it\n * (in trailing whitespace, say) and the next attempt would otherwise parse\n * it all again. `Done` checkpoints stay in place when taken.\n */\nimport type { State } from \"../Input.js\"\n\n/** The checkpoints of a resumable parse. */\nexport type Checkpoints = Map<
|
|
1
|
+
{"version":3,"file":"resume.js","names":[],"sources":["../../src/internal/resume.ts"],"sourcesContent":["/**\n * Checkpoints for resumable (streaming) parses.\n *\n * In partial mode a parser only succeeds on what it has seen, so a value\n * parsed from a prefix of the input stays the same when more input\n * arrives. A repetition that runs out of input mid-way can therefore record\n * how far it got (its accumulator and position) before the failure\n * propagates. When the parse is attempted again with more input, the same\n * repetition, entered at the same offset, takes its checkpoint and carries\n * on from there instead of re-parsing every element.\n *\n * Checkpoints are keyed by a per-parser key and the offset the repetition\n * started at. Taking a checkpoint removes it, so its accumulator has a\n * single owner; the repetition saves a new one if it runs out again.\n *\n * A resumed repetition that then completes leaves a {@link Done}\n * checkpoint with its result, since the input may still run out after it\n * (in trailing whitespace, say) and the next attempt would otherwise parse\n * it all again. `Done` checkpoints stay in place when taken.\n */\nimport type { State } from \"../Input.js\"\nimport type { Key } from \"./key.js\"\n\n/** The checkpoints of a resumable parse. */\nexport type Checkpoints = Map<Key, Map<number, unknown>>\n\n/** Takes (and removes) the checkpoint of `key` entered at `offset`, if any. */\nexport const take = (state: State<any>, key: Key, offset: number): unknown => {\n const byKey = state.resume?.get(key)\n if (byKey === undefined) return undefined\n const checkpoint = byKey.get(offset)\n if (checkpoint !== undefined && !(checkpoint instanceof Done)) byKey.delete(offset)\n return checkpoint\n}\n\n/** The result of a repetition that completed, and where it ended. */\nexport class Done {\n constructor(\n readonly value: unknown,\n readonly pos: number\n ) {}\n}\n\n/**\n * Returns `value`, the result of a repetition entered at `entry`; when the\n * repetition was resumed from a checkpoint, records it as {@link Done}.\n */\nexport const done = <A>(state: State<any>, key: Key, entry: number, resumed: boolean, value: A): A => {\n if (resumed && state.resume !== undefined) save(state, key, entry, new Done(value, state.pos))\n return value\n}\n\n/** Records the checkpoint of `key` entered at `offset`. */\nexport const save = (state: State<any>, key: Key, offset: number, checkpoint: unknown): void => {\n const resume = state.resume\n if (resume === undefined) return\n let byKey = resume.get(key)\n if (byKey === undefined) resume.set(key, (byKey = new Map()))\n byKey.set(offset, checkpoint)\n}\n"],"mappings":";;AA2BA,MAAa,QAAQ,OAAmB,KAAU,WAA4B;CAC5E,MAAM,QAAQ,MAAM,QAAQ,IAAI,GAAG;CACnC,IAAI,UAAU,KAAA,GAAW,OAAO,KAAA;CAChC,MAAM,aAAa,MAAM,IAAI,MAAM;CACnC,IAAI,eAAe,KAAA,KAAa,EAAE,sBAAsB,OAAO,MAAM,OAAO,MAAM;CAClF,OAAO;AACT;;AAGA,IAAa,OAAb,MAAkB;CAEL;CACA;CAFX,YACE,OACA,KACA;EAFS,KAAA,QAAA;EACA,KAAA,MAAA;CACR;AACL;;;;;AAMA,MAAa,QAAW,OAAmB,KAAU,OAAe,SAAkB,UAAgB;CACpG,IAAI,WAAW,MAAM,WAAW,KAAA,GAAW,KAAK,OAAO,KAAK,OAAO,IAAI,KAAK,OAAO,MAAM,GAAG,CAAC;CAC7F,OAAO;AACT;;AAGA,MAAa,QAAQ,OAAmB,KAAU,QAAgB,eAA8B;CAC9F,MAAM,SAAS,MAAM;CACrB,IAAI,WAAW,KAAA,GAAW;CAC1B,IAAI,QAAQ,OAAO,IAAI,GAAG;CAC1B,IAAI,UAAU,KAAA,GAAW,OAAO,IAAI,KAAM,wBAAQ,IAAI,IAAI,CAAE;CAC5D,MAAM,IAAI,QAAQ,UAAU;AAC9B"}
|
package/dist/internal/run.d.ts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { Fail, State } from "../Input.js";
|
|
2
2
|
import { ParserLike } from "./node.js";
|
|
3
|
-
//#region src/internal/run.d.ts
|
|
4
3
|
/**
|
|
5
4
|
* Runs `p` on `state` from `state.pos`: its compiled form when it has one
|
|
6
5
|
* and the state allows it, else its step. A compiled run that fails is
|
|
@@ -11,5 +10,4 @@ import { ParserLike } from "./node.js";
|
|
|
11
10
|
* with streaming checkpoints) use the resumable build.
|
|
12
11
|
*/
|
|
13
12
|
export declare const runOn: <A>(p: ParserLike, step: (state: State<any>) => A | Fail, state: State<any>, diagnostics?: boolean) => A | Fail;
|
|
14
|
-
//#endregion
|
|
15
13
|
//# sourceMappingURL=run.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"run.d.ts","names":[],"sources":["../../src/internal/run.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"run.d.ts","names":[],"sources":["../../src/internal/run.ts"],"mappings":";;;;;;;;;;;qBAoBa,QAAS,GACpB,GAAG,YACH,OAAO,OAAO,eAAe,IAAI,MACjC,OAAO,YACP,0BACC,IAAI"}
|
package/dist/internal/run.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Fail } from "../Input.js";
|
|
2
2
|
import * as Registry from "./compiler/registry.js";
|
|
3
3
|
import * as Stack from "./stack.js";
|
|
4
|
-
|
|
4
|
+
// src/internal/run.ts
|
|
5
5
|
/**
|
|
6
6
|
* Running a parser on a caller-owned `State`, compiled when possible.
|
|
7
7
|
*
|
|
@@ -24,13 +24,12 @@ const runOn = (p, step, state, diagnostics = true) => {
|
|
|
24
24
|
const start = state.pos;
|
|
25
25
|
const a = Stack.run(compiled, state);
|
|
26
26
|
if (a !== Fail) return a;
|
|
27
|
-
state.
|
|
27
|
+
state.rewind(start);
|
|
28
28
|
if (!diagnostics) return Fail;
|
|
29
29
|
}
|
|
30
30
|
}
|
|
31
31
|
return Stack.run(step, state);
|
|
32
32
|
};
|
|
33
|
-
//#endregion
|
|
34
33
|
export { runOn };
|
|
35
34
|
|
|
36
35
|
//# sourceMappingURL=run.js.map
|
package/dist/internal/run.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"run.js","names":[],"sources":["../../src/internal/run.ts"],"sourcesContent":["/**\n * Running a parser on a caller-owned `State`, compiled when possible.\n *\n * Shared by `Parser.run` and `ParserStream.parseMany`, which keep one\n * state across many small runs.\n */\nimport { Fail, type State } from \"../Input.js\"\nimport * as Registry from \"./compiler/registry.js\"\nimport type { ParserLike } from \"./node.js\"\nimport * as Stack from \"./stack.js\"\n\n/**\n * Runs `p` on `state` from `state.pos`: its compiled form when it has one\n * and the state allows it, else its step. A compiled run that fails is\n * thrown away and the step runs again from the same position, so a\n * failure leaves the state exactly as the interpreter would; with\n * `diagnostics` false it is not, and the state keeps the compiled run's\n * `mode`, with the cursor back at the start. Partial states (and states\n * with streaming checkpoints) use the resumable build.\n */\nexport const runOn = <A>(\n p: ParserLike,\n step: (state: State<any>) => A | Fail,\n state: State<any>,\n diagnostics: boolean = true\n): A | Fail => {\n if (state.tracer === undefined && state.recovered === undefined && state.syntax === undefined) {\n const compiled = Registry.stepFor(p, state, state.partial || state.resume !== undefined)\n if (compiled !== undefined) {\n const start = state.pos\n const a = Stack.run(compiled, state)\n if (a !== Fail) {\n // SAFETY: the compiled step returns what the parser's step returns\n return a as A\n }\n state.
|
|
1
|
+
{"version":3,"file":"run.js","names":[],"sources":["../../src/internal/run.ts"],"sourcesContent":["/**\n * Running a parser on a caller-owned `State`, compiled when possible.\n *\n * Shared by `Parser.run` and `ParserStream.parseMany`, which keep one\n * state across many small runs.\n */\nimport { Fail, type State } from \"../Input.js\"\nimport * as Registry from \"./compiler/registry.js\"\nimport type { ParserLike } from \"./node.js\"\nimport * as Stack from \"./stack.js\"\n\n/**\n * Runs `p` on `state` from `state.pos`: its compiled form when it has one\n * and the state allows it, else its step. A compiled run that fails is\n * thrown away and the step runs again from the same position, so a\n * failure leaves the state exactly as the interpreter would; with\n * `diagnostics` false it is not, and the state keeps the compiled run's\n * `mode`, with the cursor back at the start. Partial states (and states\n * with streaming checkpoints) use the resumable build.\n */\nexport const runOn = <A>(\n p: ParserLike,\n step: (state: State<any>) => A | Fail,\n state: State<any>,\n diagnostics: boolean = true\n): A | Fail => {\n if (state.tracer === undefined && state.recovered === undefined && state.syntax === undefined) {\n const compiled = Registry.stepFor(p, state, state.partial || state.resume !== undefined)\n if (compiled !== undefined) {\n const start = state.pos\n const a = Stack.run(compiled, state)\n if (a !== Fail) {\n // SAFETY: the compiled step returns what the parser's step returns\n return a as A\n }\n state.rewind(start)\n if (!diagnostics) return Fail\n }\n }\n return Stack.run(step, state)\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;AAoBA,MAAa,SACX,GACA,MACA,OACA,cAAuB,SACV;CACb,IAAI,MAAM,WAAW,KAAA,KAAa,MAAM,cAAc,KAAA,KAAa,MAAM,WAAW,KAAA,GAAW;EAC7F,MAAM,WAAW,SAAS,QAAQ,GAAG,OAAO,MAAM,WAAW,MAAM,WAAW,KAAA,CAAS;EACvF,IAAI,aAAa,KAAA,GAAW;GAC1B,MAAM,QAAQ,MAAM;GACpB,MAAM,IAAI,MAAM,IAAI,UAAU,KAAK;GACnC,IAAI,MAAM,MAER,OAAO;GAET,MAAM,OAAO,KAAK;GAClB,IAAI,CAAC,aAAa,OAAO;EAC3B;CACF;CACA,OAAO,MAAM,IAAI,MAAM,KAAK;AAC9B"}
|
package/dist/internal/stack.d.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { Fail, State } from "../Input.js";
|
|
2
|
-
//#region src/internal/stack.d.ts
|
|
3
2
|
/**
|
|
4
3
|
* Whether `e` is the engine's call-stack overflow: a `RangeError` in V8
|
|
5
4
|
* and JavaScriptCore, an `InternalError` ("too much recursion") in
|
|
@@ -12,5 +11,4 @@ export declare const isStackOverflow: (e: unknown) => boolean;
|
|
|
12
11
|
* propagate.
|
|
13
12
|
*/
|
|
14
13
|
export declare const run: <S extends State<any>, A>(step: (state: S) => A, state: S) => A | Fail;
|
|
15
|
-
//#endregion
|
|
16
14
|
//# sourceMappingURL=stack.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"stack.d.ts","names":[],"sources":["../../src/internal/stack.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"stack.d.ts","names":[],"sources":["../../src/internal/stack.ts"],"mappings":";;;;;;qBAoBa,kBAAmB;;;;;;qBAanB,MAAO,UAAU,YAAY,GAAG,OAAO,OAAO,MAAM,GAAG,OAAO,MAAI,IAAI"}
|
package/dist/internal/stack.js
CHANGED
|
@@ -1,4 +1,14 @@
|
|
|
1
|
-
|
|
1
|
+
import * as Predicate from "effect/Predicate";
|
|
2
|
+
// src/internal/stack.ts
|
|
3
|
+
/**
|
|
4
|
+
* Call-stack overflows.
|
|
5
|
+
*
|
|
6
|
+
* The interpreter and the compiled backends recurse once (or more) per
|
|
7
|
+
* nesting level of a recursive grammar, so deeply nested input, such as
|
|
8
|
+
* thousands of `{`, can exhaust the call stack. The runners catch the
|
|
9
|
+
* engine's overflow error and report a `TooDeep` failure instead, keeping
|
|
10
|
+
* their `Result` contract on untrusted input.
|
|
11
|
+
*/
|
|
2
12
|
/** The message of a `TooDeep` failure. */
|
|
3
13
|
const tooDeepMessage = "input is nested too deeply: parsing exhausted the call stack";
|
|
4
14
|
/**
|
|
@@ -6,7 +16,7 @@ const tooDeepMessage = "input is nested too deeply: parsing exhausted the call s
|
|
|
6
16
|
* and JavaScriptCore, an `InternalError` ("too much recursion") in
|
|
7
17
|
* SpiderMonkey.
|
|
8
18
|
*/
|
|
9
|
-
const isStackOverflow = (e) => e instanceof RangeError && /call stack/i.test(e.message) || e
|
|
19
|
+
const isStackOverflow = (e) => e instanceof RangeError && /call stack/i.test(e.message) || Predicate.hasProperty(e, "name") && Predicate.hasProperty(e, "message") && e.name === "InternalError" && Predicate.isString(e.message) && /recursion/i.test(e.message);
|
|
10
20
|
/**
|
|
11
21
|
* Runs `step`, turning a call-stack overflow into an unrecoverable
|
|
12
22
|
* `TooDeep` failure at the offset parsing had reached. Other exceptions
|
|
@@ -20,7 +30,6 @@ const run = (step, state) => {
|
|
|
20
30
|
return state.failMessage("Cut", "TooDeep", tooDeepMessage);
|
|
21
31
|
}
|
|
22
32
|
};
|
|
23
|
-
//#endregion
|
|
24
33
|
export { isStackOverflow, run };
|
|
25
34
|
|
|
26
35
|
//# sourceMappingURL=stack.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"stack.js","names":[],"sources":["../../src/internal/stack.ts"],"sourcesContent":["/**\n * Call-stack overflows.\n *\n * The interpreter and the compiled backends recurse once (or more) per\n * nesting level of a recursive grammar, so deeply nested input, such as\n * thousands of `{`, can exhaust the call stack. The runners catch the\n * engine's overflow error and report a `TooDeep` failure instead, keeping\n * their `Result` contract on untrusted input.\n */\nimport type { Fail, State } from \"../Input.js\"\n\n/** The message of a `TooDeep` failure. */\nconst tooDeepMessage = \"input is nested too deeply: parsing exhausted the call stack\"\n\n/**\n * Whether `e` is the engine's call-stack overflow: a `RangeError` in V8\n * and JavaScriptCore, an `InternalError` (\"too much recursion\") in\n * SpiderMonkey.\n */\nexport const isStackOverflow = (e: unknown): boolean =>\n (e instanceof RangeError && /call stack/i.test(e.message)) ||\n (e
|
|
1
|
+
{"version":3,"file":"stack.js","names":[],"sources":["../../src/internal/stack.ts"],"sourcesContent":["/**\n * Call-stack overflows.\n *\n * The interpreter and the compiled backends recurse once (or more) per\n * nesting level of a recursive grammar, so deeply nested input, such as\n * thousands of `{`, can exhaust the call stack. The runners catch the\n * engine's overflow error and report a `TooDeep` failure instead, keeping\n * their `Result` contract on untrusted input.\n */\nimport * as Predicate from \"effect/Predicate\"\nimport type { Fail, State } from \"../Input.js\"\n\n/** The message of a `TooDeep` failure. */\nconst tooDeepMessage = \"input is nested too deeply: parsing exhausted the call stack\"\n\n/**\n * Whether `e` is the engine's call-stack overflow: a `RangeError` in V8\n * and JavaScriptCore, an `InternalError` (\"too much recursion\") in\n * SpiderMonkey.\n */\nexport const isStackOverflow = (e: unknown): boolean =>\n (e instanceof RangeError && /call stack/i.test(e.message)) ||\n (Predicate.hasProperty(e, \"name\") &&\n Predicate.hasProperty(e, \"message\") &&\n e.name === \"InternalError\" &&\n Predicate.isString(e.message) &&\n /recursion/i.test(e.message))\n\n/**\n * Runs `step`, turning a call-stack overflow into an unrecoverable\n * `TooDeep` failure at the offset parsing had reached. Other exceptions\n * propagate.\n */\nexport const run = <S extends State<any>, A>(step: (state: S) => A, state: S): A | Fail => {\n try {\n return step(state)\n } catch (e) {\n if (!isStackOverflow(e)) throw e\n return state.failMessage(\"Cut\", \"TooDeep\", tooDeepMessage)\n }\n}\n"],"mappings":";;;;;;;;;;;;AAaA,MAAM,iBAAiB;;;;;;AAOvB,MAAa,mBAAmB,MAC7B,aAAa,cAAc,cAAc,KAAK,EAAE,OAAO,KACvD,UAAU,YAAY,GAAG,MAAM,KAC9B,UAAU,YAAY,GAAG,SAAS,KAClC,EAAE,SAAS,mBACX,UAAU,SAAS,EAAE,OAAO,KAC5B,aAAa,KAAK,EAAE,OAAO;;;;;;AAO/B,MAAa,OAAgC,MAAuB,UAAuB;CACzF,IAAI;EACF,OAAO,KAAK,KAAK;CACnB,SAAS,GAAG;EACV,IAAI,CAAC,gBAAgB,CAAC,GAAG,MAAM;EAC/B,OAAO,MAAM,YAAY,OAAO,WAAW,cAAc;CAC3D;AACF"}
|
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
import { ErrMode,
|
|
2
|
-
import
|
|
1
|
+
import { ErrMode, Failure, Input, State } from "../Input.js";
|
|
2
|
+
import { Key } from "./key.js";
|
|
3
3
|
import { Encoding } from "../Encoding.js";
|
|
4
|
-
//#region src/internal/syntax.d.ts
|
|
5
4
|
/** What a failure inside an `ERROR` node was. Offsets are relative to the node. */
|
|
6
5
|
export interface ErrorInfo {
|
|
7
6
|
readonly failure: Failure;
|
|
@@ -12,7 +11,7 @@ export declare class Green {
|
|
|
12
11
|
readonly kind: string;
|
|
13
12
|
readonly named: boolean;
|
|
14
13
|
/** The `Syntax.node` that built it; `undefined` for roots and errors, which are never reused alone. */
|
|
15
|
-
readonly key:
|
|
14
|
+
readonly key: Key | undefined;
|
|
16
15
|
readonly width: number;
|
|
17
16
|
/** How far its parse looked, relative to its start (at least `width`). */
|
|
18
17
|
readonly lookahead: number;
|
|
@@ -30,7 +29,7 @@ export declare class Green {
|
|
|
30
29
|
readonly diagnostics: Diagnostics | undefined;
|
|
31
30
|
constructor(kind: string, named: boolean,
|
|
32
31
|
/** The `Syntax.node` that built it; `undefined` for roots and errors, which are never reused alone. */
|
|
33
|
-
key:
|
|
32
|
+
key: Key | undefined, width: number,
|
|
34
33
|
/** How far its parse looked, relative to its start (at least `width`). */
|
|
35
34
|
lookahead: number, children: ReadonlyArray<Green>,
|
|
36
35
|
/** The children's starts, relative to this node's start. */
|
|
@@ -91,7 +90,7 @@ export interface Previous {
|
|
|
91
90
|
}
|
|
92
91
|
/** The hooks that `Syntax` combinators and `Parser.resumeAfter`/`retryAfter` call. */
|
|
93
92
|
export interface Builder {
|
|
94
|
-
node(state: State<any>, step: (state: State<any>) => unknown, key:
|
|
93
|
+
node(state: State<any>, step: (state: State<any>) => unknown, key: Key, kind: string, named: boolean): unknown;
|
|
95
94
|
field(state: State<any>, step: (state: State<any>) => unknown, name: string): unknown;
|
|
96
95
|
/** After error recovery: `[start, pos)` was skipped after `failure`. */
|
|
97
96
|
skipped(start: number, failure: Failure, mode: ErrMode): void;
|
|
@@ -100,26 +99,39 @@ export interface Builder {
|
|
|
100
99
|
* where they leave the cursor or record a failure.
|
|
101
100
|
*/
|
|
102
101
|
read(end: number): void;
|
|
102
|
+
/** A failure or hint was recorded at `offset`. */
|
|
103
|
+
reach(offset: number): void;
|
|
104
|
+
/** The cursor moved back from `from` to `to` (see `State.rewind`). */
|
|
105
|
+
rewound(from: number, to: number): void;
|
|
103
106
|
}
|
|
104
|
-
/**
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
107
|
+
/**
|
|
108
|
+
* The tree builder of a `Syntax` parse, reached through `state.syntax`. It
|
|
109
|
+
* is not a `State` subclass: one class of state keeps every parser's cursor
|
|
110
|
+
* and failure accesses monomorphic, whether or not the program also builds
|
|
111
|
+
* syntax trees. `State` calls {@link reach} and {@link rewound} itself.
|
|
112
|
+
*/
|
|
113
|
+
export declare class SyntaxBuilder implements Builder {
|
|
114
|
+
readonly state: State<any>;
|
|
115
|
+
readonly previous: Previous | undefined;
|
|
116
|
+
/**
|
|
117
|
+
* The furthest position the cursor reached before a rewind, or failure
|
|
118
|
+
* recorded, since the innermost open node started; {@link looked} adds
|
|
119
|
+
* where the cursor is now.
|
|
120
|
+
*/
|
|
108
121
|
highWater: number;
|
|
109
122
|
/** Completed nodes waiting for their parent, in input order. */
|
|
110
|
-
stack: Array<Child>;
|
|
111
|
-
previous: Previous | undefined;
|
|
123
|
+
readonly stack: Array<Child>;
|
|
112
124
|
/** How many nodes were reused from the previous tree. */
|
|
113
125
|
reused: number;
|
|
114
126
|
/** Where {@link find} found the last node it found. */
|
|
115
127
|
lastParent: Green | undefined;
|
|
116
128
|
lastParentStart: number;
|
|
117
|
-
constructor(
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
node(state: State<any>, step: (state: State<any>) => unknown, key:
|
|
129
|
+
constructor(state: State<any>, previous: Previous | undefined);
|
|
130
|
+
reach(offset: number): void;
|
|
131
|
+
rewound(from: number, to: number): void;
|
|
132
|
+
/** How far the parse looked: {@link highWater}, or the cursor if it is further. */
|
|
133
|
+
private looked;
|
|
134
|
+
node(state: State<any>, step: (state: State<any>) => unknown, key: Key, kind: string, named: boolean): unknown;
|
|
123
135
|
read(end: number): void;
|
|
124
136
|
/** Records `failure` as the furthest failure if it is, as `failWith` does. */
|
|
125
137
|
private deepen;
|
|
@@ -141,6 +153,5 @@ export declare class SyntaxState<I extends Input = Input> extends State<I> imple
|
|
|
141
153
|
/** The node of the previous tree built by `key` at `pos` (in the new input), if it can be reused. */
|
|
142
154
|
private reusable;
|
|
143
155
|
}
|
|
144
|
-
//#endregion
|
|
145
156
|
export {};
|
|
146
157
|
//# sourceMappingURL=syntax.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"syntax.d.ts","names":[],"sources":["../../src/internal/syntax.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"syntax.d.ts","names":[],"sources":["../../src/internal/syntax.ts"],"mappings":";;;;iBA4CiB;WACN,SAAS;WACT,MAAM;;;qBAIJ;WAEA;WACA;;WAEA,KAAK;WACL;;WAEA;WACA,UAAU,cAAc;;WAExB,SAAS;;WAET,QAAQ;WACR;;WAEA,OAAO;;WAEP;;WAEA,aAAa;EAlBb,YAAA,cACA;;EAEA,KAAK,iBACL;;EAEA,mBACA,UAAU,cAAc;;EAExB,SAAS;;EAET,QAAQ,+CACR;;EAEA,OAAO;;EAEP;;EAEA,aAAa;;;;;;;iBAST;;WAEN,SAAS;;WAET;;WAEA;WACA,cAAc;;;cAInB;WAEO,OAAO;WACP;WACA;EACF;EAHE,YAAA,OAAO,OACP,eACA,aACF;;qBAIE;;qBAMA,WAAY,GAAG,SAAS,kBAAgB;;;;;iBAuCpC;WACN;WACA;WACA;;;iBAIM;WACN,MAAM;WACN;WACA;WACA,UAAU,cAAc;WACxB,OAAO;;WAEP;WACA,UAAU;;;iBAIJ;EACf,KAAK,OAAO,YAAY,OAAO,OAAO,wBAAwB,KAAK,KAAK,cAAc;EACtF,MAAM,OAAO,YAAY,OAAO,OAAO,wBAAwB;;EAE/D,QAAQ,eAAe,SAAS,SAAS,MAAM;;;;;EAK/C,KAAK;;EAEL,MAAM;;EAEN,QAAQ,cAAc;;;;;;;;qBASX,yBAAyB;WAgBzB,OAAO;WACP,UAAU;;;;;;EAXrB;;WAES,OAAO,MAAM;;EAEtB;;EAEA,YAAY;EACZ;EAGW,YAAA,OAAO,YACP,UAAU;EAQrB,MAAM;EAIN,QAAQ,cAAc;;UAQd;EAIR,KAAK,OAAO,YAAY,OAAO,OAAO,wBAAwB,KAAK,KAAK,cAAc;EA0DtF,KAAK;;UAMG;EAIR,MAAM,OAAO,YAAY,OAAO,OAAO,wBAAwB;EAQ/D,QAAQ,eAAe,SAAS,SAAS,MAAM;;;;;;EAiB/C,OAAO,cAAc,gBAAgB,OAAO,uBAAuB,qBAAqB;;;;;;;UAqBhF;;UAsCA"}
|