@bcts/envelope-pattern 1.0.0-alpha.16 → 1.0.0-alpha.18
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/dist/index.cjs +1992 -1714
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +147 -31
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.mts +147 -31
- package/dist/index.d.mts.map +1 -1
- package/dist/index.iife.js +1984 -1707
- package/dist/index.iife.js.map +1 -1
- package/dist/index.mjs +1966 -1698
- package/dist/index.mjs.map +1 -1
- package/package.json +9 -9
- package/src/format.ts +32 -13
- package/src/parse/index.ts +138 -5
- package/src/parse/token.ts +59 -58
- package/src/pattern/index.ts +110 -2
- package/src/pattern/leaf/array-pattern.ts +26 -26
- package/src/pattern/leaf/bool-pattern.ts +12 -12
- package/src/pattern/leaf/byte-string-pattern.ts +15 -15
- package/src/pattern/leaf/cbor-pattern.ts +31 -31
- package/src/pattern/leaf/date-pattern.ts +9 -9
- package/src/pattern/leaf/index.ts +1 -2
- package/src/pattern/leaf/known-value-pattern.ts +21 -20
- package/src/pattern/leaf/map-pattern.ts +14 -14
- package/src/pattern/leaf/null-pattern.ts +8 -8
- package/src/pattern/leaf/number-pattern.ts +20 -20
- package/src/pattern/leaf/tagged-pattern.ts +20 -20
- package/src/pattern/leaf/text-pattern.ts +14 -14
- package/src/pattern/matcher.ts +88 -3
- package/src/pattern/meta/and-pattern.ts +19 -18
- package/src/pattern/meta/capture-pattern.ts +16 -17
- package/src/pattern/meta/group-pattern.ts +20 -17
- package/src/pattern/meta/not-pattern.ts +9 -8
- package/src/pattern/meta/or-pattern.ts +30 -25
- package/src/pattern/meta/search-pattern.ts +17 -17
- package/src/pattern/meta/traverse-pattern.ts +42 -18
- package/src/pattern/structure/assertions-pattern.ts +31 -32
- package/src/pattern/structure/digest-pattern.ts +23 -23
- package/src/pattern/structure/index.ts +1 -0
- package/src/pattern/structure/node-pattern.ts +17 -17
- package/src/pattern/structure/object-pattern.ts +14 -15
- package/src/pattern/structure/obscured-pattern.ts +7 -7
- package/src/pattern/structure/predicate-pattern.ts +14 -15
- package/src/pattern/structure/subject-pattern.ts +16 -17
- package/src/pattern/structure/wrapped-pattern.ts +40 -19
- package/src/pattern/vm.ts +12 -11
|
@@ -42,10 +42,10 @@ export function registerDatePatternFactory(factory: (pattern: DatePattern) => Pa
|
|
|
42
42
|
* Corresponds to the Rust `DatePattern` struct in date_pattern.rs
|
|
43
43
|
*/
|
|
44
44
|
export class DatePattern implements Matcher {
|
|
45
|
-
readonly
|
|
45
|
+
private readonly _inner: DCBORDatePattern;
|
|
46
46
|
|
|
47
47
|
private constructor(inner: DCBORDatePattern) {
|
|
48
|
-
this
|
|
48
|
+
this._inner = inner;
|
|
49
49
|
}
|
|
50
50
|
|
|
51
51
|
/**
|
|
@@ -109,15 +109,15 @@ export class DatePattern implements Matcher {
|
|
|
109
109
|
* Gets the underlying dcbor-pattern DatePattern.
|
|
110
110
|
*/
|
|
111
111
|
get inner(): DCBORDatePattern {
|
|
112
|
-
return this
|
|
112
|
+
return this._inner;
|
|
113
113
|
}
|
|
114
114
|
|
|
115
115
|
pathsWithCaptures(haystack: Envelope): [Path[], Map<string, Path[]>] {
|
|
116
116
|
// For leaf envelopes, extract the CBOR and delegate to dcbor-pattern
|
|
117
|
-
const cbor = haystack.asLeaf();
|
|
117
|
+
const cbor = haystack.subject().asLeaf();
|
|
118
118
|
if (cbor !== undefined) {
|
|
119
119
|
// Delegate to dcbor-pattern for CBOR matching
|
|
120
|
-
const dcborPaths = dcborDatePatternPaths(this
|
|
120
|
+
const dcborPaths = dcborDatePatternPaths(this._inner, cbor);
|
|
121
121
|
|
|
122
122
|
// For simple leaf patterns, if dcbor-pattern found matches, return the envelope
|
|
123
123
|
if (dcborPaths.length > 0) {
|
|
@@ -149,18 +149,18 @@ export class DatePattern implements Matcher {
|
|
|
149
149
|
}
|
|
150
150
|
|
|
151
151
|
toString(): string {
|
|
152
|
-
return datePatternDisplay(this
|
|
152
|
+
return datePatternDisplay(this._inner);
|
|
153
153
|
}
|
|
154
154
|
|
|
155
155
|
/**
|
|
156
156
|
* Equality comparison.
|
|
157
157
|
*/
|
|
158
158
|
equals(other: DatePattern): boolean {
|
|
159
|
-
if (this
|
|
159
|
+
if (this._inner.variant !== other._inner.variant) {
|
|
160
160
|
return false;
|
|
161
161
|
}
|
|
162
162
|
// Simplified equality - compare variant names
|
|
163
|
-
return JSON.stringify(this
|
|
163
|
+
return JSON.stringify(this._inner) === JSON.stringify(other._inner);
|
|
164
164
|
}
|
|
165
165
|
|
|
166
166
|
/**
|
|
@@ -169,7 +169,7 @@ export class DatePattern implements Matcher {
|
|
|
169
169
|
hashCode(): number {
|
|
170
170
|
// Simple hash based on variant
|
|
171
171
|
let hash = 0;
|
|
172
|
-
const str = this
|
|
172
|
+
const str = this._inner.variant;
|
|
173
173
|
for (let i = 0; i < str.length; i++) {
|
|
174
174
|
hash = hash * 31 + str.charCodeAt(i);
|
|
175
175
|
}
|
|
@@ -141,8 +141,7 @@ export function leafPatternPathsWithCaptures(
|
|
|
141
141
|
): [Path[], Map<string, Path[]>] {
|
|
142
142
|
switch (pattern.type) {
|
|
143
143
|
case "Cbor":
|
|
144
|
-
|
|
145
|
-
return [[], new Map<string, Path[]>()];
|
|
144
|
+
return pattern.pattern.pathsWithCaptures(haystack);
|
|
146
145
|
case "Number":
|
|
147
146
|
return pattern.pattern.pathsWithCaptures(haystack);
|
|
148
147
|
case "Text":
|
|
@@ -41,10 +41,10 @@ export function registerKnownValuePatternFactory(
|
|
|
41
41
|
* Corresponds to the Rust `KnownValuePattern` struct in known_value_pattern.rs
|
|
42
42
|
*/
|
|
43
43
|
export class KnownValuePattern implements Matcher {
|
|
44
|
-
readonly
|
|
44
|
+
private readonly _inner: DCBORKnownValuePattern;
|
|
45
45
|
|
|
46
46
|
private constructor(inner: DCBORKnownValuePattern) {
|
|
47
|
-
this
|
|
47
|
+
this._inner = inner;
|
|
48
48
|
}
|
|
49
49
|
|
|
50
50
|
/**
|
|
@@ -86,25 +86,26 @@ export class KnownValuePattern implements Matcher {
|
|
|
86
86
|
* Gets the underlying dcbor-pattern KnownValuePattern.
|
|
87
87
|
*/
|
|
88
88
|
get inner(): DCBORKnownValuePattern {
|
|
89
|
-
return this
|
|
89
|
+
return this._inner;
|
|
90
90
|
}
|
|
91
91
|
|
|
92
92
|
pathsWithCaptures(haystack: Envelope): [Path[], Map<string, Path[]>] {
|
|
93
|
-
// Check if the envelope is a known value via case()
|
|
94
|
-
const
|
|
93
|
+
// Check if the envelope subject is a known value via case()
|
|
94
|
+
const subject = haystack.subject();
|
|
95
|
+
const envCase = subject.case();
|
|
95
96
|
|
|
96
97
|
if (envCase.type === "knownValue") {
|
|
97
98
|
// Get the KnownValue and create CBOR for pattern matching
|
|
98
99
|
const knownValueCbor = envCase.value.taggedCbor();
|
|
99
|
-
if (knownValuePatternMatches(this
|
|
100
|
+
if (knownValuePatternMatches(this._inner, knownValueCbor)) {
|
|
100
101
|
return [[[haystack]], new Map<string, Path[]>()];
|
|
101
102
|
}
|
|
102
103
|
}
|
|
103
104
|
|
|
104
105
|
// Also try matching as a leaf (for tagged CBOR containing known values)
|
|
105
|
-
const leafCbor =
|
|
106
|
+
const leafCbor = subject.asLeaf();
|
|
106
107
|
if (leafCbor !== undefined) {
|
|
107
|
-
if (knownValuePatternMatches(this
|
|
108
|
+
if (knownValuePatternMatches(this._inner, leafCbor)) {
|
|
108
109
|
return [[[haystack]], new Map<string, Path[]>()];
|
|
109
110
|
}
|
|
110
111
|
}
|
|
@@ -132,7 +133,7 @@ export class KnownValuePattern implements Matcher {
|
|
|
132
133
|
}
|
|
133
134
|
|
|
134
135
|
toString(): string {
|
|
135
|
-
return knownValuePatternDisplay(this
|
|
136
|
+
return knownValuePatternDisplay(this._inner);
|
|
136
137
|
}
|
|
137
138
|
|
|
138
139
|
/**
|
|
@@ -140,23 +141,23 @@ export class KnownValuePattern implements Matcher {
|
|
|
140
141
|
*/
|
|
141
142
|
equals(other: KnownValuePattern): boolean {
|
|
142
143
|
// Compare by variant type and values
|
|
143
|
-
if (this
|
|
144
|
+
if (this._inner.variant !== other._inner.variant) {
|
|
144
145
|
return false;
|
|
145
146
|
}
|
|
146
|
-
switch (this
|
|
147
|
+
switch (this._inner.variant) {
|
|
147
148
|
case "Any":
|
|
148
149
|
return true;
|
|
149
150
|
case "Value":
|
|
150
151
|
return (
|
|
151
|
-
this
|
|
152
|
-
(other
|
|
152
|
+
this._inner.value.valueBigInt() ===
|
|
153
|
+
(other._inner as { variant: "Value"; value: KnownValue }).value.valueBigInt()
|
|
153
154
|
);
|
|
154
155
|
case "Named":
|
|
155
|
-
return this
|
|
156
|
+
return this._inner.name === (other._inner as { variant: "Named"; name: string }).name;
|
|
156
157
|
case "Regex":
|
|
157
158
|
return (
|
|
158
|
-
this
|
|
159
|
-
(other
|
|
159
|
+
this._inner.pattern.source ===
|
|
160
|
+
(other._inner as { variant: "Regex"; pattern: RegExp }).pattern.source
|
|
160
161
|
);
|
|
161
162
|
}
|
|
162
163
|
}
|
|
@@ -165,15 +166,15 @@ export class KnownValuePattern implements Matcher {
|
|
|
165
166
|
* Hash code for use in Maps/Sets.
|
|
166
167
|
*/
|
|
167
168
|
hashCode(): number {
|
|
168
|
-
switch (this
|
|
169
|
+
switch (this._inner.variant) {
|
|
169
170
|
case "Any":
|
|
170
171
|
return 0;
|
|
171
172
|
case "Value":
|
|
172
|
-
return Number(this
|
|
173
|
+
return Number(this._inner.value.valueBigInt() & BigInt(0xffffffff));
|
|
173
174
|
case "Named":
|
|
174
|
-
return simpleStringHash(this
|
|
175
|
+
return simpleStringHash(this._inner.name);
|
|
175
176
|
case "Regex":
|
|
176
|
-
return simpleStringHash(this
|
|
177
|
+
return simpleStringHash(this._inner.pattern.source);
|
|
177
178
|
}
|
|
178
179
|
}
|
|
179
180
|
}
|
|
@@ -37,10 +37,10 @@ export type MapPatternType =
|
|
|
37
37
|
* Corresponds to the Rust `MapPattern` struct in map_pattern.rs
|
|
38
38
|
*/
|
|
39
39
|
export class MapPattern implements Matcher {
|
|
40
|
-
readonly
|
|
40
|
+
private readonly _pattern: MapPatternType;
|
|
41
41
|
|
|
42
42
|
private constructor(pattern: MapPatternType) {
|
|
43
|
-
this
|
|
43
|
+
this._pattern = pattern;
|
|
44
44
|
}
|
|
45
45
|
|
|
46
46
|
/**
|
|
@@ -62,12 +62,12 @@ export class MapPattern implements Matcher {
|
|
|
62
62
|
* Gets the pattern type.
|
|
63
63
|
*/
|
|
64
64
|
get pattern(): MapPatternType {
|
|
65
|
-
return this
|
|
65
|
+
return this._pattern;
|
|
66
66
|
}
|
|
67
67
|
|
|
68
68
|
pathsWithCaptures(haystack: Envelope): [Path[], Map<string, Path[]>] {
|
|
69
69
|
// Try to extract CBOR from the envelope
|
|
70
|
-
const cbor = haystack.asLeaf();
|
|
70
|
+
const cbor = haystack.subject().asLeaf();
|
|
71
71
|
if (cbor === undefined) {
|
|
72
72
|
return [[], new Map<string, Path[]>()];
|
|
73
73
|
}
|
|
@@ -78,13 +78,13 @@ export class MapPattern implements Matcher {
|
|
|
78
78
|
return [[], new Map<string, Path[]>()];
|
|
79
79
|
}
|
|
80
80
|
|
|
81
|
-
switch (this
|
|
81
|
+
switch (this._pattern.type) {
|
|
82
82
|
case "Any":
|
|
83
83
|
return [[[haystack]], new Map<string, Path[]>()];
|
|
84
84
|
|
|
85
85
|
case "Interval": {
|
|
86
86
|
const size = map.size;
|
|
87
|
-
if (this
|
|
87
|
+
if (this._pattern.interval.contains(size)) {
|
|
88
88
|
return [[[haystack]], new Map<string, Path[]>()];
|
|
89
89
|
}
|
|
90
90
|
return [[], new Map<string, Path[]>()];
|
|
@@ -112,11 +112,11 @@ export class MapPattern implements Matcher {
|
|
|
112
112
|
}
|
|
113
113
|
|
|
114
114
|
toString(): string {
|
|
115
|
-
switch (this
|
|
115
|
+
switch (this._pattern.type) {
|
|
116
116
|
case "Any":
|
|
117
117
|
return "{*}";
|
|
118
118
|
case "Interval":
|
|
119
|
-
return `{{${this
|
|
119
|
+
return `{{${this._pattern.interval.toString()}}}`;
|
|
120
120
|
}
|
|
121
121
|
}
|
|
122
122
|
|
|
@@ -124,15 +124,15 @@ export class MapPattern implements Matcher {
|
|
|
124
124
|
* Equality comparison.
|
|
125
125
|
*/
|
|
126
126
|
equals(other: MapPattern): boolean {
|
|
127
|
-
if (this
|
|
127
|
+
if (this._pattern.type !== other._pattern.type) {
|
|
128
128
|
return false;
|
|
129
129
|
}
|
|
130
|
-
switch (this
|
|
130
|
+
switch (this._pattern.type) {
|
|
131
131
|
case "Any":
|
|
132
132
|
return true;
|
|
133
133
|
case "Interval":
|
|
134
|
-
return this
|
|
135
|
-
(other
|
|
134
|
+
return this._pattern.interval.equals(
|
|
135
|
+
(other._pattern as { type: "Interval"; interval: Interval }).interval,
|
|
136
136
|
);
|
|
137
137
|
}
|
|
138
138
|
}
|
|
@@ -141,12 +141,12 @@ export class MapPattern implements Matcher {
|
|
|
141
141
|
* Hash code for use in Maps/Sets.
|
|
142
142
|
*/
|
|
143
143
|
hashCode(): number {
|
|
144
|
-
switch (this
|
|
144
|
+
switch (this._pattern.type) {
|
|
145
145
|
case "Any":
|
|
146
146
|
return 0;
|
|
147
147
|
case "Interval":
|
|
148
148
|
// Simple hash based on interval min/max
|
|
149
|
-
return this
|
|
149
|
+
return this._pattern.interval.min() * 31 + (this._pattern.interval.max() ?? 0);
|
|
150
150
|
}
|
|
151
151
|
}
|
|
152
152
|
}
|
|
@@ -34,34 +34,34 @@ export function registerNullPatternFactory(factory: (pattern: NullPattern) => Pa
|
|
|
34
34
|
* Corresponds to the Rust `NullPattern` struct in null_pattern.rs
|
|
35
35
|
*/
|
|
36
36
|
export class NullPattern implements Matcher {
|
|
37
|
-
readonly
|
|
38
|
-
static readonly
|
|
37
|
+
private readonly _inner: DCBORNullPattern;
|
|
38
|
+
private static readonly _instance = new NullPattern();
|
|
39
39
|
|
|
40
40
|
private constructor() {
|
|
41
41
|
// Create the NullPattern directly - it's just { variant: "Null" }
|
|
42
|
-
this
|
|
42
|
+
this._inner = { variant: "Null" };
|
|
43
43
|
}
|
|
44
44
|
|
|
45
45
|
/**
|
|
46
46
|
* Creates a new NullPattern (returns singleton).
|
|
47
47
|
*/
|
|
48
48
|
static new(): NullPattern {
|
|
49
|
-
return NullPattern
|
|
49
|
+
return NullPattern._instance;
|
|
50
50
|
}
|
|
51
51
|
|
|
52
52
|
/**
|
|
53
53
|
* Gets the underlying dcbor-pattern NullPattern.
|
|
54
54
|
*/
|
|
55
55
|
get inner(): DCBORNullPattern {
|
|
56
|
-
return this
|
|
56
|
+
return this._inner;
|
|
57
57
|
}
|
|
58
58
|
|
|
59
59
|
pathsWithCaptures(haystack: Envelope): [Path[], Map<string, Path[]>] {
|
|
60
60
|
// For leaf envelopes, extract the CBOR and delegate to dcbor-pattern
|
|
61
|
-
const cbor = haystack.asLeaf();
|
|
61
|
+
const cbor = haystack.subject().asLeaf();
|
|
62
62
|
if (cbor !== undefined) {
|
|
63
63
|
// Delegate to dcbor-pattern for CBOR matching
|
|
64
|
-
const dcborPaths = dcborNullPatternPaths(this
|
|
64
|
+
const dcborPaths = dcborNullPatternPaths(this._inner, cbor);
|
|
65
65
|
|
|
66
66
|
if (dcborPaths.length > 0) {
|
|
67
67
|
return [[[haystack]], new Map<string, Path[]>()];
|
|
@@ -91,7 +91,7 @@ export class NullPattern implements Matcher {
|
|
|
91
91
|
}
|
|
92
92
|
|
|
93
93
|
toString(): string {
|
|
94
|
-
return nullPatternDisplay(this
|
|
94
|
+
return nullPatternDisplay(this._inner);
|
|
95
95
|
}
|
|
96
96
|
|
|
97
97
|
/**
|
|
@@ -44,10 +44,10 @@ export function registerNumberPatternFactory(factory: (pattern: NumberPattern) =
|
|
|
44
44
|
* Corresponds to the Rust `NumberPattern` struct in number_pattern.rs
|
|
45
45
|
*/
|
|
46
46
|
export class NumberPattern implements Matcher {
|
|
47
|
-
readonly
|
|
47
|
+
private readonly _inner: DCBORNumberPattern;
|
|
48
48
|
|
|
49
49
|
private constructor(inner: DCBORNumberPattern) {
|
|
50
|
-
this
|
|
50
|
+
this._inner = inner;
|
|
51
51
|
}
|
|
52
52
|
|
|
53
53
|
/**
|
|
@@ -131,15 +131,15 @@ export class NumberPattern implements Matcher {
|
|
|
131
131
|
* Gets the underlying dcbor-pattern NumberPattern.
|
|
132
132
|
*/
|
|
133
133
|
get inner(): DCBORNumberPattern {
|
|
134
|
-
return this
|
|
134
|
+
return this._inner;
|
|
135
135
|
}
|
|
136
136
|
|
|
137
137
|
pathsWithCaptures(haystack: Envelope): [Path[], Map<string, Path[]>] {
|
|
138
138
|
// For leaf envelopes, extract the CBOR and delegate to dcbor-pattern
|
|
139
|
-
const cbor = haystack.asLeaf();
|
|
139
|
+
const cbor = haystack.subject().asLeaf();
|
|
140
140
|
if (cbor !== undefined) {
|
|
141
141
|
// Delegate to dcbor-pattern for CBOR matching
|
|
142
|
-
const dcborPaths = dcborNumberPatternPaths(this
|
|
142
|
+
const dcborPaths = dcborNumberPatternPaths(this._inner, cbor);
|
|
143
143
|
|
|
144
144
|
// For simple leaf patterns, if dcbor-pattern found matches, return the envelope
|
|
145
145
|
if (dcborPaths.length > 0) {
|
|
@@ -171,7 +171,7 @@ export class NumberPattern implements Matcher {
|
|
|
171
171
|
}
|
|
172
172
|
|
|
173
173
|
toString(): string {
|
|
174
|
-
return numberPatternDisplay(this
|
|
174
|
+
return numberPatternDisplay(this._inner);
|
|
175
175
|
}
|
|
176
176
|
|
|
177
177
|
/**
|
|
@@ -179,10 +179,10 @@ export class NumberPattern implements Matcher {
|
|
|
179
179
|
*/
|
|
180
180
|
equals(other: NumberPattern): boolean {
|
|
181
181
|
// Compare by variant and values
|
|
182
|
-
if (this
|
|
182
|
+
if (this._inner.variant !== other._inner.variant) {
|
|
183
183
|
return false;
|
|
184
184
|
}
|
|
185
|
-
switch (this
|
|
185
|
+
switch (this._inner.variant) {
|
|
186
186
|
case "Any":
|
|
187
187
|
case "NaN":
|
|
188
188
|
case "Infinity":
|
|
@@ -194,14 +194,14 @@ export class NumberPattern implements Matcher {
|
|
|
194
194
|
case "LessThan":
|
|
195
195
|
case "LessThanOrEqual":
|
|
196
196
|
return (
|
|
197
|
-
(this
|
|
197
|
+
(this._inner as { value: number }).value === (other._inner as { value: number }).value
|
|
198
198
|
);
|
|
199
199
|
case "Range":
|
|
200
200
|
return (
|
|
201
|
-
(this
|
|
202
|
-
(other
|
|
203
|
-
(this
|
|
204
|
-
(other
|
|
201
|
+
(this._inner as { min: number; max: number }).min ===
|
|
202
|
+
(other._inner as { min: number; max: number }).min &&
|
|
203
|
+
(this._inner as { min: number; max: number }).max ===
|
|
204
|
+
(other._inner as { min: number; max: number }).max
|
|
205
205
|
);
|
|
206
206
|
}
|
|
207
207
|
}
|
|
@@ -211,27 +211,27 @@ export class NumberPattern implements Matcher {
|
|
|
211
211
|
*/
|
|
212
212
|
hashCode(): number {
|
|
213
213
|
let hash = 0;
|
|
214
|
-
switch (this
|
|
214
|
+
switch (this._inner.variant) {
|
|
215
215
|
case "Any":
|
|
216
216
|
hash = 1;
|
|
217
217
|
break;
|
|
218
218
|
case "Value":
|
|
219
|
-
hash = 2 * 31 + (this
|
|
219
|
+
hash = 2 * 31 + (this._inner as { value: number }).value;
|
|
220
220
|
break;
|
|
221
221
|
case "Range":
|
|
222
|
-
hash = 3 * 31 + (this
|
|
222
|
+
hash = 3 * 31 + (this._inner as { min: number }).min + (this._inner as { max: number }).max;
|
|
223
223
|
break;
|
|
224
224
|
case "GreaterThan":
|
|
225
|
-
hash = 4 * 31 + (this
|
|
225
|
+
hash = 4 * 31 + (this._inner as { value: number }).value;
|
|
226
226
|
break;
|
|
227
227
|
case "GreaterThanOrEqual":
|
|
228
|
-
hash = 5 * 31 + (this
|
|
228
|
+
hash = 5 * 31 + (this._inner as { value: number }).value;
|
|
229
229
|
break;
|
|
230
230
|
case "LessThan":
|
|
231
|
-
hash = 6 * 31 + (this
|
|
231
|
+
hash = 6 * 31 + (this._inner as { value: number }).value;
|
|
232
232
|
break;
|
|
233
233
|
case "LessThanOrEqual":
|
|
234
|
-
hash = 7 * 31 + (this
|
|
234
|
+
hash = 7 * 31 + (this._inner as { value: number }).value;
|
|
235
235
|
break;
|
|
236
236
|
case "NaN":
|
|
237
237
|
hash = 8;
|
|
@@ -41,10 +41,10 @@ export function registerTaggedPatternFactory(factory: (pattern: TaggedPattern) =
|
|
|
41
41
|
* Corresponds to the Rust `TaggedPattern` struct in tagged_pattern.rs
|
|
42
42
|
*/
|
|
43
43
|
export class TaggedPattern implements Matcher {
|
|
44
|
-
readonly
|
|
44
|
+
private readonly _inner: DCBORTaggedPattern;
|
|
45
45
|
|
|
46
46
|
private constructor(inner: DCBORTaggedPattern) {
|
|
47
|
-
this
|
|
47
|
+
this._inner = inner;
|
|
48
48
|
}
|
|
49
49
|
|
|
50
50
|
/**
|
|
@@ -86,7 +86,7 @@ export class TaggedPattern implements Matcher {
|
|
|
86
86
|
* Gets the underlying dcbor-pattern TaggedPattern.
|
|
87
87
|
*/
|
|
88
88
|
get inner(): DCBORTaggedPattern {
|
|
89
|
-
return this
|
|
89
|
+
return this._inner;
|
|
90
90
|
}
|
|
91
91
|
|
|
92
92
|
pathsWithCaptures(haystack: Envelope): [Path[], Map<string, Path[]>] {
|
|
@@ -96,7 +96,7 @@ export class TaggedPattern implements Matcher {
|
|
|
96
96
|
|
|
97
97
|
if (cbor !== undefined) {
|
|
98
98
|
// Delegate to dcbor-pattern for CBOR matching
|
|
99
|
-
const [dcborPaths, dcborCaptures] = taggedPatternPathsWithCaptures(this
|
|
99
|
+
const [dcborPaths, dcborCaptures] = taggedPatternPathsWithCaptures(this._inner, cbor);
|
|
100
100
|
|
|
101
101
|
if (dcborPaths.length > 0) {
|
|
102
102
|
// Convert dcbor paths to envelope paths
|
|
@@ -155,7 +155,7 @@ export class TaggedPattern implements Matcher {
|
|
|
155
155
|
}
|
|
156
156
|
|
|
157
157
|
toString(): string {
|
|
158
|
-
return taggedPatternDisplay(this
|
|
158
|
+
return taggedPatternDisplay(this._inner, patternDisplay);
|
|
159
159
|
}
|
|
160
160
|
|
|
161
161
|
/**
|
|
@@ -163,35 +163,35 @@ export class TaggedPattern implements Matcher {
|
|
|
163
163
|
*/
|
|
164
164
|
equals(other: TaggedPattern): boolean {
|
|
165
165
|
// Compare by variant type and values
|
|
166
|
-
if (this
|
|
166
|
+
if (this._inner.variant !== other._inner.variant) {
|
|
167
167
|
return false;
|
|
168
168
|
}
|
|
169
|
-
switch (this
|
|
169
|
+
switch (this._inner.variant) {
|
|
170
170
|
case "Any":
|
|
171
171
|
return true;
|
|
172
172
|
case "Tag": {
|
|
173
|
-
const otherTag = other
|
|
173
|
+
const otherTag = other._inner as { variant: "Tag"; tag: Tag; pattern: DCBORPattern };
|
|
174
174
|
return (
|
|
175
|
-
this
|
|
176
|
-
patternDisplay(this
|
|
175
|
+
this._inner.tag.value === otherTag.tag.value &&
|
|
176
|
+
patternDisplay(this._inner.pattern) === patternDisplay(otherTag.pattern)
|
|
177
177
|
);
|
|
178
178
|
}
|
|
179
179
|
case "Name": {
|
|
180
|
-
const otherName = other
|
|
180
|
+
const otherName = other._inner as { variant: "Name"; name: string; pattern: DCBORPattern };
|
|
181
181
|
return (
|
|
182
|
-
this
|
|
183
|
-
patternDisplay(this
|
|
182
|
+
this._inner.name === otherName.name &&
|
|
183
|
+
patternDisplay(this._inner.pattern) === patternDisplay(otherName.pattern)
|
|
184
184
|
);
|
|
185
185
|
}
|
|
186
186
|
case "Regex": {
|
|
187
|
-
const otherRegex = other
|
|
187
|
+
const otherRegex = other._inner as {
|
|
188
188
|
variant: "Regex";
|
|
189
189
|
regex: RegExp;
|
|
190
190
|
pattern: DCBORPattern;
|
|
191
191
|
};
|
|
192
192
|
return (
|
|
193
|
-
this
|
|
194
|
-
patternDisplay(this
|
|
193
|
+
this._inner.regex.source === otherRegex.regex.source &&
|
|
194
|
+
patternDisplay(this._inner.pattern) === patternDisplay(otherRegex.pattern)
|
|
195
195
|
);
|
|
196
196
|
}
|
|
197
197
|
}
|
|
@@ -201,15 +201,15 @@ export class TaggedPattern implements Matcher {
|
|
|
201
201
|
* Hash code for use in Maps/Sets.
|
|
202
202
|
*/
|
|
203
203
|
hashCode(): number {
|
|
204
|
-
switch (this
|
|
204
|
+
switch (this._inner.variant) {
|
|
205
205
|
case "Any":
|
|
206
206
|
return 0;
|
|
207
207
|
case "Tag":
|
|
208
|
-
return Number(BigInt(this
|
|
208
|
+
return Number(BigInt(this._inner.tag.value) & BigInt(0xffffffff));
|
|
209
209
|
case "Name":
|
|
210
|
-
return simpleStringHash(this
|
|
210
|
+
return simpleStringHash(this._inner.name);
|
|
211
211
|
case "Regex":
|
|
212
|
-
return simpleStringHash(this
|
|
212
|
+
return simpleStringHash(this._inner.regex.source);
|
|
213
213
|
}
|
|
214
214
|
}
|
|
215
215
|
}
|
|
@@ -37,10 +37,10 @@ export function registerTextPatternFactory(factory: (pattern: TextPattern) => Pa
|
|
|
37
37
|
* Corresponds to the Rust `TextPattern` struct in text_pattern.rs
|
|
38
38
|
*/
|
|
39
39
|
export class TextPattern implements Matcher {
|
|
40
|
-
readonly
|
|
40
|
+
private readonly _inner: DCBORTextPattern;
|
|
41
41
|
|
|
42
42
|
private constructor(inner: DCBORTextPattern) {
|
|
43
|
-
this
|
|
43
|
+
this._inner = inner;
|
|
44
44
|
}
|
|
45
45
|
|
|
46
46
|
/**
|
|
@@ -75,15 +75,15 @@ export class TextPattern implements Matcher {
|
|
|
75
75
|
* Gets the underlying dcbor-pattern TextPattern.
|
|
76
76
|
*/
|
|
77
77
|
get inner(): DCBORTextPattern {
|
|
78
|
-
return this
|
|
78
|
+
return this._inner;
|
|
79
79
|
}
|
|
80
80
|
|
|
81
81
|
pathsWithCaptures(haystack: Envelope): [Path[], Map<string, Path[]>] {
|
|
82
82
|
// For leaf envelopes, extract the CBOR and delegate to dcbor-pattern
|
|
83
|
-
const cbor = haystack.asLeaf();
|
|
83
|
+
const cbor = haystack.subject().asLeaf();
|
|
84
84
|
if (cbor !== undefined) {
|
|
85
85
|
// Delegate to dcbor-pattern for CBOR matching
|
|
86
|
-
const dcborPaths = dcborTextPatternPaths(this
|
|
86
|
+
const dcborPaths = dcborTextPatternPaths(this._inner, cbor);
|
|
87
87
|
|
|
88
88
|
// For simple leaf patterns, if dcbor-pattern found matches, return the envelope
|
|
89
89
|
if (dcborPaths.length > 0) {
|
|
@@ -115,27 +115,27 @@ export class TextPattern implements Matcher {
|
|
|
115
115
|
}
|
|
116
116
|
|
|
117
117
|
toString(): string {
|
|
118
|
-
return textPatternDisplay(this
|
|
118
|
+
return textPatternDisplay(this._inner);
|
|
119
119
|
}
|
|
120
120
|
|
|
121
121
|
/**
|
|
122
122
|
* Equality comparison.
|
|
123
123
|
*/
|
|
124
124
|
equals(other: TextPattern): boolean {
|
|
125
|
-
if (this
|
|
125
|
+
if (this._inner.variant !== other._inner.variant) {
|
|
126
126
|
return false;
|
|
127
127
|
}
|
|
128
|
-
switch (this
|
|
128
|
+
switch (this._inner.variant) {
|
|
129
129
|
case "Any":
|
|
130
130
|
return true;
|
|
131
131
|
case "Value":
|
|
132
132
|
return (
|
|
133
|
-
(this
|
|
133
|
+
(this._inner as { value: string }).value === (other._inner as { value: string }).value
|
|
134
134
|
);
|
|
135
135
|
case "Regex":
|
|
136
136
|
return (
|
|
137
|
-
(this
|
|
138
|
-
(other
|
|
137
|
+
(this._inner as { pattern: RegExp }).pattern.source ===
|
|
138
|
+
(other._inner as { pattern: RegExp }).pattern.source
|
|
139
139
|
);
|
|
140
140
|
}
|
|
141
141
|
}
|
|
@@ -145,19 +145,19 @@ export class TextPattern implements Matcher {
|
|
|
145
145
|
*/
|
|
146
146
|
hashCode(): number {
|
|
147
147
|
let hash = 0;
|
|
148
|
-
switch (this
|
|
148
|
+
switch (this._inner.variant) {
|
|
149
149
|
case "Any":
|
|
150
150
|
hash = 1;
|
|
151
151
|
break;
|
|
152
152
|
case "Value": {
|
|
153
|
-
const val = (this
|
|
153
|
+
const val = (this._inner as { value: string }).value;
|
|
154
154
|
for (let i = 0; i < val.length; i++) {
|
|
155
155
|
hash = hash * 31 + val.charCodeAt(i);
|
|
156
156
|
}
|
|
157
157
|
break;
|
|
158
158
|
}
|
|
159
159
|
case "Regex":
|
|
160
|
-
hash = 3 * 31 + (this
|
|
160
|
+
hash = 3 * 31 + (this._inner as { pattern: RegExp }).pattern.source.length;
|
|
161
161
|
break;
|
|
162
162
|
}
|
|
163
163
|
return hash;
|