effect-grammar 0.4.0 → 0.5.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 (72) hide show
  1. package/README.md +175 -87
  2. package/dist/binary.d.ts +64 -0
  3. package/dist/binary.d.ts.map +1 -0
  4. package/dist/binary.js +246 -0
  5. package/dist/binary.js.map +1 -0
  6. package/dist/codec.d.ts +17 -0
  7. package/dist/codec.d.ts.map +1 -0
  8. package/dist/codec.js +14 -0
  9. package/dist/codec.js.map +1 -0
  10. package/dist/combinators.d.ts +112 -6
  11. package/dist/combinators.d.ts.map +1 -1
  12. package/dist/combinators.js +218 -28
  13. package/dist/combinators.js.map +1 -1
  14. package/dist/compile.d.ts +36 -0
  15. package/dist/compile.d.ts.map +1 -0
  16. package/dist/compile.js +228 -0
  17. package/dist/compile.js.map +1 -0
  18. package/dist/core.d.ts +34 -1
  19. package/dist/core.d.ts.map +1 -1
  20. package/dist/core.js +51 -1
  21. package/dist/core.js.map +1 -1
  22. package/dist/env.d.ts +5 -0
  23. package/dist/env.d.ts.map +1 -1
  24. package/dist/env.js +20 -1
  25. package/dist/env.js.map +1 -1
  26. package/dist/errors.d.ts +12 -0
  27. package/dist/errors.d.ts.map +1 -1
  28. package/dist/errors.js +40 -4
  29. package/dist/errors.js.map +1 -1
  30. package/dist/gen.d.ts.map +1 -1
  31. package/dist/gen.js +5 -7
  32. package/dist/gen.js.map +1 -1
  33. package/dist/index.d.ts +5 -4
  34. package/dist/index.d.ts.map +1 -1
  35. package/dist/index.js +3 -2
  36. package/dist/index.js.map +1 -1
  37. package/dist/parse.d.ts +10 -1
  38. package/dist/parse.d.ts.map +1 -1
  39. package/dist/parse.js +81 -19
  40. package/dist/parse.js.map +1 -1
  41. package/dist/pattern.d.ts +2 -1
  42. package/dist/pattern.d.ts.map +1 -1
  43. package/dist/pattern.js +46 -2
  44. package/dist/pattern.js.map +1 -1
  45. package/dist/print.d.ts +8 -0
  46. package/dist/print.d.ts.map +1 -1
  47. package/dist/print.js +136 -18
  48. package/dist/print.js.map +1 -1
  49. package/dist/render.d.ts.map +1 -1
  50. package/dist/render.js +33 -6
  51. package/dist/render.js.map +1 -1
  52. package/dist/schema.d.ts +8 -3
  53. package/dist/schema.d.ts.map +1 -1
  54. package/dist/schema.js +11 -13
  55. package/dist/schema.js.map +1 -1
  56. package/dist/testing.d.ts +18 -0
  57. package/dist/testing.d.ts.map +1 -0
  58. package/dist/testing.js +72 -0
  59. package/dist/testing.js.map +1 -0
  60. package/package.json +9 -3
  61. package/dist/ast.d.ts +0 -115
  62. package/dist/ast.d.ts.map +0 -1
  63. package/dist/ast.js +0 -253
  64. package/dist/ast.js.map +0 -1
  65. package/dist/grammar.d.ts +0 -8
  66. package/dist/grammar.d.ts.map +0 -1
  67. package/dist/grammar.js +0 -8
  68. package/dist/grammar.js.map +0 -1
  69. package/dist/recovery.d.ts +0 -10
  70. package/dist/recovery.d.ts.map +0 -1
  71. package/dist/recovery.js +0 -296
  72. package/dist/recovery.js.map +0 -1
package/README.md CHANGED
@@ -1,106 +1,194 @@
1
1
  # effect-grammar
2
2
 
3
- ```bash
4
- pnpm add effect-grammar
5
- ```
3
+ Write a grammar once, then use it to parse text, print values, or derive an
4
+ Effect Schema codec. Grammars are bidirectional by design, with explicit
5
+ round-trip checking when you need an invertibility guarantee.
6
+
7
+ ## Install
6
8
 
7
- Invertible grammar combinators and parser-printers for Effect.
9
+ `effect` is a peer dependency:
8
10
 
9
- A `Grammar<A>` supports four operations:
11
+ ```sh
12
+ npm install effect effect-grammar
13
+ ```
10
14
 
11
- - `parse`: read a string and return a `Result<A, ParseError>`
12
- - `print`: write an `A` as canonical text and return a
13
- `Result<string, PrintError>`
14
- - `codec`: combine the grammar with an Effect Schema to make a string codec
15
- - `render`: return a readable description of the grammar
15
+ ## Quick start
16
16
 
17
17
  ```ts
18
18
  import { Schema } from "effect"
19
19
  import * as G from "effect-grammar"
20
20
 
21
- const frame = G.gen(function* () {
22
- const kind = yield* G.choice(
23
- G.literal("text").pipe(G.as("text")),
24
- G.literal("bits").pipe(G.as("bits")),
25
- )
26
- yield* G.literal("/")
27
- const size = yield* G.integer
21
+ const endpoint = G.gen(function* () {
22
+ yield* G.literal("https://")
23
+ const host = yield* G.regex(/[^:/?#]+/, "host")
28
24
  yield* G.literal(":")
29
- const body = yield* G.match(kind, {
30
- text: G.take(size),
31
- bits: G.repeat(G.regex(/[01]/, "bit"), size),
32
- })
33
- return { kind, size, body }
34
- })
35
-
36
- const FrameValue = Schema.Struct({
37
- kind: Schema.Literals(["text", "bits"]),
38
- size: Schema.Number,
39
- body: Schema.Union([Schema.String, Schema.Array(Schema.String)]),
25
+ const port = yield* G.integer
26
+ return { host, port }
40
27
  })
41
28
 
42
- const Frame = G.codec(frame, FrameValue, { identifier: "Frame" })
43
- const decode = Schema.decodeSync(Frame)
44
- const encode = Schema.encodeSync(Frame)
45
- ```
46
-
47
- The grammar and its Schema codec use the same parser and printer:
48
-
49
- ```text
50
- decode("text/5:hello") → { kind: "text", size: 5, body: "hello" }
51
- decode("bits/4:1010") → { kind: "bits", size: 4, body: ["1", "0", "1", "0"] }
29
+ const Endpoint = G.codec(
30
+ endpoint,
31
+ Schema.Struct({
32
+ host: Schema.NonEmptyString,
33
+ port: Schema.Int,
34
+ }),
35
+ )
52
36
 
53
- encode({ kind: "text", size: 2, body: "hi" }) → "text/2:hi"
54
- encode({ kind: "bits", size: 4, body: ["1", "0", "1", "0"] }) → "bits/4:1010"
37
+ Schema.decodeSync(Endpoint)("https://effect.website:443")
38
+ // { host: "effect.website", port: 443 }
55
39
 
56
- parse("bits/4:1020") line 1, column 10: expected bit, found "2"
57
- print({ kind: "text", size: 2, body: "hello" }) → .body: expected 2 UTF-16 code units, got "hello"
58
-
59
- render(frame) → kind:("text" | "bits") "/" size:<integer> ":" body:match(kind){"text" => <char>{size} | "bits" => (<bit>){size}}
40
+ Schema.encodeSync(Endpoint)({ host: "effect.website", port: 443 })
41
+ // "https://effect.website:443"
60
42
  ```
61
43
 
62
- ## Schema integration
63
-
64
- `codec` combines a grammar with an Effect Schema. Decoding parses the text and
65
- then checks the value. Encoding checks the value and then prints it. The example
66
- above shows the full integration in one code block.
44
+ ## Operations
45
+
46
+ - `parse(grammar, text)` interprets from cursor zero and succeeds only after
47
+ consuming the whole string.
48
+ - `print(grammar, value)` runs the grammar's printer. It validates local printer
49
+ requirements but does not verify that the result parses back to the same
50
+ value.
51
+ - `printChecked(grammar, value)` prints, reparses the whole output, and compares
52
+ the result with Effect's equality. It fails when that value round trip does
53
+ not hold.
54
+ - `prepare(grammar)` runs the library's static validation once, then returns
55
+ `parse`, `print`, and `printChecked` functions bound to the grammar, plus its
56
+ rendering and fidelity audit. It is not compilation or optimization; runtime
57
+ failures remain possible.
58
+ - `codec(grammar, schema)` creates an Effect Schema codec. Encoding uses checked
59
+ printing by default; `{ roundTrip: "off" }` selects unchecked printing.
60
+
61
+ `regex(re, name)` stores the source and flags without `g` or `y`. During parsing
62
+ it uses a fresh sticky matcher at the current cursor, so `^`, `$`, lookarounds,
63
+ and flags retain JavaScript `RegExp` semantics relative to the original full
64
+ input. Printing requires the value itself to be a string matched in full. The
65
+ caller's `RegExp` and `lastIndex` are not mutated.
66
+
67
+ ## Composition and correctness
68
+
69
+ `choice` parses branches in order and prints with the first printer that accepts
70
+ the value. `checkedChoice` uses the first accepting branch whose produced text
71
+ reparses to an equal value. `choiceOn(tag, cases)` instead dispatches printing
72
+ from an existing discriminant field; parsing is still ordered and can remain
73
+ ambiguous. `taggedChoice(tag, cases)` wraps each branch's value as
74
+ `{ [tag]: key, value }` and dispatches by that generated tag.
75
+ `literals(...strings)` is a choice of strings whose value is the string that
76
+ matched. It tries longer strings first, so `literals(">", ">=")` still reads
77
+ `>=`.
78
+
79
+ For explicit branch order or number/boolean discriminants, use
80
+ `choiceOnEntries(tag, entries)` with an array of `[key, grammar]` entries.
81
+ `choiceOn` and `taggedChoice` reject JavaScript array-index keys because object
82
+ enumeration can reorder them.
83
+
84
+ `gen` result objects are exact printer patterns: printing rejects missing,
85
+ extra, symbol, or otherwise unexpected own keys. Arrays must have exactly the
86
+ expected length.
87
+
88
+ `many`, `sepBy`, and exact `repeat` require every successfully parsed item to
89
+ advance the cursor; zero-width items fail rather than loop. `validate`/`prepare`
90
+ report repetitions whose item can be proved to match empty input, but validation
91
+ is intentionally not a proof of all behavior.
92
+
93
+ `take(count)` reads a fixed number of UTF-16 code units and
94
+ `repeat(item, count)` a fixed number of items; the count is a number or a ref
95
+ bound earlier in the same `gen`. `lengthPrefixed(length)` and
96
+ `countPrefixed(item, count)` parse a prefix and then that many UTF-16 code units
97
+ or items, and derive the prefix from the value when printing, so the value does
98
+ not carry it. `filter(predicate, name)` keeps a grammar's value only when the
99
+ predicate accepts it, in both directions.
100
+
101
+ `merge(...parts)` sequences grammars that produce objects and flattens their
102
+ fields into one object. Each part must have statically known fields: a `struct`,
103
+ a `gen` that returns an object, another `merge`, `Binary.bits`, or a `filter`
104
+ over any of these. A general transform is rejected, because its fields cannot be
105
+ known. Printing splits the value by those fields, so errors keep flat paths.
106
+ Duplicate fields are rejected on construction.
107
+
108
+ `suspend(() => grammar)` enables recursive definitions. Its thunk is evaluated
109
+ lazily on first resolution and the resolved grammar is cached. Direct left
110
+ recursion at the same parse position and recursive printing that does not
111
+ consume a value are rejected; recursive grammars must be productive.
112
+
113
+ Transforms state different fidelity intentions:
114
+
115
+ - `transform` and `transformOrFail` make no inverse claim.
116
+ - `iso` records the author's inverse claim; the library does not prove it.
117
+ - `partialIso` records a fallible pair intended to agree where both directions
118
+ succeed.
119
+ - `auditFidelity` lists transforms without a full inverse claim; an empty list
120
+ is not proof of a round trip.
121
+
122
+ Use `printChecked` or the helpers from `effect-grammar/testing` to test the
123
+ values and accepted texts relevant to your grammar. These are properties to
124
+ verify, not laws guaranteed for every grammar.
125
+
126
+ ## Binary
127
+
128
+ `effect-grammar/Binary` applies the same grammars to a `Uint8Array`. Bytes pass
129
+ through the engine as a binary string with one code unit per byte, so every core
130
+ combinator composes with the byte-oriented ones.
67
131
 
68
- See the [endpoint example](./examples/endpoint.ts) for a complete Schema.
69
-
70
- ## Main building blocks
71
-
72
- | Purpose | Combinators |
73
- | --------------------------- | -------------------------------------------------------- |
74
- | Text | `literal`, `regex`, `integer`, `take`, `repeat` |
75
- | Sequences and products | `gen`, `seq`, `struct`, `tuple` |
76
- | Delimiters | `prefix`, `suffix`, `between`, `wrap` |
77
- | Repetition and options | `optional`, `many`, `sepBy` |
78
- | Alternatives | `choice`, `taggedChoice`, `match`, `matchValue` |
79
- | Value conversion | `transform`, `transformOrFail`, `decodeTo`, `as`, `flag` |
80
- | Defaults and ignored values | `defaulted`, `skip` |
81
- | Whitespace | `lexeme`, `symbol`, `space`, `spaces`, `trivia` |
82
- | Recursion | `suspend` |
83
-
84
- Most delimiter and repetition combinators support data-first and data-last
85
- calls, so they also work with `pipe`.
86
-
87
- ## Results, errors, and rendering
88
-
89
- `parse` and `print` return `Result` values. Parse errors report the furthest
90
- text position, the expected forms, and the line and column. Print errors contain
91
- a `PrintIssue` tree with paths, missing fields, failed branches, and value
92
- mismatches. `PrintError.format` converts that tree to text.
93
-
94
- `render` describes a complete grammar. `describe` returns a short grammar name.
95
-
96
- ## More examples
132
+ ```ts
133
+ import { Schema } from "effect"
134
+ import * as Grammar from "effect-grammar"
135
+ import * as Binary from "effect-grammar/Binary"
136
+
137
+ const header = Grammar.merge(
138
+ Grammar.struct({ id: Binary.uint16 }),
139
+ Binary.bits({ qr: 1, opcode: 4, aa: 1, tc: 1, rd: 1, ra: 1, z: 3, rcode: 4 }),
140
+ Grammar.struct({ qdcount: Binary.uint16 }),
141
+ )
142
+
143
+ const Header = Binary.codec(
144
+ header,
145
+ Schema.Struct({
146
+ id: Binary.Uint16,
147
+ qr: Binary.Bit,
148
+ opcode: Binary.Uint(4),
149
+ aa: Binary.Bit,
150
+ tc: Binary.Bit,
151
+ rd: Binary.Bit,
152
+ ra: Binary.Bit,
153
+ z: Binary.Uint(3),
154
+ rcode: Binary.Uint(4),
155
+ qdcount: Binary.Uint16,
156
+ }),
157
+ )
158
+
159
+ Schema.decodeSync(Header)(Uint8Array.of(0xbe, 0xef, 0x01, 0x00, 0x00, 0x01))
160
+ // { id: 48879, qr: 0, opcode: 0, aa: 0, tc: 0, rd: 1, ra: 0, z: 0, rcode: 0, qdcount: 1 }
161
+ ```
97
162
 
98
- - [Postgres connection string](./examples/connection-string.ts): optional parts,
99
- query parameters, Schema checks, encoding, and round trips
100
- - [JSON](./examples/json.ts): a recursive grammar and Schema codec
101
- - [Scheme](./examples/scheme.ts): recursive expressions, tokens, and canonical
102
- whitespace
103
- - [GitHub search](./examples/github-search.ts): a larger search-query DSL
104
- - [IP address](./examples/ip.ts): transforms and Schema refinements
105
- - [Printing showcase](./examples/printing.ts): parsing, printing, rendering, and
106
- print failures
163
+ - `uint8` to `uint64`, `int8` to `int64`, `float32`, and `float64` are
164
+ big-endian; the `le` suffix, as in `uint16le`, reads little-endian. 64-bit
165
+ integers are bigints. `float32` prints only numbers that single precision
166
+ holds exactly.
167
+ - `varuint` is unsigned LEB128 within the safe integer range, and `varint` its
168
+ zigzag-encoded signed form for integers from `-(2 ** 52)` to `2 ** 52 - 1`.
169
+ Parsing accepts padded encodings of any length; printing writes the shortest
170
+ one.
171
+ - `bits(layout)` splits a whole number of bytes into named fields, first field
172
+ highest. A one-bit field has type `0 | 1`; wider fields are numbers of up to
173
+ 53 bits. Printing rejects a field that does not fit its width.
174
+ - `bytes(count)` reads a `Uint8Array` of a constant or previously bound length,
175
+ `lengthPrefixed(length)` derives its prefix, a byte count, when printing, and
176
+ `literal(...bytes)` matches a fixed sequence such as a magic number.
177
+ - `ascii` and `utf8` turn a `Uint8Array` grammar into a string grammar. Invalid
178
+ bytes fail to parse and unencodable strings fail to print; `auditFidelity`
179
+ lists `utf8` as partial.
180
+ - `Bit`, `Uint(bits)` and `Int(bits)` for 1 to 53 bits, `Uint8` to `Uint64`, and
181
+ `Int8` to `Int64` are schemas for the values these grammars produce, and
182
+ `hex(bytes)` formats a `Uint8Array` for display.
183
+ - `parse`, `print`, `printChecked`, and `codec` mirror the text operations over
184
+ `Uint8Array`. Parse failures report a byte offset and the byte found; input
185
+ that ends inside a fixed-width field fails at the end of the input.
186
+
187
+ A grammar that prints a character above `0xff` cannot be encoded and fails to
188
+ print.
189
+
190
+ ## Examples
191
+
192
+ The `examples/` directory includes endpoint and connection-string grammars,
193
+ JSON, HTTP ranges, IP addresses, recursive Scheme syntax, contextual printing,
194
+ Schema error integration, and a binary DNS message codec.
@@ -0,0 +1,64 @@
1
+ import { Result, Schema } from "effect";
2
+ import { type CodecOptions } from "./codec.ts";
3
+ import { type Grammar, type Ref, type Silent } from "./core.ts";
4
+ import { PrintError } from "./errors.ts";
5
+ export { hex } from "./errors.ts";
6
+ export declare const Bit: Schema.Literals<readonly [0, 1]>;
7
+ export declare const Uint: (size: number) => Schema.Int;
8
+ export declare const Int: (size: number) => Schema.Int;
9
+ export declare const Uint8: Schema.Int;
10
+ export declare const Uint16: Schema.Int;
11
+ export declare const Uint32: Schema.Int;
12
+ export declare const Int8: Schema.Int;
13
+ export declare const Int16: Schema.Int;
14
+ export declare const Int32: Schema.Int;
15
+ export declare const Uint64: Schema.BigInt;
16
+ export declare const Int64: Schema.BigInt;
17
+ declare const ParseError_base: Schema.Class<ParseError, Schema.TaggedStruct<"BinaryParseError", {
18
+ readonly offset: Schema.Finite;
19
+ readonly expected: Schema.$Array<Schema.String>;
20
+ readonly found: Schema.UndefinedOr<Schema.Finite>;
21
+ }>, import("effect/Cause").YieldableError>;
22
+ export declare class ParseError extends ParseError_base {
23
+ get message(): string;
24
+ }
25
+ export declare const uint8: Grammar<number>;
26
+ export declare const uint16: Grammar<number>;
27
+ export declare const uint32: Grammar<number>;
28
+ export declare const uint64: Grammar<bigint>;
29
+ export declare const uint16le: Grammar<number>;
30
+ export declare const uint32le: Grammar<number>;
31
+ export declare const uint64le: Grammar<bigint>;
32
+ export declare const int8: Grammar<number>;
33
+ export declare const int16: Grammar<number>;
34
+ export declare const int32: Grammar<number>;
35
+ export declare const int64: Grammar<bigint>;
36
+ export declare const int16le: Grammar<number>;
37
+ export declare const int32le: Grammar<number>;
38
+ export declare const int64le: Grammar<bigint>;
39
+ export declare const float32: Grammar<number>;
40
+ export declare const float64: Grammar<number>;
41
+ export declare const float32le: Grammar<number>;
42
+ export declare const float64le: Grammar<number>;
43
+ /**
44
+ * Unsigned LEB128 within the safe integer range. Parsing accepts padded
45
+ * encodings of any length; printing writes the shortest one.
46
+ */
47
+ export declare const varuint: Grammar<number>;
48
+ /** Zigzag-encoded LEB128, as in protobuf `sint64`, for integers from -(2 ** 52) to 2 ** 52 - 1. */
49
+ export declare const varint: Grammar<number>;
50
+ export type BitLayout = Readonly<Record<string, number>>;
51
+ export type Bits<Layout extends BitLayout> = {
52
+ readonly [K in keyof Layout]: Layout[K] extends 1 ? 0 | 1 : number;
53
+ };
54
+ export declare const bits: <const Layout extends BitLayout>(layout: Layout) => Grammar<Bits<Layout>>;
55
+ export declare const bytes: (count: Ref<number> | number) => Grammar<Uint8Array>;
56
+ export declare const lengthPrefixed: (length: Grammar<number>) => Grammar<Uint8Array>;
57
+ export declare const literal: (...values: ReadonlyArray<number>) => Silent;
58
+ export declare const ascii: (inner: Grammar<Uint8Array<ArrayBufferLike>>) => Grammar<string>;
59
+ export declare const utf8: (inner: Grammar<Uint8Array<ArrayBufferLike>>) => Grammar<string>;
60
+ export declare const parse: <A>(grammar: Grammar<A>, input: Uint8Array) => Result.Result<A, ParseError>;
61
+ export declare const print: <A>(grammar: Grammar<A>, value: A) => Result.Result<Uint8Array, PrintError>;
62
+ export declare const printChecked: typeof print;
63
+ export declare const codec: <S extends Schema.Top, A extends S["Encoded"]>(grammar: Grammar<A>, target: S, options?: CodecOptions) => Schema.decodeTo<S, Schema.Codec<Uint8Array<ArrayBufferLike>, Uint8Array<ArrayBufferLike>, never, never>, never, never>;
64
+ //# sourceMappingURL=binary.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CAAA;AAEF,eAAO,MAAM,KAAK,GAAI,CAAC,WAAW,OAAO,CAAC,CAAC,CAAC,SAAS,UAAU,KAAG,MAAM,CAAC,MAAM,CAAC,CAAC,EAAE,UAAU,CAK1F,CAAA;AAkBH,eAAO,MAAM,KAAK,EAAE,CAAC,CAAC,EAAE,OAAO,EAAE,OAAO,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,KAAK,MAAM,CAAC,MAAM,CAAC,UAAU,EAAE,UAAU,CAC9E,CAAA;AAEhB,eAAO,MAAM,YAAY,EAAE,OAAO,KAAqB,CAAA;AAEvD,eAAO,MAAM,KAAK,GAAI,CAAC,SAAS,MAAM,CAAC,GAAG,EAAE,CAAC,SAAS,CAAC,CAAC,SAAS,CAAC,WACvD,OAAO,CAAC,CAAC,CAAC,UACX,CAAC,YACC,YAAY,2HAWvB,CAAA"}
package/dist/binary.js ADDED
@@ -0,0 +1,246 @@
1
+ import { Function as F, Predicate, Result, Schema } from "effect";
2
+ import { codecFrom } from "./codec.js";
3
+ import { iso, partialIso, prefixedBy, regex, takeBytes, withKeys } from "./combinators.js";
4
+ import { silent, } from "./core.js";
5
+ import { isCount, nonByte, toBytes } from "./env.js";
6
+ import { describeExpected, hex, PrintError } from "./errors.js";
7
+ import { parse as parseText } from "./parse.js";
8
+ import { printCheckedUnknown, printUnknown } from "./print.js";
9
+ export { hex } from "./errors.js";
10
+ const isWidth = (size) => Number.isInteger(size) && size >= 1 && size <= 53;
11
+ const assertWidth = (name, size) => {
12
+ if (!isWidth(size)) {
13
+ throw new RangeError(`${name}: expected a width of 1 to 53 bits, got ${size}`);
14
+ }
15
+ };
16
+ export const Bit = Schema.Literals([0, 1]);
17
+ export const Uint = (size) => {
18
+ assertWidth("Uint", size);
19
+ return Schema.Int.check(Schema.isBetween({ minimum: 0, maximum: 2 ** size - 1 }));
20
+ };
21
+ export const Int = (size) => {
22
+ assertWidth("Int", size);
23
+ return Schema.Int.check(Schema.isBetween({ minimum: -(2 ** (size - 1)), maximum: 2 ** (size - 1) - 1 }));
24
+ };
25
+ export const Uint8 = Uint(8);
26
+ export const Uint16 = Uint(16);
27
+ export const Uint32 = Uint(32);
28
+ export const Int8 = Int(8);
29
+ export const Int16 = Int(16);
30
+ export const Int32 = Int(32);
31
+ export const Uint64 = Schema.BigInt.check(Schema.isBetweenBigInt({ minimum: 0n, maximum: 2n ** 64n - 1n }));
32
+ export const Int64 = Schema.BigInt.check(Schema.isBetweenBigInt({ minimum: -(2n ** 63n), maximum: 2n ** 63n - 1n }));
33
+ export class ParseError extends Schema.TaggedError()("BinaryParseError", {
34
+ offset: Schema.Finite,
35
+ expected: Schema.Array(Schema.String),
36
+ found: Schema.UndefinedOr(Schema.Finite),
37
+ }) {
38
+ get message() {
39
+ const found = this.found === undefined ? "end of input" : `0x${hex(Uint8Array.of(this.found))}`;
40
+ return `byte ${this.offset}: expected ${describeExpected(this.expected)}, found ${found}`;
41
+ }
42
+ }
43
+ const toText = (bytes) => {
44
+ let binary = "";
45
+ for (const byte of bytes)
46
+ binary += String.fromCharCode(byte);
47
+ return binary;
48
+ };
49
+ const word = (size, name, littleEndian = false) => takeBytes(size, name).pipe(iso({
50
+ decode: (binary) => {
51
+ const bytes = littleEndian ? toBytes(binary).reverse() : toBytes(binary);
52
+ return bytes.reduce((value, byte) => (value << 8n) | BigInt(byte), 0n);
53
+ },
54
+ // A negative value is written as its two's complement.
55
+ encode: (value) => {
56
+ const bytes = Uint8Array.from({ length: size }, (_, index) => Number(BigInt.asUintN(8, value >> BigInt(8 * (size - 1 - index)))));
57
+ return toText(littleEndian ? bytes.reverse() : bytes);
58
+ },
59
+ }));
60
+ const integer = (size, name, schema, decode, littleEndian) => word(size, name, littleEndian).pipe(iso({ name, decode, encode: BigInt, is: Schema.is(schema) }));
61
+ const uint = (size, name, littleEndian = false) => integer(size, name, Uint(8 * size), Number, littleEndian);
62
+ const int = (size, name, littleEndian = false) => integer(size, name, Int(8 * size), (value) => Number(BigInt.asIntN(8 * size, value)), littleEndian);
63
+ const uint64Of = (name, littleEndian = false) => integer(8, name, Uint64, F.identity, littleEndian);
64
+ const int64Of = (name, littleEndian = false) => integer(8, name, Int64, (value) => BigInt.asIntN(64, value), littleEndian);
65
+ // Floats are read and written through one shared view, so a value costs no allocation.
66
+ const scratch = new DataView(new ArrayBuffer(8));
67
+ /**
68
+ * Every NaN prints as the quiet NaN the engine writes, so a payload or a
69
+ * signalling NaN in the input does not survive parsing and printing again.
70
+ */
71
+ const float = (size, name, littleEndian = false) => takeBytes(size, name).pipe(iso({
72
+ name,
73
+ // A float32 holds only the numbers that survive rounding to single precision.
74
+ is: (value) => Predicate.isNumber(value) && (size === 8 || Object.is(Math.fround(value), value)),
75
+ decode: (binary) => {
76
+ for (let index = 0; index < size; index++)
77
+ scratch.setUint8(index, binary.charCodeAt(index));
78
+ return size === 4
79
+ ? scratch.getFloat32(0, littleEndian)
80
+ : scratch.getFloat64(0, littleEndian);
81
+ },
82
+ encode: (value) => {
83
+ if (size === 4)
84
+ scratch.setFloat32(0, value, littleEndian);
85
+ else
86
+ scratch.setFloat64(0, value, littleEndian);
87
+ let binary = "";
88
+ for (let index = 0; index < size; index++) {
89
+ binary += String.fromCharCode(scratch.getUint8(index));
90
+ }
91
+ return binary;
92
+ },
93
+ }));
94
+ export const uint8 = uint(1, "uint8");
95
+ export const uint16 = uint(2, "uint16");
96
+ export const uint32 = uint(4, "uint32");
97
+ export const uint64 = uint64Of("uint64");
98
+ export const uint16le = uint(2, "uint16le", true);
99
+ export const uint32le = uint(4, "uint32le", true);
100
+ export const uint64le = uint64Of("uint64le", true);
101
+ export const int8 = int(1, "int8");
102
+ export const int16 = int(2, "int16");
103
+ export const int32 = int(4, "int32");
104
+ export const int64 = int64Of("int64");
105
+ export const int16le = int(2, "int16le", true);
106
+ export const int32le = int(4, "int32le", true);
107
+ export const int64le = int64Of("int64le", true);
108
+ export const float32 = float(4, "float32");
109
+ export const float64 = float(8, "float64");
110
+ export const float32le = float(4, "float32le", true);
111
+ export const float64le = float(8, "float64le", true);
112
+ // No length cap: a value too wide for a number is left for decoding to reject by range.
113
+ const leb128 = (name) => regex(/[\x80-\xff]*[\0-\x7f]/, name);
114
+ /** The encoded number, or a value outside the safe integer range when it is too large to hold. */
115
+ const fromLeb128 = (binary) => {
116
+ let value = 0;
117
+ for (let index = binary.length - 1; index >= 0; index--) {
118
+ value = value * 128 + (binary.charCodeAt(index) & 0x7f);
119
+ }
120
+ return value;
121
+ };
122
+ const toLeb128 = (value) => {
123
+ let binary = "";
124
+ let rest = value;
125
+ while (rest >= 128) {
126
+ binary += String.fromCharCode((rest % 128) | 0x80);
127
+ rest = Math.floor(rest / 128);
128
+ }
129
+ return binary + String.fromCharCode(rest);
130
+ };
131
+ /**
132
+ * Unsigned LEB128 within the safe integer range. Parsing accepts padded
133
+ * encodings of any length; printing writes the shortest one.
134
+ */
135
+ export const varuint = leb128("varuint").pipe(partialIso({
136
+ name: "varuint",
137
+ decode: (binary) => {
138
+ const value = fromLeb128(binary);
139
+ return Number.isSafeInteger(value)
140
+ ? Result.succeed(value)
141
+ : Result.fail({ message: "a varuint within the safe integer range" });
142
+ },
143
+ encode: (value) => isCount(value)
144
+ ? Result.succeed(toLeb128(value))
145
+ : Result.fail({ message: "expected a non-negative safe integer" }),
146
+ }));
147
+ /** Zigzag-encoded LEB128, as in protobuf `sint64`, for integers from -(2 ** 52) to 2 ** 52 - 1. */
148
+ export const varint = leb128("varint").pipe(partialIso({
149
+ name: "varint",
150
+ decode: (binary) => {
151
+ const value = fromLeb128(binary);
152
+ return Number.isSafeInteger(value)
153
+ ? Result.succeed(value % 2 === 0 ? value / 2 : -(value + 1) / 2)
154
+ : Result.fail({ message: "a varint from -(2 ** 52) to 2 ** 52 - 1" });
155
+ },
156
+ encode: (value) => Number.isSafeInteger(value) && value >= -(2 ** 52) && value < 2 ** 52
157
+ ? Result.succeed(toLeb128(value < 0 ? -2 * value - 1 : 2 * value))
158
+ : Result.fail({ message: "expected an integer from -(2 ** 52) to 2 ** 52 - 1" }),
159
+ }));
160
+ export const bits = (layout) => {
161
+ const fields = Object.entries(layout);
162
+ const name = fields.map(([key, size]) => `${key}:${size}`).join(" ");
163
+ const width = fields.reduce((total, [, size]) => total + size, 0);
164
+ if (width % 8 !== 0 || fields.some(([key, size]) => /^\d+$/.test(key) || !isWidth(size))) {
165
+ throw new RangeError(`bits: expected non-integer field names, widths of 1 to 53 bits, and a whole number of bytes, got ${name}`);
166
+ }
167
+ let shift = BigInt(width);
168
+ const slots = fields.map(([key, size]) => ({
169
+ key,
170
+ size,
171
+ shift: (shift -= BigInt(size)),
172
+ fits: Schema.is(Uint(size)),
173
+ }));
174
+ const grammar = word(width / 8, name).pipe(iso({
175
+ name,
176
+ decode: (value) =>
177
+ // SAFETY: slots holds every key of the layout, each within its declared width.
178
+ Object.fromEntries(slots.map(({ key, size, shift }) => [key, Number(BigInt.asUintN(size, value >> shift))])),
179
+ encode: (value) => {
180
+ const extra = Reflect.ownKeys(value).find((key) => !Object.hasOwn(layout, key));
181
+ if (extra !== undefined)
182
+ throw new RangeError(`unexpected field ${String(extra)}`);
183
+ return slots.reduce((result, { key, size, shift, fits }) => {
184
+ const field = value[key];
185
+ if (!fits(field)) {
186
+ throw new RangeError(`${key} must be an integer from 0 to ${2 ** size - 1}`);
187
+ }
188
+ return result | (BigInt(field) << shift);
189
+ }, 0n);
190
+ },
191
+ }));
192
+ return withKeys(grammar, Object.keys(layout));
193
+ };
194
+ const asBytes = iso({
195
+ name: "bytes",
196
+ is: Predicate.isUint8Array,
197
+ decode: toBytes,
198
+ encode: toText,
199
+ });
200
+ export const bytes = (count) => takeBytes(count).pipe(asBytes);
201
+ export const lengthPrefixed = (length) => prefixedBy(length, takeBytes).pipe(asBytes);
202
+ export const literal = (...values) => {
203
+ if (values.some((value) => !Schema.is(Uint8)(value))) {
204
+ throw new RangeError(`literal: expected bytes, got ${values.join(", ")}`);
205
+ }
206
+ return silent({
207
+ _tag: "Literal",
208
+ value: toText(Uint8Array.from(values)),
209
+ name: values.map((value) => `0x${hex(Uint8Array.of(value))}`).join(" "),
210
+ });
211
+ };
212
+ export const ascii = iso({
213
+ name: "ascii",
214
+ is: (value) => Predicate.isString(value) && /^[\0-\x7f]*$/.test(value),
215
+ decode: toText,
216
+ encode: toBytes,
217
+ });
218
+ export const utf8 = partialIso({
219
+ name: "utf8",
220
+ decode: (value) => {
221
+ try {
222
+ return Result.succeed(new TextDecoder("utf-8", { fatal: true, ignoreBOM: true }).decode(value));
223
+ }
224
+ catch {
225
+ return Result.fail({ message: "valid UTF-8" });
226
+ }
227
+ },
228
+ encode: (value) => value.isWellFormed()
229
+ ? Result.succeed(new TextEncoder().encode(value))
230
+ : Result.fail({ message: "expected a string without lone surrogates" }),
231
+ });
232
+ export const parse = (grammar, input) => Result.mapError(parseText(grammar, toText(input)), ({ pos, expected, found }) => new ParseError({ offset: pos, expected, found: found?.charCodeAt(0) }));
233
+ const printBytes = (printer) => (grammar, value) => Result.flatMap(printer(grammar, value), (binary) => nonByte.test(binary)
234
+ ? Result.fail(new PrintError({
235
+ issue: { _tag: "InvalidValue", expected: "only bytes to be printed", actual: value },
236
+ }))
237
+ : Result.succeed(toBytes(binary)));
238
+ const printUnchecked = printBytes(printUnknown);
239
+ const printVerified = printBytes(printCheckedUnknown);
240
+ export const print = printUnchecked;
241
+ export const printChecked = printVerified;
242
+ export const codec = (grammar, target, options) => {
243
+ const printer = options?.roundTrip === "off" ? printUnchecked : printVerified;
244
+ return codecFrom(Schema.Uint8Array, target, grammar, options?.identifier, (input) => parse(grammar, input), (value) => printer(grammar, value));
245
+ };
246
+ //# sourceMappingURL=binary.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"binary.js","sourceRoot":"","sources":["../src/binary.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,IAAI,CAAC,EAAE,SAAS,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAA;AAEjE,OAAO,EAAqB,SAAS,EAAE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AAC,IAAI,CACT,IAAI,UAAU,CAAC;QACb,KAAK,EAAE,EAAE,IAAI,EAAE,cAAc,EAAE,QAAQ,EAAE,0BAA0B,EAAE,MAAM,EAAE,KAAK,EAAE;KACrF,CAAC,CACH;IACH,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,CACpC,CAAA;AAEL,MAAM,cAAc,GAAG,UAAU,CAAC,YAAY,CAAC,CAAA;AAC/C,MAAM,aAAa,GAAG,UAAU,CAAC,mBAAmB,CAAC,CAAA;AAErD,MAAM,CAAC,MAAM,KAAK,GAChB,cAAc,CAAA;AAEhB,MAAM,CAAC,MAAM,YAAY,GAAiB,aAAa,CAAA;AAEvD,MAAM,CAAC,MAAM,KAAK,GAAG,CACnB,OAAmB,EACnB,MAAS,EACT,OAAsB,EACtB,EAAE;IACF,MAAM,OAAO,GAAG,OAAO,EAAE,SAAS,KAAK,KAAK,CAAC,CAAC,CAAC,cAAc,CAAC,CAAC,CAAC,aAAa,CAAA;IAC7E,OAAO,SAAS,CACd,MAAM,CAAC,UAAU,EACjB,MAAM,EACN,OAAO,EACP,OAAO,EAAE,UAAU,EACnB,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,OAAO,EAAE,KAAK,CAAC,EAChC,CAAC,KAAK,EAAE,EAAE,CAAC,OAAO,CAAC,OAAO,EAAE,KAAK,CAAC,CACnC,CAAA;AACH,CAAC,CAAA"}
@@ -0,0 +1,17 @@
1
+ import { type Result, Schema } from "effect";
2
+ import type { GrammarInternal } from "./core.ts";
3
+ import { PrintError } from "./errors.ts";
4
+ export interface CodecOptions {
5
+ readonly identifier?: string;
6
+ /**
7
+ * - `verify` (default): encoding prints, then parses the output back and
8
+ * fails if it decodes to a different value, so a codec never encodes a
9
+ * valid value into text that decodes as another. Reparses on every encode.
10
+ * - `off`: encoding prints without the check.
11
+ */
12
+ readonly roundTrip?: "verify" | "off";
13
+ }
14
+ export declare const codecFrom: <I, S extends Schema.Top>(source: Schema.Codec<I>, target: S, grammar: GrammarInternal, identifier: string | undefined, parse: (input: I) => Result.Result<S["Encoded"], {
15
+ readonly message: string;
16
+ }>, print: (value: S["Encoded"]) => Result.Result<I, PrintError>) => Schema.decodeTo<S, Schema.Codec<I, I, never, never>, never, never>;
17
+ //# sourceMappingURL=codec.d.ts.map