@bcts/dcbor-pattern 1.0.0-alpha.11

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 (73) hide show
  1. package/LICENSE +48 -0
  2. package/README.md +14 -0
  3. package/dist/index.cjs +6561 -0
  4. package/dist/index.cjs.map +1 -0
  5. package/dist/index.d.cts +2732 -0
  6. package/dist/index.d.cts.map +1 -0
  7. package/dist/index.d.mts +2732 -0
  8. package/dist/index.d.mts.map +1 -0
  9. package/dist/index.iife.js +6562 -0
  10. package/dist/index.iife.js.map +1 -0
  11. package/dist/index.mjs +6244 -0
  12. package/dist/index.mjs.map +1 -0
  13. package/package.json +85 -0
  14. package/src/error.ts +333 -0
  15. package/src/format.ts +299 -0
  16. package/src/index.ts +20 -0
  17. package/src/interval.ts +230 -0
  18. package/src/parse/index.ts +95 -0
  19. package/src/parse/meta/and-parser.ts +47 -0
  20. package/src/parse/meta/capture-parser.ts +56 -0
  21. package/src/parse/meta/index.ts +13 -0
  22. package/src/parse/meta/not-parser.ts +28 -0
  23. package/src/parse/meta/or-parser.ts +47 -0
  24. package/src/parse/meta/primary-parser.ts +420 -0
  25. package/src/parse/meta/repeat-parser.ts +133 -0
  26. package/src/parse/meta/search-parser.ts +56 -0
  27. package/src/parse/parse-registry.ts +31 -0
  28. package/src/parse/structure/array-parser.ts +210 -0
  29. package/src/parse/structure/index.ts +9 -0
  30. package/src/parse/structure/map-parser.ts +128 -0
  31. package/src/parse/structure/tagged-parser.ts +269 -0
  32. package/src/parse/token.ts +997 -0
  33. package/src/parse/value/bool-parser.ts +33 -0
  34. package/src/parse/value/bytestring-parser.ts +42 -0
  35. package/src/parse/value/date-parser.ts +24 -0
  36. package/src/parse/value/digest-parser.ts +24 -0
  37. package/src/parse/value/index.ts +14 -0
  38. package/src/parse/value/known-value-parser.ts +24 -0
  39. package/src/parse/value/null-parser.ts +19 -0
  40. package/src/parse/value/number-parser.ts +19 -0
  41. package/src/parse/value/text-parser.ts +43 -0
  42. package/src/pattern/index.ts +740 -0
  43. package/src/pattern/match-registry.ts +137 -0
  44. package/src/pattern/matcher.ts +388 -0
  45. package/src/pattern/meta/and-pattern.ts +56 -0
  46. package/src/pattern/meta/any-pattern.ts +43 -0
  47. package/src/pattern/meta/capture-pattern.ts +57 -0
  48. package/src/pattern/meta/index.ts +168 -0
  49. package/src/pattern/meta/not-pattern.ts +70 -0
  50. package/src/pattern/meta/or-pattern.ts +56 -0
  51. package/src/pattern/meta/repeat-pattern.ts +117 -0
  52. package/src/pattern/meta/search-pattern.ts +298 -0
  53. package/src/pattern/meta/sequence-pattern.ts +72 -0
  54. package/src/pattern/structure/array-pattern/assigner.ts +95 -0
  55. package/src/pattern/structure/array-pattern/backtrack.ts +240 -0
  56. package/src/pattern/structure/array-pattern/helpers.ts +140 -0
  57. package/src/pattern/structure/array-pattern/index.ts +502 -0
  58. package/src/pattern/structure/index.ts +122 -0
  59. package/src/pattern/structure/map-pattern.ts +255 -0
  60. package/src/pattern/structure/tagged-pattern.ts +190 -0
  61. package/src/pattern/value/bool-pattern.ts +67 -0
  62. package/src/pattern/value/bytes-utils.ts +48 -0
  63. package/src/pattern/value/bytestring-pattern.ts +111 -0
  64. package/src/pattern/value/date-pattern.ts +162 -0
  65. package/src/pattern/value/digest-pattern.ts +136 -0
  66. package/src/pattern/value/index.ts +168 -0
  67. package/src/pattern/value/known-value-pattern.ts +123 -0
  68. package/src/pattern/value/null-pattern.ts +46 -0
  69. package/src/pattern/value/number-pattern.ts +181 -0
  70. package/src/pattern/value/text-pattern.ts +82 -0
  71. package/src/pattern/vm.ts +619 -0
  72. package/src/quantifier.ts +185 -0
  73. package/src/reluctance.ts +65 -0
@@ -0,0 +1,2732 @@
1
+ import { Cbor, CborDate, Tag } from "@bcts/dcbor";
2
+ import { KnownValue } from "@bcts/known-values";
3
+ import { Digest } from "@bcts/components";
4
+
5
+ //#region src/interval.d.ts
6
+
7
+ /**
8
+ * Provides an `Interval` type representing a range of values with a
9
+ * minimum and optional maximum.
10
+ *
11
+ * This module is used in the context of pattern matching for dCBOR items
12
+ * to represent cardinality specifications like `{n}`, `{n,m}`, or `{n,}`
13
+ * in pattern expressions.
14
+ *
15
+ * @module interval
16
+ */
17
+ /**
18
+ * Represents an inclusive interval with a minimum value and an optional
19
+ * maximum value.
20
+ *
21
+ * When the maximum is `undefined`, the interval is considered unbounded above.
22
+ *
23
+ * @example
24
+ * ```typescript
25
+ * // Single value interval
26
+ * const exact = new Interval(3, 3); // Matches exactly 3
27
+ *
28
+ * // Bounded range
29
+ * const range = new Interval(1, 5); // Matches 1 to 5 inclusive
30
+ *
31
+ * // Unbounded range
32
+ * const unbounded = new Interval(2); // Matches 2 or more
33
+ * ```
34
+ */
35
+ declare class Interval {
36
+ #private;
37
+ /**
38
+ * Creates a new Interval.
39
+ *
40
+ * @param min - The minimum value (inclusive)
41
+ * @param max - The maximum value (inclusive), or undefined for unbounded
42
+ */
43
+ constructor(min: number, max?: number);
44
+ /**
45
+ * Creates an interval from a range specification.
46
+ *
47
+ * @param start - The start of the range (inclusive)
48
+ * @param end - The end of the range (inclusive), or undefined for unbounded
49
+ * @returns A new Interval
50
+ */
51
+ static from(start: number, end?: number): Interval;
52
+ /**
53
+ * Creates an interval for exactly n occurrences.
54
+ *
55
+ * @param n - The exact count
56
+ * @returns A new Interval with min = max = n
57
+ */
58
+ static exactly(n: number): Interval;
59
+ /**
60
+ * Creates an interval for at least n occurrences.
61
+ *
62
+ * @param n - The minimum count
63
+ * @returns A new Interval with min = n and no maximum
64
+ */
65
+ static atLeast(n: number): Interval;
66
+ /**
67
+ * Creates an interval for at most n occurrences.
68
+ *
69
+ * @param n - The maximum count
70
+ * @returns A new Interval with min = 0 and max = n
71
+ */
72
+ static atMost(n: number): Interval;
73
+ /**
74
+ * Creates an interval for zero or more occurrences (0..).
75
+ *
76
+ * @returns A new Interval representing *
77
+ */
78
+ static zeroOrMore(): Interval;
79
+ /**
80
+ * Creates an interval for one or more occurrences (1..).
81
+ *
82
+ * @returns A new Interval representing +
83
+ */
84
+ static oneOrMore(): Interval;
85
+ /**
86
+ * Creates an interval for zero or one occurrence (0..=1).
87
+ *
88
+ * @returns A new Interval representing ?
89
+ */
90
+ static zeroOrOne(): Interval;
91
+ /**
92
+ * Returns the minimum value of the interval.
93
+ */
94
+ min(): number;
95
+ /**
96
+ * Returns the maximum value of the interval, or `undefined` if unbounded.
97
+ */
98
+ max(): number | undefined;
99
+ /**
100
+ * Checks if the given count falls within this interval.
101
+ *
102
+ * @param count - The count to check
103
+ * @returns true if count is within the interval
104
+ */
105
+ contains(count: number): boolean;
106
+ /**
107
+ * Checks if the interval represents a single value (i.e., min equals max).
108
+ */
109
+ isSingle(): boolean;
110
+ /**
111
+ * Checks if the interval is unbounded (i.e., has no maximum value).
112
+ */
113
+ isUnbounded(): boolean;
114
+ /**
115
+ * Returns a string representation of the interval using standard range notation.
116
+ *
117
+ * @returns The range notation string
118
+ *
119
+ * @example
120
+ * ```typescript
121
+ * new Interval(3, 3).rangeNotation() // "{3}"
122
+ * new Interval(1, 5).rangeNotation() // "{1,5}"
123
+ * new Interval(2).rangeNotation() // "{2,}"
124
+ * ```
125
+ */
126
+ rangeNotation(): string;
127
+ /**
128
+ * Returns a string representation of the interval using shorthand notation
129
+ * where applicable.
130
+ *
131
+ * @returns The shorthand notation string
132
+ *
133
+ * @example
134
+ * ```typescript
135
+ * new Interval(0, 1).shorthandNotation() // "?"
136
+ * new Interval(0).shorthandNotation() // "*"
137
+ * new Interval(1).shorthandNotation() // "+"
138
+ * new Interval(1, 5).shorthandNotation() // "{1,5}"
139
+ * ```
140
+ */
141
+ shorthandNotation(): string;
142
+ /**
143
+ * Returns a string representation using range notation.
144
+ */
145
+ toString(): string;
146
+ /**
147
+ * Checks equality with another Interval.
148
+ */
149
+ equals(other: Interval): boolean;
150
+ }
151
+ /**
152
+ * Default interval is exactly 1 occurrence.
153
+ */
154
+ declare const DEFAULT_INTERVAL: Interval;
155
+ //#endregion
156
+ //#region src/reluctance.d.ts
157
+ /**
158
+ * Reluctance for quantifiers.
159
+ *
160
+ * This module defines the matching behavior for quantified patterns,
161
+ * controlling how greedily the pattern matcher consumes input.
162
+ *
163
+ * @module reluctance
164
+ */
165
+ /**
166
+ * Reluctance for quantifiers.
167
+ *
168
+ * Controls how a quantified pattern matches:
169
+ * - `Greedy`: Match as many as possible, backtrack if needed
170
+ * - `Lazy`: Match as few as possible, add more if needed
171
+ * - `Possessive`: Match as many as possible, never backtrack
172
+ */
173
+ declare enum Reluctance {
174
+ /**
175
+ * Grabs as many repetitions as possible, then backtracks if the rest of
176
+ * the pattern cannot match.
177
+ */
178
+ Greedy = "greedy",
179
+ /**
180
+ * Starts with as few repetitions as possible, adding more only if the rest
181
+ * of the pattern cannot match.
182
+ */
183
+ Lazy = "lazy",
184
+ /**
185
+ * Grabs as many repetitions as possible and never backtracks; if the rest
186
+ * of the pattern cannot match, the whole match fails.
187
+ */
188
+ Possessive = "possessive",
189
+ }
190
+ /**
191
+ * Default reluctance is Greedy.
192
+ */
193
+ declare const DEFAULT_RELUCTANCE = Reluctance.Greedy;
194
+ /**
195
+ * Returns the suffix character for a reluctance type.
196
+ *
197
+ * @param reluctance - The reluctance type
198
+ * @returns The suffix string ("" for Greedy, "?" for Lazy, "+" for Possessive)
199
+ *
200
+ * @example
201
+ * ```typescript
202
+ * reluctanceSuffix(Reluctance.Greedy) // ""
203
+ * reluctanceSuffix(Reluctance.Lazy) // "?"
204
+ * reluctanceSuffix(Reluctance.Possessive) // "+"
205
+ * ```
206
+ */
207
+ declare const reluctanceSuffix: (reluctance: Reluctance) => string;
208
+ //#endregion
209
+ //#region src/quantifier.d.ts
210
+ /**
211
+ * Defines how many times a pattern may or must match, with an interval and a
212
+ * reluctance.
213
+ *
214
+ * @example
215
+ * ```typescript
216
+ * // Zero or more, greedy
217
+ * const star = Quantifier.zeroOrMore();
218
+ *
219
+ * // One or more, lazy
220
+ * const plusLazy = Quantifier.oneOrMore(Reluctance.Lazy);
221
+ *
222
+ * // Exactly 3 times
223
+ * const exact = Quantifier.exactly(3);
224
+ *
225
+ * // Between 2 and 5, possessive
226
+ * const range = Quantifier.between(2, 5, Reluctance.Possessive);
227
+ * ```
228
+ */
229
+ declare class Quantifier {
230
+ #private;
231
+ /**
232
+ * Creates a new Quantifier.
233
+ *
234
+ * @param interval - The interval defining how many times to match
235
+ * @param reluctance - The matching strategy (default: Greedy)
236
+ */
237
+ constructor(interval: Interval, reluctance?: Reluctance);
238
+ /**
239
+ * Creates a quantifier from min/max values.
240
+ *
241
+ * @param min - Minimum occurrences
242
+ * @param max - Maximum occurrences (undefined for unbounded)
243
+ * @param reluctance - The matching strategy
244
+ */
245
+ static from(min: number, max?: number, reluctance?: Reluctance): Quantifier;
246
+ /**
247
+ * Creates a quantifier for exactly n occurrences.
248
+ */
249
+ static exactly(n: number, reluctance?: Reluctance): Quantifier;
250
+ /**
251
+ * Creates a quantifier for at least n occurrences.
252
+ */
253
+ static atLeast(n: number, reluctance?: Reluctance): Quantifier;
254
+ /**
255
+ * Creates a quantifier for at most n occurrences.
256
+ */
257
+ static atMost(n: number, reluctance?: Reluctance): Quantifier;
258
+ /**
259
+ * Creates a quantifier for between min and max occurrences.
260
+ */
261
+ static between(min: number, max: number, reluctance?: Reluctance): Quantifier;
262
+ /**
263
+ * Creates a quantifier for zero or more occurrences (*).
264
+ */
265
+ static zeroOrMore(reluctance?: Reluctance): Quantifier;
266
+ /**
267
+ * Creates a quantifier for one or more occurrences (+).
268
+ */
269
+ static oneOrMore(reluctance?: Reluctance): Quantifier;
270
+ /**
271
+ * Creates a quantifier for zero or one occurrence (?).
272
+ */
273
+ static zeroOrOne(reluctance?: Reluctance): Quantifier;
274
+ /**
275
+ * Returns the minimum number of occurrences.
276
+ */
277
+ min(): number;
278
+ /**
279
+ * Returns the maximum number of occurrences, or undefined if unbounded.
280
+ */
281
+ max(): number | undefined;
282
+ /**
283
+ * Returns the interval.
284
+ */
285
+ interval(): Interval;
286
+ /**
287
+ * Returns the reluctance (matching strategy).
288
+ */
289
+ reluctance(): Reluctance;
290
+ /**
291
+ * Checks if the given count is within the quantifier's range.
292
+ */
293
+ contains(count: number): boolean;
294
+ /**
295
+ * Checks if the quantifier is unbounded (no maximum).
296
+ */
297
+ isUnbounded(): boolean;
298
+ /**
299
+ * Returns a string representation of the quantifier.
300
+ *
301
+ * @example
302
+ * ```typescript
303
+ * Quantifier.zeroOrMore().toString() // "*"
304
+ * Quantifier.zeroOrMore(Reluctance.Lazy).toString() // "*?"
305
+ * Quantifier.between(1, 5).toString() // "{1,5}"
306
+ * ```
307
+ */
308
+ toString(): string;
309
+ /**
310
+ * Checks equality with another Quantifier.
311
+ */
312
+ equals(other: Quantifier): boolean;
313
+ /**
314
+ * Converts to an Interval (discarding reluctance).
315
+ */
316
+ toInterval(): Interval;
317
+ }
318
+ /**
319
+ * Default quantifier is exactly 1 occurrence, greedy.
320
+ */
321
+ declare const DEFAULT_QUANTIFIER: Quantifier;
322
+ //#endregion
323
+ //#region src/parse/token.d.ts
324
+ /**
325
+ * Token types for dCBOR pattern parsing.
326
+ *
327
+ * This is a discriminated union matching the Rust Token enum.
328
+ */
329
+ type Token = {
330
+ readonly type: "And";
331
+ } | {
332
+ readonly type: "Or";
333
+ } | {
334
+ readonly type: "Not";
335
+ } | {
336
+ readonly type: "RepeatZeroOrMore";
337
+ } | {
338
+ readonly type: "RepeatZeroOrMoreLazy";
339
+ } | {
340
+ readonly type: "RepeatZeroOrMorePossessive";
341
+ } | {
342
+ readonly type: "RepeatOneOrMore";
343
+ } | {
344
+ readonly type: "RepeatOneOrMoreLazy";
345
+ } | {
346
+ readonly type: "RepeatOneOrMorePossessive";
347
+ } | {
348
+ readonly type: "RepeatZeroOrOne";
349
+ } | {
350
+ readonly type: "RepeatZeroOrOneLazy";
351
+ } | {
352
+ readonly type: "RepeatZeroOrOnePossessive";
353
+ } | {
354
+ readonly type: "Tagged";
355
+ } | {
356
+ readonly type: "Array";
357
+ } | {
358
+ readonly type: "Map";
359
+ } | {
360
+ readonly type: "Bool";
361
+ } | {
362
+ readonly type: "ByteString";
363
+ } | {
364
+ readonly type: "Date";
365
+ } | {
366
+ readonly type: "Known";
367
+ } | {
368
+ readonly type: "Null";
369
+ } | {
370
+ readonly type: "Number";
371
+ } | {
372
+ readonly type: "Text";
373
+ } | {
374
+ readonly type: "Digest";
375
+ } | {
376
+ readonly type: "Search";
377
+ } | {
378
+ readonly type: "BoolTrue";
379
+ } | {
380
+ readonly type: "BoolFalse";
381
+ } | {
382
+ readonly type: "NaN";
383
+ } | {
384
+ readonly type: "Infinity";
385
+ } | {
386
+ readonly type: "NegInfinity";
387
+ } | {
388
+ readonly type: "ParenOpen";
389
+ } | {
390
+ readonly type: "ParenClose";
391
+ } | {
392
+ readonly type: "BracketOpen";
393
+ } | {
394
+ readonly type: "BracketClose";
395
+ } | {
396
+ readonly type: "BraceOpen";
397
+ } | {
398
+ readonly type: "BraceClose";
399
+ } | {
400
+ readonly type: "Comma";
401
+ } | {
402
+ readonly type: "Colon";
403
+ } | {
404
+ readonly type: "Ellipsis";
405
+ } | {
406
+ readonly type: "GreaterThanOrEqual";
407
+ } | {
408
+ readonly type: "LessThanOrEqual";
409
+ } | {
410
+ readonly type: "GreaterThan";
411
+ } | {
412
+ readonly type: "LessThan";
413
+ } | {
414
+ readonly type: "NumberLiteral";
415
+ readonly value: number;
416
+ } | {
417
+ readonly type: "GroupName";
418
+ readonly name: string;
419
+ } | {
420
+ readonly type: "StringLiteral";
421
+ readonly value: string;
422
+ } | {
423
+ readonly type: "SingleQuoted";
424
+ readonly value: string;
425
+ } | {
426
+ readonly type: "Regex";
427
+ readonly pattern: string;
428
+ } | {
429
+ readonly type: "HexString";
430
+ readonly value: Uint8Array;
431
+ } | {
432
+ readonly type: "HexRegex";
433
+ readonly pattern: string;
434
+ } | {
435
+ readonly type: "DateQuoted";
436
+ readonly value: string;
437
+ } | {
438
+ readonly type: "DigestQuoted";
439
+ readonly value: string;
440
+ } | {
441
+ readonly type: "Range";
442
+ readonly quantifier: Quantifier;
443
+ };
444
+ /**
445
+ * A token with its position in the source.
446
+ */
447
+ interface SpannedToken {
448
+ readonly token: Token;
449
+ readonly span: Span;
450
+ }
451
+ /**
452
+ * Lexer state for tokenizing dCBOR pattern expressions.
453
+ */
454
+ declare class Lexer {
455
+ #private;
456
+ constructor(input: string);
457
+ /**
458
+ * Creates a new lexer for the given input.
459
+ */
460
+ static new(input: string): Lexer;
461
+ /**
462
+ * Returns the input string.
463
+ */
464
+ input(): string;
465
+ /**
466
+ * Returns the current position in the input.
467
+ */
468
+ position(): number;
469
+ /**
470
+ * Returns the remaining input.
471
+ */
472
+ remainder(): string;
473
+ /**
474
+ * Peeks at the current character without consuming it.
475
+ */
476
+ peek(): string | undefined;
477
+ /**
478
+ * Peeks at the character at offset from current position.
479
+ */
480
+ peekAt(offset: number): string | undefined;
481
+ /**
482
+ * Consumes and returns the current character.
483
+ */
484
+ advance(): string | undefined;
485
+ /**
486
+ * Advances by n characters.
487
+ */
488
+ bump(n: number): void;
489
+ /**
490
+ * Creates a span from start to current position.
491
+ */
492
+ spanFrom(start: number): Span;
493
+ /**
494
+ * Skips whitespace characters.
495
+ */
496
+ skipWhitespace(): void;
497
+ /**
498
+ * Checks if the remainder starts with the given string.
499
+ */
500
+ startsWith(s: string): boolean;
501
+ /**
502
+ * Gets the next token.
503
+ */
504
+ next(): Result<SpannedToken> | undefined;
505
+ /**
506
+ * Tokenizes the entire input and returns all tokens.
507
+ */
508
+ tokenize(): Result<SpannedToken[]>;
509
+ /**
510
+ * Parse { - could be BraceOpen or Range.
511
+ */
512
+ private parseBraceOpen;
513
+ /**
514
+ * Check if content looks like a range pattern.
515
+ */
516
+ private looksLikeRangePattern;
517
+ /**
518
+ * Parse a range pattern like {1,5} or {3,} or {5}.
519
+ */
520
+ private parseRange;
521
+ /**
522
+ * Parse a string literal.
523
+ */
524
+ private parseString;
525
+ /**
526
+ * Parse a single-quoted string.
527
+ */
528
+ private parseSingleQuoted;
529
+ /**
530
+ * Parse a regex pattern.
531
+ */
532
+ private parseRegex;
533
+ /**
534
+ * Parse a group name.
535
+ */
536
+ private parseGroupName;
537
+ /**
538
+ * Parse a hex string.
539
+ */
540
+ private parseHexString;
541
+ /**
542
+ * Parse a hex regex pattern.
543
+ */
544
+ private parseHexRegex;
545
+ /**
546
+ * Parse a number literal.
547
+ */
548
+ private parseNumber;
549
+ /**
550
+ * Parse an identifier or keyword.
551
+ */
552
+ private parseIdentifierOrKeyword;
553
+ /**
554
+ * Parse a date quoted pattern.
555
+ */
556
+ private parseDateQuoted;
557
+ /**
558
+ * Parse a digest quoted pattern.
559
+ */
560
+ private parseDigestQuoted;
561
+ /**
562
+ * Peeks at the next token without consuming it.
563
+ * Returns a Result with the token or undefined if at end of input.
564
+ */
565
+ peekToken(): Result<Token> | undefined;
566
+ /**
567
+ * Returns the current span (position to position).
568
+ */
569
+ span(): Span;
570
+ /**
571
+ * Returns the last token's span.
572
+ */
573
+ lastSpan(): Span;
574
+ }
575
+ //#endregion
576
+ //#region src/error.d.ts
577
+ /**
578
+ * Represents a span in the input string, indicating position for error reporting.
579
+ */
580
+ interface Span {
581
+ readonly start: number;
582
+ readonly end: number;
583
+ }
584
+ /**
585
+ * Creates a new Span.
586
+ */
587
+ declare const span: (start: number, end: number) => Span;
588
+ /**
589
+ * Errors that can occur during parsing of dCBOR patterns.
590
+ *
591
+ * This is a discriminated union type matching the Rust Error enum.
592
+ */
593
+ type Error = {
594
+ readonly type: "EmptyInput";
595
+ } | {
596
+ readonly type: "UnexpectedEndOfInput";
597
+ } | {
598
+ readonly type: "ExtraData";
599
+ readonly span: Span;
600
+ } | {
601
+ readonly type: "UnexpectedToken";
602
+ readonly token: Token;
603
+ readonly span: Span;
604
+ } | {
605
+ readonly type: "UnrecognizedToken";
606
+ readonly span: Span;
607
+ } | {
608
+ readonly type: "InvalidRegex";
609
+ readonly span: Span;
610
+ } | {
611
+ readonly type: "UnterminatedRegex";
612
+ readonly span: Span;
613
+ } | {
614
+ readonly type: "UnterminatedString";
615
+ readonly span: Span;
616
+ } | {
617
+ readonly type: "InvalidRange";
618
+ readonly span: Span;
619
+ } | {
620
+ readonly type: "InvalidHexString";
621
+ readonly span: Span;
622
+ } | {
623
+ readonly type: "UnterminatedHexString";
624
+ readonly span: Span;
625
+ } | {
626
+ readonly type: "InvalidDateFormat";
627
+ readonly span: Span;
628
+ } | {
629
+ readonly type: "InvalidNumberFormat";
630
+ readonly span: Span;
631
+ } | {
632
+ readonly type: "InvalidUr";
633
+ readonly message: string;
634
+ readonly span: Span;
635
+ } | {
636
+ readonly type: "ExpectedOpenParen";
637
+ readonly span: Span;
638
+ } | {
639
+ readonly type: "ExpectedCloseParen";
640
+ readonly span: Span;
641
+ } | {
642
+ readonly type: "ExpectedCloseBracket";
643
+ readonly span: Span;
644
+ } | {
645
+ readonly type: "ExpectedCloseBrace";
646
+ readonly span: Span;
647
+ } | {
648
+ readonly type: "ExpectedColon";
649
+ readonly span: Span;
650
+ } | {
651
+ readonly type: "ExpectedPattern";
652
+ readonly span: Span;
653
+ } | {
654
+ readonly type: "UnmatchedParentheses";
655
+ readonly span: Span;
656
+ } | {
657
+ readonly type: "UnmatchedBraces";
658
+ readonly span: Span;
659
+ } | {
660
+ readonly type: "InvalidCaptureGroupName";
661
+ readonly name: string;
662
+ readonly span: Span;
663
+ } | {
664
+ readonly type: "InvalidDigestPattern";
665
+ readonly message: string;
666
+ readonly span: Span;
667
+ } | {
668
+ readonly type: "UnterminatedDigestQuoted";
669
+ readonly span: Span;
670
+ } | {
671
+ readonly type: "UnterminatedDateQuoted";
672
+ readonly span: Span;
673
+ } | {
674
+ readonly type: "InvalidDigest";
675
+ readonly span: Span;
676
+ } | {
677
+ readonly type: "InvalidDate";
678
+ readonly span: Span;
679
+ } | {
680
+ readonly type: "Unknown";
681
+ };
682
+ /**
683
+ * A Result type specialized for dCBOR pattern parsing.
684
+ * Matches Rust's Result<T, Error> pattern.
685
+ */
686
+ type Result<T> = {
687
+ readonly ok: true;
688
+ readonly value: T;
689
+ } | {
690
+ readonly ok: false;
691
+ readonly error: Error;
692
+ };
693
+ /**
694
+ * Creates a successful Result.
695
+ */
696
+ declare const Ok: <T>(value: T) => Result<T>;
697
+ /**
698
+ * Creates a failed Result.
699
+ */
700
+ declare const Err: <T>(error: Error) => Result<T>;
701
+ /**
702
+ * Unwraps a Result, throwing an error if it's not Ok.
703
+ */
704
+ declare const unwrap: <T>(result: Result<T>) => T;
705
+ /**
706
+ * Unwraps a Result, returning the default value if it's an error.
707
+ */
708
+ declare const unwrapOr: <T>(result: Result<T>, defaultValue: T) => T;
709
+ /**
710
+ * Maps a Result's value if it's Ok.
711
+ */
712
+ declare const map: <T, U>(result: Result<T>, fn: (value: T) => U) => Result<U>;
713
+ /**
714
+ * Converts an Error to a human-readable string.
715
+ */
716
+ declare const errorToString: (error: Error) => string;
717
+ /**
718
+ * Adjusts the span of an error by adding the given offset to both start and end positions.
719
+ * Returns a new error with adjusted span, or the original error if it has no span.
720
+ */
721
+ declare const adjustSpan: (error: Error, offset: number) => Error;
722
+ /**
723
+ * JavaScript Error class wrapper for PatternError.
724
+ * Provides stack traces and works with try/catch blocks.
725
+ */
726
+ declare class PatternError extends globalThis.Error {
727
+ readonly errorType: Error;
728
+ constructor(errorType: Error, message?: string);
729
+ }
730
+ //#endregion
731
+ //#region src/format.d.ts
732
+ /**
733
+ * A Path is a sequence of CBOR values representing the traversal from root
734
+ * to a matched element.
735
+ */
736
+ type Path = Cbor[];
737
+ /**
738
+ * A builder that provides formatting options for each path element.
739
+ */
740
+ declare enum PathElementFormat {
741
+ /**
742
+ * Diagnostic summary format, with optional maximum length for truncation.
743
+ */
744
+ DiagnosticSummary = "diagnostic_summary",
745
+ /**
746
+ * Flat diagnostic format (single line), with optional maximum length for
747
+ * truncation.
748
+ */
749
+ DiagnosticFlat = "diagnostic_flat",
750
+ }
751
+ /**
752
+ * Options for formatting paths.
753
+ */
754
+ interface FormatPathsOpts {
755
+ /**
756
+ * Whether to indent each path element.
757
+ * If true, each element will be indented by 4 spaces per level.
758
+ * @default true
759
+ */
760
+ readonly indent: boolean;
761
+ /**
762
+ * Format for each path element.
763
+ * @default PathElementFormat.DiagnosticSummary
764
+ */
765
+ readonly elementFormat: PathElementFormat;
766
+ /**
767
+ * Maximum length for element representation before truncation.
768
+ * If undefined, no truncation is applied.
769
+ */
770
+ readonly maxLength: number | undefined;
771
+ /**
772
+ * If true, only the last element of each path will be formatted.
773
+ * This is useful for displaying only the final destination of a path.
774
+ * If false, all elements will be formatted.
775
+ * @default false
776
+ */
777
+ readonly lastElementOnly: boolean;
778
+ }
779
+ /**
780
+ * Default formatting options.
781
+ */
782
+ declare const DEFAULT_FORMAT_OPTS: FormatPathsOpts;
783
+ /**
784
+ * Creates formatting options with builder pattern.
785
+ */
786
+ declare class FormatPathsOptsBuilder {
787
+ #private;
788
+ constructor();
789
+ /**
790
+ * Creates a new builder with default options.
791
+ */
792
+ static new(): FormatPathsOptsBuilder;
793
+ /**
794
+ * Sets whether to indent each path element.
795
+ */
796
+ indent(indent: boolean): FormatPathsOptsBuilder;
797
+ /**
798
+ * Sets the format for each path element.
799
+ */
800
+ elementFormat(format: PathElementFormat): FormatPathsOptsBuilder;
801
+ /**
802
+ * Sets the maximum length for element representation.
803
+ */
804
+ maxLength(length: number | undefined): FormatPathsOptsBuilder;
805
+ /**
806
+ * Sets whether to format only the last element of each path.
807
+ */
808
+ lastElementOnly(lastOnly: boolean): FormatPathsOptsBuilder;
809
+ /**
810
+ * Builds the options object.
811
+ */
812
+ build(): FormatPathsOpts;
813
+ }
814
+ /**
815
+ * Format each path element on its own line, each line successively indented by
816
+ * 4 spaces. Options can be provided to customize the formatting.
817
+ *
818
+ * @param path - The path to format
819
+ * @param opts - Formatting options
820
+ * @returns The formatted path string
821
+ */
822
+ declare const formatPathOpt: (path: Path, opts?: FormatPathsOpts) => string;
823
+ /**
824
+ * Format each path element on its own line, each line successively indented by
825
+ * 4 spaces.
826
+ *
827
+ * @param path - The path to format
828
+ * @returns The formatted path string
829
+ */
830
+ declare const formatPath: (path: Path) => string;
831
+ /**
832
+ * Format multiple paths with captures in a structured way.
833
+ * Captures come first, sorted lexicographically by name, with their name
834
+ * prefixed by '@'. Regular paths follow after all captures.
835
+ *
836
+ * @param paths - The paths to format
837
+ * @param captures - Named capture groups and their paths
838
+ * @param opts - Formatting options
839
+ * @returns The formatted string
840
+ */
841
+ declare const formatPathsWithCaptures: (paths: Path[], captures: Map<string, Path[]>, opts?: FormatPathsOpts) => string;
842
+ /**
843
+ * Format multiple paths with custom formatting options.
844
+ *
845
+ * @param paths - The paths to format
846
+ * @param opts - Formatting options
847
+ * @returns The formatted string
848
+ */
849
+ declare const formatPathsOpt: (paths: Path[], opts?: FormatPathsOpts) => string;
850
+ /**
851
+ * Format multiple paths with default options.
852
+ *
853
+ * @param paths - The paths to format
854
+ * @returns The formatted string
855
+ */
856
+ declare const formatPaths: (paths: Path[]) => string;
857
+ //#endregion
858
+ //#region src/pattern/value/bool-pattern.d.ts
859
+ /**
860
+ * Pattern for matching boolean values in dCBOR.
861
+ */
862
+ type BoolPattern = {
863
+ readonly variant: "Any";
864
+ } | {
865
+ readonly variant: "Value";
866
+ readonly value: boolean;
867
+ };
868
+ /**
869
+ * Creates a BoolPattern that matches any boolean value.
870
+ */
871
+ declare const boolPatternAny: () => BoolPattern;
872
+ /**
873
+ * Creates a BoolPattern that matches a specific boolean value.
874
+ */
875
+ declare const boolPatternValue: (value: boolean) => BoolPattern;
876
+ /**
877
+ * Tests if a CBOR value matches this boolean pattern.
878
+ */
879
+ declare const boolPatternMatches: (pattern: BoolPattern, haystack: Cbor) => boolean;
880
+ /**
881
+ * Returns paths to matching boolean values.
882
+ */
883
+ declare const boolPatternPaths: (pattern: BoolPattern, haystack: Cbor) => Path[];
884
+ /**
885
+ * Formats a BoolPattern as a string.
886
+ */
887
+ declare const boolPatternDisplay: (pattern: BoolPattern) => string;
888
+ //#endregion
889
+ //#region src/pattern/value/null-pattern.d.ts
890
+ /**
891
+ * Pattern for matching null values in dCBOR.
892
+ * This is a unit type - there's only one way to match null.
893
+ */
894
+ interface NullPattern {
895
+ readonly variant: "Null";
896
+ }
897
+ /**
898
+ * Tests if a CBOR value matches the null pattern.
899
+ */
900
+ declare const nullPatternMatches: (_pattern: NullPattern, haystack: Cbor) => boolean;
901
+ /**
902
+ * Returns paths to matching null values.
903
+ */
904
+ declare const nullPatternPaths: (pattern: NullPattern, haystack: Cbor) => Path[];
905
+ /**
906
+ * Formats a NullPattern as a string.
907
+ */
908
+ declare const nullPatternDisplay: (_pattern: NullPattern) => string;
909
+ //#endregion
910
+ //#region src/pattern/value/number-pattern.d.ts
911
+ /**
912
+ * Pattern for matching number values in dCBOR.
913
+ */
914
+ type NumberPattern = {
915
+ readonly variant: "Any";
916
+ } | {
917
+ readonly variant: "Value";
918
+ readonly value: number;
919
+ } | {
920
+ readonly variant: "Range";
921
+ readonly min: number;
922
+ readonly max: number;
923
+ } | {
924
+ readonly variant: "GreaterThan";
925
+ readonly value: number;
926
+ } | {
927
+ readonly variant: "GreaterThanOrEqual";
928
+ readonly value: number;
929
+ } | {
930
+ readonly variant: "LessThan";
931
+ readonly value: number;
932
+ } | {
933
+ readonly variant: "LessThanOrEqual";
934
+ readonly value: number;
935
+ } | {
936
+ readonly variant: "NaN";
937
+ } | {
938
+ readonly variant: "Infinity";
939
+ } | {
940
+ readonly variant: "NegInfinity";
941
+ };
942
+ /**
943
+ * Creates a NumberPattern that matches any number.
944
+ */
945
+ declare const numberPatternAny: () => NumberPattern;
946
+ /**
947
+ * Creates a NumberPattern that matches a specific number.
948
+ */
949
+ declare const numberPatternValue: (value: number) => NumberPattern;
950
+ /**
951
+ * Creates a NumberPattern that matches numbers within a range (inclusive).
952
+ */
953
+ declare const numberPatternRange: (min: number, max: number) => NumberPattern;
954
+ /**
955
+ * Creates a NumberPattern that matches numbers greater than a value.
956
+ */
957
+ declare const numberPatternGreaterThan: (value: number) => NumberPattern;
958
+ /**
959
+ * Creates a NumberPattern that matches numbers greater than or equal to a value.
960
+ */
961
+ declare const numberPatternGreaterThanOrEqual: (value: number) => NumberPattern;
962
+ /**
963
+ * Creates a NumberPattern that matches numbers less than a value.
964
+ */
965
+ declare const numberPatternLessThan: (value: number) => NumberPattern;
966
+ /**
967
+ * Creates a NumberPattern that matches numbers less than or equal to a value.
968
+ */
969
+ declare const numberPatternLessThanOrEqual: (value: number) => NumberPattern;
970
+ /**
971
+ * Creates a NumberPattern that matches NaN.
972
+ */
973
+ declare const numberPatternNaN: () => NumberPattern;
974
+ /**
975
+ * Creates a NumberPattern that matches positive infinity.
976
+ */
977
+ declare const numberPatternInfinity: () => NumberPattern;
978
+ /**
979
+ * Creates a NumberPattern that matches negative infinity.
980
+ */
981
+ declare const numberPatternNegInfinity: () => NumberPattern;
982
+ /**
983
+ * Tests if a CBOR value matches this number pattern.
984
+ */
985
+ declare const numberPatternMatches: (pattern: NumberPattern, haystack: Cbor) => boolean;
986
+ /**
987
+ * Returns paths to matching number values.
988
+ */
989
+ declare const numberPatternPaths: (pattern: NumberPattern, haystack: Cbor) => Path[];
990
+ /**
991
+ * Formats a NumberPattern as a string.
992
+ */
993
+ declare const numberPatternDisplay: (pattern: NumberPattern) => string;
994
+ //#endregion
995
+ //#region src/pattern/value/text-pattern.d.ts
996
+ /**
997
+ * Pattern for matching text values in dCBOR.
998
+ */
999
+ type TextPattern = {
1000
+ readonly variant: "Any";
1001
+ } | {
1002
+ readonly variant: "Value";
1003
+ readonly value: string;
1004
+ } | {
1005
+ readonly variant: "Regex";
1006
+ readonly pattern: RegExp;
1007
+ };
1008
+ /**
1009
+ * Creates a TextPattern that matches any text.
1010
+ */
1011
+ declare const textPatternAny: () => TextPattern;
1012
+ /**
1013
+ * Creates a TextPattern that matches a specific text value.
1014
+ */
1015
+ declare const textPatternValue: (value: string) => TextPattern;
1016
+ /**
1017
+ * Creates a TextPattern that matches text by regex.
1018
+ */
1019
+ declare const textPatternRegex: (pattern: RegExp) => TextPattern;
1020
+ /**
1021
+ * Tests if a CBOR value matches this text pattern.
1022
+ */
1023
+ declare const textPatternMatches: (pattern: TextPattern, haystack: Cbor) => boolean;
1024
+ /**
1025
+ * Returns paths to matching text values.
1026
+ */
1027
+ declare const textPatternPaths: (pattern: TextPattern, haystack: Cbor) => Path[];
1028
+ /**
1029
+ * Formats a TextPattern as a string.
1030
+ */
1031
+ declare const textPatternDisplay: (pattern: TextPattern) => string;
1032
+ //#endregion
1033
+ //#region src/pattern/value/bytestring-pattern.d.ts
1034
+ /**
1035
+ * Pattern for matching byte string values in dCBOR.
1036
+ *
1037
+ * The BinaryRegex variant matches against raw bytes by converting them to
1038
+ * a Latin-1 string (where each byte 0-255 maps to exactly one character).
1039
+ * This mimics Rust's regex::bytes::Regex behavior.
1040
+ *
1041
+ * For example:
1042
+ * - To match bytes starting with 0x00: `/^\x00/`
1043
+ * - To match ASCII digits: `/^\d+$/`
1044
+ * - To match specific hex pattern: `/\x48\x65\x6c\x6c\x6f/` (matches "Hello")
1045
+ */
1046
+ type ByteStringPattern = {
1047
+ readonly variant: "Any";
1048
+ } | {
1049
+ readonly variant: "Value";
1050
+ readonly value: Uint8Array;
1051
+ } | {
1052
+ readonly variant: "BinaryRegex";
1053
+ readonly pattern: RegExp;
1054
+ };
1055
+ /**
1056
+ * Creates a ByteStringPattern that matches any byte string.
1057
+ */
1058
+ declare const byteStringPatternAny: () => ByteStringPattern;
1059
+ /**
1060
+ * Creates a ByteStringPattern that matches a specific byte string value.
1061
+ */
1062
+ declare const byteStringPatternValue: (value: Uint8Array) => ByteStringPattern;
1063
+ /**
1064
+ * Creates a ByteStringPattern that matches byte strings by binary regex.
1065
+ *
1066
+ * The regex matches against raw bytes converted to a Latin-1 string.
1067
+ * Use escape sequences like `\x00` to match specific byte values.
1068
+ *
1069
+ * @example
1070
+ * ```typescript
1071
+ * // Match bytes starting with 0x00
1072
+ * byteStringPatternBinaryRegex(/^\x00/)
1073
+ *
1074
+ * // Match ASCII "Hello"
1075
+ * byteStringPatternBinaryRegex(/Hello/)
1076
+ *
1077
+ * // Match any digits
1078
+ * byteStringPatternBinaryRegex(/^\d+$/)
1079
+ * ```
1080
+ */
1081
+ declare const byteStringPatternBinaryRegex: (pattern: RegExp) => ByteStringPattern;
1082
+ /**
1083
+ * Tests if a CBOR value matches this byte string pattern.
1084
+ */
1085
+ declare const byteStringPatternMatches: (pattern: ByteStringPattern, haystack: Cbor) => boolean;
1086
+ /**
1087
+ * Returns paths to matching byte string values.
1088
+ */
1089
+ declare const byteStringPatternPaths: (pattern: ByteStringPattern, haystack: Cbor) => Path[];
1090
+ /**
1091
+ * Formats a ByteStringPattern as a string.
1092
+ */
1093
+ declare const byteStringPatternDisplay: (pattern: ByteStringPattern) => string;
1094
+ //#endregion
1095
+ //#region src/pattern/value/date-pattern.d.ts
1096
+ /**
1097
+ * Pattern for matching date values in dCBOR.
1098
+ * Dates in CBOR are represented as tagged values with tag 1.
1099
+ */
1100
+ type DatePattern = {
1101
+ readonly variant: "Any";
1102
+ } | {
1103
+ readonly variant: "Value";
1104
+ readonly value: CborDate;
1105
+ } | {
1106
+ readonly variant: "Range";
1107
+ readonly min: CborDate;
1108
+ readonly max: CborDate;
1109
+ } | {
1110
+ readonly variant: "Earliest";
1111
+ readonly value: CborDate;
1112
+ } | {
1113
+ readonly variant: "Latest";
1114
+ readonly value: CborDate;
1115
+ } | {
1116
+ readonly variant: "StringValue";
1117
+ readonly value: string;
1118
+ } | {
1119
+ readonly variant: "Regex";
1120
+ readonly pattern: RegExp;
1121
+ };
1122
+ /**
1123
+ * Creates a DatePattern that matches any date.
1124
+ */
1125
+ declare const datePatternAny: () => DatePattern;
1126
+ /**
1127
+ * Creates a DatePattern that matches a specific date.
1128
+ */
1129
+ declare const datePatternValue: (value: CborDate) => DatePattern;
1130
+ /**
1131
+ * Creates a DatePattern that matches dates within a range (inclusive).
1132
+ */
1133
+ declare const datePatternRange: (min: CborDate, max: CborDate) => DatePattern;
1134
+ /**
1135
+ * Creates a DatePattern that matches dates on or after the specified date.
1136
+ */
1137
+ declare const datePatternEarliest: (value: CborDate) => DatePattern;
1138
+ /**
1139
+ * Creates a DatePattern that matches dates on or before the specified date.
1140
+ */
1141
+ declare const datePatternLatest: (value: CborDate) => DatePattern;
1142
+ /**
1143
+ * Creates a DatePattern that matches dates by their ISO-8601 string representation.
1144
+ */
1145
+ declare const datePatternStringValue: (value: string) => DatePattern;
1146
+ /**
1147
+ * Creates a DatePattern that matches dates by regex on their ISO-8601 string.
1148
+ */
1149
+ declare const datePatternRegex: (pattern: RegExp) => DatePattern;
1150
+ /**
1151
+ * Tests if a CBOR value matches this date pattern.
1152
+ */
1153
+ declare const datePatternMatches: (pattern: DatePattern, haystack: Cbor) => boolean;
1154
+ /**
1155
+ * Returns paths to matching date values.
1156
+ */
1157
+ declare const datePatternPaths: (pattern: DatePattern, haystack: Cbor) => Path[];
1158
+ /**
1159
+ * Formats a DatePattern as a string.
1160
+ */
1161
+ declare const datePatternDisplay: (pattern: DatePattern) => string;
1162
+ //#endregion
1163
+ //#region src/pattern/value/digest-pattern.d.ts
1164
+ /**
1165
+ * Pattern for matching digest values in dCBOR.
1166
+ * Digests are represented as tagged values with tag 40001.
1167
+ *
1168
+ * Note: The BinaryRegex variant uses a RegExp that matches against the
1169
+ * hex-encoded string representation of the digest bytes. This is a known
1170
+ * difference from the Rust implementation which uses regex::bytes::Regex.
1171
+ */
1172
+ type DigestPattern = {
1173
+ readonly variant: "Any";
1174
+ } | {
1175
+ readonly variant: "Value";
1176
+ readonly value: Digest;
1177
+ } | {
1178
+ readonly variant: "Prefix";
1179
+ readonly prefix: Uint8Array;
1180
+ } | {
1181
+ readonly variant: "BinaryRegex";
1182
+ readonly pattern: RegExp;
1183
+ };
1184
+ /**
1185
+ * Creates a DigestPattern that matches any digest.
1186
+ */
1187
+ declare const digestPatternAny: () => DigestPattern;
1188
+ /**
1189
+ * Creates a DigestPattern that matches a specific digest.
1190
+ */
1191
+ declare const digestPatternValue: (value: Digest) => DigestPattern;
1192
+ /**
1193
+ * Creates a DigestPattern that matches digests with a prefix.
1194
+ */
1195
+ declare const digestPatternPrefix: (prefix: Uint8Array) => DigestPattern;
1196
+ /**
1197
+ * Creates a DigestPattern that matches digests by binary regex.
1198
+ *
1199
+ * Note: In TypeScript, this matches against the hex-encoded representation
1200
+ * of the digest bytes.
1201
+ */
1202
+ declare const digestPatternBinaryRegex: (pattern: RegExp) => DigestPattern;
1203
+ /**
1204
+ * Tests if a CBOR value matches this digest pattern.
1205
+ */
1206
+ declare const digestPatternMatches: (pattern: DigestPattern, haystack: Cbor) => boolean;
1207
+ /**
1208
+ * Returns paths to matching digest values.
1209
+ */
1210
+ declare const digestPatternPaths: (pattern: DigestPattern, haystack: Cbor) => Path[];
1211
+ /**
1212
+ * Formats a DigestPattern as a string.
1213
+ */
1214
+ declare const digestPatternDisplay: (pattern: DigestPattern) => string;
1215
+ //#endregion
1216
+ //#region src/pattern/value/known-value-pattern.d.ts
1217
+ /**
1218
+ * Pattern for matching known values in dCBOR.
1219
+ * Known values are represented as tagged values with tag 40000.
1220
+ */
1221
+ type KnownValuePattern = {
1222
+ readonly variant: "Any";
1223
+ } | {
1224
+ readonly variant: "Value";
1225
+ readonly value: KnownValue;
1226
+ } | {
1227
+ readonly variant: "Named";
1228
+ readonly name: string;
1229
+ } | {
1230
+ readonly variant: "Regex";
1231
+ readonly pattern: RegExp;
1232
+ };
1233
+ /**
1234
+ * Creates a KnownValuePattern that matches any known value.
1235
+ */
1236
+ declare const knownValuePatternAny: () => KnownValuePattern;
1237
+ /**
1238
+ * Creates a KnownValuePattern that matches a specific known value.
1239
+ */
1240
+ declare const knownValuePatternValue: (value: KnownValue) => KnownValuePattern;
1241
+ /**
1242
+ * Creates a KnownValuePattern that matches a known value by name.
1243
+ */
1244
+ declare const knownValuePatternNamed: (name: string) => KnownValuePattern;
1245
+ /**
1246
+ * Creates a KnownValuePattern that matches known values by regex on name.
1247
+ */
1248
+ declare const knownValuePatternRegex: (pattern: RegExp) => KnownValuePattern;
1249
+ /**
1250
+ * Tests if a CBOR value matches this known value pattern.
1251
+ */
1252
+ declare const knownValuePatternMatches: (pattern: KnownValuePattern, haystack: Cbor) => boolean;
1253
+ /**
1254
+ * Returns paths to matching known values.
1255
+ */
1256
+ declare const knownValuePatternPaths: (pattern: KnownValuePattern, haystack: Cbor) => Path[];
1257
+ /**
1258
+ * Formats a KnownValuePattern as a string.
1259
+ */
1260
+ declare const knownValuePatternDisplay: (pattern: KnownValuePattern) => string;
1261
+ //#endregion
1262
+ //#region src/pattern/value/index.d.ts
1263
+ /**
1264
+ * Union of all value pattern types.
1265
+ */
1266
+ type ValuePattern = {
1267
+ readonly type: "Bool";
1268
+ readonly pattern: BoolPattern;
1269
+ } | {
1270
+ readonly type: "Null";
1271
+ readonly pattern: NullPattern;
1272
+ } | {
1273
+ readonly type: "Number";
1274
+ readonly pattern: NumberPattern;
1275
+ } | {
1276
+ readonly type: "Text";
1277
+ readonly pattern: TextPattern;
1278
+ } | {
1279
+ readonly type: "ByteString";
1280
+ readonly pattern: ByteStringPattern;
1281
+ } | {
1282
+ readonly type: "Date";
1283
+ readonly pattern: DatePattern;
1284
+ } | {
1285
+ readonly type: "Digest";
1286
+ readonly pattern: DigestPattern;
1287
+ } | {
1288
+ readonly type: "KnownValue";
1289
+ readonly pattern: KnownValuePattern;
1290
+ };
1291
+ /**
1292
+ * Returns paths to matching values for a ValuePattern.
1293
+ */
1294
+ declare const valuePatternPaths: (pattern: ValuePattern, haystack: Cbor) => Path[];
1295
+ /**
1296
+ * Tests if a CBOR value matches a ValuePattern.
1297
+ */
1298
+ declare const valuePatternMatches: (pattern: ValuePattern, haystack: Cbor) => boolean;
1299
+ /**
1300
+ * Formats a ValuePattern as a string.
1301
+ */
1302
+ declare const valuePatternDisplay: (pattern: ValuePattern) => string;
1303
+ /**
1304
+ * Creates a Bool ValuePattern.
1305
+ */
1306
+ declare const valueBool: (pattern: BoolPattern) => ValuePattern;
1307
+ /**
1308
+ * Creates a Null ValuePattern.
1309
+ */
1310
+ declare const valueNull: (pattern: NullPattern) => ValuePattern;
1311
+ /**
1312
+ * Creates a Number ValuePattern.
1313
+ */
1314
+ declare const valueNumber: (pattern: NumberPattern) => ValuePattern;
1315
+ /**
1316
+ * Creates a Text ValuePattern.
1317
+ */
1318
+ declare const valueText: (pattern: TextPattern) => ValuePattern;
1319
+ /**
1320
+ * Creates a ByteString ValuePattern.
1321
+ */
1322
+ declare const valueByteString: (pattern: ByteStringPattern) => ValuePattern;
1323
+ /**
1324
+ * Creates a Date ValuePattern.
1325
+ */
1326
+ declare const valueDate: (pattern: DatePattern) => ValuePattern;
1327
+ /**
1328
+ * Creates a Digest ValuePattern.
1329
+ */
1330
+ declare const valueDigest: (pattern: DigestPattern) => ValuePattern;
1331
+ /**
1332
+ * Creates a KnownValue ValuePattern.
1333
+ */
1334
+ declare const valueKnownValue: (pattern: KnownValuePattern) => ValuePattern;
1335
+ //#endregion
1336
+ //#region src/pattern/meta/repeat-pattern.d.ts
1337
+ /**
1338
+ * A pattern that matches with repetition.
1339
+ */
1340
+ interface RepeatPattern {
1341
+ readonly variant: "Repeat";
1342
+ readonly pattern: Pattern;
1343
+ readonly quantifier: Quantifier;
1344
+ }
1345
+ /**
1346
+ * Creates a RepeatPattern with the given pattern and quantifier.
1347
+ */
1348
+ declare const repeatPattern: (pattern: Pattern, quantifier: Quantifier) => RepeatPattern;
1349
+ /**
1350
+ * Creates a RepeatPattern that matches zero or more times (greedy).
1351
+ */
1352
+ declare const repeatZeroOrMore: (pattern: Pattern) => RepeatPattern;
1353
+ /**
1354
+ * Creates a RepeatPattern that matches one or more times (greedy).
1355
+ */
1356
+ declare const repeatOneOrMore: (pattern: Pattern) => RepeatPattern;
1357
+ /**
1358
+ * Creates a RepeatPattern that matches zero or one time (greedy).
1359
+ */
1360
+ declare const repeatOptional: (pattern: Pattern) => RepeatPattern;
1361
+ /**
1362
+ * Creates a RepeatPattern that matches exactly n times.
1363
+ */
1364
+ declare const repeatExact: (pattern: Pattern, n: number) => RepeatPattern;
1365
+ /**
1366
+ * Creates a RepeatPattern that matches between min and max times.
1367
+ */
1368
+ declare const repeatRange: (pattern: Pattern, min: number, max?: number) => RepeatPattern;
1369
+ /**
1370
+ * Tests if a CBOR value matches this repeat pattern.
1371
+ * Note: This is a simplified implementation. Complex matching
1372
+ * will be implemented with the VM.
1373
+ */
1374
+ declare const repeatPatternMatches: (pattern: RepeatPattern, haystack: Cbor) => boolean;
1375
+ /**
1376
+ * Returns paths to matching values.
1377
+ */
1378
+ declare const repeatPatternPaths: (pattern: RepeatPattern, haystack: Cbor) => Path[];
1379
+ /**
1380
+ * Formats a RepeatPattern as a string.
1381
+ * Always wraps the inner pattern in parentheses to match Rust behavior.
1382
+ */
1383
+ declare const repeatPatternDisplay: (pattern: RepeatPattern, patternDisplay: (p: Pattern) => string) => string;
1384
+ //#endregion
1385
+ //#region src/pattern/structure/array-pattern/helpers.d.ts
1386
+ /**
1387
+ * Check if a pattern is a repeat pattern.
1388
+ */
1389
+ declare const isRepeatPattern: (pattern: Pattern) => boolean;
1390
+ /**
1391
+ * Check if a pattern is a capture pattern containing a repeat pattern.
1392
+ * Returns the inner repeat pattern if found.
1393
+ */
1394
+ declare const extractCaptureWithRepeat: (pattern: Pattern) => RepeatPattern | undefined;
1395
+ /**
1396
+ * Extract any repeat pattern from a pattern, whether direct or within a capture.
1397
+ */
1398
+ declare const extractRepeatPattern: (pattern: Pattern) => RepeatPattern | undefined;
1399
+ /**
1400
+ * Check if a slice of patterns contains any repeat patterns (direct or in captures).
1401
+ */
1402
+ declare const hasRepeatPatternsInSlice: (patterns: Pattern[]) => boolean;
1403
+ /**
1404
+ * Calculate the bounds for repeat pattern matching based on quantifier and
1405
+ * available elements.
1406
+ */
1407
+ declare const calculateRepeatBounds: (quantifier: Quantifier, elementIdx: number, arrLen: number) => [number, number];
1408
+ /**
1409
+ * Check if a repeat pattern can match a specific number of elements starting
1410
+ * at elementIdx.
1411
+ */
1412
+ declare const canRepeatMatch: (repeatPattern: RepeatPattern, arr: Cbor[], elementIdx: number, repCount: number, matchFn: (pattern: Pattern, value: Cbor) => boolean) => boolean;
1413
+ /**
1414
+ * Build a simple array context path: [arrayCbor, element]
1415
+ */
1416
+ declare const buildSimpleArrayContextPath: (arrayCbor: Cbor, element: Cbor) => Cbor[];
1417
+ /**
1418
+ * Build an extended array context path: [arrayCbor, element] + capturedPath
1419
+ * (skip first element)
1420
+ */
1421
+ declare const buildExtendedArrayContextPath: (arrayCbor: Cbor, element: Cbor, capturedPath: Cbor[]) => Cbor[];
1422
+ /**
1423
+ * Transform nested captures to include array context, extending allCaptures.
1424
+ */
1425
+ declare const transformCapturesWithArrayContext: (arrayCbor: Cbor, element: Cbor, nestedCaptures: Map<string, Cbor[][]>, allCaptures: Map<string, Cbor[][]>) => void;
1426
+ //#endregion
1427
+ //#region src/pattern/structure/array-pattern/backtrack.d.ts
1428
+ /**
1429
+ * Generic backtracking state interface.
1430
+ * Abstracts the differences between boolean matching and assignment tracking.
1431
+ */
1432
+ interface BacktrackState<T> {
1433
+ /**
1434
+ * Try to advance the state with a new assignment and return true if successful.
1435
+ */
1436
+ tryAdvance(patternIdx: number, elementIdx: number): boolean;
1437
+ /**
1438
+ * Backtrack by removing the last state change.
1439
+ */
1440
+ backtrack(): void;
1441
+ /**
1442
+ * Check if we've reached a successful final state.
1443
+ */
1444
+ isSuccess(patternIdx: number, elementIdx: number, patternsLen: number, elementsLen: number): boolean;
1445
+ /**
1446
+ * Get the final result.
1447
+ */
1448
+ getResult(): T;
1449
+ }
1450
+ /**
1451
+ * Boolean backtracking state - just tracks success/failure.
1452
+ */
1453
+ declare class BooleanBacktrackState implements BacktrackState<boolean> {
1454
+ tryAdvance(_patternIdx: number, _elementIdx: number): boolean;
1455
+ backtrack(): void;
1456
+ isSuccess(patternIdx: number, elementIdx: number, patternsLen: number, elementsLen: number): boolean;
1457
+ getResult(): boolean;
1458
+ }
1459
+ /**
1460
+ * Assignment tracking backtracking state - collects pattern-element pairs.
1461
+ */
1462
+ declare class AssignmentBacktrackState implements BacktrackState<[number, number][]> {
1463
+ readonly assignments: [number, number][];
1464
+ tryAdvance(patternIdx: number, elementIdx: number): boolean;
1465
+ backtrack(): void;
1466
+ isSuccess(patternIdx: number, elementIdx: number, patternsLen: number, elementsLen: number): boolean;
1467
+ getResult(): [number, number][];
1468
+ len(): number;
1469
+ truncate(len: number): void;
1470
+ }
1471
+ /**
1472
+ * Generic backtracking algorithm that works with any BacktrackState.
1473
+ */
1474
+ declare class GenericBacktracker {
1475
+ #private;
1476
+ constructor(patterns: Pattern[], arr: Cbor[], matchFn: (pattern: Pattern, value: Cbor) => boolean);
1477
+ /**
1478
+ * Generic backtracking algorithm that works with any state type.
1479
+ */
1480
+ backtrack<T>(state: BacktrackState<T>, patternIdx: number, elementIdx: number): boolean;
1481
+ /**
1482
+ * Helper for repeat pattern backtracking with generic state.
1483
+ */
1484
+ private tryRepeatBacktrack;
1485
+ }
1486
+ //#endregion
1487
+ //#region src/pattern/structure/array-pattern/assigner.d.ts
1488
+ /**
1489
+ * Helper class for handling element-to-pattern assignment logic.
1490
+ * Encapsulates the complex logic for mapping array elements to sequence
1491
+ * patterns that was previously duplicated between matching and capture
1492
+ * collection.
1493
+ */
1494
+ declare class SequenceAssigner {
1495
+ #private;
1496
+ constructor(patterns: Pattern[], arr: Cbor[], matchFn: (pattern: Pattern, value: Cbor) => boolean);
1497
+ /**
1498
+ * Check if the sequence can match against the array elements (boolean result).
1499
+ */
1500
+ canMatch(): boolean;
1501
+ /**
1502
+ * Find the element-to-pattern assignments (returns assignment pairs).
1503
+ */
1504
+ findAssignments(): [number, number][] | undefined;
1505
+ }
1506
+ //#endregion
1507
+ //#region src/pattern/structure/array-pattern/index.d.ts
1508
+ /**
1509
+ * Pattern for matching CBOR array structures.
1510
+ */
1511
+ type ArrayPattern = {
1512
+ readonly variant: "Any";
1513
+ } | {
1514
+ readonly variant: "Elements";
1515
+ readonly pattern: Pattern;
1516
+ } | {
1517
+ readonly variant: "Length";
1518
+ readonly length: Interval;
1519
+ };
1520
+ /**
1521
+ * Creates an ArrayPattern that matches any array.
1522
+ */
1523
+ declare const arrayPatternAny: () => ArrayPattern;
1524
+ /**
1525
+ * Creates an ArrayPattern that matches arrays with elements matching the pattern.
1526
+ */
1527
+ declare const arrayPatternWithElements: (pattern: Pattern) => ArrayPattern;
1528
+ /**
1529
+ * Creates an ArrayPattern that matches arrays with a specific length.
1530
+ */
1531
+ declare const arrayPatternWithLength: (length: number) => ArrayPattern;
1532
+ /**
1533
+ * Creates an ArrayPattern that matches arrays with length in a range.
1534
+ */
1535
+ declare const arrayPatternWithLengthRange: (min: number, max?: number) => ArrayPattern;
1536
+ /**
1537
+ * Creates an ArrayPattern that matches arrays with length in an interval.
1538
+ */
1539
+ declare const arrayPatternWithLengthInterval: (interval: Interval) => ArrayPattern;
1540
+ /**
1541
+ * Tests if a CBOR value matches this array pattern.
1542
+ */
1543
+ declare const arrayPatternMatches: (pattern: ArrayPattern, haystack: Cbor) => boolean;
1544
+ /**
1545
+ * Returns paths to matching array values.
1546
+ */
1547
+ declare const arrayPatternPaths: (pattern: ArrayPattern, haystack: Cbor) => Path[];
1548
+ /**
1549
+ * Returns paths with captures for array patterns.
1550
+ */
1551
+ declare const arrayPatternPathsWithCaptures: (pattern: ArrayPattern, haystack: Cbor) => [Path[], Map<string, Path[]>];
1552
+ /**
1553
+ * Formats an ArrayPattern as a string.
1554
+ */
1555
+ declare const arrayPatternDisplay: (pattern: ArrayPattern, patternDisplay: (p: Pattern) => string) => string;
1556
+ /**
1557
+ * Compares two ArrayPatterns for equality.
1558
+ */
1559
+ declare const arrayPatternEquals: (a: ArrayPattern, b: ArrayPattern, patternEquals: (p1: Pattern, p2: Pattern) => boolean) => boolean;
1560
+ //#endregion
1561
+ //#region src/pattern/structure/map-pattern.d.ts
1562
+ /**
1563
+ * Pattern for matching CBOR map structures.
1564
+ */
1565
+ type MapPattern = {
1566
+ readonly variant: "Any";
1567
+ } | {
1568
+ readonly variant: "Constraints";
1569
+ readonly constraints: [Pattern, Pattern][];
1570
+ } | {
1571
+ readonly variant: "Length";
1572
+ readonly length: Interval;
1573
+ };
1574
+ /**
1575
+ * Creates a MapPattern that matches any map.
1576
+ */
1577
+ declare const mapPatternAny: () => MapPattern;
1578
+ /**
1579
+ * Creates a MapPattern that matches maps with key-value constraints.
1580
+ */
1581
+ declare const mapPatternWithConstraints: (constraints: [Pattern, Pattern][]) => MapPattern;
1582
+ /**
1583
+ * Creates a MapPattern that matches maps with a specific number of entries.
1584
+ */
1585
+ declare const mapPatternWithLength: (length: number) => MapPattern;
1586
+ /**
1587
+ * Creates a MapPattern that matches maps with length in a range.
1588
+ */
1589
+ declare const mapPatternWithLengthRange: (min: number, max?: number) => MapPattern;
1590
+ /**
1591
+ * Creates a MapPattern that matches maps with length in an interval.
1592
+ */
1593
+ declare const mapPatternWithLengthInterval: (interval: Interval) => MapPattern;
1594
+ /**
1595
+ * Tests if a CBOR value matches this map pattern.
1596
+ */
1597
+ declare const mapPatternMatches: (pattern: MapPattern, haystack: Cbor) => boolean;
1598
+ /**
1599
+ * Returns paths to matching map values.
1600
+ */
1601
+ declare const mapPatternPaths: (pattern: MapPattern, haystack: Cbor) => Path[];
1602
+ /**
1603
+ * Returns paths with captures for map patterns.
1604
+ */
1605
+ declare const mapPatternPathsWithCaptures: (pattern: MapPattern, haystack: Cbor) => [Path[], Map<string, Path[]>];
1606
+ /**
1607
+ * Formats a MapPattern as a string.
1608
+ */
1609
+ declare const mapPatternDisplay: (pattern: MapPattern, patternDisplay: (p: Pattern) => string) => string;
1610
+ /**
1611
+ * Compares two MapPatterns for equality.
1612
+ */
1613
+ declare const mapPatternEquals: (a: MapPattern, b: MapPattern, patternEquals: (p1: Pattern, p2: Pattern) => boolean) => boolean;
1614
+ //#endregion
1615
+ //#region src/pattern/structure/tagged-pattern.d.ts
1616
+ /**
1617
+ * Pattern for matching CBOR tagged value structures.
1618
+ */
1619
+ type TaggedPattern = {
1620
+ readonly variant: "Any";
1621
+ } | {
1622
+ readonly variant: "Tag";
1623
+ readonly tag: Tag;
1624
+ readonly pattern: Pattern;
1625
+ } | {
1626
+ readonly variant: "Name";
1627
+ readonly name: string;
1628
+ readonly pattern: Pattern;
1629
+ } | {
1630
+ readonly variant: "Regex";
1631
+ readonly regex: RegExp;
1632
+ readonly pattern: Pattern;
1633
+ };
1634
+ /**
1635
+ * Creates a TaggedPattern that matches any tagged value.
1636
+ */
1637
+ declare const taggedPatternAny: () => TaggedPattern;
1638
+ /**
1639
+ * Creates a TaggedPattern that matches tagged values with specific tag and content.
1640
+ */
1641
+ declare const taggedPatternWithTag: (tag: Tag, pattern: Pattern) => TaggedPattern;
1642
+ /**
1643
+ * Creates a TaggedPattern that matches tagged values with a tag having the given name.
1644
+ */
1645
+ declare const taggedPatternWithName: (name: string, pattern: Pattern) => TaggedPattern;
1646
+ /**
1647
+ * Creates a TaggedPattern that matches tagged values with a tag name matching the regex.
1648
+ */
1649
+ declare const taggedPatternWithRegex: (regex: RegExp, pattern: Pattern) => TaggedPattern;
1650
+ /**
1651
+ * Tests if a CBOR value matches this tagged pattern.
1652
+ */
1653
+ declare const taggedPatternMatches: (pattern: TaggedPattern, haystack: Cbor) => boolean;
1654
+ /**
1655
+ * Returns paths to matching tagged values.
1656
+ */
1657
+ declare const taggedPatternPaths: (pattern: TaggedPattern, haystack: Cbor) => Path[];
1658
+ /**
1659
+ * Returns paths with captures for a tagged pattern.
1660
+ * Collects captures from inner patterns for Tag variant.
1661
+ */
1662
+ declare const taggedPatternPathsWithCaptures: (pattern: TaggedPattern, haystack: Cbor) => [Path[], Map<string, Path[]>];
1663
+ /**
1664
+ * Formats a TaggedPattern as a string.
1665
+ */
1666
+ declare const taggedPatternDisplay: (pattern: TaggedPattern, patternDisplay: (p: Pattern) => string) => string;
1667
+ //#endregion
1668
+ //#region src/pattern/structure/index.d.ts
1669
+ /**
1670
+ * Union of all structure pattern types.
1671
+ */
1672
+ type StructurePattern = {
1673
+ readonly type: "Array";
1674
+ readonly pattern: ArrayPattern;
1675
+ } | {
1676
+ readonly type: "Map";
1677
+ readonly pattern: MapPattern;
1678
+ } | {
1679
+ readonly type: "Tagged";
1680
+ readonly pattern: TaggedPattern;
1681
+ };
1682
+ /**
1683
+ * Returns paths to matching structures for a StructurePattern.
1684
+ */
1685
+ declare const structurePatternPaths: (pattern: StructurePattern, haystack: Cbor) => Path[];
1686
+ /**
1687
+ * Tests if a CBOR value matches a StructurePattern.
1688
+ */
1689
+ declare const structurePatternMatches: (pattern: StructurePattern, haystack: Cbor) => boolean;
1690
+ /**
1691
+ * Returns paths with captures for a StructurePattern.
1692
+ * Used internally by the VM to avoid infinite recursion.
1693
+ */
1694
+ declare const structurePatternPathsWithCaptures: (pattern: StructurePattern, haystack: Cbor) => [Path[], Map<string, Path[]>];
1695
+ /**
1696
+ * Formats a StructurePattern as a string.
1697
+ */
1698
+ declare const structurePatternDisplay: (pattern: StructurePattern, patternDisplay: (p: Pattern) => string) => string;
1699
+ /**
1700
+ * Creates an Array StructurePattern.
1701
+ */
1702
+ declare const structureArray: (pattern: ArrayPattern) => StructurePattern;
1703
+ /**
1704
+ * Creates a Map StructurePattern.
1705
+ */
1706
+ declare const structureMap: (pattern: MapPattern) => StructurePattern;
1707
+ /**
1708
+ * Creates a Tagged StructurePattern.
1709
+ */
1710
+ declare const structureTagged: (pattern: TaggedPattern) => StructurePattern;
1711
+ //#endregion
1712
+ //#region src/pattern/meta/any-pattern.d.ts
1713
+ /**
1714
+ * A pattern that always matches any CBOR value.
1715
+ */
1716
+ interface AnyPattern {
1717
+ readonly variant: "Any";
1718
+ }
1719
+ /**
1720
+ * Creates an AnyPattern.
1721
+ */
1722
+ declare const anyPattern: () => AnyPattern;
1723
+ /**
1724
+ * Tests if a CBOR value matches this any pattern.
1725
+ * Always returns true.
1726
+ */
1727
+ declare const anyPatternMatches: (_pattern: AnyPattern, _haystack: Cbor) => boolean;
1728
+ /**
1729
+ * Returns paths to matching values.
1730
+ */
1731
+ declare const anyPatternPaths: (_pattern: AnyPattern, haystack: Cbor) => Path[];
1732
+ /**
1733
+ * Formats an AnyPattern as a string.
1734
+ */
1735
+ declare const anyPatternDisplay: (_pattern: AnyPattern) => string;
1736
+ //#endregion
1737
+ //#region src/pattern/meta/and-pattern.d.ts
1738
+ /**
1739
+ * A pattern that matches if all contained patterns match.
1740
+ */
1741
+ interface AndPattern {
1742
+ readonly variant: "And";
1743
+ readonly patterns: Pattern[];
1744
+ }
1745
+ /**
1746
+ * Creates an AndPattern with the given patterns.
1747
+ */
1748
+ declare const andPattern: (patterns: Pattern[]) => AndPattern;
1749
+ /**
1750
+ * Tests if a CBOR value matches this and pattern.
1751
+ * All patterns must match.
1752
+ */
1753
+ declare const andPatternMatches: (pattern: AndPattern, haystack: Cbor) => boolean;
1754
+ /**
1755
+ * Returns paths to matching values.
1756
+ */
1757
+ declare const andPatternPaths: (pattern: AndPattern, haystack: Cbor) => Path[];
1758
+ /**
1759
+ * Formats an AndPattern as a string.
1760
+ */
1761
+ declare const andPatternDisplay: (pattern: AndPattern, patternDisplay: (p: Pattern) => string) => string;
1762
+ //#endregion
1763
+ //#region src/pattern/meta/or-pattern.d.ts
1764
+ /**
1765
+ * A pattern that matches if any contained pattern matches.
1766
+ */
1767
+ interface OrPattern {
1768
+ readonly variant: "Or";
1769
+ readonly patterns: Pattern[];
1770
+ }
1771
+ /**
1772
+ * Creates an OrPattern with the given patterns.
1773
+ */
1774
+ declare const orPattern: (patterns: Pattern[]) => OrPattern;
1775
+ /**
1776
+ * Tests if a CBOR value matches this or pattern.
1777
+ * At least one pattern must match.
1778
+ */
1779
+ declare const orPatternMatches: (pattern: OrPattern, haystack: Cbor) => boolean;
1780
+ /**
1781
+ * Returns paths to matching values.
1782
+ */
1783
+ declare const orPatternPaths: (pattern: OrPattern, haystack: Cbor) => Path[];
1784
+ /**
1785
+ * Formats an OrPattern as a string.
1786
+ */
1787
+ declare const orPatternDisplay: (pattern: OrPattern, patternDisplay: (p: Pattern) => string) => string;
1788
+ //#endregion
1789
+ //#region src/pattern/meta/not-pattern.d.ts
1790
+ /**
1791
+ * A pattern that matches if the inner pattern does NOT match.
1792
+ */
1793
+ interface NotPattern {
1794
+ readonly variant: "Not";
1795
+ readonly pattern: Pattern;
1796
+ }
1797
+ /**
1798
+ * Creates a NotPattern with the given inner pattern.
1799
+ */
1800
+ declare const notPattern: (pattern: Pattern) => NotPattern;
1801
+ /**
1802
+ * Tests if a CBOR value matches this not pattern.
1803
+ * Returns true if the inner pattern does NOT match.
1804
+ */
1805
+ declare const notPatternMatches: (pattern: NotPattern, haystack: Cbor) => boolean;
1806
+ /**
1807
+ * Returns paths to matching values.
1808
+ */
1809
+ declare const notPatternPaths: (pattern: NotPattern, haystack: Cbor) => Path[];
1810
+ /**
1811
+ * Formats a NotPattern as a string.
1812
+ */
1813
+ declare const notPatternDisplay: (pattern: NotPattern, patternDisplay: (p: Pattern) => string) => string;
1814
+ //#endregion
1815
+ //#region src/pattern/meta/capture-pattern.d.ts
1816
+ /**
1817
+ * A pattern that captures matched values with a name.
1818
+ */
1819
+ interface CapturePattern {
1820
+ readonly variant: "Capture";
1821
+ readonly name: string;
1822
+ readonly pattern: Pattern;
1823
+ }
1824
+ /**
1825
+ * Creates a CapturePattern with the given name and inner pattern.
1826
+ */
1827
+ declare const capturePattern: (name: string, pattern: Pattern) => CapturePattern;
1828
+ /**
1829
+ * Tests if a CBOR value matches this capture pattern.
1830
+ * Capture itself doesn't affect matching - it delegates to inner pattern.
1831
+ */
1832
+ declare const capturePatternMatches: (pattern: CapturePattern, haystack: Cbor) => boolean;
1833
+ /**
1834
+ * Returns paths to matching values.
1835
+ */
1836
+ declare const capturePatternPaths: (pattern: CapturePattern, haystack: Cbor) => Path[];
1837
+ /**
1838
+ * Formats a CapturePattern as a string.
1839
+ */
1840
+ declare const capturePatternDisplay: (pattern: CapturePattern, patternDisplay: (p: Pattern) => string) => string;
1841
+ //#endregion
1842
+ //#region src/pattern/meta/search-pattern.d.ts
1843
+ /**
1844
+ * A pattern that searches the entire CBOR tree for matches.
1845
+ */
1846
+ interface SearchPattern {
1847
+ readonly variant: "Search";
1848
+ readonly pattern: Pattern;
1849
+ }
1850
+ /**
1851
+ * Creates a SearchPattern with the given inner pattern.
1852
+ */
1853
+ declare const searchPattern: (pattern: Pattern) => SearchPattern;
1854
+ /**
1855
+ * Tests if a CBOR value matches this search pattern.
1856
+ * Returns true if any node in the tree matches.
1857
+ */
1858
+ declare const searchPatternMatches: (pattern: SearchPattern, haystack: Cbor) => boolean;
1859
+ /**
1860
+ * Returns paths to all matching values in the tree.
1861
+ */
1862
+ declare const searchPatternPaths: (pattern: SearchPattern, haystack: Cbor) => Path[];
1863
+ /**
1864
+ * Result type for paths with captures from search operations.
1865
+ */
1866
+ interface SearchWithCaptures {
1867
+ readonly paths: Path[];
1868
+ readonly captures: Map<string, Path[]>;
1869
+ }
1870
+ /**
1871
+ * Returns paths with captures for all matching values in the tree.
1872
+ */
1873
+ declare const searchPatternPathsWithCaptures: (pattern: SearchPattern, haystack: Cbor) => SearchWithCaptures;
1874
+ /**
1875
+ * Formats a SearchPattern as a string.
1876
+ */
1877
+ declare const searchPatternDisplay: (pattern: SearchPattern, patternDisplay: (p: Pattern) => string) => string;
1878
+ //#endregion
1879
+ //#region src/pattern/meta/sequence-pattern.d.ts
1880
+ /**
1881
+ * A pattern that matches a sequence of patterns in order.
1882
+ * Used primarily for matching array elements.
1883
+ */
1884
+ interface SequencePattern {
1885
+ readonly variant: "Sequence";
1886
+ readonly patterns: Pattern[];
1887
+ }
1888
+ /**
1889
+ * Creates a SequencePattern with the given patterns.
1890
+ */
1891
+ declare const sequencePattern: (patterns: Pattern[]) => SequencePattern;
1892
+ /**
1893
+ * Tests if a CBOR value matches this sequence pattern.
1894
+ *
1895
+ * Note: Sequence patterns are used within array patterns for matching
1896
+ * consecutive elements. When used standalone (not within an array),
1897
+ * they return false/empty as the actual sequence matching logic is
1898
+ * handled by the VM and array pattern matching.
1899
+ */
1900
+ declare const sequencePatternMatches: (_pattern: SequencePattern, _haystack: Cbor) => boolean;
1901
+ /**
1902
+ * Returns paths to matching values.
1903
+ *
1904
+ * Note: Sequence patterns return empty paths when used directly.
1905
+ * The actual sequence matching is handled by the VM within array contexts.
1906
+ */
1907
+ declare const sequencePatternPaths: (_pattern: SequencePattern, _haystack: Cbor) => Path[];
1908
+ /**
1909
+ * Formats a SequencePattern as a string.
1910
+ */
1911
+ declare const sequencePatternDisplay: (pattern: SequencePattern, patternDisplay: (p: Pattern) => string) => string;
1912
+ /**
1913
+ * Gets the patterns in this sequence.
1914
+ */
1915
+ declare const sequencePatternPatterns: (pattern: SequencePattern) => Pattern[];
1916
+ //#endregion
1917
+ //#region src/pattern/meta/index.d.ts
1918
+ /**
1919
+ * Union of all meta pattern types.
1920
+ */
1921
+ type MetaPattern = {
1922
+ readonly type: "Any";
1923
+ readonly pattern: AnyPattern;
1924
+ } | {
1925
+ readonly type: "And";
1926
+ readonly pattern: AndPattern;
1927
+ } | {
1928
+ readonly type: "Or";
1929
+ readonly pattern: OrPattern;
1930
+ } | {
1931
+ readonly type: "Not";
1932
+ readonly pattern: NotPattern;
1933
+ } | {
1934
+ readonly type: "Repeat";
1935
+ readonly pattern: RepeatPattern;
1936
+ } | {
1937
+ readonly type: "Capture";
1938
+ readonly pattern: CapturePattern;
1939
+ } | {
1940
+ readonly type: "Search";
1941
+ readonly pattern: SearchPattern;
1942
+ } | {
1943
+ readonly type: "Sequence";
1944
+ readonly pattern: SequencePattern;
1945
+ };
1946
+ /**
1947
+ * Returns paths to matching values for a MetaPattern.
1948
+ */
1949
+ declare const metaPatternPaths: (pattern: MetaPattern, haystack: Cbor) => Path[];
1950
+ /**
1951
+ * Tests if a CBOR value matches a MetaPattern.
1952
+ */
1953
+ declare const metaPatternMatches: (pattern: MetaPattern, haystack: Cbor) => boolean;
1954
+ /**
1955
+ * Formats a MetaPattern as a string.
1956
+ */
1957
+ declare const metaPatternDisplay: (pattern: MetaPattern, patternDisplay: (p: Pattern) => string) => string;
1958
+ /**
1959
+ * Creates an Any MetaPattern.
1960
+ */
1961
+ declare const metaAny: (pattern: AnyPattern) => MetaPattern;
1962
+ /**
1963
+ * Creates an And MetaPattern.
1964
+ */
1965
+ declare const metaAnd: (pattern: AndPattern) => MetaPattern;
1966
+ /**
1967
+ * Creates an Or MetaPattern.
1968
+ */
1969
+ declare const metaOr: (pattern: OrPattern) => MetaPattern;
1970
+ /**
1971
+ * Creates a Not MetaPattern.
1972
+ */
1973
+ declare const metaNot: (pattern: NotPattern) => MetaPattern;
1974
+ /**
1975
+ * Creates a Repeat MetaPattern.
1976
+ */
1977
+ declare const metaRepeat: (pattern: RepeatPattern) => MetaPattern;
1978
+ /**
1979
+ * Creates a Capture MetaPattern.
1980
+ */
1981
+ declare const metaCapture: (pattern: CapturePattern) => MetaPattern;
1982
+ /**
1983
+ * Creates a Search MetaPattern.
1984
+ */
1985
+ declare const metaSearch: (pattern: SearchPattern) => MetaPattern;
1986
+ /**
1987
+ * Creates a Sequence MetaPattern.
1988
+ */
1989
+ declare const metaSequence: (pattern: SequencePattern) => MetaPattern;
1990
+ //#endregion
1991
+ //#region src/pattern/vm.d.ts
1992
+ /**
1993
+ * Navigation axis for traversing dCBOR tree structures.
1994
+ */
1995
+ type Axis = "ArrayElement" | "MapKey" | "MapValue" | "TaggedContent";
1996
+ /**
1997
+ * Return child CBOR values reachable from `cbor` via the given axis.
1998
+ */
1999
+ declare const axisChildren: (axis: Axis, cbor: Cbor) => Cbor[];
2000
+ /**
2001
+ * Bytecode instructions for the pattern VM.
2002
+ */
2003
+ type Instr = {
2004
+ type: "MatchPredicate";
2005
+ literalIndex: number;
2006
+ } | {
2007
+ type: "MatchStructure";
2008
+ literalIndex: number;
2009
+ } | {
2010
+ type: "Split";
2011
+ a: number;
2012
+ b: number;
2013
+ } | {
2014
+ type: "Jump";
2015
+ address: number;
2016
+ } | {
2017
+ type: "PushAxis";
2018
+ axis: Axis;
2019
+ } | {
2020
+ type: "Pop";
2021
+ } | {
2022
+ type: "Save";
2023
+ } | {
2024
+ type: "Accept";
2025
+ } | {
2026
+ type: "Search";
2027
+ patternIndex: number;
2028
+ captureMap: [string, number][];
2029
+ } | {
2030
+ type: "ExtendSequence";
2031
+ } | {
2032
+ type: "CombineSequence";
2033
+ } | {
2034
+ type: "NotMatch";
2035
+ patternIndex: number;
2036
+ } | {
2037
+ type: "Repeat";
2038
+ patternIndex: number;
2039
+ quantifier: Quantifier;
2040
+ } | {
2041
+ type: "CaptureStart";
2042
+ captureIndex: number;
2043
+ } | {
2044
+ type: "CaptureEnd";
2045
+ captureIndex: number;
2046
+ };
2047
+ /**
2048
+ * A compiled pattern program.
2049
+ */
2050
+ interface Program {
2051
+ code: Instr[];
2052
+ literals: Pattern[];
2053
+ captureNames: string[];
2054
+ }
2055
+ /**
2056
+ * Match atomic patterns without recursion into the VM.
2057
+ *
2058
+ * This function handles only the patterns that are safe to use in
2059
+ * MatchPredicate instructions.
2060
+ */
2061
+ declare const atomicPaths: (pattern: Pattern, cbor: Cbor) => Path[];
2062
+ /**
2063
+ * Execute a program against a dCBOR value, returning all matching paths and captures.
2064
+ */
2065
+ declare const run: (prog: Program, root: Cbor) => {
2066
+ paths: Path[];
2067
+ captures: Map<string, Path[]>;
2068
+ };
2069
+ /**
2070
+ * VM for executing pattern programs against dCBOR values.
2071
+ */
2072
+ declare class Vm {
2073
+ /**
2074
+ * Execute a program against a dCBOR value.
2075
+ */
2076
+ static run(prog: Program, root: Cbor): {
2077
+ paths: Path[];
2078
+ captures: Map<string, Path[]>;
2079
+ };
2080
+ }
2081
+ //#endregion
2082
+ //#region src/pattern/matcher.d.ts
2083
+ /**
2084
+ * Result of pattern matching with captures.
2085
+ */
2086
+ interface MatchWithCaptures {
2087
+ readonly paths: Path[];
2088
+ readonly captures: Map<string, Path[]>;
2089
+ }
2090
+ /**
2091
+ * Interface for objects that can match against CBOR values.
2092
+ *
2093
+ * This interface defines the contract for all pattern types in the system.
2094
+ * Implementations handle matching, path collection, and VM bytecode compilation.
2095
+ */
2096
+ interface Matcher {
2097
+ /**
2098
+ * Return all matching paths along with any named captures.
2099
+ *
2100
+ * @param haystack - The CBOR value to match against
2101
+ * @returns A tuple of paths and captures map
2102
+ */
2103
+ pathsWithCaptures(haystack: Cbor): MatchWithCaptures;
2104
+ /**
2105
+ * Return only the matching paths, discarding any captures.
2106
+ *
2107
+ * @param haystack - The CBOR value to match against
2108
+ * @returns Array of paths to matching elements
2109
+ */
2110
+ paths(haystack: Cbor): Path[];
2111
+ /**
2112
+ * Check if the pattern matches the given CBOR value.
2113
+ *
2114
+ * @param haystack - The CBOR value to test
2115
+ * @returns true if the pattern matches
2116
+ */
2117
+ matches(haystack: Cbor): boolean;
2118
+ /**
2119
+ * Compile this pattern into VM bytecode.
2120
+ *
2121
+ * @param code - The instruction array to append to
2122
+ * @param literals - The literals array to append to
2123
+ * @param captures - The capture names array
2124
+ */
2125
+ compile(code: Instr[], literals: Pattern[], captures: string[]): void;
2126
+ /**
2127
+ * Recursively collect all capture names from this pattern.
2128
+ *
2129
+ * @param names - The array to collect names into
2130
+ */
2131
+ collectCaptureNames(names: string[]): void;
2132
+ /**
2133
+ * Check if the pattern display is "complex" (requires parentheses).
2134
+ *
2135
+ * @returns true if the pattern requires grouping
2136
+ */
2137
+ isComplex(): boolean;
2138
+ /**
2139
+ * Format the pattern as a string.
2140
+ */
2141
+ toString(): string;
2142
+ }
2143
+ /**
2144
+ * Default implementation helpers for Matcher.
2145
+ */
2146
+ declare const MatcherDefaults: {
2147
+ /**
2148
+ * Default paths implementation using pathsWithCaptures.
2149
+ */
2150
+ paths(matcher: Pick<Matcher, "pathsWithCaptures">, haystack: Cbor): Path[];
2151
+ /**
2152
+ * Default matches implementation using paths.
2153
+ */
2154
+ matches(matcher: Pick<Matcher, "paths">, haystack: Cbor): boolean;
2155
+ /**
2156
+ * Default pathsWithCaptures throws not implemented.
2157
+ */
2158
+ pathsWithCaptures(_haystack: Cbor): MatchWithCaptures;
2159
+ /**
2160
+ * Default compile throws not implemented.
2161
+ */
2162
+ compile(_code: Instr[], _literals: Pattern[], _captures: string[]): void;
2163
+ /**
2164
+ * Default collectCaptureNames does nothing.
2165
+ */
2166
+ collectCaptureNames(_names: string[]): void;
2167
+ /**
2168
+ * Default isComplex returns false.
2169
+ */
2170
+ isComplex(): boolean;
2171
+ };
2172
+ /**
2173
+ * Compiles a pattern into a VM program.
2174
+ *
2175
+ * @param pattern - The pattern to compile
2176
+ * @returns A compiled program ready for execution
2177
+ */
2178
+ declare const compilePattern: (pattern: Pattern) => Program;
2179
+ //#endregion
2180
+ //#region src/pattern/match-registry.d.ts
2181
+ type Pattern$1 = any;
2182
+ /**
2183
+ * Match result with paths and captures.
2184
+ */
2185
+ interface MatchResultInternal {
2186
+ readonly paths: Path[];
2187
+ readonly captures: Map<string, Path[]>;
2188
+ }
2189
+ /**
2190
+ * Registry for the pattern matching function.
2191
+ * This gets set by pattern/index.ts after all modules are loaded.
2192
+ */
2193
+ declare let matchFn: ((pattern: Pattern$1, haystack: Cbor) => boolean) | undefined;
2194
+ /**
2195
+ * Registry for the pattern paths function.
2196
+ * This gets set by pattern/index.ts after all modules are loaded.
2197
+ */
2198
+ declare let pathsFn: ((pattern: Pattern$1, haystack: Cbor) => Path[]) | undefined;
2199
+ /**
2200
+ * Registry for the pattern paths with captures function (VM-based).
2201
+ * This gets set by pattern/index.ts after all modules are loaded.
2202
+ */
2203
+ declare let pathsWithCapturesFn: ((pattern: Pattern$1, haystack: Cbor) => MatchResultInternal) | undefined;
2204
+ /**
2205
+ * Registry for the direct pattern paths with captures function (non-VM).
2206
+ * This is used by the VM to avoid infinite recursion.
2207
+ */
2208
+ declare let pathsWithCapturesDirectFn: ((pattern: Pattern$1, haystack: Cbor) => MatchResultInternal) | undefined;
2209
+ /**
2210
+ * Sets the pattern matching function.
2211
+ * Called by pattern/index.ts during module initialization.
2212
+ */
2213
+ declare const setMatchFn: (fn: (pattern: Pattern$1, haystack: Cbor) => boolean) => void;
2214
+ /**
2215
+ * Sets the pattern paths function.
2216
+ * Called by pattern/index.ts during module initialization.
2217
+ */
2218
+ declare const setPathsFn: (fn: (pattern: Pattern$1, haystack: Cbor) => Path[]) => void;
2219
+ /**
2220
+ * Sets the pattern paths with captures function.
2221
+ * Called by pattern/index.ts during module initialization.
2222
+ */
2223
+ declare const setPathsWithCapturesFn: (fn: (pattern: Pattern$1, haystack: Cbor) => MatchResultInternal) => void;
2224
+ /**
2225
+ * Sets the direct pattern paths with captures function (non-VM).
2226
+ * Called by pattern/index.ts during module initialization.
2227
+ */
2228
+ declare const setPathsWithCapturesDirectFn: (fn: (pattern: Pattern$1, haystack: Cbor) => MatchResultInternal) => void;
2229
+ /**
2230
+ * Matches a pattern against a CBOR value using the registered function.
2231
+ * @throws Error if the match function hasn't been registered yet.
2232
+ */
2233
+ declare const matchPattern: (pattern: Pattern$1, haystack: Cbor) => boolean;
2234
+ /**
2235
+ * Gets paths for a pattern against a CBOR value using the registered function.
2236
+ * @throws Error if the paths function hasn't been registered yet.
2237
+ */
2238
+ declare const getPatternPaths: (pattern: Pattern$1, haystack: Cbor) => Path[];
2239
+ /**
2240
+ * Gets paths with captures for a pattern against a CBOR value (VM-based).
2241
+ * @throws Error if the function hasn't been registered yet.
2242
+ */
2243
+ declare const getPatternPathsWithCaptures: (pattern: Pattern$1, haystack: Cbor) => MatchResultInternal;
2244
+ /**
2245
+ * Gets paths with captures directly without the VM (non-recursive).
2246
+ * This is used by the VM to avoid infinite recursion.
2247
+ * @throws Error if the function hasn't been registered yet.
2248
+ */
2249
+ declare const getPatternPathsWithCapturesDirect: (pattern: Pattern$1, haystack: Cbor) => MatchResultInternal;
2250
+ //#endregion
2251
+ //#region src/pattern/index.d.ts
2252
+ /**
2253
+ * The main Pattern type - a discriminated union of all pattern variants.
2254
+ */
2255
+ type Pattern = {
2256
+ readonly kind: "Value";
2257
+ readonly pattern: ValuePattern;
2258
+ } | {
2259
+ readonly kind: "Structure";
2260
+ readonly pattern: StructurePattern;
2261
+ } | {
2262
+ readonly kind: "Meta";
2263
+ readonly pattern: MetaPattern;
2264
+ };
2265
+ /**
2266
+ * Result of pattern matching with captures.
2267
+ */
2268
+ interface MatchResult {
2269
+ readonly paths: Path[];
2270
+ readonly captures: Map<string, Path[]>;
2271
+ }
2272
+ /**
2273
+ * Returns paths to matching elements in a CBOR value.
2274
+ *
2275
+ * @param pattern - The pattern to match
2276
+ * @param haystack - The CBOR value to search
2277
+ * @returns Array of paths to matching elements
2278
+ */
2279
+ declare const patternPaths: (pattern: Pattern, haystack: Cbor) => Path[];
2280
+ /**
2281
+ * Tests if a pattern matches a CBOR value.
2282
+ *
2283
+ * @param pattern - The pattern to match
2284
+ * @param haystack - The CBOR value to test
2285
+ * @returns true if the pattern matches
2286
+ */
2287
+ declare const patternMatches: (pattern: Pattern, haystack: Cbor) => boolean;
2288
+ /**
2289
+ * Formats a pattern as a string.
2290
+ *
2291
+ * @param pattern - The pattern to format
2292
+ * @returns String representation of the pattern
2293
+ */
2294
+ declare const patternDisplay: (pattern: Pattern) => string;
2295
+ /**
2296
+ * Matches a pattern against a CBOR value and returns all matching paths.
2297
+ *
2298
+ * @param pattern - The pattern to match
2299
+ * @param haystack - The CBOR value to search
2300
+ * @returns Array of paths to matching elements
2301
+ */
2302
+ declare const paths: (pattern: Pattern, haystack: Cbor) => Path[];
2303
+ /**
2304
+ * Checks if a pattern matches a CBOR value.
2305
+ *
2306
+ * @param pattern - The pattern to match
2307
+ * @param haystack - The CBOR value to test
2308
+ * @returns true if the pattern matches
2309
+ */
2310
+ declare const matches: (pattern: Pattern, haystack: Cbor) => boolean;
2311
+ /**
2312
+ * Computes paths with captures directly without using the VM.
2313
+ * This is used internally by the VM to avoid infinite recursion.
2314
+ *
2315
+ * Note: This function delegates capture collection to the pattern's
2316
+ * own matching mechanism. The VM has its own capture tracking, so
2317
+ * this just returns paths with any captures found during matching.
2318
+ *
2319
+ * @param pattern - The pattern to match
2320
+ * @param haystack - The CBOR value to search
2321
+ * @returns Match result with paths and captures
2322
+ */
2323
+ declare const pathsWithCapturesDirect: (pattern: Pattern, haystack: Cbor) => MatchResult;
2324
+ /**
2325
+ * Matches a pattern against a CBOR value and returns paths with captures.
2326
+ *
2327
+ * @param pattern - The pattern to match
2328
+ * @param haystack - The CBOR value to search
2329
+ * @returns Match result with paths and captures
2330
+ */
2331
+ declare const pathsWithCaptures: (pattern: Pattern, haystack: Cbor) => MatchResult;
2332
+ /**
2333
+ * Alias for pathsWithCaptures for internal VM use.
2334
+ */
2335
+ declare const patternPathsWithCaptures: (pattern: Pattern, haystack: Cbor) => MatchResult;
2336
+ /**
2337
+ * Creates a pattern that matches any value.
2338
+ */
2339
+ declare const any: () => Pattern;
2340
+ /**
2341
+ * Creates a pattern that matches any boolean.
2342
+ */
2343
+ declare const anyBool: () => Pattern;
2344
+ /**
2345
+ * Creates a pattern that matches a specific boolean value.
2346
+ */
2347
+ declare const bool: (value: boolean) => Pattern;
2348
+ /**
2349
+ * Creates a pattern that matches null.
2350
+ */
2351
+ declare const nullPattern: () => Pattern;
2352
+ /**
2353
+ * Creates a pattern that matches any number.
2354
+ */
2355
+ declare const anyNumber: () => Pattern;
2356
+ /**
2357
+ * Creates a pattern that matches a specific number.
2358
+ */
2359
+ declare const number: (value: number) => Pattern;
2360
+ /**
2361
+ * Creates a pattern that matches numbers in a range.
2362
+ */
2363
+ declare const numberRange: (min: number, max: number) => Pattern;
2364
+ /**
2365
+ * Creates a pattern that matches any text.
2366
+ */
2367
+ declare const anyText: () => Pattern;
2368
+ /**
2369
+ * Creates a pattern that matches specific text.
2370
+ */
2371
+ declare const text: (value: string) => Pattern;
2372
+ /**
2373
+ * Creates a pattern that matches text using a regex.
2374
+ */
2375
+ declare const textRegex: (pattern: RegExp) => Pattern;
2376
+ /**
2377
+ * Creates a pattern that matches any byte string.
2378
+ */
2379
+ declare const anyByteString: () => Pattern;
2380
+ /**
2381
+ * Creates a pattern that matches a specific byte string.
2382
+ */
2383
+ declare const byteString: (value: Uint8Array) => Pattern;
2384
+ /**
2385
+ * Creates a pattern that matches byte strings using a binary regex.
2386
+ *
2387
+ * The regex matches against raw bytes converted to a Latin-1 string.
2388
+ * Use escape sequences like `\x00` to match specific byte values.
2389
+ *
2390
+ * @example
2391
+ * ```typescript
2392
+ * // Match bytes starting with 0x00
2393
+ * byteStringRegex(/^\x00/)
2394
+ *
2395
+ * // Match ASCII "Hello"
2396
+ * byteStringRegex(/Hello/)
2397
+ * ```
2398
+ */
2399
+ declare const byteStringRegex: (pattern: RegExp) => Pattern;
2400
+ /**
2401
+ * Creates a pattern that matches any array.
2402
+ */
2403
+ declare const anyArray: () => Pattern;
2404
+ /**
2405
+ * Creates a pattern that matches any map.
2406
+ */
2407
+ declare const anyMap: () => Pattern;
2408
+ /**
2409
+ * Creates a pattern that matches any tagged value.
2410
+ */
2411
+ declare const anyTagged: () => Pattern;
2412
+ /**
2413
+ * Creates an AND pattern that matches if all patterns match.
2414
+ */
2415
+ declare const and: (...patterns: Pattern[]) => Pattern;
2416
+ /**
2417
+ * Creates an OR pattern that matches if any pattern matches.
2418
+ */
2419
+ declare const or: (...patterns: Pattern[]) => Pattern;
2420
+ /**
2421
+ * Creates a NOT pattern that matches if the pattern does not match.
2422
+ */
2423
+ declare const not: (pattern: Pattern) => Pattern;
2424
+ /**
2425
+ * Creates a capture pattern with a name.
2426
+ */
2427
+ declare const capture: (name: string, pattern: Pattern) => Pattern;
2428
+ /**
2429
+ * Creates a search pattern for recursive matching.
2430
+ */
2431
+ declare const search: (pattern: Pattern) => Pattern;
2432
+ /**
2433
+ * Creates a sequence pattern for ordered matching.
2434
+ */
2435
+ declare const sequence: (...patterns: Pattern[]) => Pattern;
2436
+ /**
2437
+ * Creates a pattern that matches numbers greater than a value.
2438
+ */
2439
+ declare const numberGreaterThan: (value: number) => Pattern;
2440
+ /**
2441
+ * Creates a pattern that matches numbers greater than or equal to a value.
2442
+ */
2443
+ declare const numberGreaterThanOrEqual: (value: number) => Pattern;
2444
+ /**
2445
+ * Creates a pattern that matches numbers less than a value.
2446
+ */
2447
+ declare const numberLessThan: (value: number) => Pattern;
2448
+ /**
2449
+ * Creates a pattern that matches numbers less than or equal to a value.
2450
+ */
2451
+ declare const numberLessThanOrEqual: (value: number) => Pattern;
2452
+ /**
2453
+ * Creates a pattern that matches NaN.
2454
+ */
2455
+ declare const numberNaN: () => Pattern;
2456
+ /**
2457
+ * Creates a pattern that matches positive infinity.
2458
+ */
2459
+ declare const numberInfinity: () => Pattern;
2460
+ /**
2461
+ * Creates a pattern that matches negative infinity.
2462
+ */
2463
+ declare const numberNegInfinity: () => Pattern;
2464
+ /**
2465
+ * Creates a pattern that matches any date.
2466
+ */
2467
+ declare const anyDate: () => Pattern;
2468
+ /**
2469
+ * Creates a pattern that matches a specific date.
2470
+ */
2471
+ declare const date: (value: CborDate) => Pattern;
2472
+ /**
2473
+ * Creates a pattern that matches dates within a range (inclusive).
2474
+ */
2475
+ declare const dateRange: (min: CborDate, max: CborDate) => Pattern;
2476
+ /**
2477
+ * Creates a pattern that matches dates on or after the specified date.
2478
+ */
2479
+ declare const dateEarliest: (value: CborDate) => Pattern;
2480
+ /**
2481
+ * Creates a pattern that matches dates on or before the specified date.
2482
+ */
2483
+ declare const dateLatest: (value: CborDate) => Pattern;
2484
+ /**
2485
+ * Creates a pattern that matches dates by their ISO-8601 string representation.
2486
+ */
2487
+ declare const dateIso8601: (value: string) => Pattern;
2488
+ /**
2489
+ * Creates a pattern that matches dates by regex on their ISO-8601 string.
2490
+ */
2491
+ declare const dateRegex: (pattern: RegExp) => Pattern;
2492
+ /**
2493
+ * Creates a pattern that matches any digest.
2494
+ */
2495
+ declare const anyDigest: () => Pattern;
2496
+ /**
2497
+ * Creates a pattern that matches a specific digest.
2498
+ */
2499
+ declare const digest: (value: Digest) => Pattern;
2500
+ /**
2501
+ * Creates a pattern that matches digests with a prefix.
2502
+ */
2503
+ declare const digestPrefix: (prefix: Uint8Array) => Pattern;
2504
+ /**
2505
+ * Creates a pattern that matches digests by binary regex.
2506
+ */
2507
+ declare const digestBinaryRegex: (pattern: RegExp) => Pattern;
2508
+ /**
2509
+ * Creates a pattern that matches any known value.
2510
+ */
2511
+ declare const anyKnownValue: () => Pattern;
2512
+ /**
2513
+ * Creates a pattern that matches a specific known value.
2514
+ */
2515
+ declare const knownValue: (value: KnownValue) => Pattern;
2516
+ /**
2517
+ * Creates a pattern that matches a known value by name.
2518
+ */
2519
+ declare const knownValueNamed: (name: string) => Pattern;
2520
+ /**
2521
+ * Creates a pattern that matches known values by regex on their name.
2522
+ */
2523
+ declare const knownValueRegex: (pattern: RegExp) => Pattern;
2524
+ /**
2525
+ * Creates a pattern that matches tagged values with a specific tag.
2526
+ */
2527
+ declare const tagged: (tag: Tag, pattern: Pattern) => Pattern;
2528
+ /**
2529
+ * Creates a pattern that matches tagged values by tag name.
2530
+ */
2531
+ declare const taggedName: (name: string, pattern: Pattern) => Pattern;
2532
+ /**
2533
+ * Creates a pattern that matches tagged values by tag name regex.
2534
+ */
2535
+ declare const taggedRegex: (regex: RegExp, pattern: Pattern) => Pattern;
2536
+ /**
2537
+ * Creates a repeat pattern with the given pattern and quantifier.
2538
+ */
2539
+ declare const repeat: (pattern: Pattern, quantifier: Quantifier) => Pattern;
2540
+ /**
2541
+ * Creates a grouped pattern (equivalent to repeat with exactly 1).
2542
+ * This is useful for precedence grouping in pattern expressions.
2543
+ */
2544
+ declare const group: (pattern: Pattern) => Pattern;
2545
+ //#endregion
2546
+ //#region src/parse/value/bool-parser.d.ts
2547
+ /**
2548
+ * Parse a boolean pattern from the `bool` keyword.
2549
+ */
2550
+ declare const parseBool: (_lexer: Lexer) => Result<Pattern>;
2551
+ /**
2552
+ * Parse a `true` literal.
2553
+ */
2554
+ declare const parseBoolTrue: (_lexer: Lexer) => Result<Pattern>;
2555
+ /**
2556
+ * Parse a `false` literal.
2557
+ */
2558
+ declare const parseBoolFalse: (_lexer: Lexer) => Result<Pattern>;
2559
+ //#endregion
2560
+ //#region src/parse/value/null-parser.d.ts
2561
+ /**
2562
+ * Parse a null pattern from the `null` keyword.
2563
+ */
2564
+ declare const parseNull: (_lexer: Lexer) => Result<Pattern>;
2565
+ //#endregion
2566
+ //#region src/parse/value/number-parser.d.ts
2567
+ /**
2568
+ * Parse a number pattern from the `number` keyword.
2569
+ */
2570
+ declare const parseNumber: (_lexer: Lexer) => Result<Pattern>;
2571
+ //#endregion
2572
+ //#region src/parse/value/text-parser.d.ts
2573
+ /**
2574
+ * Parse a text pattern from the `text` keyword.
2575
+ */
2576
+ declare const parseText: (lexer: Lexer) => Result<Pattern>;
2577
+ //#endregion
2578
+ //#region src/parse/value/bytestring-parser.d.ts
2579
+ /**
2580
+ * Parse a bytestring pattern from the `bytes` keyword.
2581
+ */
2582
+ declare const parseByteString: (_lexer: Lexer) => Result<Pattern>;
2583
+ /**
2584
+ * Parse a hex string token result into a pattern.
2585
+ */
2586
+ declare const parseHexStringToken: (hexResult: Result<Uint8Array>) => Result<Pattern>;
2587
+ /**
2588
+ * Parse a hex regex token result into a pattern.
2589
+ *
2590
+ * In TypeScript, binary regex matching is implemented by converting bytes to Latin-1 strings.
2591
+ * This mimics Rust's regex::bytes::Regex behavior where each byte 0-255 maps to a character.
2592
+ */
2593
+ declare const parseHexRegexToken: (regexResult: Result<RegExp>) => Result<Pattern>;
2594
+ //#endregion
2595
+ //#region src/parse/value/date-parser.d.ts
2596
+ /**
2597
+ * Parse a date pattern from the `date` keyword.
2598
+ */
2599
+ declare const parseDate: (_lexer: Lexer) => Result<Pattern>;
2600
+ //#endregion
2601
+ //#region src/parse/value/digest-parser.d.ts
2602
+ /**
2603
+ * Parse a digest pattern from the `digest` keyword.
2604
+ */
2605
+ declare const parseDigest: (_lexer: Lexer) => Result<Pattern>;
2606
+ //#endregion
2607
+ //#region src/parse/value/known-value-parser.d.ts
2608
+ /**
2609
+ * Parse a known value pattern from the `known` keyword.
2610
+ */
2611
+ declare const parseKnownValue: (_lexer: Lexer) => Result<Pattern>;
2612
+ //#endregion
2613
+ //#region src/parse/structure/array-parser.d.ts
2614
+ /**
2615
+ * Parse a bracket array pattern: [pattern] or [{n}] etc.
2616
+ */
2617
+ declare const parseBracketArray: (lexer: Lexer) => Result<Pattern>;
2618
+ //#endregion
2619
+ //#region src/parse/structure/map-parser.d.ts
2620
+ /**
2621
+ * Parse a bracket map pattern: {pattern: pattern} or {{n}} etc.
2622
+ */
2623
+ declare const parseBracketMap: (lexer: Lexer) => Result<Pattern>;
2624
+ //#endregion
2625
+ //#region src/parse/structure/tagged-parser.d.ts
2626
+ /**
2627
+ * Parse a tagged pattern from the `tagged` keyword.
2628
+ *
2629
+ * Supports:
2630
+ * - `tagged` - matches any tagged value
2631
+ * - `tagged(value, pattern)` - matches tagged value with specific tag number
2632
+ * - `tagged(name, pattern)` - matches tagged value with named tag
2633
+ * - `tagged(/regex/, pattern)` - matches tagged value with tag name matching regex
2634
+ */
2635
+ declare const parseTagged: (lexer: Lexer) => Result<Pattern>;
2636
+ //#endregion
2637
+ //#region src/parse/meta/or-parser.d.ts
2638
+ /**
2639
+ * Parse an OR pattern - the top-level pattern parser.
2640
+ */
2641
+ declare const parseOr: (lexer: Lexer) => Result<Pattern>;
2642
+ //#endregion
2643
+ //#region src/parse/meta/and-parser.d.ts
2644
+ /**
2645
+ * Parse an AND pattern.
2646
+ */
2647
+ declare const parseAnd: (lexer: Lexer) => Result<Pattern>;
2648
+ //#endregion
2649
+ //#region src/parse/meta/not-parser.d.ts
2650
+ /**
2651
+ * Parse a NOT pattern or delegate to primary parser.
2652
+ */
2653
+ declare const parseNot: (lexer: Lexer) => Result<Pattern>;
2654
+ //#endregion
2655
+ //#region src/parse/meta/repeat-parser.d.ts
2656
+ /**
2657
+ * Parse quantifier tokens that follow a grouped pattern.
2658
+ */
2659
+ declare const parseQuantifier: (pattern: Pattern, lexer: Lexer, forceRepeat: boolean) => Result<Pattern>;
2660
+ //#endregion
2661
+ //#region src/parse/meta/primary-parser.d.ts
2662
+ /**
2663
+ * Parse a primary pattern - the most basic unit of pattern matching.
2664
+ */
2665
+ declare const parsePrimary: (lexer: Lexer) => Result<Pattern>;
2666
+ //#endregion
2667
+ //#region src/parse/meta/capture-parser.d.ts
2668
+ /**
2669
+ * Parse a capture pattern of the form `@name(pattern)`.
2670
+ */
2671
+ declare const parseCapture: (lexer: Lexer, name: string) => Result<Pattern>;
2672
+ //#endregion
2673
+ //#region src/parse/meta/search-parser.d.ts
2674
+ /**
2675
+ * Parse a search pattern `...(pattern)`.
2676
+ */
2677
+ declare const parseSearch: (lexer: Lexer) => Result<Pattern>;
2678
+ //#endregion
2679
+ //#region src/parse/parse-registry.d.ts
2680
+ /**
2681
+ * The registered parseOr function.
2682
+ */
2683
+ declare let parseOrFn: ((lexer: Lexer) => Result<Pattern>) | undefined;
2684
+ /**
2685
+ * Registers the parseOr function.
2686
+ */
2687
+ declare const setParseOrFn: (fn: (lexer: Lexer) => Result<Pattern>) => void;
2688
+ /**
2689
+ * Calls the registered parseOr function.
2690
+ */
2691
+ declare const parseOrFromRegistry: (lexer: Lexer) => Result<Pattern>;
2692
+ //#endregion
2693
+ //#region src/parse/index.d.ts
2694
+ /**
2695
+ * Parses a complete dCBOR pattern expression.
2696
+ *
2697
+ * @param input - The pattern string to parse
2698
+ * @returns A Result containing the parsed Pattern or an error
2699
+ *
2700
+ * @example
2701
+ * ```typescript
2702
+ * const result = parse("number");
2703
+ * if (result.ok) {
2704
+ * console.log(result.value);
2705
+ * }
2706
+ * ```
2707
+ */
2708
+ declare const parse: (input: string) => Result<Pattern>;
2709
+ /**
2710
+ * Parses a partial dCBOR pattern expression, returning the parsed pattern
2711
+ * and the number of characters consumed.
2712
+ *
2713
+ * Unlike `parse()`, this function succeeds even if additional characters
2714
+ * follow the first pattern. The returned index points to the first unparsed
2715
+ * character after the pattern.
2716
+ *
2717
+ * @param input - The pattern string to parse
2718
+ * @returns A Result containing a tuple of [Pattern, consumedLength] or an error
2719
+ *
2720
+ * @example
2721
+ * ```typescript
2722
+ * const result = parsePartial("true rest");
2723
+ * if (result.ok) {
2724
+ * const [pattern, consumed] = result.value;
2725
+ * console.log(consumed); // 4 or 5 (includes whitespace)
2726
+ * }
2727
+ * ```
2728
+ */
2729
+ declare const parsePartial: (input: string) => Result<[Pattern, number]>;
2730
+ //#endregion
2731
+ export { AndPattern, AnyPattern, ArrayPattern, AssignmentBacktrackState, Axis, BacktrackState, BoolPattern, BooleanBacktrackState, ByteStringPattern, CapturePattern, DEFAULT_FORMAT_OPTS, DEFAULT_INTERVAL, DEFAULT_QUANTIFIER, DEFAULT_RELUCTANCE, DatePattern, DigestPattern, Err, Error, FormatPathsOpts, FormatPathsOptsBuilder, GenericBacktracker, Instr, Interval, KnownValuePattern, Lexer, MapPattern, MatchResult, MatchResultInternal, MatchWithCaptures, Matcher, MatcherDefaults, MetaPattern, NotPattern, NullPattern, NumberPattern, Ok, OrPattern, Path, PathElementFormat, Pattern, PatternError, Program, Quantifier, Reluctance, RepeatPattern, Result, SearchPattern, SearchWithCaptures, SequenceAssigner, SequencePattern, type Span, SpannedToken, StructurePattern, TaggedPattern, TextPattern, Token, ValuePattern, Vm, adjustSpan, and, andPattern, andPatternDisplay, andPatternMatches, andPatternPaths, any, anyArray, anyBool, anyByteString, anyDate, anyDigest, anyKnownValue, anyMap, anyNumber, anyPattern, anyPatternDisplay, anyPatternMatches, anyPatternPaths, anyTagged, anyText, arrayPatternAny, arrayPatternDisplay, arrayPatternEquals, arrayPatternMatches, arrayPatternPaths, arrayPatternPathsWithCaptures, arrayPatternWithElements, arrayPatternWithLength, arrayPatternWithLengthInterval, arrayPatternWithLengthRange, atomicPaths, axisChildren, bool, boolPatternAny, boolPatternDisplay, boolPatternMatches, boolPatternPaths, boolPatternValue, buildExtendedArrayContextPath, buildSimpleArrayContextPath, byteString, byteStringPatternAny, byteStringPatternBinaryRegex, byteStringPatternDisplay, byteStringPatternMatches, byteStringPatternPaths, byteStringPatternValue, byteStringRegex, calculateRepeatBounds, canRepeatMatch, capture, capturePattern, capturePatternDisplay, capturePatternMatches, capturePatternPaths, compilePattern, date, dateEarliest, dateIso8601, dateLatest, datePatternAny, datePatternDisplay, datePatternEarliest, datePatternLatest, datePatternMatches, datePatternPaths, datePatternRange, datePatternRegex, datePatternStringValue, datePatternValue, dateRange, dateRegex, digest, digestBinaryRegex, digestPatternAny, digestPatternBinaryRegex, digestPatternDisplay, digestPatternMatches, digestPatternPaths, digestPatternPrefix, digestPatternValue, digestPrefix, errorToString, extractCaptureWithRepeat, extractRepeatPattern, formatPath, formatPathOpt, formatPaths, formatPathsOpt, formatPathsWithCaptures, getPatternPaths, getPatternPathsWithCaptures, getPatternPathsWithCapturesDirect, group, hasRepeatPatternsInSlice, isRepeatPattern, knownValue, knownValueNamed, knownValuePatternAny, knownValuePatternDisplay, knownValuePatternMatches, knownValuePatternNamed, knownValuePatternPaths, knownValuePatternRegex, knownValuePatternValue, knownValueRegex, map, mapPatternAny, mapPatternDisplay, mapPatternEquals, mapPatternMatches, mapPatternPaths, mapPatternPathsWithCaptures, mapPatternWithConstraints, mapPatternWithLength, mapPatternWithLengthInterval, mapPatternWithLengthRange, matchFn, matchPattern, matches, metaAnd, metaAny, metaCapture, metaNot, metaOr, metaPatternDisplay, metaPatternMatches, metaPatternPaths, metaRepeat, metaSearch, metaSequence, not, notPattern, notPatternDisplay, notPatternMatches, notPatternPaths, nullPattern, nullPatternDisplay, nullPatternMatches, nullPatternPaths, number, numberGreaterThan, numberGreaterThanOrEqual, numberInfinity, numberLessThan, numberLessThanOrEqual, numberNaN, numberNegInfinity, numberPatternAny, numberPatternDisplay, numberPatternGreaterThan, numberPatternGreaterThanOrEqual, numberPatternInfinity, numberPatternLessThan, numberPatternLessThanOrEqual, numberPatternMatches, numberPatternNaN, numberPatternNegInfinity, numberPatternPaths, numberPatternRange, numberPatternValue, numberRange, or, orPattern, orPatternDisplay, orPatternMatches, orPatternPaths, parse, parseAnd, parseBool, parseBoolFalse, parseBoolTrue, parseBracketArray, parseBracketMap, parseByteString, parseCapture, parseDate, parseDigest, parseHexRegexToken, parseHexStringToken, parseKnownValue, parseNot, parseNull, parseNumber, parseOr, parseOrFn, parseOrFromRegistry, parsePartial, parsePrimary, parseQuantifier, parseSearch, parseTagged, parseText, paths, pathsFn, pathsWithCaptures, pathsWithCapturesDirect, pathsWithCapturesDirectFn, pathsWithCapturesFn, patternDisplay, patternMatches, patternPaths, patternPathsWithCaptures, reluctanceSuffix, repeat, repeatExact, repeatOneOrMore, repeatOptional, repeatPattern, repeatPatternDisplay, repeatPatternMatches, repeatPatternPaths, repeatRange, repeatZeroOrMore, run, search, searchPattern, searchPatternDisplay, searchPatternMatches, searchPatternPaths, searchPatternPathsWithCaptures, sequence, sequencePattern, sequencePatternDisplay, sequencePatternMatches, sequencePatternPaths, sequencePatternPatterns, setMatchFn, setParseOrFn, setPathsFn, setPathsWithCapturesDirectFn, setPathsWithCapturesFn, span, structureArray, structureMap, structurePatternDisplay, structurePatternMatches, structurePatternPaths, structurePatternPathsWithCaptures, structureTagged, tagged, taggedName, taggedPatternAny, taggedPatternDisplay, taggedPatternMatches, taggedPatternPaths, taggedPatternPathsWithCaptures, taggedPatternWithName, taggedPatternWithRegex, taggedPatternWithTag, taggedRegex, text, textPatternAny, textPatternDisplay, textPatternMatches, textPatternPaths, textPatternRegex, textPatternValue, textRegex, transformCapturesWithArrayContext, unwrap, unwrapOr, valueBool, valueByteString, valueDate, valueDigest, valueKnownValue, valueNull, valueNumber, valuePatternDisplay, valuePatternMatches, valuePatternPaths, valueText };
2732
+ //# sourceMappingURL=index.d.mts.map