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