@bcts/envelope-pattern 1.0.0-alpha.15 → 1.0.0-alpha.17
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 +485 -485
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +93 -29
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.mts +93 -29
- package/dist/index.d.mts.map +1 -1
- package/dist/index.iife.js +485 -485
- package/dist/index.iife.js.map +1 -1
- package/dist/index.mjs +504 -504
- package/dist/index.mjs.map +1 -1
- package/package.json +9 -9
- package/src/format.ts +9 -9
- package/src/parse/token.ts +55 -55
- package/src/pattern/leaf/array-pattern.ts +25 -25
- package/src/pattern/leaf/bool-pattern.ts +11 -11
- package/src/pattern/leaf/byte-string-pattern.ts +14 -14
- package/src/pattern/leaf/cbor-pattern.ts +29 -29
- package/src/pattern/leaf/date-pattern.ts +8 -8
- package/src/pattern/leaf/known-value-pattern.ts +17 -17
- package/src/pattern/leaf/map-pattern.ts +13 -13
- package/src/pattern/leaf/null-pattern.ts +7 -7
- package/src/pattern/leaf/number-pattern.ts +19 -19
- package/src/pattern/leaf/tagged-pattern.ts +20 -20
- package/src/pattern/leaf/text-pattern.ts +13 -13
- package/src/pattern/meta/and-pattern.ts +11 -11
- package/src/pattern/meta/capture-pattern.ts +14 -14
- package/src/pattern/meta/group-pattern.ts +13 -13
- package/src/pattern/meta/not-pattern.ts +7 -7
- package/src/pattern/meta/or-pattern.ts +15 -15
- package/src/pattern/meta/search-pattern.ts +15 -15
- package/src/pattern/meta/traverse-pattern.ts +15 -15
- package/src/pattern/structure/assertions-pattern.ts +28 -28
- package/src/pattern/structure/digest-pattern.ts +23 -23
- package/src/pattern/structure/node-pattern.ts +17 -17
- package/src/pattern/structure/object-pattern.ts +13 -13
- package/src/pattern/structure/obscured-pattern.ts +7 -7
- package/src/pattern/structure/predicate-pattern.ts +13 -13
- package/src/pattern/structure/subject-pattern.ts +15 -15
- package/src/pattern/structure/wrapped-pattern.ts +15 -15
package/dist/index.mjs
CHANGED
|
@@ -262,28 +262,28 @@ function defaultFormatPathsOpts() {
|
|
|
262
262
|
* Builder for FormatPathsOpts.
|
|
263
263
|
*/
|
|
264
264
|
var FormatPathsOptsBuilder = class {
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
265
|
+
_indent = true;
|
|
266
|
+
_elementFormat = defaultPathElementFormat();
|
|
267
|
+
_lastElementOnly = false;
|
|
268
268
|
/**
|
|
269
269
|
* Sets whether to indent each path element.
|
|
270
270
|
*/
|
|
271
271
|
indent(indent) {
|
|
272
|
-
this
|
|
272
|
+
this._indent = indent;
|
|
273
273
|
return this;
|
|
274
274
|
}
|
|
275
275
|
/**
|
|
276
276
|
* Sets the format for each path element.
|
|
277
277
|
*/
|
|
278
278
|
elementFormat(format) {
|
|
279
|
-
this
|
|
279
|
+
this._elementFormat = format;
|
|
280
280
|
return this;
|
|
281
281
|
}
|
|
282
282
|
/**
|
|
283
283
|
* Sets whether to format only the last element of each path.
|
|
284
284
|
*/
|
|
285
285
|
lastElementOnly(lastElementOnly) {
|
|
286
|
-
this
|
|
286
|
+
this._lastElementOnly = lastElementOnly;
|
|
287
287
|
return this;
|
|
288
288
|
}
|
|
289
289
|
/**
|
|
@@ -291,9 +291,9 @@ var FormatPathsOptsBuilder = class {
|
|
|
291
291
|
*/
|
|
292
292
|
build() {
|
|
293
293
|
return {
|
|
294
|
-
indent: this
|
|
295
|
-
elementFormat: this
|
|
296
|
-
lastElementOnly: this
|
|
294
|
+
indent: this._indent,
|
|
295
|
+
elementFormat: this._elementFormat,
|
|
296
|
+
lastElementOnly: this._lastElementOnly
|
|
297
297
|
};
|
|
298
298
|
}
|
|
299
299
|
};
|
|
@@ -533,9 +533,9 @@ function registerBoolPatternFactory(factory) {
|
|
|
533
533
|
* Corresponds to the Rust `BoolPattern` struct in bool_pattern.rs
|
|
534
534
|
*/
|
|
535
535
|
var BoolPattern = class BoolPattern {
|
|
536
|
-
|
|
536
|
+
_inner;
|
|
537
537
|
constructor(inner) {
|
|
538
|
-
this
|
|
538
|
+
this._inner = inner;
|
|
539
539
|
}
|
|
540
540
|
/**
|
|
541
541
|
* Creates a new BoolPattern that matches any boolean value.
|
|
@@ -559,12 +559,12 @@ var BoolPattern = class BoolPattern {
|
|
|
559
559
|
* Gets the underlying dcbor-pattern BoolPattern.
|
|
560
560
|
*/
|
|
561
561
|
get inner() {
|
|
562
|
-
return this
|
|
562
|
+
return this._inner;
|
|
563
563
|
}
|
|
564
564
|
pathsWithCaptures(haystack) {
|
|
565
|
-
const cbor
|
|
566
|
-
if (cbor
|
|
567
|
-
if (boolPatternPaths(this
|
|
565
|
+
const cbor = haystack.asLeaf();
|
|
566
|
+
if (cbor !== void 0) {
|
|
567
|
+
if (boolPatternPaths(this._inner, cbor).length > 0) return [[[haystack]], /* @__PURE__ */ new Map()];
|
|
568
568
|
}
|
|
569
569
|
return [[], /* @__PURE__ */ new Map()];
|
|
570
570
|
}
|
|
@@ -582,22 +582,22 @@ var BoolPattern = class BoolPattern {
|
|
|
582
582
|
return false;
|
|
583
583
|
}
|
|
584
584
|
toString() {
|
|
585
|
-
return boolPatternDisplay(this
|
|
585
|
+
return boolPatternDisplay(this._inner);
|
|
586
586
|
}
|
|
587
587
|
/**
|
|
588
588
|
* Equality comparison.
|
|
589
589
|
*/
|
|
590
590
|
equals(other) {
|
|
591
|
-
if (this
|
|
592
|
-
if (this
|
|
591
|
+
if (this._inner.variant !== other._inner.variant) return false;
|
|
592
|
+
if (this._inner.variant === "Value" && other._inner.variant === "Value") return this._inner.value === other._inner.value;
|
|
593
593
|
return true;
|
|
594
594
|
}
|
|
595
595
|
/**
|
|
596
596
|
* Hash code for use in Maps/Sets.
|
|
597
597
|
*/
|
|
598
598
|
hashCode() {
|
|
599
|
-
let hash = this
|
|
600
|
-
if (this
|
|
599
|
+
let hash = this._inner.variant === "Any" ? 0 : 1;
|
|
600
|
+
if (this._inner.variant === "Value") hash = hash * 31 + (this._inner.value ? 1 : 0);
|
|
601
601
|
return hash;
|
|
602
602
|
}
|
|
603
603
|
};
|
|
@@ -617,27 +617,27 @@ function registerNullPatternFactory(factory) {
|
|
|
617
617
|
* Corresponds to the Rust `NullPattern` struct in null_pattern.rs
|
|
618
618
|
*/
|
|
619
619
|
var NullPattern = class NullPattern {
|
|
620
|
-
|
|
621
|
-
static
|
|
620
|
+
_inner;
|
|
621
|
+
static _instance = new NullPattern();
|
|
622
622
|
constructor() {
|
|
623
|
-
this
|
|
623
|
+
this._inner = { variant: "Null" };
|
|
624
624
|
}
|
|
625
625
|
/**
|
|
626
626
|
* Creates a new NullPattern (returns singleton).
|
|
627
627
|
*/
|
|
628
628
|
static new() {
|
|
629
|
-
return NullPattern
|
|
629
|
+
return NullPattern._instance;
|
|
630
630
|
}
|
|
631
631
|
/**
|
|
632
632
|
* Gets the underlying dcbor-pattern NullPattern.
|
|
633
633
|
*/
|
|
634
634
|
get inner() {
|
|
635
|
-
return this
|
|
635
|
+
return this._inner;
|
|
636
636
|
}
|
|
637
637
|
pathsWithCaptures(haystack) {
|
|
638
|
-
const cbor
|
|
639
|
-
if (cbor
|
|
640
|
-
if (nullPatternPaths(this
|
|
638
|
+
const cbor = haystack.asLeaf();
|
|
639
|
+
if (cbor !== void 0) {
|
|
640
|
+
if (nullPatternPaths(this._inner, cbor).length > 0) return [[[haystack]], /* @__PURE__ */ new Map()];
|
|
641
641
|
}
|
|
642
642
|
return [[], /* @__PURE__ */ new Map()];
|
|
643
643
|
}
|
|
@@ -655,7 +655,7 @@ var NullPattern = class NullPattern {
|
|
|
655
655
|
return false;
|
|
656
656
|
}
|
|
657
657
|
toString() {
|
|
658
|
-
return nullPatternDisplay(this
|
|
658
|
+
return nullPatternDisplay(this._inner);
|
|
659
659
|
}
|
|
660
660
|
/**
|
|
661
661
|
* Equality comparison.
|
|
@@ -686,9 +686,9 @@ function registerNumberPatternFactory(factory) {
|
|
|
686
686
|
* Corresponds to the Rust `NumberPattern` struct in number_pattern.rs
|
|
687
687
|
*/
|
|
688
688
|
var NumberPattern = class NumberPattern {
|
|
689
|
-
|
|
689
|
+
_inner;
|
|
690
690
|
constructor(inner) {
|
|
691
|
-
this
|
|
691
|
+
this._inner = inner;
|
|
692
692
|
}
|
|
693
693
|
/**
|
|
694
694
|
* Creates a new NumberPattern that matches any number.
|
|
@@ -760,12 +760,12 @@ var NumberPattern = class NumberPattern {
|
|
|
760
760
|
* Gets the underlying dcbor-pattern NumberPattern.
|
|
761
761
|
*/
|
|
762
762
|
get inner() {
|
|
763
|
-
return this
|
|
763
|
+
return this._inner;
|
|
764
764
|
}
|
|
765
765
|
pathsWithCaptures(haystack) {
|
|
766
|
-
const cbor
|
|
767
|
-
if (cbor
|
|
768
|
-
if (numberPatternPaths(this
|
|
766
|
+
const cbor = haystack.asLeaf();
|
|
767
|
+
if (cbor !== void 0) {
|
|
768
|
+
if (numberPatternPaths(this._inner, cbor).length > 0) return [[[haystack]], /* @__PURE__ */ new Map()];
|
|
769
769
|
}
|
|
770
770
|
return [[], /* @__PURE__ */ new Map()];
|
|
771
771
|
}
|
|
@@ -783,14 +783,14 @@ var NumberPattern = class NumberPattern {
|
|
|
783
783
|
return false;
|
|
784
784
|
}
|
|
785
785
|
toString() {
|
|
786
|
-
return numberPatternDisplay(this
|
|
786
|
+
return numberPatternDisplay(this._inner);
|
|
787
787
|
}
|
|
788
788
|
/**
|
|
789
789
|
* Equality comparison.
|
|
790
790
|
*/
|
|
791
791
|
equals(other) {
|
|
792
|
-
if (this
|
|
793
|
-
switch (this
|
|
792
|
+
if (this._inner.variant !== other._inner.variant) return false;
|
|
793
|
+
switch (this._inner.variant) {
|
|
794
794
|
case "Any":
|
|
795
795
|
case "NaN":
|
|
796
796
|
case "Infinity":
|
|
@@ -799,8 +799,8 @@ var NumberPattern = class NumberPattern {
|
|
|
799
799
|
case "GreaterThan":
|
|
800
800
|
case "GreaterThanOrEqual":
|
|
801
801
|
case "LessThan":
|
|
802
|
-
case "LessThanOrEqual": return this
|
|
803
|
-
case "Range": return this
|
|
802
|
+
case "LessThanOrEqual": return this._inner.value === other._inner.value;
|
|
803
|
+
case "Range": return this._inner.min === other._inner.min && this._inner.max === other._inner.max;
|
|
804
804
|
}
|
|
805
805
|
}
|
|
806
806
|
/**
|
|
@@ -808,27 +808,27 @@ var NumberPattern = class NumberPattern {
|
|
|
808
808
|
*/
|
|
809
809
|
hashCode() {
|
|
810
810
|
let hash = 0;
|
|
811
|
-
switch (this
|
|
811
|
+
switch (this._inner.variant) {
|
|
812
812
|
case "Any":
|
|
813
813
|
hash = 1;
|
|
814
814
|
break;
|
|
815
815
|
case "Value":
|
|
816
|
-
hash = 62 + this
|
|
816
|
+
hash = 62 + this._inner.value;
|
|
817
817
|
break;
|
|
818
818
|
case "Range":
|
|
819
|
-
hash = 93 + this
|
|
819
|
+
hash = 93 + this._inner.min + this._inner.max;
|
|
820
820
|
break;
|
|
821
821
|
case "GreaterThan":
|
|
822
|
-
hash = 124 + this
|
|
822
|
+
hash = 124 + this._inner.value;
|
|
823
823
|
break;
|
|
824
824
|
case "GreaterThanOrEqual":
|
|
825
|
-
hash = 155 + this
|
|
825
|
+
hash = 155 + this._inner.value;
|
|
826
826
|
break;
|
|
827
827
|
case "LessThan":
|
|
828
|
-
hash = 186 + this
|
|
828
|
+
hash = 186 + this._inner.value;
|
|
829
829
|
break;
|
|
830
830
|
case "LessThanOrEqual":
|
|
831
|
-
hash = 217 + this
|
|
831
|
+
hash = 217 + this._inner.value;
|
|
832
832
|
break;
|
|
833
833
|
case "NaN":
|
|
834
834
|
hash = 8;
|
|
@@ -859,9 +859,9 @@ function registerTextPatternFactory(factory) {
|
|
|
859
859
|
* Corresponds to the Rust `TextPattern` struct in text_pattern.rs
|
|
860
860
|
*/
|
|
861
861
|
var TextPattern = class TextPattern {
|
|
862
|
-
|
|
862
|
+
_inner;
|
|
863
863
|
constructor(inner) {
|
|
864
|
-
this
|
|
864
|
+
this._inner = inner;
|
|
865
865
|
}
|
|
866
866
|
/**
|
|
867
867
|
* Creates a new TextPattern that matches any text.
|
|
@@ -891,12 +891,12 @@ var TextPattern = class TextPattern {
|
|
|
891
891
|
* Gets the underlying dcbor-pattern TextPattern.
|
|
892
892
|
*/
|
|
893
893
|
get inner() {
|
|
894
|
-
return this
|
|
894
|
+
return this._inner;
|
|
895
895
|
}
|
|
896
896
|
pathsWithCaptures(haystack) {
|
|
897
|
-
const cbor
|
|
898
|
-
if (cbor
|
|
899
|
-
if (textPatternPaths(this
|
|
897
|
+
const cbor = haystack.asLeaf();
|
|
898
|
+
if (cbor !== void 0) {
|
|
899
|
+
if (textPatternPaths(this._inner, cbor).length > 0) return [[[haystack]], /* @__PURE__ */ new Map()];
|
|
900
900
|
}
|
|
901
901
|
return [[], /* @__PURE__ */ new Map()];
|
|
902
902
|
}
|
|
@@ -914,17 +914,17 @@ var TextPattern = class TextPattern {
|
|
|
914
914
|
return false;
|
|
915
915
|
}
|
|
916
916
|
toString() {
|
|
917
|
-
return textPatternDisplay(this
|
|
917
|
+
return textPatternDisplay(this._inner);
|
|
918
918
|
}
|
|
919
919
|
/**
|
|
920
920
|
* Equality comparison.
|
|
921
921
|
*/
|
|
922
922
|
equals(other) {
|
|
923
|
-
if (this
|
|
924
|
-
switch (this
|
|
923
|
+
if (this._inner.variant !== other._inner.variant) return false;
|
|
924
|
+
switch (this._inner.variant) {
|
|
925
925
|
case "Any": return true;
|
|
926
|
-
case "Value": return this
|
|
927
|
-
case "Regex": return this
|
|
926
|
+
case "Value": return this._inner.value === other._inner.value;
|
|
927
|
+
case "Regex": return this._inner.pattern.source === other._inner.pattern.source;
|
|
928
928
|
}
|
|
929
929
|
}
|
|
930
930
|
/**
|
|
@@ -932,17 +932,17 @@ var TextPattern = class TextPattern {
|
|
|
932
932
|
*/
|
|
933
933
|
hashCode() {
|
|
934
934
|
let hash = 0;
|
|
935
|
-
switch (this
|
|
935
|
+
switch (this._inner.variant) {
|
|
936
936
|
case "Any":
|
|
937
937
|
hash = 1;
|
|
938
938
|
break;
|
|
939
939
|
case "Value": {
|
|
940
|
-
const val = this
|
|
940
|
+
const val = this._inner.value;
|
|
941
941
|
for (let i = 0; i < val.length; i++) hash = hash * 31 + val.charCodeAt(i);
|
|
942
942
|
break;
|
|
943
943
|
}
|
|
944
944
|
case "Regex":
|
|
945
|
-
hash = 93 + this
|
|
945
|
+
hash = 93 + this._inner.pattern.source.length;
|
|
946
946
|
break;
|
|
947
947
|
}
|
|
948
948
|
return hash;
|
|
@@ -964,9 +964,9 @@ function registerByteStringPatternFactory(factory) {
|
|
|
964
964
|
* Corresponds to the Rust `ByteStringPattern` struct in byte_string_pattern.rs
|
|
965
965
|
*/
|
|
966
966
|
var ByteStringPattern = class ByteStringPattern {
|
|
967
|
-
|
|
967
|
+
_inner;
|
|
968
968
|
constructor(inner) {
|
|
969
|
-
this
|
|
969
|
+
this._inner = inner;
|
|
970
970
|
}
|
|
971
971
|
/**
|
|
972
972
|
* Creates a new ByteStringPattern that matches any byte string.
|
|
@@ -996,12 +996,12 @@ var ByteStringPattern = class ByteStringPattern {
|
|
|
996
996
|
* Gets the underlying dcbor-pattern ByteStringPattern.
|
|
997
997
|
*/
|
|
998
998
|
get inner() {
|
|
999
|
-
return this
|
|
999
|
+
return this._inner;
|
|
1000
1000
|
}
|
|
1001
1001
|
pathsWithCaptures(haystack) {
|
|
1002
|
-
const cbor
|
|
1003
|
-
if (cbor
|
|
1004
|
-
if (byteStringPatternPaths(this
|
|
1002
|
+
const cbor = haystack.asLeaf();
|
|
1003
|
+
if (cbor !== void 0) {
|
|
1004
|
+
if (byteStringPatternPaths(this._inner, cbor).length > 0) return [[[haystack]], /* @__PURE__ */ new Map()];
|
|
1005
1005
|
}
|
|
1006
1006
|
return [[], /* @__PURE__ */ new Map()];
|
|
1007
1007
|
}
|
|
@@ -1019,23 +1019,23 @@ var ByteStringPattern = class ByteStringPattern {
|
|
|
1019
1019
|
return false;
|
|
1020
1020
|
}
|
|
1021
1021
|
toString() {
|
|
1022
|
-
return byteStringPatternDisplay(this
|
|
1022
|
+
return byteStringPatternDisplay(this._inner);
|
|
1023
1023
|
}
|
|
1024
1024
|
/**
|
|
1025
1025
|
* Equality comparison.
|
|
1026
1026
|
*/
|
|
1027
1027
|
equals(other) {
|
|
1028
|
-
if (this
|
|
1029
|
-
switch (this
|
|
1028
|
+
if (this._inner.variant !== other._inner.variant) return false;
|
|
1029
|
+
switch (this._inner.variant) {
|
|
1030
1030
|
case "Any": return true;
|
|
1031
1031
|
case "Value": {
|
|
1032
|
-
const a = this
|
|
1033
|
-
const b = other
|
|
1032
|
+
const a = this._inner.value;
|
|
1033
|
+
const b = other._inner.value;
|
|
1034
1034
|
if (a.length !== b.length) return false;
|
|
1035
1035
|
for (let i = 0; i < a.length; i++) if (a[i] !== b[i]) return false;
|
|
1036
1036
|
return true;
|
|
1037
1037
|
}
|
|
1038
|
-
case "BinaryRegex": return this
|
|
1038
|
+
case "BinaryRegex": return this._inner.pattern.source === other._inner.pattern.source;
|
|
1039
1039
|
}
|
|
1040
1040
|
}
|
|
1041
1041
|
/**
|
|
@@ -1043,17 +1043,17 @@ var ByteStringPattern = class ByteStringPattern {
|
|
|
1043
1043
|
*/
|
|
1044
1044
|
hashCode() {
|
|
1045
1045
|
let hash = 0;
|
|
1046
|
-
switch (this
|
|
1046
|
+
switch (this._inner.variant) {
|
|
1047
1047
|
case "Any":
|
|
1048
1048
|
hash = 1;
|
|
1049
1049
|
break;
|
|
1050
1050
|
case "Value": {
|
|
1051
|
-
const val = this
|
|
1051
|
+
const val = this._inner.value;
|
|
1052
1052
|
for (const byte of val) hash = hash * 31 + byte;
|
|
1053
1053
|
break;
|
|
1054
1054
|
}
|
|
1055
1055
|
case "BinaryRegex":
|
|
1056
|
-
hash = 93 + this
|
|
1056
|
+
hash = 93 + this._inner.pattern.source.length;
|
|
1057
1057
|
break;
|
|
1058
1058
|
}
|
|
1059
1059
|
return hash;
|
|
@@ -1075,9 +1075,9 @@ function registerDatePatternFactory(factory) {
|
|
|
1075
1075
|
* Corresponds to the Rust `DatePattern` struct in date_pattern.rs
|
|
1076
1076
|
*/
|
|
1077
1077
|
var DatePattern = class DatePattern {
|
|
1078
|
-
|
|
1078
|
+
_inner;
|
|
1079
1079
|
constructor(inner) {
|
|
1080
|
-
this
|
|
1080
|
+
this._inner = inner;
|
|
1081
1081
|
}
|
|
1082
1082
|
/**
|
|
1083
1083
|
* Creates a new DatePattern that matches any date.
|
|
@@ -1088,8 +1088,8 @@ var DatePattern = class DatePattern {
|
|
|
1088
1088
|
/**
|
|
1089
1089
|
* Creates a new DatePattern that matches the specific date.
|
|
1090
1090
|
*/
|
|
1091
|
-
static value(date
|
|
1092
|
-
return new DatePattern(datePatternValue(date
|
|
1091
|
+
static value(date) {
|
|
1092
|
+
return new DatePattern(datePatternValue(date));
|
|
1093
1093
|
}
|
|
1094
1094
|
/**
|
|
1095
1095
|
* Creates a new DatePattern that matches dates within a range (inclusive).
|
|
@@ -1100,14 +1100,14 @@ var DatePattern = class DatePattern {
|
|
|
1100
1100
|
/**
|
|
1101
1101
|
* Creates a new DatePattern that matches dates on or after the specified date.
|
|
1102
1102
|
*/
|
|
1103
|
-
static earliest(date
|
|
1104
|
-
return new DatePattern(datePatternEarliest(date
|
|
1103
|
+
static earliest(date) {
|
|
1104
|
+
return new DatePattern(datePatternEarliest(date));
|
|
1105
1105
|
}
|
|
1106
1106
|
/**
|
|
1107
1107
|
* Creates a new DatePattern that matches dates on or before the specified date.
|
|
1108
1108
|
*/
|
|
1109
|
-
static latest(date
|
|
1110
|
-
return new DatePattern(datePatternLatest(date
|
|
1109
|
+
static latest(date) {
|
|
1110
|
+
return new DatePattern(datePatternLatest(date));
|
|
1111
1111
|
}
|
|
1112
1112
|
/**
|
|
1113
1113
|
* Creates a new DatePattern that matches dates by their ISO-8601 string representation.
|
|
@@ -1132,12 +1132,12 @@ var DatePattern = class DatePattern {
|
|
|
1132
1132
|
* Gets the underlying dcbor-pattern DatePattern.
|
|
1133
1133
|
*/
|
|
1134
1134
|
get inner() {
|
|
1135
|
-
return this
|
|
1135
|
+
return this._inner;
|
|
1136
1136
|
}
|
|
1137
1137
|
pathsWithCaptures(haystack) {
|
|
1138
|
-
const cbor
|
|
1139
|
-
if (cbor
|
|
1140
|
-
if (datePatternPaths(this
|
|
1138
|
+
const cbor = haystack.asLeaf();
|
|
1139
|
+
if (cbor !== void 0) {
|
|
1140
|
+
if (datePatternPaths(this._inner, cbor).length > 0) return [[[haystack]], /* @__PURE__ */ new Map()];
|
|
1141
1141
|
}
|
|
1142
1142
|
return [[], /* @__PURE__ */ new Map()];
|
|
1143
1143
|
}
|
|
@@ -1155,21 +1155,21 @@ var DatePattern = class DatePattern {
|
|
|
1155
1155
|
return false;
|
|
1156
1156
|
}
|
|
1157
1157
|
toString() {
|
|
1158
|
-
return datePatternDisplay(this
|
|
1158
|
+
return datePatternDisplay(this._inner);
|
|
1159
1159
|
}
|
|
1160
1160
|
/**
|
|
1161
1161
|
* Equality comparison.
|
|
1162
1162
|
*/
|
|
1163
1163
|
equals(other) {
|
|
1164
|
-
if (this
|
|
1165
|
-
return JSON.stringify(this
|
|
1164
|
+
if (this._inner.variant !== other._inner.variant) return false;
|
|
1165
|
+
return JSON.stringify(this._inner) === JSON.stringify(other._inner);
|
|
1166
1166
|
}
|
|
1167
1167
|
/**
|
|
1168
1168
|
* Hash code for use in Maps/Sets.
|
|
1169
1169
|
*/
|
|
1170
1170
|
hashCode() {
|
|
1171
1171
|
let hash = 0;
|
|
1172
|
-
const str = this
|
|
1172
|
+
const str = this._inner.variant;
|
|
1173
1173
|
for (let i = 0; i < str.length; i++) hash = hash * 31 + str.charCodeAt(i);
|
|
1174
1174
|
return hash;
|
|
1175
1175
|
}
|
|
@@ -1194,9 +1194,9 @@ function registerArrayPatternFactory(factory) {
|
|
|
1194
1194
|
* Corresponds to the Rust `ArrayPattern` struct in array_pattern.rs
|
|
1195
1195
|
*/
|
|
1196
1196
|
var ArrayPattern = class ArrayPattern {
|
|
1197
|
-
|
|
1197
|
+
_pattern;
|
|
1198
1198
|
constructor(pattern) {
|
|
1199
|
-
this
|
|
1199
|
+
this._pattern = pattern;
|
|
1200
1200
|
}
|
|
1201
1201
|
/**
|
|
1202
1202
|
* Creates a new ArrayPattern that matches any array.
|
|
@@ -1244,22 +1244,22 @@ var ArrayPattern = class ArrayPattern {
|
|
|
1244
1244
|
* Gets the pattern type.
|
|
1245
1245
|
*/
|
|
1246
1246
|
get pattern() {
|
|
1247
|
-
return this
|
|
1247
|
+
return this._pattern;
|
|
1248
1248
|
}
|
|
1249
1249
|
pathsWithCaptures(haystack) {
|
|
1250
|
-
const cbor
|
|
1251
|
-
if (cbor
|
|
1252
|
-
const array = asCborArray(cbor
|
|
1250
|
+
const cbor = haystack.asLeaf();
|
|
1251
|
+
if (cbor === void 0) return [[], /* @__PURE__ */ new Map()];
|
|
1252
|
+
const array = asCborArray(cbor);
|
|
1253
1253
|
if (array === void 0) return [[], /* @__PURE__ */ new Map()];
|
|
1254
|
-
switch (this
|
|
1254
|
+
switch (this._pattern.type) {
|
|
1255
1255
|
case "Any": return [[[haystack]], /* @__PURE__ */ new Map()];
|
|
1256
1256
|
case "Interval": {
|
|
1257
1257
|
const length = array.length;
|
|
1258
|
-
if (this
|
|
1258
|
+
if (this._pattern.interval.contains(length)) return [[[haystack]], /* @__PURE__ */ new Map()];
|
|
1259
1259
|
return [[], /* @__PURE__ */ new Map()];
|
|
1260
1260
|
}
|
|
1261
1261
|
case "DCBORPattern": {
|
|
1262
|
-
const { paths: dcborPaths, captures: dcborCaptures } = patternPathsWithCaptures$1(this
|
|
1262
|
+
const { paths: dcborPaths, captures: dcborCaptures } = patternPathsWithCaptures$1(this._pattern.pattern, cbor);
|
|
1263
1263
|
if (dcborPaths.length > 0) {
|
|
1264
1264
|
const envelopePaths = dcborPaths.map((dcborPath) => {
|
|
1265
1265
|
const envPath = [haystack];
|
|
@@ -1286,7 +1286,7 @@ var ArrayPattern = class ArrayPattern {
|
|
|
1286
1286
|
return [[], /* @__PURE__ */ new Map()];
|
|
1287
1287
|
}
|
|
1288
1288
|
case "WithPatterns":
|
|
1289
|
-
if (array.length === this
|
|
1289
|
+
if (array.length === this._pattern.patterns.length) return [[[haystack]], /* @__PURE__ */ new Map()];
|
|
1290
1290
|
return [[], /* @__PURE__ */ new Map()];
|
|
1291
1291
|
}
|
|
1292
1292
|
}
|
|
@@ -1304,26 +1304,26 @@ var ArrayPattern = class ArrayPattern {
|
|
|
1304
1304
|
return false;
|
|
1305
1305
|
}
|
|
1306
1306
|
toString() {
|
|
1307
|
-
switch (this
|
|
1307
|
+
switch (this._pattern.type) {
|
|
1308
1308
|
case "Any": return "[*]";
|
|
1309
|
-
case "Interval": return `[{${this
|
|
1310
|
-
case "DCBORPattern": return patternDisplay(this
|
|
1311
|
-
case "WithPatterns": return `[${this
|
|
1309
|
+
case "Interval": return `[{${this._pattern.interval.toString()}}]`;
|
|
1310
|
+
case "DCBORPattern": return patternDisplay(this._pattern.pattern);
|
|
1311
|
+
case "WithPatterns": return `[${this._pattern.patterns.map(String).join(", ")}]`;
|
|
1312
1312
|
}
|
|
1313
1313
|
}
|
|
1314
1314
|
/**
|
|
1315
1315
|
* Equality comparison.
|
|
1316
1316
|
*/
|
|
1317
1317
|
equals(other) {
|
|
1318
|
-
if (this
|
|
1319
|
-
switch (this
|
|
1318
|
+
if (this._pattern.type !== other._pattern.type) return false;
|
|
1319
|
+
switch (this._pattern.type) {
|
|
1320
1320
|
case "Any": return true;
|
|
1321
|
-
case "Interval": return this
|
|
1322
|
-
case "DCBORPattern": return patternDisplay(this
|
|
1321
|
+
case "Interval": return this._pattern.interval.equals(other._pattern.interval);
|
|
1322
|
+
case "DCBORPattern": return patternDisplay(this._pattern.pattern) === patternDisplay(other._pattern.pattern);
|
|
1323
1323
|
case "WithPatterns": {
|
|
1324
|
-
const otherPatterns = other
|
|
1325
|
-
if (this
|
|
1326
|
-
for (let i = 0; i < this
|
|
1324
|
+
const otherPatterns = other._pattern.patterns;
|
|
1325
|
+
if (this._pattern.patterns.length !== otherPatterns.length) return false;
|
|
1326
|
+
for (let i = 0; i < this._pattern.patterns.length; i++) if (this._pattern.patterns[i] !== otherPatterns[i]) return false;
|
|
1327
1327
|
return true;
|
|
1328
1328
|
}
|
|
1329
1329
|
}
|
|
@@ -1332,11 +1332,11 @@ var ArrayPattern = class ArrayPattern {
|
|
|
1332
1332
|
* Hash code for use in Maps/Sets.
|
|
1333
1333
|
*/
|
|
1334
1334
|
hashCode() {
|
|
1335
|
-
switch (this
|
|
1335
|
+
switch (this._pattern.type) {
|
|
1336
1336
|
case "Any": return 0;
|
|
1337
|
-
case "Interval": return this
|
|
1338
|
-
case "DCBORPattern": return simpleStringHash$3(patternDisplay(this
|
|
1339
|
-
case "WithPatterns": return this
|
|
1337
|
+
case "Interval": return this._pattern.interval.min() * 31 + (this._pattern.interval.max() ?? 0);
|
|
1338
|
+
case "DCBORPattern": return simpleStringHash$3(patternDisplay(this._pattern.pattern));
|
|
1339
|
+
case "WithPatterns": return this._pattern.patterns.length;
|
|
1340
1340
|
}
|
|
1341
1341
|
}
|
|
1342
1342
|
};
|
|
@@ -1365,9 +1365,9 @@ function registerMapPatternFactory(factory) {
|
|
|
1365
1365
|
* Corresponds to the Rust `MapPattern` struct in map_pattern.rs
|
|
1366
1366
|
*/
|
|
1367
1367
|
var MapPattern = class MapPattern {
|
|
1368
|
-
|
|
1368
|
+
_pattern;
|
|
1369
1369
|
constructor(pattern) {
|
|
1370
|
-
this
|
|
1370
|
+
this._pattern = pattern;
|
|
1371
1371
|
}
|
|
1372
1372
|
/**
|
|
1373
1373
|
* Creates a new MapPattern that matches any map.
|
|
@@ -1388,18 +1388,18 @@ var MapPattern = class MapPattern {
|
|
|
1388
1388
|
* Gets the pattern type.
|
|
1389
1389
|
*/
|
|
1390
1390
|
get pattern() {
|
|
1391
|
-
return this
|
|
1391
|
+
return this._pattern;
|
|
1392
1392
|
}
|
|
1393
1393
|
pathsWithCaptures(haystack) {
|
|
1394
|
-
const cbor
|
|
1395
|
-
if (cbor
|
|
1396
|
-
const map
|
|
1397
|
-
if (map
|
|
1398
|
-
switch (this
|
|
1394
|
+
const cbor = haystack.asLeaf();
|
|
1395
|
+
if (cbor === void 0) return [[], /* @__PURE__ */ new Map()];
|
|
1396
|
+
const map = asCborMap(cbor);
|
|
1397
|
+
if (map === void 0) return [[], /* @__PURE__ */ new Map()];
|
|
1398
|
+
switch (this._pattern.type) {
|
|
1399
1399
|
case "Any": return [[[haystack]], /* @__PURE__ */ new Map()];
|
|
1400
1400
|
case "Interval": {
|
|
1401
|
-
const size = map
|
|
1402
|
-
if (this
|
|
1401
|
+
const size = map.size;
|
|
1402
|
+
if (this._pattern.interval.contains(size)) return [[[haystack]], /* @__PURE__ */ new Map()];
|
|
1403
1403
|
return [[], /* @__PURE__ */ new Map()];
|
|
1404
1404
|
}
|
|
1405
1405
|
}
|
|
@@ -1418,28 +1418,28 @@ var MapPattern = class MapPattern {
|
|
|
1418
1418
|
return false;
|
|
1419
1419
|
}
|
|
1420
1420
|
toString() {
|
|
1421
|
-
switch (this
|
|
1421
|
+
switch (this._pattern.type) {
|
|
1422
1422
|
case "Any": return "{*}";
|
|
1423
|
-
case "Interval": return `{{${this
|
|
1423
|
+
case "Interval": return `{{${this._pattern.interval.toString()}}}`;
|
|
1424
1424
|
}
|
|
1425
1425
|
}
|
|
1426
1426
|
/**
|
|
1427
1427
|
* Equality comparison.
|
|
1428
1428
|
*/
|
|
1429
1429
|
equals(other) {
|
|
1430
|
-
if (this
|
|
1431
|
-
switch (this
|
|
1430
|
+
if (this._pattern.type !== other._pattern.type) return false;
|
|
1431
|
+
switch (this._pattern.type) {
|
|
1432
1432
|
case "Any": return true;
|
|
1433
|
-
case "Interval": return this
|
|
1433
|
+
case "Interval": return this._pattern.interval.equals(other._pattern.interval);
|
|
1434
1434
|
}
|
|
1435
1435
|
}
|
|
1436
1436
|
/**
|
|
1437
1437
|
* Hash code for use in Maps/Sets.
|
|
1438
1438
|
*/
|
|
1439
1439
|
hashCode() {
|
|
1440
|
-
switch (this
|
|
1440
|
+
switch (this._pattern.type) {
|
|
1441
1441
|
case "Any": return 0;
|
|
1442
|
-
case "Interval": return this
|
|
1442
|
+
case "Interval": return this._pattern.interval.min() * 31 + (this._pattern.interval.max() ?? 0);
|
|
1443
1443
|
}
|
|
1444
1444
|
}
|
|
1445
1445
|
};
|
|
@@ -1459,9 +1459,9 @@ function registerKnownValuePatternFactory(factory) {
|
|
|
1459
1459
|
* Corresponds to the Rust `KnownValuePattern` struct in known_value_pattern.rs
|
|
1460
1460
|
*/
|
|
1461
1461
|
var KnownValuePattern = class KnownValuePattern {
|
|
1462
|
-
|
|
1462
|
+
_inner;
|
|
1463
1463
|
constructor(inner) {
|
|
1464
|
-
this
|
|
1464
|
+
this._inner = inner;
|
|
1465
1465
|
}
|
|
1466
1466
|
/**
|
|
1467
1467
|
* Creates a new KnownValuePattern that matches any known value.
|
|
@@ -1497,17 +1497,17 @@ var KnownValuePattern = class KnownValuePattern {
|
|
|
1497
1497
|
* Gets the underlying dcbor-pattern KnownValuePattern.
|
|
1498
1498
|
*/
|
|
1499
1499
|
get inner() {
|
|
1500
|
-
return this
|
|
1500
|
+
return this._inner;
|
|
1501
1501
|
}
|
|
1502
1502
|
pathsWithCaptures(haystack) {
|
|
1503
1503
|
const envCase = haystack.case();
|
|
1504
1504
|
if (envCase.type === "knownValue") {
|
|
1505
1505
|
const knownValueCbor = envCase.value.taggedCbor();
|
|
1506
|
-
if (knownValuePatternMatches(this
|
|
1506
|
+
if (knownValuePatternMatches(this._inner, knownValueCbor)) return [[[haystack]], /* @__PURE__ */ new Map()];
|
|
1507
1507
|
}
|
|
1508
|
-
const leafCbor
|
|
1509
|
-
if (leafCbor
|
|
1510
|
-
if (knownValuePatternMatches(this
|
|
1508
|
+
const leafCbor = haystack.asLeaf();
|
|
1509
|
+
if (leafCbor !== void 0) {
|
|
1510
|
+
if (knownValuePatternMatches(this._inner, leafCbor)) return [[[haystack]], /* @__PURE__ */ new Map()];
|
|
1511
1511
|
}
|
|
1512
1512
|
return [[], /* @__PURE__ */ new Map()];
|
|
1513
1513
|
}
|
|
@@ -1525,29 +1525,29 @@ var KnownValuePattern = class KnownValuePattern {
|
|
|
1525
1525
|
return false;
|
|
1526
1526
|
}
|
|
1527
1527
|
toString() {
|
|
1528
|
-
return knownValuePatternDisplay(this
|
|
1528
|
+
return knownValuePatternDisplay(this._inner);
|
|
1529
1529
|
}
|
|
1530
1530
|
/**
|
|
1531
1531
|
* Equality comparison.
|
|
1532
1532
|
*/
|
|
1533
1533
|
equals(other) {
|
|
1534
|
-
if (this
|
|
1535
|
-
switch (this
|
|
1534
|
+
if (this._inner.variant !== other._inner.variant) return false;
|
|
1535
|
+
switch (this._inner.variant) {
|
|
1536
1536
|
case "Any": return true;
|
|
1537
|
-
case "Value": return this
|
|
1538
|
-
case "Named": return this
|
|
1539
|
-
case "Regex": return this
|
|
1537
|
+
case "Value": return this._inner.value.valueBigInt() === other._inner.value.valueBigInt();
|
|
1538
|
+
case "Named": return this._inner.name === other._inner.name;
|
|
1539
|
+
case "Regex": return this._inner.pattern.source === other._inner.pattern.source;
|
|
1540
1540
|
}
|
|
1541
1541
|
}
|
|
1542
1542
|
/**
|
|
1543
1543
|
* Hash code for use in Maps/Sets.
|
|
1544
1544
|
*/
|
|
1545
1545
|
hashCode() {
|
|
1546
|
-
switch (this
|
|
1546
|
+
switch (this._inner.variant) {
|
|
1547
1547
|
case "Any": return 0;
|
|
1548
|
-
case "Value": return Number(this
|
|
1549
|
-
case "Named": return simpleStringHash$2(this
|
|
1550
|
-
case "Regex": return simpleStringHash$2(this
|
|
1548
|
+
case "Value": return Number(this._inner.value.valueBigInt() & BigInt(4294967295));
|
|
1549
|
+
case "Named": return simpleStringHash$2(this._inner.name);
|
|
1550
|
+
case "Regex": return simpleStringHash$2(this._inner.pattern.source);
|
|
1551
1551
|
}
|
|
1552
1552
|
}
|
|
1553
1553
|
};
|
|
@@ -1586,9 +1586,9 @@ function registerTaggedPatternFactory(factory) {
|
|
|
1586
1586
|
* Corresponds to the Rust `TaggedPattern` struct in tagged_pattern.rs
|
|
1587
1587
|
*/
|
|
1588
1588
|
var TaggedPattern = class TaggedPattern {
|
|
1589
|
-
|
|
1589
|
+
_inner;
|
|
1590
1590
|
constructor(inner) {
|
|
1591
|
-
this
|
|
1591
|
+
this._inner = inner;
|
|
1592
1592
|
}
|
|
1593
1593
|
/**
|
|
1594
1594
|
* Creates a new TaggedPattern that matches any tagged value.
|
|
@@ -1624,12 +1624,12 @@ var TaggedPattern = class TaggedPattern {
|
|
|
1624
1624
|
* Gets the underlying dcbor-pattern TaggedPattern.
|
|
1625
1625
|
*/
|
|
1626
1626
|
get inner() {
|
|
1627
|
-
return this
|
|
1627
|
+
return this._inner;
|
|
1628
1628
|
}
|
|
1629
1629
|
pathsWithCaptures(haystack) {
|
|
1630
|
-
const cbor
|
|
1631
|
-
if (cbor
|
|
1632
|
-
const [dcborPaths, dcborCaptures] = taggedPatternPathsWithCaptures(this
|
|
1630
|
+
const cbor = haystack.subject().asLeaf();
|
|
1631
|
+
if (cbor !== void 0) {
|
|
1632
|
+
const [dcborPaths, dcborCaptures] = taggedPatternPathsWithCaptures(this._inner, cbor);
|
|
1633
1633
|
if (dcborPaths.length > 0) {
|
|
1634
1634
|
const envelopePaths = dcborPaths.map((dcborPath) => {
|
|
1635
1635
|
const envPath = [haystack];
|
|
@@ -1670,26 +1670,26 @@ var TaggedPattern = class TaggedPattern {
|
|
|
1670
1670
|
return false;
|
|
1671
1671
|
}
|
|
1672
1672
|
toString() {
|
|
1673
|
-
return taggedPatternDisplay(this
|
|
1673
|
+
return taggedPatternDisplay(this._inner, patternDisplay);
|
|
1674
1674
|
}
|
|
1675
1675
|
/**
|
|
1676
1676
|
* Equality comparison.
|
|
1677
1677
|
*/
|
|
1678
1678
|
equals(other) {
|
|
1679
|
-
if (this
|
|
1680
|
-
switch (this
|
|
1679
|
+
if (this._inner.variant !== other._inner.variant) return false;
|
|
1680
|
+
switch (this._inner.variant) {
|
|
1681
1681
|
case "Any": return true;
|
|
1682
1682
|
case "Tag": {
|
|
1683
|
-
const otherTag = other
|
|
1684
|
-
return this
|
|
1683
|
+
const otherTag = other._inner;
|
|
1684
|
+
return this._inner.tag.value === otherTag.tag.value && patternDisplay(this._inner.pattern) === patternDisplay(otherTag.pattern);
|
|
1685
1685
|
}
|
|
1686
1686
|
case "Name": {
|
|
1687
|
-
const otherName = other
|
|
1688
|
-
return this
|
|
1687
|
+
const otherName = other._inner;
|
|
1688
|
+
return this._inner.name === otherName.name && patternDisplay(this._inner.pattern) === patternDisplay(otherName.pattern);
|
|
1689
1689
|
}
|
|
1690
1690
|
case "Regex": {
|
|
1691
|
-
const otherRegex = other
|
|
1692
|
-
return this
|
|
1691
|
+
const otherRegex = other._inner;
|
|
1692
|
+
return this._inner.regex.source === otherRegex.regex.source && patternDisplay(this._inner.pattern) === patternDisplay(otherRegex.pattern);
|
|
1693
1693
|
}
|
|
1694
1694
|
}
|
|
1695
1695
|
}
|
|
@@ -1697,11 +1697,11 @@ var TaggedPattern = class TaggedPattern {
|
|
|
1697
1697
|
* Hash code for use in Maps/Sets.
|
|
1698
1698
|
*/
|
|
1699
1699
|
hashCode() {
|
|
1700
|
-
switch (this
|
|
1700
|
+
switch (this._inner.variant) {
|
|
1701
1701
|
case "Any": return 0;
|
|
1702
|
-
case "Tag": return Number(BigInt(this
|
|
1703
|
-
case "Name": return simpleStringHash$1(this
|
|
1704
|
-
case "Regex": return simpleStringHash$1(this
|
|
1702
|
+
case "Tag": return Number(BigInt(this._inner.tag.value) & BigInt(4294967295));
|
|
1703
|
+
case "Name": return simpleStringHash$1(this._inner.name);
|
|
1704
|
+
case "Regex": return simpleStringHash$1(this._inner.regex.source);
|
|
1705
1705
|
}
|
|
1706
1706
|
}
|
|
1707
1707
|
};
|
|
@@ -1737,9 +1737,9 @@ function registerCBORPatternFactory(factory) {
|
|
|
1737
1737
|
* Corresponds to the Rust `CBORPattern` enum in cbor_pattern.rs
|
|
1738
1738
|
*/
|
|
1739
1739
|
var CBORPattern = class CBORPattern {
|
|
1740
|
-
|
|
1740
|
+
_pattern;
|
|
1741
1741
|
constructor(pattern) {
|
|
1742
|
-
this
|
|
1742
|
+
this._pattern = pattern;
|
|
1743
1743
|
}
|
|
1744
1744
|
/**
|
|
1745
1745
|
* Creates a new CBORPattern that matches any CBOR value.
|
|
@@ -1778,15 +1778,15 @@ var CBORPattern = class CBORPattern {
|
|
|
1778
1778
|
* Gets the pattern type.
|
|
1779
1779
|
*/
|
|
1780
1780
|
get pattern() {
|
|
1781
|
-
return this
|
|
1781
|
+
return this._pattern;
|
|
1782
1782
|
}
|
|
1783
1783
|
/**
|
|
1784
1784
|
* Convert dcbor captures to envelope captures.
|
|
1785
1785
|
*/
|
|
1786
|
-
|
|
1786
|
+
_convertDcborCapturesToEnvelopeCaptures(dcborCaptures, baseEnvelope, baseCbor) {
|
|
1787
1787
|
const envelopeCaptures = /* @__PURE__ */ new Map();
|
|
1788
1788
|
for (const [captureName, dcborCapturePaths] of dcborCaptures) {
|
|
1789
|
-
const envelopeCapturePaths = dcborCapturePaths.map((dcborPath) => this
|
|
1789
|
+
const envelopeCapturePaths = dcborCapturePaths.map((dcborPath) => this._convertDcborPathToEnvelopePath(dcborPath, baseEnvelope, baseCbor));
|
|
1790
1790
|
envelopeCaptures.set(captureName, envelopeCapturePaths);
|
|
1791
1791
|
}
|
|
1792
1792
|
return envelopeCaptures;
|
|
@@ -1794,7 +1794,7 @@ var CBORPattern = class CBORPattern {
|
|
|
1794
1794
|
/**
|
|
1795
1795
|
* Convert a single dcbor path to an envelope path.
|
|
1796
1796
|
*/
|
|
1797
|
-
|
|
1797
|
+
_convertDcborPathToEnvelopePath(dcborPath, baseEnvelope, baseCbor) {
|
|
1798
1798
|
const envelopePath = [baseEnvelope];
|
|
1799
1799
|
const elementsToAdd = dcborPath.length > 0 && dcborPath[0]?.toDiagnostic() === baseCbor.toDiagnostic() ? dcborPath.slice(1) : dcborPath;
|
|
1800
1800
|
for (const cborElement of elementsToAdd) envelopePath.push(Envelope.newLeaf(cborElement));
|
|
@@ -1803,7 +1803,7 @@ var CBORPattern = class CBORPattern {
|
|
|
1803
1803
|
/**
|
|
1804
1804
|
* Collect capture names from a dcbor pattern.
|
|
1805
1805
|
*/
|
|
1806
|
-
|
|
1806
|
+
_collectDcborCaptureNames(dcborPattern, names) {
|
|
1807
1807
|
const patternStr = patternDisplay(dcborPattern);
|
|
1808
1808
|
let i = 0;
|
|
1809
1809
|
while (i < patternStr.length) if (patternStr[i] === "@") {
|
|
@@ -1820,13 +1820,13 @@ var CBORPattern = class CBORPattern {
|
|
|
1820
1820
|
const envCase = haystack.case();
|
|
1821
1821
|
if (envCase.type === "knownValue") {
|
|
1822
1822
|
const knownValueCbor = envCase.value.taggedCbor();
|
|
1823
|
-
switch (this
|
|
1823
|
+
switch (this._pattern.type) {
|
|
1824
1824
|
case "Any": return [[[haystack]], /* @__PURE__ */ new Map()];
|
|
1825
1825
|
case "Value":
|
|
1826
|
-
if (knownValueCbor.toDiagnostic() === this
|
|
1826
|
+
if (knownValueCbor.toDiagnostic() === this._pattern.cbor.toDiagnostic()) return [[[haystack]], /* @__PURE__ */ new Map()];
|
|
1827
1827
|
return [[], /* @__PURE__ */ new Map()];
|
|
1828
1828
|
case "Pattern": {
|
|
1829
|
-
const { paths: dcborPaths, captures: dcborCaptures } = patternPathsWithCaptures$1(this
|
|
1829
|
+
const { paths: dcborPaths, captures: dcborCaptures } = patternPathsWithCaptures$1(this._pattern.pattern, knownValueCbor);
|
|
1830
1830
|
if (dcborPaths.length > 0) {
|
|
1831
1831
|
const basePath = [haystack];
|
|
1832
1832
|
return [dcborPaths.map((dcborPath) => {
|
|
@@ -1836,29 +1836,29 @@ var CBORPattern = class CBORPattern {
|
|
|
1836
1836
|
if (elem !== void 0) extendedPath.push(Envelope.newLeaf(elem));
|
|
1837
1837
|
}
|
|
1838
1838
|
return extendedPath;
|
|
1839
|
-
}), this
|
|
1839
|
+
}), this._convertDcborCapturesToEnvelopeCaptures(dcborCaptures, haystack, knownValueCbor)];
|
|
1840
1840
|
}
|
|
1841
1841
|
return [[], /* @__PURE__ */ new Map()];
|
|
1842
1842
|
}
|
|
1843
1843
|
}
|
|
1844
1844
|
}
|
|
1845
|
-
const leafCbor
|
|
1846
|
-
if (leafCbor
|
|
1847
|
-
switch (this
|
|
1845
|
+
const leafCbor = haystack.asLeaf();
|
|
1846
|
+
if (leafCbor === void 0) return [[], /* @__PURE__ */ new Map()];
|
|
1847
|
+
switch (this._pattern.type) {
|
|
1848
1848
|
case "Any": return [[[haystack]], /* @__PURE__ */ new Map()];
|
|
1849
1849
|
case "Value":
|
|
1850
|
-
if (leafCbor
|
|
1850
|
+
if (leafCbor.toDiagnostic() === this._pattern.cbor.toDiagnostic()) return [[[haystack]], /* @__PURE__ */ new Map()];
|
|
1851
1851
|
return [[], /* @__PURE__ */ new Map()];
|
|
1852
1852
|
case "Pattern": {
|
|
1853
|
-
const { paths: dcborPaths, captures: dcborCaptures } = patternPathsWithCaptures$1(this
|
|
1853
|
+
const { paths: dcborPaths, captures: dcborCaptures } = patternPathsWithCaptures$1(this._pattern.pattern, leafCbor);
|
|
1854
1854
|
if (dcborPaths.length > 0) {
|
|
1855
1855
|
const basePath = [haystack];
|
|
1856
1856
|
return [dcborPaths.map((dcborPath) => {
|
|
1857
1857
|
const extendedPath = [...basePath];
|
|
1858
|
-
const elementsToAdd = dcborPath.length > 0 && dcborPath[0]?.toDiagnostic() === leafCbor
|
|
1858
|
+
const elementsToAdd = dcborPath.length > 0 && dcborPath[0]?.toDiagnostic() === leafCbor.toDiagnostic() ? dcborPath.slice(1) : dcborPath;
|
|
1859
1859
|
for (const cborElement of elementsToAdd) extendedPath.push(Envelope.newLeaf(cborElement));
|
|
1860
1860
|
return extendedPath;
|
|
1861
|
-
}), this
|
|
1861
|
+
}), this._convertDcborCapturesToEnvelopeCaptures(dcborCaptures, haystack, leafCbor)];
|
|
1862
1862
|
}
|
|
1863
1863
|
return [[], /* @__PURE__ */ new Map()];
|
|
1864
1864
|
}
|
|
@@ -1871,9 +1871,9 @@ var CBORPattern = class CBORPattern {
|
|
|
1871
1871
|
return this.paths(haystack).length > 0;
|
|
1872
1872
|
}
|
|
1873
1873
|
compile(code, literals, captures) {
|
|
1874
|
-
if (this
|
|
1874
|
+
if (this._pattern.type === "Pattern") {
|
|
1875
1875
|
const captureNames = [];
|
|
1876
|
-
this
|
|
1876
|
+
this._collectDcborCaptureNames(this._pattern.pattern, captureNames);
|
|
1877
1877
|
for (const name of captureNames) if (!captures.includes(name)) captures.push(name);
|
|
1878
1878
|
}
|
|
1879
1879
|
if (createLeafCBORPattern === void 0) throw new Error("CBORPattern factory not registered");
|
|
@@ -1883,31 +1883,31 @@ var CBORPattern = class CBORPattern {
|
|
|
1883
1883
|
return false;
|
|
1884
1884
|
}
|
|
1885
1885
|
toString() {
|
|
1886
|
-
switch (this
|
|
1886
|
+
switch (this._pattern.type) {
|
|
1887
1887
|
case "Any": return "cbor";
|
|
1888
|
-
case "Value": return `cbor(${this
|
|
1889
|
-
case "Pattern": return `cbor(/${patternDisplay(this
|
|
1888
|
+
case "Value": return `cbor(${this._pattern.cbor.toDiagnostic()})`;
|
|
1889
|
+
case "Pattern": return `cbor(/${patternDisplay(this._pattern.pattern)}/)`;
|
|
1890
1890
|
}
|
|
1891
1891
|
}
|
|
1892
1892
|
/**
|
|
1893
1893
|
* Equality comparison.
|
|
1894
1894
|
*/
|
|
1895
1895
|
equals(other) {
|
|
1896
|
-
if (this
|
|
1897
|
-
switch (this
|
|
1896
|
+
if (this._pattern.type !== other._pattern.type) return false;
|
|
1897
|
+
switch (this._pattern.type) {
|
|
1898
1898
|
case "Any": return true;
|
|
1899
|
-
case "Value": return this
|
|
1900
|
-
case "Pattern": return patternDisplay(this
|
|
1899
|
+
case "Value": return this._pattern.cbor.toDiagnostic() === other._pattern.cbor.toDiagnostic();
|
|
1900
|
+
case "Pattern": return patternDisplay(this._pattern.pattern) === patternDisplay(other._pattern.pattern);
|
|
1901
1901
|
}
|
|
1902
1902
|
}
|
|
1903
1903
|
/**
|
|
1904
1904
|
* Hash code for use in Maps/Sets.
|
|
1905
1905
|
*/
|
|
1906
1906
|
hashCode() {
|
|
1907
|
-
switch (this
|
|
1907
|
+
switch (this._pattern.type) {
|
|
1908
1908
|
case "Any": return 0;
|
|
1909
|
-
case "Value": return simpleStringHash(this
|
|
1910
|
-
case "Pattern": return simpleStringHash(patternDisplay(this
|
|
1909
|
+
case "Value": return simpleStringHash(this._pattern.cbor.toDiagnostic());
|
|
1910
|
+
case "Pattern": return simpleStringHash(patternDisplay(this._pattern.pattern));
|
|
1911
1911
|
}
|
|
1912
1912
|
}
|
|
1913
1913
|
};
|
|
@@ -2190,9 +2190,9 @@ function registerSubjectPatternFactory(factory) {
|
|
|
2190
2190
|
* Corresponds to the Rust `SubjectPattern` enum in subject_pattern.rs
|
|
2191
2191
|
*/
|
|
2192
2192
|
var SubjectPattern = class SubjectPattern {
|
|
2193
|
-
|
|
2193
|
+
_pattern;
|
|
2194
2194
|
constructor(pattern) {
|
|
2195
|
-
this
|
|
2195
|
+
this._pattern = pattern;
|
|
2196
2196
|
}
|
|
2197
2197
|
/**
|
|
2198
2198
|
* Creates a new SubjectPattern that matches any subject.
|
|
@@ -2213,23 +2213,23 @@ var SubjectPattern = class SubjectPattern {
|
|
|
2213
2213
|
* Gets the pattern type.
|
|
2214
2214
|
*/
|
|
2215
2215
|
get patternType() {
|
|
2216
|
-
return this
|
|
2216
|
+
return this._pattern;
|
|
2217
2217
|
}
|
|
2218
2218
|
/**
|
|
2219
2219
|
* Gets the inner pattern if this is a Pattern type, undefined otherwise.
|
|
2220
2220
|
*/
|
|
2221
2221
|
innerPattern() {
|
|
2222
|
-
return this
|
|
2222
|
+
return this._pattern.type === "Pattern" ? this._pattern.pattern : void 0;
|
|
2223
2223
|
}
|
|
2224
2224
|
pathsWithCaptures(haystack) {
|
|
2225
|
-
const subject
|
|
2225
|
+
const subject = haystack.subject();
|
|
2226
2226
|
let paths;
|
|
2227
|
-
switch (this
|
|
2227
|
+
switch (this._pattern.type) {
|
|
2228
2228
|
case "Any":
|
|
2229
|
-
paths = [[subject
|
|
2229
|
+
paths = [[subject]];
|
|
2230
2230
|
break;
|
|
2231
2231
|
case "Pattern":
|
|
2232
|
-
if (this
|
|
2232
|
+
if (this._pattern.pattern.matches(subject)) paths = [[subject]];
|
|
2233
2233
|
else paths = [];
|
|
2234
2234
|
break;
|
|
2235
2235
|
}
|
|
@@ -2242,14 +2242,14 @@ var SubjectPattern = class SubjectPattern {
|
|
|
2242
2242
|
return this.paths(haystack).length > 0;
|
|
2243
2243
|
}
|
|
2244
2244
|
compile(code, literals, captures) {
|
|
2245
|
-
switch (this
|
|
2245
|
+
switch (this._pattern.type) {
|
|
2246
2246
|
case "Any":
|
|
2247
2247
|
code.push({ type: "NavigateSubject" });
|
|
2248
2248
|
break;
|
|
2249
2249
|
case "Pattern":
|
|
2250
2250
|
code.push({ type: "NavigateSubject" });
|
|
2251
2251
|
code.push({ type: "ExtendTraversal" });
|
|
2252
|
-
this
|
|
2252
|
+
this._pattern.pattern.compile(code, literals, captures);
|
|
2253
2253
|
code.push({ type: "CombineTraversal" });
|
|
2254
2254
|
break;
|
|
2255
2255
|
}
|
|
@@ -2258,24 +2258,24 @@ var SubjectPattern = class SubjectPattern {
|
|
|
2258
2258
|
return false;
|
|
2259
2259
|
}
|
|
2260
2260
|
toString() {
|
|
2261
|
-
switch (this
|
|
2261
|
+
switch (this._pattern.type) {
|
|
2262
2262
|
case "Any": return "subj";
|
|
2263
|
-
case "Pattern": return `subj(${this
|
|
2263
|
+
case "Pattern": return `subj(${this._pattern.pattern.toString()})`;
|
|
2264
2264
|
}
|
|
2265
2265
|
}
|
|
2266
2266
|
/**
|
|
2267
2267
|
* Equality comparison.
|
|
2268
2268
|
*/
|
|
2269
2269
|
equals(other) {
|
|
2270
|
-
if (this
|
|
2271
|
-
if (this
|
|
2272
|
-
return this
|
|
2270
|
+
if (this._pattern.type !== other._pattern.type) return false;
|
|
2271
|
+
if (this._pattern.type === "Any") return true;
|
|
2272
|
+
return this._pattern.pattern === other._pattern.pattern;
|
|
2273
2273
|
}
|
|
2274
2274
|
/**
|
|
2275
2275
|
* Hash code for use in Maps/Sets.
|
|
2276
2276
|
*/
|
|
2277
2277
|
hashCode() {
|
|
2278
|
-
return this
|
|
2278
|
+
return this._pattern.type === "Any" ? 0 : 1;
|
|
2279
2279
|
}
|
|
2280
2280
|
};
|
|
2281
2281
|
|
|
@@ -2291,9 +2291,9 @@ function registerPredicatePatternFactory(factory) {
|
|
|
2291
2291
|
* Corresponds to the Rust `PredicatePattern` enum in predicate_pattern.rs
|
|
2292
2292
|
*/
|
|
2293
2293
|
var PredicatePattern = class PredicatePattern {
|
|
2294
|
-
|
|
2294
|
+
_pattern;
|
|
2295
2295
|
constructor(pattern) {
|
|
2296
|
-
this
|
|
2296
|
+
this._pattern = pattern;
|
|
2297
2297
|
}
|
|
2298
2298
|
/**
|
|
2299
2299
|
* Creates a new PredicatePattern that matches any predicate.
|
|
@@ -2314,24 +2314,24 @@ var PredicatePattern = class PredicatePattern {
|
|
|
2314
2314
|
* Gets the pattern type.
|
|
2315
2315
|
*/
|
|
2316
2316
|
get patternType() {
|
|
2317
|
-
return this
|
|
2317
|
+
return this._pattern;
|
|
2318
2318
|
}
|
|
2319
2319
|
/**
|
|
2320
2320
|
* Gets the inner pattern if this is a Pattern type, undefined otherwise.
|
|
2321
2321
|
*/
|
|
2322
2322
|
innerPattern() {
|
|
2323
|
-
return this
|
|
2323
|
+
return this._pattern.type === "Pattern" ? this._pattern.pattern : void 0;
|
|
2324
2324
|
}
|
|
2325
2325
|
pathsWithCaptures(haystack) {
|
|
2326
|
-
const predicate
|
|
2327
|
-
if (predicate
|
|
2326
|
+
const predicate = haystack.asPredicate?.();
|
|
2327
|
+
if (predicate === void 0) return [[], /* @__PURE__ */ new Map()];
|
|
2328
2328
|
let paths;
|
|
2329
|
-
switch (this
|
|
2329
|
+
switch (this._pattern.type) {
|
|
2330
2330
|
case "Any":
|
|
2331
|
-
paths = [[predicate
|
|
2331
|
+
paths = [[predicate]];
|
|
2332
2332
|
break;
|
|
2333
2333
|
case "Pattern":
|
|
2334
|
-
if (this
|
|
2334
|
+
if (this._pattern.pattern.matches(predicate)) paths = [[predicate]];
|
|
2335
2335
|
else paths = [];
|
|
2336
2336
|
break;
|
|
2337
2337
|
}
|
|
@@ -2356,24 +2356,24 @@ var PredicatePattern = class PredicatePattern {
|
|
|
2356
2356
|
return false;
|
|
2357
2357
|
}
|
|
2358
2358
|
toString() {
|
|
2359
|
-
switch (this
|
|
2359
|
+
switch (this._pattern.type) {
|
|
2360
2360
|
case "Any": return "pred";
|
|
2361
|
-
case "Pattern": return `pred(${this
|
|
2361
|
+
case "Pattern": return `pred(${this._pattern.pattern.toString()})`;
|
|
2362
2362
|
}
|
|
2363
2363
|
}
|
|
2364
2364
|
/**
|
|
2365
2365
|
* Equality comparison.
|
|
2366
2366
|
*/
|
|
2367
2367
|
equals(other) {
|
|
2368
|
-
if (this
|
|
2369
|
-
if (this
|
|
2370
|
-
return this
|
|
2368
|
+
if (this._pattern.type !== other._pattern.type) return false;
|
|
2369
|
+
if (this._pattern.type === "Any") return true;
|
|
2370
|
+
return this._pattern.pattern === other._pattern.pattern;
|
|
2371
2371
|
}
|
|
2372
2372
|
/**
|
|
2373
2373
|
* Hash code for use in Maps/Sets.
|
|
2374
2374
|
*/
|
|
2375
2375
|
hashCode() {
|
|
2376
|
-
return this
|
|
2376
|
+
return this._pattern.type === "Any" ? 0 : 1;
|
|
2377
2377
|
}
|
|
2378
2378
|
};
|
|
2379
2379
|
|
|
@@ -2389,9 +2389,9 @@ function registerObjectPatternFactory(factory) {
|
|
|
2389
2389
|
* Corresponds to the Rust `ObjectPattern` enum in object_pattern.rs
|
|
2390
2390
|
*/
|
|
2391
2391
|
var ObjectPattern = class ObjectPattern {
|
|
2392
|
-
|
|
2392
|
+
_pattern;
|
|
2393
2393
|
constructor(pattern) {
|
|
2394
|
-
this
|
|
2394
|
+
this._pattern = pattern;
|
|
2395
2395
|
}
|
|
2396
2396
|
/**
|
|
2397
2397
|
* Creates a new ObjectPattern that matches any object.
|
|
@@ -2412,24 +2412,24 @@ var ObjectPattern = class ObjectPattern {
|
|
|
2412
2412
|
* Gets the pattern type.
|
|
2413
2413
|
*/
|
|
2414
2414
|
get patternType() {
|
|
2415
|
-
return this
|
|
2415
|
+
return this._pattern;
|
|
2416
2416
|
}
|
|
2417
2417
|
/**
|
|
2418
2418
|
* Gets the inner pattern if this is a Pattern type, undefined otherwise.
|
|
2419
2419
|
*/
|
|
2420
2420
|
innerPattern() {
|
|
2421
|
-
return this
|
|
2421
|
+
return this._pattern.type === "Pattern" ? this._pattern.pattern : void 0;
|
|
2422
2422
|
}
|
|
2423
2423
|
pathsWithCaptures(haystack) {
|
|
2424
|
-
const object
|
|
2425
|
-
if (object
|
|
2424
|
+
const object = haystack.asObject?.();
|
|
2425
|
+
if (object === void 0) return [[], /* @__PURE__ */ new Map()];
|
|
2426
2426
|
let paths;
|
|
2427
|
-
switch (this
|
|
2427
|
+
switch (this._pattern.type) {
|
|
2428
2428
|
case "Any":
|
|
2429
|
-
paths = [[object
|
|
2429
|
+
paths = [[object]];
|
|
2430
2430
|
break;
|
|
2431
2431
|
case "Pattern":
|
|
2432
|
-
if (this
|
|
2432
|
+
if (this._pattern.pattern.matches(object)) paths = [[object]];
|
|
2433
2433
|
else paths = [];
|
|
2434
2434
|
break;
|
|
2435
2435
|
}
|
|
@@ -2454,24 +2454,24 @@ var ObjectPattern = class ObjectPattern {
|
|
|
2454
2454
|
return false;
|
|
2455
2455
|
}
|
|
2456
2456
|
toString() {
|
|
2457
|
-
switch (this
|
|
2457
|
+
switch (this._pattern.type) {
|
|
2458
2458
|
case "Any": return "obj";
|
|
2459
|
-
case "Pattern": return `obj(${this
|
|
2459
|
+
case "Pattern": return `obj(${this._pattern.pattern.toString()})`;
|
|
2460
2460
|
}
|
|
2461
2461
|
}
|
|
2462
2462
|
/**
|
|
2463
2463
|
* Equality comparison.
|
|
2464
2464
|
*/
|
|
2465
2465
|
equals(other) {
|
|
2466
|
-
if (this
|
|
2467
|
-
if (this
|
|
2468
|
-
return this
|
|
2466
|
+
if (this._pattern.type !== other._pattern.type) return false;
|
|
2467
|
+
if (this._pattern.type === "Any") return true;
|
|
2468
|
+
return this._pattern.pattern === other._pattern.pattern;
|
|
2469
2469
|
}
|
|
2470
2470
|
/**
|
|
2471
2471
|
* Hash code for use in Maps/Sets.
|
|
2472
2472
|
*/
|
|
2473
2473
|
hashCode() {
|
|
2474
|
-
return this
|
|
2474
|
+
return this._pattern.type === "Any" ? 0 : 1;
|
|
2475
2475
|
}
|
|
2476
2476
|
};
|
|
2477
2477
|
|
|
@@ -2487,9 +2487,9 @@ function registerAssertionsPatternFactory(factory) {
|
|
|
2487
2487
|
* Corresponds to the Rust `AssertionsPattern` enum in assertions_pattern.rs
|
|
2488
2488
|
*/
|
|
2489
2489
|
var AssertionsPattern = class AssertionsPattern {
|
|
2490
|
-
|
|
2490
|
+
_pattern;
|
|
2491
2491
|
constructor(pattern) {
|
|
2492
|
-
this
|
|
2492
|
+
this._pattern = pattern;
|
|
2493
2493
|
}
|
|
2494
2494
|
/**
|
|
2495
2495
|
* Creates a new AssertionsPattern that matches any assertion.
|
|
@@ -2532,49 +2532,49 @@ var AssertionsPattern = class AssertionsPattern {
|
|
|
2532
2532
|
* Gets the pattern type.
|
|
2533
2533
|
*/
|
|
2534
2534
|
get patternType() {
|
|
2535
|
-
return this
|
|
2535
|
+
return this._pattern;
|
|
2536
2536
|
}
|
|
2537
2537
|
/**
|
|
2538
2538
|
* Gets the predicate pattern if this has one, undefined otherwise.
|
|
2539
2539
|
*/
|
|
2540
2540
|
predicatePattern() {
|
|
2541
|
-
if (this
|
|
2542
|
-
if (this
|
|
2541
|
+
if (this._pattern.type === "WithPredicate") return this._pattern.pattern;
|
|
2542
|
+
if (this._pattern.type === "WithBoth") return this._pattern.predicatePattern;
|
|
2543
2543
|
}
|
|
2544
2544
|
/**
|
|
2545
2545
|
* Gets the object pattern if this has one, undefined otherwise.
|
|
2546
2546
|
*/
|
|
2547
2547
|
objectPattern() {
|
|
2548
|
-
if (this
|
|
2549
|
-
if (this
|
|
2548
|
+
if (this._pattern.type === "WithObject") return this._pattern.pattern;
|
|
2549
|
+
if (this._pattern.type === "WithBoth") return this._pattern.objectPattern;
|
|
2550
2550
|
}
|
|
2551
2551
|
pathsWithCaptures(haystack) {
|
|
2552
2552
|
const paths = [];
|
|
2553
|
-
for (const assertion of haystack.assertions()) switch (this
|
|
2553
|
+
for (const assertion of haystack.assertions()) switch (this._pattern.type) {
|
|
2554
2554
|
case "Any":
|
|
2555
2555
|
paths.push([assertion]);
|
|
2556
2556
|
break;
|
|
2557
2557
|
case "WithPredicate": {
|
|
2558
|
-
const predicate
|
|
2559
|
-
if (predicate
|
|
2560
|
-
if (this
|
|
2558
|
+
const predicate = assertion.asPredicate?.();
|
|
2559
|
+
if (predicate !== void 0) {
|
|
2560
|
+
if (this._pattern.pattern.matches(predicate)) paths.push([assertion]);
|
|
2561
2561
|
}
|
|
2562
2562
|
break;
|
|
2563
2563
|
}
|
|
2564
2564
|
case "WithObject": {
|
|
2565
|
-
const object
|
|
2566
|
-
if (object
|
|
2567
|
-
if (this
|
|
2565
|
+
const object = assertion.asObject?.();
|
|
2566
|
+
if (object !== void 0) {
|
|
2567
|
+
if (this._pattern.pattern.matches(object)) paths.push([assertion]);
|
|
2568
2568
|
}
|
|
2569
2569
|
break;
|
|
2570
2570
|
}
|
|
2571
2571
|
case "WithBoth": {
|
|
2572
|
-
const predicate
|
|
2573
|
-
const object
|
|
2574
|
-
if (predicate
|
|
2575
|
-
const predMatcher = this
|
|
2576
|
-
const objMatcher = this
|
|
2577
|
-
if (predMatcher.matches(predicate
|
|
2572
|
+
const predicate = assertion.asPredicate?.();
|
|
2573
|
+
const object = assertion.asObject?.();
|
|
2574
|
+
if (predicate !== void 0 && object !== void 0) {
|
|
2575
|
+
const predMatcher = this._pattern.predicatePattern;
|
|
2576
|
+
const objMatcher = this._pattern.objectPattern;
|
|
2577
|
+
if (predMatcher.matches(predicate) && objMatcher.matches(object)) paths.push([assertion]);
|
|
2578
2578
|
}
|
|
2579
2579
|
break;
|
|
2580
2580
|
}
|
|
@@ -2600,25 +2600,25 @@ var AssertionsPattern = class AssertionsPattern {
|
|
|
2600
2600
|
return false;
|
|
2601
2601
|
}
|
|
2602
2602
|
toString() {
|
|
2603
|
-
switch (this
|
|
2603
|
+
switch (this._pattern.type) {
|
|
2604
2604
|
case "Any": return "assert";
|
|
2605
|
-
case "WithPredicate": return `assertpred(${this
|
|
2606
|
-
case "WithObject": return `assertobj(${this
|
|
2607
|
-
case "WithBoth": return `assert(${this
|
|
2605
|
+
case "WithPredicate": return `assertpred(${this._pattern.pattern.toString()})`;
|
|
2606
|
+
case "WithObject": return `assertobj(${this._pattern.pattern.toString()})`;
|
|
2607
|
+
case "WithBoth": return `assert(${this._pattern.predicatePattern.toString()}, ${this._pattern.objectPattern.toString()})`;
|
|
2608
2608
|
}
|
|
2609
2609
|
}
|
|
2610
2610
|
/**
|
|
2611
2611
|
* Equality comparison.
|
|
2612
2612
|
*/
|
|
2613
2613
|
equals(other) {
|
|
2614
|
-
if (this
|
|
2615
|
-
switch (this
|
|
2614
|
+
if (this._pattern.type !== other._pattern.type) return false;
|
|
2615
|
+
switch (this._pattern.type) {
|
|
2616
2616
|
case "Any": return true;
|
|
2617
2617
|
case "WithPredicate":
|
|
2618
|
-
case "WithObject": return this
|
|
2618
|
+
case "WithObject": return this._pattern.pattern === other._pattern.pattern;
|
|
2619
2619
|
case "WithBoth": {
|
|
2620
|
-
const otherBoth = other
|
|
2621
|
-
return this
|
|
2620
|
+
const otherBoth = other._pattern;
|
|
2621
|
+
return this._pattern.predicatePattern === otherBoth.predicatePattern && this._pattern.objectPattern === otherBoth.objectPattern;
|
|
2622
2622
|
}
|
|
2623
2623
|
}
|
|
2624
2624
|
}
|
|
@@ -2626,7 +2626,7 @@ var AssertionsPattern = class AssertionsPattern {
|
|
|
2626
2626
|
* Hash code for use in Maps/Sets.
|
|
2627
2627
|
*/
|
|
2628
2628
|
hashCode() {
|
|
2629
|
-
switch (this
|
|
2629
|
+
switch (this._pattern.type) {
|
|
2630
2630
|
case "Any": return 0;
|
|
2631
2631
|
case "WithPredicate": return 1;
|
|
2632
2632
|
case "WithObject": return 2;
|
|
@@ -2655,9 +2655,9 @@ function bytesToLatin1(bytes) {
|
|
|
2655
2655
|
* Corresponds to the Rust `DigestPattern` enum in digest_pattern.rs
|
|
2656
2656
|
*/
|
|
2657
2657
|
var DigestPattern = class DigestPattern {
|
|
2658
|
-
|
|
2658
|
+
_pattern;
|
|
2659
2659
|
constructor(pattern) {
|
|
2660
|
-
this
|
|
2660
|
+
this._pattern = pattern;
|
|
2661
2661
|
}
|
|
2662
2662
|
/**
|
|
2663
2663
|
* Creates a new DigestPattern that matches any digest.
|
|
@@ -2668,10 +2668,10 @@ var DigestPattern = class DigestPattern {
|
|
|
2668
2668
|
/**
|
|
2669
2669
|
* Creates a new DigestPattern that matches the exact digest.
|
|
2670
2670
|
*/
|
|
2671
|
-
static digest(digest
|
|
2671
|
+
static digest(digest) {
|
|
2672
2672
|
return new DigestPattern({
|
|
2673
2673
|
type: "Digest",
|
|
2674
|
-
digest
|
|
2674
|
+
digest
|
|
2675
2675
|
});
|
|
2676
2676
|
}
|
|
2677
2677
|
/**
|
|
@@ -2696,21 +2696,21 @@ var DigestPattern = class DigestPattern {
|
|
|
2696
2696
|
* Gets the pattern type.
|
|
2697
2697
|
*/
|
|
2698
2698
|
get patternType() {
|
|
2699
|
-
return this
|
|
2699
|
+
return this._pattern;
|
|
2700
2700
|
}
|
|
2701
2701
|
pathsWithCaptures(haystack) {
|
|
2702
|
-
const digest
|
|
2703
|
-
const digestData = digest
|
|
2702
|
+
const digest = haystack.digest();
|
|
2703
|
+
const digestData = digest.data();
|
|
2704
2704
|
let isHit = false;
|
|
2705
|
-
switch (this
|
|
2705
|
+
switch (this._pattern.type) {
|
|
2706
2706
|
case "Any":
|
|
2707
2707
|
isHit = true;
|
|
2708
2708
|
break;
|
|
2709
2709
|
case "Digest":
|
|
2710
|
-
isHit = digest
|
|
2710
|
+
isHit = digest.equals(this._pattern.digest);
|
|
2711
2711
|
break;
|
|
2712
2712
|
case "Prefix": {
|
|
2713
|
-
const prefix = this
|
|
2713
|
+
const prefix = this._pattern.prefix;
|
|
2714
2714
|
if (digestData.length >= prefix.length) {
|
|
2715
2715
|
isHit = true;
|
|
2716
2716
|
for (let i = 0; i < prefix.length; i++) if (digestData[i] !== prefix[i]) {
|
|
@@ -2722,7 +2722,7 @@ var DigestPattern = class DigestPattern {
|
|
|
2722
2722
|
}
|
|
2723
2723
|
case "BinaryRegex": {
|
|
2724
2724
|
const latin1 = bytesToLatin1(digestData);
|
|
2725
|
-
isHit = this
|
|
2725
|
+
isHit = this._pattern.regex.test(latin1);
|
|
2726
2726
|
break;
|
|
2727
2727
|
}
|
|
2728
2728
|
}
|
|
@@ -2742,51 +2742,51 @@ var DigestPattern = class DigestPattern {
|
|
|
2742
2742
|
return false;
|
|
2743
2743
|
}
|
|
2744
2744
|
toString() {
|
|
2745
|
-
switch (this
|
|
2745
|
+
switch (this._pattern.type) {
|
|
2746
2746
|
case "Any": return "digest";
|
|
2747
|
-
case "Digest": return `digest(${this
|
|
2748
|
-
case "Prefix": return `digest(${bytesToHex(this
|
|
2749
|
-
case "BinaryRegex": return `digest(/${this
|
|
2747
|
+
case "Digest": return `digest(${this._pattern.digest.hex()})`;
|
|
2748
|
+
case "Prefix": return `digest(${bytesToHex(this._pattern.prefix)})`;
|
|
2749
|
+
case "BinaryRegex": return `digest(/${this._pattern.regex.source}/)`;
|
|
2750
2750
|
}
|
|
2751
2751
|
}
|
|
2752
2752
|
/**
|
|
2753
2753
|
* Equality comparison.
|
|
2754
2754
|
*/
|
|
2755
2755
|
equals(other) {
|
|
2756
|
-
if (this
|
|
2757
|
-
switch (this
|
|
2756
|
+
if (this._pattern.type !== other._pattern.type) return false;
|
|
2757
|
+
switch (this._pattern.type) {
|
|
2758
2758
|
case "Any": return true;
|
|
2759
|
-
case "Digest": return this
|
|
2759
|
+
case "Digest": return this._pattern.digest.equals(other._pattern.digest);
|
|
2760
2760
|
case "Prefix": {
|
|
2761
|
-
const thisPrefix = this
|
|
2762
|
-
const otherPrefix = other
|
|
2761
|
+
const thisPrefix = this._pattern.prefix;
|
|
2762
|
+
const otherPrefix = other._pattern.prefix;
|
|
2763
2763
|
if (thisPrefix.length !== otherPrefix.length) return false;
|
|
2764
2764
|
for (let i = 0; i < thisPrefix.length; i++) if (thisPrefix[i] !== otherPrefix[i]) return false;
|
|
2765
2765
|
return true;
|
|
2766
2766
|
}
|
|
2767
|
-
case "BinaryRegex": return this
|
|
2767
|
+
case "BinaryRegex": return this._pattern.regex.source === other._pattern.regex.source;
|
|
2768
2768
|
}
|
|
2769
2769
|
}
|
|
2770
2770
|
/**
|
|
2771
2771
|
* Hash code for use in Maps/Sets.
|
|
2772
2772
|
*/
|
|
2773
2773
|
hashCode() {
|
|
2774
|
-
switch (this
|
|
2774
|
+
switch (this._pattern.type) {
|
|
2775
2775
|
case "Any": return 0;
|
|
2776
2776
|
case "Digest": {
|
|
2777
|
-
const data = this
|
|
2777
|
+
const data = this._pattern.digest.data().slice(0, 8);
|
|
2778
2778
|
let hash = 0;
|
|
2779
2779
|
for (const byte of data) hash = hash * 31 + byte | 0;
|
|
2780
2780
|
return hash;
|
|
2781
2781
|
}
|
|
2782
2782
|
case "Prefix": {
|
|
2783
2783
|
let hash = 0;
|
|
2784
|
-
for (const byte of this
|
|
2784
|
+
for (const byte of this._pattern.prefix) hash = hash * 31 + byte | 0;
|
|
2785
2785
|
return hash;
|
|
2786
2786
|
}
|
|
2787
2787
|
case "BinaryRegex": {
|
|
2788
2788
|
let hash = 0;
|
|
2789
|
-
for (const char of this
|
|
2789
|
+
for (const char of this._pattern.regex.source) hash = hash * 31 + char.charCodeAt(0) | 0;
|
|
2790
2790
|
return hash;
|
|
2791
2791
|
}
|
|
2792
2792
|
}
|
|
@@ -2805,9 +2805,9 @@ function registerNodePatternFactory(factory) {
|
|
|
2805
2805
|
* Corresponds to the Rust `NodePattern` enum in node_pattern.rs
|
|
2806
2806
|
*/
|
|
2807
2807
|
var NodePattern = class NodePattern {
|
|
2808
|
-
|
|
2808
|
+
_pattern;
|
|
2809
2809
|
constructor(pattern) {
|
|
2810
|
-
this
|
|
2810
|
+
this._pattern = pattern;
|
|
2811
2811
|
}
|
|
2812
2812
|
/**
|
|
2813
2813
|
* Creates a new NodePattern that matches any node.
|
|
@@ -2846,13 +2846,13 @@ var NodePattern = class NodePattern {
|
|
|
2846
2846
|
* Gets the pattern type.
|
|
2847
2847
|
*/
|
|
2848
2848
|
get patternType() {
|
|
2849
|
-
return this
|
|
2849
|
+
return this._pattern;
|
|
2850
2850
|
}
|
|
2851
2851
|
/**
|
|
2852
2852
|
* Gets the subject pattern if this is a WithSubject type, undefined otherwise.
|
|
2853
2853
|
*/
|
|
2854
2854
|
subjectPattern() {
|
|
2855
|
-
return this
|
|
2855
|
+
return this._pattern.type === "WithSubject" ? this._pattern.subjectPattern : void 0;
|
|
2856
2856
|
}
|
|
2857
2857
|
/**
|
|
2858
2858
|
* Gets the assertion patterns (empty array if none).
|
|
@@ -2863,12 +2863,12 @@ var NodePattern = class NodePattern {
|
|
|
2863
2863
|
pathsWithCaptures(haystack) {
|
|
2864
2864
|
if (!haystack.isNode()) return [[], /* @__PURE__ */ new Map()];
|
|
2865
2865
|
let isHit = false;
|
|
2866
|
-
switch (this
|
|
2866
|
+
switch (this._pattern.type) {
|
|
2867
2867
|
case "Any":
|
|
2868
2868
|
isHit = true;
|
|
2869
2869
|
break;
|
|
2870
2870
|
case "AssertionsInterval":
|
|
2871
|
-
isHit = this
|
|
2871
|
+
isHit = this._pattern.interval.contains(haystack.assertions().length);
|
|
2872
2872
|
break;
|
|
2873
2873
|
case "WithSubject":
|
|
2874
2874
|
isHit = true;
|
|
@@ -2890,30 +2890,30 @@ var NodePattern = class NodePattern {
|
|
|
2890
2890
|
return false;
|
|
2891
2891
|
}
|
|
2892
2892
|
toString() {
|
|
2893
|
-
switch (this
|
|
2893
|
+
switch (this._pattern.type) {
|
|
2894
2894
|
case "Any": return "node";
|
|
2895
|
-
case "AssertionsInterval": return `node(${this
|
|
2896
|
-
case "WithSubject": return `node(${this
|
|
2895
|
+
case "AssertionsInterval": return `node(${this._pattern.interval.toString()})`;
|
|
2896
|
+
case "WithSubject": return `node(${this._pattern.subjectPattern.toString()})`;
|
|
2897
2897
|
}
|
|
2898
2898
|
}
|
|
2899
2899
|
/**
|
|
2900
2900
|
* Equality comparison.
|
|
2901
2901
|
*/
|
|
2902
2902
|
equals(other) {
|
|
2903
|
-
if (this
|
|
2904
|
-
switch (this
|
|
2903
|
+
if (this._pattern.type !== other._pattern.type) return false;
|
|
2904
|
+
switch (this._pattern.type) {
|
|
2905
2905
|
case "Any": return true;
|
|
2906
|
-
case "AssertionsInterval": return this
|
|
2907
|
-
case "WithSubject": return this
|
|
2906
|
+
case "AssertionsInterval": return this._pattern.interval.equals(other._pattern.interval);
|
|
2907
|
+
case "WithSubject": return this._pattern.subjectPattern === other._pattern.subjectPattern;
|
|
2908
2908
|
}
|
|
2909
2909
|
}
|
|
2910
2910
|
/**
|
|
2911
2911
|
* Hash code for use in Maps/Sets.
|
|
2912
2912
|
*/
|
|
2913
2913
|
hashCode() {
|
|
2914
|
-
switch (this
|
|
2914
|
+
switch (this._pattern.type) {
|
|
2915
2915
|
case "Any": return 0;
|
|
2916
|
-
case "AssertionsInterval": return this
|
|
2916
|
+
case "AssertionsInterval": return this._pattern.interval.min() * 31 + (this._pattern.interval.max() ?? 0);
|
|
2917
2917
|
case "WithSubject": return 1;
|
|
2918
2918
|
}
|
|
2919
2919
|
}
|
|
@@ -2931,9 +2931,9 @@ function registerObscuredPatternFactory(factory) {
|
|
|
2931
2931
|
* Corresponds to the Rust `ObscuredPattern` enum in obscured_pattern.rs
|
|
2932
2932
|
*/
|
|
2933
2933
|
var ObscuredPattern = class ObscuredPattern {
|
|
2934
|
-
|
|
2934
|
+
_pattern;
|
|
2935
2935
|
constructor(pattern) {
|
|
2936
|
-
this
|
|
2936
|
+
this._pattern = pattern;
|
|
2937
2937
|
}
|
|
2938
2938
|
/**
|
|
2939
2939
|
* Creates a new ObscuredPattern that matches any obscured element.
|
|
@@ -2963,11 +2963,11 @@ var ObscuredPattern = class ObscuredPattern {
|
|
|
2963
2963
|
* Gets the pattern type.
|
|
2964
2964
|
*/
|
|
2965
2965
|
get patternType() {
|
|
2966
|
-
return this
|
|
2966
|
+
return this._pattern;
|
|
2967
2967
|
}
|
|
2968
2968
|
pathsWithCaptures(haystack) {
|
|
2969
2969
|
let isHit = false;
|
|
2970
|
-
switch (this
|
|
2970
|
+
switch (this._pattern.type) {
|
|
2971
2971
|
case "Any":
|
|
2972
2972
|
isHit = haystack.isObscured();
|
|
2973
2973
|
break;
|
|
@@ -2997,7 +2997,7 @@ var ObscuredPattern = class ObscuredPattern {
|
|
|
2997
2997
|
return false;
|
|
2998
2998
|
}
|
|
2999
2999
|
toString() {
|
|
3000
|
-
switch (this
|
|
3000
|
+
switch (this._pattern.type) {
|
|
3001
3001
|
case "Any": return "obscured";
|
|
3002
3002
|
case "Elided": return "elided";
|
|
3003
3003
|
case "Encrypted": return "encrypted";
|
|
@@ -3008,13 +3008,13 @@ var ObscuredPattern = class ObscuredPattern {
|
|
|
3008
3008
|
* Equality comparison.
|
|
3009
3009
|
*/
|
|
3010
3010
|
equals(other) {
|
|
3011
|
-
return this
|
|
3011
|
+
return this._pattern.type === other._pattern.type;
|
|
3012
3012
|
}
|
|
3013
3013
|
/**
|
|
3014
3014
|
* Hash code for use in Maps/Sets.
|
|
3015
3015
|
*/
|
|
3016
3016
|
hashCode() {
|
|
3017
|
-
switch (this
|
|
3017
|
+
switch (this._pattern.type) {
|
|
3018
3018
|
case "Any": return 0;
|
|
3019
3019
|
case "Elided": return 1;
|
|
3020
3020
|
case "Encrypted": return 2;
|
|
@@ -3035,9 +3035,9 @@ function registerWrappedPatternFactory(factory) {
|
|
|
3035
3035
|
* Corresponds to the Rust `WrappedPattern` enum in wrapped_pattern.rs
|
|
3036
3036
|
*/
|
|
3037
3037
|
var WrappedPattern = class WrappedPattern {
|
|
3038
|
-
|
|
3038
|
+
_pattern;
|
|
3039
3039
|
constructor(pattern) {
|
|
3040
|
-
this
|
|
3040
|
+
this._pattern = pattern;
|
|
3041
3041
|
}
|
|
3042
3042
|
/**
|
|
3043
3043
|
* Creates a new WrappedPattern that matches any wrapped envelope without descending.
|
|
@@ -3066,25 +3066,25 @@ var WrappedPattern = class WrappedPattern {
|
|
|
3066
3066
|
* Gets the pattern type.
|
|
3067
3067
|
*/
|
|
3068
3068
|
get patternType() {
|
|
3069
|
-
return this
|
|
3069
|
+
return this._pattern;
|
|
3070
3070
|
}
|
|
3071
3071
|
/**
|
|
3072
3072
|
* Gets the inner pattern if this is an Unwrap type, undefined otherwise.
|
|
3073
3073
|
*/
|
|
3074
3074
|
innerPattern() {
|
|
3075
|
-
return this
|
|
3075
|
+
return this._pattern.type === "Unwrap" ? this._pattern.pattern : void 0;
|
|
3076
3076
|
}
|
|
3077
3077
|
pathsWithCaptures(haystack) {
|
|
3078
|
-
const subject
|
|
3079
|
-
if (!subject
|
|
3078
|
+
const subject = haystack.subject();
|
|
3079
|
+
if (!subject.isWrapped()) return [[], /* @__PURE__ */ new Map()];
|
|
3080
3080
|
let paths;
|
|
3081
|
-
switch (this
|
|
3081
|
+
switch (this._pattern.type) {
|
|
3082
3082
|
case "Any":
|
|
3083
3083
|
paths = [[haystack]];
|
|
3084
3084
|
break;
|
|
3085
3085
|
case "Unwrap": {
|
|
3086
|
-
const unwrapped = subject
|
|
3087
|
-
if (unwrapped !== void 0) paths = this
|
|
3086
|
+
const unwrapped = subject.tryUnwrap?.();
|
|
3087
|
+
if (unwrapped !== void 0) paths = this._pattern.pattern.paths(unwrapped).map((path) => {
|
|
3088
3088
|
return [haystack, ...path];
|
|
3089
3089
|
});
|
|
3090
3090
|
else paths = [];
|
|
@@ -3101,7 +3101,7 @@ var WrappedPattern = class WrappedPattern {
|
|
|
3101
3101
|
}
|
|
3102
3102
|
compile(code, literals, captures) {
|
|
3103
3103
|
if (createStructureWrappedPattern === void 0) throw new Error("WrappedPattern factory not registered");
|
|
3104
|
-
switch (this
|
|
3104
|
+
switch (this._pattern.type) {
|
|
3105
3105
|
case "Any": {
|
|
3106
3106
|
const idx = literals.length;
|
|
3107
3107
|
literals.push(createStructureWrappedPattern(this));
|
|
@@ -3122,7 +3122,7 @@ var WrappedPattern = class WrappedPattern {
|
|
|
3122
3122
|
type: "PushAxis",
|
|
3123
3123
|
axis: "Wrapped"
|
|
3124
3124
|
});
|
|
3125
|
-
this
|
|
3125
|
+
this._pattern.pattern.compile(code, literals, captures);
|
|
3126
3126
|
break;
|
|
3127
3127
|
}
|
|
3128
3128
|
}
|
|
@@ -3131,10 +3131,10 @@ var WrappedPattern = class WrappedPattern {
|
|
|
3131
3131
|
return false;
|
|
3132
3132
|
}
|
|
3133
3133
|
toString() {
|
|
3134
|
-
switch (this
|
|
3134
|
+
switch (this._pattern.type) {
|
|
3135
3135
|
case "Any": return "wrapped";
|
|
3136
3136
|
case "Unwrap": {
|
|
3137
|
-
const patternStr = this
|
|
3137
|
+
const patternStr = this._pattern.pattern.toString();
|
|
3138
3138
|
if (patternStr === "*") return "unwrap";
|
|
3139
3139
|
return `unwrap(${patternStr})`;
|
|
3140
3140
|
}
|
|
@@ -3144,15 +3144,15 @@ var WrappedPattern = class WrappedPattern {
|
|
|
3144
3144
|
* Equality comparison.
|
|
3145
3145
|
*/
|
|
3146
3146
|
equals(other) {
|
|
3147
|
-
if (this
|
|
3148
|
-
if (this
|
|
3149
|
-
return this
|
|
3147
|
+
if (this._pattern.type !== other._pattern.type) return false;
|
|
3148
|
+
if (this._pattern.type === "Any") return true;
|
|
3149
|
+
return this._pattern.pattern === other._pattern.pattern;
|
|
3150
3150
|
}
|
|
3151
3151
|
/**
|
|
3152
3152
|
* Hash code for use in Maps/Sets.
|
|
3153
3153
|
*/
|
|
3154
3154
|
hashCode() {
|
|
3155
|
-
return this
|
|
3155
|
+
return this._pattern.type === "Any" ? 0 : 1;
|
|
3156
3156
|
}
|
|
3157
3157
|
};
|
|
3158
3158
|
|
|
@@ -3392,9 +3392,9 @@ function registerAndPatternFactory(factory) {
|
|
|
3392
3392
|
* Corresponds to the Rust `AndPattern` struct in and_pattern.rs
|
|
3393
3393
|
*/
|
|
3394
3394
|
var AndPattern = class AndPattern {
|
|
3395
|
-
|
|
3395
|
+
_patterns;
|
|
3396
3396
|
constructor(patterns) {
|
|
3397
|
-
this
|
|
3397
|
+
this._patterns = patterns;
|
|
3398
3398
|
}
|
|
3399
3399
|
/**
|
|
3400
3400
|
* Creates a new AndPattern with the given patterns.
|
|
@@ -3406,10 +3406,10 @@ var AndPattern = class AndPattern {
|
|
|
3406
3406
|
* Gets the patterns.
|
|
3407
3407
|
*/
|
|
3408
3408
|
patterns() {
|
|
3409
|
-
return this
|
|
3409
|
+
return this._patterns;
|
|
3410
3410
|
}
|
|
3411
3411
|
pathsWithCaptures(haystack) {
|
|
3412
|
-
return [this
|
|
3412
|
+
return [this._patterns.every((pattern) => matchPattern(pattern, haystack)) ? [[haystack]] : [], /* @__PURE__ */ new Map()];
|
|
3413
3413
|
}
|
|
3414
3414
|
paths(haystack) {
|
|
3415
3415
|
return this.pathsWithCaptures(haystack)[0];
|
|
@@ -3418,27 +3418,27 @@ var AndPattern = class AndPattern {
|
|
|
3418
3418
|
return this.paths(haystack).length > 0;
|
|
3419
3419
|
}
|
|
3420
3420
|
compile(code, literals, captures) {
|
|
3421
|
-
for (const pattern of this
|
|
3421
|
+
for (const pattern of this._patterns) pattern.compile(code, literals, captures);
|
|
3422
3422
|
}
|
|
3423
3423
|
isComplex() {
|
|
3424
|
-
return this
|
|
3424
|
+
return this._patterns.length > 1 || this._patterns.some((p) => p.isComplex());
|
|
3425
3425
|
}
|
|
3426
3426
|
toString() {
|
|
3427
|
-
return this
|
|
3427
|
+
return this._patterns.map((p) => p.toString()).join(" & ");
|
|
3428
3428
|
}
|
|
3429
3429
|
/**
|
|
3430
3430
|
* Equality comparison.
|
|
3431
3431
|
*/
|
|
3432
3432
|
equals(other) {
|
|
3433
|
-
if (this
|
|
3434
|
-
for (let i = 0; i < this
|
|
3433
|
+
if (this._patterns.length !== other._patterns.length) return false;
|
|
3434
|
+
for (let i = 0; i < this._patterns.length; i++) if (this._patterns[i] !== other._patterns[i]) return false;
|
|
3435
3435
|
return true;
|
|
3436
3436
|
}
|
|
3437
3437
|
/**
|
|
3438
3438
|
* Hash code for use in Maps/Sets.
|
|
3439
3439
|
*/
|
|
3440
3440
|
hashCode() {
|
|
3441
|
-
return this
|
|
3441
|
+
return this._patterns.length;
|
|
3442
3442
|
}
|
|
3443
3443
|
};
|
|
3444
3444
|
|
|
@@ -3454,9 +3454,9 @@ function registerOrPatternFactory(factory) {
|
|
|
3454
3454
|
* Corresponds to the Rust `OrPattern` struct in or_pattern.rs
|
|
3455
3455
|
*/
|
|
3456
3456
|
var OrPattern = class OrPattern {
|
|
3457
|
-
|
|
3457
|
+
_patterns;
|
|
3458
3458
|
constructor(patterns) {
|
|
3459
|
-
this
|
|
3459
|
+
this._patterns = patterns;
|
|
3460
3460
|
}
|
|
3461
3461
|
/**
|
|
3462
3462
|
* Creates a new OrPattern with the given patterns.
|
|
@@ -3468,10 +3468,10 @@ var OrPattern = class OrPattern {
|
|
|
3468
3468
|
* Gets the patterns.
|
|
3469
3469
|
*/
|
|
3470
3470
|
patterns() {
|
|
3471
|
-
return this
|
|
3471
|
+
return this._patterns;
|
|
3472
3472
|
}
|
|
3473
3473
|
pathsWithCaptures(haystack) {
|
|
3474
|
-
return [this
|
|
3474
|
+
return [this._patterns.some((pattern) => matchPattern(pattern, haystack)) ? [[haystack]] : [], /* @__PURE__ */ new Map()];
|
|
3475
3475
|
}
|
|
3476
3476
|
paths(haystack) {
|
|
3477
3477
|
return this.pathsWithCaptures(haystack)[0];
|
|
@@ -3480,9 +3480,9 @@ var OrPattern = class OrPattern {
|
|
|
3480
3480
|
return this.paths(haystack).length > 0;
|
|
3481
3481
|
}
|
|
3482
3482
|
compile(code, literals, captures) {
|
|
3483
|
-
if (this
|
|
3483
|
+
if (this._patterns.length === 0) return;
|
|
3484
3484
|
const splits = [];
|
|
3485
|
-
for (let i = 0; i < this
|
|
3485
|
+
for (let i = 0; i < this._patterns.length - 1; i++) {
|
|
3486
3486
|
splits.push(code.length);
|
|
3487
3487
|
code.push({
|
|
3488
3488
|
type: "Split",
|
|
@@ -3491,16 +3491,16 @@ var OrPattern = class OrPattern {
|
|
|
3491
3491
|
});
|
|
3492
3492
|
}
|
|
3493
3493
|
const jumps = [];
|
|
3494
|
-
for (let i = 0; i < this
|
|
3494
|
+
for (let i = 0; i < this._patterns.length; i++) {
|
|
3495
3495
|
const patternStart = code.length;
|
|
3496
|
-
this
|
|
3496
|
+
this._patterns[i].compile(code, literals, captures);
|
|
3497
3497
|
const jumpPastAll = code.length;
|
|
3498
3498
|
code.push({
|
|
3499
3499
|
type: "Jump",
|
|
3500
3500
|
address: 0
|
|
3501
3501
|
});
|
|
3502
3502
|
jumps.push(jumpPastAll);
|
|
3503
|
-
if (i < this
|
|
3503
|
+
if (i < this._patterns.length - 1) {
|
|
3504
3504
|
const nextPattern = code.length;
|
|
3505
3505
|
code[splits[i]] = {
|
|
3506
3506
|
type: "Split",
|
|
@@ -3516,24 +3516,24 @@ var OrPattern = class OrPattern {
|
|
|
3516
3516
|
};
|
|
3517
3517
|
}
|
|
3518
3518
|
isComplex() {
|
|
3519
|
-
return this
|
|
3519
|
+
return this._patterns.length > 1 || this._patterns.some((p) => p.isComplex());
|
|
3520
3520
|
}
|
|
3521
3521
|
toString() {
|
|
3522
|
-
return this
|
|
3522
|
+
return this._patterns.map((p) => p.toString()).join(" | ");
|
|
3523
3523
|
}
|
|
3524
3524
|
/**
|
|
3525
3525
|
* Equality comparison.
|
|
3526
3526
|
*/
|
|
3527
3527
|
equals(other) {
|
|
3528
|
-
if (this
|
|
3529
|
-
for (let i = 0; i < this
|
|
3528
|
+
if (this._patterns.length !== other._patterns.length) return false;
|
|
3529
|
+
for (let i = 0; i < this._patterns.length; i++) if (this._patterns[i] !== other._patterns[i]) return false;
|
|
3530
3530
|
return true;
|
|
3531
3531
|
}
|
|
3532
3532
|
/**
|
|
3533
3533
|
* Hash code for use in Maps/Sets.
|
|
3534
3534
|
*/
|
|
3535
3535
|
hashCode() {
|
|
3536
|
-
return this
|
|
3536
|
+
return this._patterns.length;
|
|
3537
3537
|
}
|
|
3538
3538
|
};
|
|
3539
3539
|
|
|
@@ -3549,9 +3549,9 @@ function registerNotPatternFactory(factory) {
|
|
|
3549
3549
|
* Corresponds to the Rust `NotPattern` struct in not_pattern.rs
|
|
3550
3550
|
*/
|
|
3551
3551
|
var NotPattern = class NotPattern {
|
|
3552
|
-
|
|
3552
|
+
_pattern;
|
|
3553
3553
|
constructor(pattern) {
|
|
3554
|
-
this
|
|
3554
|
+
this._pattern = pattern;
|
|
3555
3555
|
}
|
|
3556
3556
|
/**
|
|
3557
3557
|
* Creates a new NotPattern with the given pattern.
|
|
@@ -3563,10 +3563,10 @@ var NotPattern = class NotPattern {
|
|
|
3563
3563
|
* Gets the inner pattern.
|
|
3564
3564
|
*/
|
|
3565
3565
|
pattern() {
|
|
3566
|
-
return this
|
|
3566
|
+
return this._pattern;
|
|
3567
3567
|
}
|
|
3568
3568
|
pathsWithCaptures(haystack) {
|
|
3569
|
-
return [!matchPattern(this
|
|
3569
|
+
return [!matchPattern(this._pattern, haystack) ? [[haystack]] : [], /* @__PURE__ */ new Map()];
|
|
3570
3570
|
}
|
|
3571
3571
|
paths(haystack) {
|
|
3572
3572
|
return this.pathsWithCaptures(haystack)[0];
|
|
@@ -3576,7 +3576,7 @@ var NotPattern = class NotPattern {
|
|
|
3576
3576
|
}
|
|
3577
3577
|
compile(code, literals, _captures) {
|
|
3578
3578
|
const idx = literals.length;
|
|
3579
|
-
literals.push(this
|
|
3579
|
+
literals.push(this._pattern);
|
|
3580
3580
|
code.push({
|
|
3581
3581
|
type: "NotMatch",
|
|
3582
3582
|
patternIndex: idx
|
|
@@ -3586,13 +3586,13 @@ var NotPattern = class NotPattern {
|
|
|
3586
3586
|
return false;
|
|
3587
3587
|
}
|
|
3588
3588
|
toString() {
|
|
3589
|
-
return `!${this
|
|
3589
|
+
return `!${this._pattern.toString()}`;
|
|
3590
3590
|
}
|
|
3591
3591
|
/**
|
|
3592
3592
|
* Equality comparison.
|
|
3593
3593
|
*/
|
|
3594
3594
|
equals(other) {
|
|
3595
|
-
return this
|
|
3595
|
+
return this._pattern === other._pattern;
|
|
3596
3596
|
}
|
|
3597
3597
|
/**
|
|
3598
3598
|
* Hash code for use in Maps/Sets.
|
|
@@ -3614,11 +3614,11 @@ function registerCapturePatternFactory(factory) {
|
|
|
3614
3614
|
* Corresponds to the Rust `CapturePattern` struct in capture_pattern.rs
|
|
3615
3615
|
*/
|
|
3616
3616
|
var CapturePattern = class CapturePattern {
|
|
3617
|
-
|
|
3618
|
-
|
|
3617
|
+
_name;
|
|
3618
|
+
_pattern;
|
|
3619
3619
|
constructor(name, pattern) {
|
|
3620
|
-
this
|
|
3621
|
-
this
|
|
3620
|
+
this._name = name;
|
|
3621
|
+
this._pattern = pattern;
|
|
3622
3622
|
}
|
|
3623
3623
|
/**
|
|
3624
3624
|
* Creates a new CapturePattern with the given name and pattern.
|
|
@@ -3630,19 +3630,19 @@ var CapturePattern = class CapturePattern {
|
|
|
3630
3630
|
* Gets the name of the capture.
|
|
3631
3631
|
*/
|
|
3632
3632
|
name() {
|
|
3633
|
-
return this
|
|
3633
|
+
return this._name;
|
|
3634
3634
|
}
|
|
3635
3635
|
/**
|
|
3636
3636
|
* Gets the inner pattern.
|
|
3637
3637
|
*/
|
|
3638
3638
|
pattern() {
|
|
3639
|
-
return this
|
|
3639
|
+
return this._pattern;
|
|
3640
3640
|
}
|
|
3641
3641
|
pathsWithCaptures(haystack) {
|
|
3642
|
-
const [paths, caps] = this
|
|
3642
|
+
const [paths, caps] = this._pattern.pathsWithCaptures(haystack);
|
|
3643
3643
|
if (paths.length > 0) {
|
|
3644
|
-
const existing = caps.get(this
|
|
3645
|
-
caps.set(this
|
|
3644
|
+
const existing = caps.get(this._name) ?? [];
|
|
3645
|
+
caps.set(this._name, [...existing, ...paths]);
|
|
3646
3646
|
}
|
|
3647
3647
|
return [paths, caps];
|
|
3648
3648
|
}
|
|
@@ -3654,12 +3654,12 @@ var CapturePattern = class CapturePattern {
|
|
|
3654
3654
|
}
|
|
3655
3655
|
compile(code, literals, captures) {
|
|
3656
3656
|
const id = captures.length;
|
|
3657
|
-
captures.push(this
|
|
3657
|
+
captures.push(this._name);
|
|
3658
3658
|
code.push({
|
|
3659
3659
|
type: "CaptureStart",
|
|
3660
3660
|
captureIndex: id
|
|
3661
3661
|
});
|
|
3662
|
-
this
|
|
3662
|
+
this._pattern.compile(code, literals, captures);
|
|
3663
3663
|
code.push({
|
|
3664
3664
|
type: "CaptureEnd",
|
|
3665
3665
|
captureIndex: id
|
|
@@ -3669,20 +3669,20 @@ var CapturePattern = class CapturePattern {
|
|
|
3669
3669
|
return false;
|
|
3670
3670
|
}
|
|
3671
3671
|
toString() {
|
|
3672
|
-
return `@${this
|
|
3672
|
+
return `@${this._name}(${this._pattern.toString()})`;
|
|
3673
3673
|
}
|
|
3674
3674
|
/**
|
|
3675
3675
|
* Equality comparison.
|
|
3676
3676
|
*/
|
|
3677
3677
|
equals(other) {
|
|
3678
|
-
return this
|
|
3678
|
+
return this._name === other._name && this._pattern === other._pattern;
|
|
3679
3679
|
}
|
|
3680
3680
|
/**
|
|
3681
3681
|
* Hash code for use in Maps/Sets.
|
|
3682
3682
|
*/
|
|
3683
3683
|
hashCode() {
|
|
3684
3684
|
let hash = 0;
|
|
3685
|
-
for (const char of this
|
|
3685
|
+
for (const char of this._name) hash = hash * 31 + char.charCodeAt(0) | 0;
|
|
3686
3686
|
return hash;
|
|
3687
3687
|
}
|
|
3688
3688
|
};
|
|
@@ -3699,9 +3699,9 @@ function registerSearchPatternFactory(factory) {
|
|
|
3699
3699
|
* Corresponds to the Rust `SearchPattern` struct in search_pattern.rs
|
|
3700
3700
|
*/
|
|
3701
3701
|
var SearchPattern = class SearchPattern {
|
|
3702
|
-
|
|
3702
|
+
_pattern;
|
|
3703
3703
|
constructor(pattern) {
|
|
3704
|
-
this
|
|
3704
|
+
this._pattern = pattern;
|
|
3705
3705
|
}
|
|
3706
3706
|
/**
|
|
3707
3707
|
* Creates a new SearchPattern with the given pattern.
|
|
@@ -3713,15 +3713,15 @@ var SearchPattern = class SearchPattern {
|
|
|
3713
3713
|
* Gets the inner pattern.
|
|
3714
3714
|
*/
|
|
3715
3715
|
pattern() {
|
|
3716
|
-
return this
|
|
3716
|
+
return this._pattern;
|
|
3717
3717
|
}
|
|
3718
3718
|
pathsWithCaptures(haystack) {
|
|
3719
3719
|
const resultPaths = [];
|
|
3720
|
-
const matcher = this
|
|
3721
|
-
this
|
|
3720
|
+
const matcher = this._pattern;
|
|
3721
|
+
this._walkEnvelope(haystack, [], (currentEnvelope, pathToCurrent) => {
|
|
3722
3722
|
const newPath = [...pathToCurrent, currentEnvelope];
|
|
3723
|
-
const patternPaths
|
|
3724
|
-
for (const patternPath of patternPaths
|
|
3723
|
+
const patternPaths = matcher.paths(currentEnvelope);
|
|
3724
|
+
for (const patternPath of patternPaths) {
|
|
3725
3725
|
const fullPath = [...newPath];
|
|
3726
3726
|
if (patternPath.length > 1) fullPath.push(...patternPath.slice(1));
|
|
3727
3727
|
else if (patternPath.length === 1) {
|
|
@@ -3745,27 +3745,27 @@ var SearchPattern = class SearchPattern {
|
|
|
3745
3745
|
/**
|
|
3746
3746
|
* Walk the envelope tree recursively.
|
|
3747
3747
|
*/
|
|
3748
|
-
|
|
3748
|
+
_walkEnvelope(envelope, pathToCurrent, visitor) {
|
|
3749
3749
|
visitor(envelope, pathToCurrent);
|
|
3750
|
-
const subject
|
|
3750
|
+
const subject = envelope.subject();
|
|
3751
3751
|
const newPath = [...pathToCurrent, envelope];
|
|
3752
|
-
if (!subject
|
|
3752
|
+
if (!subject.digest().equals(envelope.digest())) this._walkEnvelope(subject, newPath, visitor);
|
|
3753
3753
|
for (const assertion of envelope.assertions()) {
|
|
3754
|
-
this
|
|
3755
|
-
const predicate
|
|
3756
|
-
if (predicate
|
|
3754
|
+
this._walkEnvelope(assertion, newPath, visitor);
|
|
3755
|
+
const predicate = assertion.asPredicate?.();
|
|
3756
|
+
if (predicate !== void 0) {
|
|
3757
3757
|
const assertionPath = [...newPath, assertion];
|
|
3758
|
-
this
|
|
3758
|
+
this._walkEnvelope(predicate, assertionPath, visitor);
|
|
3759
3759
|
}
|
|
3760
|
-
const object
|
|
3761
|
-
if (object
|
|
3760
|
+
const object = assertion.asObject?.();
|
|
3761
|
+
if (object !== void 0) {
|
|
3762
3762
|
const assertionPath = [...newPath, assertion];
|
|
3763
|
-
this
|
|
3763
|
+
this._walkEnvelope(object, assertionPath, visitor);
|
|
3764
3764
|
}
|
|
3765
3765
|
}
|
|
3766
|
-
if (subject
|
|
3767
|
-
const unwrapped = subject
|
|
3768
|
-
if (unwrapped !== void 0) this
|
|
3766
|
+
if (subject.isWrapped()) {
|
|
3767
|
+
const unwrapped = subject.tryUnwrap?.();
|
|
3768
|
+
if (unwrapped !== void 0) this._walkEnvelope(unwrapped, newPath, visitor);
|
|
3769
3769
|
}
|
|
3770
3770
|
}
|
|
3771
3771
|
paths(haystack) {
|
|
@@ -3776,9 +3776,9 @@ var SearchPattern = class SearchPattern {
|
|
|
3776
3776
|
}
|
|
3777
3777
|
compile(code, literals, captures) {
|
|
3778
3778
|
const idx = literals.length;
|
|
3779
|
-
literals.push(this
|
|
3779
|
+
literals.push(this._pattern);
|
|
3780
3780
|
const innerNames = [];
|
|
3781
|
-
collectCaptureNames$1(this
|
|
3781
|
+
collectCaptureNames$1(this._pattern, innerNames);
|
|
3782
3782
|
const captureMap = [];
|
|
3783
3783
|
for (const name of innerNames) {
|
|
3784
3784
|
let pos = captures.indexOf(name);
|
|
@@ -3798,13 +3798,13 @@ var SearchPattern = class SearchPattern {
|
|
|
3798
3798
|
return true;
|
|
3799
3799
|
}
|
|
3800
3800
|
toString() {
|
|
3801
|
-
return `search(${this
|
|
3801
|
+
return `search(${this._pattern.toString()})`;
|
|
3802
3802
|
}
|
|
3803
3803
|
/**
|
|
3804
3804
|
* Equality comparison.
|
|
3805
3805
|
*/
|
|
3806
3806
|
equals(other) {
|
|
3807
|
-
return this
|
|
3807
|
+
return this._pattern === other._pattern;
|
|
3808
3808
|
}
|
|
3809
3809
|
/**
|
|
3810
3810
|
* Hash code for use in Maps/Sets.
|
|
@@ -3833,11 +3833,11 @@ function registerTraversePatternFactory(factory) {
|
|
|
3833
3833
|
* Corresponds to the Rust `TraversePattern` struct in traverse_pattern.rs
|
|
3834
3834
|
*/
|
|
3835
3835
|
var TraversePattern = class TraversePattern {
|
|
3836
|
-
|
|
3837
|
-
|
|
3836
|
+
_first;
|
|
3837
|
+
_rest;
|
|
3838
3838
|
constructor(first, rest) {
|
|
3839
|
-
this
|
|
3840
|
-
this
|
|
3839
|
+
this._first = first;
|
|
3840
|
+
this._rest = rest;
|
|
3841
3841
|
}
|
|
3842
3842
|
/**
|
|
3843
3843
|
* Creates a new TraversePattern with the given patterns.
|
|
@@ -3852,18 +3852,18 @@ var TraversePattern = class TraversePattern {
|
|
|
3852
3852
|
* Gets all patterns in this traversal.
|
|
3853
3853
|
*/
|
|
3854
3854
|
patterns() {
|
|
3855
|
-
const result = [this
|
|
3856
|
-
if (this
|
|
3855
|
+
const result = [this._first];
|
|
3856
|
+
if (this._rest !== void 0) result.push(...this._rest.patterns());
|
|
3857
3857
|
return result;
|
|
3858
3858
|
}
|
|
3859
3859
|
pathsWithCaptures(haystack) {
|
|
3860
|
-
const headPaths = this
|
|
3861
|
-
if (this
|
|
3860
|
+
const headPaths = this._first.paths(haystack);
|
|
3861
|
+
if (this._rest === void 0) return [headPaths, /* @__PURE__ */ new Map()];
|
|
3862
3862
|
const result = [];
|
|
3863
3863
|
for (const path of headPaths) {
|
|
3864
3864
|
const lastEnv = path[path.length - 1];
|
|
3865
3865
|
if (lastEnv !== void 0) {
|
|
3866
|
-
const tailPaths = this
|
|
3866
|
+
const tailPaths = this._rest.paths(lastEnv);
|
|
3867
3867
|
for (const tailPath of tailPaths) {
|
|
3868
3868
|
const combined = [...path, ...tailPath];
|
|
3869
3869
|
result.push(combined);
|
|
@@ -3879,15 +3879,15 @@ var TraversePattern = class TraversePattern {
|
|
|
3879
3879
|
return this.paths(haystack).length > 0;
|
|
3880
3880
|
}
|
|
3881
3881
|
compile(code, literals, captures) {
|
|
3882
|
-
this
|
|
3883
|
-
if (this
|
|
3882
|
+
this._first.compile(code, literals, captures);
|
|
3883
|
+
if (this._rest !== void 0) {
|
|
3884
3884
|
code.push({ type: "ExtendTraversal" });
|
|
3885
|
-
this
|
|
3885
|
+
this._rest.compile(code, literals, captures);
|
|
3886
3886
|
code.push({ type: "CombineTraversal" });
|
|
3887
3887
|
}
|
|
3888
3888
|
}
|
|
3889
3889
|
isComplex() {
|
|
3890
|
-
return this
|
|
3890
|
+
return this._first.isComplex() || this._rest !== void 0;
|
|
3891
3891
|
}
|
|
3892
3892
|
toString() {
|
|
3893
3893
|
return this.patterns().map((p) => p.toString()).join(" -> ");
|
|
@@ -3922,11 +3922,11 @@ function registerGroupPatternFactory(factory) {
|
|
|
3922
3922
|
* Corresponds to the Rust `GroupPattern` struct in repeat_pattern.rs
|
|
3923
3923
|
*/
|
|
3924
3924
|
var GroupPattern = class GroupPattern {
|
|
3925
|
-
|
|
3926
|
-
|
|
3925
|
+
_pattern;
|
|
3926
|
+
_quantifier;
|
|
3927
3927
|
constructor(pattern, quantifier) {
|
|
3928
|
-
this
|
|
3929
|
-
this
|
|
3928
|
+
this._pattern = pattern;
|
|
3929
|
+
this._quantifier = quantifier;
|
|
3930
3930
|
}
|
|
3931
3931
|
/**
|
|
3932
3932
|
* Creates a new GroupPattern with the specified sub-pattern and quantifier.
|
|
@@ -3944,13 +3944,13 @@ var GroupPattern = class GroupPattern {
|
|
|
3944
3944
|
* Gets the sub-pattern of this group pattern.
|
|
3945
3945
|
*/
|
|
3946
3946
|
pattern() {
|
|
3947
|
-
return this
|
|
3947
|
+
return this._pattern;
|
|
3948
3948
|
}
|
|
3949
3949
|
/**
|
|
3950
3950
|
* Gets the quantifier of this group pattern.
|
|
3951
3951
|
*/
|
|
3952
3952
|
quantifier() {
|
|
3953
|
-
return this
|
|
3953
|
+
return this._quantifier;
|
|
3954
3954
|
}
|
|
3955
3955
|
pathsWithCaptures(_haystack) {
|
|
3956
3956
|
throw new Error("GroupPattern does not support pathsWithCaptures directly; use compile instead");
|
|
@@ -3959,35 +3959,35 @@ var GroupPattern = class GroupPattern {
|
|
|
3959
3959
|
return this.pathsWithCaptures(haystack)[0];
|
|
3960
3960
|
}
|
|
3961
3961
|
matches(haystack) {
|
|
3962
|
-
return this
|
|
3962
|
+
return this._pattern.matches(haystack);
|
|
3963
3963
|
}
|
|
3964
3964
|
compile(code, literals, _captures) {
|
|
3965
3965
|
const idx = literals.length;
|
|
3966
|
-
literals.push(this
|
|
3966
|
+
literals.push(this._pattern);
|
|
3967
3967
|
code.push({
|
|
3968
3968
|
type: "Repeat",
|
|
3969
3969
|
patternIndex: idx,
|
|
3970
|
-
quantifier: this
|
|
3970
|
+
quantifier: this._quantifier
|
|
3971
3971
|
});
|
|
3972
3972
|
}
|
|
3973
3973
|
isComplex() {
|
|
3974
3974
|
return true;
|
|
3975
3975
|
}
|
|
3976
3976
|
toString() {
|
|
3977
|
-
const formattedRange = this
|
|
3978
|
-
return `(${this
|
|
3977
|
+
const formattedRange = this._quantifier.toString();
|
|
3978
|
+
return `(${this._pattern.toString()})${formattedRange}`;
|
|
3979
3979
|
}
|
|
3980
3980
|
/**
|
|
3981
3981
|
* Equality comparison.
|
|
3982
3982
|
*/
|
|
3983
3983
|
equals(other) {
|
|
3984
|
-
return this
|
|
3984
|
+
return this._pattern === other._pattern && this._quantifier.equals(other._quantifier);
|
|
3985
3985
|
}
|
|
3986
3986
|
/**
|
|
3987
3987
|
* Hash code for use in Maps/Sets.
|
|
3988
3988
|
*/
|
|
3989
3989
|
hashCode() {
|
|
3990
|
-
return this
|
|
3990
|
+
return this._quantifier.min() * 31 + (this._quantifier.max() ?? 0);
|
|
3991
3991
|
}
|
|
3992
3992
|
};
|
|
3993
3993
|
|
|
@@ -4214,9 +4214,9 @@ function axisChildren(axis, env) {
|
|
|
4214
4214
|
return [];
|
|
4215
4215
|
case "Wrapped":
|
|
4216
4216
|
if (envCase.type === "node") {
|
|
4217
|
-
const subject
|
|
4218
|
-
if (subject
|
|
4219
|
-
const unwrapped = subject
|
|
4217
|
+
const subject = envCase.subject;
|
|
4218
|
+
if (subject.isWrapped()) {
|
|
4219
|
+
const unwrapped = subject.unwrap();
|
|
4220
4220
|
if (unwrapped !== void 0) return [[unwrapped, "Content"]];
|
|
4221
4221
|
}
|
|
4222
4222
|
} else if (envCase.type === "wrapped") return [[envCase.envelope, "Content"]];
|
|
@@ -4512,9 +4512,9 @@ function runThread(prog, start, out) {
|
|
|
4512
4512
|
}
|
|
4513
4513
|
case "NavigateSubject":
|
|
4514
4514
|
if (th.env.isNode()) {
|
|
4515
|
-
const subject
|
|
4516
|
-
th.env = subject
|
|
4517
|
-
th.path.push(subject
|
|
4515
|
+
const subject = th.env.subject();
|
|
4516
|
+
th.env = subject;
|
|
4517
|
+
th.path.push(subject);
|
|
4518
4518
|
}
|
|
4519
4519
|
th.pc += 1;
|
|
4520
4520
|
continue;
|
|
@@ -4588,12 +4588,12 @@ function run(prog, root) {
|
|
|
4588
4588
|
seen: /* @__PURE__ */ new Set()
|
|
4589
4589
|
}, out);
|
|
4590
4590
|
return out.map(([path, caps]) => {
|
|
4591
|
-
const map
|
|
4591
|
+
const map = /* @__PURE__ */ new Map();
|
|
4592
4592
|
for (let i = 0; i < caps.length; i++) {
|
|
4593
4593
|
const paths = caps[i];
|
|
4594
|
-
if (paths.length > 0) map
|
|
4594
|
+
if (paths.length > 0) map.set(prog.captureNames[i], paths);
|
|
4595
4595
|
}
|
|
4596
|
-
return [path, map
|
|
4596
|
+
return [path, map];
|
|
4597
4597
|
});
|
|
4598
4598
|
}
|
|
4599
4599
|
/**
|
|
@@ -4965,10 +4965,10 @@ function convertMetaPatternToEnvelopePattern(metaPattern, originalPattern) {
|
|
|
4965
4965
|
/**
|
|
4966
4966
|
* Creates a Leaf pattern.
|
|
4967
4967
|
*/
|
|
4968
|
-
function patternLeaf(leaf
|
|
4968
|
+
function patternLeaf(leaf) {
|
|
4969
4969
|
return {
|
|
4970
4970
|
type: "Leaf",
|
|
4971
|
-
pattern: leaf
|
|
4971
|
+
pattern: leaf
|
|
4972
4972
|
};
|
|
4973
4973
|
}
|
|
4974
4974
|
/**
|
|
@@ -5501,26 +5501,26 @@ function isHexDigit(ch) {
|
|
|
5501
5501
|
* Lexer for Gordian Envelope pattern syntax.
|
|
5502
5502
|
*/
|
|
5503
5503
|
var Lexer = class {
|
|
5504
|
-
|
|
5505
|
-
|
|
5506
|
-
|
|
5507
|
-
|
|
5504
|
+
_source;
|
|
5505
|
+
_position = 0;
|
|
5506
|
+
_tokenStart = 0;
|
|
5507
|
+
_peekedToken = void 0;
|
|
5508
5508
|
constructor(source) {
|
|
5509
|
-
this
|
|
5509
|
+
this._source = source;
|
|
5510
5510
|
}
|
|
5511
5511
|
/**
|
|
5512
5512
|
* Gets the current position in the source.
|
|
5513
5513
|
*/
|
|
5514
5514
|
get position() {
|
|
5515
|
-
return this
|
|
5515
|
+
return this._position;
|
|
5516
5516
|
}
|
|
5517
5517
|
/**
|
|
5518
5518
|
* Peeks at the next token without consuming it.
|
|
5519
5519
|
*/
|
|
5520
5520
|
peekToken() {
|
|
5521
|
-
if (this
|
|
5521
|
+
if (this._peekedToken !== void 0) return this._peekedToken;
|
|
5522
5522
|
const result = this.next();
|
|
5523
|
-
this
|
|
5523
|
+
this._peekedToken = result;
|
|
5524
5524
|
return result;
|
|
5525
5525
|
}
|
|
5526
5526
|
/**
|
|
@@ -5528,50 +5528,50 @@ var Lexer = class {
|
|
|
5528
5528
|
*/
|
|
5529
5529
|
span() {
|
|
5530
5530
|
return {
|
|
5531
|
-
start: this
|
|
5532
|
-
end: this
|
|
5531
|
+
start: this._tokenStart,
|
|
5532
|
+
end: this._position
|
|
5533
5533
|
};
|
|
5534
5534
|
}
|
|
5535
5535
|
/**
|
|
5536
5536
|
* Gets the remaining source string.
|
|
5537
5537
|
*/
|
|
5538
5538
|
remainder() {
|
|
5539
|
-
return this
|
|
5539
|
+
return this._source.slice(this._position);
|
|
5540
5540
|
}
|
|
5541
5541
|
/**
|
|
5542
5542
|
* Peeks at the current character without consuming it.
|
|
5543
5543
|
*/
|
|
5544
5544
|
peek() {
|
|
5545
|
-
if (this
|
|
5546
|
-
return this
|
|
5545
|
+
if (this._position >= this._source.length) return;
|
|
5546
|
+
return this._source[this._position];
|
|
5547
5547
|
}
|
|
5548
5548
|
/**
|
|
5549
5549
|
* Peeks at the next character without consuming current.
|
|
5550
5550
|
*/
|
|
5551
5551
|
peekNext() {
|
|
5552
|
-
if (this
|
|
5553
|
-
return this
|
|
5552
|
+
if (this._position + 1 >= this._source.length) return;
|
|
5553
|
+
return this._source[this._position + 1];
|
|
5554
5554
|
}
|
|
5555
5555
|
/**
|
|
5556
5556
|
* Advances the position by n characters.
|
|
5557
5557
|
*/
|
|
5558
5558
|
bump(n = 1) {
|
|
5559
|
-
this
|
|
5559
|
+
this._position = Math.min(this._position + n, this._source.length);
|
|
5560
5560
|
}
|
|
5561
5561
|
/**
|
|
5562
5562
|
* Skips whitespace.
|
|
5563
5563
|
*/
|
|
5564
|
-
|
|
5565
|
-
while (this
|
|
5566
|
-
const ch = this
|
|
5567
|
-
if (ch !== void 0 && isWhitespace(ch)) this
|
|
5564
|
+
_skipWhitespace() {
|
|
5565
|
+
while (this._position < this._source.length) {
|
|
5566
|
+
const ch = this._source[this._position];
|
|
5567
|
+
if (ch !== void 0 && isWhitespace(ch)) this._position++;
|
|
5568
5568
|
else break;
|
|
5569
5569
|
}
|
|
5570
5570
|
}
|
|
5571
5571
|
/**
|
|
5572
5572
|
* Parses a string literal (after the opening quote).
|
|
5573
5573
|
*/
|
|
5574
|
-
|
|
5574
|
+
_parseStringLiteral() {
|
|
5575
5575
|
const src = this.remainder();
|
|
5576
5576
|
let escape = false;
|
|
5577
5577
|
let content = "";
|
|
@@ -5615,7 +5615,7 @@ var Lexer = class {
|
|
|
5615
5615
|
/**
|
|
5616
5616
|
* Parses a regex pattern (after the opening slash).
|
|
5617
5617
|
*/
|
|
5618
|
-
|
|
5618
|
+
_parseRegex() {
|
|
5619
5619
|
const src = this.remainder();
|
|
5620
5620
|
let escape = false;
|
|
5621
5621
|
for (let i = 0; i < src.length; i++) {
|
|
@@ -5642,7 +5642,7 @@ var Lexer = class {
|
|
|
5642
5642
|
/**
|
|
5643
5643
|
* Parses a hex pattern (after h').
|
|
5644
5644
|
*/
|
|
5645
|
-
|
|
5645
|
+
_parseHexPattern() {
|
|
5646
5646
|
const src = this.remainder();
|
|
5647
5647
|
for (let i = 0; i < src.length; i++) {
|
|
5648
5648
|
const ch = src[i];
|
|
@@ -5666,7 +5666,7 @@ var Lexer = class {
|
|
|
5666
5666
|
/**
|
|
5667
5667
|
* Parses a hex binary regex (after h'/).
|
|
5668
5668
|
*/
|
|
5669
|
-
|
|
5669
|
+
_parseHexBinaryRegex() {
|
|
5670
5670
|
const src = this.remainder();
|
|
5671
5671
|
let escape = false;
|
|
5672
5672
|
for (let i = 0; i < src.length; i++) {
|
|
@@ -5694,7 +5694,7 @@ var Lexer = class {
|
|
|
5694
5694
|
/**
|
|
5695
5695
|
* Parses a date pattern (after date').
|
|
5696
5696
|
*/
|
|
5697
|
-
|
|
5697
|
+
_parseDatePattern() {
|
|
5698
5698
|
const src = this.remainder();
|
|
5699
5699
|
for (let i = 0; i < src.length; i++) if (src[i] === "'") {
|
|
5700
5700
|
const content = src.slice(0, i);
|
|
@@ -5706,7 +5706,7 @@ var Lexer = class {
|
|
|
5706
5706
|
/**
|
|
5707
5707
|
* Parses a range pattern (after {).
|
|
5708
5708
|
*/
|
|
5709
|
-
|
|
5709
|
+
_parseRange() {
|
|
5710
5710
|
const src = this.remainder();
|
|
5711
5711
|
let pos = 0;
|
|
5712
5712
|
while (pos < src.length && src[pos] !== void 0 && isWhitespace(src[pos])) pos++;
|
|
@@ -5755,7 +5755,7 @@ var Lexer = class {
|
|
|
5755
5755
|
/**
|
|
5756
5756
|
* Parses a single quoted pattern (after ').
|
|
5757
5757
|
*/
|
|
5758
|
-
|
|
5758
|
+
_parseSingleQuotedPattern() {
|
|
5759
5759
|
const src = this.remainder();
|
|
5760
5760
|
for (let i = 0; i < src.length; i++) if (src[i] === "'") {
|
|
5761
5761
|
const content = src.slice(0, i);
|
|
@@ -5767,7 +5767,7 @@ var Lexer = class {
|
|
|
5767
5767
|
/**
|
|
5768
5768
|
* Parses a single quoted regex (after '/).
|
|
5769
5769
|
*/
|
|
5770
|
-
|
|
5770
|
+
_parseSingleQuotedRegex() {
|
|
5771
5771
|
const src = this.remainder();
|
|
5772
5772
|
let escape = false;
|
|
5773
5773
|
for (let i = 0; i < src.length; i++) {
|
|
@@ -5795,8 +5795,8 @@ var Lexer = class {
|
|
|
5795
5795
|
/**
|
|
5796
5796
|
* Parses a number (integer or float).
|
|
5797
5797
|
*/
|
|
5798
|
-
|
|
5799
|
-
const startPos = this
|
|
5798
|
+
_parseNumber() {
|
|
5799
|
+
const startPos = this._position;
|
|
5800
5800
|
let isFloat = false;
|
|
5801
5801
|
let isNegative = false;
|
|
5802
5802
|
if (this.peek() === "-") {
|
|
@@ -5828,16 +5828,16 @@ var Lexer = class {
|
|
|
5828
5828
|
c = this.peek();
|
|
5829
5829
|
}
|
|
5830
5830
|
}
|
|
5831
|
-
const numStr = this
|
|
5831
|
+
const numStr = this._source.slice(startPos, this._position);
|
|
5832
5832
|
if (isFloat) {
|
|
5833
|
-
const value
|
|
5834
|
-
if (Number.isNaN(value
|
|
5833
|
+
const value = parseFloat(numStr);
|
|
5834
|
+
if (Number.isNaN(value)) return {
|
|
5835
5835
|
type: "Float",
|
|
5836
5836
|
value: err(invalidNumberFormat(this.span()))
|
|
5837
5837
|
};
|
|
5838
5838
|
return {
|
|
5839
5839
|
type: "Float",
|
|
5840
|
-
value: ok(value
|
|
5840
|
+
value: ok(value)
|
|
5841
5841
|
};
|
|
5842
5842
|
}
|
|
5843
5843
|
const value = parseInt(numStr, 10);
|
|
@@ -5858,25 +5858,25 @@ var Lexer = class {
|
|
|
5858
5858
|
* Gets the next token from the input.
|
|
5859
5859
|
*/
|
|
5860
5860
|
next() {
|
|
5861
|
-
if (this
|
|
5862
|
-
const peeked = this
|
|
5863
|
-
this
|
|
5861
|
+
if (this._peekedToken !== void 0) {
|
|
5862
|
+
const peeked = this._peekedToken;
|
|
5863
|
+
this._peekedToken = void 0;
|
|
5864
5864
|
return peeked;
|
|
5865
5865
|
}
|
|
5866
|
-
this
|
|
5867
|
-
this
|
|
5868
|
-
if (this
|
|
5869
|
-
const ch = this
|
|
5866
|
+
this._skipWhitespace();
|
|
5867
|
+
this._tokenStart = this._position;
|
|
5868
|
+
if (this._position >= this._source.length) return;
|
|
5869
|
+
const ch = this._source[this._position];
|
|
5870
5870
|
if (ch === void 0) return void 0;
|
|
5871
|
-
const twoChar = this
|
|
5872
|
-
if (this
|
|
5871
|
+
const twoChar = this._source.slice(this._position, this._position + 2);
|
|
5872
|
+
if (this._source.slice(this._position, this._position + 3) === "...") {
|
|
5873
5873
|
this.bump(3);
|
|
5874
5874
|
return {
|
|
5875
5875
|
token: { type: "Ellipsis" },
|
|
5876
5876
|
span: this.span()
|
|
5877
5877
|
};
|
|
5878
5878
|
}
|
|
5879
|
-
if (this
|
|
5879
|
+
if (this._source.slice(this._position, this._position + 9) === "-Infinity") {
|
|
5880
5880
|
this.bump(9);
|
|
5881
5881
|
return {
|
|
5882
5882
|
token: { type: "NegativeInfinity" },
|
|
@@ -5945,7 +5945,7 @@ var Lexer = class {
|
|
|
5945
5945
|
return {
|
|
5946
5946
|
token: {
|
|
5947
5947
|
type: "HexBinaryRegex",
|
|
5948
|
-
value: this
|
|
5948
|
+
value: this._parseHexBinaryRegex()
|
|
5949
5949
|
},
|
|
5950
5950
|
span: this.span()
|
|
5951
5951
|
};
|
|
@@ -5953,7 +5953,7 @@ var Lexer = class {
|
|
|
5953
5953
|
return {
|
|
5954
5954
|
token: {
|
|
5955
5955
|
type: "HexPattern",
|
|
5956
|
-
value: this
|
|
5956
|
+
value: this._parseHexPattern()
|
|
5957
5957
|
},
|
|
5958
5958
|
span: this.span()
|
|
5959
5959
|
};
|
|
@@ -5962,7 +5962,7 @@ var Lexer = class {
|
|
|
5962
5962
|
return {
|
|
5963
5963
|
token: {
|
|
5964
5964
|
type: "SingleQuotedRegex",
|
|
5965
|
-
value: this
|
|
5965
|
+
value: this._parseSingleQuotedRegex()
|
|
5966
5966
|
},
|
|
5967
5967
|
span: this.span()
|
|
5968
5968
|
};
|
|
@@ -6051,7 +6051,7 @@ var Lexer = class {
|
|
|
6051
6051
|
return {
|
|
6052
6052
|
token: {
|
|
6053
6053
|
type: "StringLiteral",
|
|
6054
|
-
value: this
|
|
6054
|
+
value: this._parseStringLiteral()
|
|
6055
6055
|
},
|
|
6056
6056
|
span: this.span()
|
|
6057
6057
|
};
|
|
@@ -6060,7 +6060,7 @@ var Lexer = class {
|
|
|
6060
6060
|
return {
|
|
6061
6061
|
token: {
|
|
6062
6062
|
type: "Regex",
|
|
6063
|
-
value: this
|
|
6063
|
+
value: this._parseRegex()
|
|
6064
6064
|
},
|
|
6065
6065
|
span: this.span()
|
|
6066
6066
|
};
|
|
@@ -6069,7 +6069,7 @@ var Lexer = class {
|
|
|
6069
6069
|
return {
|
|
6070
6070
|
token: {
|
|
6071
6071
|
type: "Range",
|
|
6072
|
-
value: this
|
|
6072
|
+
value: this._parseRange()
|
|
6073
6073
|
},
|
|
6074
6074
|
span: this.span()
|
|
6075
6075
|
};
|
|
@@ -6078,13 +6078,13 @@ var Lexer = class {
|
|
|
6078
6078
|
return {
|
|
6079
6079
|
token: {
|
|
6080
6080
|
type: "SingleQuotedPattern",
|
|
6081
|
-
value: this
|
|
6081
|
+
value: this._parseSingleQuotedPattern()
|
|
6082
6082
|
},
|
|
6083
6083
|
span: this.span()
|
|
6084
6084
|
};
|
|
6085
6085
|
case "@": {
|
|
6086
6086
|
this.bump(1);
|
|
6087
|
-
const start = this
|
|
6087
|
+
const start = this._position;
|
|
6088
6088
|
let gc = this.peek();
|
|
6089
6089
|
if (gc !== void 0 && isIdentStart(gc)) {
|
|
6090
6090
|
gc = this.peek();
|
|
@@ -6095,7 +6095,7 @@ var Lexer = class {
|
|
|
6095
6095
|
return {
|
|
6096
6096
|
token: {
|
|
6097
6097
|
type: "GroupName",
|
|
6098
|
-
name: this
|
|
6098
|
+
name: this._source.slice(start, this._position)
|
|
6099
6099
|
},
|
|
6100
6100
|
span: this.span()
|
|
6101
6101
|
};
|
|
@@ -6109,29 +6109,29 @@ var Lexer = class {
|
|
|
6109
6109
|
};
|
|
6110
6110
|
}
|
|
6111
6111
|
}
|
|
6112
|
-
if (this
|
|
6112
|
+
if (this._source.slice(this._position, this._position + 5) === "date'") {
|
|
6113
6113
|
this.bump(5);
|
|
6114
6114
|
return {
|
|
6115
6115
|
token: {
|
|
6116
6116
|
type: "DatePattern",
|
|
6117
|
-
value: this
|
|
6117
|
+
value: this._parseDatePattern()
|
|
6118
6118
|
},
|
|
6119
6119
|
span: this.span()
|
|
6120
6120
|
};
|
|
6121
6121
|
}
|
|
6122
6122
|
const nextChar = this.peekNext();
|
|
6123
6123
|
if (isDigit(ch) || ch === "-" && nextChar !== void 0 && isDigit(nextChar)) return {
|
|
6124
|
-
token: this
|
|
6124
|
+
token: this._parseNumber(),
|
|
6125
6125
|
span: this.span()
|
|
6126
6126
|
};
|
|
6127
6127
|
if (isIdentStart(ch)) {
|
|
6128
|
-
const start = this
|
|
6128
|
+
const start = this._position;
|
|
6129
6129
|
let ic = this.peek();
|
|
6130
6130
|
while (ic !== void 0 && isIdentContinue(ic)) {
|
|
6131
6131
|
this.bump(1);
|
|
6132
6132
|
ic = this.peek();
|
|
6133
6133
|
}
|
|
6134
|
-
const ident = this
|
|
6134
|
+
const ident = this._source.slice(start, this._position);
|
|
6135
6135
|
const keyword = KEYWORDS.get(ident);
|
|
6136
6136
|
if (keyword !== void 0) return {
|
|
6137
6137
|
token: keyword,
|