react-dsl-editor 0.3.0 → 0.3.2
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/index.d.ts +24 -5
- package/dist/react-dsl-editor.js +654 -574
- package/package.json +1 -1
package/dist/react-dsl-editor.js
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
import { forwardRef, useCallback, useEffect, useImperativeHandle, useMemo, useRef, useState } from "react";
|
|
2
|
-
import { jsx, jsxs } from "react/jsx-runtime";
|
|
3
|
-
var __create = Object.create, __defProp = Object.defineProperty, __getOwnPropDesc = Object.getOwnPropertyDescriptor, __getOwnPropNames = Object.getOwnPropertyNames, __getProtoOf = Object.getPrototypeOf, __hasOwnProp = Object.prototype.hasOwnProperty, __commonJSMin = (o,
|
|
4
|
-
if (
|
|
5
|
-
get: ((o) =>
|
|
6
|
-
enumerable: !(
|
|
2
|
+
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
3
|
+
var __create = Object.create, __defProp = Object.defineProperty, __getOwnPropDesc = Object.getOwnPropertyDescriptor, __getOwnPropNames = Object.getOwnPropertyNames, __getProtoOf = Object.getPrototypeOf, __hasOwnProp = Object.prototype.hasOwnProperty, __commonJSMin = (o, h) => () => (h || o((h = { exports: {} }).exports, h), h.exports), __copyProps = (o, h, g, _) => {
|
|
4
|
+
if (h && typeof h == "object" || typeof h == "function") for (var v = __getOwnPropNames(h), y = 0, b = v.length, x; y < b; y++) x = v[y], !__hasOwnProp.call(o, x) && x !== g && __defProp(o, x, {
|
|
5
|
+
get: ((o) => h[o]).bind(null, x),
|
|
6
|
+
enumerable: !(_ = __getOwnPropDesc(h, x)) || _.enumerable
|
|
7
7
|
});
|
|
8
8
|
return o;
|
|
9
|
-
}, __toESM = (o,
|
|
9
|
+
}, __toESM = (o, h, g) => (g = o == null ? {} : __create(__getProtoOf(o)), __copyProps(h || !o || !o.__esModule ? __defProp(g, "default", {
|
|
10
10
|
value: o,
|
|
11
11
|
enumerable: !0
|
|
12
|
-
}) :
|
|
12
|
+
}) : g, o));
|
|
13
13
|
const textStyle = {
|
|
14
14
|
position: "absolute",
|
|
15
15
|
inset: 0,
|
|
@@ -18,84 +18,84 @@ const textStyle = {
|
|
|
18
18
|
fontSize: "1em",
|
|
19
19
|
lineHeight: "1.3em",
|
|
20
20
|
fontFamily: "monospace"
|
|
21
|
-
}, ReadOnlyTextarea = forwardRef(function({ wrap: o, children:
|
|
21
|
+
}, ReadOnlyTextarea = forwardRef(function({ wrap: o, children: h, style: g = {} }, _) {
|
|
22
22
|
return /* @__PURE__ */ jsx("pre", {
|
|
23
|
-
ref:
|
|
23
|
+
ref: _,
|
|
24
24
|
style: {
|
|
25
25
|
...textStyle,
|
|
26
26
|
pointerEvents: "none",
|
|
27
27
|
margin: 0,
|
|
28
28
|
overflow: "auto",
|
|
29
29
|
whiteSpace: o ? "pre-wrap" : "pre",
|
|
30
|
-
...
|
|
30
|
+
...g
|
|
31
31
|
},
|
|
32
|
-
children:
|
|
32
|
+
children: h
|
|
33
33
|
});
|
|
34
34
|
});
|
|
35
|
-
function e$4(o,
|
|
36
|
-
let
|
|
37
|
-
return
|
|
38
|
-
lazy:
|
|
39
|
-
lazyArgs:
|
|
35
|
+
function e$4(o, h, g) {
|
|
36
|
+
let _ = (g) => o(g, ...h);
|
|
37
|
+
return g === void 0 ? _ : Object.assign(_, {
|
|
38
|
+
lazy: g,
|
|
39
|
+
lazyArgs: h
|
|
40
40
|
});
|
|
41
41
|
}
|
|
42
|
-
function t$10(o,
|
|
43
|
-
let
|
|
44
|
-
if (
|
|
45
|
-
if (
|
|
42
|
+
function t$10(o, h, g) {
|
|
43
|
+
let _ = o.length - h.length;
|
|
44
|
+
if (_ === 0) return o(...h);
|
|
45
|
+
if (_ === 1) return e$4(o, h, g);
|
|
46
46
|
throw Error("Wrong number of arguments");
|
|
47
47
|
}
|
|
48
48
|
function t$5(...o) {
|
|
49
49
|
return t$10(n$13, o);
|
|
50
50
|
}
|
|
51
|
-
var n$13 = (o,
|
|
51
|
+
var n$13 = (o, h) => o ?? h, e$3 = {
|
|
52
52
|
done: !0,
|
|
53
53
|
hasNext: !1
|
|
54
54
|
}, t$8 = {
|
|
55
55
|
done: !1,
|
|
56
56
|
hasNext: !1
|
|
57
57
|
}, n$5 = () => e$3;
|
|
58
|
-
function t(o, ...
|
|
59
|
-
let
|
|
60
|
-
for (;
|
|
61
|
-
if (
|
|
62
|
-
let o =
|
|
63
|
-
|
|
58
|
+
function t(o, ...h) {
|
|
59
|
+
let g = o, _ = h.map((o) => "lazy" in o ? r$8(o) : void 0), v = 0;
|
|
60
|
+
for (; v < h.length;) {
|
|
61
|
+
if (_[v] === void 0 || !i$4(g)) {
|
|
62
|
+
let o = h[v];
|
|
63
|
+
g = o(g), v += 1;
|
|
64
64
|
continue;
|
|
65
65
|
}
|
|
66
66
|
let o = [];
|
|
67
|
-
for (let
|
|
68
|
-
let
|
|
69
|
-
if (
|
|
67
|
+
for (let g = v; g < h.length; g++) {
|
|
68
|
+
let h = _[g];
|
|
69
|
+
if (h === void 0 || (o.push(h), h.isSingle)) break;
|
|
70
70
|
}
|
|
71
|
-
let
|
|
72
|
-
for (let
|
|
73
|
-
let { isSingle:
|
|
74
|
-
|
|
71
|
+
let y = [];
|
|
72
|
+
for (let h of g) if (n$12(h, y, o)) break;
|
|
73
|
+
let { isSingle: b } = o.at(-1);
|
|
74
|
+
g = b ? y[0] : y, v += o.length;
|
|
75
75
|
}
|
|
76
|
-
return
|
|
76
|
+
return g;
|
|
77
77
|
}
|
|
78
|
-
function n$12(o,
|
|
79
|
-
if (
|
|
80
|
-
let
|
|
81
|
-
for (let [o,
|
|
82
|
-
let { index:
|
|
83
|
-
if (
|
|
84
|
-
if (
|
|
85
|
-
for (let
|
|
86
|
-
return
|
|
78
|
+
function n$12(o, h, g) {
|
|
79
|
+
if (g.length === 0) return h.push(o), !1;
|
|
80
|
+
let _ = o, v = t$8, y = !1;
|
|
81
|
+
for (let [o, b] of g.entries()) {
|
|
82
|
+
let { index: x, items: S } = b;
|
|
83
|
+
if (S.push(_), v = b(_, x, S), b.index += 1, v.hasNext) {
|
|
84
|
+
if (v.hasMany ?? !1) {
|
|
85
|
+
for (let _ of v.next) if (n$12(_, h, g.slice(o + 1))) return !0;
|
|
86
|
+
return y;
|
|
87
87
|
}
|
|
88
|
-
|
|
88
|
+
_ = v.next;
|
|
89
89
|
}
|
|
90
|
-
if (!
|
|
91
|
-
|
|
90
|
+
if (!v.hasNext) break;
|
|
91
|
+
v.done && (y = !0);
|
|
92
92
|
}
|
|
93
|
-
return
|
|
93
|
+
return v.hasNext && h.push(_), y;
|
|
94
94
|
}
|
|
95
95
|
function r$8(o) {
|
|
96
|
-
let { lazy:
|
|
97
|
-
return Object.assign(
|
|
98
|
-
isSingle:
|
|
96
|
+
let { lazy: h, lazyArgs: g } = o, _ = h(...g);
|
|
97
|
+
return Object.assign(_, {
|
|
98
|
+
isSingle: h.single ?? !1,
|
|
99
99
|
index: 0,
|
|
100
100
|
items: []
|
|
101
101
|
});
|
|
@@ -103,58 +103,58 @@ function r$8(o) {
|
|
|
103
103
|
function i$4(o) {
|
|
104
104
|
return typeof o == "string" || typeof o == "object" && !!o && Symbol.iterator in o;
|
|
105
105
|
}
|
|
106
|
-
function t$9(o,
|
|
107
|
-
let
|
|
108
|
-
if (
|
|
109
|
-
let [
|
|
110
|
-
return t(
|
|
106
|
+
function t$9(o, h) {
|
|
107
|
+
let g = h.length - o.length;
|
|
108
|
+
if (g === 1) {
|
|
109
|
+
let [g, ..._] = h;
|
|
110
|
+
return t(g, {
|
|
111
111
|
lazy: o,
|
|
112
|
-
lazyArgs:
|
|
112
|
+
lazyArgs: _
|
|
113
113
|
});
|
|
114
114
|
}
|
|
115
|
-
if (
|
|
116
|
-
let
|
|
115
|
+
if (g === 0) {
|
|
116
|
+
let g = {
|
|
117
117
|
lazy: o,
|
|
118
|
-
lazyArgs:
|
|
118
|
+
lazyArgs: h
|
|
119
119
|
};
|
|
120
|
-
return Object.assign((o) => t(o,
|
|
120
|
+
return Object.assign((o) => t(o, g), g);
|
|
121
121
|
}
|
|
122
122
|
throw Error("Wrong number of arguments");
|
|
123
123
|
}
|
|
124
124
|
var e$2 = {
|
|
125
|
-
asc: (o,
|
|
126
|
-
desc: (o,
|
|
125
|
+
asc: (o, h) => o > h,
|
|
126
|
+
desc: (o, h) => o < h
|
|
127
127
|
};
|
|
128
|
-
function t$11(o,
|
|
129
|
-
let [
|
|
130
|
-
if (!i$3(
|
|
131
|
-
let
|
|
132
|
-
return o(
|
|
128
|
+
function t$11(o, h) {
|
|
129
|
+
let [g, ..._] = h;
|
|
130
|
+
if (!i$3(g)) {
|
|
131
|
+
let h = r$7(..._);
|
|
132
|
+
return o(g, h);
|
|
133
133
|
}
|
|
134
|
-
let
|
|
135
|
-
return (
|
|
134
|
+
let v = r$7(g, ..._);
|
|
135
|
+
return (h) => o(h, v);
|
|
136
136
|
}
|
|
137
|
-
function r$7(o,
|
|
138
|
-
let
|
|
139
|
-
return (o,
|
|
140
|
-
let
|
|
141
|
-
return
|
|
137
|
+
function r$7(o, h, ...g) {
|
|
138
|
+
let _ = typeof o == "function" ? o : o[0], v = typeof o == "function" ? "asc" : o[1], { [v]: y } = e$2, b = h === void 0 ? void 0 : r$7(h, ...g);
|
|
139
|
+
return (o, h) => {
|
|
140
|
+
let g = _(o), v = _(h);
|
|
141
|
+
return y(g, v) ? 1 : y(v, g) ? -1 : b?.(o, h) ?? 0;
|
|
142
142
|
};
|
|
143
143
|
}
|
|
144
144
|
function i$3(o) {
|
|
145
145
|
if (a$1(o)) return !0;
|
|
146
146
|
if (typeof o != "object" || !Array.isArray(o)) return !1;
|
|
147
|
-
let [
|
|
148
|
-
return a$1(
|
|
147
|
+
let [h, g, ..._] = o;
|
|
148
|
+
return a$1(h) && typeof g == "string" && g in e$2 && _.length === 0;
|
|
149
149
|
}
|
|
150
150
|
var a$1 = (o) => typeof o == "function" && o.length === 1;
|
|
151
151
|
function n(...o) {
|
|
152
152
|
return t$10(r$6, o, i$2);
|
|
153
153
|
}
|
|
154
|
-
var r$6 = (o,
|
|
154
|
+
var r$6 = (o, h) => o.filter(h), i$2 = (o) => (h, g, _) => o(h, g, _) ? {
|
|
155
155
|
done: !1,
|
|
156
156
|
hasNext: !0,
|
|
157
|
-
next:
|
|
157
|
+
next: h
|
|
158
158
|
} : t$8, e$1 = (o) => Object.assign(o, { single: !0 });
|
|
159
159
|
function n$1(...o) {
|
|
160
160
|
return t$10(r$5, o, e$1(i$1));
|
|
@@ -167,17 +167,17 @@ var r$5 = ([o]) => o, i$1 = () => a, a = (o) => ({
|
|
|
167
167
|
function t$7(...o) {
|
|
168
168
|
return t$10(n$11, o, r$4);
|
|
169
169
|
}
|
|
170
|
-
var n$11 = (o,
|
|
171
|
-
let
|
|
172
|
-
return Array.isArray(
|
|
170
|
+
var n$11 = (o, h) => o.flatMap(h), r$4 = (o) => (h, g, _) => {
|
|
171
|
+
let v = o(h, g, _);
|
|
172
|
+
return Array.isArray(v) ? {
|
|
173
173
|
done: !1,
|
|
174
174
|
hasNext: !0,
|
|
175
175
|
hasMany: !0,
|
|
176
|
-
next:
|
|
176
|
+
next: v
|
|
177
177
|
} : {
|
|
178
178
|
done: !1,
|
|
179
179
|
hasNext: !0,
|
|
180
|
-
next:
|
|
180
|
+
next: v
|
|
181
181
|
};
|
|
182
182
|
};
|
|
183
183
|
function e(o) {
|
|
@@ -190,10 +190,10 @@ var n$10 = (o) => o.at(-1);
|
|
|
190
190
|
function t$3(...o) {
|
|
191
191
|
return t$10(n$9, o, r$3);
|
|
192
192
|
}
|
|
193
|
-
var n$9 = (o,
|
|
193
|
+
var n$9 = (o, h) => o.map(h), r$3 = (o) => (h, g, _) => ({
|
|
194
194
|
done: !1,
|
|
195
195
|
hasNext: !0,
|
|
196
|
-
next: o(
|
|
196
|
+
next: o(h, g, _)
|
|
197
197
|
});
|
|
198
198
|
function t$6(...o) {
|
|
199
199
|
return t$10(n$8, o);
|
|
@@ -202,24 +202,24 @@ var n$8 = (o) => o.length === 1 ? o[0] : void 0;
|
|
|
202
202
|
function t$4(...o) {
|
|
203
203
|
return t$10(n$7, o);
|
|
204
204
|
}
|
|
205
|
-
function n$7(o,
|
|
206
|
-
let
|
|
207
|
-
for (let
|
|
208
|
-
return
|
|
205
|
+
function n$7(o, h) {
|
|
206
|
+
let g = [];
|
|
207
|
+
for (let _ = o; _ < h; _++) g.push(_);
|
|
208
|
+
return g;
|
|
209
209
|
}
|
|
210
210
|
function t$1(...o) {
|
|
211
211
|
return t$11(n$6, o);
|
|
212
212
|
}
|
|
213
|
-
var n$6 = (o,
|
|
213
|
+
var n$6 = (o, h) => [...o].sort(h);
|
|
214
214
|
function n$3(...o) {
|
|
215
215
|
return t$10(r$2, o, i);
|
|
216
216
|
}
|
|
217
|
-
var r$2 = (o,
|
|
217
|
+
var r$2 = (o, h) => h < 0 ? [] : o.slice(0, h);
|
|
218
218
|
function i(o) {
|
|
219
219
|
if (o <= 0) return n$5;
|
|
220
|
-
let
|
|
221
|
-
return (o) => (--
|
|
222
|
-
done:
|
|
220
|
+
let h = o;
|
|
221
|
+
return (o) => (--h, {
|
|
222
|
+
done: h <= 0,
|
|
223
223
|
hasNext: !0,
|
|
224
224
|
next: o
|
|
225
225
|
});
|
|
@@ -229,121 +229,120 @@ function n$2(...o) {
|
|
|
229
229
|
}
|
|
230
230
|
function r$1() {
|
|
231
231
|
let o = /* @__PURE__ */ new Set();
|
|
232
|
-
return (
|
|
232
|
+
return (h) => o.has(h) ? t$8 : (o.add(h), {
|
|
233
233
|
done: !1,
|
|
234
234
|
hasNext: !0,
|
|
235
|
-
next:
|
|
235
|
+
next: h
|
|
236
236
|
});
|
|
237
237
|
}
|
|
238
238
|
function n$4(...o) {
|
|
239
239
|
return t$9(r, o);
|
|
240
240
|
}
|
|
241
241
|
function r(o) {
|
|
242
|
-
let
|
|
243
|
-
return (o,
|
|
244
|
-
let
|
|
245
|
-
return
|
|
242
|
+
let h = o, g = /* @__PURE__ */ new Set();
|
|
243
|
+
return (o, _, v) => {
|
|
244
|
+
let y = h(o, _, v);
|
|
245
|
+
return g.has(y) ? t$8 : (g.add(y), {
|
|
246
246
|
done: !1,
|
|
247
247
|
hasNext: !0,
|
|
248
248
|
next: o
|
|
249
249
|
});
|
|
250
250
|
};
|
|
251
251
|
}
|
|
252
|
-
var
|
|
253
|
-
"
|
|
254
|
-
"
|
|
255
|
-
"
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
"#000080",
|
|
259
|
-
"#808000",
|
|
260
|
-
"#800080",
|
|
261
|
-
"#008080",
|
|
262
|
-
"#808080",
|
|
263
|
-
"#993366",
|
|
264
|
-
"#336699"
|
|
265
|
-
], colorAssignments = /* @__PURE__ */ new Map();
|
|
266
|
-
function getColorAssigment(o) {
|
|
267
|
-
let _ = String(o), v = colorAssignments.get(_);
|
|
268
|
-
if (v) return v;
|
|
269
|
-
let y = colors[colorAssignments.size % colors.length];
|
|
270
|
-
return colorAssignments.set(_, y), console.log(colorAssignments), y;
|
|
271
|
-
}
|
|
272
|
-
function defaultStyleFor(o) {
|
|
273
|
-
let { name: _, regex: v } = o.grammar.meta ?? {}, y = _ ?? v;
|
|
274
|
-
if (y) return { color: getColorAssigment(y) };
|
|
275
|
-
}
|
|
276
|
-
function SyntaxHighlighter({ cstRoot: o, ref: _, wrap: v }) {
|
|
252
|
+
var squiggly = {
|
|
253
|
+
textDecorationLine: "underline",
|
|
254
|
+
textDecorationStyle: "wavy",
|
|
255
|
+
textDecorationColor: "red"
|
|
256
|
+
};
|
|
257
|
+
function SyntaxHighlighter({ cstRoot: o, ref: h, wrap: g, syntaxColors: _ }) {
|
|
277
258
|
return /* @__PURE__ */ jsx(ReadOnlyTextarea, {
|
|
278
|
-
ref:
|
|
279
|
-
wrap:
|
|
259
|
+
ref: h,
|
|
260
|
+
wrap: g,
|
|
280
261
|
children: /* @__PURE__ */ jsx(StyledNode, {
|
|
281
262
|
node: o,
|
|
282
|
-
styleFor:
|
|
263
|
+
styleFor: _
|
|
283
264
|
})
|
|
284
265
|
});
|
|
285
266
|
}
|
|
267
|
+
function ErrorHighlighter({ ref: o, wrap: h, errors: g, children: _ }) {
|
|
268
|
+
let v = `${_} `, [y] = g;
|
|
269
|
+
return y ? /* @__PURE__ */ jsxs(ReadOnlyTextarea, {
|
|
270
|
+
ref: o,
|
|
271
|
+
wrap: h,
|
|
272
|
+
"data-id": "ErrorHighlighter",
|
|
273
|
+
style: { color: "transparent" },
|
|
274
|
+
children: [
|
|
275
|
+
v.substring(0, y.start),
|
|
276
|
+
/* @__PURE__ */ jsx("span", {
|
|
277
|
+
style: squiggly,
|
|
278
|
+
title: y.message,
|
|
279
|
+
children: v.substring(y.start, y.end)
|
|
280
|
+
}),
|
|
281
|
+
v.substring(y.end)
|
|
282
|
+
]
|
|
283
|
+
}) : /* @__PURE__ */ jsx(Fragment, {});
|
|
284
|
+
}
|
|
286
285
|
function StyledNode(o) {
|
|
287
|
-
let
|
|
286
|
+
let h = o.styleFor(o.node);
|
|
288
287
|
return /* @__PURE__ */ jsx("span", {
|
|
289
|
-
style:
|
|
290
|
-
children: e(o.node.children ?? []) ? o.node.text : o.node.children.map((
|
|
291
|
-
node:
|
|
288
|
+
style: h,
|
|
289
|
+
children: e(o.node.children ?? []) ? o.node.text : o.node.children.map((h, g) => /* @__PURE__ */ jsx(StyledNode, {
|
|
290
|
+
node: h,
|
|
292
291
|
styleFor: o.styleFor
|
|
293
|
-
},
|
|
292
|
+
}, g))
|
|
294
293
|
});
|
|
295
294
|
}
|
|
296
|
-
function cstPathAt(o,
|
|
297
|
-
return _cstPathAt(o,
|
|
295
|
+
function cstPathAt(o, h) {
|
|
296
|
+
return _cstPathAt(o, h, []);
|
|
298
297
|
}
|
|
299
|
-
function _cstPathAt(o,
|
|
300
|
-
return o.offset <=
|
|
298
|
+
function _cstPathAt(o, h, g = []) {
|
|
299
|
+
return o.offset <= h && h <= o.end ? (g.push(o), o.children?.forEach((o) => _cstPathAt(o, h, g)), g) : [];
|
|
301
300
|
}
|
|
302
|
-
function getSuggestions(o,
|
|
303
|
-
let
|
|
301
|
+
function getSuggestions(o, h, g = () => void 0) {
|
|
302
|
+
let _ = cstPathAt(o, h), v = t(_, t$7((o) => {
|
|
304
303
|
if (o.grammar.meta?.name !== void 0) {
|
|
305
|
-
let
|
|
306
|
-
if (
|
|
304
|
+
let h = g(o);
|
|
305
|
+
if (h) return h.map((h) => ({
|
|
307
306
|
node: o,
|
|
308
|
-
suggestion:
|
|
307
|
+
suggestion: h
|
|
309
308
|
}));
|
|
310
309
|
}
|
|
311
|
-
return o.grammar.suggestions().map((
|
|
310
|
+
return o.grammar.suggestions().map((h) => ({
|
|
312
311
|
node: o,
|
|
313
|
-
suggestion:
|
|
312
|
+
suggestion: h
|
|
314
313
|
}));
|
|
315
314
|
}));
|
|
316
|
-
return t(
|
|
317
|
-
let
|
|
318
|
-
return o.suggestion.startsWith(
|
|
315
|
+
return t(v, t$7((o) => {
|
|
316
|
+
let g = o.node.text.substring(0, h - o.node.offset);
|
|
317
|
+
return o.suggestion.startsWith(g) ? [{
|
|
319
318
|
suggestion: o.suggestion,
|
|
320
|
-
prefix:
|
|
319
|
+
prefix: g
|
|
321
320
|
}] : [];
|
|
322
321
|
}), n$4((o) => o.suggestion));
|
|
323
322
|
}
|
|
324
|
-
const CursorPosition = forwardRef(function(o,
|
|
325
|
-
let
|
|
326
|
-
return useImperativeHandle(
|
|
327
|
-
if (!
|
|
323
|
+
const CursorPosition = forwardRef(function(o, h) {
|
|
324
|
+
let g = useRef(null), v = useRef(null);
|
|
325
|
+
return useImperativeHandle(h, () => ({ getCursorPosition() {
|
|
326
|
+
if (!g.current || !v.current) return {
|
|
328
327
|
top: 0,
|
|
329
328
|
left: 0
|
|
330
329
|
};
|
|
331
|
-
let { offsetTop: o, offsetLeft:
|
|
330
|
+
let { offsetTop: o, offsetLeft: h } = g.current, { scrollTop: _, scrollLeft: y } = v.current, b = window.getComputedStyle(v.current), x = parseInt(b.lineHeight);
|
|
332
331
|
return {
|
|
333
|
-
top: o -
|
|
334
|
-
left:
|
|
332
|
+
top: o - _ + x,
|
|
333
|
+
left: h - y
|
|
335
334
|
};
|
|
336
335
|
} }), []), /* @__PURE__ */ jsxs(ReadOnlyTextarea, {
|
|
337
|
-
ref:
|
|
336
|
+
ref: v,
|
|
338
337
|
wrap: o.wrap,
|
|
339
338
|
style: { visibility: "hidden" },
|
|
340
339
|
children: [o.text, /* @__PURE__ */ jsx("span", {
|
|
341
|
-
ref:
|
|
340
|
+
ref: g,
|
|
342
341
|
children: "\xA0"
|
|
343
342
|
})]
|
|
344
343
|
});
|
|
345
344
|
});
|
|
346
|
-
function SuggestionsView({ suggestions: o, onSelect:
|
|
345
|
+
function SuggestionsView({ suggestions: o, onSelect: h }) {
|
|
347
346
|
return /* @__PURE__ */ jsx("div", {
|
|
348
347
|
style: {
|
|
349
348
|
display: "flex",
|
|
@@ -351,26 +350,28 @@ function SuggestionsView({ suggestions: o, onSelect: _ }) {
|
|
|
351
350
|
padding: "4px 0",
|
|
352
351
|
overflowY: "auto"
|
|
353
352
|
},
|
|
354
|
-
children: o.map((o,
|
|
355
|
-
onClick: () =>
|
|
353
|
+
children: o.map((o, g) => /* @__PURE__ */ jsxs("button", {
|
|
354
|
+
onClick: () => h(o),
|
|
356
355
|
children: [
|
|
357
356
|
"\xA0",
|
|
358
357
|
o,
|
|
359
358
|
"\xA0"
|
|
360
359
|
]
|
|
361
|
-
},
|
|
360
|
+
}, g))
|
|
362
361
|
});
|
|
363
362
|
}
|
|
364
363
|
function shortcutName(o) {
|
|
365
|
-
let
|
|
366
|
-
o.ctrlKey && (
|
|
367
|
-
let { key:
|
|
368
|
-
return
|
|
364
|
+
let h = "";
|
|
365
|
+
o.ctrlKey && (h = "Ctrl");
|
|
366
|
+
let { key: g } = o;
|
|
367
|
+
return g === " " && (g = "Space"), `${h}${g}`;
|
|
369
368
|
}
|
|
370
|
-
function useSyncScroll(o) {
|
|
371
|
-
return useCallback((
|
|
372
|
-
let
|
|
373
|
-
o.
|
|
369
|
+
function useSyncScroll(...o) {
|
|
370
|
+
return useCallback((h) => {
|
|
371
|
+
let g = h.currentTarget;
|
|
372
|
+
o.forEach((o) => {
|
|
373
|
+
o.current && g && (o.current.scrollTop = g.scrollTop, o.current.scrollLeft = g.scrollLeft);
|
|
374
|
+
});
|
|
374
375
|
}, [o]);
|
|
375
376
|
}
|
|
376
377
|
var ParsingError = class extends Error {
|
|
@@ -382,7 +383,10 @@ function success(o) {
|
|
|
382
383
|
return o;
|
|
383
384
|
}
|
|
384
385
|
function error(o) {
|
|
385
|
-
return
|
|
386
|
+
return {
|
|
387
|
+
...o,
|
|
388
|
+
offset: 0
|
|
389
|
+
};
|
|
386
390
|
}
|
|
387
391
|
function isParserError(o) {
|
|
388
392
|
return "expected" in o;
|
|
@@ -394,30 +398,39 @@ function asException(o) {
|
|
|
394
398
|
return new ParsingError(`[${o.grammar.type}]: Expected ${o.expected.map((o) => `'${o}'`).join(" | ")}, but got '${o.got}'`);
|
|
395
399
|
}
|
|
396
400
|
function sequence(...o) {
|
|
397
|
-
let
|
|
401
|
+
let h = {
|
|
398
402
|
children: o,
|
|
399
403
|
type: "sequence",
|
|
400
404
|
suggestions() {
|
|
401
405
|
return t(o, t$3((o) => o.suggestions()), n$3(1), t$6(), t$5([]));
|
|
402
406
|
},
|
|
403
|
-
parse(
|
|
404
|
-
let
|
|
405
|
-
for (let
|
|
406
|
-
let o =
|
|
407
|
-
if (isParserError(
|
|
408
|
-
if (
|
|
409
|
-
|
|
407
|
+
parse(g, _) {
|
|
408
|
+
let v = 0, y = [], b = !1;
|
|
409
|
+
for (let x of o) {
|
|
410
|
+
let o = g.substring(v), S = _.faultCorrection(x.parse(o, _), h);
|
|
411
|
+
if (isParserError(S)) {
|
|
412
|
+
if (_.faultTolerant) {
|
|
413
|
+
b = !0;
|
|
414
|
+
continue;
|
|
415
|
+
}
|
|
416
|
+
return {
|
|
417
|
+
...S,
|
|
418
|
+
offset: v
|
|
419
|
+
};
|
|
410
420
|
}
|
|
411
|
-
|
|
421
|
+
v += S.text.length, y.push({
|
|
422
|
+
...S,
|
|
423
|
+
recoverableError: b
|
|
424
|
+
}), b = !1;
|
|
412
425
|
}
|
|
413
426
|
return success({
|
|
414
|
-
grammar:
|
|
415
|
-
text:
|
|
416
|
-
children:
|
|
427
|
+
grammar: h,
|
|
428
|
+
text: g.substring(0, v),
|
|
429
|
+
children: y
|
|
417
430
|
});
|
|
418
431
|
}
|
|
419
432
|
};
|
|
420
|
-
return
|
|
433
|
+
return h;
|
|
421
434
|
}
|
|
422
435
|
const eof = {
|
|
423
436
|
type: "eof",
|
|
@@ -435,17 +448,18 @@ const eof = {
|
|
|
435
448
|
});
|
|
436
449
|
}
|
|
437
450
|
};
|
|
438
|
-
function withOffset(o,
|
|
439
|
-
let
|
|
451
|
+
function withOffset(o, h = 0) {
|
|
452
|
+
let g = h;
|
|
440
453
|
return {
|
|
441
454
|
text: o.text,
|
|
442
|
-
offset:
|
|
443
|
-
end:
|
|
444
|
-
children: o.children?.map((o,
|
|
445
|
-
let { text:
|
|
446
|
-
return
|
|
455
|
+
offset: h,
|
|
456
|
+
end: h + o.text.length,
|
|
457
|
+
children: o.children?.map((o, h, _) => {
|
|
458
|
+
let { text: v } = _[h - 1] ?? { text: "" };
|
|
459
|
+
return g += v.length, withOffset(o, g);
|
|
447
460
|
}),
|
|
448
|
-
grammar: o.grammar
|
|
461
|
+
grammar: o.grammar,
|
|
462
|
+
recoverableError: o.recoverableError ?? !1
|
|
449
463
|
};
|
|
450
464
|
}
|
|
451
465
|
function _flatCST(o) {
|
|
@@ -454,37 +468,85 @@ function _flatCST(o) {
|
|
|
454
468
|
function flatCST(o) {
|
|
455
469
|
return _flatCST(o).filter((o) => o.text !== "");
|
|
456
470
|
}
|
|
471
|
+
function getErrors(o) {
|
|
472
|
+
let h = o.children?.flatMap((o) => getErrors(o)) ?? [];
|
|
473
|
+
return o.recoverableError ? [{
|
|
474
|
+
start: o.offset,
|
|
475
|
+
end: Math.max(o.end, o.offset + 1),
|
|
476
|
+
message: o.grammar.type
|
|
477
|
+
}, ...h] : h;
|
|
478
|
+
}
|
|
457
479
|
var DSLParser = class {
|
|
458
480
|
grammar;
|
|
459
481
|
constructor(o) {
|
|
460
482
|
this.grammar = sequence(o, eof);
|
|
461
483
|
}
|
|
462
|
-
|
|
463
|
-
let
|
|
484
|
+
parse(o) {
|
|
485
|
+
let h = this.grammar.parse(o, {
|
|
464
486
|
faultTolerant: !1,
|
|
465
487
|
faultCorrection: (o) => o
|
|
466
|
-
})
|
|
467
|
-
return isParserError(_) ? this.grammar.parse(o, {
|
|
488
|
+
}), g = isParserError(h) ? this.grammar.parse(o, {
|
|
468
489
|
faultTolerant: !0,
|
|
469
490
|
faultCorrection: (o) => o
|
|
470
|
-
}) :
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
let _ = this._parse(o);
|
|
474
|
-
if (isParserError(_)) throw asException(_);
|
|
475
|
-
let v = withOffset(_), y = flatCST(v);
|
|
491
|
+
}) : h;
|
|
492
|
+
if (isParserError(g)) throw asException(g);
|
|
493
|
+
let _ = withOffset(g), v = flatCST(_);
|
|
476
494
|
return {
|
|
477
|
-
cst:
|
|
478
|
-
terminals:
|
|
479
|
-
result:
|
|
495
|
+
cst: _,
|
|
496
|
+
terminals: v,
|
|
497
|
+
result: g,
|
|
498
|
+
strictResult: isParserSuccess(h) ? h : void 0,
|
|
499
|
+
errors: getErrors(_)
|
|
480
500
|
};
|
|
481
501
|
}
|
|
482
|
-
}
|
|
483
|
-
|
|
502
|
+
}, themes = {
|
|
503
|
+
light: [
|
|
504
|
+
"#FF0000",
|
|
505
|
+
"#0000FF",
|
|
506
|
+
"#FF00FF",
|
|
507
|
+
"#800000",
|
|
508
|
+
"#008000",
|
|
509
|
+
"#000080",
|
|
510
|
+
"#808000",
|
|
511
|
+
"#800080",
|
|
512
|
+
"#008080",
|
|
513
|
+
"#808080",
|
|
514
|
+
"#993366",
|
|
515
|
+
"#336699"
|
|
516
|
+
],
|
|
517
|
+
dark: [
|
|
518
|
+
"#FF5555",
|
|
519
|
+
"#5555FF",
|
|
520
|
+
"#FF55FF",
|
|
521
|
+
"#FF5555",
|
|
522
|
+
"#55FF55",
|
|
523
|
+
"#5555FF",
|
|
524
|
+
"#FFFF55",
|
|
525
|
+
"#FF55FF",
|
|
526
|
+
"#55FFFF",
|
|
527
|
+
"#AAAAAA",
|
|
528
|
+
"#CC99FF",
|
|
529
|
+
"#99CCFF"
|
|
530
|
+
]
|
|
531
|
+
}, colorAssignments = /* @__PURE__ */ new Map();
|
|
532
|
+
function getColorAssigment(o, h) {
|
|
533
|
+
let g = String(o), _ = colorAssignments.get(g);
|
|
534
|
+
if (_) return _;
|
|
535
|
+
let v = h[colorAssignments.size % h.length];
|
|
536
|
+
return colorAssignments.set(g, v), console.log(colorAssignments), v;
|
|
537
|
+
}
|
|
538
|
+
function defaultStyleFor(o, h) {
|
|
539
|
+
let { name: g, regex: _ } = o.grammar.meta ?? {}, v = g ?? _;
|
|
540
|
+
if (v) return { color: getColorAssigment(v, h) };
|
|
541
|
+
}
|
|
542
|
+
function defaultSyntaxColors(o) {
|
|
543
|
+
return (h) => defaultStyleFor(h, themes[o]);
|
|
544
|
+
}
|
|
545
|
+
function SuggestionsMenu({ suggestions: o, onSelect: h, style: g, selectedIndex: _, onHover: v }) {
|
|
484
546
|
return /* @__PURE__ */ jsx("div", {
|
|
485
547
|
style: {
|
|
486
548
|
position: "absolute",
|
|
487
|
-
...
|
|
549
|
+
...g,
|
|
488
550
|
background: "#252526",
|
|
489
551
|
border: "1px solid #454545",
|
|
490
552
|
boxShadow: "0 2px 8px rgba(0,0,0,0.3)",
|
|
@@ -494,89 +556,89 @@ function SuggestionsMenu({ suggestions: o, onSelect: _, style: v, selectedIndex:
|
|
|
494
556
|
minWidth: 200,
|
|
495
557
|
zIndex: 100
|
|
496
558
|
},
|
|
497
|
-
children: o.map((o,
|
|
498
|
-
onClick: () =>
|
|
499
|
-
onMouseOver: () =>
|
|
559
|
+
children: o.map((o, g) => /* @__PURE__ */ jsx("div", {
|
|
560
|
+
onClick: () => h(o),
|
|
561
|
+
onMouseOver: () => v(g),
|
|
500
562
|
style: {
|
|
501
563
|
cursor: "pointer",
|
|
502
564
|
padding: "4px 8px",
|
|
503
|
-
backgroundColor:
|
|
565
|
+
backgroundColor: _ === g ? "#094771" : "transparent"
|
|
504
566
|
},
|
|
505
567
|
children: o
|
|
506
|
-
},
|
|
568
|
+
}, g))
|
|
507
569
|
});
|
|
508
570
|
}
|
|
509
|
-
function DslEditor({ code: o, onChange:
|
|
510
|
-
let [
|
|
571
|
+
function DslEditor({ code: o, onChange: _, onParsed: x, grammar: w, wrap: T = !1, suggestions: E, className: D = DslEditor.name, syntaxColors: O = defaultSyntaxColors("light"),...k }) {
|
|
572
|
+
let [A, j] = useState([]), [M, P] = useState(), [F, I] = useState({
|
|
511
573
|
top: 0,
|
|
512
574
|
left: 0,
|
|
513
575
|
visible: !1
|
|
514
|
-
}), [
|
|
515
|
-
let
|
|
516
|
-
|
|
517
|
-
}, [
|
|
518
|
-
|
|
519
|
-
}, [
|
|
576
|
+
}), [L, R] = useState(0), [z, B] = useState(""), V = useRef(null), H = useRef(null), U = useRef(null), W = useRef(null), G = useRef(null), K = useCallback((o) => {
|
|
577
|
+
let h = H.current?.selectionStart ?? 0, g = getSuggestions(o, h, E);
|
|
578
|
+
j(g);
|
|
579
|
+
}, [E]), q = useCallback(() => {
|
|
580
|
+
M && (K(M.cst), B(H.current?.value?.substring(0, H.current?.selectionStart ?? 0) ?? ""));
|
|
581
|
+
}, [M, K]);
|
|
520
582
|
useEffect(() => {
|
|
521
|
-
|
|
522
|
-
}, [
|
|
523
|
-
if (!
|
|
524
|
-
let
|
|
525
|
-
|
|
583
|
+
V.current = new DSLParser(w);
|
|
584
|
+
}, [w]), useEffect(() => {
|
|
585
|
+
if (!V.current) return;
|
|
586
|
+
let h = V.current.parse(o);
|
|
587
|
+
P(h), x?.(h), K(h.cst), B(o.substring(0, H.current?.selectionStart ?? 0));
|
|
526
588
|
}, [
|
|
527
589
|
o,
|
|
528
|
-
|
|
590
|
+
x,
|
|
529
591
|
K
|
|
530
592
|
]);
|
|
531
|
-
let J = useCallback(() =>
|
|
593
|
+
let J = useCallback(() => U.current?.getCursorPosition?.() ?? {
|
|
532
594
|
top: 0,
|
|
533
595
|
left: 0
|
|
534
596
|
}, []), Y = useCallback((o) => {
|
|
535
|
-
|
|
597
|
+
H.current && console.log(o);
|
|
536
598
|
}, [
|
|
537
599
|
o,
|
|
538
|
-
|
|
539
|
-
|
|
600
|
+
_,
|
|
601
|
+
A
|
|
540
602
|
]), X = useMemo(() => ({
|
|
541
603
|
ArrowDown() {
|
|
542
|
-
|
|
604
|
+
R((o) => (o + 1) % A.length);
|
|
543
605
|
},
|
|
544
606
|
ArrowUp() {
|
|
545
|
-
|
|
607
|
+
R((o) => (o - 1 + A.length) % A.length);
|
|
546
608
|
},
|
|
547
609
|
Enter() {
|
|
548
|
-
|
|
610
|
+
A[L] && Y(A[L].suggestion);
|
|
549
611
|
},
|
|
550
612
|
Escape() {
|
|
551
|
-
|
|
613
|
+
I((o) => ({
|
|
552
614
|
...o,
|
|
553
615
|
visible: !1
|
|
554
616
|
}));
|
|
555
617
|
}
|
|
556
618
|
}), [
|
|
557
619
|
Y,
|
|
558
|
-
|
|
559
|
-
|
|
620
|
+
L,
|
|
621
|
+
A
|
|
560
622
|
]), Z = useMemo(() => ({ CtrlSpace() {
|
|
561
|
-
let { top: o, left:
|
|
562
|
-
|
|
623
|
+
let { top: o, left: h } = J();
|
|
624
|
+
R(0), I({
|
|
563
625
|
visible: !0,
|
|
564
626
|
top: o,
|
|
565
|
-
left:
|
|
627
|
+
left: h
|
|
566
628
|
});
|
|
567
629
|
} }), [J]), Q = useCallback((o) => {
|
|
568
|
-
let
|
|
569
|
-
|
|
630
|
+
let h = (F.visible ? X : Z)[shortcutName(o)];
|
|
631
|
+
h && (o.preventDefault(), h());
|
|
570
632
|
}, [
|
|
571
|
-
|
|
633
|
+
F.visible,
|
|
572
634
|
X,
|
|
573
635
|
Z
|
|
574
636
|
]), $ = useCallback((o) => {
|
|
575
|
-
|
|
637
|
+
_(o.target.value), I((o) => ({
|
|
576
638
|
...o,
|
|
577
639
|
visible: !1
|
|
578
|
-
})),
|
|
579
|
-
}, [
|
|
640
|
+
})), B(o.target.value.substring(0, o.target.selectionStart));
|
|
641
|
+
}, [_]);
|
|
580
642
|
return /* @__PURE__ */ jsxs("div", {
|
|
581
643
|
style: {
|
|
582
644
|
display: "grid",
|
|
@@ -585,7 +647,7 @@ function DslEditor({ code: o, onChange: y, onParsed: T, grammar: E, wrap: D = !1
|
|
|
585
647
|
width: "100%",
|
|
586
648
|
height: "100%"
|
|
587
649
|
},
|
|
588
|
-
className:
|
|
650
|
+
className: D,
|
|
589
651
|
children: [
|
|
590
652
|
/* @__PURE__ */ jsxs("div", {
|
|
591
653
|
style: {
|
|
@@ -595,9 +657,9 @@ function DslEditor({ code: o, onChange: y, onParsed: T, grammar: E, wrap: D = !1
|
|
|
595
657
|
},
|
|
596
658
|
children: [
|
|
597
659
|
/* @__PURE__ */ jsx("textarea", {
|
|
598
|
-
ref:
|
|
660
|
+
ref: H,
|
|
599
661
|
spellCheck: !1,
|
|
600
|
-
wrap:
|
|
662
|
+
wrap: T ? "soft" : "off",
|
|
601
663
|
style: {
|
|
602
664
|
...textStyle,
|
|
603
665
|
color: "transparent",
|
|
@@ -609,45 +671,52 @@ function DslEditor({ code: o, onChange: y, onParsed: T, grammar: E, wrap: D = !1
|
|
|
609
671
|
value: o,
|
|
610
672
|
onSelect: q,
|
|
611
673
|
onChange: $,
|
|
612
|
-
onScroll: useSyncScroll(G),
|
|
674
|
+
onScroll: useSyncScroll(W, G),
|
|
613
675
|
onKeyDown: Q,
|
|
614
|
-
...
|
|
676
|
+
...k
|
|
615
677
|
}),
|
|
616
|
-
|
|
617
|
-
cstRoot:
|
|
678
|
+
M && /* @__PURE__ */ jsx(SyntaxHighlighter, {
|
|
679
|
+
cstRoot: M.cst,
|
|
680
|
+
ref: W,
|
|
681
|
+
wrap: T,
|
|
682
|
+
syntaxColors: O
|
|
683
|
+
}),
|
|
684
|
+
!e(M?.errors ?? []) && /* @__PURE__ */ jsx(ErrorHighlighter, {
|
|
618
685
|
ref: G,
|
|
619
|
-
|
|
686
|
+
errors: M?.errors ?? [],
|
|
687
|
+
wrap: T,
|
|
688
|
+
children: o
|
|
620
689
|
}),
|
|
621
690
|
/* @__PURE__ */ jsx(CursorPosition, {
|
|
622
|
-
ref:
|
|
623
|
-
text:
|
|
624
|
-
wrap:
|
|
691
|
+
ref: U,
|
|
692
|
+
text: z,
|
|
693
|
+
wrap: T
|
|
625
694
|
}),
|
|
626
|
-
|
|
627
|
-
suggestions:
|
|
695
|
+
F.visible && A.length > 0 && /* @__PURE__ */ jsx(SuggestionsMenu, {
|
|
696
|
+
suggestions: A.map((o) => o.suggestion),
|
|
628
697
|
onSelect: Y,
|
|
629
698
|
style: {
|
|
630
|
-
top:
|
|
631
|
-
left:
|
|
699
|
+
top: F.top,
|
|
700
|
+
left: F.left
|
|
632
701
|
},
|
|
633
|
-
selectedIndex:
|
|
634
|
-
onHover:
|
|
702
|
+
selectedIndex: L,
|
|
703
|
+
onHover: R
|
|
635
704
|
})
|
|
636
705
|
]
|
|
637
706
|
}),
|
|
638
|
-
JSON.stringify(
|
|
707
|
+
JSON.stringify(M?.errors ?? []),
|
|
639
708
|
/* @__PURE__ */ jsx(SuggestionsView, {
|
|
640
|
-
suggestions:
|
|
709
|
+
suggestions: A.map((o) => o.suggestion),
|
|
641
710
|
onSelect: Y
|
|
642
711
|
})
|
|
643
712
|
]
|
|
644
713
|
});
|
|
645
714
|
}
|
|
646
|
-
function visit(o,
|
|
647
|
-
return isParserError(o) ? [] : (((o) => o.grammar.meta?.name
|
|
715
|
+
function visit(o, h, g = (o) => o.text) {
|
|
716
|
+
return isParserError(o) ? [] : (((o) => o.grammar.meta?.name !== void 0 && h.includes(o.grammar.meta?.name))(o) ? [g(o)] : []).concat(...o.children?.flatMap((o) => visit(o, h, g)) ?? []);
|
|
648
717
|
}
|
|
649
|
-
var require_types = /* @__PURE__ */ __commonJSMin(((o,
|
|
650
|
-
|
|
718
|
+
var require_types = /* @__PURE__ */ __commonJSMin(((o, h) => {
|
|
719
|
+
h.exports = {
|
|
651
720
|
ROOT: 0,
|
|
652
721
|
GROUP: 1,
|
|
653
722
|
POSITION: 2,
|
|
@@ -658,136 +727,136 @@ var require_types = /* @__PURE__ */ __commonJSMin(((o, _) => {
|
|
|
658
727
|
CHAR: 7
|
|
659
728
|
};
|
|
660
729
|
})), require_sets = /* @__PURE__ */ __commonJSMin(((o) => {
|
|
661
|
-
var
|
|
662
|
-
type:
|
|
730
|
+
var h = require_types(), g = () => [{
|
|
731
|
+
type: h.RANGE,
|
|
663
732
|
from: 48,
|
|
664
733
|
to: 57
|
|
665
|
-
}],
|
|
734
|
+
}], _ = () => [
|
|
666
735
|
{
|
|
667
|
-
type:
|
|
736
|
+
type: h.CHAR,
|
|
668
737
|
value: 95
|
|
669
738
|
},
|
|
670
739
|
{
|
|
671
|
-
type:
|
|
740
|
+
type: h.RANGE,
|
|
672
741
|
from: 97,
|
|
673
742
|
to: 122
|
|
674
743
|
},
|
|
675
744
|
{
|
|
676
|
-
type:
|
|
745
|
+
type: h.RANGE,
|
|
677
746
|
from: 65,
|
|
678
747
|
to: 90
|
|
679
748
|
}
|
|
680
|
-
].concat(
|
|
749
|
+
].concat(g()), v = () => [
|
|
681
750
|
{
|
|
682
|
-
type:
|
|
751
|
+
type: h.CHAR,
|
|
683
752
|
value: 9
|
|
684
753
|
},
|
|
685
754
|
{
|
|
686
|
-
type:
|
|
755
|
+
type: h.CHAR,
|
|
687
756
|
value: 10
|
|
688
757
|
},
|
|
689
758
|
{
|
|
690
|
-
type:
|
|
759
|
+
type: h.CHAR,
|
|
691
760
|
value: 11
|
|
692
761
|
},
|
|
693
762
|
{
|
|
694
|
-
type:
|
|
763
|
+
type: h.CHAR,
|
|
695
764
|
value: 12
|
|
696
765
|
},
|
|
697
766
|
{
|
|
698
|
-
type:
|
|
767
|
+
type: h.CHAR,
|
|
699
768
|
value: 13
|
|
700
769
|
},
|
|
701
770
|
{
|
|
702
|
-
type:
|
|
771
|
+
type: h.CHAR,
|
|
703
772
|
value: 32
|
|
704
773
|
},
|
|
705
774
|
{
|
|
706
|
-
type:
|
|
775
|
+
type: h.CHAR,
|
|
707
776
|
value: 160
|
|
708
777
|
},
|
|
709
778
|
{
|
|
710
|
-
type:
|
|
779
|
+
type: h.CHAR,
|
|
711
780
|
value: 5760
|
|
712
781
|
},
|
|
713
782
|
{
|
|
714
|
-
type:
|
|
783
|
+
type: h.RANGE,
|
|
715
784
|
from: 8192,
|
|
716
785
|
to: 8202
|
|
717
786
|
},
|
|
718
787
|
{
|
|
719
|
-
type:
|
|
788
|
+
type: h.CHAR,
|
|
720
789
|
value: 8232
|
|
721
790
|
},
|
|
722
791
|
{
|
|
723
|
-
type:
|
|
792
|
+
type: h.CHAR,
|
|
724
793
|
value: 8233
|
|
725
794
|
},
|
|
726
795
|
{
|
|
727
|
-
type:
|
|
796
|
+
type: h.CHAR,
|
|
728
797
|
value: 8239
|
|
729
798
|
},
|
|
730
799
|
{
|
|
731
|
-
type:
|
|
800
|
+
type: h.CHAR,
|
|
732
801
|
value: 8287
|
|
733
802
|
},
|
|
734
803
|
{
|
|
735
|
-
type:
|
|
804
|
+
type: h.CHAR,
|
|
736
805
|
value: 12288
|
|
737
806
|
},
|
|
738
807
|
{
|
|
739
|
-
type:
|
|
808
|
+
type: h.CHAR,
|
|
740
809
|
value: 65279
|
|
741
810
|
}
|
|
742
|
-
],
|
|
811
|
+
], y = () => [
|
|
743
812
|
{
|
|
744
|
-
type:
|
|
813
|
+
type: h.CHAR,
|
|
745
814
|
value: 10
|
|
746
815
|
},
|
|
747
816
|
{
|
|
748
|
-
type:
|
|
817
|
+
type: h.CHAR,
|
|
749
818
|
value: 13
|
|
750
819
|
},
|
|
751
820
|
{
|
|
752
|
-
type:
|
|
821
|
+
type: h.CHAR,
|
|
753
822
|
value: 8232
|
|
754
823
|
},
|
|
755
824
|
{
|
|
756
|
-
type:
|
|
825
|
+
type: h.CHAR,
|
|
757
826
|
value: 8233
|
|
758
827
|
}
|
|
759
828
|
];
|
|
760
829
|
o.words = () => ({
|
|
761
|
-
type:
|
|
762
|
-
set:
|
|
830
|
+
type: h.SET,
|
|
831
|
+
set: _(),
|
|
763
832
|
not: !1
|
|
764
833
|
}), o.notWords = () => ({
|
|
765
|
-
type:
|
|
766
|
-
set:
|
|
834
|
+
type: h.SET,
|
|
835
|
+
set: _(),
|
|
767
836
|
not: !0
|
|
768
837
|
}), o.ints = () => ({
|
|
769
|
-
type:
|
|
770
|
-
set:
|
|
838
|
+
type: h.SET,
|
|
839
|
+
set: g(),
|
|
771
840
|
not: !1
|
|
772
841
|
}), o.notInts = () => ({
|
|
773
|
-
type:
|
|
774
|
-
set:
|
|
842
|
+
type: h.SET,
|
|
843
|
+
set: g(),
|
|
775
844
|
not: !0
|
|
776
845
|
}), o.whitespace = () => ({
|
|
777
|
-
type:
|
|
778
|
-
set:
|
|
846
|
+
type: h.SET,
|
|
847
|
+
set: v(),
|
|
779
848
|
not: !1
|
|
780
849
|
}), o.notWhitespace = () => ({
|
|
781
|
-
type:
|
|
782
|
-
set:
|
|
850
|
+
type: h.SET,
|
|
851
|
+
set: v(),
|
|
783
852
|
not: !0
|
|
784
853
|
}), o.anyChar = () => ({
|
|
785
|
-
type:
|
|
786
|
-
set:
|
|
854
|
+
type: h.SET,
|
|
855
|
+
set: y(),
|
|
787
856
|
not: !0
|
|
788
857
|
});
|
|
789
858
|
})), require_util = /* @__PURE__ */ __commonJSMin(((o) => {
|
|
790
|
-
var
|
|
859
|
+
var h = require_types(), g = require_sets(), _ = "@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^ ?", v = {
|
|
791
860
|
0: 0,
|
|
792
861
|
t: 9,
|
|
793
862
|
n: 10,
|
|
@@ -796,174 +865,174 @@ var require_types = /* @__PURE__ */ __commonJSMin(((o, _) => {
|
|
|
796
865
|
r: 13
|
|
797
866
|
};
|
|
798
867
|
o.strToChars = function(o) {
|
|
799
|
-
return o = o.replace(/(\[\\b\])|(\\)?\\(?:u([A-F0-9]{4})|x([A-F0-9]{2})|(0?[0-7]{2})|c([@A-Z[\\\]^?])|([0tnvfr]))/g, function(o,
|
|
800
|
-
if (
|
|
801
|
-
var
|
|
802
|
-
return /[[\]{}^$.|?*+()]/.test(
|
|
868
|
+
return o = o.replace(/(\[\\b\])|(\\)?\\(?:u([A-F0-9]{4})|x([A-F0-9]{2})|(0?[0-7]{2})|c([@A-Z[\\\]^?])|([0tnvfr]))/g, function(o, h, g, y, b, x, S, C) {
|
|
869
|
+
if (g) return o;
|
|
870
|
+
var w = h ? 8 : y ? parseInt(y, 16) : b ? parseInt(b, 16) : x ? parseInt(x, 8) : S ? _.indexOf(S) : v[C], T = String.fromCharCode(w);
|
|
871
|
+
return /[[\]{}^$.|?*+()]/.test(T) && (T = "\\" + T), T;
|
|
803
872
|
}), o;
|
|
804
|
-
}, o.tokenizeClass = (
|
|
805
|
-
for (var
|
|
806
|
-
else if (
|
|
807
|
-
else if (
|
|
808
|
-
else if (
|
|
809
|
-
else if (
|
|
810
|
-
else if (
|
|
811
|
-
else if (
|
|
812
|
-
type:
|
|
813
|
-
from: (
|
|
814
|
-
to:
|
|
873
|
+
}, o.tokenizeClass = (_, v) => {
|
|
874
|
+
for (var y = [], b = /\\(?:(w)|(d)|(s)|(W)|(D)|(S))|((?:(?:\\)(.)|([^\]\\]))-(?:\\)?([^\]]))|(\])|(?:\\)?([^])/g, x, S; (x = b.exec(_)) != null;) if (x[1]) y.push(g.words());
|
|
875
|
+
else if (x[2]) y.push(g.ints());
|
|
876
|
+
else if (x[3]) y.push(g.whitespace());
|
|
877
|
+
else if (x[4]) y.push(g.notWords());
|
|
878
|
+
else if (x[5]) y.push(g.notInts());
|
|
879
|
+
else if (x[6]) y.push(g.notWhitespace());
|
|
880
|
+
else if (x[7]) y.push({
|
|
881
|
+
type: h.RANGE,
|
|
882
|
+
from: (x[8] || x[9]).charCodeAt(0),
|
|
883
|
+
to: x[10].charCodeAt(0)
|
|
815
884
|
});
|
|
816
|
-
else if (
|
|
817
|
-
type:
|
|
818
|
-
value:
|
|
885
|
+
else if (S = x[12]) y.push({
|
|
886
|
+
type: h.CHAR,
|
|
887
|
+
value: S.charCodeAt(0)
|
|
819
888
|
});
|
|
820
|
-
else return [
|
|
821
|
-
o.error(
|
|
822
|
-
}, o.error = (o,
|
|
823
|
-
throw SyntaxError("Invalid regular expression: /" + o + "/: " +
|
|
889
|
+
else return [y, b.lastIndex];
|
|
890
|
+
o.error(v, "Unterminated character class");
|
|
891
|
+
}, o.error = (o, h) => {
|
|
892
|
+
throw SyntaxError("Invalid regular expression: /" + o + "/: " + h);
|
|
824
893
|
};
|
|
825
894
|
})), require_positions = /* @__PURE__ */ __commonJSMin(((o) => {
|
|
826
|
-
var
|
|
895
|
+
var h = require_types();
|
|
827
896
|
o.wordBoundary = () => ({
|
|
828
|
-
type:
|
|
897
|
+
type: h.POSITION,
|
|
829
898
|
value: "b"
|
|
830
899
|
}), o.nonWordBoundary = () => ({
|
|
831
|
-
type:
|
|
900
|
+
type: h.POSITION,
|
|
832
901
|
value: "B"
|
|
833
902
|
}), o.begin = () => ({
|
|
834
|
-
type:
|
|
903
|
+
type: h.POSITION,
|
|
835
904
|
value: "^"
|
|
836
905
|
}), o.end = () => ({
|
|
837
|
-
type:
|
|
906
|
+
type: h.POSITION,
|
|
838
907
|
value: "$"
|
|
839
908
|
});
|
|
840
|
-
})), require_lib$1 = /* @__PURE__ */ __commonJSMin(((o,
|
|
841
|
-
var
|
|
842
|
-
|
|
843
|
-
var
|
|
844
|
-
type:
|
|
909
|
+
})), require_lib$1 = /* @__PURE__ */ __commonJSMin(((o, h) => {
|
|
910
|
+
var g = require_util(), _ = require_types(), v = require_sets(), y = require_positions();
|
|
911
|
+
h.exports = (o) => {
|
|
912
|
+
var h = 0, b, x, S = {
|
|
913
|
+
type: _.ROOT,
|
|
845
914
|
stack: []
|
|
846
|
-
},
|
|
847
|
-
|
|
848
|
-
},
|
|
849
|
-
for (
|
|
915
|
+
}, C = S, w = S.stack, T = [], E = (h) => {
|
|
916
|
+
g.error(o, `Nothing to repeat at column ${h - 1}`);
|
|
917
|
+
}, D = g.strToChars(o);
|
|
918
|
+
for (b = D.length; h < b;) switch (x = D[h++], x) {
|
|
850
919
|
case "\\":
|
|
851
|
-
switch (
|
|
920
|
+
switch (x = D[h++], x) {
|
|
852
921
|
case "b":
|
|
853
|
-
|
|
922
|
+
w.push(y.wordBoundary());
|
|
854
923
|
break;
|
|
855
924
|
case "B":
|
|
856
|
-
|
|
925
|
+
w.push(y.nonWordBoundary());
|
|
857
926
|
break;
|
|
858
927
|
case "w":
|
|
859
|
-
|
|
928
|
+
w.push(v.words());
|
|
860
929
|
break;
|
|
861
930
|
case "W":
|
|
862
|
-
|
|
931
|
+
w.push(v.notWords());
|
|
863
932
|
break;
|
|
864
933
|
case "d":
|
|
865
|
-
|
|
934
|
+
w.push(v.ints());
|
|
866
935
|
break;
|
|
867
936
|
case "D":
|
|
868
|
-
|
|
937
|
+
w.push(v.notInts());
|
|
869
938
|
break;
|
|
870
939
|
case "s":
|
|
871
|
-
|
|
940
|
+
w.push(v.whitespace());
|
|
872
941
|
break;
|
|
873
942
|
case "S":
|
|
874
|
-
|
|
943
|
+
w.push(v.notWhitespace());
|
|
875
944
|
break;
|
|
876
|
-
default: /\d/.test(
|
|
877
|
-
type:
|
|
878
|
-
value: parseInt(
|
|
879
|
-
}) :
|
|
880
|
-
type:
|
|
881
|
-
value:
|
|
945
|
+
default: /\d/.test(x) ? w.push({
|
|
946
|
+
type: _.REFERENCE,
|
|
947
|
+
value: parseInt(x, 10)
|
|
948
|
+
}) : w.push({
|
|
949
|
+
type: _.CHAR,
|
|
950
|
+
value: x.charCodeAt(0)
|
|
882
951
|
});
|
|
883
952
|
}
|
|
884
953
|
break;
|
|
885
954
|
case "^":
|
|
886
|
-
|
|
955
|
+
w.push(y.begin());
|
|
887
956
|
break;
|
|
888
957
|
case "$":
|
|
889
|
-
|
|
958
|
+
w.push(y.end());
|
|
890
959
|
break;
|
|
891
960
|
case "[":
|
|
892
|
-
var
|
|
893
|
-
|
|
894
|
-
var
|
|
895
|
-
|
|
896
|
-
type:
|
|
897
|
-
set:
|
|
898
|
-
not:
|
|
961
|
+
var O;
|
|
962
|
+
D[h] === "^" ? (O = !0, h++) : O = !1;
|
|
963
|
+
var k = g.tokenizeClass(D.slice(h), o);
|
|
964
|
+
h += k[1], w.push({
|
|
965
|
+
type: _.SET,
|
|
966
|
+
set: k[0],
|
|
967
|
+
not: O
|
|
899
968
|
});
|
|
900
969
|
break;
|
|
901
970
|
case ".":
|
|
902
|
-
|
|
971
|
+
w.push(v.anyChar());
|
|
903
972
|
break;
|
|
904
973
|
case "(":
|
|
905
|
-
var
|
|
906
|
-
type:
|
|
974
|
+
var A = {
|
|
975
|
+
type: _.GROUP,
|
|
907
976
|
stack: [],
|
|
908
977
|
remember: !0
|
|
909
978
|
};
|
|
910
|
-
|
|
979
|
+
x = D[h], x === "?" && (x = D[h + 1], h += 2, x === "=" ? A.followedBy = !0 : x === "!" ? A.notFollowedBy = !0 : x !== ":" && g.error(o, `Invalid group, character '${x}' after '?' at column ${h - 1}`), A.remember = !1), w.push(A), T.push(C), C = A, w = A.stack;
|
|
911
980
|
break;
|
|
912
981
|
case ")":
|
|
913
|
-
|
|
982
|
+
T.length === 0 && g.error(o, `Unmatched ) at column ${h - 1}`), C = T.pop(), w = C.options ? C.options[C.options.length - 1] : C.stack;
|
|
914
983
|
break;
|
|
915
984
|
case "|":
|
|
916
|
-
|
|
917
|
-
var
|
|
918
|
-
|
|
985
|
+
C.options || (C.options = [C.stack], delete C.stack);
|
|
986
|
+
var j = [];
|
|
987
|
+
C.options.push(j), w = j;
|
|
919
988
|
break;
|
|
920
989
|
case "{":
|
|
921
|
-
var
|
|
922
|
-
|
|
923
|
-
type:
|
|
990
|
+
var M = /^(\d+)(,(\d+)?)?\}/.exec(D.slice(h)), N, P;
|
|
991
|
+
M === null ? w.push({
|
|
992
|
+
type: _.CHAR,
|
|
924
993
|
value: 123
|
|
925
|
-
}) : (
|
|
926
|
-
type:
|
|
927
|
-
min:
|
|
928
|
-
max:
|
|
929
|
-
value:
|
|
994
|
+
}) : (w.length === 0 && E(h), N = parseInt(M[1], 10), P = M[2] ? M[3] ? parseInt(M[3], 10) : Infinity : N, h += M[0].length, w.push({
|
|
995
|
+
type: _.REPETITION,
|
|
996
|
+
min: N,
|
|
997
|
+
max: P,
|
|
998
|
+
value: w.pop()
|
|
930
999
|
}));
|
|
931
1000
|
break;
|
|
932
1001
|
case "?":
|
|
933
|
-
|
|
934
|
-
type:
|
|
1002
|
+
w.length === 0 && E(h), w.push({
|
|
1003
|
+
type: _.REPETITION,
|
|
935
1004
|
min: 0,
|
|
936
1005
|
max: 1,
|
|
937
|
-
value:
|
|
1006
|
+
value: w.pop()
|
|
938
1007
|
});
|
|
939
1008
|
break;
|
|
940
1009
|
case "+":
|
|
941
|
-
|
|
942
|
-
type:
|
|
1010
|
+
w.length === 0 && E(h), w.push({
|
|
1011
|
+
type: _.REPETITION,
|
|
943
1012
|
min: 1,
|
|
944
1013
|
max: Infinity,
|
|
945
|
-
value:
|
|
1014
|
+
value: w.pop()
|
|
946
1015
|
});
|
|
947
1016
|
break;
|
|
948
1017
|
case "*":
|
|
949
|
-
|
|
950
|
-
type:
|
|
1018
|
+
w.length === 0 && E(h), w.push({
|
|
1019
|
+
type: _.REPETITION,
|
|
951
1020
|
min: 0,
|
|
952
1021
|
max: Infinity,
|
|
953
|
-
value:
|
|
1022
|
+
value: w.pop()
|
|
954
1023
|
});
|
|
955
1024
|
break;
|
|
956
|
-
default:
|
|
957
|
-
type:
|
|
958
|
-
value:
|
|
1025
|
+
default: w.push({
|
|
1026
|
+
type: _.CHAR,
|
|
1027
|
+
value: x.charCodeAt(0)
|
|
959
1028
|
});
|
|
960
1029
|
}
|
|
961
|
-
return
|
|
962
|
-
},
|
|
963
|
-
})), require_lib = /* @__PURE__ */ __commonJSMin(((o,
|
|
964
|
-
var
|
|
965
|
-
constructor(o,
|
|
966
|
-
this.low = o, this.high =
|
|
1030
|
+
return T.length !== 0 && g.error(o, "Unterminated group"), S;
|
|
1031
|
+
}, h.exports.types = _;
|
|
1032
|
+
})), require_lib = /* @__PURE__ */ __commonJSMin(((o, h) => {
|
|
1033
|
+
var g = class o {
|
|
1034
|
+
constructor(o, h) {
|
|
1035
|
+
this.low = o, this.high = h, this.length = 1 + h - o;
|
|
967
1036
|
}
|
|
968
1037
|
overlaps(o) {
|
|
969
1038
|
return !(this.high < o.low || this.low > o.high);
|
|
@@ -971,52 +1040,52 @@ var require_types = /* @__PURE__ */ __commonJSMin(((o, _) => {
|
|
|
971
1040
|
touches(o) {
|
|
972
1041
|
return !(this.high + 1 < o.low || this.low - 1 > o.high);
|
|
973
1042
|
}
|
|
974
|
-
add(
|
|
975
|
-
return new o(Math.min(this.low,
|
|
1043
|
+
add(h) {
|
|
1044
|
+
return new o(Math.min(this.low, h.low), Math.max(this.high, h.high));
|
|
976
1045
|
}
|
|
977
|
-
subtract(
|
|
978
|
-
return
|
|
1046
|
+
subtract(h) {
|
|
1047
|
+
return h.low <= this.low && h.high >= this.high ? [] : h.low > this.low && h.high < this.high ? [new o(this.low, h.low - 1), new o(h.high + 1, this.high)] : h.low <= this.low ? [new o(h.high + 1, this.high)] : [new o(this.low, h.low - 1)];
|
|
979
1048
|
}
|
|
980
1049
|
toString() {
|
|
981
1050
|
return this.low == this.high ? this.low.toString() : this.low + "-" + this.high;
|
|
982
1051
|
}
|
|
983
1052
|
};
|
|
984
|
-
|
|
985
|
-
constructor(o,
|
|
986
|
-
this.ranges = [], this.length = 0, o != null && this.add(o,
|
|
1053
|
+
h.exports = class o {
|
|
1054
|
+
constructor(o, h) {
|
|
1055
|
+
this.ranges = [], this.length = 0, o != null && this.add(o, h);
|
|
987
1056
|
}
|
|
988
1057
|
_update_length() {
|
|
989
|
-
this.length = this.ranges.reduce((o,
|
|
1058
|
+
this.length = this.ranges.reduce((o, h) => o + h.length, 0);
|
|
990
1059
|
}
|
|
991
|
-
add(
|
|
992
|
-
var
|
|
993
|
-
for (var
|
|
994
|
-
for (var
|
|
995
|
-
|
|
1060
|
+
add(h, _) {
|
|
1061
|
+
var v = (o) => {
|
|
1062
|
+
for (var h = 0; h < this.ranges.length && !o.touches(this.ranges[h]);) h++;
|
|
1063
|
+
for (var g = this.ranges.slice(0, h); h < this.ranges.length && o.touches(this.ranges[h]);) o = o.add(this.ranges[h]), h++;
|
|
1064
|
+
g.push(o), this.ranges = g.concat(this.ranges.slice(h)), this._update_length();
|
|
996
1065
|
};
|
|
997
|
-
return
|
|
1066
|
+
return h instanceof o ? h.ranges.forEach(v) : (_ ??= h, v(new g(h, _))), this;
|
|
998
1067
|
}
|
|
999
|
-
subtract(
|
|
1000
|
-
var
|
|
1001
|
-
for (var
|
|
1002
|
-
for (var
|
|
1003
|
-
this.ranges =
|
|
1068
|
+
subtract(h, _) {
|
|
1069
|
+
var v = (o) => {
|
|
1070
|
+
for (var h = 0; h < this.ranges.length && !o.overlaps(this.ranges[h]);) h++;
|
|
1071
|
+
for (var g = this.ranges.slice(0, h); h < this.ranges.length && o.overlaps(this.ranges[h]);) g = g.concat(this.ranges[h].subtract(o)), h++;
|
|
1072
|
+
this.ranges = g.concat(this.ranges.slice(h)), this._update_length();
|
|
1004
1073
|
};
|
|
1005
|
-
return
|
|
1074
|
+
return h instanceof o ? h.ranges.forEach(v) : (_ ??= h, v(new g(h, _))), this;
|
|
1006
1075
|
}
|
|
1007
|
-
intersect(
|
|
1008
|
-
var
|
|
1009
|
-
for (var
|
|
1010
|
-
for (;
|
|
1011
|
-
var
|
|
1012
|
-
|
|
1076
|
+
intersect(h, _) {
|
|
1077
|
+
var v = [], y = (o) => {
|
|
1078
|
+
for (var h = 0; h < this.ranges.length && !o.overlaps(this.ranges[h]);) h++;
|
|
1079
|
+
for (; h < this.ranges.length && o.overlaps(this.ranges[h]);) {
|
|
1080
|
+
var _ = Math.max(this.ranges[h].low, o.low), y = Math.min(this.ranges[h].high, o.high);
|
|
1081
|
+
v.push(new g(_, y)), h++;
|
|
1013
1082
|
}
|
|
1014
1083
|
};
|
|
1015
|
-
return
|
|
1084
|
+
return h instanceof o ? h.ranges.forEach(y) : (_ ??= h, y(new g(h, _))), this.ranges = v, this._update_length(), this;
|
|
1016
1085
|
}
|
|
1017
1086
|
index(o) {
|
|
1018
|
-
for (var
|
|
1019
|
-
return this.ranges[
|
|
1087
|
+
for (var h = 0; h < this.ranges.length && this.ranges[h].length <= o;) o -= this.ranges[h].length, h++;
|
|
1088
|
+
return this.ranges[h].low + o;
|
|
1020
1089
|
}
|
|
1021
1090
|
toString() {
|
|
1022
1091
|
return "[ " + this.ranges.join(", ") + " ]";
|
|
@@ -1025,8 +1094,8 @@ var require_types = /* @__PURE__ */ __commonJSMin(((o, _) => {
|
|
|
1025
1094
|
return new o(this);
|
|
1026
1095
|
}
|
|
1027
1096
|
numbers() {
|
|
1028
|
-
return this.ranges.reduce((o,
|
|
1029
|
-
for (var
|
|
1097
|
+
return this.ranges.reduce((o, h) => {
|
|
1098
|
+
for (var g = h.low; g <= h.high;) o.push(g), g++;
|
|
1030
1099
|
return o;
|
|
1031
1100
|
}, []);
|
|
1032
1101
|
}
|
|
@@ -1038,40 +1107,40 @@ var require_types = /* @__PURE__ */ __commonJSMin(((o, _) => {
|
|
|
1038
1107
|
}));
|
|
1039
1108
|
}
|
|
1040
1109
|
};
|
|
1041
|
-
})), import_randexp = /* @__PURE__ */ __toESM((/* @__PURE__ */ __commonJSMin(((o,
|
|
1042
|
-
var
|
|
1043
|
-
|
|
1044
|
-
constructor(o,
|
|
1110
|
+
})), import_randexp = /* @__PURE__ */ __toESM((/* @__PURE__ */ __commonJSMin(((o, h) => {
|
|
1111
|
+
var g = require_lib$1(), _ = require_lib(), v = g.types;
|
|
1112
|
+
h.exports = class o {
|
|
1113
|
+
constructor(o, h) {
|
|
1045
1114
|
if (this._setDefaults(o), o instanceof RegExp) this.ignoreCase = o.ignoreCase, this.multiline = o.multiline, o = o.source;
|
|
1046
|
-
else if (typeof o == "string") this.ignoreCase =
|
|
1115
|
+
else if (typeof o == "string") this.ignoreCase = h && h.indexOf("i") !== -1, this.multiline = h && h.indexOf("m") !== -1;
|
|
1047
1116
|
else throw Error("Expected a regexp or string");
|
|
1048
|
-
this.tokens =
|
|
1117
|
+
this.tokens = g(o);
|
|
1049
1118
|
}
|
|
1050
|
-
_setDefaults(
|
|
1051
|
-
this.max =
|
|
1119
|
+
_setDefaults(h) {
|
|
1120
|
+
this.max = h.max == null ? o.prototype.max == null ? 100 : o.prototype.max : h.max, this.defaultRange = h.defaultRange ? h.defaultRange : this.defaultRange.clone(), h.randInt && (this.randInt = h.randInt);
|
|
1052
1121
|
}
|
|
1053
1122
|
gen() {
|
|
1054
1123
|
return this._gen(this.tokens, []);
|
|
1055
1124
|
}
|
|
1056
|
-
_gen(o,
|
|
1057
|
-
var
|
|
1125
|
+
_gen(o, h) {
|
|
1126
|
+
var g, _, y, b, x;
|
|
1058
1127
|
switch (o.type) {
|
|
1059
|
-
case
|
|
1060
|
-
case
|
|
1128
|
+
case v.ROOT:
|
|
1129
|
+
case v.GROUP:
|
|
1061
1130
|
if (o.followedBy || o.notFollowedBy) return "";
|
|
1062
|
-
for (o.remember && o.groupNumber === void 0 && (o.groupNumber =
|
|
1063
|
-
return o.remember && (
|
|
1064
|
-
case
|
|
1065
|
-
case
|
|
1066
|
-
var
|
|
1067
|
-
return
|
|
1068
|
-
case
|
|
1069
|
-
for (
|
|
1070
|
-
return
|
|
1071
|
-
case
|
|
1072
|
-
case
|
|
1073
|
-
var
|
|
1074
|
-
return String.fromCharCode(
|
|
1131
|
+
for (o.remember && o.groupNumber === void 0 && (o.groupNumber = h.push(null) - 1), g = o.options ? this._randSelect(o.options) : o.stack, _ = "", b = 0, x = g.length; b < x; b++) _ += this._gen(g[b], h);
|
|
1132
|
+
return o.remember && (h[o.groupNumber] = _), _;
|
|
1133
|
+
case v.POSITION: return "";
|
|
1134
|
+
case v.SET:
|
|
1135
|
+
var S = this._expand(o);
|
|
1136
|
+
return S.length ? String.fromCharCode(this._randSelect(S)) : "";
|
|
1137
|
+
case v.REPETITION:
|
|
1138
|
+
for (y = this.randInt(o.min, o.max === Infinity ? o.min + this.max : o.max), _ = "", b = 0; b < y; b++) _ += this._gen(o.value, h);
|
|
1139
|
+
return _;
|
|
1140
|
+
case v.REFERENCE: return h[o.value - 1] || "";
|
|
1141
|
+
case v.CHAR:
|
|
1142
|
+
var C = this.ignoreCase && this._randBool() ? this._toOtherCase(o.value) : o.value;
|
|
1143
|
+
return String.fromCharCode(C);
|
|
1075
1144
|
}
|
|
1076
1145
|
}
|
|
1077
1146
|
_toOtherCase(o) {
|
|
@@ -1081,35 +1150,35 @@ var require_types = /* @__PURE__ */ __commonJSMin(((o, _) => {
|
|
|
1081
1150
|
return !this.randInt(0, 1);
|
|
1082
1151
|
}
|
|
1083
1152
|
_randSelect(o) {
|
|
1084
|
-
return o instanceof
|
|
1153
|
+
return o instanceof _ ? o.index(this.randInt(0, o.length - 1)) : o[this.randInt(0, o.length - 1)];
|
|
1085
1154
|
}
|
|
1086
1155
|
_expand(o) {
|
|
1087
|
-
if (o.type ===
|
|
1088
|
-
if (o.type ===
|
|
1156
|
+
if (o.type === g.types.CHAR) return new _(o.value);
|
|
1157
|
+
if (o.type === g.types.RANGE) return new _(o.from, o.to);
|
|
1089
1158
|
{
|
|
1090
|
-
let
|
|
1091
|
-
for (let
|
|
1092
|
-
let
|
|
1093
|
-
if (
|
|
1094
|
-
let
|
|
1095
|
-
|
|
1159
|
+
let h = new _();
|
|
1160
|
+
for (let g = 0; g < o.set.length; g++) {
|
|
1161
|
+
let _ = this._expand(o.set[g]);
|
|
1162
|
+
if (h.add(_), this.ignoreCase) for (let o = 0; o < _.length; o++) {
|
|
1163
|
+
let g = _.index(o), v = this._toOtherCase(g);
|
|
1164
|
+
g !== v && h.add(v);
|
|
1096
1165
|
}
|
|
1097
1166
|
}
|
|
1098
|
-
return o.not ? this.defaultRange.clone().subtract(
|
|
1167
|
+
return o.not ? this.defaultRange.clone().subtract(h) : this.defaultRange.clone().intersect(h);
|
|
1099
1168
|
}
|
|
1100
1169
|
}
|
|
1101
|
-
randInt(o,
|
|
1102
|
-
return o + Math.floor(Math.random() * (1 +
|
|
1170
|
+
randInt(o, h) {
|
|
1171
|
+
return o + Math.floor(Math.random() * (1 + h - o));
|
|
1103
1172
|
}
|
|
1104
1173
|
get defaultRange() {
|
|
1105
|
-
return this._range = this._range || new
|
|
1174
|
+
return this._range = this._range || new _(32, 126);
|
|
1106
1175
|
}
|
|
1107
1176
|
set defaultRange(o) {
|
|
1108
1177
|
this._range = o;
|
|
1109
1178
|
}
|
|
1110
|
-
static randexp(
|
|
1111
|
-
var
|
|
1112
|
-
return typeof
|
|
1179
|
+
static randexp(h, g) {
|
|
1180
|
+
var _;
|
|
1181
|
+
return typeof h == "string" && (h = new RegExp(h, g)), h._randexp === void 0 ? (_ = new o(h, g), h._randexp = _) : (_ = h._randexp, _._setDefaults(h)), _.gen();
|
|
1113
1182
|
}
|
|
1114
1183
|
static sugar() {
|
|
1115
1184
|
RegExp.prototype.gen = function() {
|
|
@@ -1118,81 +1187,82 @@ var require_types = /* @__PURE__ */ __commonJSMin(((o, _) => {
|
|
|
1118
1187
|
}
|
|
1119
1188
|
};
|
|
1120
1189
|
})))()), array = [], characterCodeCache = [];
|
|
1121
|
-
function leven(o,
|
|
1122
|
-
if (o ===
|
|
1123
|
-
let
|
|
1124
|
-
o.length >
|
|
1125
|
-
let
|
|
1126
|
-
for (;
|
|
1127
|
-
let
|
|
1128
|
-
for (;
|
|
1129
|
-
if (
|
|
1130
|
-
if (
|
|
1131
|
-
let
|
|
1132
|
-
for (;
|
|
1133
|
-
for (;
|
|
1134
|
-
for (
|
|
1135
|
-
if (
|
|
1136
|
-
let o =
|
|
1137
|
-
for (
|
|
1138
|
-
if (o >
|
|
1190
|
+
function leven(o, h, g) {
|
|
1191
|
+
if (o === h) return 0;
|
|
1192
|
+
let _ = g?.maxDistance, v = o;
|
|
1193
|
+
o.length > h.length && (o = h, h = v);
|
|
1194
|
+
let y = o.length, b = h.length;
|
|
1195
|
+
for (; y > 0 && o.charCodeAt(~-y) === h.charCodeAt(~-b);) y--, b--;
|
|
1196
|
+
let x = 0;
|
|
1197
|
+
for (; x < y && o.charCodeAt(x) === h.charCodeAt(x);) x++;
|
|
1198
|
+
if (y -= x, b -= x, _ !== void 0 && b - y > _) return _;
|
|
1199
|
+
if (y === 0) return _ !== void 0 && b > _ ? _ : b;
|
|
1200
|
+
let S, C, w, T, E = 0, D = 0;
|
|
1201
|
+
for (; E < y;) characterCodeCache[E] = o.charCodeAt(x + E), array[E] = ++E;
|
|
1202
|
+
for (; D < b;) {
|
|
1203
|
+
for (S = h.charCodeAt(x + D), w = D++, C = D, E = 0; E < y; E++) T = S === characterCodeCache[E] ? w : w + 1, w = array[E], C = array[E] = w > C ? T > C ? C + 1 : T : T > w ? w + 1 : T;
|
|
1204
|
+
if (_ !== void 0) {
|
|
1205
|
+
let o = C;
|
|
1206
|
+
for (E = 0; E < y; E++) array[E] < o && (o = array[E]);
|
|
1207
|
+
if (o > _) return _;
|
|
1139
1208
|
}
|
|
1140
1209
|
}
|
|
1141
|
-
return array.length =
|
|
1210
|
+
return array.length = y, characterCodeCache.length = y, _ !== void 0 && C > _ ? _ : C;
|
|
1142
1211
|
}
|
|
1143
1212
|
function pattern(o) {
|
|
1144
|
-
let
|
|
1145
|
-
|
|
1146
|
-
function
|
|
1147
|
-
return t(t$4(0, 10), t$3(() =>
|
|
1213
|
+
let h = new import_randexp.default(o);
|
|
1214
|
+
h.randInt = () => 0, h.defaultRange.subtract(-Infinity, Infinity);
|
|
1215
|
+
function g() {
|
|
1216
|
+
return t(t$4(0, 10), t$3(() => h.gen()), n$2());
|
|
1148
1217
|
}
|
|
1149
|
-
let
|
|
1218
|
+
let _ = {
|
|
1150
1219
|
type: "pattern",
|
|
1151
1220
|
children: [],
|
|
1152
1221
|
meta: { regex: o },
|
|
1153
|
-
suggestions:
|
|
1154
|
-
parse(
|
|
1155
|
-
let
|
|
1156
|
-
|
|
1157
|
-
let
|
|
1158
|
-
if (
|
|
1159
|
-
text:
|
|
1160
|
-
grammar:
|
|
1222
|
+
suggestions: g,
|
|
1223
|
+
parse(h, v) {
|
|
1224
|
+
let y = new RegExp(o, "yu");
|
|
1225
|
+
y.lastIndex = 0;
|
|
1226
|
+
let b = y.exec(h);
|
|
1227
|
+
if (b) return success({
|
|
1228
|
+
text: b[0],
|
|
1229
|
+
grammar: _,
|
|
1161
1230
|
children: []
|
|
1162
1231
|
});
|
|
1163
|
-
if (
|
|
1164
|
-
let o = t(
|
|
1232
|
+
if (v.faultTolerant) {
|
|
1233
|
+
let o = t(g(), n((o) => leven(o, h) <= 2), n$1());
|
|
1165
1234
|
if (o !== void 0) return success({
|
|
1166
|
-
text:
|
|
1167
|
-
grammar:
|
|
1168
|
-
children: []
|
|
1235
|
+
text: h.substring(0, o.length),
|
|
1236
|
+
grammar: _,
|
|
1237
|
+
children: [],
|
|
1238
|
+
recoverableError: !0
|
|
1169
1239
|
});
|
|
1170
1240
|
}
|
|
1171
1241
|
return error({
|
|
1172
|
-
grammar:
|
|
1173
|
-
got:
|
|
1174
|
-
expected:
|
|
1242
|
+
grammar: _,
|
|
1243
|
+
got: h,
|
|
1244
|
+
expected: _.suggestions()
|
|
1175
1245
|
});
|
|
1176
1246
|
}
|
|
1177
1247
|
};
|
|
1178
|
-
return
|
|
1248
|
+
return _;
|
|
1179
1249
|
}
|
|
1180
1250
|
const rational = pattern(/\d+(:?.\d+)?/);
|
|
1181
1251
|
function optional(o) {
|
|
1182
|
-
let
|
|
1252
|
+
let h = {
|
|
1183
1253
|
type: "optional",
|
|
1184
1254
|
suggestions: () => o.suggestions(),
|
|
1185
1255
|
children: [o],
|
|
1186
|
-
parse(
|
|
1187
|
-
let
|
|
1188
|
-
return isParserError(
|
|
1256
|
+
parse(g, _) {
|
|
1257
|
+
let v = o.parse(g, _);
|
|
1258
|
+
return isParserError(v) ? success({
|
|
1189
1259
|
text: "",
|
|
1190
|
-
grammar:
|
|
1260
|
+
grammar: h,
|
|
1191
1261
|
children: []
|
|
1192
|
-
}) :
|
|
1262
|
+
}) : v;
|
|
1193
1263
|
}
|
|
1194
1264
|
};
|
|
1195
|
-
return
|
|
1265
|
+
return h;
|
|
1196
1266
|
}
|
|
1197
1267
|
const ws = optional(pattern(/\s+/));
|
|
1198
1268
|
function seq(...o) {
|
|
@@ -1205,94 +1275,104 @@ function regexEscape(o) {
|
|
|
1205
1275
|
return o.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
1206
1276
|
}
|
|
1207
1277
|
function alternative(...o) {
|
|
1208
|
-
let
|
|
1278
|
+
let h = {
|
|
1209
1279
|
type: "alternative",
|
|
1210
1280
|
children: o,
|
|
1211
|
-
parse(
|
|
1212
|
-
let
|
|
1213
|
-
if (
|
|
1214
|
-
for (let
|
|
1215
|
-
let o =
|
|
1216
|
-
...
|
|
1281
|
+
parse(g, _) {
|
|
1282
|
+
let v = [];
|
|
1283
|
+
if (_.faultTolerant) {
|
|
1284
|
+
for (let h of o) {
|
|
1285
|
+
let o = h.parse(g, {
|
|
1286
|
+
..._,
|
|
1217
1287
|
faultTolerant: !1
|
|
1218
1288
|
});
|
|
1219
1289
|
if (isParserSuccess(o)) return o;
|
|
1220
1290
|
}
|
|
1221
|
-
let
|
|
1222
|
-
...
|
|
1291
|
+
let h = o.map((o) => o.parse(g, {
|
|
1292
|
+
..._,
|
|
1223
1293
|
faultTolerant: !0
|
|
1224
|
-
})),
|
|
1225
|
-
if (
|
|
1226
|
-
|
|
1227
|
-
|
|
1294
|
+
})), v = t(h, n(isParserSuccess), t$1((o) => o.text.length), t$2());
|
|
1295
|
+
if (v) return {
|
|
1296
|
+
...v,
|
|
1297
|
+
recoverableError: !0
|
|
1298
|
+
};
|
|
1299
|
+
} else for (let h of o) {
|
|
1300
|
+
let o = h.parse(g, _);
|
|
1228
1301
|
if (isParserError(o)) {
|
|
1229
|
-
|
|
1302
|
+
v.push(o);
|
|
1230
1303
|
continue;
|
|
1231
1304
|
}
|
|
1232
1305
|
return o;
|
|
1233
1306
|
}
|
|
1234
1307
|
return error({
|
|
1235
|
-
got:
|
|
1236
|
-
expected:
|
|
1237
|
-
grammar:
|
|
1308
|
+
got: g,
|
|
1309
|
+
expected: v.flatMap((o) => o.expected),
|
|
1310
|
+
grammar: h
|
|
1238
1311
|
});
|
|
1239
1312
|
},
|
|
1240
1313
|
suggestions() {
|
|
1241
1314
|
return o.flatMap((o) => o.suggestions());
|
|
1242
1315
|
}
|
|
1243
1316
|
};
|
|
1244
|
-
return
|
|
1317
|
+
return h;
|
|
1245
1318
|
}
|
|
1246
|
-
function named(o,
|
|
1247
|
-
let
|
|
1319
|
+
function named(o, h) {
|
|
1320
|
+
let g = {
|
|
1248
1321
|
meta: { name: o },
|
|
1249
1322
|
type: "named",
|
|
1250
1323
|
suggestions() {
|
|
1251
|
-
return
|
|
1324
|
+
return h.suggestions();
|
|
1252
1325
|
},
|
|
1253
|
-
children: [
|
|
1254
|
-
parse(o,
|
|
1255
|
-
let
|
|
1256
|
-
return isParserError(
|
|
1257
|
-
text:
|
|
1258
|
-
grammar:
|
|
1259
|
-
children: [
|
|
1326
|
+
children: [h],
|
|
1327
|
+
parse(o, _) {
|
|
1328
|
+
let v = h.parse(o, _);
|
|
1329
|
+
return isParserError(v) ? v : success({
|
|
1330
|
+
text: v.text,
|
|
1331
|
+
grammar: g,
|
|
1332
|
+
children: [v]
|
|
1260
1333
|
});
|
|
1261
1334
|
}
|
|
1262
1335
|
};
|
|
1263
|
-
return
|
|
1336
|
+
return g;
|
|
1264
1337
|
}
|
|
1265
|
-
function repeat(o,
|
|
1266
|
-
let
|
|
1338
|
+
function repeat(o, h = 1, g = 1e3) {
|
|
1339
|
+
let _ = {
|
|
1267
1340
|
type: "repeat",
|
|
1268
1341
|
children: [o],
|
|
1269
1342
|
suggestions: () => o.suggestions(),
|
|
1270
|
-
parse(
|
|
1271
|
-
let
|
|
1272
|
-
for (let
|
|
1273
|
-
let
|
|
1274
|
-
...
|
|
1275
|
-
faultTolerant:
|
|
1343
|
+
parse(v, y) {
|
|
1344
|
+
let b = 0, x = !1, S = [];
|
|
1345
|
+
for (let _ = 0; _ < g && b < v.length; _++) {
|
|
1346
|
+
let g = v.substring(b), C = o.parse(g, {
|
|
1347
|
+
...y,
|
|
1348
|
+
faultTolerant: y.faultTolerant && !x
|
|
1276
1349
|
});
|
|
1277
|
-
if (isParserError(
|
|
1278
|
-
|
|
1279
|
-
|
|
1280
|
-
|
|
1281
|
-
|
|
1350
|
+
if (isParserError(C)) {
|
|
1351
|
+
let o = {
|
|
1352
|
+
...C,
|
|
1353
|
+
offset: b
|
|
1354
|
+
};
|
|
1355
|
+
if (_ >= h) break;
|
|
1356
|
+
if (y.faultTolerant) {
|
|
1357
|
+
if (!x) {
|
|
1358
|
+
x = !0;
|
|
1282
1359
|
continue;
|
|
1283
1360
|
}
|
|
1284
|
-
return
|
|
1285
|
-
} else return
|
|
1361
|
+
return o;
|
|
1362
|
+
} else return o;
|
|
1286
1363
|
}
|
|
1287
|
-
|
|
1364
|
+
b += C.text.length, S.push({
|
|
1365
|
+
...C,
|
|
1366
|
+
recoverableError: x
|
|
1367
|
+
});
|
|
1288
1368
|
}
|
|
1289
1369
|
return success({
|
|
1290
|
-
grammar:
|
|
1291
|
-
children:
|
|
1292
|
-
text:
|
|
1370
|
+
grammar: _,
|
|
1371
|
+
children: S,
|
|
1372
|
+
text: v.substring(0, b)
|
|
1293
1373
|
});
|
|
1294
1374
|
}
|
|
1295
1375
|
};
|
|
1296
|
-
return
|
|
1376
|
+
return _;
|
|
1297
1377
|
}
|
|
1298
1378
|
export { DSLParser, DslEditor, ParsingError, alternative, asException, eof, error, isParserError, isParserSuccess, named, optional, pattern, rational, repeat, seq, sequence, success, term, visit, ws };
|