react-dsl-editor 0.4.5 → 0.4.7
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 +4 -0
- package/dist/react-dsl-editor.js +56 -41
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -62,6 +62,10 @@ export declare const eof: GrammarNode<never>;
|
|
|
62
62
|
|
|
63
63
|
export declare function error<T extends string>(param: ParserError<T>): ParserError<T>;
|
|
64
64
|
|
|
65
|
+
export declare function extractAll<T extends string>(parserResult: ParserSuccess<T>, type: T): string[];
|
|
66
|
+
|
|
67
|
+
export declare function extractFirst<T extends string>(result: ParserSuccess<T>, name: T): string | undefined;
|
|
68
|
+
|
|
65
69
|
export declare type FaultToleranceMode = 'skip-parser' | 'skip-input' | 'fuzzy-match' | 'partial-match';
|
|
66
70
|
|
|
67
71
|
export declare interface GrammarNode<T extends string = never> {
|
package/dist/react-dsl-editor.js
CHANGED
|
@@ -35,7 +35,7 @@ const textStyle = {
|
|
|
35
35
|
children: h
|
|
36
36
|
});
|
|
37
37
|
});
|
|
38
|
-
function e$
|
|
38
|
+
function e$4(o, h, g) {
|
|
39
39
|
let _ = (g) => o(g, ...h);
|
|
40
40
|
return g === void 0 ? _ : Object.assign(_, {
|
|
41
41
|
lazy: g,
|
|
@@ -45,7 +45,7 @@ function e$3(o, h, g) {
|
|
|
45
45
|
function t$6(o, h, g) {
|
|
46
46
|
let _ = o.length - h.length;
|
|
47
47
|
if (_ === 0) return o(...h);
|
|
48
|
-
if (_ === 1) return e$
|
|
48
|
+
if (_ === 1) return e$4(o, h, g);
|
|
49
49
|
throw Error("Wrong number of arguments");
|
|
50
50
|
}
|
|
51
51
|
var t$4 = {
|
|
@@ -53,9 +53,9 @@ var t$4 = {
|
|
|
53
53
|
hasNext: !1
|
|
54
54
|
};
|
|
55
55
|
function t$1(o, ...h) {
|
|
56
|
-
let g = o, _ = h.map((o) => "lazy" in o ? r$
|
|
56
|
+
let g = o, _ = h.map((o) => "lazy" in o ? r$8(o) : void 0), v = 0;
|
|
57
57
|
for (; v < h.length;) {
|
|
58
|
-
if (_[v] === void 0 || !i$
|
|
58
|
+
if (_[v] === void 0 || !i$3(g)) {
|
|
59
59
|
let o = h[v];
|
|
60
60
|
g = o(g), v += 1;
|
|
61
61
|
continue;
|
|
@@ -66,20 +66,20 @@ function t$1(o, ...h) {
|
|
|
66
66
|
if (h === void 0 || (o.push(h), h.isSingle)) break;
|
|
67
67
|
}
|
|
68
68
|
let y = [];
|
|
69
|
-
for (let h of g) if (n$
|
|
69
|
+
for (let h of g) if (n$9(h, y, o)) break;
|
|
70
70
|
let { isSingle: b } = o.at(-1);
|
|
71
71
|
g = b ? y[0] : y, v += o.length;
|
|
72
72
|
}
|
|
73
73
|
return g;
|
|
74
74
|
}
|
|
75
|
-
function n$
|
|
75
|
+
function n$9(o, h, g) {
|
|
76
76
|
if (g.length === 0) return h.push(o), !1;
|
|
77
77
|
let _ = o, v = t$4, y = !1;
|
|
78
78
|
for (let [o, b] of g.entries()) {
|
|
79
79
|
let { index: x, items: S } = b;
|
|
80
80
|
if (S.push(_), v = b(_, x, S), b.index += 1, v.hasNext) {
|
|
81
81
|
if (v.hasMany ?? !1) {
|
|
82
|
-
for (let _ of v.next) if (n$
|
|
82
|
+
for (let _ of v.next) if (n$9(_, h, g.slice(o + 1))) return !0;
|
|
83
83
|
return y;
|
|
84
84
|
}
|
|
85
85
|
_ = v.next;
|
|
@@ -89,7 +89,7 @@ function n$8(o, h, g) {
|
|
|
89
89
|
}
|
|
90
90
|
return v.hasNext && h.push(_), y;
|
|
91
91
|
}
|
|
92
|
-
function r$
|
|
92
|
+
function r$8(o) {
|
|
93
93
|
let { lazy: h, lazyArgs: g } = o, _ = h(...g);
|
|
94
94
|
return Object.assign(_, {
|
|
95
95
|
isSingle: h.single ?? !1,
|
|
@@ -97,7 +97,7 @@ function r$7(o) {
|
|
|
97
97
|
items: []
|
|
98
98
|
});
|
|
99
99
|
}
|
|
100
|
-
function i$
|
|
100
|
+
function i$3(o) {
|
|
101
101
|
return typeof o == "string" || typeof o == "object" && !!o && Symbol.iterator in o;
|
|
102
102
|
}
|
|
103
103
|
function t$5(o, h) {
|
|
@@ -119,44 +119,52 @@ function t$5(o, h) {
|
|
|
119
119
|
throw Error("Wrong number of arguments");
|
|
120
120
|
}
|
|
121
121
|
function t$7(...o) {
|
|
122
|
-
return t$6(n$
|
|
122
|
+
return t$6(n$8, o);
|
|
123
123
|
}
|
|
124
|
-
var n$
|
|
124
|
+
var n$8 = (o, h) => o.length >= h, e$2 = {
|
|
125
125
|
asc: (o, h) => o > h,
|
|
126
126
|
desc: (o, h) => o < h
|
|
127
127
|
};
|
|
128
128
|
function t$8(o, h) {
|
|
129
129
|
let [g, ..._] = h;
|
|
130
|
-
if (!i$
|
|
131
|
-
let h = r$
|
|
130
|
+
if (!i$2(g)) {
|
|
131
|
+
let h = r$7(..._);
|
|
132
132
|
return o(g, h);
|
|
133
133
|
}
|
|
134
|
-
let v = r$
|
|
134
|
+
let v = r$7(g, ..._);
|
|
135
135
|
return (h) => o(h, v);
|
|
136
136
|
}
|
|
137
|
-
function r$
|
|
138
|
-
let _ = typeof o == "function" ? o : o[0], v = typeof o == "function" ? "asc" : o[1], { [v]: y } = e$
|
|
137
|
+
function r$7(o, h, ...g) {
|
|
138
|
+
let _ = typeof o == "function" ? o : o[0], v = typeof o == "function" ? "asc" : o[1], { [v]: y } = e$2, b = h === void 0 ? void 0 : r$7(h, ...g);
|
|
139
139
|
return (o, h) => {
|
|
140
140
|
let g = _(o), v = _(h);
|
|
141
141
|
return y(g, v) ? 1 : y(v, g) ? -1 : b?.(o, h) ?? 0;
|
|
142
142
|
};
|
|
143
143
|
}
|
|
144
|
-
function i$
|
|
145
|
-
if (a(o)) return !0;
|
|
144
|
+
function i$2(o) {
|
|
145
|
+
if (a$1(o)) return !0;
|
|
146
146
|
if (typeof o != "object" || !Array.isArray(o)) return !1;
|
|
147
147
|
let [h, g, ..._] = o;
|
|
148
|
-
return a(h) && typeof g == "string" && g in e$
|
|
148
|
+
return a$1(h) && typeof g == "string" && g in e$2 && _.length === 0;
|
|
149
149
|
}
|
|
150
|
-
var a = (o) => typeof o == "function" && o.length === 1;
|
|
151
|
-
function n$
|
|
152
|
-
return t$6(r$
|
|
150
|
+
var a$1 = (o) => typeof o == "function" && o.length === 1;
|
|
151
|
+
function n$3(...o) {
|
|
152
|
+
return t$6(r$6, o, i$1);
|
|
153
153
|
}
|
|
154
|
-
var r$
|
|
154
|
+
var r$6 = (o, h) => o.filter(h), i$1 = (o) => (h, g, _) => o(h, g, _) ? {
|
|
155
155
|
done: !1,
|
|
156
156
|
hasNext: !0,
|
|
157
157
|
next: h
|
|
158
|
-
} : t$4;
|
|
159
|
-
function n$
|
|
158
|
+
} : t$4, e$1 = (o) => Object.assign(o, { single: !0 });
|
|
159
|
+
function n$1(...o) {
|
|
160
|
+
return t$6(r$5, o, e$1(i));
|
|
161
|
+
}
|
|
162
|
+
var r$5 = ([o]) => o, i = () => a, a = (o) => ({
|
|
163
|
+
hasNext: !0,
|
|
164
|
+
next: o,
|
|
165
|
+
done: !0
|
|
166
|
+
});
|
|
167
|
+
function n$4(...o) {
|
|
160
168
|
return t$8(r$4, o);
|
|
161
169
|
}
|
|
162
170
|
function r$4(o, h) {
|
|
@@ -166,9 +174,9 @@ function r$4(o, h) {
|
|
|
166
174
|
return g;
|
|
167
175
|
}
|
|
168
176
|
function t(...o) {
|
|
169
|
-
return t$6(n$
|
|
177
|
+
return t$6(n$7, o, r$3);
|
|
170
178
|
}
|
|
171
|
-
var n$
|
|
179
|
+
var n$7 = (o, h) => o.flatMap(h), r$3 = (o) => (h, g, _) => {
|
|
172
180
|
let v = o(h, g, _);
|
|
173
181
|
return Array.isArray(v) ? {
|
|
174
182
|
done: !1,
|
|
@@ -185,22 +193,22 @@ function e(o) {
|
|
|
185
193
|
return o === "" || o === void 0 ? !0 : Array.isArray(o) ? o.length === 0 : Object.keys(o).length === 0;
|
|
186
194
|
}
|
|
187
195
|
function t$2(...o) {
|
|
188
|
-
return t$6(n$
|
|
196
|
+
return t$6(n$6, o, r$2);
|
|
189
197
|
}
|
|
190
|
-
var n$
|
|
198
|
+
var n$6 = (o, h) => o.map(h), r$2 = (o) => (h, g, _) => ({
|
|
191
199
|
done: !1,
|
|
192
200
|
hasNext: !0,
|
|
193
201
|
next: o(h, g, _)
|
|
194
202
|
});
|
|
195
203
|
function t$3(...o) {
|
|
196
|
-
return t$6(n$
|
|
204
|
+
return t$6(n$5, o);
|
|
197
205
|
}
|
|
198
|
-
function n$
|
|
206
|
+
function n$5(o, h) {
|
|
199
207
|
let g = [];
|
|
200
208
|
for (let _ = o; _ < h; _++) g.push(_);
|
|
201
209
|
return g;
|
|
202
210
|
}
|
|
203
|
-
function n$
|
|
211
|
+
function n$2(...o) {
|
|
204
212
|
return t$5(r$1, o);
|
|
205
213
|
}
|
|
206
214
|
function r$1() {
|
|
@@ -279,7 +287,7 @@ function asException(o) {
|
|
|
279
287
|
return new ParsingError(`[${o.grammar.type}]: Expected ${o.expected.map((o) => JSON.stringify(o)).join(" | ")}, but got '${o.got}' (${pathToString([...o.path, o.grammar])})`);
|
|
280
288
|
}
|
|
281
289
|
function pickFromErrorLabels(o) {
|
|
282
|
-
return t$1(o, n$
|
|
290
|
+
return t$1(o, n$3((o) => o.errorLabel !== void 0), n$4((o) => o.errorLabel.got.length));
|
|
283
291
|
}
|
|
284
292
|
function alternative(...o) {
|
|
285
293
|
let h = {
|
|
@@ -832,7 +840,7 @@ function pattern(o) {
|
|
|
832
840
|
let h = new import_randexp.default(o);
|
|
833
841
|
h.randInt = (o) => o, h.defaultRange.subtract(-Infinity, Infinity);
|
|
834
842
|
function g() {
|
|
835
|
-
return t$1(t$3(0, 10), t$2(() => h.gen()), n$
|
|
843
|
+
return t$1(t$3(0, 10), t$2(() => h.gen()), n$2(), t$2((o) => ({
|
|
836
844
|
node: _,
|
|
837
845
|
text: o
|
|
838
846
|
})));
|
|
@@ -938,12 +946,7 @@ function sequence(...o) {
|
|
|
938
946
|
children: o,
|
|
939
947
|
type: "sequence",
|
|
940
948
|
suggestions() {
|
|
941
|
-
|
|
942
|
-
for (let g of o) {
|
|
943
|
-
let o = g.suggestions();
|
|
944
|
-
h.push(...o.filter((o) => o.text !== ""));
|
|
945
|
-
}
|
|
946
|
-
return h;
|
|
949
|
+
return t$1(o, t$2((o) => o.suggestions()), n$1()) ?? [];
|
|
947
950
|
},
|
|
948
951
|
parse(g, _) {
|
|
949
952
|
let v = {
|
|
@@ -1082,6 +1085,18 @@ function visit(o, h, g = (o) => o.text) {
|
|
|
1082
1085
|
function visitPredicate(o, h, g = (o) => o.text) {
|
|
1083
1086
|
return isParserError(o) ? [] : (h(o) ? [g(o)] : []).concat(...o.children?.flatMap((o) => visitPredicate(o, h, g)) ?? []);
|
|
1084
1087
|
}
|
|
1088
|
+
function extractAll(o, h) {
|
|
1089
|
+
return visit(o, [h]);
|
|
1090
|
+
}
|
|
1091
|
+
function extractFirst(o, h) {
|
|
1092
|
+
if (!isParserError(o)) {
|
|
1093
|
+
if (nodeName(o) === h) return o.text;
|
|
1094
|
+
if (o.children?.length > 0) for (let g of o.children) {
|
|
1095
|
+
let o = extractFirst(g, h);
|
|
1096
|
+
if (o) return o;
|
|
1097
|
+
}
|
|
1098
|
+
}
|
|
1099
|
+
}
|
|
1085
1100
|
function getSuggestions(o, h, g = () => void 0) {
|
|
1086
1101
|
let _ = cstPathAt(o, h), v = t$1(_, t((o) => {
|
|
1087
1102
|
if (nodeName(o) !== void 0) {
|
|
@@ -1466,4 +1481,4 @@ function DslEditor({ code: o, onChange: h, onParsed: v, grammar: S, wrap: T = !1
|
|
|
1466
1481
|
})
|
|
1467
1482
|
});
|
|
1468
1483
|
}
|
|
1469
|
-
export { DSLParser, DslEditor, ParsingError, alternative, asException, defaultSyntaxColors, eof, error, isParserError, isParserSuccess, named, newline, nodeName, optional, pathToString, pattern, rational, repeat, seq, sequence, success, term, visit, visitPredicate, ws };
|
|
1484
|
+
export { DSLParser, DslEditor, ParsingError, alternative, asException, defaultSyntaxColors, eof, error, extractAll, extractFirst, isParserError, isParserSuccess, named, newline, nodeName, optional, pathToString, pattern, rational, repeat, seq, sequence, success, term, visit, visitPredicate, ws };
|