@poe-platform/safe-bash 0.1.755 → 0.1.757
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/dist/image-ast/index.browser.js +30 -6
- package/dist/image-ast/index.js +30 -6
- package/dist/pdf-ast/canvas.d.ts +1 -0
- package/dist/pdf-ast/index.js +26 -2
- package/dist/safe-bash/chunks/{chunk-LESPJ3OG.js → chunk-WNWIBBJZ.js} +15 -2
- package/dist/safe-bash/command-chunks/{chunk-S4J6MSLY.js → chunk-444OTXM7.js} +3 -3
- package/dist/safe-bash/command-chunks/{chunk-6AIOGLZO.js → chunk-CE6Z2ULX.js} +2 -2
- package/dist/safe-bash/command-chunks/{chunk-5VSGEE6J.js → chunk-F4IQCXZG.js} +5 -5
- package/dist/safe-bash/command-chunks/{chunk-F5MORDSU.js → chunk-FDNCPZQS.js} +32 -1
- package/dist/safe-bash/command-chunks/{chunk-SG3ZDZCX.js → chunk-FLMLM7Y4.js} +2 -2
- package/dist/safe-bash/command-chunks/{chunk-XRVNFK7Z.js → chunk-H2FQA4OU.js} +26 -2
- package/dist/safe-bash/command-chunks/{chunk-CT3FB722.js → chunk-J7UMKBRK.js} +1 -1
- package/dist/safe-bash/command-chunks/{chunk-KB2LQ4HG.js → chunk-KBBI4CSU.js} +2 -2
- package/dist/safe-bash/command-chunks/{chunk-QQOAK7JQ.js → chunk-KKJCKPTA.js} +1 -1
- package/dist/safe-bash/command-chunks/{chunk-7KS6PX4U.js → chunk-KSIGF4AG.js} +3 -3
- package/dist/safe-bash/command-chunks/{chunk-4HQ7WYSI.js → chunk-MED2BOOW.js} +30 -5
- package/dist/safe-bash/command-chunks/{chunk-JRNLDPLI.js → chunk-OZSWW23M.js} +1 -1
- package/dist/safe-bash/command-chunks/{chunk-DKQ5REXF.js → chunk-QDPRSPHQ.js} +1 -1
- package/dist/safe-bash/command-chunks/{chunk-WOPU2VWF.js → chunk-RID3B5RE.js} +1 -1
- package/dist/safe-bash/command-chunks/{chunk-DVZCHNB5.js → chunk-S4MLIYSN.js} +7 -7
- package/dist/safe-bash/command-chunks/{chunk-REYTQLLB.js → chunk-TT2DMDBY.js} +1 -1
- package/dist/safe-bash/command-chunks/{chunk-UGX6MXDD.js → chunk-UIIT4ULR.js} +3 -3
- package/dist/safe-bash/command-chunks/{chunk-MENC7RPR.js → chunk-WI35236J.js} +1 -1
- package/dist/safe-bash/command-chunks/{chunk-A6NFLWZI.js → chunk-WKPOGTZY.js} +22 -6
- package/dist/safe-bash/command-chunks/{chunk-3DOHQQJR.js → chunk-Y64PA6IA.js} +8 -8
- package/dist/safe-bash/command-chunks/{chunk-6Z7OS3TZ.js → chunk-ZP5KDHB4.js} +7 -7
- package/dist/safe-bash/commands/pandoc/index.d.ts +1 -1
- package/dist/safe-bash/commands/pandoc/index.js +5 -3
- package/dist/safe-bash/commands/python/index.browser.js +1 -1
- package/dist/safe-bash/commands/python/index.js +6 -0
- package/dist/safe-bash/commands/python/jspi.js +11 -2
- package/dist/safe-bash/core.browser.js +6 -4
- package/dist/safe-bash-command-csvkit/index.js +8 -8
- package/dist/safe-bash-command-ffmpeg/index.js +20 -2
- package/dist/safe-bash-command-imagemagick/index.js +2 -2
- package/dist/safe-bash-command-pandoc/command.js +3 -3
- package/dist/safe-bash-command-pandoc/index.js +3 -3
- package/dist/safe-bash-command-pdfimages/index.js +26 -2
- package/dist/safe-bash-command-pdfinfo/index.js +26 -2
- package/dist/safe-bash-command-pdftk/index.js +26 -2
- package/dist/safe-bash-command-pdftoppm/index.js +26 -2
- package/dist/safe-bash-command-pdftotext/index.js +26 -2
- package/dist/safe-bash-command-qpdf/index.js +26 -2
- package/dist/safe-bash-command-sips/index.js +2 -2
- package/dist/safe-bash-command-soffice/index.js +17 -17
- package/dist/safe-bash-command-ssconvert/core.js +8 -8
- package/dist/safe-bash-command-ssconvert/formats/csv.js +9 -9
- package/dist/safe-bash-command-ssconvert/formats/ods.js +8 -8
- package/dist/safe-bash-command-ssconvert/formats/spreadsheetml.js +1 -1
- package/dist/safe-bash-command-ssconvert/formats/xls.js +9 -8
- package/dist/safe-bash-command-ssconvert/formats/xlsx.js +8 -8
- package/dist/safe-bash-command-ssconvert/index.js +133 -29
- package/dist/safe-bash-command-wkhtmltopdf/index.js +26 -2
- package/dist/safe-bash-contracts/filesystem-descriptor.js +1 -1
- package/dist/safe-bash-contracts/filesystem-output.js +1 -1
- package/dist/safe-bash-mcp/index.js +4 -4
- package/dist/spreadsheet-engine/formulas/ast.d.ts +13 -0
- package/dist/spreadsheet-engine/formulas/conventions.js +1 -1
- package/dist/spreadsheet-engine/formulas/dependencies.js +2 -2
- package/dist/spreadsheet-engine/formulas/evaluator.js +2 -2
- package/dist/spreadsheet-engine/formulas/named-expressions.d.ts +2 -2
- package/dist/spreadsheet-engine/formulas/named-expressions.js +31 -5
- package/dist/spreadsheet-engine/formulas/parser.js +34 -0
- package/dist/spreadsheet-engine/formulas/rewriting.js +19 -1
- package/dist/spreadsheet-engine/formulas/serialization.js +6 -0
- package/dist/spreadsheet-format-xls/biff-write-formulas.js +2 -0
- package/dist/xlsx-ast/formula-semantics.js +2 -0
- package/package.json +2 -2
- package/third-party/pdf-ast/THIRD_PARTY_NOTICES.md +1 -1
- package/dist/safe-bash/chunks/browser-ECQX6GMK.js +0 -6766
- package/dist/safe-bash/chunks/bz2-4OP3OWW3.js +0 -8
- package/dist/safe-bash/chunks/chunk-22XPAAOI.js +0 -173
- package/dist/safe-bash/chunks/chunk-44WUNUPV.js +0 -649
- package/dist/safe-bash/chunks/chunk-4E3SGG37.js +0 -876
- package/dist/safe-bash/chunks/chunk-4QTSSQKP.js +0 -898
- package/dist/safe-bash/chunks/chunk-5UVGPVXP.js +0 -410
- package/dist/safe-bash/chunks/chunk-64OE6Q6X.js +0 -3487
- package/dist/safe-bash/chunks/chunk-6IIFUPN2.js +0 -1526
- package/dist/safe-bash/chunks/chunk-6XDKK63A.js +0 -38959
- package/dist/safe-bash/chunks/chunk-BENDLTQD.js +0 -7065
- package/dist/safe-bash/chunks/chunk-BMO5LWEX.js +0 -534
- package/dist/safe-bash/chunks/chunk-BPMCPTNP.js +0 -1920
- package/dist/safe-bash/chunks/chunk-BRJTAWP5.js +0 -2955
- package/dist/safe-bash/chunks/chunk-C3GEIN7Q.js +0 -20054
- package/dist/safe-bash/chunks/chunk-CEWCRI6H.js +0 -2813
- package/dist/safe-bash/chunks/chunk-CGL53DQQ.js +0 -37
- package/dist/safe-bash/chunks/chunk-CTYJJD4O.js +0 -869
- package/dist/safe-bash/chunks/chunk-CWSS4MQA.js +0 -7
- package/dist/safe-bash/chunks/chunk-DLIGMTCP.js +0 -3266
- package/dist/safe-bash/chunks/chunk-EMAJ7WUW.js +0 -1031
- package/dist/safe-bash/chunks/chunk-FDKIZ2IJ.js +0 -1950
- package/dist/safe-bash/chunks/chunk-FZWJ2A7V.js +0 -3093
- package/dist/safe-bash/chunks/chunk-G2VCIF2J.js +0 -22
- package/dist/safe-bash/chunks/chunk-GVKBUQDX.js +0 -2649
- package/dist/safe-bash/chunks/chunk-IO2OGW3E.js +0 -28051
- package/dist/safe-bash/chunks/chunk-ISCZG7WA.js +0 -2648
- package/dist/safe-bash/chunks/chunk-JEFBTRY7.js +0 -174814
- package/dist/safe-bash/chunks/chunk-KJHDD4A2.js +0 -759
- package/dist/safe-bash/chunks/chunk-LB6HVRXS.js +0 -857
- package/dist/safe-bash/chunks/chunk-LLWAJOZH.js +0 -15
- package/dist/safe-bash/chunks/chunk-LMUKYZIJ.js +0 -708
- package/dist/safe-bash/chunks/chunk-M5SCNKIK.js +0 -2012
- package/dist/safe-bash/chunks/chunk-MJPFHANT.js +0 -3350
- package/dist/safe-bash/chunks/chunk-MZQW2DOL.js +0 -82
- package/dist/safe-bash/chunks/chunk-NB2V7EOY.js +0 -1348
- package/dist/safe-bash/chunks/chunk-NJVGOIYN.js +0 -17
- package/dist/safe-bash/chunks/chunk-OLNZHDIQ.js +0 -5141
- package/dist/safe-bash/chunks/chunk-OUUVROTM.js +0 -38
- package/dist/safe-bash/chunks/chunk-PA6GYKBQ.js +0 -151
- package/dist/safe-bash/chunks/chunk-PEFHZ226.js +0 -6957
- package/dist/safe-bash/chunks/chunk-QBB5P5KW.js +0 -4839
- package/dist/safe-bash/chunks/chunk-QHB7HBLA.js +0 -2317
- package/dist/safe-bash/chunks/chunk-RSAWYAEH.js +0 -973
- package/dist/safe-bash/chunks/chunk-UWLYRWT4.js +0 -739
- package/dist/safe-bash/chunks/chunk-V463NBQH.js +0 -13
- package/dist/safe-bash/chunks/chunk-WPUALYUS.js +0 -843
- package/dist/safe-bash/chunks/chunk-XHKFSRGU.js +0 -5747
- package/dist/safe-bash/chunks/chunk-XHRCLZ3N.js +0 -13391
- package/dist/safe-bash/chunks/chunk-XPF5XHLY.js +0 -15
- package/dist/safe-bash/chunks/chunk-ZBFOWARG.js +0 -305
- package/dist/safe-bash/chunks/chunk-ZG7GWQ5P.js +0 -1859
- package/dist/safe-bash/chunks/model-store-EIY3ZQLZ.js +0 -10
- package/dist/safe-bash/chunks/pdf-renderer-XIFUTX34.js +0 -22
- package/dist/safe-bash/chunks/pptx-ZL6L7KP2-O425BFIU.js +0 -30658
- package/dist/safe-bash/chunks/src-HHEPGR7U.js +0 -18969
- package/dist/safe-bash/chunks/src-V4VCM5OX.js +0 -187
- package/dist/safe-bash/chunks/usage-6TGVA2OM.js +0 -35
- package/dist/safe-bash/chunks/xz-EGQGQUEI.js +0 -8
- package/dist/safe-bash/chunks/xz-K2E2WLM6.js +0 -9
- package/dist/safe-bash/chunks/zstd-6JBLP5EF.js +0 -8
- package/dist/safe-bash/git_rust-C3QYOAZL.wasm +0 -0
|
@@ -1,1920 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
init_platform
|
|
3
|
-
} from "./chunk-ZG7GWQ5P.js";
|
|
4
|
-
|
|
5
|
-
// packages/safe-bash-regex-engine/src/ere/errors.ts
|
|
6
|
-
init_platform();
|
|
7
|
-
var EreSyntaxError = class extends Error {
|
|
8
|
-
constructor(message, offset) {
|
|
9
|
-
super(`invalid ERE at ${offset}: ${message}`);
|
|
10
|
-
this.offset = offset;
|
|
11
|
-
this.name = "EreSyntaxError";
|
|
12
|
-
}
|
|
13
|
-
offset;
|
|
14
|
-
status = 2;
|
|
15
|
-
};
|
|
16
|
-
var EreUnsupportedError = class extends Error {
|
|
17
|
-
constructor(message, offset) {
|
|
18
|
-
super(`unsupported ERE profile at ${offset}: ${message}`);
|
|
19
|
-
this.offset = offset;
|
|
20
|
-
this.name = "EreUnsupportedError";
|
|
21
|
-
}
|
|
22
|
-
offset;
|
|
23
|
-
status = 2;
|
|
24
|
-
};
|
|
25
|
-
var EreProfileLimitError = class extends Error {
|
|
26
|
-
constructor(resource, limit) {
|
|
27
|
-
super(`ERE profile limit exceeded: ${resource} (${limit})`);
|
|
28
|
-
this.resource = resource;
|
|
29
|
-
this.limit = limit;
|
|
30
|
-
this.name = "EreProfileLimitError";
|
|
31
|
-
}
|
|
32
|
-
resource;
|
|
33
|
-
limit;
|
|
34
|
-
status = 3;
|
|
35
|
-
};
|
|
36
|
-
var EreUsageUnknownError = class extends Error {
|
|
37
|
-
status = 3;
|
|
38
|
-
constructor(reason) {
|
|
39
|
-
super("ERE invocation usage is unknown; further work is refused", { cause: reason });
|
|
40
|
-
this.name = "EreUsageUnknownError";
|
|
41
|
-
}
|
|
42
|
-
};
|
|
43
|
-
|
|
44
|
-
// packages/safe-bash-regex-engine/src/ere/limits.ts
|
|
45
|
-
init_platform();
|
|
46
|
-
import { hasYieldCheckpoint, runYieldCheckpoint, yieldTurn } from "../../safe-bash-contracts/yield.js";
|
|
47
|
-
var resources = Object.freeze([
|
|
48
|
-
"patternBytes",
|
|
49
|
-
"subjectBytes",
|
|
50
|
-
"work",
|
|
51
|
-
"states",
|
|
52
|
-
"allocationUnits",
|
|
53
|
-
"captureBytes",
|
|
54
|
-
"captureSlots"
|
|
55
|
-
]);
|
|
56
|
-
function integer(value) {
|
|
57
|
-
if (!Number.isSafeInteger(value) || value < 0) throw new TypeError("ERE bounds must be nonnegative safe integers");
|
|
58
|
-
}
|
|
59
|
-
function deriveEreLimits(bounds) {
|
|
60
|
-
if (bounds.maxExpansionBytes !== Infinity) integer(bounds.maxExpansionBytes);
|
|
61
|
-
if (bounds.maxExpansionFields !== Infinity) integer(bounds.maxExpansionFields);
|
|
62
|
-
return Object.freeze({
|
|
63
|
-
patternBytes: Infinity,
|
|
64
|
-
subjectBytes: Infinity,
|
|
65
|
-
work: Infinity,
|
|
66
|
-
states: Infinity,
|
|
67
|
-
allocationUnits: Infinity,
|
|
68
|
-
captureBytes: bounds.maxExpansionBytes,
|
|
69
|
-
captureSlots: bounds.maxExpansionFields
|
|
70
|
-
});
|
|
71
|
-
}
|
|
72
|
-
var EreLedger = class _EreLedger {
|
|
73
|
-
limits;
|
|
74
|
-
limitWorkSmi = 1073741823;
|
|
75
|
-
uPatternBytes = 0;
|
|
76
|
-
uSubjectBytes = 0;
|
|
77
|
-
uWork = 0;
|
|
78
|
-
uStates = 0;
|
|
79
|
-
uAllocationUnits = 0;
|
|
80
|
-
uCaptureBytes = 0;
|
|
81
|
-
uCaptureSlots = 0;
|
|
82
|
-
poison;
|
|
83
|
-
lastYield = 0;
|
|
84
|
-
constructor(bounds, overrides, prevalidated) {
|
|
85
|
-
if (prevalidated !== void 0) {
|
|
86
|
-
this.limits = prevalidated;
|
|
87
|
-
this.limitWorkSmi = prevalidated.work > 1073741823 ? 1073741823 : prevalidated.work | 0;
|
|
88
|
-
return;
|
|
89
|
-
}
|
|
90
|
-
const limits = { ...deriveEreLimits(bounds) };
|
|
91
|
-
if (overrides !== void 0) {
|
|
92
|
-
for (const resource of Object.keys(overrides)) {
|
|
93
|
-
if (!resources.includes(resource)) throw new TypeError("unknown ERE limit");
|
|
94
|
-
const key = resource;
|
|
95
|
-
const value = overrides[key];
|
|
96
|
-
if (value === void 0) throw new TypeError("undefined ERE limit");
|
|
97
|
-
if (value !== Infinity) integer(value);
|
|
98
|
-
limits[key] = value;
|
|
99
|
-
}
|
|
100
|
-
}
|
|
101
|
-
this.limits = Object.freeze(limits);
|
|
102
|
-
this.limitWorkSmi = limits.work > 1073741823 ? 1073741823 : limits.work | 0;
|
|
103
|
-
}
|
|
104
|
-
resetWithLimits(limits) {
|
|
105
|
-
this.limits = limits;
|
|
106
|
-
this.limitWorkSmi = limits.work > 1073741823 ? 1073741823 : limits.work | 0;
|
|
107
|
-
this.uPatternBytes = 0;
|
|
108
|
-
this.uSubjectBytes = 0;
|
|
109
|
-
this.uWork = 0;
|
|
110
|
-
this.uStates = 0;
|
|
111
|
-
this.uAllocationUnits = 0;
|
|
112
|
-
this.uCaptureBytes = 0;
|
|
113
|
-
this.uCaptureSlots = 0;
|
|
114
|
-
this.poison = void 0;
|
|
115
|
-
this.lastYield = 0;
|
|
116
|
-
return this;
|
|
117
|
-
}
|
|
118
|
-
static withPrevalidatedLimits(limits) {
|
|
119
|
-
return new _EreLedger({ maxExpansionBytes: Infinity, maxExpansionFields: Infinity }, void 0, limits);
|
|
120
|
-
}
|
|
121
|
-
get usage() {
|
|
122
|
-
return Object.freeze({
|
|
123
|
-
patternBytes: this.uPatternBytes,
|
|
124
|
-
subjectBytes: this.uSubjectBytes,
|
|
125
|
-
work: this.uWork,
|
|
126
|
-
states: this.uStates,
|
|
127
|
-
allocationUnits: this.uAllocationUnits,
|
|
128
|
-
captureBytes: this.uCaptureBytes,
|
|
129
|
-
captureSlots: this.uCaptureSlots
|
|
130
|
-
});
|
|
131
|
-
}
|
|
132
|
-
getResource(resource) {
|
|
133
|
-
switch (resource) {
|
|
134
|
-
case "patternBytes":
|
|
135
|
-
return this.uPatternBytes;
|
|
136
|
-
case "subjectBytes":
|
|
137
|
-
return this.uSubjectBytes;
|
|
138
|
-
case "work":
|
|
139
|
-
return this.uWork;
|
|
140
|
-
case "states":
|
|
141
|
-
return this.uStates;
|
|
142
|
-
case "allocationUnits":
|
|
143
|
-
return this.uAllocationUnits;
|
|
144
|
-
case "captureBytes":
|
|
145
|
-
return this.uCaptureBytes;
|
|
146
|
-
case "captureSlots":
|
|
147
|
-
return this.uCaptureSlots;
|
|
148
|
-
}
|
|
149
|
-
}
|
|
150
|
-
addResource(resource, amount) {
|
|
151
|
-
const amtSmi = amount | 0;
|
|
152
|
-
switch (resource) {
|
|
153
|
-
case "patternBytes":
|
|
154
|
-
this.uPatternBytes = amtSmi === amount && this.uPatternBytes + amtSmi <= 1073741823 ? this.uPatternBytes + amtSmi | 0 : this.uPatternBytes + amount;
|
|
155
|
-
break;
|
|
156
|
-
case "subjectBytes":
|
|
157
|
-
this.uSubjectBytes = amtSmi === amount && this.uSubjectBytes + amtSmi <= 1073741823 ? this.uSubjectBytes + amtSmi | 0 : this.uSubjectBytes + amount;
|
|
158
|
-
break;
|
|
159
|
-
case "work":
|
|
160
|
-
this.uWork = amtSmi === amount && this.uWork + amtSmi <= 1073741823 ? this.uWork + amtSmi | 0 : this.uWork + amount;
|
|
161
|
-
break;
|
|
162
|
-
case "states":
|
|
163
|
-
this.uStates = amtSmi === amount && this.uStates + amtSmi <= 1073741823 ? this.uStates + amtSmi | 0 : this.uStates + amount;
|
|
164
|
-
break;
|
|
165
|
-
case "allocationUnits":
|
|
166
|
-
this.uAllocationUnits = amtSmi === amount && this.uAllocationUnits + amtSmi <= 1073741823 ? this.uAllocationUnits + amtSmi | 0 : this.uAllocationUnits + amount;
|
|
167
|
-
break;
|
|
168
|
-
case "captureBytes":
|
|
169
|
-
this.uCaptureBytes = amtSmi === amount && this.uCaptureBytes + amtSmi <= 1073741823 ? this.uCaptureBytes + amtSmi | 0 : this.uCaptureBytes + amount;
|
|
170
|
-
break;
|
|
171
|
-
case "captureSlots":
|
|
172
|
-
this.uCaptureSlots = amtSmi === amount && this.uCaptureSlots + amtSmi <= 1073741823 ? this.uCaptureSlots + amtSmi | 0 : this.uCaptureSlots + amount;
|
|
173
|
-
break;
|
|
174
|
-
}
|
|
175
|
-
}
|
|
176
|
-
check(signal) {
|
|
177
|
-
if (signal?.aborted) throw signal.reason;
|
|
178
|
-
if (this.poison) throw this.poison;
|
|
179
|
-
}
|
|
180
|
-
charge(resource, amount, signal) {
|
|
181
|
-
this.check(signal);
|
|
182
|
-
integer(amount);
|
|
183
|
-
const current = this.getResource(resource);
|
|
184
|
-
const limit = this.limits[resource];
|
|
185
|
-
if (limit !== Infinity && amount > limit - current) {
|
|
186
|
-
throw new EreProfileLimitError(resource, limit);
|
|
187
|
-
}
|
|
188
|
-
this.addResource(resource, amount);
|
|
189
|
-
}
|
|
190
|
-
chargeWork(amount, signal) {
|
|
191
|
-
if (signal?.aborted) throw signal.reason;
|
|
192
|
-
if (this.poison) throw this.poison;
|
|
193
|
-
if (amount > this.limitWorkSmi - this.uWork && amount > this.limits.work - this.uWork) {
|
|
194
|
-
throw new EreProfileLimitError("work", this.limits.work);
|
|
195
|
-
}
|
|
196
|
-
const amtSmi = amount | 0;
|
|
197
|
-
this.uWork = amtSmi === amount && this.uWork + amtSmi <= 1073741823 ? this.uWork + amtSmi | 0 : this.uWork + amount;
|
|
198
|
-
}
|
|
199
|
-
workAllowanceUntilCheckpoint(signal) {
|
|
200
|
-
const untilLimit = this.limitWorkSmi - (this.uWork | 0) | 0;
|
|
201
|
-
const interval = hasYieldCheckpoint(signal) ? 256 : 16384;
|
|
202
|
-
const untilYield = interval - ((this.uWork | 0) - (this.lastYield | 0)) | 0;
|
|
203
|
-
const min = untilLimit < untilYield ? untilLimit : untilYield;
|
|
204
|
-
return min > 0 ? min : 0;
|
|
205
|
-
}
|
|
206
|
-
advanceSyncCheckpointIfNoExternalYield(signal) {
|
|
207
|
-
if (hasYieldCheckpoint(signal)) return false;
|
|
208
|
-
if (signal?.aborted) throw signal.reason;
|
|
209
|
-
if (this.poison) throw this.poison;
|
|
210
|
-
this.lastYield = this.uWork;
|
|
211
|
-
return true;
|
|
212
|
-
}
|
|
213
|
-
admitInput(resource, length, signal) {
|
|
214
|
-
this.check(signal);
|
|
215
|
-
integer(length);
|
|
216
|
-
if (length > this.limits[resource]) throw new EreProfileLimitError(resource, this.limits[resource]);
|
|
217
|
-
if (resource === "patternBytes") this.uPatternBytes = Math.max(this.uPatternBytes, length);
|
|
218
|
-
else this.uSubjectBytes = Math.max(this.uSubjectBytes, length);
|
|
219
|
-
}
|
|
220
|
-
checkpoint(signal) {
|
|
221
|
-
runYieldCheckpoint(signal);
|
|
222
|
-
this.check(signal);
|
|
223
|
-
const hasExt = hasYieldCheckpoint(signal);
|
|
224
|
-
const interval = hasExt ? 256 : 16384;
|
|
225
|
-
if (this.uWork - this.lastYield >= interval) {
|
|
226
|
-
this.lastYield = this.uWork;
|
|
227
|
-
return yieldTurn(signal).then(() => {
|
|
228
|
-
this.check(signal);
|
|
229
|
-
});
|
|
230
|
-
}
|
|
231
|
-
return void 0;
|
|
232
|
-
}
|
|
233
|
-
markUnknownUsage(reason) {
|
|
234
|
-
this.poison ??= new EreUsageUnknownError(reason);
|
|
235
|
-
}
|
|
236
|
-
};
|
|
237
|
-
|
|
238
|
-
// packages/safe-bash-regex-engine/src/ere/syntax.ts
|
|
239
|
-
init_platform();
|
|
240
|
-
var programs = /* @__PURE__ */ new WeakMap();
|
|
241
|
-
var ereCompilationCache = /* @__PURE__ */ new Map();
|
|
242
|
-
var special = "\\.^$[]()|*+?{}";
|
|
243
|
-
var classes = /* @__PURE__ */ new Set(["alnum", "alpha", "blank", "cntrl", "digit", "graph", "lower", "print", "punct", "space", "upper", "xdigit"]);
|
|
244
|
-
function classMember(name, code) {
|
|
245
|
-
const upper = code >= 65 && code <= 90;
|
|
246
|
-
const lower = code >= 97 && code <= 122;
|
|
247
|
-
const digit = code >= 48 && code <= 57;
|
|
248
|
-
switch (name) {
|
|
249
|
-
case "alnum":
|
|
250
|
-
return upper || lower || digit;
|
|
251
|
-
case "alpha":
|
|
252
|
-
return upper || lower;
|
|
253
|
-
case "blank":
|
|
254
|
-
return code === 9 || code === 32;
|
|
255
|
-
case "cntrl":
|
|
256
|
-
return code < 32 || code === 127;
|
|
257
|
-
case "digit":
|
|
258
|
-
return digit;
|
|
259
|
-
case "graph":
|
|
260
|
-
return code >= 33 && code <= 126;
|
|
261
|
-
case "lower":
|
|
262
|
-
return lower;
|
|
263
|
-
case "print":
|
|
264
|
-
return code >= 32 && code <= 126;
|
|
265
|
-
case "punct":
|
|
266
|
-
return code >= 33 && code <= 126 && !upper && !lower && !digit;
|
|
267
|
-
case "space":
|
|
268
|
-
return code === 32 || code >= 9 && code <= 13;
|
|
269
|
-
case "upper":
|
|
270
|
-
return upper;
|
|
271
|
-
case "xdigit":
|
|
272
|
-
return digit || code >= 65 && code <= 70 || code >= 97 && code <= 102;
|
|
273
|
-
default:
|
|
274
|
-
return false;
|
|
275
|
-
}
|
|
276
|
-
}
|
|
277
|
-
function admitAscii(text, ledger, signal) {
|
|
278
|
-
if (ledger.charge === EreLedger.prototype.charge && ledger.workAllowanceUntilCheckpoint(signal) >= text.length + 4) {
|
|
279
|
-
for (let offset = 0; offset < text.length; offset++) {
|
|
280
|
-
ledger.chargeWork(1, signal);
|
|
281
|
-
const code = text.charCodeAt(offset);
|
|
282
|
-
if (code === 0 || code > 127) throw new EreUnsupportedError("only non-NUL ASCII in the C/POSIX profile", offset);
|
|
283
|
-
}
|
|
284
|
-
const c = ledger.checkpoint(signal);
|
|
285
|
-
if (c) return c;
|
|
286
|
-
return;
|
|
287
|
-
}
|
|
288
|
-
return (async () => {
|
|
289
|
-
for (let offset = 0; offset < text.length; offset++) {
|
|
290
|
-
ledger.charge("work", 1, signal);
|
|
291
|
-
const code = text.charCodeAt(offset);
|
|
292
|
-
if (code === 0 || code > 127) throw new EreUnsupportedError("only non-NUL ASCII in the C/POSIX profile", offset);
|
|
293
|
-
{
|
|
294
|
-
const c = ledger.checkpoint(signal);
|
|
295
|
-
if (c) await c;
|
|
296
|
-
}
|
|
297
|
-
}
|
|
298
|
-
})();
|
|
299
|
-
}
|
|
300
|
-
async function flatten(input, ledger, signal) {
|
|
301
|
-
if (typeof input === "string") {
|
|
302
|
-
ledger.admitInput("patternBytes", input.length, signal);
|
|
303
|
-
await admitAscii(input, ledger, signal);
|
|
304
|
-
return { pattern: input, quoted: null };
|
|
305
|
-
}
|
|
306
|
-
let size = 0;
|
|
307
|
-
for (const fragment of input) {
|
|
308
|
-
if (typeof fragment.text !== "string" || typeof fragment.literal !== "boolean") throw new TypeError("invalid ERE fragment");
|
|
309
|
-
ledger.charge("work", 1, signal);
|
|
310
|
-
{
|
|
311
|
-
const c = ledger.checkpoint(signal);
|
|
312
|
-
if (c) await c;
|
|
313
|
-
}
|
|
314
|
-
ledger.admitInput("patternBytes", fragment.text.length, signal);
|
|
315
|
-
await admitAscii(fragment.text, ledger, signal);
|
|
316
|
-
if (fragment.text.length > ledger.limits.patternBytes - size) ledger.admitInput("patternBytes", ledger.limits.patternBytes + 1, signal);
|
|
317
|
-
size += fragment.text.length;
|
|
318
|
-
ledger.admitInput("patternBytes", size, signal);
|
|
319
|
-
}
|
|
320
|
-
ledger.charge("allocationUnits", size * 2 + input.length + 2, signal);
|
|
321
|
-
const output = [];
|
|
322
|
-
const quoted = [];
|
|
323
|
-
for (const fragment of input) {
|
|
324
|
-
for (let offset = 0; offset < fragment.text.length; offset++) {
|
|
325
|
-
ledger.charge("work", 1, signal);
|
|
326
|
-
{
|
|
327
|
-
const c = ledger.checkpoint(signal);
|
|
328
|
-
if (c) await c;
|
|
329
|
-
}
|
|
330
|
-
quoted.push(fragment.literal);
|
|
331
|
-
}
|
|
332
|
-
output.push(fragment.text);
|
|
333
|
-
{
|
|
334
|
-
const c = ledger.checkpoint(signal);
|
|
335
|
-
if (c) await c;
|
|
336
|
-
}
|
|
337
|
-
}
|
|
338
|
-
return { pattern: output.join(""), quoted: Object.freeze(quoted) };
|
|
339
|
-
}
|
|
340
|
-
var Parser = class {
|
|
341
|
-
constructor(pattern, quoted, ledger, signal, insensitive, localeProfile) {
|
|
342
|
-
this.pattern = pattern;
|
|
343
|
-
this.quoted = quoted;
|
|
344
|
-
this.ledger = ledger;
|
|
345
|
-
this.signal = signal;
|
|
346
|
-
this.insensitive = insensitive;
|
|
347
|
-
this.localeProfile = localeProfile;
|
|
348
|
-
}
|
|
349
|
-
pattern;
|
|
350
|
-
quoted;
|
|
351
|
-
ledger;
|
|
352
|
-
signal;
|
|
353
|
-
insensitive;
|
|
354
|
-
localeProfile;
|
|
355
|
-
offset = 0;
|
|
356
|
-
groups = 0;
|
|
357
|
-
at(character, offset = this.offset) {
|
|
358
|
-
return !this.quoted?.[offset] && this.pattern[offset] === character;
|
|
359
|
-
}
|
|
360
|
-
node(create) {
|
|
361
|
-
this.ledger.charge("allocationUnits", 8, this.signal);
|
|
362
|
-
return Object.freeze(create());
|
|
363
|
-
}
|
|
364
|
-
async expression() {
|
|
365
|
-
this.ledger.charge("allocationUnits", 1, this.signal);
|
|
366
|
-
const alternatives = [];
|
|
367
|
-
while (true) {
|
|
368
|
-
const child = await this.sequence();
|
|
369
|
-
this.ledger.charge("allocationUnits", 1, this.signal);
|
|
370
|
-
alternatives.push(child);
|
|
371
|
-
if (!this.at("|")) break;
|
|
372
|
-
this.offset++;
|
|
373
|
-
}
|
|
374
|
-
if (alternatives.length === 1) return alternatives[0];
|
|
375
|
-
this.ledger.charge("work", alternatives.length * 2, this.signal);
|
|
376
|
-
{
|
|
377
|
-
const c = this.ledger.checkpoint(this.signal);
|
|
378
|
-
if (c) await c;
|
|
379
|
-
}
|
|
380
|
-
return this.node(() => ({ kind: "alternative", children: Object.freeze(alternatives), nullable: alternatives.some((value) => value.nullable), captured: alternatives.some((value) => value.captured) }));
|
|
381
|
-
}
|
|
382
|
-
async sequence() {
|
|
383
|
-
this.ledger.charge("allocationUnits", 1, this.signal);
|
|
384
|
-
const children = [];
|
|
385
|
-
while (this.offset < this.pattern.length && !this.at("|") && !this.at(")")) {
|
|
386
|
-
this.ledger.charge("work", 1, this.signal);
|
|
387
|
-
{
|
|
388
|
-
const c = this.ledger.checkpoint(this.signal);
|
|
389
|
-
if (c) await c;
|
|
390
|
-
}
|
|
391
|
-
let child = await this.atom();
|
|
392
|
-
const operator = this.quoted?.[this.offset] ? void 0 : this.pattern[this.offset];
|
|
393
|
-
if (operator === "*" || operator === "+" || operator === "?" || operator === "{") {
|
|
394
|
-
const begin = this.offset++;
|
|
395
|
-
let min = operator === "+" ? 1 : 0;
|
|
396
|
-
let max = operator === "?" ? 1 : Infinity;
|
|
397
|
-
if (operator === "{") {
|
|
398
|
-
min = await this.count();
|
|
399
|
-
max = min;
|
|
400
|
-
if (this.at(",")) {
|
|
401
|
-
this.offset++;
|
|
402
|
-
max = this.at("}") ? Infinity : await this.count();
|
|
403
|
-
}
|
|
404
|
-
if (!this.at("}") || max < min) throw new EreSyntaxError("invalid interval", begin);
|
|
405
|
-
this.offset++;
|
|
406
|
-
}
|
|
407
|
-
if (child.kind === "start" || child.kind === "end") throw new EreUnsupportedError("repeated anchor", begin);
|
|
408
|
-
if (child.nullable && child.captured && max > 1) throw new EreUnsupportedError("nullable captured repetition", begin);
|
|
409
|
-
const repeated = child;
|
|
410
|
-
child = this.node(() => ({ kind: "repeat", child: repeated, min, max, nullable: min === 0 || repeated.nullable, captured: repeated.captured }));
|
|
411
|
-
const next = this.quoted?.[this.offset] ? void 0 : this.pattern[this.offset];
|
|
412
|
-
if (next === "*" || next === "+" || next === "?" || next === "{") throw new EreUnsupportedError("stacked repetition", this.offset);
|
|
413
|
-
}
|
|
414
|
-
this.ledger.charge("allocationUnits", 1, this.signal);
|
|
415
|
-
children.push(child);
|
|
416
|
-
}
|
|
417
|
-
if (children.length === 0) return this.node(() => ({ kind: "empty", nullable: true, captured: false }));
|
|
418
|
-
if (children.length === 1) return children[0];
|
|
419
|
-
this.ledger.charge("work", children.length * 2, this.signal);
|
|
420
|
-
{
|
|
421
|
-
const c = this.ledger.checkpoint(this.signal);
|
|
422
|
-
if (c) await c;
|
|
423
|
-
}
|
|
424
|
-
return this.node(() => ({ kind: "sequence", children: Object.freeze(children), nullable: children.every((value) => value.nullable), captured: children.some((value) => value.captured) }));
|
|
425
|
-
}
|
|
426
|
-
async count() {
|
|
427
|
-
const begin = this.offset;
|
|
428
|
-
let value = 0;
|
|
429
|
-
while (!this.quoted?.[this.offset] && this.pattern[this.offset] !== void 0 && this.pattern[this.offset] >= "0" && this.pattern[this.offset] <= "9") {
|
|
430
|
-
this.ledger.charge("work", 1, this.signal);
|
|
431
|
-
{
|
|
432
|
-
const c = this.ledger.checkpoint(this.signal);
|
|
433
|
-
if (c) await c;
|
|
434
|
-
}
|
|
435
|
-
value = value * 10 + this.pattern.charCodeAt(this.offset++) - 48;
|
|
436
|
-
if (!Number.isSafeInteger(value)) throw new EreUnsupportedError("interval count is not a safe integer", begin);
|
|
437
|
-
}
|
|
438
|
-
if (begin === this.offset) throw new EreSyntaxError("missing interval count", begin);
|
|
439
|
-
return value;
|
|
440
|
-
}
|
|
441
|
-
async atom() {
|
|
442
|
-
const begin = this.offset;
|
|
443
|
-
const character = this.pattern[this.offset++];
|
|
444
|
-
if (this.quoted?.[begin]) return this.node(() => ({ kind: "literal", code: character.charCodeAt(0), insensitive: this.insensitive, nullable: false, captured: false }));
|
|
445
|
-
if (character === "(") {
|
|
446
|
-
if (this.at("?")) throw new EreUnsupportedError("extended group syntax", begin);
|
|
447
|
-
const index = ++this.groups;
|
|
448
|
-
const child = await this.expression();
|
|
449
|
-
if (!this.at(")")) throw new EreSyntaxError("unclosed group", begin);
|
|
450
|
-
this.offset++;
|
|
451
|
-
return this.node(() => ({ kind: "group", index, child, nullable: child.nullable, captured: true }));
|
|
452
|
-
}
|
|
453
|
-
if (character === "[") return this.set(begin);
|
|
454
|
-
if (character === "\\") {
|
|
455
|
-
const escaped = this.pattern[this.offset++];
|
|
456
|
-
if (escaped === void 0) throw new EreSyntaxError("trailing escape", begin);
|
|
457
|
-
if (!special.includes(escaped)) throw new EreUnsupportedError("backreference or escape extension", begin);
|
|
458
|
-
return this.node(() => ({ kind: "literal", code: escaped.charCodeAt(0), insensitive: this.insensitive, nullable: false, captured: false }));
|
|
459
|
-
}
|
|
460
|
-
if (character === "*" || character === "+" || character === "?" || character === "{") throw new EreSyntaxError("repetition without operand", begin);
|
|
461
|
-
if (character === ".") return this.node(() => ({ kind: "dot", nullable: false, captured: false }));
|
|
462
|
-
if (character === "^") return this.node(() => ({ kind: "start", nullable: true, captured: false }));
|
|
463
|
-
if (character === "$") return this.node(() => ({ kind: "end", nullable: true, captured: false }));
|
|
464
|
-
return this.node(() => ({ kind: "literal", code: character.charCodeAt(0), insensitive: this.insensitive, nullable: false, captured: false }));
|
|
465
|
-
}
|
|
466
|
-
async set(begin) {
|
|
467
|
-
this.ledger.charge("allocationUnits", 128, this.signal);
|
|
468
|
-
const members = new Array(128).fill(false);
|
|
469
|
-
const negate = this.at("^");
|
|
470
|
-
if (negate) this.offset++;
|
|
471
|
-
let first = true;
|
|
472
|
-
while (this.offset < this.pattern.length) {
|
|
473
|
-
this.ledger.charge("work", 1, this.signal);
|
|
474
|
-
{
|
|
475
|
-
const c = this.ledger.checkpoint(this.signal);
|
|
476
|
-
if (c) await c;
|
|
477
|
-
}
|
|
478
|
-
if (this.at("]") && !first) {
|
|
479
|
-
this.offset++;
|
|
480
|
-
if (this.insensitive) for (let upper = 65; upper <= 90; upper++) {
|
|
481
|
-
this.ledger.charge("work", 1, this.signal);
|
|
482
|
-
{
|
|
483
|
-
const c = this.ledger.checkpoint(this.signal);
|
|
484
|
-
if (c) await c;
|
|
485
|
-
}
|
|
486
|
-
if (members[upper] || members[upper + 32]) members[upper] = members[upper + 32] = true;
|
|
487
|
-
}
|
|
488
|
-
if (negate) for (let code = 1; code < 128; code++) {
|
|
489
|
-
this.ledger.charge("work", 1, this.signal);
|
|
490
|
-
{
|
|
491
|
-
const c = this.ledger.checkpoint(this.signal);
|
|
492
|
-
if (c) await c;
|
|
493
|
-
}
|
|
494
|
-
members[code] = !members[code];
|
|
495
|
-
}
|
|
496
|
-
return this.node(() => ({ kind: "set", members: Object.freeze(members), nonAscii: negate, nullable: false, captured: false }));
|
|
497
|
-
}
|
|
498
|
-
first = false;
|
|
499
|
-
if (this.at("[") && (this.at(".", this.offset + 1) || this.at("=", this.offset + 1))) {
|
|
500
|
-
throw new EreUnsupportedError("collating or equivalence element", this.offset);
|
|
501
|
-
}
|
|
502
|
-
if (this.at("[") && this.at(":", this.offset + 1)) {
|
|
503
|
-
if (!this.localeProfile.classes) throw new EreUnsupportedError("locale character class", this.offset);
|
|
504
|
-
const classBegin = this.offset;
|
|
505
|
-
this.offset += 2;
|
|
506
|
-
let name = "";
|
|
507
|
-
while (this.offset < this.pattern.length && !this.at(":")) {
|
|
508
|
-
this.ledger.charge("work", 1, this.signal);
|
|
509
|
-
{
|
|
510
|
-
const c = this.ledger.checkpoint(this.signal);
|
|
511
|
-
if (c) await c;
|
|
512
|
-
}
|
|
513
|
-
if (name.length >= 6) throw new EreSyntaxError("unknown character class", classBegin);
|
|
514
|
-
name += this.pattern[this.offset++];
|
|
515
|
-
}
|
|
516
|
-
if (!this.at(":") || !this.at("]", this.offset + 1) || !classes.has(name)) throw new EreSyntaxError("unknown character class", classBegin);
|
|
517
|
-
this.offset += 2;
|
|
518
|
-
for (let code = 1; code < 128; code++) {
|
|
519
|
-
this.ledger.charge("work", 1, this.signal);
|
|
520
|
-
{
|
|
521
|
-
const c = this.ledger.checkpoint(this.signal);
|
|
522
|
-
if (c) await c;
|
|
523
|
-
}
|
|
524
|
-
if (classMember(name, code)) members[code] = true;
|
|
525
|
-
}
|
|
526
|
-
if (this.at("-") && !this.at("]", this.offset + 1)) throw new EreSyntaxError("class cannot be a range endpoint", this.offset);
|
|
527
|
-
} else {
|
|
528
|
-
const lower = this.pattern.charCodeAt(this.offset++);
|
|
529
|
-
if (this.at("-") && !this.at("]", this.offset + 1) && this.pattern[this.offset + 1] !== void 0) {
|
|
530
|
-
if (!this.localeProfile.ranges) throw new EreUnsupportedError("collation locale range", this.offset);
|
|
531
|
-
this.offset++;
|
|
532
|
-
if (this.at("[")) throw new EreSyntaxError("nonliteral range endpoint", this.offset);
|
|
533
|
-
const upper = this.pattern.charCodeAt(this.offset++);
|
|
534
|
-
if (lower > upper) throw new EreSyntaxError("descending range", this.offset - 3);
|
|
535
|
-
for (let code = lower; code <= upper; code++) {
|
|
536
|
-
this.ledger.charge("work", 1, this.signal);
|
|
537
|
-
{
|
|
538
|
-
const c = this.ledger.checkpoint(this.signal);
|
|
539
|
-
if (c) await c;
|
|
540
|
-
}
|
|
541
|
-
members[code] = true;
|
|
542
|
-
}
|
|
543
|
-
} else members[lower] = true;
|
|
544
|
-
}
|
|
545
|
-
}
|
|
546
|
-
throw new EreSyntaxError("unclosed bracket expression", begin);
|
|
547
|
-
}
|
|
548
|
-
};
|
|
549
|
-
async function compileEre(input, ledger, signal, asciiInsensitive = false, localeProfile = { ranges: true, classes: true }) {
|
|
550
|
-
ledger.check(signal);
|
|
551
|
-
if (typeof asciiInsensitive !== "boolean") throw new TypeError("ASCII case mode must be boolean");
|
|
552
|
-
let cacheKey;
|
|
553
|
-
if (typeof input === "string" && input.length <= 128) {
|
|
554
|
-
cacheKey = `S:${asciiInsensitive ? 1 : 0}:${localeProfile.ranges ? 1 : 0}:${localeProfile.classes ? 1 : 0}:${input}`;
|
|
555
|
-
} else if (Array.isArray(input) && input.length === 1 && typeof input[0]?.text === "string" && typeof input[0]?.literal === "boolean" && input[0].text.length <= 128) {
|
|
556
|
-
cacheKey = `F:${asciiInsensitive ? 1 : 0}:${localeProfile.ranges ? 1 : 0}:${localeProfile.classes ? 1 : 0}:${input[0].literal ? 1 : 0}:${input[0].text}`;
|
|
557
|
-
}
|
|
558
|
-
if (cacheKey !== void 0 && ledger.charge === EreLedger.prototype.charge) {
|
|
559
|
-
const cached = ereCompilationCache.get(cacheKey);
|
|
560
|
-
if (cached && ledger.workAllowanceUntilCheckpoint(signal) >= cached.work + 16 && cached.patternBytes <= ledger.limits.patternBytes && cached.states <= ledger.limits.states - ledger.usage.states && cached.allocationUnits <= ledger.limits.allocationUnits - ledger.usage.allocationUnits) {
|
|
561
|
-
ledger.admitInput("patternBytes", cached.patternBytes, signal);
|
|
562
|
-
if (cached.work > 0) ledger.chargeWork(cached.work, signal);
|
|
563
|
-
if (cached.states > 0) ledger.charge("states", cached.states, signal);
|
|
564
|
-
if (cached.allocationUnits > 0) ledger.charge("allocationUnits", cached.allocationUnits, signal);
|
|
565
|
-
const c = ledger.checkpoint(signal);
|
|
566
|
-
if (c) await c;
|
|
567
|
-
const program2 = Object.freeze({ pattern: cached.pattern, groups: cached.groups });
|
|
568
|
-
programs.set(program2, { root: cached.root, ledger });
|
|
569
|
-
return program2;
|
|
570
|
-
}
|
|
571
|
-
}
|
|
572
|
-
const before = cacheKey !== void 0 ? ledger.usage : void 0;
|
|
573
|
-
const { pattern, quoted } = await flatten(input, ledger, signal);
|
|
574
|
-
const parser = new Parser(pattern, quoted, ledger, signal, asciiInsensitive, localeProfile);
|
|
575
|
-
const root = await parser.expression();
|
|
576
|
-
if (parser.offset !== pattern.length) throw new EreSyntaxError("unmatched closing group", parser.offset);
|
|
577
|
-
ledger.charge("allocationUnits", 3, signal);
|
|
578
|
-
const program = Object.freeze({ pattern, groups: parser.groups });
|
|
579
|
-
programs.set(program, { root, ledger });
|
|
580
|
-
if (cacheKey !== void 0 && before !== void 0) {
|
|
581
|
-
const after = ledger.usage;
|
|
582
|
-
if (ereCompilationCache.size >= 256) ereCompilationCache.clear();
|
|
583
|
-
ereCompilationCache.set(cacheKey, {
|
|
584
|
-
pattern,
|
|
585
|
-
groups: parser.groups,
|
|
586
|
-
root,
|
|
587
|
-
patternBytes: after.patternBytes,
|
|
588
|
-
work: after.work - before.work,
|
|
589
|
-
states: after.states - before.states,
|
|
590
|
-
allocationUnits: after.allocationUnits - before.allocationUnits
|
|
591
|
-
});
|
|
592
|
-
}
|
|
593
|
-
return program;
|
|
594
|
-
}
|
|
595
|
-
function tryCompileEreSync(input, ledger, signal, asciiInsensitive = false, localeProfile = { ranges: true, classes: true }) {
|
|
596
|
-
let cacheKey;
|
|
597
|
-
if (typeof input === "string" && input.length <= 128) {
|
|
598
|
-
cacheKey = `S:${asciiInsensitive ? 1 : 0}:${localeProfile.ranges ? 1 : 0}:${localeProfile.classes ? 1 : 0}:${input}`;
|
|
599
|
-
} else if (Array.isArray(input) && input.length === 1 && typeof input[0]?.text === "string" && typeof input[0]?.literal === "boolean" && input[0].text.length <= 128) {
|
|
600
|
-
cacheKey = `F:${asciiInsensitive ? 1 : 0}:${localeProfile.ranges ? 1 : 0}:${localeProfile.classes ? 1 : 0}:${input[0].literal ? 1 : 0}:${input[0].text}`;
|
|
601
|
-
}
|
|
602
|
-
if (cacheKey === void 0) return void 0;
|
|
603
|
-
const cached = ereCompilationCache.get(cacheKey);
|
|
604
|
-
if (!cached || ledger.workAllowanceUntilCheckpoint(signal) < cached.work + 16 || cached.patternBytes > ledger.limits.patternBytes || cached.states > ledger.limits.states - ledger.usage.states || cached.allocationUnits > ledger.limits.allocationUnits - ledger.usage.allocationUnits) {
|
|
605
|
-
return void 0;
|
|
606
|
-
}
|
|
607
|
-
ledger.admitInput("patternBytes", cached.patternBytes, signal);
|
|
608
|
-
if (cached.work > 0) ledger.chargeWork(cached.work, signal);
|
|
609
|
-
if (cached.states > 0) ledger.charge("states", cached.states, signal);
|
|
610
|
-
if (cached.allocationUnits > 0) ledger.charge("allocationUnits", cached.allocationUnits, signal);
|
|
611
|
-
if (ledger.checkpoint(signal)) return void 0;
|
|
612
|
-
const program = Object.freeze({ pattern: cached.pattern, groups: cached.groups });
|
|
613
|
-
programs.set(program, { root: cached.root, ledger });
|
|
614
|
-
return program;
|
|
615
|
-
}
|
|
616
|
-
function resolveEreProgram(program, ledger) {
|
|
617
|
-
const entry = programs.get(program);
|
|
618
|
-
if (!entry || entry.ledger !== ledger) throw new TypeError("ERE program is not bound to this invocation ledger");
|
|
619
|
-
return entry.root;
|
|
620
|
-
}
|
|
621
|
-
function resolveEreProgramUnchecked(program) {
|
|
622
|
-
const entry = programs.get(program);
|
|
623
|
-
if (!entry) throw new TypeError("ERE program is not bound to this invocation ledger");
|
|
624
|
-
return entry.root;
|
|
625
|
-
}
|
|
626
|
-
|
|
627
|
-
// packages/safe-bash-regex-engine/src/ere/matcher.ts
|
|
628
|
-
init_platform();
|
|
629
|
-
|
|
630
|
-
// packages/safe-bash-regex-engine/src/utf8.ts
|
|
631
|
-
init_platform();
|
|
632
|
-
import { PublicDiagnostic } from "../../safe-bash-contracts/public-diagnostic.js";
|
|
633
|
-
function invalidUtf8() {
|
|
634
|
-
throw new PublicDiagnostic("bounded regex unsupported: literal patterns and subjects require valid non-NUL UTF-8 bytes");
|
|
635
|
-
}
|
|
636
|
-
function validateUtf8(input, ledger, signal) {
|
|
637
|
-
const len = input.length;
|
|
638
|
-
if (len === 0) {
|
|
639
|
-
ledger.check(signal);
|
|
640
|
-
return void 0;
|
|
641
|
-
}
|
|
642
|
-
if (ledger.workAllowanceUntilCheckpoint(signal) >= len) {
|
|
643
|
-
let ascii = true;
|
|
644
|
-
if (typeof input === "string") {
|
|
645
|
-
for (let i = 0; i < len; i++) {
|
|
646
|
-
const b = input.charCodeAt(i);
|
|
647
|
-
if (b === 0 || b >= 128) {
|
|
648
|
-
ascii = false;
|
|
649
|
-
break;
|
|
650
|
-
}
|
|
651
|
-
}
|
|
652
|
-
} else {
|
|
653
|
-
for (let i = 0; i < len; i++) {
|
|
654
|
-
const b = input[i];
|
|
655
|
-
if (b === 0 || b >= 128) {
|
|
656
|
-
ascii = false;
|
|
657
|
-
break;
|
|
658
|
-
}
|
|
659
|
-
}
|
|
660
|
-
}
|
|
661
|
-
if (ascii) {
|
|
662
|
-
ledger.chargeWork(len, signal);
|
|
663
|
-
return ledger.checkpoint(signal);
|
|
664
|
-
}
|
|
665
|
-
}
|
|
666
|
-
return validateUtf8Async(input, ledger, signal);
|
|
667
|
-
}
|
|
668
|
-
async function validateUtf8Async(input, ledger, signal) {
|
|
669
|
-
for (let index = 0; index < input.length; ) {
|
|
670
|
-
if (typeof input !== "string") {
|
|
671
|
-
const allowance = ledger.workAllowanceUntilCheckpoint(signal);
|
|
672
|
-
if (allowance > 1) {
|
|
673
|
-
const maxRun = Math.min(input.length, index + allowance);
|
|
674
|
-
let scan = index;
|
|
675
|
-
while (scan < maxRun) {
|
|
676
|
-
const b = input[scan];
|
|
677
|
-
if (b === 0 || b >= 128) break;
|
|
678
|
-
scan++;
|
|
679
|
-
}
|
|
680
|
-
if (scan > index) {
|
|
681
|
-
ledger.chargeWork(scan - index, signal);
|
|
682
|
-
index = scan;
|
|
683
|
-
const pending2 = ledger.checkpoint(signal);
|
|
684
|
-
if (pending2) await pending2;
|
|
685
|
-
if (index >= input.length) break;
|
|
686
|
-
}
|
|
687
|
-
}
|
|
688
|
-
}
|
|
689
|
-
const first = typeof input === "string" ? input.charCodeAt(index) : input[index];
|
|
690
|
-
const width = first < 128 ? 1 : first >= 194 && first <= 223 ? 2 : first >= 224 && first <= 239 ? 3 : first >= 240 && first <= 244 ? 4 : 0;
|
|
691
|
-
ledger.chargeWork(Math.max(width, 1), signal);
|
|
692
|
-
if (first === 0 || width === 0 || width > input.length - index) invalidUtf8();
|
|
693
|
-
for (let continuation = 1; continuation < width; continuation++) {
|
|
694
|
-
const byte = typeof input === "string" ? input.charCodeAt(index + continuation) : input[index + continuation];
|
|
695
|
-
if (byte < 128 || byte > 191 || continuation === 1 && (first === 224 && byte < 160 || first === 237 && byte > 159 || first === 240 && byte < 144 || first === 244 && byte > 143)) invalidUtf8();
|
|
696
|
-
}
|
|
697
|
-
index += width;
|
|
698
|
-
const pending = ledger.checkpoint(signal);
|
|
699
|
-
if (pending) await pending;
|
|
700
|
-
}
|
|
701
|
-
}
|
|
702
|
-
|
|
703
|
-
// packages/safe-bash-regex-engine/src/ascii.ts
|
|
704
|
-
init_platform();
|
|
705
|
-
function foldAscii(code) {
|
|
706
|
-
return code >= 65 && code <= 90 ? code + 32 : code;
|
|
707
|
-
}
|
|
708
|
-
function isAsciiWord(code) {
|
|
709
|
-
return code >= 65 && code <= 90 || code >= 97 && code <= 122 || code >= 48 && code <= 57 || code === 95;
|
|
710
|
-
}
|
|
711
|
-
|
|
712
|
-
// packages/safe-bash-regex-engine/src/ere/matcher.ts
|
|
713
|
-
var initialCharacters = /* @__PURE__ */ new WeakMap();
|
|
714
|
-
var sequenceNullNextTasks = /* @__PURE__ */ new WeakMap();
|
|
715
|
-
var SINGLE_NULL_CAPTURES = Object.freeze([null]);
|
|
716
|
-
var SINGLE_NULL_HISTORIES = Object.freeze([null]);
|
|
717
|
-
var fastLiteralSeqs = /* @__PURE__ */ new WeakMap();
|
|
718
|
-
var fastPrefixAlts = /* @__PURE__ */ new WeakMap();
|
|
719
|
-
function extractLiteralBytes(node) {
|
|
720
|
-
if (node.kind === "literal") {
|
|
721
|
-
return node.insensitive ? null : Uint8Array.of(node.code);
|
|
722
|
-
}
|
|
723
|
-
if (node.kind === "group") {
|
|
724
|
-
return extractLiteralBytes(node.child);
|
|
725
|
-
}
|
|
726
|
-
if (node.kind === "sequence") {
|
|
727
|
-
const out = [];
|
|
728
|
-
for (const c of node.children) {
|
|
729
|
-
if (c.kind === "literal" && !c.insensitive) out.push(c.code);
|
|
730
|
-
else return null;
|
|
731
|
-
}
|
|
732
|
-
return out.length > 0 ? Uint8Array.from(out) : null;
|
|
733
|
-
}
|
|
734
|
-
return null;
|
|
735
|
-
}
|
|
736
|
-
function getFastErePrefixAlt(root) {
|
|
737
|
-
const existing = fastPrefixAlts.get(root);
|
|
738
|
-
if (existing !== void 0) return existing;
|
|
739
|
-
let anchoredStart = false;
|
|
740
|
-
let anchoredEnd = false;
|
|
741
|
-
const prefixBytes = [];
|
|
742
|
-
let alts = null;
|
|
743
|
-
const nodes = root.kind === "sequence" ? root.children : [root];
|
|
744
|
-
let idx = 0;
|
|
745
|
-
let endIdx = nodes.length;
|
|
746
|
-
if (idx < endIdx && nodes[idx].kind === "start") {
|
|
747
|
-
anchoredStart = true;
|
|
748
|
-
idx++;
|
|
749
|
-
}
|
|
750
|
-
if (idx < endIdx && nodes[endIdx - 1].kind === "end") {
|
|
751
|
-
anchoredEnd = true;
|
|
752
|
-
endIdx--;
|
|
753
|
-
}
|
|
754
|
-
while (idx < endIdx) {
|
|
755
|
-
const n = nodes[idx];
|
|
756
|
-
if (n.kind === "literal" && !n.insensitive) {
|
|
757
|
-
prefixBytes.push(n.code);
|
|
758
|
-
idx++;
|
|
759
|
-
} else {
|
|
760
|
-
break;
|
|
761
|
-
}
|
|
762
|
-
}
|
|
763
|
-
if (idx === endIdx - 1) {
|
|
764
|
-
let tail = nodes[idx];
|
|
765
|
-
while (tail.kind === "group") tail = tail.child;
|
|
766
|
-
if (tail.kind === "alternative" && tail.children.length > 0) {
|
|
767
|
-
const branches = [];
|
|
768
|
-
let ok = true;
|
|
769
|
-
for (const b of tail.children) {
|
|
770
|
-
const bytes = extractLiteralBytes(b);
|
|
771
|
-
if (!bytes || bytes.length === 0) {
|
|
772
|
-
ok = false;
|
|
773
|
-
break;
|
|
774
|
-
}
|
|
775
|
-
branches.push(bytes);
|
|
776
|
-
}
|
|
777
|
-
if (ok) {
|
|
778
|
-
alts = branches;
|
|
779
|
-
idx++;
|
|
780
|
-
}
|
|
781
|
-
}
|
|
782
|
-
}
|
|
783
|
-
if (idx !== endIdx || prefixBytes.length === 0 && alts === null) {
|
|
784
|
-
fastPrefixAlts.set(root, null);
|
|
785
|
-
return null;
|
|
786
|
-
}
|
|
787
|
-
const created = {
|
|
788
|
-
anchoredStart,
|
|
789
|
-
anchoredEnd,
|
|
790
|
-
prefix: Uint8Array.from(prefixBytes),
|
|
791
|
-
alts
|
|
792
|
-
};
|
|
793
|
-
fastPrefixAlts.set(root, created);
|
|
794
|
-
return created;
|
|
795
|
-
}
|
|
796
|
-
function getFastEreLiteralSeq(root) {
|
|
797
|
-
const existing = fastLiteralSeqs.get(root);
|
|
798
|
-
if (existing !== void 0) return existing;
|
|
799
|
-
let anchoredStart = false;
|
|
800
|
-
let anchoredEnd = false;
|
|
801
|
-
let insensitive = false;
|
|
802
|
-
const bytes = [];
|
|
803
|
-
if (root.kind === "literal") {
|
|
804
|
-
insensitive = root.insensitive;
|
|
805
|
-
bytes.push(insensitive ? foldAscii(root.code) : root.code);
|
|
806
|
-
} else if (root.kind === "sequence") {
|
|
807
|
-
const children = root.children;
|
|
808
|
-
for (let i = 0; i < children.length; i++) {
|
|
809
|
-
const child = children[i];
|
|
810
|
-
if (child.kind === "start") {
|
|
811
|
-
if (i !== 0) {
|
|
812
|
-
fastLiteralSeqs.set(root, null);
|
|
813
|
-
return null;
|
|
814
|
-
}
|
|
815
|
-
anchoredStart = true;
|
|
816
|
-
} else if (child.kind === "end") {
|
|
817
|
-
if (i !== children.length - 1) {
|
|
818
|
-
fastLiteralSeqs.set(root, null);
|
|
819
|
-
return null;
|
|
820
|
-
}
|
|
821
|
-
anchoredEnd = true;
|
|
822
|
-
} else if (child.kind === "literal") {
|
|
823
|
-
if (bytes.length === 0) insensitive = child.insensitive;
|
|
824
|
-
else if (insensitive !== child.insensitive) {
|
|
825
|
-
fastLiteralSeqs.set(root, null);
|
|
826
|
-
return null;
|
|
827
|
-
}
|
|
828
|
-
bytes.push(insensitive ? foldAscii(child.code) : child.code);
|
|
829
|
-
} else {
|
|
830
|
-
fastLiteralSeqs.set(root, null);
|
|
831
|
-
return null;
|
|
832
|
-
}
|
|
833
|
-
}
|
|
834
|
-
} else {
|
|
835
|
-
fastLiteralSeqs.set(root, null);
|
|
836
|
-
return null;
|
|
837
|
-
}
|
|
838
|
-
const codes = Uint8Array.from(bytes);
|
|
839
|
-
const created = {
|
|
840
|
-
anchoredStart,
|
|
841
|
-
anchoredEnd,
|
|
842
|
-
codes,
|
|
843
|
-
insensitive,
|
|
844
|
-
spanAtZero: Object.freeze({ start: 0, end: codes.length })
|
|
845
|
-
};
|
|
846
|
-
fastLiteralSeqs.set(root, created);
|
|
847
|
-
return created;
|
|
848
|
-
}
|
|
849
|
-
function getSequenceNullNextTask(node) {
|
|
850
|
-
let cached = sequenceNullNextTasks.get(node);
|
|
851
|
-
if (!cached) {
|
|
852
|
-
let next = null;
|
|
853
|
-
for (let index = node.children.length - 1; index >= 0; index--) {
|
|
854
|
-
next = { kind: "node", node: node.children[index], next };
|
|
855
|
-
}
|
|
856
|
-
cached = next;
|
|
857
|
-
sequenceNullNextTasks.set(node, cached);
|
|
858
|
-
}
|
|
859
|
-
return cached;
|
|
860
|
-
}
|
|
861
|
-
var warmLedger = EreLedger.withPrevalidatedLimits({
|
|
862
|
-
patternBytes: Infinity,
|
|
863
|
-
subjectBytes: Infinity,
|
|
864
|
-
work: Infinity,
|
|
865
|
-
states: Infinity,
|
|
866
|
-
allocationUnits: Infinity,
|
|
867
|
-
captureBytes: Infinity,
|
|
868
|
-
captureSlots: Infinity
|
|
869
|
-
});
|
|
870
|
-
async function warmEreProgram(program) {
|
|
871
|
-
const root = resolveEreProgramUnchecked(program);
|
|
872
|
-
await prepareInitialCharacters(root, warmLedger);
|
|
873
|
-
}
|
|
874
|
-
function canFastSyncEreProgram(_program) {
|
|
875
|
-
return true;
|
|
876
|
-
}
|
|
877
|
-
function tryMatchEreAsciiRangeSync(program, buf, rStart, rEnd, ledger, signal, leftmostFirst = false, word = false, skipPerRowLedgerCharge = false) {
|
|
878
|
-
const root = resolveEreProgramUnchecked(program);
|
|
879
|
-
if (program.groups !== 0) {
|
|
880
|
-
if (!skipPerRowLedgerCharge || ledger.limits.work !== Infinity || ledger.limits.states !== Infinity || ledger.limits.allocationUnits !== Infinity || ledger.limits.captureBytes !== Infinity || ledger.limits.captureSlots !== Infinity) {
|
|
881
|
-
return null;
|
|
882
|
-
}
|
|
883
|
-
}
|
|
884
|
-
const initial = root.nullable ? void 0 : initialCharacters.get(root);
|
|
885
|
-
if (!root.nullable && !initial) return null;
|
|
886
|
-
const rLen = rEnd - rStart;
|
|
887
|
-
if (!skipPerRowLedgerCharge) {
|
|
888
|
-
ledger.check(signal);
|
|
889
|
-
ledger.admitInput("subjectBytes", rLen, signal);
|
|
890
|
-
ledger.charge("allocationUnits", rLen * 11 + 23, signal);
|
|
891
|
-
ledger.chargeWork(rLen * 4 + 4, signal);
|
|
892
|
-
}
|
|
893
|
-
const fastSeq = getFastEreLiteralSeq(root);
|
|
894
|
-
if (fastSeq !== null) {
|
|
895
|
-
const { anchoredStart, anchoredEnd, codes, insensitive, spanAtZero } = fastSeq;
|
|
896
|
-
const patLen = codes.length;
|
|
897
|
-
if (rLen < patLen || anchoredStart && anchoredEnd && rLen !== patLen) {
|
|
898
|
-
if (!skipPerRowLedgerCharge) ledger.chargeWork(1, signal);
|
|
899
|
-
return void 0;
|
|
900
|
-
}
|
|
901
|
-
if (anchoredStart) {
|
|
902
|
-
if (!skipPerRowLedgerCharge) ledger.chargeWork(1 + patLen, signal);
|
|
903
|
-
if (!insensitive) {
|
|
904
|
-
for (let i = 0; i < patLen; i++) {
|
|
905
|
-
if (buf[rStart + i] !== codes[i]) return void 0;
|
|
906
|
-
}
|
|
907
|
-
} else {
|
|
908
|
-
for (let i = 0; i < patLen; i++) {
|
|
909
|
-
if (foldAscii(buf[rStart + i]) !== codes[i]) return void 0;
|
|
910
|
-
}
|
|
911
|
-
}
|
|
912
|
-
if (word && patLen > 0 && patLen < rLen && isAsciiWord(buf[rStart + patLen])) return void 0;
|
|
913
|
-
return spanAtZero;
|
|
914
|
-
}
|
|
915
|
-
if (anchoredEnd && !word) {
|
|
916
|
-
const start = rLen - patLen;
|
|
917
|
-
if (!skipPerRowLedgerCharge) ledger.chargeWork(1 + patLen, signal);
|
|
918
|
-
if (!insensitive) {
|
|
919
|
-
for (let i = 0; i < patLen; i++) {
|
|
920
|
-
if (buf[rStart + start + i] !== codes[i]) return void 0;
|
|
921
|
-
}
|
|
922
|
-
} else {
|
|
923
|
-
for (let i = 0; i < patLen; i++) {
|
|
924
|
-
if (foldAscii(buf[rStart + start + i]) !== codes[i]) return void 0;
|
|
925
|
-
}
|
|
926
|
-
}
|
|
927
|
-
return start === 0 ? spanAtZero : { start, end: rLen };
|
|
928
|
-
}
|
|
929
|
-
}
|
|
930
|
-
if (ledger.limits.work === Infinity && ledger.limits.states === Infinity && ledger.limits.allocationUnits === Infinity) {
|
|
931
|
-
const fastPA = getFastErePrefixAlt(root);
|
|
932
|
-
if (fastPA !== null && fastPA.prefix.length > 0) {
|
|
933
|
-
const { anchoredStart, anchoredEnd, prefix, alts } = fastPA;
|
|
934
|
-
const pLen = prefix.length;
|
|
935
|
-
const p0 = prefix[0];
|
|
936
|
-
let searchPos = rStart;
|
|
937
|
-
const maxSearch = anchoredStart ? rStart : rEnd - pLen;
|
|
938
|
-
while (searchPos <= maxSearch) {
|
|
939
|
-
const foundAbs = anchoredStart ? buf[rStart] === p0 ? rStart : -1 : buf.indexOf(p0, searchPos);
|
|
940
|
-
if (foundAbs < 0 || foundAbs > maxSearch) break;
|
|
941
|
-
const relStart = foundAbs - rStart;
|
|
942
|
-
let prefixOk = true;
|
|
943
|
-
for (let k = 1; k < pLen; k++) {
|
|
944
|
-
if (buf[foundAbs + k] !== prefix[k]) {
|
|
945
|
-
prefixOk = false;
|
|
946
|
-
break;
|
|
947
|
-
}
|
|
948
|
-
}
|
|
949
|
-
if (prefixOk && (!word || relStart === 0 || !isAsciiWord(buf[foundAbs - 1]))) {
|
|
950
|
-
if (alts === null) {
|
|
951
|
-
const relEnd = relStart + pLen;
|
|
952
|
-
if ((!anchoredEnd || relEnd === rLen) && (!word || relEnd === rLen || !isAsciiWord(buf[rStart + relEnd]))) {
|
|
953
|
-
return { start: relStart, end: relEnd };
|
|
954
|
-
}
|
|
955
|
-
} else {
|
|
956
|
-
let bestEnd = -1;
|
|
957
|
-
const afterPrefixAbs = foundAbs + pLen;
|
|
958
|
-
for (let a = 0; a < alts.length; a++) {
|
|
959
|
-
const alt = alts[a];
|
|
960
|
-
const aLen = alt.length;
|
|
961
|
-
if (afterPrefixAbs + aLen > rEnd) continue;
|
|
962
|
-
let altOk = true;
|
|
963
|
-
for (let k = 0; k < aLen; k++) {
|
|
964
|
-
if (buf[afterPrefixAbs + k] !== alt[k]) {
|
|
965
|
-
altOk = false;
|
|
966
|
-
break;
|
|
967
|
-
}
|
|
968
|
-
}
|
|
969
|
-
if (!altOk) continue;
|
|
970
|
-
const relEnd = relStart + pLen + aLen;
|
|
971
|
-
if (anchoredEnd && relEnd !== rLen) continue;
|
|
972
|
-
if (word && relEnd < rLen && isAsciiWord(buf[rStart + relEnd])) continue;
|
|
973
|
-
if (leftmostFirst) {
|
|
974
|
-
bestEnd = relEnd;
|
|
975
|
-
break;
|
|
976
|
-
}
|
|
977
|
-
if (relEnd > bestEnd) bestEnd = relEnd;
|
|
978
|
-
}
|
|
979
|
-
if (bestEnd >= 0) return { start: relStart, end: bestEnd };
|
|
980
|
-
}
|
|
981
|
-
}
|
|
982
|
-
if (anchoredStart) break;
|
|
983
|
-
searchPos = foundAbs + 1;
|
|
984
|
-
}
|
|
985
|
-
return void 0;
|
|
986
|
-
}
|
|
987
|
-
}
|
|
988
|
-
const unbounded = skipPerRowLedgerCharge && ledger.limits.work === Infinity && ledger.limits.states === Infinity && ledger.limits.allocationUnits === Infinity;
|
|
989
|
-
return tryMatchEreAsciiRangeNfaSync(root, initial, buf, rStart, rLen, ledger, signal, leftmostFirst, word, unbounded);
|
|
990
|
-
}
|
|
991
|
-
function tryMatchEreAsciiRangeNfaSync(root, initial, buf, rStart, rLen, ledger, signal, leftmostFirst, word, unbounded = false) {
|
|
992
|
-
let firstLitCode = -1;
|
|
993
|
-
let secondLitCode = -1;
|
|
994
|
-
let rootSeqLen = 0;
|
|
995
|
-
if (root.kind === "sequence" && root.children.length >= 1) {
|
|
996
|
-
const c0 = root.children[0];
|
|
997
|
-
if (c0.kind === "literal" && !c0.insensitive) {
|
|
998
|
-
firstLitCode = c0.code;
|
|
999
|
-
if (root.children.length >= 2) {
|
|
1000
|
-
const c1 = root.children[1];
|
|
1001
|
-
if (c1.kind === "literal" && !c1.insensitive) {
|
|
1002
|
-
secondLitCode = c1.code;
|
|
1003
|
-
rootSeqLen = root.children.length;
|
|
1004
|
-
}
|
|
1005
|
-
}
|
|
1006
|
-
}
|
|
1007
|
-
}
|
|
1008
|
-
if (unbounded) {
|
|
1009
|
-
if (signal?.aborted) throw signal.reason;
|
|
1010
|
-
const pendingPos = [];
|
|
1011
|
-
const pendingTask = [];
|
|
1012
|
-
const push2 = (position, next) => {
|
|
1013
|
-
pendingPos.push(position);
|
|
1014
|
-
pendingTask.push(next);
|
|
1015
|
-
};
|
|
1016
|
-
const rootTask2 = root.kind === "sequence" ? getSequenceNullNextTask(root) : { kind: "node", node: root, next: null };
|
|
1017
|
-
const anchored = root.kind === "start" || root.kind === "sequence" && root.children[0]?.kind === "start";
|
|
1018
|
-
const maxStart2 = anchored ? 0 : rLen;
|
|
1019
|
-
for (let start = 0; start <= maxStart2; start++) {
|
|
1020
|
-
if (firstLitCode >= 0 && !anchored) {
|
|
1021
|
-
const found = buf.indexOf(firstLitCode, rStart + start);
|
|
1022
|
-
if (found < 0 || found >= rStart + rLen) break;
|
|
1023
|
-
start = found - rStart;
|
|
1024
|
-
} else if (initial) {
|
|
1025
|
-
const firstCode = start < rLen ? buf[rStart + start] : -1;
|
|
1026
|
-
if (firstCode < 0 || !initial[firstCode]) continue;
|
|
1027
|
-
}
|
|
1028
|
-
if (word && start > 0 && isAsciiWord(buf[rStart + start - 1])) continue;
|
|
1029
|
-
if (secondLitCode >= 0 && (start + 1 >= rLen || buf[rStart + start + 1] !== secondLitCode)) continue;
|
|
1030
|
-
push2(start, rootTask2);
|
|
1031
|
-
let bestPos = -1;
|
|
1032
|
-
while (pendingPos.length > 0) {
|
|
1033
|
-
const statePos = pendingPos.pop();
|
|
1034
|
-
const current = pendingTask.pop();
|
|
1035
|
-
if (current === null) {
|
|
1036
|
-
if (word && statePos < rLen && isAsciiWord(buf[rStart + statePos])) continue;
|
|
1037
|
-
if (leftmostFirst) {
|
|
1038
|
-
bestPos = statePos;
|
|
1039
|
-
pendingPos.length = 0;
|
|
1040
|
-
pendingTask.length = 0;
|
|
1041
|
-
break;
|
|
1042
|
-
}
|
|
1043
|
-
if (statePos > bestPos) bestPos = statePos;
|
|
1044
|
-
continue;
|
|
1045
|
-
}
|
|
1046
|
-
if (current.kind === "repeat") {
|
|
1047
|
-
const { node: node2, count } = current;
|
|
1048
|
-
if (count === 0 && node2.child.kind === "dot" && node2.max === Infinity) {
|
|
1049
|
-
let maxDotPos = rLen;
|
|
1050
|
-
if (leftmostFirst) {
|
|
1051
|
-
const nl = buf.indexOf(10, rStart + statePos);
|
|
1052
|
-
if (nl >= 0 && nl < rStart + rLen) maxDotPos = nl - rStart;
|
|
1053
|
-
}
|
|
1054
|
-
const minDotPos = statePos + node2.min;
|
|
1055
|
-
if (minDotPos <= maxDotPos) {
|
|
1056
|
-
const nextTask = current.next;
|
|
1057
|
-
if (nextTask && nextTask.kind === "node" && nextTask.node.kind === "literal" && !nextTask.node.insensitive) {
|
|
1058
|
-
const targetCode = nextTask.node.code;
|
|
1059
|
-
const afterLit = nextTask.next;
|
|
1060
|
-
for (let p = minDotPos; p < maxDotPos; p++) {
|
|
1061
|
-
if (buf[rStart + p] === targetCode) push2(p + 1, afterLit);
|
|
1062
|
-
}
|
|
1063
|
-
} else {
|
|
1064
|
-
for (let p = minDotPos; p <= maxDotPos; p++) {
|
|
1065
|
-
push2(p, nextTask);
|
|
1066
|
-
}
|
|
1067
|
-
}
|
|
1068
|
-
}
|
|
1069
|
-
continue;
|
|
1070
|
-
}
|
|
1071
|
-
if (count >= node2.min) push2(statePos, current.next);
|
|
1072
|
-
const noProgress = count > 0 && statePos === current.previous;
|
|
1073
|
-
if (count < node2.max && (!noProgress || count < node2.min)) {
|
|
1074
|
-
const repeat = { kind: "repeat", node: node2, count: count + 1, previous: statePos, next: current.next };
|
|
1075
|
-
push2(statePos, { kind: "node", node: node2.child, next: repeat });
|
|
1076
|
-
}
|
|
1077
|
-
continue;
|
|
1078
|
-
}
|
|
1079
|
-
if (current.kind === "close") return null;
|
|
1080
|
-
const node = current.node;
|
|
1081
|
-
switch (node.kind) {
|
|
1082
|
-
case "empty":
|
|
1083
|
-
push2(statePos, current.next);
|
|
1084
|
-
break;
|
|
1085
|
-
case "start":
|
|
1086
|
-
if (statePos === 0) push2(statePos, current.next);
|
|
1087
|
-
break;
|
|
1088
|
-
case "end":
|
|
1089
|
-
if (statePos === rLen) push2(statePos, current.next);
|
|
1090
|
-
break;
|
|
1091
|
-
case "dot":
|
|
1092
|
-
case "literal":
|
|
1093
|
-
case "set": {
|
|
1094
|
-
if (statePos < rLen) {
|
|
1095
|
-
const code = buf[rStart + statePos];
|
|
1096
|
-
if (node.kind === "dot" && (!leftmostFirst || code !== 10) || node.kind === "literal" && (node.insensitive ? foldAscii(node.code) === foldAscii(code) : node.code === code) || node.kind === "set" && (code < 128 ? node.members[code] : node.nonAscii)) {
|
|
1097
|
-
push2(statePos + 1, current.next);
|
|
1098
|
-
}
|
|
1099
|
-
}
|
|
1100
|
-
break;
|
|
1101
|
-
}
|
|
1102
|
-
case "sequence": {
|
|
1103
|
-
if (current.next === null) {
|
|
1104
|
-
push2(statePos, getSequenceNullNextTask(node));
|
|
1105
|
-
} else {
|
|
1106
|
-
let next = current.next;
|
|
1107
|
-
for (let index = node.children.length - 1; index >= 0; index--) {
|
|
1108
|
-
next = { kind: "node", node: node.children[index], next };
|
|
1109
|
-
}
|
|
1110
|
-
push2(statePos, next);
|
|
1111
|
-
}
|
|
1112
|
-
break;
|
|
1113
|
-
}
|
|
1114
|
-
case "alternative":
|
|
1115
|
-
for (let index = node.children.length - 1; index >= 0; index--) {
|
|
1116
|
-
push2(statePos, { kind: "node", node: node.children[index], next: current.next });
|
|
1117
|
-
}
|
|
1118
|
-
break;
|
|
1119
|
-
case "group":
|
|
1120
|
-
push2(statePos, { kind: "node", node: node.child, next: current.next });
|
|
1121
|
-
break;
|
|
1122
|
-
case "repeat":
|
|
1123
|
-
push2(statePos, { kind: "repeat", node, count: 0, previous: -1, next: current.next });
|
|
1124
|
-
break;
|
|
1125
|
-
}
|
|
1126
|
-
}
|
|
1127
|
-
if (bestPos >= 0) return { start, end: bestPos };
|
|
1128
|
-
}
|
|
1129
|
-
return void 0;
|
|
1130
|
-
}
|
|
1131
|
-
const pending = [];
|
|
1132
|
-
const push = (position, next) => {
|
|
1133
|
-
ledger.charge("states", 1, signal);
|
|
1134
|
-
ledger.charge("allocationUnits", 5, signal);
|
|
1135
|
-
pending.push({ position, task: next, captures: SINGLE_NULL_CAPTURES, histories: SINGLE_NULL_HISTORIES });
|
|
1136
|
-
};
|
|
1137
|
-
const rootTask = root.kind === "sequence" ? getSequenceNullNextTask(root) : { kind: "node", node: root, next: null };
|
|
1138
|
-
const maxStart = root.kind === "start" || root.kind === "sequence" && root.children[0]?.kind === "start" ? 0 : rLen;
|
|
1139
|
-
for (let start = 0; start <= maxStart; start++) {
|
|
1140
|
-
if (initial) {
|
|
1141
|
-
ledger.chargeWork(1, signal);
|
|
1142
|
-
const firstCode = start < rLen ? buf[rStart + start] : -1;
|
|
1143
|
-
if (firstCode < 0 || !initial[firstCode]) continue;
|
|
1144
|
-
}
|
|
1145
|
-
if (word) {
|
|
1146
|
-
ledger.chargeWork(1, signal);
|
|
1147
|
-
if (start > 0 && isAsciiWord(buf[rStart + start - 1])) continue;
|
|
1148
|
-
}
|
|
1149
|
-
if (secondLitCode >= 0) {
|
|
1150
|
-
if (start + 1 >= rLen || buf[rStart + start + 1] !== secondLitCode) {
|
|
1151
|
-
ledger.chargeWork(3 + rootSeqLen, signal);
|
|
1152
|
-
ledger.charge("states", 3, signal);
|
|
1153
|
-
ledger.charge("allocationUnits", (rootSeqLen + 1) * 5 + 15, signal);
|
|
1154
|
-
continue;
|
|
1155
|
-
}
|
|
1156
|
-
}
|
|
1157
|
-
if (root.kind === "sequence") {
|
|
1158
|
-
ledger.charge("allocationUnits", 5, signal);
|
|
1159
|
-
ledger.charge("states", 1, signal);
|
|
1160
|
-
ledger.charge("allocationUnits", 5, signal);
|
|
1161
|
-
ledger.chargeWork(1 + root.children.length, signal);
|
|
1162
|
-
ledger.charge("allocationUnits", root.children.length * 5, signal);
|
|
1163
|
-
push(start, rootTask);
|
|
1164
|
-
} else {
|
|
1165
|
-
ledger.charge("allocationUnits", 5, signal);
|
|
1166
|
-
push(start, rootTask);
|
|
1167
|
-
}
|
|
1168
|
-
let bestPos = -1;
|
|
1169
|
-
while (pending.length > 0) {
|
|
1170
|
-
if (ledger.workAllowanceUntilCheckpoint(signal) < 64 && !ledger.advanceSyncCheckpointIfNoExternalYield(signal)) return null;
|
|
1171
|
-
ledger.chargeWork(1, signal);
|
|
1172
|
-
const state = pending.pop();
|
|
1173
|
-
const current = state.task;
|
|
1174
|
-
if (current === null) {
|
|
1175
|
-
if (word && state.position < rLen && isAsciiWord(buf[rStart + state.position])) continue;
|
|
1176
|
-
if (leftmostFirst) {
|
|
1177
|
-
bestPos = state.position;
|
|
1178
|
-
pending.length = 0;
|
|
1179
|
-
break;
|
|
1180
|
-
}
|
|
1181
|
-
if (state.position > bestPos) bestPos = state.position;
|
|
1182
|
-
continue;
|
|
1183
|
-
}
|
|
1184
|
-
if (current.kind === "repeat") {
|
|
1185
|
-
const { node: node2, count } = current;
|
|
1186
|
-
if (count >= node2.min) push(state.position, current.next);
|
|
1187
|
-
const noProgress = count > 0 && state.position === current.previous;
|
|
1188
|
-
if (count < node2.max && (!noProgress || count < node2.min)) {
|
|
1189
|
-
ledger.charge("allocationUnits", 10, signal);
|
|
1190
|
-
const repeat = { kind: "repeat", node: node2, count: count + 1, previous: state.position, next: current.next };
|
|
1191
|
-
push(state.position, { kind: "node", node: node2.child, next: repeat });
|
|
1192
|
-
}
|
|
1193
|
-
continue;
|
|
1194
|
-
}
|
|
1195
|
-
if (current.kind === "close") return null;
|
|
1196
|
-
const node = current.node;
|
|
1197
|
-
switch (node.kind) {
|
|
1198
|
-
case "empty":
|
|
1199
|
-
push(state.position, current.next);
|
|
1200
|
-
break;
|
|
1201
|
-
case "start":
|
|
1202
|
-
if (state.position === 0) push(state.position, current.next);
|
|
1203
|
-
break;
|
|
1204
|
-
case "end":
|
|
1205
|
-
if (state.position === rLen) push(state.position, current.next);
|
|
1206
|
-
break;
|
|
1207
|
-
case "dot":
|
|
1208
|
-
case "literal":
|
|
1209
|
-
case "set": {
|
|
1210
|
-
if (state.position < rLen) {
|
|
1211
|
-
const code = buf[rStart + state.position];
|
|
1212
|
-
if (node.kind === "dot" && (!leftmostFirst || code !== 10) || node.kind === "literal" && (node.insensitive ? foldAscii(node.code) === foldAscii(code) : node.code === code) || node.kind === "set" && (code < 128 ? node.members[code] : node.nonAscii)) {
|
|
1213
|
-
push(state.position + 1, current.next);
|
|
1214
|
-
}
|
|
1215
|
-
}
|
|
1216
|
-
break;
|
|
1217
|
-
}
|
|
1218
|
-
case "sequence": {
|
|
1219
|
-
if (ledger.workAllowanceUntilCheckpoint(signal) < node.children.length + 4 && !ledger.advanceSyncCheckpointIfNoExternalYield(signal)) return null;
|
|
1220
|
-
ledger.chargeWork(node.children.length, signal);
|
|
1221
|
-
ledger.charge("allocationUnits", node.children.length * 5, signal);
|
|
1222
|
-
if (current.next === null) {
|
|
1223
|
-
push(state.position, getSequenceNullNextTask(node));
|
|
1224
|
-
} else {
|
|
1225
|
-
let next = current.next;
|
|
1226
|
-
for (let index = node.children.length - 1; index >= 0; index--) {
|
|
1227
|
-
next = { kind: "node", node: node.children[index], next };
|
|
1228
|
-
}
|
|
1229
|
-
push(state.position, next);
|
|
1230
|
-
}
|
|
1231
|
-
break;
|
|
1232
|
-
}
|
|
1233
|
-
case "alternative":
|
|
1234
|
-
if (ledger.workAllowanceUntilCheckpoint(signal) < node.children.length + 4 && !ledger.advanceSyncCheckpointIfNoExternalYield(signal)) return null;
|
|
1235
|
-
for (let index = node.children.length - 1; index >= 0; index--) {
|
|
1236
|
-
ledger.chargeWork(1, signal);
|
|
1237
|
-
ledger.charge("allocationUnits", 5, signal);
|
|
1238
|
-
push(state.position, { kind: "node", node: node.children[index], next: current.next });
|
|
1239
|
-
}
|
|
1240
|
-
break;
|
|
1241
|
-
case "group":
|
|
1242
|
-
ledger.charge("allocationUnits", 5, signal);
|
|
1243
|
-
push(state.position, { kind: "node", node: node.child, next: current.next });
|
|
1244
|
-
break;
|
|
1245
|
-
case "repeat":
|
|
1246
|
-
ledger.charge("allocationUnits", 5, signal);
|
|
1247
|
-
push(state.position, { kind: "repeat", node, count: 0, previous: -1, next: current.next });
|
|
1248
|
-
break;
|
|
1249
|
-
}
|
|
1250
|
-
}
|
|
1251
|
-
if (bestPos >= 0) {
|
|
1252
|
-
ledger.charge("allocationUnits", 4, signal);
|
|
1253
|
-
ledger.check(signal);
|
|
1254
|
-
return { start, end: bestPos };
|
|
1255
|
-
}
|
|
1256
|
-
}
|
|
1257
|
-
return void 0;
|
|
1258
|
-
}
|
|
1259
|
-
async function prepareInitialCharacters(root, ledger, signal) {
|
|
1260
|
-
if (root.nullable) return void 0;
|
|
1261
|
-
const cached = initialCharacters.get(root);
|
|
1262
|
-
if (cached) return cached;
|
|
1263
|
-
ledger.charge("work", 129, signal);
|
|
1264
|
-
ledger.charge("allocationUnits", 133, signal);
|
|
1265
|
-
{
|
|
1266
|
-
const c = ledger.checkpoint(signal);
|
|
1267
|
-
if (c) await c;
|
|
1268
|
-
}
|
|
1269
|
-
const codes = new Array(129).fill(false);
|
|
1270
|
-
const pending = [root];
|
|
1271
|
-
while (pending.length > 0) {
|
|
1272
|
-
ledger.charge("work", 1, signal);
|
|
1273
|
-
{
|
|
1274
|
-
const c = ledger.checkpoint(signal);
|
|
1275
|
-
if (c) await c;
|
|
1276
|
-
}
|
|
1277
|
-
const node = pending.pop();
|
|
1278
|
-
switch (node.kind) {
|
|
1279
|
-
case "literal": {
|
|
1280
|
-
codes[node.code] = true;
|
|
1281
|
-
const folded = foldAscii(node.code);
|
|
1282
|
-
if (node.insensitive && folded >= 97 && folded <= 122) {
|
|
1283
|
-
codes[folded] = codes[folded - 32] = true;
|
|
1284
|
-
}
|
|
1285
|
-
break;
|
|
1286
|
-
}
|
|
1287
|
-
case "dot":
|
|
1288
|
-
case "set":
|
|
1289
|
-
for (let code = 0; code < codes.length; code++) {
|
|
1290
|
-
ledger.charge("work", 1, signal);
|
|
1291
|
-
{
|
|
1292
|
-
const c = ledger.checkpoint(signal);
|
|
1293
|
-
if (c) await c;
|
|
1294
|
-
}
|
|
1295
|
-
if (node.kind === "dot" || node.kind === "set" && (code < 128 ? node.members[code] : node.nonAscii)) codes[code] = true;
|
|
1296
|
-
}
|
|
1297
|
-
break;
|
|
1298
|
-
case "group":
|
|
1299
|
-
case "repeat":
|
|
1300
|
-
if (node.kind === "repeat" && node.max === 0) break;
|
|
1301
|
-
ledger.charge("allocationUnits", 1, signal);
|
|
1302
|
-
pending.push(node.child);
|
|
1303
|
-
break;
|
|
1304
|
-
case "sequence":
|
|
1305
|
-
case "alternative":
|
|
1306
|
-
for (const child of node.children) {
|
|
1307
|
-
ledger.charge("work", 1, signal);
|
|
1308
|
-
ledger.charge("allocationUnits", 1, signal);
|
|
1309
|
-
{
|
|
1310
|
-
const c = ledger.checkpoint(signal);
|
|
1311
|
-
if (c) await c;
|
|
1312
|
-
}
|
|
1313
|
-
pending.push(child);
|
|
1314
|
-
if (node.kind === "sequence" && !child.nullable) break;
|
|
1315
|
-
}
|
|
1316
|
-
break;
|
|
1317
|
-
}
|
|
1318
|
-
}
|
|
1319
|
-
ledger.check(signal);
|
|
1320
|
-
initialCharacters.set(root, Object.freeze(codes));
|
|
1321
|
-
return codes;
|
|
1322
|
-
}
|
|
1323
|
-
function spanOrder(left, right) {
|
|
1324
|
-
if (left === null) return right === null ? 0 : -1;
|
|
1325
|
-
if (right === null) return 1;
|
|
1326
|
-
const length = left.end - left.start - (right.end - right.start);
|
|
1327
|
-
return length === 0 ? right.start - left.start : length;
|
|
1328
|
-
}
|
|
1329
|
-
async function historySpans(history, ledger, signal) {
|
|
1330
|
-
ledger.charge("work", history.count, signal);
|
|
1331
|
-
ledger.charge("allocationUnits", history.count + 1, signal);
|
|
1332
|
-
{
|
|
1333
|
-
const c = ledger.checkpoint(signal);
|
|
1334
|
-
if (c) await c;
|
|
1335
|
-
}
|
|
1336
|
-
const spans = new Array(history.count);
|
|
1337
|
-
for (let entry = history; entry !== null; entry = entry.previous) {
|
|
1338
|
-
ledger.charge("work", 1, signal);
|
|
1339
|
-
{
|
|
1340
|
-
const c = ledger.checkpoint(signal);
|
|
1341
|
-
if (c) await c;
|
|
1342
|
-
}
|
|
1343
|
-
spans[entry.count - 1] = entry.span;
|
|
1344
|
-
}
|
|
1345
|
-
return spans;
|
|
1346
|
-
}
|
|
1347
|
-
async function historyOrder(left, right, ledger, signal) {
|
|
1348
|
-
const leftCount = left?.count ?? 0;
|
|
1349
|
-
const rightCount = right?.count ?? 0;
|
|
1350
|
-
if (left === null || right === null) return leftCount - rightCount;
|
|
1351
|
-
const leftSpans = await historySpans(left, ledger, signal);
|
|
1352
|
-
const rightSpans = await historySpans(right, ledger, signal);
|
|
1353
|
-
for (let ordinal = 0; ordinal < Math.min(leftCount, rightCount); ordinal++) {
|
|
1354
|
-
ledger.charge("work", 1, signal);
|
|
1355
|
-
{
|
|
1356
|
-
const c = ledger.checkpoint(signal);
|
|
1357
|
-
if (c) await c;
|
|
1358
|
-
}
|
|
1359
|
-
const compared = spanOrder(leftSpans[ordinal], rightSpans[ordinal]);
|
|
1360
|
-
if (compared !== 0) return compared;
|
|
1361
|
-
}
|
|
1362
|
-
return leftCount - rightCount;
|
|
1363
|
-
}
|
|
1364
|
-
async function preferred(candidate, incumbent, ledger, signal) {
|
|
1365
|
-
if (candidate.position !== incumbent.position) return candidate.position > incumbent.position;
|
|
1366
|
-
for (let group = 1; group < candidate.captures.length; group++) {
|
|
1367
|
-
ledger.charge("work", 1, signal);
|
|
1368
|
-
{
|
|
1369
|
-
const c = ledger.checkpoint(signal);
|
|
1370
|
-
if (c) await c;
|
|
1371
|
-
}
|
|
1372
|
-
const compared = await historyOrder(candidate.histories[group], incumbent.histories[group], ledger, signal);
|
|
1373
|
-
if (compared !== 0) return compared > 0;
|
|
1374
|
-
}
|
|
1375
|
-
return false;
|
|
1376
|
-
}
|
|
1377
|
-
function resetDescendants(node, previous, ledger, signal) {
|
|
1378
|
-
if (ledger.charge === EreLedger.prototype.charge && ledger.workAllowanceUntilCheckpoint(signal) >= previous.length + 32) {
|
|
1379
|
-
ledger.charge("work", previous.length, signal);
|
|
1380
|
-
ledger.charge("allocationUnits", previous.length + 3, signal);
|
|
1381
|
-
const captures = previous.slice();
|
|
1382
|
-
ledger.charge("work", 1, signal);
|
|
1383
|
-
if (node.kind === "group") {
|
|
1384
|
-
captures[node.index] = null;
|
|
1385
|
-
if (!node.child.captured) return captures;
|
|
1386
|
-
}
|
|
1387
|
-
const pending = [node];
|
|
1388
|
-
while (pending.length > 0 && ledger.workAllowanceUntilCheckpoint(signal) >= 16) {
|
|
1389
|
-
ledger.chargeWork(1, signal);
|
|
1390
|
-
const current = pending.pop();
|
|
1391
|
-
if (current.kind === "group") captures[current.index] = null;
|
|
1392
|
-
if (current.kind === "group" || current.kind === "repeat") {
|
|
1393
|
-
if (current.child.captured) {
|
|
1394
|
-
ledger.charge("allocationUnits", 1, signal);
|
|
1395
|
-
pending.push(current.child);
|
|
1396
|
-
}
|
|
1397
|
-
} else if (current.kind === "sequence" || current.kind === "alternative") {
|
|
1398
|
-
for (const child of current.children) {
|
|
1399
|
-
ledger.chargeWork(1, signal);
|
|
1400
|
-
if (child.captured) {
|
|
1401
|
-
ledger.charge("allocationUnits", 1, signal);
|
|
1402
|
-
pending.push(child);
|
|
1403
|
-
}
|
|
1404
|
-
}
|
|
1405
|
-
}
|
|
1406
|
-
}
|
|
1407
|
-
if (pending.length === 0) return captures;
|
|
1408
|
-
}
|
|
1409
|
-
return (async () => {
|
|
1410
|
-
ledger.charge("work", previous.length, signal);
|
|
1411
|
-
ledger.charge("allocationUnits", previous.length + 3, signal);
|
|
1412
|
-
{
|
|
1413
|
-
const c = ledger.checkpoint(signal);
|
|
1414
|
-
if (c) await c;
|
|
1415
|
-
}
|
|
1416
|
-
const captures = previous.slice();
|
|
1417
|
-
const pending = [node];
|
|
1418
|
-
while (pending.length > 0) {
|
|
1419
|
-
ledger.charge("work", 1, signal);
|
|
1420
|
-
{
|
|
1421
|
-
const c = ledger.checkpoint(signal);
|
|
1422
|
-
if (c) await c;
|
|
1423
|
-
}
|
|
1424
|
-
const current = pending.pop();
|
|
1425
|
-
if (current.kind === "group") captures[current.index] = null;
|
|
1426
|
-
if (current.kind === "group" || current.kind === "repeat") {
|
|
1427
|
-
if (current.child.captured) {
|
|
1428
|
-
ledger.charge("allocationUnits", 1, signal);
|
|
1429
|
-
pending.push(current.child);
|
|
1430
|
-
}
|
|
1431
|
-
} else if (current.kind === "sequence" || current.kind === "alternative") {
|
|
1432
|
-
for (const child of current.children) {
|
|
1433
|
-
ledger.charge("work", 1, signal);
|
|
1434
|
-
{
|
|
1435
|
-
const c = ledger.checkpoint(signal);
|
|
1436
|
-
if (c) await c;
|
|
1437
|
-
}
|
|
1438
|
-
if (child.captured) {
|
|
1439
|
-
ledger.charge("allocationUnits", 1, signal);
|
|
1440
|
-
pending.push(child);
|
|
1441
|
-
}
|
|
1442
|
-
}
|
|
1443
|
-
}
|
|
1444
|
-
}
|
|
1445
|
-
return captures;
|
|
1446
|
-
})();
|
|
1447
|
-
}
|
|
1448
|
-
var ereLinearChainCache = /* @__PURE__ */ new WeakMap();
|
|
1449
|
-
function ereAtomMatchesCode(atom, code) {
|
|
1450
|
-
if (atom.kind === "literal") {
|
|
1451
|
-
return atom.insensitive ? foldAscii(atom.code) === foldAscii(code) : atom.code === code;
|
|
1452
|
-
}
|
|
1453
|
-
return code < 128 ? atom.members[code] : atom.nonAscii;
|
|
1454
|
-
}
|
|
1455
|
-
function ereAtomsDisjoint(a, b) {
|
|
1456
|
-
for (let code = 0; code <= 128; code++) {
|
|
1457
|
-
if (ereAtomMatchesCode(a, code) && ereAtomMatchesCode(b, code)) return false;
|
|
1458
|
-
}
|
|
1459
|
-
return true;
|
|
1460
|
-
}
|
|
1461
|
-
function admitSynchronousWork(ledger, amount, signal) {
|
|
1462
|
-
if (ledger.workAllowanceUntilCheckpoint(signal) < amount) {
|
|
1463
|
-
ledger.check(signal);
|
|
1464
|
-
return false;
|
|
1465
|
-
}
|
|
1466
|
-
ledger.chargeWork(amount, signal);
|
|
1467
|
-
return true;
|
|
1468
|
-
}
|
|
1469
|
-
function compileEreLinearChain(root, ledger, signal) {
|
|
1470
|
-
if (!admitSynchronousWork(ledger, 1, signal)) return void 0;
|
|
1471
|
-
const cached = ereLinearChainCache.get(root);
|
|
1472
|
-
if (cached !== void 0) return cached;
|
|
1473
|
-
ledger.charge("allocationUnits", 3, signal);
|
|
1474
|
-
let anchoredStart = false;
|
|
1475
|
-
let anchoredEnd = false;
|
|
1476
|
-
let seenConsuming = false;
|
|
1477
|
-
const steps = [];
|
|
1478
|
-
const pending = [root];
|
|
1479
|
-
let supported = true;
|
|
1480
|
-
while (pending.length > 0 && supported) {
|
|
1481
|
-
if (!admitSynchronousWork(ledger, 1, signal)) return void 0;
|
|
1482
|
-
const node = pending.pop();
|
|
1483
|
-
switch (node.kind) {
|
|
1484
|
-
case "start":
|
|
1485
|
-
if (seenConsuming || steps.length > 0) {
|
|
1486
|
-
supported = false;
|
|
1487
|
-
break;
|
|
1488
|
-
}
|
|
1489
|
-
anchoredStart = true;
|
|
1490
|
-
break;
|
|
1491
|
-
case "end":
|
|
1492
|
-
anchoredEnd = true;
|
|
1493
|
-
break;
|
|
1494
|
-
case "sequence":
|
|
1495
|
-
if (!admitSynchronousWork(ledger, node.children.length, signal)) return void 0;
|
|
1496
|
-
ledger.charge("allocationUnits", node.children.length, signal);
|
|
1497
|
-
for (let i = node.children.length - 1; i >= 0; i--) pending.push(node.children[i]);
|
|
1498
|
-
break;
|
|
1499
|
-
case "group":
|
|
1500
|
-
if (anchoredEnd) {
|
|
1501
|
-
supported = false;
|
|
1502
|
-
break;
|
|
1503
|
-
}
|
|
1504
|
-
ledger.charge("allocationUnits", 7, signal);
|
|
1505
|
-
steps.push({ kind: "groupOpen", index: node.index });
|
|
1506
|
-
pending.push({ kind: "groupClose", index: node.index }, node.child);
|
|
1507
|
-
break;
|
|
1508
|
-
case "groupClose":
|
|
1509
|
-
ledger.charge("allocationUnits", 1, signal);
|
|
1510
|
-
steps.push(node);
|
|
1511
|
-
break;
|
|
1512
|
-
case "literal":
|
|
1513
|
-
case "set":
|
|
1514
|
-
if (anchoredEnd) {
|
|
1515
|
-
supported = false;
|
|
1516
|
-
break;
|
|
1517
|
-
}
|
|
1518
|
-
seenConsuming = true;
|
|
1519
|
-
ledger.charge("allocationUnits", 3, signal);
|
|
1520
|
-
steps.push({ kind: "char", atom: node });
|
|
1521
|
-
break;
|
|
1522
|
-
case "repeat":
|
|
1523
|
-
if (anchoredEnd || node.min < 1 || node.max !== Infinity || node.child.kind !== "literal" && node.child.kind !== "set") {
|
|
1524
|
-
supported = false;
|
|
1525
|
-
break;
|
|
1526
|
-
}
|
|
1527
|
-
seenConsuming = true;
|
|
1528
|
-
ledger.charge("allocationUnits", 4, signal);
|
|
1529
|
-
steps.push({ kind: "repeat", atom: node.child, min: node.min });
|
|
1530
|
-
break;
|
|
1531
|
-
default:
|
|
1532
|
-
supported = false;
|
|
1533
|
-
}
|
|
1534
|
-
}
|
|
1535
|
-
let firstAtom;
|
|
1536
|
-
for (let i = steps.length - 1; supported && i >= 0; i--) {
|
|
1537
|
-
if (!admitSynchronousWork(ledger, 1, signal)) return void 0;
|
|
1538
|
-
const step = steps[i];
|
|
1539
|
-
if (step.kind !== "char" && step.kind !== "repeat") continue;
|
|
1540
|
-
if (step.kind === "repeat" && firstAtom) {
|
|
1541
|
-
if (!admitSynchronousWork(ledger, 129, signal)) return void 0;
|
|
1542
|
-
if (!ereAtomsDisjoint(step.atom, firstAtom)) supported = false;
|
|
1543
|
-
}
|
|
1544
|
-
firstAtom = step.atom;
|
|
1545
|
-
}
|
|
1546
|
-
if (!admitSynchronousWork(ledger, 1, signal)) return void 0;
|
|
1547
|
-
ledger.charge("allocationUnits", supported && seenConsuming ? 6 : 2, signal);
|
|
1548
|
-
if (!supported || !seenConsuming) {
|
|
1549
|
-
ereLinearChainCache.set(root, null);
|
|
1550
|
-
return null;
|
|
1551
|
-
}
|
|
1552
|
-
const compiled = { anchoredStart, anchoredEnd, steps, firstAtom };
|
|
1553
|
-
ereLinearChainCache.set(root, compiled);
|
|
1554
|
-
return compiled;
|
|
1555
|
-
}
|
|
1556
|
-
function tryMatchEreLinearChainSync(program, root, subject, ledger, signal) {
|
|
1557
|
-
const chain = compileEreLinearChain(root, ledger, signal);
|
|
1558
|
-
if (!chain) return void 0;
|
|
1559
|
-
const width = program.groups + 1;
|
|
1560
|
-
if (!admitSynchronousWork(ledger, width * 2, signal)) return void 0;
|
|
1561
|
-
ledger.charge("allocationUnits", width * 2 + 2, signal);
|
|
1562
|
-
const groupStarts = new Int32Array(width);
|
|
1563
|
-
const groupEnds = new Int32Array(width);
|
|
1564
|
-
const maxStart = chain.anchoredStart ? 0 : subject.length;
|
|
1565
|
-
const steps = chain.steps;
|
|
1566
|
-
const stepsLen = steps.length;
|
|
1567
|
-
for (let start = 0; start <= maxStart; start++) {
|
|
1568
|
-
if (!admitSynchronousWork(ledger, 1, signal)) return void 0;
|
|
1569
|
-
ledger.charge("states", 1, signal);
|
|
1570
|
-
if (chain.firstAtom) {
|
|
1571
|
-
if (start >= subject.length) break;
|
|
1572
|
-
if (!ereAtomMatchesCode(chain.firstAtom, subject.charCodeAt(start))) {
|
|
1573
|
-
continue;
|
|
1574
|
-
}
|
|
1575
|
-
}
|
|
1576
|
-
if (!admitSynchronousWork(ledger, width * 2, signal)) return void 0;
|
|
1577
|
-
groupStarts.fill(-1);
|
|
1578
|
-
groupEnds.fill(-1);
|
|
1579
|
-
let pos = start;
|
|
1580
|
-
let ok = true;
|
|
1581
|
-
for (let s = 0; s < stepsLen; s++) {
|
|
1582
|
-
if (!admitSynchronousWork(ledger, 1, signal)) return void 0;
|
|
1583
|
-
ledger.charge("states", 1, signal);
|
|
1584
|
-
const step = steps[s];
|
|
1585
|
-
if (step.kind === "groupOpen") {
|
|
1586
|
-
groupStarts[step.index] = pos;
|
|
1587
|
-
} else if (step.kind === "groupClose") {
|
|
1588
|
-
groupEnds[step.index] = pos;
|
|
1589
|
-
} else if (step.kind === "char") {
|
|
1590
|
-
if (pos >= subject.length || !ereAtomMatchesCode(step.atom, subject.charCodeAt(pos))) {
|
|
1591
|
-
ok = false;
|
|
1592
|
-
break;
|
|
1593
|
-
}
|
|
1594
|
-
pos++;
|
|
1595
|
-
} else {
|
|
1596
|
-
let count = 0;
|
|
1597
|
-
while (pos < subject.length) {
|
|
1598
|
-
if (!admitSynchronousWork(ledger, 1, signal)) return void 0;
|
|
1599
|
-
ledger.charge("states", 1, signal);
|
|
1600
|
-
if (!ereAtomMatchesCode(step.atom, subject.charCodeAt(pos))) break;
|
|
1601
|
-
pos++;
|
|
1602
|
-
count++;
|
|
1603
|
-
}
|
|
1604
|
-
if (count < step.min) {
|
|
1605
|
-
ok = false;
|
|
1606
|
-
break;
|
|
1607
|
-
}
|
|
1608
|
-
}
|
|
1609
|
-
}
|
|
1610
|
-
if (!ok || chain.anchoredEnd && pos !== subject.length) continue;
|
|
1611
|
-
if (!admitSynchronousWork(ledger, width, signal)) return void 0;
|
|
1612
|
-
let bytes = pos - start;
|
|
1613
|
-
for (let g = 1; g < width; g++) {
|
|
1614
|
-
if (groupStarts[g] >= 0 && groupEnds[g] >= groupStarts[g]) {
|
|
1615
|
-
bytes += groupEnds[g] - groupStarts[g];
|
|
1616
|
-
}
|
|
1617
|
-
}
|
|
1618
|
-
if (!admitSynchronousWork(ledger, width * 3 + bytes, signal)) return void 0;
|
|
1619
|
-
ledger.charge("captureSlots", width, signal);
|
|
1620
|
-
ledger.charge("captureBytes", bytes, signal);
|
|
1621
|
-
ledger.charge("allocationUnits", width * 4 + bytes + 6, signal);
|
|
1622
|
-
const captures = new Array(width);
|
|
1623
|
-
const values = new Array(width);
|
|
1624
|
-
captures[0] = Object.freeze({ start, end: pos });
|
|
1625
|
-
values[0] = subject.slice(start, pos);
|
|
1626
|
-
for (let g = 1; g < width; g++) {
|
|
1627
|
-
const gs = groupStarts[g];
|
|
1628
|
-
const ge = groupEnds[g];
|
|
1629
|
-
if (gs >= 0 && ge >= gs) {
|
|
1630
|
-
captures[g] = Object.freeze({ start: gs, end: ge });
|
|
1631
|
-
values[g] = subject.slice(gs, ge);
|
|
1632
|
-
} else {
|
|
1633
|
-
captures[g] = null;
|
|
1634
|
-
values[g] = "";
|
|
1635
|
-
}
|
|
1636
|
-
}
|
|
1637
|
-
ledger.check(signal);
|
|
1638
|
-
return Object.freeze({ matched: true, captures: Object.freeze(captures), values: Object.freeze(values) });
|
|
1639
|
-
}
|
|
1640
|
-
if (!admitSynchronousWork(ledger, 1, signal)) return void 0;
|
|
1641
|
-
ledger.charge("allocationUnits", 4, signal);
|
|
1642
|
-
ledger.check(signal);
|
|
1643
|
-
return Object.freeze({ matched: false, captures: Object.freeze([]), values: Object.freeze([]) });
|
|
1644
|
-
}
|
|
1645
|
-
function tryMatchEreSync(program, subject, ledger, signal) {
|
|
1646
|
-
ledger.check(signal);
|
|
1647
|
-
const root = resolveEreProgram(program, ledger);
|
|
1648
|
-
if (subject.length > ledger.limits.subjectBytes || ledger.workAllowanceUntilCheckpoint(signal) < subject.length + 16) {
|
|
1649
|
-
return void 0;
|
|
1650
|
-
}
|
|
1651
|
-
ledger.admitInput("subjectBytes", subject.length, signal);
|
|
1652
|
-
const adm = admitAscii(subject, ledger, signal);
|
|
1653
|
-
if (adm) return void 0;
|
|
1654
|
-
return tryMatchEreLinearChainSync(program, root, subject, ledger, signal);
|
|
1655
|
-
}
|
|
1656
|
-
async function matchEre(program, subject, ledger, signal) {
|
|
1657
|
-
ledger.check(signal);
|
|
1658
|
-
resolveEreProgram(program, ledger);
|
|
1659
|
-
ledger.admitInput("subjectBytes", subject.length, signal);
|
|
1660
|
-
const root = resolveEreProgram(program, ledger);
|
|
1661
|
-
const adm = admitAscii(subject, ledger, signal);
|
|
1662
|
-
if (adm) await adm;
|
|
1663
|
-
const fastLinear = tryMatchEreLinearChainSync(program, root, subject, ledger, signal);
|
|
1664
|
-
if (fastLinear !== void 0) return fastLinear;
|
|
1665
|
-
return runMatcher(program, subject, ledger, signal, 0, true);
|
|
1666
|
-
}
|
|
1667
|
-
async function prepareUtf8EreSubject(bytes, ledger, signal, leftmostFirst = false, word = false) {
|
|
1668
|
-
ledger.check(signal);
|
|
1669
|
-
ledger.admitInput("subjectBytes", bytes.length, signal);
|
|
1670
|
-
ledger.charge("allocationUnits", bytes.length * 11 + 16, signal);
|
|
1671
|
-
ledger.charge("work", bytes.length, signal);
|
|
1672
|
-
const owned = new Uint8Array(bytes);
|
|
1673
|
-
await validateUtf8(owned, ledger, signal);
|
|
1674
|
-
const characters = [];
|
|
1675
|
-
const offsets = [];
|
|
1676
|
-
for (let offset = 0; offset < owned.length; ) {
|
|
1677
|
-
const first = owned[offset];
|
|
1678
|
-
const width = word || first < 128 ? 1 : first < 224 ? 2 : first < 240 ? 3 : 4;
|
|
1679
|
-
ledger.charge("work", width, signal);
|
|
1680
|
-
{
|
|
1681
|
-
const c = ledger.checkpoint(signal);
|
|
1682
|
-
if (c) await c;
|
|
1683
|
-
}
|
|
1684
|
-
offsets.push(offset);
|
|
1685
|
-
characters.push(String.fromCharCode(first < 128 ? first : 128));
|
|
1686
|
-
offset += width;
|
|
1687
|
-
}
|
|
1688
|
-
offsets.push(owned.length);
|
|
1689
|
-
ledger.charge("work", characters.length, signal);
|
|
1690
|
-
{
|
|
1691
|
-
const c = ledger.checkpoint(signal);
|
|
1692
|
-
if (c) await c;
|
|
1693
|
-
}
|
|
1694
|
-
const subject = characters.join("");
|
|
1695
|
-
return (program) => {
|
|
1696
|
-
resolveEreProgram(program, ledger);
|
|
1697
|
-
ledger.charge("allocationUnits", 2, signal);
|
|
1698
|
-
return async (start) => {
|
|
1699
|
-
if (!Number.isSafeInteger(start) || start < 0 || start > owned.length) throw new RangeError("Invalid UTF-8 ERE search cursor");
|
|
1700
|
-
let lower = 0, upper = offsets.length - 1;
|
|
1701
|
-
while (lower < upper) {
|
|
1702
|
-
ledger.charge("work", 1, signal);
|
|
1703
|
-
{
|
|
1704
|
-
const c = ledger.checkpoint(signal);
|
|
1705
|
-
if (c) await c;
|
|
1706
|
-
}
|
|
1707
|
-
const middle = Math.floor((lower + upper) / 2);
|
|
1708
|
-
if (offsets[middle] < start) lower = middle + 1;
|
|
1709
|
-
else upper = middle;
|
|
1710
|
-
}
|
|
1711
|
-
if (offsets[lower] !== start) throw new RangeError("UTF-8 ERE cursor must be a scalar boundary");
|
|
1712
|
-
const span = await runMatcher(program, subject, ledger, signal, lower, false, leftmostFirst, word);
|
|
1713
|
-
if (!span) return void 0;
|
|
1714
|
-
ledger.charge("allocationUnits", 2, signal);
|
|
1715
|
-
return Object.freeze({ start: offsets[span.start], end: offsets[span.end] });
|
|
1716
|
-
};
|
|
1717
|
-
};
|
|
1718
|
-
}
|
|
1719
|
-
async function runMatcher(program, subject, ledger, signal, from, materialize, leftmostFirst = false, word = false) {
|
|
1720
|
-
const root = resolveEreProgram(program, ledger);
|
|
1721
|
-
const initial = await prepareInitialCharacters(root, ledger, signal);
|
|
1722
|
-
const width = program.groups + 1;
|
|
1723
|
-
ledger.charge("work", width * 2, signal);
|
|
1724
|
-
ledger.charge("allocationUnits", width * 2 + 1, signal);
|
|
1725
|
-
{
|
|
1726
|
-
const c = ledger.checkpoint(signal);
|
|
1727
|
-
if (c) await c;
|
|
1728
|
-
}
|
|
1729
|
-
const emptyCaptures = Object.freeze(new Array(width).fill(null));
|
|
1730
|
-
const emptyHistories = Object.freeze(new Array(width).fill(null));
|
|
1731
|
-
const pending = [];
|
|
1732
|
-
const task = (create) => {
|
|
1733
|
-
ledger.charge("allocationUnits", 5, signal);
|
|
1734
|
-
return create();
|
|
1735
|
-
};
|
|
1736
|
-
const push = (position, next, captures, histories) => {
|
|
1737
|
-
ledger.charge("states", 1, signal);
|
|
1738
|
-
ledger.charge("allocationUnits", 5, signal);
|
|
1739
|
-
pending.push({ position, task: next, captures, histories });
|
|
1740
|
-
};
|
|
1741
|
-
for (let start = from; start <= subject.length; start++) {
|
|
1742
|
-
if (initial) {
|
|
1743
|
-
ledger.charge("work", 1, signal);
|
|
1744
|
-
const pendingCheck = ledger.checkpoint(signal);
|
|
1745
|
-
if (pendingCheck) await pendingCheck;
|
|
1746
|
-
if (!initial[subject.charCodeAt(start)]) continue;
|
|
1747
|
-
}
|
|
1748
|
-
if (word) {
|
|
1749
|
-
ledger.charge("work", 1, signal);
|
|
1750
|
-
const pendingCheck = ledger.checkpoint(signal);
|
|
1751
|
-
if (pendingCheck) await pendingCheck;
|
|
1752
|
-
if (isAsciiWord(subject.charCodeAt(start - 1))) continue;
|
|
1753
|
-
}
|
|
1754
|
-
push(start, task(() => ({ kind: "node", node: root, next: null })), emptyCaptures, emptyHistories);
|
|
1755
|
-
let best;
|
|
1756
|
-
while (pending.length > 0) {
|
|
1757
|
-
ledger.charge("work", 1, signal);
|
|
1758
|
-
const pendingCheck = ledger.checkpoint(signal);
|
|
1759
|
-
if (pendingCheck) await pendingCheck;
|
|
1760
|
-
const state = pending.pop();
|
|
1761
|
-
const current = state.task;
|
|
1762
|
-
if (current === null) {
|
|
1763
|
-
if (word && isAsciiWord(subject.charCodeAt(state.position))) continue;
|
|
1764
|
-
if (leftmostFirst) {
|
|
1765
|
-
best = state;
|
|
1766
|
-
break;
|
|
1767
|
-
}
|
|
1768
|
-
if (!best || (state.position !== best.position ? state.position > best.position : await preferred(state, best, ledger, signal))) best = state;
|
|
1769
|
-
continue;
|
|
1770
|
-
}
|
|
1771
|
-
if (current.kind === "close") {
|
|
1772
|
-
ledger.charge("work", width * 2, signal);
|
|
1773
|
-
ledger.charge("allocationUnits", width * 2 + 6, signal);
|
|
1774
|
-
{
|
|
1775
|
-
const c = ledger.checkpoint(signal);
|
|
1776
|
-
if (c) await c;
|
|
1777
|
-
}
|
|
1778
|
-
const span = Object.freeze({ start: current.start, end: state.position });
|
|
1779
|
-
const captures = state.captures.slice();
|
|
1780
|
-
captures[current.group] = span;
|
|
1781
|
-
const histories = state.histories.slice();
|
|
1782
|
-
const previous = histories[current.group];
|
|
1783
|
-
histories[current.group] = { span, previous, count: (previous?.count ?? 0) + 1 };
|
|
1784
|
-
push(state.position, current.next, captures, histories);
|
|
1785
|
-
continue;
|
|
1786
|
-
}
|
|
1787
|
-
if (current.kind === "repeat") {
|
|
1788
|
-
const { node: node2, count } = current;
|
|
1789
|
-
if (count >= node2.min) push(state.position, current.next, state.captures, state.histories);
|
|
1790
|
-
const noProgress = count > 0 && state.position === current.previous;
|
|
1791
|
-
if (count < node2.max && (!noProgress || count < node2.min)) {
|
|
1792
|
-
const repeat = task(() => ({ kind: "repeat", node: node2, count: count + 1, previous: state.position, next: current.next }));
|
|
1793
|
-
push(state.position, task(() => ({ kind: "node", node: node2.child, next: repeat })), state.captures, state.histories);
|
|
1794
|
-
}
|
|
1795
|
-
continue;
|
|
1796
|
-
}
|
|
1797
|
-
const node = current.node;
|
|
1798
|
-
switch (node.kind) {
|
|
1799
|
-
case "empty":
|
|
1800
|
-
push(state.position, current.next, state.captures, state.histories);
|
|
1801
|
-
break;
|
|
1802
|
-
case "start":
|
|
1803
|
-
if (state.position === 0) push(state.position, current.next, state.captures, state.histories);
|
|
1804
|
-
break;
|
|
1805
|
-
case "end":
|
|
1806
|
-
if (state.position === subject.length) push(state.position, current.next, state.captures, state.histories);
|
|
1807
|
-
break;
|
|
1808
|
-
case "dot":
|
|
1809
|
-
case "literal":
|
|
1810
|
-
case "set": {
|
|
1811
|
-
const code = subject.charCodeAt(state.position);
|
|
1812
|
-
if (state.position < subject.length && (node.kind === "dot" && (!leftmostFirst || code !== 10) || node.kind === "literal" && (node.insensitive ? foldAscii(node.code) === foldAscii(code) : node.code === code) || node.kind === "set" && (code < 128 ? node.members[code] : node.nonAscii))) {
|
|
1813
|
-
push(state.position + 1, current.next, state.captures, state.histories);
|
|
1814
|
-
}
|
|
1815
|
-
break;
|
|
1816
|
-
}
|
|
1817
|
-
case "sequence": {
|
|
1818
|
-
let next = current.next;
|
|
1819
|
-
for (let index = node.children.length - 1; index >= 0; index--) {
|
|
1820
|
-
ledger.charge("work", 1, signal);
|
|
1821
|
-
{
|
|
1822
|
-
const c = ledger.checkpoint(signal);
|
|
1823
|
-
if (c) await c;
|
|
1824
|
-
}
|
|
1825
|
-
const following = next;
|
|
1826
|
-
next = task(() => ({ kind: "node", node: node.children[index], next: following }));
|
|
1827
|
-
}
|
|
1828
|
-
push(state.position, next, state.captures, state.histories);
|
|
1829
|
-
break;
|
|
1830
|
-
}
|
|
1831
|
-
case "alternative":
|
|
1832
|
-
for (let index = node.children.length - 1; index >= 0; index--) {
|
|
1833
|
-
ledger.charge("work", 1, signal);
|
|
1834
|
-
{
|
|
1835
|
-
const c = ledger.checkpoint(signal);
|
|
1836
|
-
if (c) await c;
|
|
1837
|
-
}
|
|
1838
|
-
push(state.position, task(() => ({ kind: "node", node: node.children[index], next: current.next })), state.captures, state.histories);
|
|
1839
|
-
}
|
|
1840
|
-
break;
|
|
1841
|
-
case "group": {
|
|
1842
|
-
let captures = state.captures;
|
|
1843
|
-
if (node.child.captured) {
|
|
1844
|
-
const rd = resetDescendants(node.child, state.captures, ledger, signal);
|
|
1845
|
-
captures = rd instanceof Promise ? await rd : rd;
|
|
1846
|
-
}
|
|
1847
|
-
const close = task(() => ({ kind: "close", group: node.index, start: state.position, next: current.next }));
|
|
1848
|
-
push(state.position, task(() => ({ kind: "node", node: node.child, next: close })), captures, state.histories);
|
|
1849
|
-
break;
|
|
1850
|
-
}
|
|
1851
|
-
case "repeat":
|
|
1852
|
-
push(state.position, task(() => ({ kind: "repeat", node, count: 0, previous: -1, next: current.next })), state.captures, state.histories);
|
|
1853
|
-
break;
|
|
1854
|
-
}
|
|
1855
|
-
}
|
|
1856
|
-
if (best) {
|
|
1857
|
-
if (!materialize) {
|
|
1858
|
-
ledger.charge("allocationUnits", 2, signal);
|
|
1859
|
-
ledger.check(signal);
|
|
1860
|
-
return Object.freeze({ start, end: best.position });
|
|
1861
|
-
}
|
|
1862
|
-
ledger.charge("captureSlots", width, signal);
|
|
1863
|
-
let bytes = best.position - start;
|
|
1864
|
-
for (let group = 1; group < width; group++) {
|
|
1865
|
-
ledger.charge("work", 1, signal);
|
|
1866
|
-
{
|
|
1867
|
-
const c = ledger.checkpoint(signal);
|
|
1868
|
-
if (c) await c;
|
|
1869
|
-
}
|
|
1870
|
-
const span = best.captures[group];
|
|
1871
|
-
if (span) bytes += span.end - span.start;
|
|
1872
|
-
}
|
|
1873
|
-
ledger.charge("captureBytes", bytes, signal);
|
|
1874
|
-
ledger.charge("work", width * 2 + bytes, signal);
|
|
1875
|
-
ledger.charge("allocationUnits", width * 2 + bytes + 4, signal);
|
|
1876
|
-
{
|
|
1877
|
-
const c = ledger.checkpoint(signal);
|
|
1878
|
-
if (c) await c;
|
|
1879
|
-
}
|
|
1880
|
-
const captures = best.captures.slice();
|
|
1881
|
-
captures[0] = Object.freeze({ start, end: best.position });
|
|
1882
|
-
const values = new Array(width);
|
|
1883
|
-
for (let group = 0; group < width; group++) {
|
|
1884
|
-
ledger.charge("work", 1, signal);
|
|
1885
|
-
{
|
|
1886
|
-
const c = ledger.checkpoint(signal);
|
|
1887
|
-
if (c) await c;
|
|
1888
|
-
}
|
|
1889
|
-
const span = captures[group];
|
|
1890
|
-
values[group] = span === null ? "" : subject.slice(span.start, span.end);
|
|
1891
|
-
}
|
|
1892
|
-
ledger.check(signal);
|
|
1893
|
-
return Object.freeze({ matched: true, captures: Object.freeze(captures), values: Object.freeze(values) });
|
|
1894
|
-
}
|
|
1895
|
-
}
|
|
1896
|
-
ledger.check(signal);
|
|
1897
|
-
if (!materialize) return void 0;
|
|
1898
|
-
ledger.charge("allocationUnits", 3, signal);
|
|
1899
|
-
return Object.freeze({ matched: false, captures: Object.freeze([]), values: Object.freeze([]) });
|
|
1900
|
-
}
|
|
1901
|
-
|
|
1902
|
-
export {
|
|
1903
|
-
foldAscii,
|
|
1904
|
-
isAsciiWord,
|
|
1905
|
-
EreSyntaxError,
|
|
1906
|
-
EreUnsupportedError,
|
|
1907
|
-
EreProfileLimitError,
|
|
1908
|
-
EreUsageUnknownError,
|
|
1909
|
-
EreLedger,
|
|
1910
|
-
compileEre,
|
|
1911
|
-
tryCompileEreSync,
|
|
1912
|
-
validateUtf8,
|
|
1913
|
-
warmEreProgram,
|
|
1914
|
-
canFastSyncEreProgram,
|
|
1915
|
-
tryMatchEreAsciiRangeSync,
|
|
1916
|
-
tryMatchEreSync,
|
|
1917
|
-
matchEre,
|
|
1918
|
-
prepareUtf8EreSubject
|
|
1919
|
-
};
|
|
1920
|
-
//# sourceMappingURL=chunk-BPMCPTNP.js.map
|