effect-grammar 0.0.1

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 ADDED
@@ -0,0 +1,96 @@
1
+ # effect-grammar
2
+
3
+ Effect Schema, but for text formats. One definition yields a parser, a printer,
4
+ a rendered grammar, and a `Schema<A, string>`.
5
+
6
+ ## Install
7
+
8
+ ```bash
9
+ pnpm add effect-grammar effect
10
+ ```
11
+
12
+ Depends on Effect v4.
13
+
14
+ ## Grammar
15
+
16
+ Define an HTTPS endpoint once, then parse it, print it, or derive a validated
17
+ Schema.
18
+
19
+ ```ts
20
+ import { Schema } from "effect"
21
+ import { Grammar } from "effect-grammar"
22
+
23
+ const endpoint = Grammar.map(
24
+ Grammar.struct({
25
+ scheme: Grammar.literal("https://"),
26
+ host: Grammar.label("host", Grammar.regex(/[^:/?#]+/, "host")),
27
+ portPart: Grammar.optional(
28
+ Grammar.struct({ sep: Grammar.literal(":"), port: Grammar.integer }),
29
+ ),
30
+ }),
31
+ {
32
+ to: ({ host, portPart }) => ({ host, port: portPart?.port ?? 443 }),
33
+ from: ({ host, port }) => ({
34
+ scheme: "https://" as const,
35
+ host,
36
+ portPart: { sep: ":" as const, port },
37
+ }),
38
+ },
39
+ )
40
+ const Endpoint = Grammar.toSchema(
41
+ endpoint,
42
+ Schema.Struct({
43
+ host: Schema.NonEmptyString,
44
+ port: Schema.Int.check(Schema.isBetween({ minimum: 1, maximum: 65535 })),
45
+ }),
46
+ { identifier: "Endpoint" },
47
+ )
48
+ Schema.decodeUnknownSync(Endpoint)("https://effect.website:443") // { host: "effect.website", port: 443 }
49
+ Schema.encodeSync(Endpoint)({ host: "effect.website", port: 443 }) // "https://effect.website:443"
50
+ ```
51
+
52
+ ## Parse-only with `Effect.gen`
53
+
54
+ Write plain Effect programs over the input. Custom errors are yielded failures.
55
+
56
+ ```ts
57
+ import { Effect, Schema } from "effect"
58
+ import { char, digit, endOfInput, many, parse } from "effect-grammar/parser"
59
+
60
+ class OutOfRange extends Schema.TaggedErrorClass<OutOfRange>()("OutOfRange", {
61
+ n: Schema.Finite,
62
+ }) {}
63
+
64
+ const byte = Effect.gen(function* () {
65
+ const digits = yield* many(digit, { atLeast: 1 })
66
+ const n = Number(digits.join(""))
67
+ if (n > 255) return yield* new OutOfRange({ n })
68
+ return n
69
+ })
70
+
71
+ const ip = Effect.gen(function* () {
72
+ const a = yield* byte
73
+ yield* char(".")
74
+ const b = yield* byte
75
+ yield* char(".")
76
+ const c = yield* byte
77
+ yield* char(".")
78
+ const d = yield* byte
79
+ yield* endOfInput
80
+ return [a, b, c, d] as const
81
+ })
82
+
83
+ Effect.runSync(parse("192.168.1.1", ip))
84
+ // { _tag: "Success", value: [192, 168, 1, 1] }
85
+ ```
86
+
87
+ ## Releasing
88
+
89
+ Add a changeset for a user-facing change:
90
+
91
+ ```bash
92
+ pnpm changeset
93
+ ```
94
+
95
+ After the change lands on `main`, the release workflow opens a version pull
96
+ request. Merging that pull request publishes the package to npm.
@@ -0,0 +1,28 @@
1
+ import { Effect } from "effect";
2
+ import { ParseError } from "./error.ts";
3
+ export declare const satisfy: (pred: (c: string) => boolean, expected: string) => Effect.Effect<string, ParseError | import("./error.ts").UpstreamError, import("./state.ts").ParseState>;
4
+ export declare const char: (c: string) => Effect.Effect<string, ParseError | import("./error.ts").UpstreamError, import("./state.ts").ParseState>;
5
+ export declare const digit: Effect.Effect<string, ParseError | import("./error.ts").UpstreamError, import("./state.ts").ParseState>;
6
+ export declare const regex: (re: RegExp, expected: string) => Effect.Effect<string, ParseError | import("./error.ts").UpstreamError, import("./state.ts").ParseState>;
7
+ export declare const endOfInput: Effect.Effect<undefined, ParseError | import("./error.ts").UpstreamError, import("./state.ts").ParseState>;
8
+ /**
9
+ * Ordered choice. Commits to `p` once it has consumed input — if `p` fails
10
+ * after consuming, `q` is not tried. Wrap `p` in {@link attempt} to opt back
11
+ * into backtracking.
12
+ */
13
+ export declare const or_: <A, E, R, B, E2, R2>(p: Effect.Effect<A, E, R>, q: Effect.Effect<B, E2, R2>) => Effect.Effect<A | B, E | E2, R | R2 | import("./state.ts").ParseState>;
14
+ /**
15
+ * Rewind on failure: run `p`, and if it fails, restore the input position so
16
+ * an enclosing {@link or_} will try its next option. Errors keep their
17
+ * original position for messages.
18
+ */
19
+ export declare const attempt: <A, E, R>(p: Effect.Effect<A, E, R>) => Effect.Effect<A, E, R | import("./state.ts").ParseState>;
20
+ /**
21
+ * Run `p` zero or more times (`atLeast` sets a minimum). If `p` fails after
22
+ * consuming input, `many` fails too — wrap `p` in {@link attempt} to keep
23
+ * collecting instead.
24
+ */
25
+ export declare const many: <A, E, R>(p: Effect.Effect<A, E, R>, opts?: {
26
+ atLeast?: number;
27
+ }) => Effect.Effect<A[], E, R | import("./state.ts").ParseState>;
28
+ //# sourceMappingURL=combinators.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"combinators.d.ts","sourceRoot":"","sources":["../src/combinators.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAkB,MAAM,QAAQ,CAAA;AAE/C,OAAO,EAAE,UAAU,EAAE,MAAM,YAAY,CAAA;AAGvC,eAAO,MAAM,OAAO,SAAU,CAAC,CAAC,EAAE,MAAM,KAAK,OAAO,YAAY,MAAM,4GAMlE,CAAA;AAEJ,eAAO,MAAM,IAAI,MAAO,MAAM,4GAA+C,CAAA;AAE7E,eAAO,MAAM,KAAK,yGAAgD,CAAA;AAElE,eAAO,MAAM,KAAK,OAAQ,MAAM,YAAY,MAAM,4GAUjD,CAAA;AAED,eAAO,MAAM,UAAU,4GAGrB,CAAA;AAEF;;;;GAIG;AACH,eAAO,MAAM,GAAG,GAAI,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,EAAE,EAAE,EAAE,KAAK,MAAM,CAAC,MAAM,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,KAAK,MAAM,CAAC,MAAM,CAAC,CAAC,EAAE,EAAE,EAAE,EAAE,CAAC,2EAc1F,CAAA;AAEJ;;;;GAIG;AACH,eAAO,MAAM,OAAO,GAAI,CAAC,EAAE,CAAC,EAAE,CAAC,KAAK,MAAM,CAAC,MAAM,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,6DAOtD,CAAA;AAEJ;;;;GAIG;AACH,eAAO,MAAM,IAAI,GAAI,CAAC,EAAE,CAAC,EAAE,CAAC,KAAK,MAAM,CAAC,MAAM,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,SAAS;IAAE,OAAO,CAAC,EAAE,MAAM,CAAA;CAAE,+DAmBhF,CAAA"}
@@ -0,0 +1,95 @@
1
+ import { Effect, Option, Schema } from "effect";
2
+ import { ParseError } from "./error.js";
3
+ import { failHere, getPos, matchRegex, peek, seek } from "./state.js";
4
+ export const satisfy = (pred, expected) => Effect.gen(function* () {
5
+ const c = yield* peek;
6
+ if (c === undefined || !pred(c))
7
+ return yield* failHere(expected);
8
+ yield* seek((yield* getPos) + 1);
9
+ return c;
10
+ });
11
+ export const char = (c) => satisfy((x) => x === c, JSON.stringify(c));
12
+ export const digit = satisfy((c) => c >= "0" && c <= "9", "digit");
13
+ export const regex = (re, expected) => {
14
+ // Drop g/y so sticky/global lastIndex cannot break sequential matches.
15
+ const normalized = new RegExp(re.source, re.flags.replace(/[gy]/g, ""));
16
+ return Effect.gen(function* () {
17
+ const pos = yield* getPos;
18
+ const m = yield* matchRegex(normalized);
19
+ if (Option.isNone(m))
20
+ return yield* failHere(expected);
21
+ yield* seek(pos + m.value.length);
22
+ return m.value;
23
+ });
24
+ };
25
+ export const endOfInput = Effect.gen(function* () {
26
+ const c = yield* peek;
27
+ if (c !== undefined)
28
+ return yield* failHere("end of input");
29
+ });
30
+ /**
31
+ * Ordered choice. Commits to `p` once it has consumed input — if `p` fails
32
+ * after consuming, `q` is not tried. Wrap `p` in {@link attempt} to opt back
33
+ * into backtracking.
34
+ */
35
+ export const or_ = (p, q) => Effect.gen(function* () {
36
+ const mark = yield* getPos;
37
+ const r1 = yield* Effect.result(p);
38
+ if (r1._tag === "Success")
39
+ return r1.success;
40
+ const e1 = r1.failure;
41
+ if (!Schema.is(ParseError)(e1))
42
+ return yield* Effect.fail(e1);
43
+ if ((yield* getPos) > mark)
44
+ return yield* e1;
45
+ yield* seek(mark);
46
+ const r2 = yield* Effect.result(q);
47
+ if (r2._tag === "Success")
48
+ return r2.success;
49
+ const e2 = r2.failure;
50
+ if (!Schema.is(ParseError)(e2))
51
+ return yield* Effect.fail(e2);
52
+ return yield* e2.pos >= e1.pos ? e2 : e1;
53
+ });
54
+ /**
55
+ * Rewind on failure: run `p`, and if it fails, restore the input position so
56
+ * an enclosing {@link or_} will try its next option. Errors keep their
57
+ * original position for messages.
58
+ */
59
+ export const attempt = (p) => Effect.gen(function* () {
60
+ const mark = yield* getPos;
61
+ const r = yield* Effect.result(p);
62
+ if (r._tag === "Success")
63
+ return r.success;
64
+ if (Schema.is(ParseError)(r.failure))
65
+ yield* seek(mark);
66
+ return yield* Effect.fail(r.failure);
67
+ });
68
+ /**
69
+ * Run `p` zero or more times (`atLeast` sets a minimum). If `p` fails after
70
+ * consuming input, `many` fails too — wrap `p` in {@link attempt} to keep
71
+ * collecting instead.
72
+ */
73
+ export const many = (p, opts) => Effect.gen(function* () {
74
+ const out = [];
75
+ const atLeast = opts?.atLeast ?? 0;
76
+ for (let i = 0; i < atLeast; i++)
77
+ out.push(yield* p);
78
+ while (true) {
79
+ const mark = yield* getPos;
80
+ const r = yield* Effect.result(p);
81
+ if (r._tag === "Failure") {
82
+ if (!Schema.is(ParseError)(r.failure))
83
+ return yield* Effect.fail(r.failure);
84
+ if ((yield* getPos) > mark)
85
+ return yield* r.failure;
86
+ yield* seek(mark);
87
+ return out;
88
+ }
89
+ if ((yield* getPos) === mark) {
90
+ return yield* Effect.die(new Error("many: parser succeeded without consuming input"));
91
+ }
92
+ out.push(r.success);
93
+ }
94
+ });
95
+ //# sourceMappingURL=combinators.js.map
@@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,CAAA;QACvF,CAAC;QACD,GAAG,CAAC,IAAI,CAAC,CAAC,CAAC,OAAO,CAAC,CAAA;IACrB,CAAC;AACH,CAAC,CAAC,CAAA"}
@@ -0,0 +1,28 @@
1
+ import { Schema } from "effect";
2
+ declare const ParseError_base: Schema.Class<ParseError, Schema.TaggedStruct<"ParseError", {
3
+ readonly pos: Schema.Finite;
4
+ readonly expected: Schema.String;
5
+ readonly found: Schema.UndefinedOr<Schema.String>;
6
+ /** 1-based; set at the parse / toSchema boundary. Absent for raw streaming failures. */
7
+ readonly line: Schema.optionalKey<Schema.Finite>;
8
+ /** 1-based column within `line`. */
9
+ readonly column: Schema.optionalKey<Schema.Finite>;
10
+ }>, import("effect/Cause").YieldableError>;
11
+ export declare class ParseError extends ParseError_base {
12
+ get message(): string;
13
+ }
14
+ declare const UpstreamError_base: Schema.Class<UpstreamError, Schema.TaggedStruct<"UpstreamError", {
15
+ readonly cause: Schema.Defect;
16
+ }>, import("effect/Cause").YieldableError>;
17
+ /** A chunk source feeding a streaming parse failed. `cause` is the original error. */
18
+ export declare class UpstreamError extends UpstreamError_base {
19
+ }
20
+ /** Absolute offset → 1-based line/column (`"\n"` only). */
21
+ export declare const offsetToLineColumn: (input: string, pos: number) => {
22
+ readonly line: number;
23
+ readonly column: number;
24
+ };
25
+ /** Attach line/column from `input` at `e.pos`. */
26
+ export declare const locateParseError: (input: string, e: ParseError) => ParseError;
27
+ export {};
28
+ //# sourceMappingURL=error.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"error.d.ts","sourceRoot":"","sources":["../src/error.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAA;;;;;IAM7B,wFAAwF;;IAExF,oCAAoC;;;AANtC,qBAAa,UAAW,SAAQ,eAQ9B;IACA,IAAa,OAAO,IAAI,MAAM,CAO7B;CACF;;;;AAED,sFAAsF;AACtF,qBAAa,aAAc,SAAQ,kBAEjC;CAAG;AAEL,2DAA2D;AAC3D,eAAO,MAAM,kBAAkB,UACtB,MAAM,OACR,MAAM,KACV;IAAE,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAA;CAYlD,CAAA;AAED,kDAAkD;AAClD,eAAO,MAAM,gBAAgB,UAAW,MAAM,KAAK,UAAU,KAAG,UAU/D,CAAA"}
package/dist/error.js ADDED
@@ -0,0 +1,52 @@
1
+ import { Schema } from "effect";
2
+ export class ParseError extends Schema.TaggedErrorClass()("ParseError", {
3
+ pos: Schema.Finite,
4
+ expected: Schema.String,
5
+ found: Schema.UndefinedOr(Schema.String),
6
+ /** 1-based; set at the parse / toSchema boundary. Absent for raw streaming failures. */
7
+ line: Schema.optionalKey(Schema.Finite),
8
+ /** 1-based column within `line`. */
9
+ column: Schema.optionalKey(Schema.Finite),
10
+ }) {
11
+ get message() {
12
+ const loc = this.line !== undefined && this.column !== undefined
13
+ ? `line ${this.line}, column ${this.column}`
14
+ : `position ${this.pos}`;
15
+ const found = this.found === undefined ? "end of input" : JSON.stringify(this.found);
16
+ return `${loc}: expected ${this.expected}, found ${found}`;
17
+ }
18
+ }
19
+ /** A chunk source feeding a streaming parse failed. `cause` is the original error. */
20
+ export class UpstreamError extends Schema.TaggedErrorClass()("UpstreamError", {
21
+ cause: Schema.Defect(),
22
+ }) {
23
+ }
24
+ /** Absolute offset → 1-based line/column (`"\n"` only). */
25
+ export const offsetToLineColumn = (input, pos) => {
26
+ let line = 1;
27
+ let column = 1;
28
+ for (let i = 0; i < pos; i++) {
29
+ if (input.charCodeAt(i) === 10 /* \n */) {
30
+ line++;
31
+ column = 1;
32
+ }
33
+ else {
34
+ column++;
35
+ }
36
+ }
37
+ return { line, column };
38
+ };
39
+ /** Attach line/column from `input` at `e.pos`. */
40
+ export const locateParseError = (input, e) => {
41
+ if (e.line !== undefined && e.column !== undefined)
42
+ return e;
43
+ const { line, column } = offsetToLineColumn(input, e.pos);
44
+ return new ParseError({
45
+ pos: e.pos,
46
+ expected: e.expected,
47
+ found: e.found,
48
+ line,
49
+ column,
50
+ });
51
+ };
52
+ //# sourceMappingURL=error.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"error.js","sourceRoot":"","sources":["../src/error.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAA;AAE/B,MAAM,OAAO,UAAW,SAAQ,MAAM,CAAC,gBAAgB,EAAc,CAAC,YAAY,EAAE;IAClF,GAAG,EAAE,MAAM,CAAC,MAAM;IAClB,QAAQ,EAAE,MAAM,CAAC,MAAM;IACvB,KAAK,EAAE,MAAM,CAAC,WAAW,CAAC,MAAM,CAAC,MAAM,CAAC;IACxC,wFAAwF;IACxF,IAAI,EAAE,MAAM,CAAC,WAAW,CAAC,MAAM,CAAC,MAAM,CAAC;IACvC,oCAAoC;IACpC,MAAM,EAAE,MAAM,CAAC,WAAW,CAAC,MAAM,CAAC,MAAM,CAAC;CAC1C,CAAC;IACA,IAAa,OAAO;QAClB,MAAM,GAAG,GACP,IAAI,CAAC,IAAI,KAAK,SAAS,IAAI,IAAI,CAAC,MAAM,KAAK,SAAS;YAClD,CAAC,CAAC,QAAQ,IAAI,CAAC,IAAI,YAAY,IAAI,CAAC,MAAM,EAAE;YAC5C,CAAC,CAAC,YAAY,IAAI,CAAC,GAAG,EAAE,CAAA;QAC5B,MAAM,KAAK,GAAG,IAAI,CAAC,KAAK,KAAK,SAAS,CAAC,CAAC,CAAC,cAAc,CAAC,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,KAAK,CAAC,CAAA;QACpF,OAAO,GAAG,GAAG,cAAc,IAAI,CAAC,QAAQ,WAAW,KAAK,EAAE,CAAA;IAC5D,CAAC;CACF;AAED,sFAAsF;AACtF,MAAM,OAAO,aAAc,SAAQ,MAAM,CAAC,gBAAgB,EAAiB,CAAC,eAAe,EAAE;IAC3F,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE;CACvB,CAAC;CAAG;AAEL,2DAA2D;AAC3D,MAAM,CAAC,MAAM,kBAAkB,GAAG,CAChC,KAAa,EACb,GAAW,EACyC,EAAE;IACtD,IAAI,IAAI,GAAG,CAAC,CAAA;IACZ,IAAI,MAAM,GAAG,CAAC,CAAA;IACd,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,GAAG,EAAE,CAAC,EAAE,EAAE,CAAC;QAC7B,IAAI,KAAK,CAAC,UAAU,CAAC,CAAC,CAAC,KAAK,EAAE,CAAC,QAAQ,EAAE,CAAC;YACxC,IAAI,EAAE,CAAA;YACN,MAAM,GAAG,CAAC,CAAA;QACZ,CAAC;aAAM,CAAC;YACN,MAAM,EAAE,CAAA;QACV,CAAC;IACH,CAAC;IACD,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,CAAA;AACzB,CAAC,CAAA;AAED,kDAAkD;AAClD,MAAM,CAAC,MAAM,gBAAgB,GAAG,CAAC,KAAa,EAAE,CAAa,EAAc,EAAE;IAC3E,IAAI,CAAC,CAAC,IAAI,KAAK,SAAS,IAAI,CAAC,CAAC,MAAM,KAAK,SAAS;QAAE,OAAO,CAAC,CAAA;IAC5D,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,GAAG,kBAAkB,CAAC,KAAK,EAAE,CAAC,CAAC,GAAG,CAAC,CAAA;IACzD,OAAO,IAAI,UAAU,CAAC;QACpB,GAAG,EAAE,CAAC,CAAC,GAAG;QACV,QAAQ,EAAE,CAAC,CAAC,QAAQ;QACpB,KAAK,EAAE,CAAC,CAAC,KAAK;QACd,IAAI;QACJ,MAAM;KACP,CAAC,CAAA;AACJ,CAAC,CAAA"}
@@ -0,0 +1,191 @@
1
+ import { Effect, Schema, Scope, Stream } from "effect";
2
+ import { ParseError, UpstreamError } from "./error.ts";
3
+ import { ParseState } from "./state.ts";
4
+ declare const PrintError_base: Schema.Class<PrintError, Schema.TaggedStruct<"PrintError", {
5
+ readonly message: Schema.String;
6
+ }>, import("effect/Cause").YieldableError>;
7
+ export declare class PrintError extends PrintError_base {
8
+ }
9
+ declare const RoundTripError_base: Schema.Class<RoundTripError, Schema.TaggedStruct<"RoundTripError", {
10
+ readonly stage: Schema.Literals<readonly ["print", "parse", "equal"]>;
11
+ readonly message: Schema.String;
12
+ }>, import("effect/Cause").YieldableError>;
13
+ /**
14
+ * Failure of {@link checkRoundTrip}. `stage` names which step broke:
15
+ * - `"print"` — the value could not be printed
16
+ * - `"parse"` — the printed string failed to re-parse
17
+ * - `"equal"` — re-parse succeeded but the value differed
18
+ */
19
+ export declare class RoundTripError extends RoundTripError_base {
20
+ }
21
+ declare const typeId: unique symbol;
22
+ export interface Literal {
23
+ readonly _tag: "Literal";
24
+ readonly value: string;
25
+ }
26
+ export interface Regex {
27
+ readonly _tag: "Regex";
28
+ readonly re: RegExp;
29
+ readonly expected: string;
30
+ }
31
+ export interface MapNode {
32
+ readonly _tag: "Map";
33
+ readonly inner: Grammar<any>;
34
+ readonly to: (a: any) => any;
35
+ readonly from: ((b: any) => any) | undefined;
36
+ }
37
+ export interface StructNode {
38
+ readonly _tag: "Struct";
39
+ readonly fields: Record<string, Grammar<any>>;
40
+ }
41
+ export interface Choice {
42
+ readonly _tag: "Choice";
43
+ readonly options: ReadonlyArray<Grammar<any>>;
44
+ }
45
+ export interface Many {
46
+ readonly _tag: "Many";
47
+ readonly inner: Grammar<any>;
48
+ readonly atLeast: number;
49
+ }
50
+ export interface SepBy {
51
+ readonly _tag: "SepBy";
52
+ readonly inner: Grammar<any>;
53
+ readonly sep: Grammar<any>;
54
+ readonly atLeast: number;
55
+ }
56
+ export interface Optional {
57
+ readonly _tag: "Optional";
58
+ readonly inner: Grammar<any>;
59
+ }
60
+ export interface Attempt {
61
+ readonly _tag: "Attempt";
62
+ readonly inner: Grammar<any>;
63
+ }
64
+ export interface FromEffect {
65
+ readonly _tag: "FromEffect";
66
+ readonly eff: Effect.Effect<any, ParseError, ParseState>;
67
+ readonly expected: string;
68
+ }
69
+ export interface Lazy {
70
+ readonly _tag: "Lazy";
71
+ readonly thunk: () => Grammar<any>;
72
+ readonly name: string | undefined;
73
+ /** Memoized `thunk()` result, filled in on first use. */
74
+ resolved?: Grammar<any>;
75
+ }
76
+ export interface End {
77
+ readonly _tag: "End";
78
+ }
79
+ export interface Bind {
80
+ readonly _tag: "Bind";
81
+ readonly inner: Grammar<any>;
82
+ readonly to: (a: any) => Grammar<any>;
83
+ readonly from: ((b: any) => any) | undefined;
84
+ }
85
+ export interface Count {
86
+ readonly _tag: "Count";
87
+ readonly inner: Grammar<any>;
88
+ readonly n: number;
89
+ }
90
+ export interface Guard {
91
+ readonly _tag: "Guard";
92
+ readonly inner: Grammar<any>;
93
+ readonly pred: (value: any) => boolean;
94
+ }
95
+ export interface Label {
96
+ readonly _tag: "Label";
97
+ readonly expected: string;
98
+ readonly inner: Grammar<any>;
99
+ }
100
+ export type Node = Literal | Regex | MapNode | StructNode | Choice | Many | SepBy | Optional | Attempt | FromEffect | Lazy | End | Bind | Count | Guard | Label;
101
+ export type Grammar<A> = Node & {
102
+ readonly [typeId]?: A;
103
+ };
104
+ export type GrammarType<G> = G extends Grammar<infer A> ? A : never;
105
+ export declare const literal: <L extends string>(value: L) => Grammar<L>;
106
+ /** Clone the pattern and drop `g`/`y` so `lastIndex` and sticky start never affect matching. */
107
+ export declare const regex: (re: RegExp, expected: string) => Grammar<string>;
108
+ export declare const map: <A, B>(inner: Grammar<A>, f: {
109
+ readonly to: (a: A) => B;
110
+ readonly from?: (b: B) => A;
111
+ }) => Grammar<B>;
112
+ export declare const struct: <F extends Record<string, Grammar<any>>>(fields: F) => Grammar<{ [K in keyof F]: GrammarType<F[K]>; }>;
113
+ export declare const choice: <Gs extends readonly [Grammar<any>, ...Array<Grammar<any>>]>(...options: Gs) => Grammar<GrammarType<Gs[number]>>;
114
+ export declare const many: <A>(inner: Grammar<A>, opts?: {
115
+ readonly atLeast?: number;
116
+ }) => Grammar<Array<A>>;
117
+ export declare const sepBy: <A, S>(inner: Grammar<A>, sep: Grammar<S>) => Grammar<Array<A>>;
118
+ /** Like `sepBy`, but requires at least one element — the first failure propagates. */
119
+ export declare const sepBy1: <A, S>(inner: Grammar<A>, sep: Grammar<S>) => Grammar<Array<A>>;
120
+ export declare const optional: <A>(inner: Grammar<A>) => Grammar<A | undefined>;
121
+ /**
122
+ * Rewind on failure: if `inner` fails after consuming input, restore the
123
+ * position so an enclosing `choice` tries its next option.
124
+ */
125
+ export declare const attempt: <A>(inner: Grammar<A>) => Grammar<A>;
126
+ /**
127
+ * Print-time filter: parse runs `inner` unchanged, but printing fails with
128
+ * `PrintError` when `pred(value)` is false — so an enclosing `choice` moves
129
+ * on to its next option.
130
+ */
131
+ export declare const guard: <A>(inner: Grammar<A>, pred: (value: A) => boolean) => Grammar<A>;
132
+ /**
133
+ * Name a grammar for error messages. Replaces `expected` only when `inner`
134
+ * fails without consuming input. Print is transparent; render shows
135
+ * `<expected>` when `inner` is a raw regex.
136
+ */
137
+ export declare const label: <A>(expected: string, inner: Grammar<A>) => Grammar<A>;
138
+ export declare const fromEffect: <A>(eff: Effect.Effect<A, ParseError, ParseState>, expected: string) => Grammar<A>;
139
+ /**
140
+ * Defer grammar construction to first use — the building block for recursive
141
+ * grammars. The thunk result is memoized on the node. `name` is what `render`
142
+ * shows at the recursion point.
143
+ */
144
+ export declare const lazy: <A>(thunk: () => Grammar<A>, opts?: {
145
+ readonly name?: string;
146
+ }) => Grammar<A>;
147
+ /** Zero-width assertion: succeeds only at end of input. Prints as "". */
148
+ export declare const end: Grammar<void>;
149
+ /**
150
+ * Dependent parsing: the grammar that runs next is computed from the value
151
+ * just parsed (e.g. a length prefix deciding how many chars to read).
152
+ * Printable when `from` recovers the intermediate value from the result.
153
+ */
154
+ export declare const bind: <A, B>(inner: Grammar<A>, f: {
155
+ readonly to: (a: A) => Grammar<B>;
156
+ readonly from?: (b: B) => A;
157
+ }) => Grammar<B>;
158
+ /** Run `inner` exactly `n` times, collecting the results. */
159
+ export declare const count: <A>(inner: Grammar<A>, n: number) => Grammar<Array<A>>;
160
+ export declare const integer: Grammar<number>;
161
+ /** Run `inner`, then skip trailing whitespace. Printing emits one canonical space. */
162
+ export declare const lexeme: <A>(inner: Grammar<A>) => Grammar<A>;
163
+ /** A literal that skips trailing whitespace. */
164
+ export declare const symbol: <L extends string>(s: L) => Grammar<L>;
165
+ /**
166
+ * Run `open`, `inner`, `close` in sequence, keeping only `inner`'s value.
167
+ * Print supplies `undefined` for open/close — they must be value-ignoring
168
+ * printers (`literal`, `symbol`, `end`, or a transparent wrapper around those).
169
+ */
170
+ export declare const between: <O, C, A>(open: Grammar<O>, close: Grammar<C>, inner: Grammar<A>) => Grammar<A>;
171
+ export declare const parse: <A>(input: string, grammar: Grammar<A>) => Effect.Effect<A, ParseError>;
172
+ /** Like `parse`, but leaves the cursor wherever the grammar stopped — trailing input is allowed. */
173
+ export declare const parsePrefix: <A>(input: string, grammar: Grammar<A>) => Effect.Effect<A, ParseError>;
174
+ /** Run a grammar once over a stream of chunks. See `parseStream` in `stream.ts`. */
175
+ export declare const parseStream: <A, E2, R2>(input: Stream.Stream<string, E2, R2>, grammar: Grammar<A>) => Effect.Effect<A, ParseError | UpstreamError, Exclude<R2, Scope.Scope>>;
176
+ /** Parse a stream of chunks into a stream of values, one per grammar run. */
177
+ export declare const streamElements: <A, E2, R2>(input: Stream.Stream<string, E2, R2>, grammar: Grammar<A>) => Stream.Stream<A, ParseError | UpstreamError, Exclude<R2, Scope.Scope>>;
178
+ export declare const print: <A>(grammar: Grammar<A>, value: A) => Effect.Effect<string, PrintError>;
179
+ /**
180
+ * Law: `parse(print(value))` equals `value` (structurally).
181
+ *
182
+ * Prints, re-parses with strict EOF, then compares with `Equal.equals`.
183
+ * Fails with {@link RoundTripError} naming the stage that broke.
184
+ */
185
+ export declare const checkRoundTrip: <A>(grammar: Grammar<A>, value: A) => Effect.Effect<void, RoundTripError>;
186
+ export declare const render: (g: Grammar<any>) => string;
187
+ export declare const toSchema: <S extends Schema.Top>(grammar: Grammar<S["Encoded"]>, target: S, options?: {
188
+ readonly identifier?: string;
189
+ }) => Schema.decodeTo<S, Schema.String, never, never>;
190
+ export {};
191
+ //# sourceMappingURL=grammar.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"grammar.d.ts","sourceRoot":"","sources":["../src/grammar.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,MAAM,EAGN,MAAM,EAGN,KAAK,EACL,MAAM,EACP,MAAM,QAAQ,CAAA;AAEf,OAAO,EAAoB,UAAU,EAAE,aAAa,EAAE,MAAM,YAAY,CAAA;AACxE,OAAO,EAML,UAAU,EAGX,MAAM,YAAY,CAAA;;;;AAMnB,qBAAa,UAAW,SAAQ,eAE9B;CAAG;;;;;AAEL;;;;;GAKG;AACH,qBAAa,cAAe,SAAQ,mBAGlC;CAAG;AAEL,OAAO,CAAC,MAAM,MAAM,EAAE,OAAO,MAAM,CAAA;AAEnC,MAAM,WAAW,OAAO;IACtB,QAAQ,CAAC,IAAI,EAAE,SAAS,CAAA;IACxB,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAA;CACvB;AAED,MAAM,WAAW,KAAK;IACpB,QAAQ,CAAC,IAAI,EAAE,OAAO,CAAA;IACtB,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAA;IACnB,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAA;CAC1B;AAED,MAAM,WAAW,OAAO;IACtB,QAAQ,CAAC,IAAI,EAAE,KAAK,CAAA;IACpB,QAAQ,CAAC,KAAK,EAAE,OAAO,CAAC,GAAG,CAAC,CAAA;IAC5B,QAAQ,CAAC,EAAE,EAAE,CAAC,CAAC,EAAE,GAAG,KAAK,GAAG,CAAA;IAC5B,QAAQ,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC,EAAE,GAAG,KAAK,GAAG,CAAC,GAAG,SAAS,CAAA;CAC7C;AAED,MAAM,WAAW,UAAU;IACzB,QAAQ,CAAC,IAAI,EAAE,QAAQ,CAA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