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