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