@vuu-ui/vuu-filters 0.7.6-debug → 0.8.0-debug
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/cjs/index.js +3320 -486
- package/cjs/index.js.map +4 -4
- package/esm/index.js +3273 -425
- package/esm/index.js.map +4 -4
- package/package.json +10 -5
- package/types/column-filter/ColumnFilter.d.ts +2 -2
- package/types/column-filter/TypeaheadFilter.d.ts +1 -1
- package/types/column-filter/useColumnFilterStore.d.ts +3 -2
- package/types/filter-input/index.d.ts +0 -1
- package/types/filter-input/useFilterSuggestionProvider.d.ts +2 -2
- package/types/filter-utils.d.ts +1 -4
- package/types/index.d.ts +0 -2
- package/types/local-config.d.ts +3 -0
- package/types/use-filter-config.d.ts +12 -0
- package/types/use-rest-config.d.ts +11 -0
- package/LICENSE +0 -201
- package/types/filter-evaluation-utils.d.ts +0 -6
- package/types/filter-input/filter-language-parser/FilterParser.d.ts +0 -2
- package/types/filter-input/filter-language-parser/FilterTreeWalker.d.ts +0 -3
- package/types/filter-input/filter-language-parser/generated/filter-parser.d.ts +0 -2
- package/types/filter-input/filter-language-parser/generated/filter-parser.terms.d.ts +0 -27
- package/types/filter-input/filter-language-parser/index.d.ts +0 -2
- package/types/filterTypes.d.ts +0 -9
- /package/types/filter-input/{filter-language-parser/FilterLanguage.d.ts → FilterLanguage.d.ts} +0 -0
package/cjs/index.js
CHANGED
|
@@ -114,23 +114,10 @@ __export(src_exports, {
|
|
|
114
114
|
OR: () => OR,
|
|
115
115
|
STARTS_WITH: () => STARTS_WITH,
|
|
116
116
|
addFilter: () => addFilter,
|
|
117
|
-
filterAsQuery: () => filterAsQuery,
|
|
118
117
|
filterClauses: () => filterClauses,
|
|
119
118
|
filterEquals: () => filterEquals,
|
|
120
119
|
filterIncludesColumn: () => filterIncludesColumn,
|
|
121
|
-
filterPredicate: () => filterPredicate,
|
|
122
|
-
getFilterPredicate: () => getFilterPredicate,
|
|
123
|
-
isAndFilter: () => isAndFilter,
|
|
124
|
-
isFilterClause: () => isFilterClause,
|
|
125
|
-
isInFilter: () => isInFilter,
|
|
126
|
-
isMultiClauseFilter: () => isMultiClauseFilter,
|
|
127
|
-
isMultiValueFilter: () => isMultiValueFilter,
|
|
128
|
-
isNamedFilter: () => isNamedFilter,
|
|
129
|
-
isOrFilter: () => isOrFilter,
|
|
130
|
-
isSingleValueFilter: () => isSingleValueFilter,
|
|
131
120
|
overrideColName: () => overrideColName,
|
|
132
|
-
parseFilter: () => parseFilter,
|
|
133
|
-
removeColumnFromFilter: () => removeColumnFromFilter,
|
|
134
121
|
removeFilter: () => removeFilter,
|
|
135
122
|
splitFilterOnColumn: () => splitFilterOnColumn,
|
|
136
123
|
updateFilter: () => updateFilter,
|
|
@@ -250,30 +237,6 @@ var import_salt_lab = require("@heswell/salt-lab");
|
|
|
250
237
|
|
|
251
238
|
// src/filter-utils.ts
|
|
252
239
|
var import_vuu_utils = require("@vuu-ui/vuu-utils");
|
|
253
|
-
|
|
254
|
-
// src/filterTypes.ts
|
|
255
|
-
var singleValueFilterOps = /* @__PURE__ */ new Set([
|
|
256
|
-
"=",
|
|
257
|
-
"!=",
|
|
258
|
-
">",
|
|
259
|
-
">=",
|
|
260
|
-
"<",
|
|
261
|
-
"<=",
|
|
262
|
-
"starts",
|
|
263
|
-
"ends"
|
|
264
|
-
]);
|
|
265
|
-
var isNamedFilter = (f) => f !== void 0 && f.name !== void 0;
|
|
266
|
-
var isSingleValueFilter = (f) => f !== void 0 && singleValueFilterOps.has(f.op);
|
|
267
|
-
var isFilterClause = (f) => f !== void 0 && (isSingleValueFilter(f) || isMultiValueFilter(f));
|
|
268
|
-
var isMultiValueFilter = (f) => f !== void 0 && f.op === "in";
|
|
269
|
-
var isInFilter = (f) => f.op === "in";
|
|
270
|
-
var isAndFilter = (f) => f.op === "and";
|
|
271
|
-
var isOrFilter = (f) => f.op === "or";
|
|
272
|
-
function isMultiClauseFilter(f) {
|
|
273
|
-
return f !== void 0 && (f.op === "and" || f.op === "or");
|
|
274
|
-
}
|
|
275
|
-
|
|
276
|
-
// src/filter-utils.ts
|
|
277
240
|
var AND = "and";
|
|
278
241
|
var EQUALS = "=";
|
|
279
242
|
var GREATER_THAN = ">";
|
|
@@ -284,7 +247,7 @@ var ENDS_WITH = "ends";
|
|
|
284
247
|
var IN = "in";
|
|
285
248
|
var filterClauses = (filter, clauses = []) => {
|
|
286
249
|
if (filter) {
|
|
287
|
-
if (isMultiClauseFilter(filter)) {
|
|
250
|
+
if ((0, import_vuu_utils.isMultiClauseFilter)(filter)) {
|
|
288
251
|
filter.filters.forEach((f) => clauses.push(...filterClauses(f)));
|
|
289
252
|
} else {
|
|
290
253
|
clauses.push(filter);
|
|
@@ -298,14 +261,14 @@ var DEFAULT_ADD_FILTER_OPTS = {
|
|
|
298
261
|
var addFilter = (existingFilter, filter, { combineWith = AND } = DEFAULT_ADD_FILTER_OPTS) => {
|
|
299
262
|
var _a;
|
|
300
263
|
if (includesNoValues(filter)) {
|
|
301
|
-
if (isMultiClauseFilter(filter)) {
|
|
264
|
+
if ((0, import_vuu_utils.isMultiClauseFilter)(filter)) {
|
|
302
265
|
} else {
|
|
303
266
|
existingFilter = removeFilterForColumn(existingFilter, {
|
|
304
267
|
name: filter.column
|
|
305
268
|
});
|
|
306
269
|
}
|
|
307
270
|
} else if (includesAllValues(filter)) {
|
|
308
|
-
if (isMultiClauseFilter(filter)) {
|
|
271
|
+
if ((0, import_vuu_utils.isMultiClauseFilter)(filter)) {
|
|
309
272
|
}
|
|
310
273
|
return removeFilterForColumn(existingFilter, { name: (_a = filter.column) != null ? _a : "" });
|
|
311
274
|
}
|
|
@@ -340,20 +303,10 @@ var includesNoValues = (filter) => {
|
|
|
340
303
|
if (!filter) {
|
|
341
304
|
return false;
|
|
342
305
|
}
|
|
343
|
-
if (isInFilter(filter) && filter.values.length === 0) {
|
|
306
|
+
if ((0, import_vuu_utils.isInFilter)(filter) && filter.values.length === 0) {
|
|
344
307
|
return true;
|
|
345
308
|
}
|
|
346
|
-
return isAndFilter(filter) && filter.filters.some((f) => includesNoValues(f));
|
|
347
|
-
};
|
|
348
|
-
var filterValue = (value) => typeof value === "string" ? `"${value}"` : value;
|
|
349
|
-
var filterAsQuery = (f) => {
|
|
350
|
-
if (isMultiClauseFilter(f)) {
|
|
351
|
-
return f.filters.map((filter) => filterAsQuery(filter)).join(` ${f.op} `);
|
|
352
|
-
} else if (isMultiValueFilter(f)) {
|
|
353
|
-
return `${f.column} ${f.op} [${f.values.join(",")}]`;
|
|
354
|
-
} else {
|
|
355
|
-
return `${f.column} ${f.op} ${filterValue(f.value)}`;
|
|
356
|
-
}
|
|
309
|
+
return (0, import_vuu_utils.isAndFilter)(filter) && filter.filters.some((f) => includesNoValues(f));
|
|
357
310
|
};
|
|
358
311
|
var includesAllValues = (filter) => {
|
|
359
312
|
if (!filter) {
|
|
@@ -371,7 +324,7 @@ var merge = (f1, f2) => {
|
|
|
371
324
|
if (includesNoValues(f2)) {
|
|
372
325
|
return f2;
|
|
373
326
|
}
|
|
374
|
-
if (isInFilter(f1) && isInFilter(f2)) {
|
|
327
|
+
if ((0, import_vuu_utils.isInFilter)(f1) && (0, import_vuu_utils.isInFilter)(f2)) {
|
|
375
328
|
return {
|
|
376
329
|
...f1,
|
|
377
330
|
values: [
|
|
@@ -381,7 +334,7 @@ var merge = (f1, f2) => {
|
|
|
381
334
|
)
|
|
382
335
|
]
|
|
383
336
|
};
|
|
384
|
-
} else if (isInFilter(f1) && f2.op === EQUALS) {
|
|
337
|
+
} else if ((0, import_vuu_utils.isInFilter)(f1) && f2.op === EQUALS) {
|
|
385
338
|
return {
|
|
386
339
|
...f1,
|
|
387
340
|
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
@@ -411,18 +364,6 @@ var combine = (existingFilters, replacementFilters) => {
|
|
|
411
364
|
) === false;
|
|
412
365
|
return existingFilters.filter(stillApplicable).concat(replacementFilters);
|
|
413
366
|
};
|
|
414
|
-
var removeColumnFromFilter = (column, filter) => {
|
|
415
|
-
if (isMultiClauseFilter(filter)) {
|
|
416
|
-
const [clause1, clause2] = filter.filters;
|
|
417
|
-
if (clause1.column === column.name) {
|
|
418
|
-
return [clause2, filterAsQuery(clause2)];
|
|
419
|
-
}
|
|
420
|
-
if (clause2.column === column.name) {
|
|
421
|
-
return [clause1, filterAsQuery(clause1)];
|
|
422
|
-
}
|
|
423
|
-
}
|
|
424
|
-
return [void 0, ""];
|
|
425
|
-
};
|
|
426
367
|
var removeFilter = (sourceFilter, filterToRemove) => {
|
|
427
368
|
if (filterEquals(sourceFilter, filterToRemove, true)) {
|
|
428
369
|
return null;
|
|
@@ -439,24 +380,24 @@ var removeFilter = (sourceFilter, filterToRemove) => {
|
|
|
439
380
|
);
|
|
440
381
|
return filters.length > 0 ? { type: AND, filters } : null;
|
|
441
382
|
};
|
|
442
|
-
var splitFilterOnColumn = (
|
|
383
|
+
var splitFilterOnColumn = (columnName, filter) => {
|
|
443
384
|
if (!filter) {
|
|
444
|
-
return [
|
|
385
|
+
return [void 0, void 0];
|
|
445
386
|
}
|
|
446
387
|
if (filter.column === columnName) {
|
|
447
|
-
return [filter,
|
|
388
|
+
return [filter, void 0];
|
|
448
389
|
}
|
|
449
390
|
if (filter.op !== AND) {
|
|
450
|
-
return [
|
|
391
|
+
return [void 0, filter];
|
|
451
392
|
}
|
|
452
|
-
const [[columnFilter =
|
|
393
|
+
const [[columnFilter = void 0], filters] = (0, import_vuu_utils.partition)(
|
|
453
394
|
filter.filters,
|
|
454
395
|
(f) => f.column === columnName
|
|
455
396
|
);
|
|
456
397
|
return filters.length === 1 ? [columnFilter, filters[0]] : [columnFilter, { op: AND, filters }];
|
|
457
398
|
};
|
|
458
399
|
var overrideColName = (filter, column) => {
|
|
459
|
-
if (isMultiClauseFilter(filter)) {
|
|
400
|
+
if ((0, import_vuu_utils.isMultiClauseFilter)(filter)) {
|
|
460
401
|
return {
|
|
461
402
|
op: filter.op,
|
|
462
403
|
filters: filter.filters.map((f) => overrideColName(f, column))
|
|
@@ -485,7 +426,7 @@ var removeFilterForColumn = (sourceFilter, column) => {
|
|
|
485
426
|
if (sourceFilter.column === colName) {
|
|
486
427
|
return void 0;
|
|
487
428
|
}
|
|
488
|
-
if (isAndFilter(sourceFilter) || isOrFilter(sourceFilter)) {
|
|
429
|
+
if ((0, import_vuu_utils.isAndFilter)(sourceFilter) || (0, import_vuu_utils.isOrFilter)(sourceFilter)) {
|
|
489
430
|
const { op } = sourceFilter;
|
|
490
431
|
const filters = sourceFilter.filters;
|
|
491
432
|
const otherColFilters = filters.filter((f) => f.column !== colName);
|
|
@@ -517,7 +458,7 @@ var filterEquals = (f1, f2, strict = false) => {
|
|
|
517
458
|
return true;
|
|
518
459
|
}
|
|
519
460
|
if (f1 && f2 && canMerge(f1, f2)) {
|
|
520
|
-
return f1.op === f2.op && (isSingleValueFilter(f1) && isSingleValueFilter(f2) && f1.value === f2.value || isMultiValueFilter(f1) && isMultiValueFilter(f2) && sameValues(f1.values, f2.values));
|
|
461
|
+
return f1.op === f2.op && ((0, import_vuu_utils.isSingleValueFilter)(f1) && (0, import_vuu_utils.isSingleValueFilter)(f2) && f1.value === f2.value || (0, import_vuu_utils.isMultiValueFilter)(f1) && (0, import_vuu_utils.isMultiValueFilter)(f2) && sameValues(f1.values, f2.values));
|
|
521
462
|
}
|
|
522
463
|
return false;
|
|
523
464
|
};
|
|
@@ -540,96 +481,3215 @@ var updateFilter = (filter, newFilter, mode) => {
|
|
|
540
481
|
return updateFilter(result, newFilter, "add");
|
|
541
482
|
}
|
|
542
483
|
}
|
|
543
|
-
return {
|
|
544
|
-
op: "and",
|
|
545
|
-
filters: [filter, newFilter]
|
|
546
|
-
};
|
|
547
|
-
}
|
|
548
|
-
if (newFilter) {
|
|
549
|
-
return newFilter;
|
|
550
|
-
}
|
|
551
|
-
return filter;
|
|
484
|
+
return {
|
|
485
|
+
op: "and",
|
|
486
|
+
filters: [filter, newFilter]
|
|
487
|
+
};
|
|
488
|
+
}
|
|
489
|
+
if (newFilter) {
|
|
490
|
+
return newFilter;
|
|
491
|
+
}
|
|
492
|
+
return filter;
|
|
493
|
+
};
|
|
494
|
+
|
|
495
|
+
// src/column-filter/utils.ts
|
|
496
|
+
var isStartsWithValue = (value) => /\.\.\.$/.test(value);
|
|
497
|
+
var getTypeaheadFilter = (column, filterValues, isStartsWithFilter) => {
|
|
498
|
+
if (filterValues.length === 0) {
|
|
499
|
+
return void 0;
|
|
500
|
+
}
|
|
501
|
+
if (isStartsWithFilter) {
|
|
502
|
+
const startsWith = filterValues[0].substring(0, filterValues[0].length - 3);
|
|
503
|
+
return {
|
|
504
|
+
column,
|
|
505
|
+
op: "starts",
|
|
506
|
+
value: `"${startsWith}"`
|
|
507
|
+
};
|
|
508
|
+
}
|
|
509
|
+
return {
|
|
510
|
+
column,
|
|
511
|
+
op: "in",
|
|
512
|
+
values: filterValues.map((value) => `"${value}"`)
|
|
513
|
+
};
|
|
514
|
+
};
|
|
515
|
+
var getRangeFilter = (column, startValue, endValue) => {
|
|
516
|
+
const startFilter = startValue === void 0 ? void 0 : { column, op: ">", value: startValue - 1 };
|
|
517
|
+
const endFilter = endValue === void 0 ? void 0 : { column, op: "<", value: endValue + 1 };
|
|
518
|
+
if (endFilter === void 0)
|
|
519
|
+
return startFilter;
|
|
520
|
+
return addFilter(startFilter, endFilter, { combineWith: "and" });
|
|
521
|
+
};
|
|
522
|
+
|
|
523
|
+
// src/column-filter/RangeFilter.tsx
|
|
524
|
+
var import_jsx_runtime3 = require("react/jsx-runtime");
|
|
525
|
+
var RangeFilter = ({
|
|
526
|
+
defaultTypeaheadParams,
|
|
527
|
+
filterValues,
|
|
528
|
+
onChange
|
|
529
|
+
}) => {
|
|
530
|
+
var _a, _b;
|
|
531
|
+
const columnName = defaultTypeaheadParams[1];
|
|
532
|
+
const startChangeHandler = (e) => {
|
|
533
|
+
const value = parseFloat(e.target.value);
|
|
534
|
+
const newRange = {
|
|
535
|
+
start: isNaN(value) ? void 0 : value,
|
|
536
|
+
end: filterValues == null ? void 0 : filterValues.end
|
|
537
|
+
};
|
|
538
|
+
const filter = getRangeFilter(columnName, newRange.start, newRange.end);
|
|
539
|
+
onChange(newRange, filter);
|
|
540
|
+
};
|
|
541
|
+
const endChangeHandler = (e) => {
|
|
542
|
+
const value = parseFloat(e.target.value);
|
|
543
|
+
const newRange = {
|
|
544
|
+
start: filterValues == null ? void 0 : filterValues.start,
|
|
545
|
+
end: isNaN(value) ? void 0 : value
|
|
546
|
+
};
|
|
547
|
+
const filter = getRangeFilter(columnName, newRange.start, newRange.end);
|
|
548
|
+
onChange(newRange, filter);
|
|
549
|
+
};
|
|
550
|
+
return /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("div", { style: { display: "flex", flexDirection: "row" }, children: [
|
|
551
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)(import_salt_lab.ToolbarField, { label: "From", children: /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
|
|
552
|
+
import_salt_lab.Input,
|
|
553
|
+
{
|
|
554
|
+
onChange: startChangeHandler,
|
|
555
|
+
value: ((_a = filterValues == null ? void 0 : filterValues.start) == null ? void 0 : _a.toString()) || "",
|
|
556
|
+
type: "number"
|
|
557
|
+
}
|
|
558
|
+
) }),
|
|
559
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)(import_salt_lab.ToolbarField, { label: "To", children: /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
|
|
560
|
+
import_salt_lab.Input,
|
|
561
|
+
{
|
|
562
|
+
onChange: endChangeHandler,
|
|
563
|
+
value: ((_b = filterValues == null ? void 0 : filterValues.end) == null ? void 0 : _b.toString()) || "",
|
|
564
|
+
type: "number"
|
|
565
|
+
}
|
|
566
|
+
) })
|
|
567
|
+
] });
|
|
568
|
+
};
|
|
569
|
+
|
|
570
|
+
// ../vuu-data-react/src/hooks/useDataSource.ts
|
|
571
|
+
var import_vuu_utils2 = require("@vuu-ui/vuu-utils");
|
|
572
|
+
var import_react3 = require("react");
|
|
573
|
+
var { SELECTED } = import_vuu_utils2.metadataKeys;
|
|
574
|
+
|
|
575
|
+
// ../vuu-data-react/src/hooks/useServerConnectionStatus.ts
|
|
576
|
+
var import_react4 = require("react");
|
|
577
|
+
var import_vuu_data = require("@vuu-ui/vuu-data");
|
|
578
|
+
|
|
579
|
+
// ../vuu-data-react/src/hooks/useServerConnectionQuality.ts
|
|
580
|
+
var import_react5 = require("react");
|
|
581
|
+
var import_vuu_data2 = require("@vuu-ui/vuu-data");
|
|
582
|
+
|
|
583
|
+
// ../vuu-data-react/src/hooks/useTypeaheadSuggestions.ts
|
|
584
|
+
var import_react6 = require("react");
|
|
585
|
+
var import_vuu_data3 = require("@vuu-ui/vuu-data");
|
|
586
|
+
var TYPEAHEAD_MESSAGE_CONSTANTS = {
|
|
587
|
+
type: "RPC_CALL",
|
|
588
|
+
service: "TypeAheadRpcHandler"
|
|
589
|
+
};
|
|
590
|
+
var getTypeaheadParams = (table, column, text = "", selectedValues = []) => {
|
|
591
|
+
if (text !== "" && !selectedValues.includes(text.toLowerCase())) {
|
|
592
|
+
return [table, column, text];
|
|
593
|
+
}
|
|
594
|
+
return [table, column];
|
|
595
|
+
};
|
|
596
|
+
var useTypeaheadSuggestions = () => {
|
|
597
|
+
const getTypeaheadSuggestions = (0, import_react6.useCallback)(
|
|
598
|
+
async (params) => {
|
|
599
|
+
const rpcMessage = params.length === 2 ? {
|
|
600
|
+
method: "getUniqueFieldValues",
|
|
601
|
+
params,
|
|
602
|
+
...TYPEAHEAD_MESSAGE_CONSTANTS
|
|
603
|
+
} : {
|
|
604
|
+
method: "getUniqueFieldValuesStartingWith",
|
|
605
|
+
params,
|
|
606
|
+
...TYPEAHEAD_MESSAGE_CONSTANTS
|
|
607
|
+
};
|
|
608
|
+
const suggestions = await (0, import_vuu_data3.makeRpcCall)(rpcMessage);
|
|
609
|
+
return suggestions;
|
|
610
|
+
},
|
|
611
|
+
[]
|
|
612
|
+
);
|
|
613
|
+
return getTypeaheadSuggestions;
|
|
614
|
+
};
|
|
615
|
+
|
|
616
|
+
// ../../node_modules/@lezer/common/dist/index.js
|
|
617
|
+
var DefaultBufferLength = 1024;
|
|
618
|
+
var nextPropID = 0;
|
|
619
|
+
var Range = class {
|
|
620
|
+
constructor(from, to) {
|
|
621
|
+
this.from = from;
|
|
622
|
+
this.to = to;
|
|
623
|
+
}
|
|
624
|
+
};
|
|
625
|
+
var NodeProp = class {
|
|
626
|
+
/// Create a new node prop type.
|
|
627
|
+
constructor(config = {}) {
|
|
628
|
+
this.id = nextPropID++;
|
|
629
|
+
this.perNode = !!config.perNode;
|
|
630
|
+
this.deserialize = config.deserialize || (() => {
|
|
631
|
+
throw new Error("This node type doesn't define a deserialize function");
|
|
632
|
+
});
|
|
633
|
+
}
|
|
634
|
+
/// This is meant to be used with
|
|
635
|
+
/// [`NodeSet.extend`](#common.NodeSet.extend) or
|
|
636
|
+
/// [`LRParser.configure`](#lr.ParserConfig.props) to compute
|
|
637
|
+
/// prop values for each node type in the set. Takes a [match
|
|
638
|
+
/// object](#common.NodeType^match) or function that returns undefined
|
|
639
|
+
/// if the node type doesn't get this prop, and the prop's value if
|
|
640
|
+
/// it does.
|
|
641
|
+
add(match) {
|
|
642
|
+
if (this.perNode)
|
|
643
|
+
throw new RangeError("Can't add per-node props to node types");
|
|
644
|
+
if (typeof match != "function")
|
|
645
|
+
match = NodeType.match(match);
|
|
646
|
+
return (type) => {
|
|
647
|
+
let result = match(type);
|
|
648
|
+
return result === void 0 ? null : [this, result];
|
|
649
|
+
};
|
|
650
|
+
}
|
|
651
|
+
};
|
|
652
|
+
NodeProp.closedBy = new NodeProp({ deserialize: (str) => str.split(" ") });
|
|
653
|
+
NodeProp.openedBy = new NodeProp({ deserialize: (str) => str.split(" ") });
|
|
654
|
+
NodeProp.group = new NodeProp({ deserialize: (str) => str.split(" ") });
|
|
655
|
+
NodeProp.contextHash = new NodeProp({ perNode: true });
|
|
656
|
+
NodeProp.lookAhead = new NodeProp({ perNode: true });
|
|
657
|
+
NodeProp.mounted = new NodeProp({ perNode: true });
|
|
658
|
+
var noProps = /* @__PURE__ */ Object.create(null);
|
|
659
|
+
var NodeType = class {
|
|
660
|
+
/// @internal
|
|
661
|
+
constructor(name, props, id, flags = 0) {
|
|
662
|
+
this.name = name;
|
|
663
|
+
this.props = props;
|
|
664
|
+
this.id = id;
|
|
665
|
+
this.flags = flags;
|
|
666
|
+
}
|
|
667
|
+
/// Define a node type.
|
|
668
|
+
static define(spec) {
|
|
669
|
+
let props = spec.props && spec.props.length ? /* @__PURE__ */ Object.create(null) : noProps;
|
|
670
|
+
let flags = (spec.top ? 1 : 0) | (spec.skipped ? 2 : 0) | (spec.error ? 4 : 0) | (spec.name == null ? 8 : 0);
|
|
671
|
+
let type = new NodeType(spec.name || "", props, spec.id, flags);
|
|
672
|
+
if (spec.props)
|
|
673
|
+
for (let src of spec.props) {
|
|
674
|
+
if (!Array.isArray(src))
|
|
675
|
+
src = src(type);
|
|
676
|
+
if (src) {
|
|
677
|
+
if (src[0].perNode)
|
|
678
|
+
throw new RangeError("Can't store a per-node prop on a node type");
|
|
679
|
+
props[src[0].id] = src[1];
|
|
680
|
+
}
|
|
681
|
+
}
|
|
682
|
+
return type;
|
|
683
|
+
}
|
|
684
|
+
/// Retrieves a node prop for this type. Will return `undefined` if
|
|
685
|
+
/// the prop isn't present on this node.
|
|
686
|
+
prop(prop) {
|
|
687
|
+
return this.props[prop.id];
|
|
688
|
+
}
|
|
689
|
+
/// True when this is the top node of a grammar.
|
|
690
|
+
get isTop() {
|
|
691
|
+
return (this.flags & 1) > 0;
|
|
692
|
+
}
|
|
693
|
+
/// True when this node is produced by a skip rule.
|
|
694
|
+
get isSkipped() {
|
|
695
|
+
return (this.flags & 2) > 0;
|
|
696
|
+
}
|
|
697
|
+
/// Indicates whether this is an error node.
|
|
698
|
+
get isError() {
|
|
699
|
+
return (this.flags & 4) > 0;
|
|
700
|
+
}
|
|
701
|
+
/// When true, this node type doesn't correspond to a user-declared
|
|
702
|
+
/// named node, for example because it is used to cache repetition.
|
|
703
|
+
get isAnonymous() {
|
|
704
|
+
return (this.flags & 8) > 0;
|
|
705
|
+
}
|
|
706
|
+
/// Returns true when this node's name or one of its
|
|
707
|
+
/// [groups](#common.NodeProp^group) matches the given string.
|
|
708
|
+
is(name) {
|
|
709
|
+
if (typeof name == "string") {
|
|
710
|
+
if (this.name == name)
|
|
711
|
+
return true;
|
|
712
|
+
let group = this.prop(NodeProp.group);
|
|
713
|
+
return group ? group.indexOf(name) > -1 : false;
|
|
714
|
+
}
|
|
715
|
+
return this.id == name;
|
|
716
|
+
}
|
|
717
|
+
/// Create a function from node types to arbitrary values by
|
|
718
|
+
/// specifying an object whose property names are node or
|
|
719
|
+
/// [group](#common.NodeProp^group) names. Often useful with
|
|
720
|
+
/// [`NodeProp.add`](#common.NodeProp.add). You can put multiple
|
|
721
|
+
/// names, separated by spaces, in a single property name to map
|
|
722
|
+
/// multiple node names to a single value.
|
|
723
|
+
static match(map) {
|
|
724
|
+
let direct = /* @__PURE__ */ Object.create(null);
|
|
725
|
+
for (let prop in map)
|
|
726
|
+
for (let name of prop.split(" "))
|
|
727
|
+
direct[name] = map[prop];
|
|
728
|
+
return (node) => {
|
|
729
|
+
for (let groups = node.prop(NodeProp.group), i = -1; i < (groups ? groups.length : 0); i++) {
|
|
730
|
+
let found = direct[i < 0 ? node.name : groups[i]];
|
|
731
|
+
if (found)
|
|
732
|
+
return found;
|
|
733
|
+
}
|
|
734
|
+
};
|
|
735
|
+
}
|
|
736
|
+
};
|
|
737
|
+
NodeType.none = new NodeType(
|
|
738
|
+
"",
|
|
739
|
+
/* @__PURE__ */ Object.create(null),
|
|
740
|
+
0,
|
|
741
|
+
8
|
|
742
|
+
/* NodeFlag.Anonymous */
|
|
743
|
+
);
|
|
744
|
+
var NodeSet = class {
|
|
745
|
+
/// Create a set with the given types. The `id` property of each
|
|
746
|
+
/// type should correspond to its position within the array.
|
|
747
|
+
constructor(types) {
|
|
748
|
+
this.types = types;
|
|
749
|
+
for (let i = 0; i < types.length; i++)
|
|
750
|
+
if (types[i].id != i)
|
|
751
|
+
throw new RangeError("Node type ids should correspond to array positions when creating a node set");
|
|
752
|
+
}
|
|
753
|
+
/// Create a copy of this set with some node properties added. The
|
|
754
|
+
/// arguments to this method can be created with
|
|
755
|
+
/// [`NodeProp.add`](#common.NodeProp.add).
|
|
756
|
+
extend(...props) {
|
|
757
|
+
let newTypes = [];
|
|
758
|
+
for (let type of this.types) {
|
|
759
|
+
let newProps = null;
|
|
760
|
+
for (let source of props) {
|
|
761
|
+
let add = source(type);
|
|
762
|
+
if (add) {
|
|
763
|
+
if (!newProps)
|
|
764
|
+
newProps = Object.assign({}, type.props);
|
|
765
|
+
newProps[add[0].id] = add[1];
|
|
766
|
+
}
|
|
767
|
+
}
|
|
768
|
+
newTypes.push(newProps ? new NodeType(type.name, newProps, type.id, type.flags) : type);
|
|
769
|
+
}
|
|
770
|
+
return new NodeSet(newTypes);
|
|
771
|
+
}
|
|
772
|
+
};
|
|
773
|
+
var CachedNode = /* @__PURE__ */ new WeakMap();
|
|
774
|
+
var CachedInnerNode = /* @__PURE__ */ new WeakMap();
|
|
775
|
+
var IterMode;
|
|
776
|
+
(function(IterMode2) {
|
|
777
|
+
IterMode2[IterMode2["ExcludeBuffers"] = 1] = "ExcludeBuffers";
|
|
778
|
+
IterMode2[IterMode2["IncludeAnonymous"] = 2] = "IncludeAnonymous";
|
|
779
|
+
IterMode2[IterMode2["IgnoreMounts"] = 4] = "IgnoreMounts";
|
|
780
|
+
IterMode2[IterMode2["IgnoreOverlays"] = 8] = "IgnoreOverlays";
|
|
781
|
+
})(IterMode || (IterMode = {}));
|
|
782
|
+
var Tree = class {
|
|
783
|
+
/// Construct a new tree. See also [`Tree.build`](#common.Tree^build).
|
|
784
|
+
constructor(type, children, positions, length, props) {
|
|
785
|
+
this.type = type;
|
|
786
|
+
this.children = children;
|
|
787
|
+
this.positions = positions;
|
|
788
|
+
this.length = length;
|
|
789
|
+
this.props = null;
|
|
790
|
+
if (props && props.length) {
|
|
791
|
+
this.props = /* @__PURE__ */ Object.create(null);
|
|
792
|
+
for (let [prop, value] of props)
|
|
793
|
+
this.props[typeof prop == "number" ? prop : prop.id] = value;
|
|
794
|
+
}
|
|
795
|
+
}
|
|
796
|
+
/// @internal
|
|
797
|
+
toString() {
|
|
798
|
+
let mounted = this.prop(NodeProp.mounted);
|
|
799
|
+
if (mounted && !mounted.overlay)
|
|
800
|
+
return mounted.tree.toString();
|
|
801
|
+
let children = "";
|
|
802
|
+
for (let ch of this.children) {
|
|
803
|
+
let str = ch.toString();
|
|
804
|
+
if (str) {
|
|
805
|
+
if (children)
|
|
806
|
+
children += ",";
|
|
807
|
+
children += str;
|
|
808
|
+
}
|
|
809
|
+
}
|
|
810
|
+
return !this.type.name ? children : (/\W/.test(this.type.name) && !this.type.isError ? JSON.stringify(this.type.name) : this.type.name) + (children.length ? "(" + children + ")" : "");
|
|
811
|
+
}
|
|
812
|
+
/// Get a [tree cursor](#common.TreeCursor) positioned at the top of
|
|
813
|
+
/// the tree. Mode can be used to [control](#common.IterMode) which
|
|
814
|
+
/// nodes the cursor visits.
|
|
815
|
+
cursor(mode = 0) {
|
|
816
|
+
return new TreeCursor(this.topNode, mode);
|
|
817
|
+
}
|
|
818
|
+
/// Get a [tree cursor](#common.TreeCursor) pointing into this tree
|
|
819
|
+
/// at the given position and side (see
|
|
820
|
+
/// [`moveTo`](#common.TreeCursor.moveTo).
|
|
821
|
+
cursorAt(pos, side = 0, mode = 0) {
|
|
822
|
+
let scope = CachedNode.get(this) || this.topNode;
|
|
823
|
+
let cursor = new TreeCursor(scope);
|
|
824
|
+
cursor.moveTo(pos, side);
|
|
825
|
+
CachedNode.set(this, cursor._tree);
|
|
826
|
+
return cursor;
|
|
827
|
+
}
|
|
828
|
+
/// Get a [syntax node](#common.SyntaxNode) object for the top of the
|
|
829
|
+
/// tree.
|
|
830
|
+
get topNode() {
|
|
831
|
+
return new TreeNode(this, 0, 0, null);
|
|
832
|
+
}
|
|
833
|
+
/// Get the [syntax node](#common.SyntaxNode) at the given position.
|
|
834
|
+
/// If `side` is -1, this will move into nodes that end at the
|
|
835
|
+
/// position. If 1, it'll move into nodes that start at the
|
|
836
|
+
/// position. With 0, it'll only enter nodes that cover the position
|
|
837
|
+
/// from both sides.
|
|
838
|
+
///
|
|
839
|
+
/// Note that this will not enter
|
|
840
|
+
/// [overlays](#common.MountedTree.overlay), and you often want
|
|
841
|
+
/// [`resolveInner`](#common.Tree.resolveInner) instead.
|
|
842
|
+
resolve(pos, side = 0) {
|
|
843
|
+
let node = resolveNode(CachedNode.get(this) || this.topNode, pos, side, false);
|
|
844
|
+
CachedNode.set(this, node);
|
|
845
|
+
return node;
|
|
846
|
+
}
|
|
847
|
+
/// Like [`resolve`](#common.Tree.resolve), but will enter
|
|
848
|
+
/// [overlaid](#common.MountedTree.overlay) nodes, producing a syntax node
|
|
849
|
+
/// pointing into the innermost overlaid tree at the given position
|
|
850
|
+
/// (with parent links going through all parent structure, including
|
|
851
|
+
/// the host trees).
|
|
852
|
+
resolveInner(pos, side = 0) {
|
|
853
|
+
let node = resolveNode(CachedInnerNode.get(this) || this.topNode, pos, side, true);
|
|
854
|
+
CachedInnerNode.set(this, node);
|
|
855
|
+
return node;
|
|
856
|
+
}
|
|
857
|
+
/// Iterate over the tree and its children, calling `enter` for any
|
|
858
|
+
/// node that touches the `from`/`to` region (if given) before
|
|
859
|
+
/// running over such a node's children, and `leave` (if given) when
|
|
860
|
+
/// leaving the node. When `enter` returns `false`, that node will
|
|
861
|
+
/// not have its children iterated over (or `leave` called).
|
|
862
|
+
iterate(spec) {
|
|
863
|
+
let { enter, leave, from = 0, to = this.length } = spec;
|
|
864
|
+
let mode = spec.mode || 0, anon = (mode & IterMode.IncludeAnonymous) > 0;
|
|
865
|
+
for (let c = this.cursor(mode | IterMode.IncludeAnonymous); ; ) {
|
|
866
|
+
let entered = false;
|
|
867
|
+
if (c.from <= to && c.to >= from && (!anon && c.type.isAnonymous || enter(c) !== false)) {
|
|
868
|
+
if (c.firstChild())
|
|
869
|
+
continue;
|
|
870
|
+
entered = true;
|
|
871
|
+
}
|
|
872
|
+
for (; ; ) {
|
|
873
|
+
if (entered && leave && (anon || !c.type.isAnonymous))
|
|
874
|
+
leave(c);
|
|
875
|
+
if (c.nextSibling())
|
|
876
|
+
break;
|
|
877
|
+
if (!c.parent())
|
|
878
|
+
return;
|
|
879
|
+
entered = true;
|
|
880
|
+
}
|
|
881
|
+
}
|
|
882
|
+
}
|
|
883
|
+
/// Get the value of the given [node prop](#common.NodeProp) for this
|
|
884
|
+
/// node. Works with both per-node and per-type props.
|
|
885
|
+
prop(prop) {
|
|
886
|
+
return !prop.perNode ? this.type.prop(prop) : this.props ? this.props[prop.id] : void 0;
|
|
887
|
+
}
|
|
888
|
+
/// Returns the node's [per-node props](#common.NodeProp.perNode) in a
|
|
889
|
+
/// format that can be passed to the [`Tree`](#common.Tree)
|
|
890
|
+
/// constructor.
|
|
891
|
+
get propValues() {
|
|
892
|
+
let result = [];
|
|
893
|
+
if (this.props)
|
|
894
|
+
for (let id in this.props)
|
|
895
|
+
result.push([+id, this.props[id]]);
|
|
896
|
+
return result;
|
|
897
|
+
}
|
|
898
|
+
/// Balance the direct children of this tree, producing a copy of
|
|
899
|
+
/// which may have children grouped into subtrees with type
|
|
900
|
+
/// [`NodeType.none`](#common.NodeType^none).
|
|
901
|
+
balance(config = {}) {
|
|
902
|
+
return this.children.length <= 8 ? this : balanceRange(NodeType.none, this.children, this.positions, 0, this.children.length, 0, this.length, (children, positions, length) => new Tree(this.type, children, positions, length, this.propValues), config.makeTree || ((children, positions, length) => new Tree(NodeType.none, children, positions, length)));
|
|
903
|
+
}
|
|
904
|
+
/// Build a tree from a postfix-ordered buffer of node information,
|
|
905
|
+
/// or a cursor over such a buffer.
|
|
906
|
+
static build(data) {
|
|
907
|
+
return buildTree(data);
|
|
908
|
+
}
|
|
909
|
+
};
|
|
910
|
+
Tree.empty = new Tree(NodeType.none, [], [], 0);
|
|
911
|
+
var FlatBufferCursor = class {
|
|
912
|
+
constructor(buffer, index) {
|
|
913
|
+
this.buffer = buffer;
|
|
914
|
+
this.index = index;
|
|
915
|
+
}
|
|
916
|
+
get id() {
|
|
917
|
+
return this.buffer[this.index - 4];
|
|
918
|
+
}
|
|
919
|
+
get start() {
|
|
920
|
+
return this.buffer[this.index - 3];
|
|
921
|
+
}
|
|
922
|
+
get end() {
|
|
923
|
+
return this.buffer[this.index - 2];
|
|
924
|
+
}
|
|
925
|
+
get size() {
|
|
926
|
+
return this.buffer[this.index - 1];
|
|
927
|
+
}
|
|
928
|
+
get pos() {
|
|
929
|
+
return this.index;
|
|
930
|
+
}
|
|
931
|
+
next() {
|
|
932
|
+
this.index -= 4;
|
|
933
|
+
}
|
|
934
|
+
fork() {
|
|
935
|
+
return new FlatBufferCursor(this.buffer, this.index);
|
|
936
|
+
}
|
|
937
|
+
};
|
|
938
|
+
var TreeBuffer = class {
|
|
939
|
+
/// Create a tree buffer.
|
|
940
|
+
constructor(buffer, length, set) {
|
|
941
|
+
this.buffer = buffer;
|
|
942
|
+
this.length = length;
|
|
943
|
+
this.set = set;
|
|
944
|
+
}
|
|
945
|
+
/// @internal
|
|
946
|
+
get type() {
|
|
947
|
+
return NodeType.none;
|
|
948
|
+
}
|
|
949
|
+
/// @internal
|
|
950
|
+
toString() {
|
|
951
|
+
let result = [];
|
|
952
|
+
for (let index = 0; index < this.buffer.length; ) {
|
|
953
|
+
result.push(this.childString(index));
|
|
954
|
+
index = this.buffer[index + 3];
|
|
955
|
+
}
|
|
956
|
+
return result.join(",");
|
|
957
|
+
}
|
|
958
|
+
/// @internal
|
|
959
|
+
childString(index) {
|
|
960
|
+
let id = this.buffer[index], endIndex = this.buffer[index + 3];
|
|
961
|
+
let type = this.set.types[id], result = type.name;
|
|
962
|
+
if (/\W/.test(result) && !type.isError)
|
|
963
|
+
result = JSON.stringify(result);
|
|
964
|
+
index += 4;
|
|
965
|
+
if (endIndex == index)
|
|
966
|
+
return result;
|
|
967
|
+
let children = [];
|
|
968
|
+
while (index < endIndex) {
|
|
969
|
+
children.push(this.childString(index));
|
|
970
|
+
index = this.buffer[index + 3];
|
|
971
|
+
}
|
|
972
|
+
return result + "(" + children.join(",") + ")";
|
|
973
|
+
}
|
|
974
|
+
/// @internal
|
|
975
|
+
findChild(startIndex, endIndex, dir, pos, side) {
|
|
976
|
+
let { buffer } = this, pick = -1;
|
|
977
|
+
for (let i = startIndex; i != endIndex; i = buffer[i + 3]) {
|
|
978
|
+
if (checkSide(side, pos, buffer[i + 1], buffer[i + 2])) {
|
|
979
|
+
pick = i;
|
|
980
|
+
if (dir > 0)
|
|
981
|
+
break;
|
|
982
|
+
}
|
|
983
|
+
}
|
|
984
|
+
return pick;
|
|
985
|
+
}
|
|
986
|
+
/// @internal
|
|
987
|
+
slice(startI, endI, from) {
|
|
988
|
+
let b = this.buffer;
|
|
989
|
+
let copy = new Uint16Array(endI - startI), len = 0;
|
|
990
|
+
for (let i = startI, j = 0; i < endI; ) {
|
|
991
|
+
copy[j++] = b[i++];
|
|
992
|
+
copy[j++] = b[i++] - from;
|
|
993
|
+
let to = copy[j++] = b[i++] - from;
|
|
994
|
+
copy[j++] = b[i++] - startI;
|
|
995
|
+
len = Math.max(len, to);
|
|
996
|
+
}
|
|
997
|
+
return new TreeBuffer(copy, len, this.set);
|
|
998
|
+
}
|
|
999
|
+
};
|
|
1000
|
+
function checkSide(side, pos, from, to) {
|
|
1001
|
+
switch (side) {
|
|
1002
|
+
case -2:
|
|
1003
|
+
return from < pos;
|
|
1004
|
+
case -1:
|
|
1005
|
+
return to >= pos && from < pos;
|
|
1006
|
+
case 0:
|
|
1007
|
+
return from < pos && to > pos;
|
|
1008
|
+
case 1:
|
|
1009
|
+
return from <= pos && to > pos;
|
|
1010
|
+
case 2:
|
|
1011
|
+
return to > pos;
|
|
1012
|
+
case 4:
|
|
1013
|
+
return true;
|
|
1014
|
+
}
|
|
1015
|
+
}
|
|
1016
|
+
function enterUnfinishedNodesBefore(node, pos) {
|
|
1017
|
+
let scan = node.childBefore(pos);
|
|
1018
|
+
while (scan) {
|
|
1019
|
+
let last = scan.lastChild;
|
|
1020
|
+
if (!last || last.to != scan.to)
|
|
1021
|
+
break;
|
|
1022
|
+
if (last.type.isError && last.from == last.to) {
|
|
1023
|
+
node = scan;
|
|
1024
|
+
scan = last.prevSibling;
|
|
1025
|
+
} else {
|
|
1026
|
+
scan = last;
|
|
1027
|
+
}
|
|
1028
|
+
}
|
|
1029
|
+
return node;
|
|
1030
|
+
}
|
|
1031
|
+
function resolveNode(node, pos, side, overlays) {
|
|
1032
|
+
var _a;
|
|
1033
|
+
while (node.from == node.to || (side < 1 ? node.from >= pos : node.from > pos) || (side > -1 ? node.to <= pos : node.to < pos)) {
|
|
1034
|
+
let parent = !overlays && node instanceof TreeNode && node.index < 0 ? null : node.parent;
|
|
1035
|
+
if (!parent)
|
|
1036
|
+
return node;
|
|
1037
|
+
node = parent;
|
|
1038
|
+
}
|
|
1039
|
+
let mode = overlays ? 0 : IterMode.IgnoreOverlays;
|
|
1040
|
+
if (overlays)
|
|
1041
|
+
for (let scan = node, parent = scan.parent; parent; scan = parent, parent = scan.parent) {
|
|
1042
|
+
if (scan instanceof TreeNode && scan.index < 0 && ((_a = parent.enter(pos, side, mode)) === null || _a === void 0 ? void 0 : _a.from) != scan.from)
|
|
1043
|
+
node = parent;
|
|
1044
|
+
}
|
|
1045
|
+
for (; ; ) {
|
|
1046
|
+
let inner = node.enter(pos, side, mode);
|
|
1047
|
+
if (!inner)
|
|
1048
|
+
return node;
|
|
1049
|
+
node = inner;
|
|
1050
|
+
}
|
|
1051
|
+
}
|
|
1052
|
+
var TreeNode = class {
|
|
1053
|
+
constructor(_tree, from, index, _parent) {
|
|
1054
|
+
this._tree = _tree;
|
|
1055
|
+
this.from = from;
|
|
1056
|
+
this.index = index;
|
|
1057
|
+
this._parent = _parent;
|
|
1058
|
+
}
|
|
1059
|
+
get type() {
|
|
1060
|
+
return this._tree.type;
|
|
1061
|
+
}
|
|
1062
|
+
get name() {
|
|
1063
|
+
return this._tree.type.name;
|
|
1064
|
+
}
|
|
1065
|
+
get to() {
|
|
1066
|
+
return this.from + this._tree.length;
|
|
1067
|
+
}
|
|
1068
|
+
nextChild(i, dir, pos, side, mode = 0) {
|
|
1069
|
+
for (let parent = this; ; ) {
|
|
1070
|
+
for (let { children, positions } = parent._tree, e = dir > 0 ? children.length : -1; i != e; i += dir) {
|
|
1071
|
+
let next = children[i], start = positions[i] + parent.from;
|
|
1072
|
+
if (!checkSide(side, pos, start, start + next.length))
|
|
1073
|
+
continue;
|
|
1074
|
+
if (next instanceof TreeBuffer) {
|
|
1075
|
+
if (mode & IterMode.ExcludeBuffers)
|
|
1076
|
+
continue;
|
|
1077
|
+
let index = next.findChild(0, next.buffer.length, dir, pos - start, side);
|
|
1078
|
+
if (index > -1)
|
|
1079
|
+
return new BufferNode(new BufferContext(parent, next, i, start), null, index);
|
|
1080
|
+
} else if (mode & IterMode.IncludeAnonymous || (!next.type.isAnonymous || hasChild(next))) {
|
|
1081
|
+
let mounted;
|
|
1082
|
+
if (!(mode & IterMode.IgnoreMounts) && next.props && (mounted = next.prop(NodeProp.mounted)) && !mounted.overlay)
|
|
1083
|
+
return new TreeNode(mounted.tree, start, i, parent);
|
|
1084
|
+
let inner = new TreeNode(next, start, i, parent);
|
|
1085
|
+
return mode & IterMode.IncludeAnonymous || !inner.type.isAnonymous ? inner : inner.nextChild(dir < 0 ? next.children.length - 1 : 0, dir, pos, side);
|
|
1086
|
+
}
|
|
1087
|
+
}
|
|
1088
|
+
if (mode & IterMode.IncludeAnonymous || !parent.type.isAnonymous)
|
|
1089
|
+
return null;
|
|
1090
|
+
if (parent.index >= 0)
|
|
1091
|
+
i = parent.index + dir;
|
|
1092
|
+
else
|
|
1093
|
+
i = dir < 0 ? -1 : parent._parent._tree.children.length;
|
|
1094
|
+
parent = parent._parent;
|
|
1095
|
+
if (!parent)
|
|
1096
|
+
return null;
|
|
1097
|
+
}
|
|
1098
|
+
}
|
|
1099
|
+
get firstChild() {
|
|
1100
|
+
return this.nextChild(
|
|
1101
|
+
0,
|
|
1102
|
+
1,
|
|
1103
|
+
0,
|
|
1104
|
+
4
|
|
1105
|
+
/* Side.DontCare */
|
|
1106
|
+
);
|
|
1107
|
+
}
|
|
1108
|
+
get lastChild() {
|
|
1109
|
+
return this.nextChild(
|
|
1110
|
+
this._tree.children.length - 1,
|
|
1111
|
+
-1,
|
|
1112
|
+
0,
|
|
1113
|
+
4
|
|
1114
|
+
/* Side.DontCare */
|
|
1115
|
+
);
|
|
1116
|
+
}
|
|
1117
|
+
childAfter(pos) {
|
|
1118
|
+
return this.nextChild(
|
|
1119
|
+
0,
|
|
1120
|
+
1,
|
|
1121
|
+
pos,
|
|
1122
|
+
2
|
|
1123
|
+
/* Side.After */
|
|
1124
|
+
);
|
|
1125
|
+
}
|
|
1126
|
+
childBefore(pos) {
|
|
1127
|
+
return this.nextChild(
|
|
1128
|
+
this._tree.children.length - 1,
|
|
1129
|
+
-1,
|
|
1130
|
+
pos,
|
|
1131
|
+
-2
|
|
1132
|
+
/* Side.Before */
|
|
1133
|
+
);
|
|
1134
|
+
}
|
|
1135
|
+
enter(pos, side, mode = 0) {
|
|
1136
|
+
let mounted;
|
|
1137
|
+
if (!(mode & IterMode.IgnoreOverlays) && (mounted = this._tree.prop(NodeProp.mounted)) && mounted.overlay) {
|
|
1138
|
+
let rPos = pos - this.from;
|
|
1139
|
+
for (let { from, to } of mounted.overlay) {
|
|
1140
|
+
if ((side > 0 ? from <= rPos : from < rPos) && (side < 0 ? to >= rPos : to > rPos))
|
|
1141
|
+
return new TreeNode(mounted.tree, mounted.overlay[0].from + this.from, -1, this);
|
|
1142
|
+
}
|
|
1143
|
+
}
|
|
1144
|
+
return this.nextChild(0, 1, pos, side, mode);
|
|
1145
|
+
}
|
|
1146
|
+
nextSignificantParent() {
|
|
1147
|
+
let val = this;
|
|
1148
|
+
while (val.type.isAnonymous && val._parent)
|
|
1149
|
+
val = val._parent;
|
|
1150
|
+
return val;
|
|
1151
|
+
}
|
|
1152
|
+
get parent() {
|
|
1153
|
+
return this._parent ? this._parent.nextSignificantParent() : null;
|
|
1154
|
+
}
|
|
1155
|
+
get nextSibling() {
|
|
1156
|
+
return this._parent && this.index >= 0 ? this._parent.nextChild(
|
|
1157
|
+
this.index + 1,
|
|
1158
|
+
1,
|
|
1159
|
+
0,
|
|
1160
|
+
4
|
|
1161
|
+
/* Side.DontCare */
|
|
1162
|
+
) : null;
|
|
1163
|
+
}
|
|
1164
|
+
get prevSibling() {
|
|
1165
|
+
return this._parent && this.index >= 0 ? this._parent.nextChild(
|
|
1166
|
+
this.index - 1,
|
|
1167
|
+
-1,
|
|
1168
|
+
0,
|
|
1169
|
+
4
|
|
1170
|
+
/* Side.DontCare */
|
|
1171
|
+
) : null;
|
|
1172
|
+
}
|
|
1173
|
+
cursor(mode = 0) {
|
|
1174
|
+
return new TreeCursor(this, mode);
|
|
1175
|
+
}
|
|
1176
|
+
get tree() {
|
|
1177
|
+
return this._tree;
|
|
1178
|
+
}
|
|
1179
|
+
toTree() {
|
|
1180
|
+
return this._tree;
|
|
1181
|
+
}
|
|
1182
|
+
resolve(pos, side = 0) {
|
|
1183
|
+
return resolveNode(this, pos, side, false);
|
|
1184
|
+
}
|
|
1185
|
+
resolveInner(pos, side = 0) {
|
|
1186
|
+
return resolveNode(this, pos, side, true);
|
|
1187
|
+
}
|
|
1188
|
+
enterUnfinishedNodesBefore(pos) {
|
|
1189
|
+
return enterUnfinishedNodesBefore(this, pos);
|
|
1190
|
+
}
|
|
1191
|
+
getChild(type, before = null, after = null) {
|
|
1192
|
+
let r2 = getChildren(this, type, before, after);
|
|
1193
|
+
return r2.length ? r2[0] : null;
|
|
1194
|
+
}
|
|
1195
|
+
getChildren(type, before = null, after = null) {
|
|
1196
|
+
return getChildren(this, type, before, after);
|
|
1197
|
+
}
|
|
1198
|
+
/// @internal
|
|
1199
|
+
toString() {
|
|
1200
|
+
return this._tree.toString();
|
|
1201
|
+
}
|
|
1202
|
+
get node() {
|
|
1203
|
+
return this;
|
|
1204
|
+
}
|
|
1205
|
+
matchContext(context) {
|
|
1206
|
+
return matchNodeContext(this, context);
|
|
1207
|
+
}
|
|
1208
|
+
};
|
|
1209
|
+
function getChildren(node, type, before, after) {
|
|
1210
|
+
let cur = node.cursor(), result = [];
|
|
1211
|
+
if (!cur.firstChild())
|
|
1212
|
+
return result;
|
|
1213
|
+
if (before != null) {
|
|
1214
|
+
while (!cur.type.is(before))
|
|
1215
|
+
if (!cur.nextSibling())
|
|
1216
|
+
return result;
|
|
1217
|
+
}
|
|
1218
|
+
for (; ; ) {
|
|
1219
|
+
if (after != null && cur.type.is(after))
|
|
1220
|
+
return result;
|
|
1221
|
+
if (cur.type.is(type))
|
|
1222
|
+
result.push(cur.node);
|
|
1223
|
+
if (!cur.nextSibling())
|
|
1224
|
+
return after == null ? result : [];
|
|
1225
|
+
}
|
|
1226
|
+
}
|
|
1227
|
+
function matchNodeContext(node, context, i = context.length - 1) {
|
|
1228
|
+
for (let p = node.parent; i >= 0; p = p.parent) {
|
|
1229
|
+
if (!p)
|
|
1230
|
+
return false;
|
|
1231
|
+
if (!p.type.isAnonymous) {
|
|
1232
|
+
if (context[i] && context[i] != p.name)
|
|
1233
|
+
return false;
|
|
1234
|
+
i--;
|
|
1235
|
+
}
|
|
1236
|
+
}
|
|
1237
|
+
return true;
|
|
1238
|
+
}
|
|
1239
|
+
var BufferContext = class {
|
|
1240
|
+
constructor(parent, buffer, index, start) {
|
|
1241
|
+
this.parent = parent;
|
|
1242
|
+
this.buffer = buffer;
|
|
1243
|
+
this.index = index;
|
|
1244
|
+
this.start = start;
|
|
1245
|
+
}
|
|
1246
|
+
};
|
|
1247
|
+
var BufferNode = class {
|
|
1248
|
+
get name() {
|
|
1249
|
+
return this.type.name;
|
|
1250
|
+
}
|
|
1251
|
+
get from() {
|
|
1252
|
+
return this.context.start + this.context.buffer.buffer[this.index + 1];
|
|
1253
|
+
}
|
|
1254
|
+
get to() {
|
|
1255
|
+
return this.context.start + this.context.buffer.buffer[this.index + 2];
|
|
1256
|
+
}
|
|
1257
|
+
constructor(context, _parent, index) {
|
|
1258
|
+
this.context = context;
|
|
1259
|
+
this._parent = _parent;
|
|
1260
|
+
this.index = index;
|
|
1261
|
+
this.type = context.buffer.set.types[context.buffer.buffer[index]];
|
|
1262
|
+
}
|
|
1263
|
+
child(dir, pos, side) {
|
|
1264
|
+
let { buffer } = this.context;
|
|
1265
|
+
let index = buffer.findChild(this.index + 4, buffer.buffer[this.index + 3], dir, pos - this.context.start, side);
|
|
1266
|
+
return index < 0 ? null : new BufferNode(this.context, this, index);
|
|
1267
|
+
}
|
|
1268
|
+
get firstChild() {
|
|
1269
|
+
return this.child(
|
|
1270
|
+
1,
|
|
1271
|
+
0,
|
|
1272
|
+
4
|
|
1273
|
+
/* Side.DontCare */
|
|
1274
|
+
);
|
|
1275
|
+
}
|
|
1276
|
+
get lastChild() {
|
|
1277
|
+
return this.child(
|
|
1278
|
+
-1,
|
|
1279
|
+
0,
|
|
1280
|
+
4
|
|
1281
|
+
/* Side.DontCare */
|
|
1282
|
+
);
|
|
1283
|
+
}
|
|
1284
|
+
childAfter(pos) {
|
|
1285
|
+
return this.child(
|
|
1286
|
+
1,
|
|
1287
|
+
pos,
|
|
1288
|
+
2
|
|
1289
|
+
/* Side.After */
|
|
1290
|
+
);
|
|
1291
|
+
}
|
|
1292
|
+
childBefore(pos) {
|
|
1293
|
+
return this.child(
|
|
1294
|
+
-1,
|
|
1295
|
+
pos,
|
|
1296
|
+
-2
|
|
1297
|
+
/* Side.Before */
|
|
1298
|
+
);
|
|
1299
|
+
}
|
|
1300
|
+
enter(pos, side, mode = 0) {
|
|
1301
|
+
if (mode & IterMode.ExcludeBuffers)
|
|
1302
|
+
return null;
|
|
1303
|
+
let { buffer } = this.context;
|
|
1304
|
+
let index = buffer.findChild(this.index + 4, buffer.buffer[this.index + 3], side > 0 ? 1 : -1, pos - this.context.start, side);
|
|
1305
|
+
return index < 0 ? null : new BufferNode(this.context, this, index);
|
|
1306
|
+
}
|
|
1307
|
+
get parent() {
|
|
1308
|
+
return this._parent || this.context.parent.nextSignificantParent();
|
|
1309
|
+
}
|
|
1310
|
+
externalSibling(dir) {
|
|
1311
|
+
return this._parent ? null : this.context.parent.nextChild(
|
|
1312
|
+
this.context.index + dir,
|
|
1313
|
+
dir,
|
|
1314
|
+
0,
|
|
1315
|
+
4
|
|
1316
|
+
/* Side.DontCare */
|
|
1317
|
+
);
|
|
1318
|
+
}
|
|
1319
|
+
get nextSibling() {
|
|
1320
|
+
let { buffer } = this.context;
|
|
1321
|
+
let after = buffer.buffer[this.index + 3];
|
|
1322
|
+
if (after < (this._parent ? buffer.buffer[this._parent.index + 3] : buffer.buffer.length))
|
|
1323
|
+
return new BufferNode(this.context, this._parent, after);
|
|
1324
|
+
return this.externalSibling(1);
|
|
1325
|
+
}
|
|
1326
|
+
get prevSibling() {
|
|
1327
|
+
let { buffer } = this.context;
|
|
1328
|
+
let parentStart = this._parent ? this._parent.index + 4 : 0;
|
|
1329
|
+
if (this.index == parentStart)
|
|
1330
|
+
return this.externalSibling(-1);
|
|
1331
|
+
return new BufferNode(this.context, this._parent, buffer.findChild(
|
|
1332
|
+
parentStart,
|
|
1333
|
+
this.index,
|
|
1334
|
+
-1,
|
|
1335
|
+
0,
|
|
1336
|
+
4
|
|
1337
|
+
/* Side.DontCare */
|
|
1338
|
+
));
|
|
1339
|
+
}
|
|
1340
|
+
cursor(mode = 0) {
|
|
1341
|
+
return new TreeCursor(this, mode);
|
|
1342
|
+
}
|
|
1343
|
+
get tree() {
|
|
1344
|
+
return null;
|
|
1345
|
+
}
|
|
1346
|
+
toTree() {
|
|
1347
|
+
let children = [], positions = [];
|
|
1348
|
+
let { buffer } = this.context;
|
|
1349
|
+
let startI = this.index + 4, endI = buffer.buffer[this.index + 3];
|
|
1350
|
+
if (endI > startI) {
|
|
1351
|
+
let from = buffer.buffer[this.index + 1];
|
|
1352
|
+
children.push(buffer.slice(startI, endI, from));
|
|
1353
|
+
positions.push(0);
|
|
1354
|
+
}
|
|
1355
|
+
return new Tree(this.type, children, positions, this.to - this.from);
|
|
1356
|
+
}
|
|
1357
|
+
resolve(pos, side = 0) {
|
|
1358
|
+
return resolveNode(this, pos, side, false);
|
|
1359
|
+
}
|
|
1360
|
+
resolveInner(pos, side = 0) {
|
|
1361
|
+
return resolveNode(this, pos, side, true);
|
|
1362
|
+
}
|
|
1363
|
+
enterUnfinishedNodesBefore(pos) {
|
|
1364
|
+
return enterUnfinishedNodesBefore(this, pos);
|
|
1365
|
+
}
|
|
1366
|
+
/// @internal
|
|
1367
|
+
toString() {
|
|
1368
|
+
return this.context.buffer.childString(this.index);
|
|
1369
|
+
}
|
|
1370
|
+
getChild(type, before = null, after = null) {
|
|
1371
|
+
let r2 = getChildren(this, type, before, after);
|
|
1372
|
+
return r2.length ? r2[0] : null;
|
|
1373
|
+
}
|
|
1374
|
+
getChildren(type, before = null, after = null) {
|
|
1375
|
+
return getChildren(this, type, before, after);
|
|
1376
|
+
}
|
|
1377
|
+
get node() {
|
|
1378
|
+
return this;
|
|
1379
|
+
}
|
|
1380
|
+
matchContext(context) {
|
|
1381
|
+
return matchNodeContext(this, context);
|
|
1382
|
+
}
|
|
1383
|
+
};
|
|
1384
|
+
var TreeCursor = class {
|
|
1385
|
+
/// Shorthand for `.type.name`.
|
|
1386
|
+
get name() {
|
|
1387
|
+
return this.type.name;
|
|
1388
|
+
}
|
|
1389
|
+
/// @internal
|
|
1390
|
+
constructor(node, mode = 0) {
|
|
1391
|
+
this.mode = mode;
|
|
1392
|
+
this.buffer = null;
|
|
1393
|
+
this.stack = [];
|
|
1394
|
+
this.index = 0;
|
|
1395
|
+
this.bufferNode = null;
|
|
1396
|
+
if (node instanceof TreeNode) {
|
|
1397
|
+
this.yieldNode(node);
|
|
1398
|
+
} else {
|
|
1399
|
+
this._tree = node.context.parent;
|
|
1400
|
+
this.buffer = node.context;
|
|
1401
|
+
for (let n = node._parent; n; n = n._parent)
|
|
1402
|
+
this.stack.unshift(n.index);
|
|
1403
|
+
this.bufferNode = node;
|
|
1404
|
+
this.yieldBuf(node.index);
|
|
1405
|
+
}
|
|
1406
|
+
}
|
|
1407
|
+
yieldNode(node) {
|
|
1408
|
+
if (!node)
|
|
1409
|
+
return false;
|
|
1410
|
+
this._tree = node;
|
|
1411
|
+
this.type = node.type;
|
|
1412
|
+
this.from = node.from;
|
|
1413
|
+
this.to = node.to;
|
|
1414
|
+
return true;
|
|
1415
|
+
}
|
|
1416
|
+
yieldBuf(index, type) {
|
|
1417
|
+
this.index = index;
|
|
1418
|
+
let { start, buffer } = this.buffer;
|
|
1419
|
+
this.type = type || buffer.set.types[buffer.buffer[index]];
|
|
1420
|
+
this.from = start + buffer.buffer[index + 1];
|
|
1421
|
+
this.to = start + buffer.buffer[index + 2];
|
|
1422
|
+
return true;
|
|
1423
|
+
}
|
|
1424
|
+
yield(node) {
|
|
1425
|
+
if (!node)
|
|
1426
|
+
return false;
|
|
1427
|
+
if (node instanceof TreeNode) {
|
|
1428
|
+
this.buffer = null;
|
|
1429
|
+
return this.yieldNode(node);
|
|
1430
|
+
}
|
|
1431
|
+
this.buffer = node.context;
|
|
1432
|
+
return this.yieldBuf(node.index, node.type);
|
|
1433
|
+
}
|
|
1434
|
+
/// @internal
|
|
1435
|
+
toString() {
|
|
1436
|
+
return this.buffer ? this.buffer.buffer.childString(this.index) : this._tree.toString();
|
|
1437
|
+
}
|
|
1438
|
+
/// @internal
|
|
1439
|
+
enterChild(dir, pos, side) {
|
|
1440
|
+
if (!this.buffer)
|
|
1441
|
+
return this.yield(this._tree.nextChild(dir < 0 ? this._tree._tree.children.length - 1 : 0, dir, pos, side, this.mode));
|
|
1442
|
+
let { buffer } = this.buffer;
|
|
1443
|
+
let index = buffer.findChild(this.index + 4, buffer.buffer[this.index + 3], dir, pos - this.buffer.start, side);
|
|
1444
|
+
if (index < 0)
|
|
1445
|
+
return false;
|
|
1446
|
+
this.stack.push(this.index);
|
|
1447
|
+
return this.yieldBuf(index);
|
|
1448
|
+
}
|
|
1449
|
+
/// Move the cursor to this node's first child. When this returns
|
|
1450
|
+
/// false, the node has no child, and the cursor has not been moved.
|
|
1451
|
+
firstChild() {
|
|
1452
|
+
return this.enterChild(
|
|
1453
|
+
1,
|
|
1454
|
+
0,
|
|
1455
|
+
4
|
|
1456
|
+
/* Side.DontCare */
|
|
1457
|
+
);
|
|
1458
|
+
}
|
|
1459
|
+
/// Move the cursor to this node's last child.
|
|
1460
|
+
lastChild() {
|
|
1461
|
+
return this.enterChild(
|
|
1462
|
+
-1,
|
|
1463
|
+
0,
|
|
1464
|
+
4
|
|
1465
|
+
/* Side.DontCare */
|
|
1466
|
+
);
|
|
1467
|
+
}
|
|
1468
|
+
/// Move the cursor to the first child that ends after `pos`.
|
|
1469
|
+
childAfter(pos) {
|
|
1470
|
+
return this.enterChild(
|
|
1471
|
+
1,
|
|
1472
|
+
pos,
|
|
1473
|
+
2
|
|
1474
|
+
/* Side.After */
|
|
1475
|
+
);
|
|
1476
|
+
}
|
|
1477
|
+
/// Move to the last child that starts before `pos`.
|
|
1478
|
+
childBefore(pos) {
|
|
1479
|
+
return this.enterChild(
|
|
1480
|
+
-1,
|
|
1481
|
+
pos,
|
|
1482
|
+
-2
|
|
1483
|
+
/* Side.Before */
|
|
1484
|
+
);
|
|
1485
|
+
}
|
|
1486
|
+
/// Move the cursor to the child around `pos`. If side is -1 the
|
|
1487
|
+
/// child may end at that position, when 1 it may start there. This
|
|
1488
|
+
/// will also enter [overlaid](#common.MountedTree.overlay)
|
|
1489
|
+
/// [mounted](#common.NodeProp^mounted) trees unless `overlays` is
|
|
1490
|
+
/// set to false.
|
|
1491
|
+
enter(pos, side, mode = this.mode) {
|
|
1492
|
+
if (!this.buffer)
|
|
1493
|
+
return this.yield(this._tree.enter(pos, side, mode));
|
|
1494
|
+
return mode & IterMode.ExcludeBuffers ? false : this.enterChild(1, pos, side);
|
|
1495
|
+
}
|
|
1496
|
+
/// Move to the node's parent node, if this isn't the top node.
|
|
1497
|
+
parent() {
|
|
1498
|
+
if (!this.buffer)
|
|
1499
|
+
return this.yieldNode(this.mode & IterMode.IncludeAnonymous ? this._tree._parent : this._tree.parent);
|
|
1500
|
+
if (this.stack.length)
|
|
1501
|
+
return this.yieldBuf(this.stack.pop());
|
|
1502
|
+
let parent = this.mode & IterMode.IncludeAnonymous ? this.buffer.parent : this.buffer.parent.nextSignificantParent();
|
|
1503
|
+
this.buffer = null;
|
|
1504
|
+
return this.yieldNode(parent);
|
|
1505
|
+
}
|
|
1506
|
+
/// @internal
|
|
1507
|
+
sibling(dir) {
|
|
1508
|
+
if (!this.buffer)
|
|
1509
|
+
return !this._tree._parent ? false : this.yield(this._tree.index < 0 ? null : this._tree._parent.nextChild(this._tree.index + dir, dir, 0, 4, this.mode));
|
|
1510
|
+
let { buffer } = this.buffer, d = this.stack.length - 1;
|
|
1511
|
+
if (dir < 0) {
|
|
1512
|
+
let parentStart = d < 0 ? 0 : this.stack[d] + 4;
|
|
1513
|
+
if (this.index != parentStart)
|
|
1514
|
+
return this.yieldBuf(buffer.findChild(
|
|
1515
|
+
parentStart,
|
|
1516
|
+
this.index,
|
|
1517
|
+
-1,
|
|
1518
|
+
0,
|
|
1519
|
+
4
|
|
1520
|
+
/* Side.DontCare */
|
|
1521
|
+
));
|
|
1522
|
+
} else {
|
|
1523
|
+
let after = buffer.buffer[this.index + 3];
|
|
1524
|
+
if (after < (d < 0 ? buffer.buffer.length : buffer.buffer[this.stack[d] + 3]))
|
|
1525
|
+
return this.yieldBuf(after);
|
|
1526
|
+
}
|
|
1527
|
+
return d < 0 ? this.yield(this.buffer.parent.nextChild(this.buffer.index + dir, dir, 0, 4, this.mode)) : false;
|
|
1528
|
+
}
|
|
1529
|
+
/// Move to this node's next sibling, if any.
|
|
1530
|
+
nextSibling() {
|
|
1531
|
+
return this.sibling(1);
|
|
1532
|
+
}
|
|
1533
|
+
/// Move to this node's previous sibling, if any.
|
|
1534
|
+
prevSibling() {
|
|
1535
|
+
return this.sibling(-1);
|
|
1536
|
+
}
|
|
1537
|
+
atLastNode(dir) {
|
|
1538
|
+
let index, parent, { buffer } = this;
|
|
1539
|
+
if (buffer) {
|
|
1540
|
+
if (dir > 0) {
|
|
1541
|
+
if (this.index < buffer.buffer.buffer.length)
|
|
1542
|
+
return false;
|
|
1543
|
+
} else {
|
|
1544
|
+
for (let i = 0; i < this.index; i++)
|
|
1545
|
+
if (buffer.buffer.buffer[i + 3] < this.index)
|
|
1546
|
+
return false;
|
|
1547
|
+
}
|
|
1548
|
+
({ index, parent } = buffer);
|
|
1549
|
+
} else {
|
|
1550
|
+
({ index, _parent: parent } = this._tree);
|
|
1551
|
+
}
|
|
1552
|
+
for (; parent; { index, _parent: parent } = parent) {
|
|
1553
|
+
if (index > -1)
|
|
1554
|
+
for (let i = index + dir, e = dir < 0 ? -1 : parent._tree.children.length; i != e; i += dir) {
|
|
1555
|
+
let child = parent._tree.children[i];
|
|
1556
|
+
if (this.mode & IterMode.IncludeAnonymous || child instanceof TreeBuffer || !child.type.isAnonymous || hasChild(child))
|
|
1557
|
+
return false;
|
|
1558
|
+
}
|
|
1559
|
+
}
|
|
1560
|
+
return true;
|
|
1561
|
+
}
|
|
1562
|
+
move(dir, enter) {
|
|
1563
|
+
if (enter && this.enterChild(
|
|
1564
|
+
dir,
|
|
1565
|
+
0,
|
|
1566
|
+
4
|
|
1567
|
+
/* Side.DontCare */
|
|
1568
|
+
))
|
|
1569
|
+
return true;
|
|
1570
|
+
for (; ; ) {
|
|
1571
|
+
if (this.sibling(dir))
|
|
1572
|
+
return true;
|
|
1573
|
+
if (this.atLastNode(dir) || !this.parent())
|
|
1574
|
+
return false;
|
|
1575
|
+
}
|
|
1576
|
+
}
|
|
1577
|
+
/// Move to the next node in a
|
|
1578
|
+
/// [pre-order](https://en.wikipedia.org/wiki/Tree_traversal#Pre-order,_NLR)
|
|
1579
|
+
/// traversal, going from a node to its first child or, if the
|
|
1580
|
+
/// current node is empty or `enter` is false, its next sibling or
|
|
1581
|
+
/// the next sibling of the first parent node that has one.
|
|
1582
|
+
next(enter = true) {
|
|
1583
|
+
return this.move(1, enter);
|
|
1584
|
+
}
|
|
1585
|
+
/// Move to the next node in a last-to-first pre-order traveral. A
|
|
1586
|
+
/// node is followed by its last child or, if it has none, its
|
|
1587
|
+
/// previous sibling or the previous sibling of the first parent
|
|
1588
|
+
/// node that has one.
|
|
1589
|
+
prev(enter = true) {
|
|
1590
|
+
return this.move(-1, enter);
|
|
1591
|
+
}
|
|
1592
|
+
/// Move the cursor to the innermost node that covers `pos`. If
|
|
1593
|
+
/// `side` is -1, it will enter nodes that end at `pos`. If it is 1,
|
|
1594
|
+
/// it will enter nodes that start at `pos`.
|
|
1595
|
+
moveTo(pos, side = 0) {
|
|
1596
|
+
while (this.from == this.to || (side < 1 ? this.from >= pos : this.from > pos) || (side > -1 ? this.to <= pos : this.to < pos))
|
|
1597
|
+
if (!this.parent())
|
|
1598
|
+
break;
|
|
1599
|
+
while (this.enterChild(1, pos, side)) {
|
|
1600
|
+
}
|
|
1601
|
+
return this;
|
|
1602
|
+
}
|
|
1603
|
+
/// Get a [syntax node](#common.SyntaxNode) at the cursor's current
|
|
1604
|
+
/// position.
|
|
1605
|
+
get node() {
|
|
1606
|
+
if (!this.buffer)
|
|
1607
|
+
return this._tree;
|
|
1608
|
+
let cache = this.bufferNode, result = null, depth = 0;
|
|
1609
|
+
if (cache && cache.context == this.buffer) {
|
|
1610
|
+
scan:
|
|
1611
|
+
for (let index = this.index, d = this.stack.length; d >= 0; ) {
|
|
1612
|
+
for (let c = cache; c; c = c._parent)
|
|
1613
|
+
if (c.index == index) {
|
|
1614
|
+
if (index == this.index)
|
|
1615
|
+
return c;
|
|
1616
|
+
result = c;
|
|
1617
|
+
depth = d + 1;
|
|
1618
|
+
break scan;
|
|
1619
|
+
}
|
|
1620
|
+
index = this.stack[--d];
|
|
1621
|
+
}
|
|
1622
|
+
}
|
|
1623
|
+
for (let i = depth; i < this.stack.length; i++)
|
|
1624
|
+
result = new BufferNode(this.buffer, result, this.stack[i]);
|
|
1625
|
+
return this.bufferNode = new BufferNode(this.buffer, result, this.index);
|
|
1626
|
+
}
|
|
1627
|
+
/// Get the [tree](#common.Tree) that represents the current node, if
|
|
1628
|
+
/// any. Will return null when the node is in a [tree
|
|
1629
|
+
/// buffer](#common.TreeBuffer).
|
|
1630
|
+
get tree() {
|
|
1631
|
+
return this.buffer ? null : this._tree._tree;
|
|
1632
|
+
}
|
|
1633
|
+
/// Iterate over the current node and all its descendants, calling
|
|
1634
|
+
/// `enter` when entering a node and `leave`, if given, when leaving
|
|
1635
|
+
/// one. When `enter` returns `false`, any children of that node are
|
|
1636
|
+
/// skipped, and `leave` isn't called for it.
|
|
1637
|
+
iterate(enter, leave) {
|
|
1638
|
+
for (let depth = 0; ; ) {
|
|
1639
|
+
let mustLeave = false;
|
|
1640
|
+
if (this.type.isAnonymous || enter(this) !== false) {
|
|
1641
|
+
if (this.firstChild()) {
|
|
1642
|
+
depth++;
|
|
1643
|
+
continue;
|
|
1644
|
+
}
|
|
1645
|
+
if (!this.type.isAnonymous)
|
|
1646
|
+
mustLeave = true;
|
|
1647
|
+
}
|
|
1648
|
+
for (; ; ) {
|
|
1649
|
+
if (mustLeave && leave)
|
|
1650
|
+
leave(this);
|
|
1651
|
+
mustLeave = this.type.isAnonymous;
|
|
1652
|
+
if (this.nextSibling())
|
|
1653
|
+
break;
|
|
1654
|
+
if (!depth)
|
|
1655
|
+
return;
|
|
1656
|
+
this.parent();
|
|
1657
|
+
depth--;
|
|
1658
|
+
mustLeave = true;
|
|
1659
|
+
}
|
|
1660
|
+
}
|
|
1661
|
+
}
|
|
1662
|
+
/// Test whether the current node matches a given context—a sequence
|
|
1663
|
+
/// of direct parent node names. Empty strings in the context array
|
|
1664
|
+
/// are treated as wildcards.
|
|
1665
|
+
matchContext(context) {
|
|
1666
|
+
if (!this.buffer)
|
|
1667
|
+
return matchNodeContext(this.node, context);
|
|
1668
|
+
let { buffer } = this.buffer, { types } = buffer.set;
|
|
1669
|
+
for (let i = context.length - 1, d = this.stack.length - 1; i >= 0; d--) {
|
|
1670
|
+
if (d < 0)
|
|
1671
|
+
return matchNodeContext(this.node, context, i);
|
|
1672
|
+
let type = types[buffer.buffer[this.stack[d]]];
|
|
1673
|
+
if (!type.isAnonymous) {
|
|
1674
|
+
if (context[i] && context[i] != type.name)
|
|
1675
|
+
return false;
|
|
1676
|
+
i--;
|
|
1677
|
+
}
|
|
1678
|
+
}
|
|
1679
|
+
return true;
|
|
1680
|
+
}
|
|
1681
|
+
};
|
|
1682
|
+
function hasChild(tree) {
|
|
1683
|
+
return tree.children.some((ch) => ch instanceof TreeBuffer || !ch.type.isAnonymous || hasChild(ch));
|
|
1684
|
+
}
|
|
1685
|
+
function buildTree(data) {
|
|
1686
|
+
var _a;
|
|
1687
|
+
let { buffer, nodeSet, maxBufferLength = DefaultBufferLength, reused = [], minRepeatType = nodeSet.types.length } = data;
|
|
1688
|
+
let cursor = Array.isArray(buffer) ? new FlatBufferCursor(buffer, buffer.length) : buffer;
|
|
1689
|
+
let types = nodeSet.types;
|
|
1690
|
+
let contextHash = 0, lookAhead = 0;
|
|
1691
|
+
function takeNode(parentStart, minPos, children2, positions2, inRepeat) {
|
|
1692
|
+
let { id, start, end, size } = cursor;
|
|
1693
|
+
let lookAheadAtStart = lookAhead;
|
|
1694
|
+
while (size < 0) {
|
|
1695
|
+
cursor.next();
|
|
1696
|
+
if (size == -1) {
|
|
1697
|
+
let node2 = reused[id];
|
|
1698
|
+
children2.push(node2);
|
|
1699
|
+
positions2.push(start - parentStart);
|
|
1700
|
+
return;
|
|
1701
|
+
} else if (size == -3) {
|
|
1702
|
+
contextHash = id;
|
|
1703
|
+
return;
|
|
1704
|
+
} else if (size == -4) {
|
|
1705
|
+
lookAhead = id;
|
|
1706
|
+
return;
|
|
1707
|
+
} else {
|
|
1708
|
+
throw new RangeError(`Unrecognized record size: ${size}`);
|
|
1709
|
+
}
|
|
1710
|
+
}
|
|
1711
|
+
let type = types[id], node, buffer2;
|
|
1712
|
+
let startPos = start - parentStart;
|
|
1713
|
+
if (end - start <= maxBufferLength && (buffer2 = findBufferSize(cursor.pos - minPos, inRepeat))) {
|
|
1714
|
+
let data2 = new Uint16Array(buffer2.size - buffer2.skip);
|
|
1715
|
+
let endPos = cursor.pos - buffer2.size, index = data2.length;
|
|
1716
|
+
while (cursor.pos > endPos)
|
|
1717
|
+
index = copyToBuffer(buffer2.start, data2, index);
|
|
1718
|
+
node = new TreeBuffer(data2, end - buffer2.start, nodeSet);
|
|
1719
|
+
startPos = buffer2.start - parentStart;
|
|
1720
|
+
} else {
|
|
1721
|
+
let endPos = cursor.pos - size;
|
|
1722
|
+
cursor.next();
|
|
1723
|
+
let localChildren = [], localPositions = [];
|
|
1724
|
+
let localInRepeat = id >= minRepeatType ? id : -1;
|
|
1725
|
+
let lastGroup = 0, lastEnd = end;
|
|
1726
|
+
while (cursor.pos > endPos) {
|
|
1727
|
+
if (localInRepeat >= 0 && cursor.id == localInRepeat && cursor.size >= 0) {
|
|
1728
|
+
if (cursor.end <= lastEnd - maxBufferLength) {
|
|
1729
|
+
makeRepeatLeaf(localChildren, localPositions, start, lastGroup, cursor.end, lastEnd, localInRepeat, lookAheadAtStart);
|
|
1730
|
+
lastGroup = localChildren.length;
|
|
1731
|
+
lastEnd = cursor.end;
|
|
1732
|
+
}
|
|
1733
|
+
cursor.next();
|
|
1734
|
+
} else {
|
|
1735
|
+
takeNode(start, endPos, localChildren, localPositions, localInRepeat);
|
|
1736
|
+
}
|
|
1737
|
+
}
|
|
1738
|
+
if (localInRepeat >= 0 && lastGroup > 0 && lastGroup < localChildren.length)
|
|
1739
|
+
makeRepeatLeaf(localChildren, localPositions, start, lastGroup, start, lastEnd, localInRepeat, lookAheadAtStart);
|
|
1740
|
+
localChildren.reverse();
|
|
1741
|
+
localPositions.reverse();
|
|
1742
|
+
if (localInRepeat > -1 && lastGroup > 0) {
|
|
1743
|
+
let make = makeBalanced(type);
|
|
1744
|
+
node = balanceRange(type, localChildren, localPositions, 0, localChildren.length, 0, end - start, make, make);
|
|
1745
|
+
} else {
|
|
1746
|
+
node = makeTree(type, localChildren, localPositions, end - start, lookAheadAtStart - end);
|
|
1747
|
+
}
|
|
1748
|
+
}
|
|
1749
|
+
children2.push(node);
|
|
1750
|
+
positions2.push(startPos);
|
|
1751
|
+
}
|
|
1752
|
+
function makeBalanced(type) {
|
|
1753
|
+
return (children2, positions2, length2) => {
|
|
1754
|
+
let lookAhead2 = 0, lastI = children2.length - 1, last, lookAheadProp;
|
|
1755
|
+
if (lastI >= 0 && (last = children2[lastI]) instanceof Tree) {
|
|
1756
|
+
if (!lastI && last.type == type && last.length == length2)
|
|
1757
|
+
return last;
|
|
1758
|
+
if (lookAheadProp = last.prop(NodeProp.lookAhead))
|
|
1759
|
+
lookAhead2 = positions2[lastI] + last.length + lookAheadProp;
|
|
1760
|
+
}
|
|
1761
|
+
return makeTree(type, children2, positions2, length2, lookAhead2);
|
|
1762
|
+
};
|
|
1763
|
+
}
|
|
1764
|
+
function makeRepeatLeaf(children2, positions2, base, i, from, to, type, lookAhead2) {
|
|
1765
|
+
let localChildren = [], localPositions = [];
|
|
1766
|
+
while (children2.length > i) {
|
|
1767
|
+
localChildren.push(children2.pop());
|
|
1768
|
+
localPositions.push(positions2.pop() + base - from);
|
|
1769
|
+
}
|
|
1770
|
+
children2.push(makeTree(nodeSet.types[type], localChildren, localPositions, to - from, lookAhead2 - to));
|
|
1771
|
+
positions2.push(from - base);
|
|
1772
|
+
}
|
|
1773
|
+
function makeTree(type, children2, positions2, length2, lookAhead2 = 0, props) {
|
|
1774
|
+
if (contextHash) {
|
|
1775
|
+
let pair2 = [NodeProp.contextHash, contextHash];
|
|
1776
|
+
props = props ? [pair2].concat(props) : [pair2];
|
|
1777
|
+
}
|
|
1778
|
+
if (lookAhead2 > 25) {
|
|
1779
|
+
let pair2 = [NodeProp.lookAhead, lookAhead2];
|
|
1780
|
+
props = props ? [pair2].concat(props) : [pair2];
|
|
1781
|
+
}
|
|
1782
|
+
return new Tree(type, children2, positions2, length2, props);
|
|
1783
|
+
}
|
|
1784
|
+
function findBufferSize(maxSize, inRepeat) {
|
|
1785
|
+
let fork = cursor.fork();
|
|
1786
|
+
let size = 0, start = 0, skip = 0, minStart = fork.end - maxBufferLength;
|
|
1787
|
+
let result = { size: 0, start: 0, skip: 0 };
|
|
1788
|
+
scan:
|
|
1789
|
+
for (let minPos = fork.pos - maxSize; fork.pos > minPos; ) {
|
|
1790
|
+
let nodeSize2 = fork.size;
|
|
1791
|
+
if (fork.id == inRepeat && nodeSize2 >= 0) {
|
|
1792
|
+
result.size = size;
|
|
1793
|
+
result.start = start;
|
|
1794
|
+
result.skip = skip;
|
|
1795
|
+
skip += 4;
|
|
1796
|
+
size += 4;
|
|
1797
|
+
fork.next();
|
|
1798
|
+
continue;
|
|
1799
|
+
}
|
|
1800
|
+
let startPos = fork.pos - nodeSize2;
|
|
1801
|
+
if (nodeSize2 < 0 || startPos < minPos || fork.start < minStart)
|
|
1802
|
+
break;
|
|
1803
|
+
let localSkipped = fork.id >= minRepeatType ? 4 : 0;
|
|
1804
|
+
let nodeStart = fork.start;
|
|
1805
|
+
fork.next();
|
|
1806
|
+
while (fork.pos > startPos) {
|
|
1807
|
+
if (fork.size < 0) {
|
|
1808
|
+
if (fork.size == -3)
|
|
1809
|
+
localSkipped += 4;
|
|
1810
|
+
else
|
|
1811
|
+
break scan;
|
|
1812
|
+
} else if (fork.id >= minRepeatType) {
|
|
1813
|
+
localSkipped += 4;
|
|
1814
|
+
}
|
|
1815
|
+
fork.next();
|
|
1816
|
+
}
|
|
1817
|
+
start = nodeStart;
|
|
1818
|
+
size += nodeSize2;
|
|
1819
|
+
skip += localSkipped;
|
|
1820
|
+
}
|
|
1821
|
+
if (inRepeat < 0 || size == maxSize) {
|
|
1822
|
+
result.size = size;
|
|
1823
|
+
result.start = start;
|
|
1824
|
+
result.skip = skip;
|
|
1825
|
+
}
|
|
1826
|
+
return result.size > 4 ? result : void 0;
|
|
1827
|
+
}
|
|
1828
|
+
function copyToBuffer(bufferStart, buffer2, index) {
|
|
1829
|
+
let { id, start, end, size } = cursor;
|
|
1830
|
+
cursor.next();
|
|
1831
|
+
if (size >= 0 && id < minRepeatType) {
|
|
1832
|
+
let startIndex = index;
|
|
1833
|
+
if (size > 4) {
|
|
1834
|
+
let endPos = cursor.pos - (size - 4);
|
|
1835
|
+
while (cursor.pos > endPos)
|
|
1836
|
+
index = copyToBuffer(bufferStart, buffer2, index);
|
|
1837
|
+
}
|
|
1838
|
+
buffer2[--index] = startIndex;
|
|
1839
|
+
buffer2[--index] = end - bufferStart;
|
|
1840
|
+
buffer2[--index] = start - bufferStart;
|
|
1841
|
+
buffer2[--index] = id;
|
|
1842
|
+
} else if (size == -3) {
|
|
1843
|
+
contextHash = id;
|
|
1844
|
+
} else if (size == -4) {
|
|
1845
|
+
lookAhead = id;
|
|
1846
|
+
}
|
|
1847
|
+
return index;
|
|
1848
|
+
}
|
|
1849
|
+
let children = [], positions = [];
|
|
1850
|
+
while (cursor.pos > 0)
|
|
1851
|
+
takeNode(data.start || 0, data.bufferStart || 0, children, positions, -1);
|
|
1852
|
+
let length = (_a = data.length) !== null && _a !== void 0 ? _a : children.length ? positions[0] + children[0].length : 0;
|
|
1853
|
+
return new Tree(types[data.topID], children.reverse(), positions.reverse(), length);
|
|
1854
|
+
}
|
|
1855
|
+
var nodeSizeCache = /* @__PURE__ */ new WeakMap();
|
|
1856
|
+
function nodeSize(balanceType, node) {
|
|
1857
|
+
if (!balanceType.isAnonymous || node instanceof TreeBuffer || node.type != balanceType)
|
|
1858
|
+
return 1;
|
|
1859
|
+
let size = nodeSizeCache.get(node);
|
|
1860
|
+
if (size == null) {
|
|
1861
|
+
size = 1;
|
|
1862
|
+
for (let child of node.children) {
|
|
1863
|
+
if (child.type != balanceType || !(child instanceof Tree)) {
|
|
1864
|
+
size = 1;
|
|
1865
|
+
break;
|
|
1866
|
+
}
|
|
1867
|
+
size += nodeSize(balanceType, child);
|
|
1868
|
+
}
|
|
1869
|
+
nodeSizeCache.set(node, size);
|
|
1870
|
+
}
|
|
1871
|
+
return size;
|
|
1872
|
+
}
|
|
1873
|
+
function balanceRange(balanceType, children, positions, from, to, start, length, mkTop, mkTree) {
|
|
1874
|
+
let total = 0;
|
|
1875
|
+
for (let i = from; i < to; i++)
|
|
1876
|
+
total += nodeSize(balanceType, children[i]);
|
|
1877
|
+
let maxChild = Math.ceil(
|
|
1878
|
+
total * 1.5 / 8
|
|
1879
|
+
/* Balance.BranchFactor */
|
|
1880
|
+
);
|
|
1881
|
+
let localChildren = [], localPositions = [];
|
|
1882
|
+
function divide(children2, positions2, from2, to2, offset) {
|
|
1883
|
+
for (let i = from2; i < to2; ) {
|
|
1884
|
+
let groupFrom = i, groupStart = positions2[i], groupSize = nodeSize(balanceType, children2[i]);
|
|
1885
|
+
i++;
|
|
1886
|
+
for (; i < to2; i++) {
|
|
1887
|
+
let nextSize = nodeSize(balanceType, children2[i]);
|
|
1888
|
+
if (groupSize + nextSize >= maxChild)
|
|
1889
|
+
break;
|
|
1890
|
+
groupSize += nextSize;
|
|
1891
|
+
}
|
|
1892
|
+
if (i == groupFrom + 1) {
|
|
1893
|
+
if (groupSize > maxChild) {
|
|
1894
|
+
let only = children2[groupFrom];
|
|
1895
|
+
divide(only.children, only.positions, 0, only.children.length, positions2[groupFrom] + offset);
|
|
1896
|
+
continue;
|
|
1897
|
+
}
|
|
1898
|
+
localChildren.push(children2[groupFrom]);
|
|
1899
|
+
} else {
|
|
1900
|
+
let length2 = positions2[i - 1] + children2[i - 1].length - groupStart;
|
|
1901
|
+
localChildren.push(balanceRange(balanceType, children2, positions2, groupFrom, i, groupStart, length2, null, mkTree));
|
|
1902
|
+
}
|
|
1903
|
+
localPositions.push(groupStart + offset - start);
|
|
1904
|
+
}
|
|
1905
|
+
}
|
|
1906
|
+
divide(children, positions, from, to, 0);
|
|
1907
|
+
return (mkTop || mkTree)(localChildren, localPositions, length);
|
|
1908
|
+
}
|
|
1909
|
+
var Parser = class {
|
|
1910
|
+
/// Start a parse, returning a [partial parse](#common.PartialParse)
|
|
1911
|
+
/// object. [`fragments`](#common.TreeFragment) can be passed in to
|
|
1912
|
+
/// make the parse incremental.
|
|
1913
|
+
///
|
|
1914
|
+
/// By default, the entire input is parsed. You can pass `ranges`,
|
|
1915
|
+
/// which should be a sorted array of non-empty, non-overlapping
|
|
1916
|
+
/// ranges, to parse only those ranges. The tree returned in that
|
|
1917
|
+
/// case will start at `ranges[0].from`.
|
|
1918
|
+
startParse(input, fragments, ranges) {
|
|
1919
|
+
if (typeof input == "string")
|
|
1920
|
+
input = new StringInput(input);
|
|
1921
|
+
ranges = !ranges ? [new Range(0, input.length)] : ranges.length ? ranges.map((r2) => new Range(r2.from, r2.to)) : [new Range(0, 0)];
|
|
1922
|
+
return this.createParse(input, fragments || [], ranges);
|
|
1923
|
+
}
|
|
1924
|
+
/// Run a full parse, returning the resulting tree.
|
|
1925
|
+
parse(input, fragments, ranges) {
|
|
1926
|
+
let parse = this.startParse(input, fragments, ranges);
|
|
1927
|
+
for (; ; ) {
|
|
1928
|
+
let done = parse.advance();
|
|
1929
|
+
if (done)
|
|
1930
|
+
return done;
|
|
1931
|
+
}
|
|
1932
|
+
}
|
|
1933
|
+
};
|
|
1934
|
+
var StringInput = class {
|
|
1935
|
+
constructor(string) {
|
|
1936
|
+
this.string = string;
|
|
1937
|
+
}
|
|
1938
|
+
get length() {
|
|
1939
|
+
return this.string.length;
|
|
1940
|
+
}
|
|
1941
|
+
chunk(from) {
|
|
1942
|
+
return this.string.slice(from);
|
|
1943
|
+
}
|
|
1944
|
+
get lineChunks() {
|
|
1945
|
+
return false;
|
|
1946
|
+
}
|
|
1947
|
+
read(from, to) {
|
|
1948
|
+
return this.string.slice(from, to);
|
|
1949
|
+
}
|
|
1950
|
+
};
|
|
1951
|
+
var stoppedInner = new NodeProp({ perNode: true });
|
|
1952
|
+
|
|
1953
|
+
// ../../node_modules/@lezer/lr/dist/index.js
|
|
1954
|
+
var Stack = class {
|
|
1955
|
+
/// @internal
|
|
1956
|
+
constructor(p, stack, state, reducePos, pos, score, buffer, bufferBase, curContext, lookAhead = 0, parent) {
|
|
1957
|
+
this.p = p;
|
|
1958
|
+
this.stack = stack;
|
|
1959
|
+
this.state = state;
|
|
1960
|
+
this.reducePos = reducePos;
|
|
1961
|
+
this.pos = pos;
|
|
1962
|
+
this.score = score;
|
|
1963
|
+
this.buffer = buffer;
|
|
1964
|
+
this.bufferBase = bufferBase;
|
|
1965
|
+
this.curContext = curContext;
|
|
1966
|
+
this.lookAhead = lookAhead;
|
|
1967
|
+
this.parent = parent;
|
|
1968
|
+
}
|
|
1969
|
+
/// @internal
|
|
1970
|
+
toString() {
|
|
1971
|
+
return `[${this.stack.filter((_, i) => i % 3 == 0).concat(this.state)}]@${this.pos}${this.score ? "!" + this.score : ""}`;
|
|
1972
|
+
}
|
|
1973
|
+
// Start an empty stack
|
|
1974
|
+
/// @internal
|
|
1975
|
+
static start(p, state, pos = 0) {
|
|
1976
|
+
let cx3 = p.parser.context;
|
|
1977
|
+
return new Stack(p, [], state, pos, pos, 0, [], 0, cx3 ? new StackContext(cx3, cx3.start) : null, 0, null);
|
|
1978
|
+
}
|
|
1979
|
+
/// The stack's current [context](#lr.ContextTracker) value, if
|
|
1980
|
+
/// any. Its type will depend on the context tracker's type
|
|
1981
|
+
/// parameter, or it will be `null` if there is no context
|
|
1982
|
+
/// tracker.
|
|
1983
|
+
get context() {
|
|
1984
|
+
return this.curContext ? this.curContext.context : null;
|
|
1985
|
+
}
|
|
1986
|
+
// Push a state onto the stack, tracking its start position as well
|
|
1987
|
+
// as the buffer base at that point.
|
|
1988
|
+
/// @internal
|
|
1989
|
+
pushState(state, start) {
|
|
1990
|
+
this.stack.push(this.state, start, this.bufferBase + this.buffer.length);
|
|
1991
|
+
this.state = state;
|
|
1992
|
+
}
|
|
1993
|
+
// Apply a reduce action
|
|
1994
|
+
/// @internal
|
|
1995
|
+
reduce(action) {
|
|
1996
|
+
var _a;
|
|
1997
|
+
let depth = action >> 19, type = action & 65535;
|
|
1998
|
+
let { parser: parser2 } = this.p;
|
|
1999
|
+
let dPrec = parser2.dynamicPrecedence(type);
|
|
2000
|
+
if (dPrec)
|
|
2001
|
+
this.score += dPrec;
|
|
2002
|
+
if (depth == 0) {
|
|
2003
|
+
this.pushState(parser2.getGoto(this.state, type, true), this.reducePos);
|
|
2004
|
+
if (type < parser2.minRepeatTerm)
|
|
2005
|
+
this.storeNode(type, this.reducePos, this.reducePos, 4, true);
|
|
2006
|
+
this.reduceContext(type, this.reducePos);
|
|
2007
|
+
return;
|
|
2008
|
+
}
|
|
2009
|
+
let base = this.stack.length - (depth - 1) * 3 - (action & 262144 ? 6 : 0);
|
|
2010
|
+
let start = base ? this.stack[base - 2] : this.p.ranges[0].from, size = this.reducePos - start;
|
|
2011
|
+
if (size >= 2e3 && !((_a = this.p.parser.nodeSet.types[type]) === null || _a === void 0 ? void 0 : _a.isAnonymous)) {
|
|
2012
|
+
if (start == this.p.lastBigReductionStart) {
|
|
2013
|
+
this.p.bigReductionCount++;
|
|
2014
|
+
this.p.lastBigReductionSize = size;
|
|
2015
|
+
} else if (this.p.lastBigReductionSize < size) {
|
|
2016
|
+
this.p.bigReductionCount = 1;
|
|
2017
|
+
this.p.lastBigReductionStart = start;
|
|
2018
|
+
this.p.lastBigReductionSize = size;
|
|
2019
|
+
}
|
|
2020
|
+
}
|
|
2021
|
+
let bufferBase = base ? this.stack[base - 1] : 0, count = this.bufferBase + this.buffer.length - bufferBase;
|
|
2022
|
+
if (type < parser2.minRepeatTerm || action & 131072) {
|
|
2023
|
+
let pos = parser2.stateFlag(
|
|
2024
|
+
this.state,
|
|
2025
|
+
1
|
|
2026
|
+
/* StateFlag.Skipped */
|
|
2027
|
+
) ? this.pos : this.reducePos;
|
|
2028
|
+
this.storeNode(type, start, pos, count + 4, true);
|
|
2029
|
+
}
|
|
2030
|
+
if (action & 262144) {
|
|
2031
|
+
this.state = this.stack[base];
|
|
2032
|
+
} else {
|
|
2033
|
+
let baseStateID = this.stack[base - 3];
|
|
2034
|
+
this.state = parser2.getGoto(baseStateID, type, true);
|
|
2035
|
+
}
|
|
2036
|
+
while (this.stack.length > base)
|
|
2037
|
+
this.stack.pop();
|
|
2038
|
+
this.reduceContext(type, start);
|
|
2039
|
+
}
|
|
2040
|
+
// Shift a value into the buffer
|
|
2041
|
+
/// @internal
|
|
2042
|
+
storeNode(term, start, end, size = 4, isReduce = false) {
|
|
2043
|
+
if (term == 0 && (!this.stack.length || this.stack[this.stack.length - 1] < this.buffer.length + this.bufferBase)) {
|
|
2044
|
+
let cur = this, top = this.buffer.length;
|
|
2045
|
+
if (top == 0 && cur.parent) {
|
|
2046
|
+
top = cur.bufferBase - cur.parent.bufferBase;
|
|
2047
|
+
cur = cur.parent;
|
|
2048
|
+
}
|
|
2049
|
+
if (top > 0 && cur.buffer[top - 4] == 0 && cur.buffer[top - 1] > -1) {
|
|
2050
|
+
if (start == end)
|
|
2051
|
+
return;
|
|
2052
|
+
if (cur.buffer[top - 2] >= start) {
|
|
2053
|
+
cur.buffer[top - 2] = end;
|
|
2054
|
+
return;
|
|
2055
|
+
}
|
|
2056
|
+
}
|
|
2057
|
+
}
|
|
2058
|
+
if (!isReduce || this.pos == end) {
|
|
2059
|
+
this.buffer.push(term, start, end, size);
|
|
2060
|
+
} else {
|
|
2061
|
+
let index = this.buffer.length;
|
|
2062
|
+
if (index > 0 && this.buffer[index - 4] != 0)
|
|
2063
|
+
while (index > 0 && this.buffer[index - 2] > end) {
|
|
2064
|
+
this.buffer[index] = this.buffer[index - 4];
|
|
2065
|
+
this.buffer[index + 1] = this.buffer[index - 3];
|
|
2066
|
+
this.buffer[index + 2] = this.buffer[index - 2];
|
|
2067
|
+
this.buffer[index + 3] = this.buffer[index - 1];
|
|
2068
|
+
index -= 4;
|
|
2069
|
+
if (size > 4)
|
|
2070
|
+
size -= 4;
|
|
2071
|
+
}
|
|
2072
|
+
this.buffer[index] = term;
|
|
2073
|
+
this.buffer[index + 1] = start;
|
|
2074
|
+
this.buffer[index + 2] = end;
|
|
2075
|
+
this.buffer[index + 3] = size;
|
|
2076
|
+
}
|
|
2077
|
+
}
|
|
2078
|
+
// Apply a shift action
|
|
2079
|
+
/// @internal
|
|
2080
|
+
shift(action, next, nextEnd) {
|
|
2081
|
+
let start = this.pos;
|
|
2082
|
+
if (action & 131072) {
|
|
2083
|
+
this.pushState(action & 65535, this.pos);
|
|
2084
|
+
} else if ((action & 262144) == 0) {
|
|
2085
|
+
let nextState = action, { parser: parser2 } = this.p;
|
|
2086
|
+
if (nextEnd > this.pos || next <= parser2.maxNode) {
|
|
2087
|
+
this.pos = nextEnd;
|
|
2088
|
+
if (!parser2.stateFlag(
|
|
2089
|
+
nextState,
|
|
2090
|
+
1
|
|
2091
|
+
/* StateFlag.Skipped */
|
|
2092
|
+
))
|
|
2093
|
+
this.reducePos = nextEnd;
|
|
2094
|
+
}
|
|
2095
|
+
this.pushState(nextState, start);
|
|
2096
|
+
this.shiftContext(next, start);
|
|
2097
|
+
if (next <= parser2.maxNode)
|
|
2098
|
+
this.buffer.push(next, start, nextEnd, 4);
|
|
2099
|
+
} else {
|
|
2100
|
+
this.pos = nextEnd;
|
|
2101
|
+
this.shiftContext(next, start);
|
|
2102
|
+
if (next <= this.p.parser.maxNode)
|
|
2103
|
+
this.buffer.push(next, start, nextEnd, 4);
|
|
2104
|
+
}
|
|
2105
|
+
}
|
|
2106
|
+
// Apply an action
|
|
2107
|
+
/// @internal
|
|
2108
|
+
apply(action, next, nextEnd) {
|
|
2109
|
+
if (action & 65536)
|
|
2110
|
+
this.reduce(action);
|
|
2111
|
+
else
|
|
2112
|
+
this.shift(action, next, nextEnd);
|
|
2113
|
+
}
|
|
2114
|
+
// Add a prebuilt (reused) node into the buffer.
|
|
2115
|
+
/// @internal
|
|
2116
|
+
useNode(value, next) {
|
|
2117
|
+
let index = this.p.reused.length - 1;
|
|
2118
|
+
if (index < 0 || this.p.reused[index] != value) {
|
|
2119
|
+
this.p.reused.push(value);
|
|
2120
|
+
index++;
|
|
2121
|
+
}
|
|
2122
|
+
let start = this.pos;
|
|
2123
|
+
this.reducePos = this.pos = start + value.length;
|
|
2124
|
+
this.pushState(next, start);
|
|
2125
|
+
this.buffer.push(
|
|
2126
|
+
index,
|
|
2127
|
+
start,
|
|
2128
|
+
this.reducePos,
|
|
2129
|
+
-1
|
|
2130
|
+
/* size == -1 means this is a reused value */
|
|
2131
|
+
);
|
|
2132
|
+
if (this.curContext)
|
|
2133
|
+
this.updateContext(this.curContext.tracker.reuse(this.curContext.context, value, this, this.p.stream.reset(this.pos - value.length)));
|
|
2134
|
+
}
|
|
2135
|
+
// Split the stack. Due to the buffer sharing and the fact
|
|
2136
|
+
// that `this.stack` tends to stay quite shallow, this isn't very
|
|
2137
|
+
// expensive.
|
|
2138
|
+
/// @internal
|
|
2139
|
+
split() {
|
|
2140
|
+
let parent = this;
|
|
2141
|
+
let off = parent.buffer.length;
|
|
2142
|
+
while (off > 0 && parent.buffer[off - 2] > parent.reducePos)
|
|
2143
|
+
off -= 4;
|
|
2144
|
+
let buffer = parent.buffer.slice(off), base = parent.bufferBase + off;
|
|
2145
|
+
while (parent && base == parent.bufferBase)
|
|
2146
|
+
parent = parent.parent;
|
|
2147
|
+
return new Stack(this.p, this.stack.slice(), this.state, this.reducePos, this.pos, this.score, buffer, base, this.curContext, this.lookAhead, parent);
|
|
2148
|
+
}
|
|
2149
|
+
// Try to recover from an error by 'deleting' (ignoring) one token.
|
|
2150
|
+
/// @internal
|
|
2151
|
+
recoverByDelete(next, nextEnd) {
|
|
2152
|
+
let isNode = next <= this.p.parser.maxNode;
|
|
2153
|
+
if (isNode)
|
|
2154
|
+
this.storeNode(next, this.pos, nextEnd, 4);
|
|
2155
|
+
this.storeNode(0, this.pos, nextEnd, isNode ? 8 : 4);
|
|
2156
|
+
this.pos = this.reducePos = nextEnd;
|
|
2157
|
+
this.score -= 190;
|
|
2158
|
+
}
|
|
2159
|
+
/// Check if the given term would be able to be shifted (optionally
|
|
2160
|
+
/// after some reductions) on this stack. This can be useful for
|
|
2161
|
+
/// external tokenizers that want to make sure they only provide a
|
|
2162
|
+
/// given token when it applies.
|
|
2163
|
+
canShift(term) {
|
|
2164
|
+
for (let sim = new SimulatedStack(this); ; ) {
|
|
2165
|
+
let action = this.p.parser.stateSlot(
|
|
2166
|
+
sim.state,
|
|
2167
|
+
4
|
|
2168
|
+
/* ParseState.DefaultReduce */
|
|
2169
|
+
) || this.p.parser.hasAction(sim.state, term);
|
|
2170
|
+
if (action == 0)
|
|
2171
|
+
return false;
|
|
2172
|
+
if ((action & 65536) == 0)
|
|
2173
|
+
return true;
|
|
2174
|
+
sim.reduce(action);
|
|
2175
|
+
}
|
|
2176
|
+
}
|
|
2177
|
+
// Apply up to Recover.MaxNext recovery actions that conceptually
|
|
2178
|
+
// inserts some missing token or rule.
|
|
2179
|
+
/// @internal
|
|
2180
|
+
recoverByInsert(next) {
|
|
2181
|
+
if (this.stack.length >= 300)
|
|
2182
|
+
return [];
|
|
2183
|
+
let nextStates = this.p.parser.nextStates(this.state);
|
|
2184
|
+
if (nextStates.length > 4 << 1 || this.stack.length >= 120) {
|
|
2185
|
+
let best = [];
|
|
2186
|
+
for (let i = 0, s; i < nextStates.length; i += 2) {
|
|
2187
|
+
if ((s = nextStates[i + 1]) != this.state && this.p.parser.hasAction(s, next))
|
|
2188
|
+
best.push(nextStates[i], s);
|
|
2189
|
+
}
|
|
2190
|
+
if (this.stack.length < 120)
|
|
2191
|
+
for (let i = 0; best.length < 4 << 1 && i < nextStates.length; i += 2) {
|
|
2192
|
+
let s = nextStates[i + 1];
|
|
2193
|
+
if (!best.some((v, i2) => i2 & 1 && v == s))
|
|
2194
|
+
best.push(nextStates[i], s);
|
|
2195
|
+
}
|
|
2196
|
+
nextStates = best;
|
|
2197
|
+
}
|
|
2198
|
+
let result = [];
|
|
2199
|
+
for (let i = 0; i < nextStates.length && result.length < 4; i += 2) {
|
|
2200
|
+
let s = nextStates[i + 1];
|
|
2201
|
+
if (s == this.state)
|
|
2202
|
+
continue;
|
|
2203
|
+
let stack = this.split();
|
|
2204
|
+
stack.pushState(s, this.pos);
|
|
2205
|
+
stack.storeNode(0, stack.pos, stack.pos, 4, true);
|
|
2206
|
+
stack.shiftContext(nextStates[i], this.pos);
|
|
2207
|
+
stack.score -= 200;
|
|
2208
|
+
result.push(stack);
|
|
2209
|
+
}
|
|
2210
|
+
return result;
|
|
2211
|
+
}
|
|
2212
|
+
// Force a reduce, if possible. Return false if that can't
|
|
2213
|
+
// be done.
|
|
2214
|
+
/// @internal
|
|
2215
|
+
forceReduce() {
|
|
2216
|
+
let reduce = this.p.parser.stateSlot(
|
|
2217
|
+
this.state,
|
|
2218
|
+
5
|
|
2219
|
+
/* ParseState.ForcedReduce */
|
|
2220
|
+
);
|
|
2221
|
+
if ((reduce & 65536) == 0)
|
|
2222
|
+
return false;
|
|
2223
|
+
let { parser: parser2 } = this.p;
|
|
2224
|
+
if (!parser2.validAction(this.state, reduce)) {
|
|
2225
|
+
let depth = reduce >> 19, term = reduce & 65535;
|
|
2226
|
+
let target = this.stack.length - depth * 3;
|
|
2227
|
+
if (target < 0 || parser2.getGoto(this.stack[target], term, false) < 0)
|
|
2228
|
+
return false;
|
|
2229
|
+
this.storeNode(0, this.reducePos, this.reducePos, 4, true);
|
|
2230
|
+
this.score -= 100;
|
|
2231
|
+
}
|
|
2232
|
+
this.reducePos = this.pos;
|
|
2233
|
+
this.reduce(reduce);
|
|
2234
|
+
return true;
|
|
2235
|
+
}
|
|
2236
|
+
/// @internal
|
|
2237
|
+
forceAll() {
|
|
2238
|
+
while (!this.p.parser.stateFlag(
|
|
2239
|
+
this.state,
|
|
2240
|
+
2
|
|
2241
|
+
/* StateFlag.Accepting */
|
|
2242
|
+
)) {
|
|
2243
|
+
if (!this.forceReduce()) {
|
|
2244
|
+
this.storeNode(0, this.pos, this.pos, 4, true);
|
|
2245
|
+
break;
|
|
2246
|
+
}
|
|
2247
|
+
}
|
|
2248
|
+
return this;
|
|
2249
|
+
}
|
|
2250
|
+
/// Check whether this state has no further actions (assumed to be a direct descendant of the
|
|
2251
|
+
/// top state, since any other states must be able to continue
|
|
2252
|
+
/// somehow). @internal
|
|
2253
|
+
get deadEnd() {
|
|
2254
|
+
if (this.stack.length != 3)
|
|
2255
|
+
return false;
|
|
2256
|
+
let { parser: parser2 } = this.p;
|
|
2257
|
+
return parser2.data[parser2.stateSlot(
|
|
2258
|
+
this.state,
|
|
2259
|
+
1
|
|
2260
|
+
/* ParseState.Actions */
|
|
2261
|
+
)] == 65535 && !parser2.stateSlot(
|
|
2262
|
+
this.state,
|
|
2263
|
+
4
|
|
2264
|
+
/* ParseState.DefaultReduce */
|
|
2265
|
+
);
|
|
2266
|
+
}
|
|
2267
|
+
/// Restart the stack (put it back in its start state). Only safe
|
|
2268
|
+
/// when this.stack.length == 3 (state is directly below the top
|
|
2269
|
+
/// state). @internal
|
|
2270
|
+
restart() {
|
|
2271
|
+
this.state = this.stack[0];
|
|
2272
|
+
this.stack.length = 0;
|
|
2273
|
+
}
|
|
2274
|
+
/// @internal
|
|
2275
|
+
sameState(other) {
|
|
2276
|
+
if (this.state != other.state || this.stack.length != other.stack.length)
|
|
2277
|
+
return false;
|
|
2278
|
+
for (let i = 0; i < this.stack.length; i += 3)
|
|
2279
|
+
if (this.stack[i] != other.stack[i])
|
|
2280
|
+
return false;
|
|
2281
|
+
return true;
|
|
2282
|
+
}
|
|
2283
|
+
/// Get the parser used by this stack.
|
|
2284
|
+
get parser() {
|
|
2285
|
+
return this.p.parser;
|
|
2286
|
+
}
|
|
2287
|
+
/// Test whether a given dialect (by numeric ID, as exported from
|
|
2288
|
+
/// the terms file) is enabled.
|
|
2289
|
+
dialectEnabled(dialectID) {
|
|
2290
|
+
return this.p.parser.dialect.flags[dialectID];
|
|
2291
|
+
}
|
|
2292
|
+
shiftContext(term, start) {
|
|
2293
|
+
if (this.curContext)
|
|
2294
|
+
this.updateContext(this.curContext.tracker.shift(this.curContext.context, term, this, this.p.stream.reset(start)));
|
|
2295
|
+
}
|
|
2296
|
+
reduceContext(term, start) {
|
|
2297
|
+
if (this.curContext)
|
|
2298
|
+
this.updateContext(this.curContext.tracker.reduce(this.curContext.context, term, this, this.p.stream.reset(start)));
|
|
2299
|
+
}
|
|
2300
|
+
/// @internal
|
|
2301
|
+
emitContext() {
|
|
2302
|
+
let last = this.buffer.length - 1;
|
|
2303
|
+
if (last < 0 || this.buffer[last] != -3)
|
|
2304
|
+
this.buffer.push(this.curContext.hash, this.reducePos, this.reducePos, -3);
|
|
2305
|
+
}
|
|
2306
|
+
/// @internal
|
|
2307
|
+
emitLookAhead() {
|
|
2308
|
+
let last = this.buffer.length - 1;
|
|
2309
|
+
if (last < 0 || this.buffer[last] != -4)
|
|
2310
|
+
this.buffer.push(this.lookAhead, this.reducePos, this.reducePos, -4);
|
|
2311
|
+
}
|
|
2312
|
+
updateContext(context) {
|
|
2313
|
+
if (context != this.curContext.context) {
|
|
2314
|
+
let newCx = new StackContext(this.curContext.tracker, context);
|
|
2315
|
+
if (newCx.hash != this.curContext.hash)
|
|
2316
|
+
this.emitContext();
|
|
2317
|
+
this.curContext = newCx;
|
|
2318
|
+
}
|
|
2319
|
+
}
|
|
2320
|
+
/// @internal
|
|
2321
|
+
setLookAhead(lookAhead) {
|
|
2322
|
+
if (lookAhead > this.lookAhead) {
|
|
2323
|
+
this.emitLookAhead();
|
|
2324
|
+
this.lookAhead = lookAhead;
|
|
2325
|
+
}
|
|
2326
|
+
}
|
|
2327
|
+
/// @internal
|
|
2328
|
+
close() {
|
|
2329
|
+
if (this.curContext && this.curContext.tracker.strict)
|
|
2330
|
+
this.emitContext();
|
|
2331
|
+
if (this.lookAhead > 0)
|
|
2332
|
+
this.emitLookAhead();
|
|
2333
|
+
}
|
|
2334
|
+
};
|
|
2335
|
+
var StackContext = class {
|
|
2336
|
+
constructor(tracker, context) {
|
|
2337
|
+
this.tracker = tracker;
|
|
2338
|
+
this.context = context;
|
|
2339
|
+
this.hash = tracker.strict ? tracker.hash(context) : 0;
|
|
2340
|
+
}
|
|
2341
|
+
};
|
|
2342
|
+
var Recover;
|
|
2343
|
+
(function(Recover2) {
|
|
2344
|
+
Recover2[Recover2["Insert"] = 200] = "Insert";
|
|
2345
|
+
Recover2[Recover2["Delete"] = 190] = "Delete";
|
|
2346
|
+
Recover2[Recover2["Reduce"] = 100] = "Reduce";
|
|
2347
|
+
Recover2[Recover2["MaxNext"] = 4] = "MaxNext";
|
|
2348
|
+
Recover2[Recover2["MaxInsertStackDepth"] = 300] = "MaxInsertStackDepth";
|
|
2349
|
+
Recover2[Recover2["DampenInsertStackDepth"] = 120] = "DampenInsertStackDepth";
|
|
2350
|
+
Recover2[Recover2["MinBigReduction"] = 2e3] = "MinBigReduction";
|
|
2351
|
+
})(Recover || (Recover = {}));
|
|
2352
|
+
var SimulatedStack = class {
|
|
2353
|
+
constructor(start) {
|
|
2354
|
+
this.start = start;
|
|
2355
|
+
this.state = start.state;
|
|
2356
|
+
this.stack = start.stack;
|
|
2357
|
+
this.base = this.stack.length;
|
|
2358
|
+
}
|
|
2359
|
+
reduce(action) {
|
|
2360
|
+
let term = action & 65535, depth = action >> 19;
|
|
2361
|
+
if (depth == 0) {
|
|
2362
|
+
if (this.stack == this.start.stack)
|
|
2363
|
+
this.stack = this.stack.slice();
|
|
2364
|
+
this.stack.push(this.state, 0, 0);
|
|
2365
|
+
this.base += 3;
|
|
2366
|
+
} else {
|
|
2367
|
+
this.base -= (depth - 1) * 3;
|
|
2368
|
+
}
|
|
2369
|
+
let goto = this.start.p.parser.getGoto(this.stack[this.base - 3], term, true);
|
|
2370
|
+
this.state = goto;
|
|
2371
|
+
}
|
|
2372
|
+
};
|
|
2373
|
+
var StackBufferCursor = class {
|
|
2374
|
+
constructor(stack, pos, index) {
|
|
2375
|
+
this.stack = stack;
|
|
2376
|
+
this.pos = pos;
|
|
2377
|
+
this.index = index;
|
|
2378
|
+
this.buffer = stack.buffer;
|
|
2379
|
+
if (this.index == 0)
|
|
2380
|
+
this.maybeNext();
|
|
2381
|
+
}
|
|
2382
|
+
static create(stack, pos = stack.bufferBase + stack.buffer.length) {
|
|
2383
|
+
return new StackBufferCursor(stack, pos, pos - stack.bufferBase);
|
|
2384
|
+
}
|
|
2385
|
+
maybeNext() {
|
|
2386
|
+
let next = this.stack.parent;
|
|
2387
|
+
if (next != null) {
|
|
2388
|
+
this.index = this.stack.bufferBase - next.bufferBase;
|
|
2389
|
+
this.stack = next;
|
|
2390
|
+
this.buffer = next.buffer;
|
|
2391
|
+
}
|
|
2392
|
+
}
|
|
2393
|
+
get id() {
|
|
2394
|
+
return this.buffer[this.index - 4];
|
|
2395
|
+
}
|
|
2396
|
+
get start() {
|
|
2397
|
+
return this.buffer[this.index - 3];
|
|
2398
|
+
}
|
|
2399
|
+
get end() {
|
|
2400
|
+
return this.buffer[this.index - 2];
|
|
2401
|
+
}
|
|
2402
|
+
get size() {
|
|
2403
|
+
return this.buffer[this.index - 1];
|
|
2404
|
+
}
|
|
2405
|
+
next() {
|
|
2406
|
+
this.index -= 4;
|
|
2407
|
+
this.pos -= 4;
|
|
2408
|
+
if (this.index == 0)
|
|
2409
|
+
this.maybeNext();
|
|
2410
|
+
}
|
|
2411
|
+
fork() {
|
|
2412
|
+
return new StackBufferCursor(this.stack, this.pos, this.index);
|
|
2413
|
+
}
|
|
2414
|
+
};
|
|
2415
|
+
function decodeArray(input, Type = Uint16Array) {
|
|
2416
|
+
if (typeof input != "string")
|
|
2417
|
+
return input;
|
|
2418
|
+
let array = null;
|
|
2419
|
+
for (let pos = 0, out = 0; pos < input.length; ) {
|
|
2420
|
+
let value = 0;
|
|
2421
|
+
for (; ; ) {
|
|
2422
|
+
let next = input.charCodeAt(pos++), stop = false;
|
|
2423
|
+
if (next == 126) {
|
|
2424
|
+
value = 65535;
|
|
2425
|
+
break;
|
|
2426
|
+
}
|
|
2427
|
+
if (next >= 92)
|
|
2428
|
+
next--;
|
|
2429
|
+
if (next >= 34)
|
|
2430
|
+
next--;
|
|
2431
|
+
let digit = next - 32;
|
|
2432
|
+
if (digit >= 46) {
|
|
2433
|
+
digit -= 46;
|
|
2434
|
+
stop = true;
|
|
2435
|
+
}
|
|
2436
|
+
value += digit;
|
|
2437
|
+
if (stop)
|
|
2438
|
+
break;
|
|
2439
|
+
value *= 46;
|
|
2440
|
+
}
|
|
2441
|
+
if (array)
|
|
2442
|
+
array[out++] = value;
|
|
2443
|
+
else
|
|
2444
|
+
array = new Type(value);
|
|
2445
|
+
}
|
|
2446
|
+
return array;
|
|
2447
|
+
}
|
|
2448
|
+
var CachedToken = class {
|
|
2449
|
+
constructor() {
|
|
2450
|
+
this.start = -1;
|
|
2451
|
+
this.value = -1;
|
|
2452
|
+
this.end = -1;
|
|
2453
|
+
this.extended = -1;
|
|
2454
|
+
this.lookAhead = 0;
|
|
2455
|
+
this.mask = 0;
|
|
2456
|
+
this.context = 0;
|
|
2457
|
+
}
|
|
2458
|
+
};
|
|
2459
|
+
var nullToken = new CachedToken();
|
|
2460
|
+
var InputStream = class {
|
|
2461
|
+
/// @internal
|
|
2462
|
+
constructor(input, ranges) {
|
|
2463
|
+
this.input = input;
|
|
2464
|
+
this.ranges = ranges;
|
|
2465
|
+
this.chunk = "";
|
|
2466
|
+
this.chunkOff = 0;
|
|
2467
|
+
this.chunk2 = "";
|
|
2468
|
+
this.chunk2Pos = 0;
|
|
2469
|
+
this.next = -1;
|
|
2470
|
+
this.token = nullToken;
|
|
2471
|
+
this.rangeIndex = 0;
|
|
2472
|
+
this.pos = this.chunkPos = ranges[0].from;
|
|
2473
|
+
this.range = ranges[0];
|
|
2474
|
+
this.end = ranges[ranges.length - 1].to;
|
|
2475
|
+
this.readNext();
|
|
2476
|
+
}
|
|
2477
|
+
/// @internal
|
|
2478
|
+
resolveOffset(offset, assoc) {
|
|
2479
|
+
let range = this.range, index = this.rangeIndex;
|
|
2480
|
+
let pos = this.pos + offset;
|
|
2481
|
+
while (pos < range.from) {
|
|
2482
|
+
if (!index)
|
|
2483
|
+
return null;
|
|
2484
|
+
let next = this.ranges[--index];
|
|
2485
|
+
pos -= range.from - next.to;
|
|
2486
|
+
range = next;
|
|
2487
|
+
}
|
|
2488
|
+
while (assoc < 0 ? pos > range.to : pos >= range.to) {
|
|
2489
|
+
if (index == this.ranges.length - 1)
|
|
2490
|
+
return null;
|
|
2491
|
+
let next = this.ranges[++index];
|
|
2492
|
+
pos += next.from - range.to;
|
|
2493
|
+
range = next;
|
|
2494
|
+
}
|
|
2495
|
+
return pos;
|
|
2496
|
+
}
|
|
2497
|
+
/// @internal
|
|
2498
|
+
clipPos(pos) {
|
|
2499
|
+
if (pos >= this.range.from && pos < this.range.to)
|
|
2500
|
+
return pos;
|
|
2501
|
+
for (let range of this.ranges)
|
|
2502
|
+
if (range.to > pos)
|
|
2503
|
+
return Math.max(pos, range.from);
|
|
2504
|
+
return this.end;
|
|
2505
|
+
}
|
|
2506
|
+
/// Look at a code unit near the stream position. `.peek(0)` equals
|
|
2507
|
+
/// `.next`, `.peek(-1)` gives you the previous character, and so
|
|
2508
|
+
/// on.
|
|
2509
|
+
///
|
|
2510
|
+
/// Note that looking around during tokenizing creates dependencies
|
|
2511
|
+
/// on potentially far-away content, which may reduce the
|
|
2512
|
+
/// effectiveness incremental parsing—when looking forward—or even
|
|
2513
|
+
/// cause invalid reparses when looking backward more than 25 code
|
|
2514
|
+
/// units, since the library does not track lookbehind.
|
|
2515
|
+
peek(offset) {
|
|
2516
|
+
let idx = this.chunkOff + offset, pos, result;
|
|
2517
|
+
if (idx >= 0 && idx < this.chunk.length) {
|
|
2518
|
+
pos = this.pos + offset;
|
|
2519
|
+
result = this.chunk.charCodeAt(idx);
|
|
2520
|
+
} else {
|
|
2521
|
+
let resolved = this.resolveOffset(offset, 1);
|
|
2522
|
+
if (resolved == null)
|
|
2523
|
+
return -1;
|
|
2524
|
+
pos = resolved;
|
|
2525
|
+
if (pos >= this.chunk2Pos && pos < this.chunk2Pos + this.chunk2.length) {
|
|
2526
|
+
result = this.chunk2.charCodeAt(pos - this.chunk2Pos);
|
|
2527
|
+
} else {
|
|
2528
|
+
let i = this.rangeIndex, range = this.range;
|
|
2529
|
+
while (range.to <= pos)
|
|
2530
|
+
range = this.ranges[++i];
|
|
2531
|
+
this.chunk2 = this.input.chunk(this.chunk2Pos = pos);
|
|
2532
|
+
if (pos + this.chunk2.length > range.to)
|
|
2533
|
+
this.chunk2 = this.chunk2.slice(0, range.to - pos);
|
|
2534
|
+
result = this.chunk2.charCodeAt(0);
|
|
2535
|
+
}
|
|
2536
|
+
}
|
|
2537
|
+
if (pos >= this.token.lookAhead)
|
|
2538
|
+
this.token.lookAhead = pos + 1;
|
|
2539
|
+
return result;
|
|
2540
|
+
}
|
|
2541
|
+
/// Accept a token. By default, the end of the token is set to the
|
|
2542
|
+
/// current stream position, but you can pass an offset (relative to
|
|
2543
|
+
/// the stream position) to change that.
|
|
2544
|
+
acceptToken(token, endOffset = 0) {
|
|
2545
|
+
let end = endOffset ? this.resolveOffset(endOffset, -1) : this.pos;
|
|
2546
|
+
if (end == null || end < this.token.start)
|
|
2547
|
+
throw new RangeError("Token end out of bounds");
|
|
2548
|
+
this.token.value = token;
|
|
2549
|
+
this.token.end = end;
|
|
2550
|
+
}
|
|
2551
|
+
getChunk() {
|
|
2552
|
+
if (this.pos >= this.chunk2Pos && this.pos < this.chunk2Pos + this.chunk2.length) {
|
|
2553
|
+
let { chunk, chunkPos } = this;
|
|
2554
|
+
this.chunk = this.chunk2;
|
|
2555
|
+
this.chunkPos = this.chunk2Pos;
|
|
2556
|
+
this.chunk2 = chunk;
|
|
2557
|
+
this.chunk2Pos = chunkPos;
|
|
2558
|
+
this.chunkOff = this.pos - this.chunkPos;
|
|
2559
|
+
} else {
|
|
2560
|
+
this.chunk2 = this.chunk;
|
|
2561
|
+
this.chunk2Pos = this.chunkPos;
|
|
2562
|
+
let nextChunk = this.input.chunk(this.pos);
|
|
2563
|
+
let end = this.pos + nextChunk.length;
|
|
2564
|
+
this.chunk = end > this.range.to ? nextChunk.slice(0, this.range.to - this.pos) : nextChunk;
|
|
2565
|
+
this.chunkPos = this.pos;
|
|
2566
|
+
this.chunkOff = 0;
|
|
2567
|
+
}
|
|
2568
|
+
}
|
|
2569
|
+
readNext() {
|
|
2570
|
+
if (this.chunkOff >= this.chunk.length) {
|
|
2571
|
+
this.getChunk();
|
|
2572
|
+
if (this.chunkOff == this.chunk.length)
|
|
2573
|
+
return this.next = -1;
|
|
2574
|
+
}
|
|
2575
|
+
return this.next = this.chunk.charCodeAt(this.chunkOff);
|
|
2576
|
+
}
|
|
2577
|
+
/// Move the stream forward N (defaults to 1) code units. Returns
|
|
2578
|
+
/// the new value of [`next`](#lr.InputStream.next).
|
|
2579
|
+
advance(n = 1) {
|
|
2580
|
+
this.chunkOff += n;
|
|
2581
|
+
while (this.pos + n >= this.range.to) {
|
|
2582
|
+
if (this.rangeIndex == this.ranges.length - 1)
|
|
2583
|
+
return this.setDone();
|
|
2584
|
+
n -= this.range.to - this.pos;
|
|
2585
|
+
this.range = this.ranges[++this.rangeIndex];
|
|
2586
|
+
this.pos = this.range.from;
|
|
2587
|
+
}
|
|
2588
|
+
this.pos += n;
|
|
2589
|
+
if (this.pos >= this.token.lookAhead)
|
|
2590
|
+
this.token.lookAhead = this.pos + 1;
|
|
2591
|
+
return this.readNext();
|
|
2592
|
+
}
|
|
2593
|
+
setDone() {
|
|
2594
|
+
this.pos = this.chunkPos = this.end;
|
|
2595
|
+
this.range = this.ranges[this.rangeIndex = this.ranges.length - 1];
|
|
2596
|
+
this.chunk = "";
|
|
2597
|
+
return this.next = -1;
|
|
2598
|
+
}
|
|
2599
|
+
/// @internal
|
|
2600
|
+
reset(pos, token) {
|
|
2601
|
+
if (token) {
|
|
2602
|
+
this.token = token;
|
|
2603
|
+
token.start = pos;
|
|
2604
|
+
token.lookAhead = pos + 1;
|
|
2605
|
+
token.value = token.extended = -1;
|
|
2606
|
+
} else {
|
|
2607
|
+
this.token = nullToken;
|
|
2608
|
+
}
|
|
2609
|
+
if (this.pos != pos) {
|
|
2610
|
+
this.pos = pos;
|
|
2611
|
+
if (pos == this.end) {
|
|
2612
|
+
this.setDone();
|
|
2613
|
+
return this;
|
|
2614
|
+
}
|
|
2615
|
+
while (pos < this.range.from)
|
|
2616
|
+
this.range = this.ranges[--this.rangeIndex];
|
|
2617
|
+
while (pos >= this.range.to)
|
|
2618
|
+
this.range = this.ranges[++this.rangeIndex];
|
|
2619
|
+
if (pos >= this.chunkPos && pos < this.chunkPos + this.chunk.length) {
|
|
2620
|
+
this.chunkOff = pos - this.chunkPos;
|
|
2621
|
+
} else {
|
|
2622
|
+
this.chunk = "";
|
|
2623
|
+
this.chunkOff = 0;
|
|
2624
|
+
}
|
|
2625
|
+
this.readNext();
|
|
2626
|
+
}
|
|
2627
|
+
return this;
|
|
2628
|
+
}
|
|
2629
|
+
/// @internal
|
|
2630
|
+
read(from, to) {
|
|
2631
|
+
if (from >= this.chunkPos && to <= this.chunkPos + this.chunk.length)
|
|
2632
|
+
return this.chunk.slice(from - this.chunkPos, to - this.chunkPos);
|
|
2633
|
+
if (from >= this.chunk2Pos && to <= this.chunk2Pos + this.chunk2.length)
|
|
2634
|
+
return this.chunk2.slice(from - this.chunk2Pos, to - this.chunk2Pos);
|
|
2635
|
+
if (from >= this.range.from && to <= this.range.to)
|
|
2636
|
+
return this.input.read(from, to);
|
|
2637
|
+
let result = "";
|
|
2638
|
+
for (let r2 of this.ranges) {
|
|
2639
|
+
if (r2.from >= to)
|
|
2640
|
+
break;
|
|
2641
|
+
if (r2.to > from)
|
|
2642
|
+
result += this.input.read(Math.max(r2.from, from), Math.min(r2.to, to));
|
|
2643
|
+
}
|
|
2644
|
+
return result;
|
|
2645
|
+
}
|
|
2646
|
+
};
|
|
2647
|
+
var TokenGroup = class {
|
|
2648
|
+
constructor(data, id) {
|
|
2649
|
+
this.data = data;
|
|
2650
|
+
this.id = id;
|
|
2651
|
+
}
|
|
2652
|
+
token(input, stack) {
|
|
2653
|
+
let { parser: parser2 } = stack.p;
|
|
2654
|
+
readToken(this.data, input, stack, this.id, parser2.data, parser2.tokenPrecTable);
|
|
2655
|
+
}
|
|
2656
|
+
};
|
|
2657
|
+
TokenGroup.prototype.contextual = TokenGroup.prototype.fallback = TokenGroup.prototype.extend = false;
|
|
2658
|
+
var LocalTokenGroup = class {
|
|
2659
|
+
constructor(data, precTable, elseToken) {
|
|
2660
|
+
this.precTable = precTable;
|
|
2661
|
+
this.elseToken = elseToken;
|
|
2662
|
+
this.data = typeof data == "string" ? decodeArray(data) : data;
|
|
2663
|
+
}
|
|
2664
|
+
token(input, stack) {
|
|
2665
|
+
let start = input.pos, skipped = 0;
|
|
2666
|
+
for (; ; ) {
|
|
2667
|
+
readToken(this.data, input, stack, 0, this.data, this.precTable);
|
|
2668
|
+
if (input.token.value > -1)
|
|
2669
|
+
break;
|
|
2670
|
+
if (this.elseToken == null)
|
|
2671
|
+
return;
|
|
2672
|
+
if (input.next < 0)
|
|
2673
|
+
break;
|
|
2674
|
+
input.advance();
|
|
2675
|
+
input.reset(input.pos, input.token);
|
|
2676
|
+
skipped++;
|
|
2677
|
+
}
|
|
2678
|
+
if (skipped) {
|
|
2679
|
+
input.reset(start, input.token);
|
|
2680
|
+
input.acceptToken(this.elseToken, skipped);
|
|
2681
|
+
}
|
|
2682
|
+
}
|
|
2683
|
+
};
|
|
2684
|
+
LocalTokenGroup.prototype.contextual = TokenGroup.prototype.fallback = TokenGroup.prototype.extend = false;
|
|
2685
|
+
function readToken(data, input, stack, group, precTable, precOffset) {
|
|
2686
|
+
let state = 0, groupMask = 1 << group, { dialect } = stack.p.parser;
|
|
2687
|
+
scan:
|
|
2688
|
+
for (; ; ) {
|
|
2689
|
+
if ((groupMask & data[state]) == 0)
|
|
2690
|
+
break;
|
|
2691
|
+
let accEnd = data[state + 1];
|
|
2692
|
+
for (let i = state + 3; i < accEnd; i += 2)
|
|
2693
|
+
if ((data[i + 1] & groupMask) > 0) {
|
|
2694
|
+
let term = data[i];
|
|
2695
|
+
if (dialect.allows(term) && (input.token.value == -1 || input.token.value == term || overrides(term, input.token.value, precTable, precOffset))) {
|
|
2696
|
+
input.acceptToken(term);
|
|
2697
|
+
break;
|
|
2698
|
+
}
|
|
2699
|
+
}
|
|
2700
|
+
let next = input.next, low = 0, high = data[state + 2];
|
|
2701
|
+
if (input.next < 0 && high > low && data[accEnd + high * 3 - 3] == 65535 && data[accEnd + high * 3 - 3] == 65535) {
|
|
2702
|
+
state = data[accEnd + high * 3 - 1];
|
|
2703
|
+
continue scan;
|
|
2704
|
+
}
|
|
2705
|
+
for (; low < high; ) {
|
|
2706
|
+
let mid = low + high >> 1;
|
|
2707
|
+
let index = accEnd + mid + (mid << 1);
|
|
2708
|
+
let from = data[index], to = data[index + 1] || 65536;
|
|
2709
|
+
if (next < from)
|
|
2710
|
+
high = mid;
|
|
2711
|
+
else if (next >= to)
|
|
2712
|
+
low = mid + 1;
|
|
2713
|
+
else {
|
|
2714
|
+
state = data[index + 2];
|
|
2715
|
+
input.advance();
|
|
2716
|
+
continue scan;
|
|
2717
|
+
}
|
|
2718
|
+
}
|
|
2719
|
+
break;
|
|
2720
|
+
}
|
|
2721
|
+
}
|
|
2722
|
+
function findOffset(data, start, term) {
|
|
2723
|
+
for (let i = start, next; (next = data[i]) != 65535; i++)
|
|
2724
|
+
if (next == term)
|
|
2725
|
+
return i - start;
|
|
2726
|
+
return -1;
|
|
2727
|
+
}
|
|
2728
|
+
function overrides(token, prev, tableData, tableOffset) {
|
|
2729
|
+
let iPrev = findOffset(tableData, tableOffset, prev);
|
|
2730
|
+
return iPrev < 0 || findOffset(tableData, tableOffset, token) < iPrev;
|
|
2731
|
+
}
|
|
2732
|
+
var verbose = typeof process != "undefined" && process.env && /\bparse\b/.test(process.env.LOG);
|
|
2733
|
+
var stackIDs = null;
|
|
2734
|
+
var Safety;
|
|
2735
|
+
(function(Safety2) {
|
|
2736
|
+
Safety2[Safety2["Margin"] = 25] = "Margin";
|
|
2737
|
+
})(Safety || (Safety = {}));
|
|
2738
|
+
function cutAt(tree, pos, side) {
|
|
2739
|
+
let cursor = tree.cursor(IterMode.IncludeAnonymous);
|
|
2740
|
+
cursor.moveTo(pos);
|
|
2741
|
+
for (; ; ) {
|
|
2742
|
+
if (!(side < 0 ? cursor.childBefore(pos) : cursor.childAfter(pos)))
|
|
2743
|
+
for (; ; ) {
|
|
2744
|
+
if ((side < 0 ? cursor.to < pos : cursor.from > pos) && !cursor.type.isError)
|
|
2745
|
+
return side < 0 ? Math.max(0, Math.min(
|
|
2746
|
+
cursor.to - 1,
|
|
2747
|
+
pos - 25
|
|
2748
|
+
/* Safety.Margin */
|
|
2749
|
+
)) : Math.min(tree.length, Math.max(
|
|
2750
|
+
cursor.from + 1,
|
|
2751
|
+
pos + 25
|
|
2752
|
+
/* Safety.Margin */
|
|
2753
|
+
));
|
|
2754
|
+
if (side < 0 ? cursor.prevSibling() : cursor.nextSibling())
|
|
2755
|
+
break;
|
|
2756
|
+
if (!cursor.parent())
|
|
2757
|
+
return side < 0 ? 0 : tree.length;
|
|
2758
|
+
}
|
|
2759
|
+
}
|
|
2760
|
+
}
|
|
2761
|
+
var FragmentCursor = class {
|
|
2762
|
+
constructor(fragments, nodeSet) {
|
|
2763
|
+
this.fragments = fragments;
|
|
2764
|
+
this.nodeSet = nodeSet;
|
|
2765
|
+
this.i = 0;
|
|
2766
|
+
this.fragment = null;
|
|
2767
|
+
this.safeFrom = -1;
|
|
2768
|
+
this.safeTo = -1;
|
|
2769
|
+
this.trees = [];
|
|
2770
|
+
this.start = [];
|
|
2771
|
+
this.index = [];
|
|
2772
|
+
this.nextFragment();
|
|
2773
|
+
}
|
|
2774
|
+
nextFragment() {
|
|
2775
|
+
let fr = this.fragment = this.i == this.fragments.length ? null : this.fragments[this.i++];
|
|
2776
|
+
if (fr) {
|
|
2777
|
+
this.safeFrom = fr.openStart ? cutAt(fr.tree, fr.from + fr.offset, 1) - fr.offset : fr.from;
|
|
2778
|
+
this.safeTo = fr.openEnd ? cutAt(fr.tree, fr.to + fr.offset, -1) - fr.offset : fr.to;
|
|
2779
|
+
while (this.trees.length) {
|
|
2780
|
+
this.trees.pop();
|
|
2781
|
+
this.start.pop();
|
|
2782
|
+
this.index.pop();
|
|
2783
|
+
}
|
|
2784
|
+
this.trees.push(fr.tree);
|
|
2785
|
+
this.start.push(-fr.offset);
|
|
2786
|
+
this.index.push(0);
|
|
2787
|
+
this.nextStart = this.safeFrom;
|
|
2788
|
+
} else {
|
|
2789
|
+
this.nextStart = 1e9;
|
|
2790
|
+
}
|
|
2791
|
+
}
|
|
2792
|
+
// `pos` must be >= any previously given `pos` for this cursor
|
|
2793
|
+
nodeAt(pos) {
|
|
2794
|
+
if (pos < this.nextStart)
|
|
2795
|
+
return null;
|
|
2796
|
+
while (this.fragment && this.safeTo <= pos)
|
|
2797
|
+
this.nextFragment();
|
|
2798
|
+
if (!this.fragment)
|
|
2799
|
+
return null;
|
|
2800
|
+
for (; ; ) {
|
|
2801
|
+
let last = this.trees.length - 1;
|
|
2802
|
+
if (last < 0) {
|
|
2803
|
+
this.nextFragment();
|
|
2804
|
+
return null;
|
|
2805
|
+
}
|
|
2806
|
+
let top = this.trees[last], index = this.index[last];
|
|
2807
|
+
if (index == top.children.length) {
|
|
2808
|
+
this.trees.pop();
|
|
2809
|
+
this.start.pop();
|
|
2810
|
+
this.index.pop();
|
|
2811
|
+
continue;
|
|
2812
|
+
}
|
|
2813
|
+
let next = top.children[index];
|
|
2814
|
+
let start = this.start[last] + top.positions[index];
|
|
2815
|
+
if (start > pos) {
|
|
2816
|
+
this.nextStart = start;
|
|
2817
|
+
return null;
|
|
2818
|
+
}
|
|
2819
|
+
if (next instanceof Tree) {
|
|
2820
|
+
if (start == pos) {
|
|
2821
|
+
if (start < this.safeFrom)
|
|
2822
|
+
return null;
|
|
2823
|
+
let end = start + next.length;
|
|
2824
|
+
if (end <= this.safeTo) {
|
|
2825
|
+
let lookAhead = next.prop(NodeProp.lookAhead);
|
|
2826
|
+
if (!lookAhead || end + lookAhead < this.fragment.to)
|
|
2827
|
+
return next;
|
|
2828
|
+
}
|
|
2829
|
+
}
|
|
2830
|
+
this.index[last]++;
|
|
2831
|
+
if (start + next.length >= Math.max(this.safeFrom, pos)) {
|
|
2832
|
+
this.trees.push(next);
|
|
2833
|
+
this.start.push(start);
|
|
2834
|
+
this.index.push(0);
|
|
2835
|
+
}
|
|
2836
|
+
} else {
|
|
2837
|
+
this.index[last]++;
|
|
2838
|
+
this.nextStart = start + next.length;
|
|
2839
|
+
}
|
|
2840
|
+
}
|
|
2841
|
+
}
|
|
2842
|
+
};
|
|
2843
|
+
var TokenCache = class {
|
|
2844
|
+
constructor(parser2, stream) {
|
|
2845
|
+
this.stream = stream;
|
|
2846
|
+
this.tokens = [];
|
|
2847
|
+
this.mainToken = null;
|
|
2848
|
+
this.actions = [];
|
|
2849
|
+
this.tokens = parser2.tokenizers.map((_) => new CachedToken());
|
|
2850
|
+
}
|
|
2851
|
+
getActions(stack) {
|
|
2852
|
+
let actionIndex = 0;
|
|
2853
|
+
let main = null;
|
|
2854
|
+
let { parser: parser2 } = stack.p, { tokenizers } = parser2;
|
|
2855
|
+
let mask = parser2.stateSlot(
|
|
2856
|
+
stack.state,
|
|
2857
|
+
3
|
|
2858
|
+
/* ParseState.TokenizerMask */
|
|
2859
|
+
);
|
|
2860
|
+
let context = stack.curContext ? stack.curContext.hash : 0;
|
|
2861
|
+
let lookAhead = 0;
|
|
2862
|
+
for (let i = 0; i < tokenizers.length; i++) {
|
|
2863
|
+
if ((1 << i & mask) == 0)
|
|
2864
|
+
continue;
|
|
2865
|
+
let tokenizer = tokenizers[i], token = this.tokens[i];
|
|
2866
|
+
if (main && !tokenizer.fallback)
|
|
2867
|
+
continue;
|
|
2868
|
+
if (tokenizer.contextual || token.start != stack.pos || token.mask != mask || token.context != context) {
|
|
2869
|
+
this.updateCachedToken(token, tokenizer, stack);
|
|
2870
|
+
token.mask = mask;
|
|
2871
|
+
token.context = context;
|
|
2872
|
+
}
|
|
2873
|
+
if (token.lookAhead > token.end + 25)
|
|
2874
|
+
lookAhead = Math.max(token.lookAhead, lookAhead);
|
|
2875
|
+
if (token.value != 0) {
|
|
2876
|
+
let startIndex = actionIndex;
|
|
2877
|
+
if (token.extended > -1)
|
|
2878
|
+
actionIndex = this.addActions(stack, token.extended, token.end, actionIndex);
|
|
2879
|
+
actionIndex = this.addActions(stack, token.value, token.end, actionIndex);
|
|
2880
|
+
if (!tokenizer.extend) {
|
|
2881
|
+
main = token;
|
|
2882
|
+
if (actionIndex > startIndex)
|
|
2883
|
+
break;
|
|
2884
|
+
}
|
|
2885
|
+
}
|
|
2886
|
+
}
|
|
2887
|
+
while (this.actions.length > actionIndex)
|
|
2888
|
+
this.actions.pop();
|
|
2889
|
+
if (lookAhead)
|
|
2890
|
+
stack.setLookAhead(lookAhead);
|
|
2891
|
+
if (!main && stack.pos == this.stream.end) {
|
|
2892
|
+
main = new CachedToken();
|
|
2893
|
+
main.value = stack.p.parser.eofTerm;
|
|
2894
|
+
main.start = main.end = stack.pos;
|
|
2895
|
+
actionIndex = this.addActions(stack, main.value, main.end, actionIndex);
|
|
2896
|
+
}
|
|
2897
|
+
this.mainToken = main;
|
|
2898
|
+
return this.actions;
|
|
2899
|
+
}
|
|
2900
|
+
getMainToken(stack) {
|
|
2901
|
+
if (this.mainToken)
|
|
2902
|
+
return this.mainToken;
|
|
2903
|
+
let main = new CachedToken(), { pos, p } = stack;
|
|
2904
|
+
main.start = pos;
|
|
2905
|
+
main.end = Math.min(pos + 1, p.stream.end);
|
|
2906
|
+
main.value = pos == p.stream.end ? p.parser.eofTerm : 0;
|
|
2907
|
+
return main;
|
|
2908
|
+
}
|
|
2909
|
+
updateCachedToken(token, tokenizer, stack) {
|
|
2910
|
+
let start = this.stream.clipPos(stack.pos);
|
|
2911
|
+
tokenizer.token(this.stream.reset(start, token), stack);
|
|
2912
|
+
if (token.value > -1) {
|
|
2913
|
+
let { parser: parser2 } = stack.p;
|
|
2914
|
+
for (let i = 0; i < parser2.specialized.length; i++)
|
|
2915
|
+
if (parser2.specialized[i] == token.value) {
|
|
2916
|
+
let result = parser2.specializers[i](this.stream.read(token.start, token.end), stack);
|
|
2917
|
+
if (result >= 0 && stack.p.parser.dialect.allows(result >> 1)) {
|
|
2918
|
+
if ((result & 1) == 0)
|
|
2919
|
+
token.value = result >> 1;
|
|
2920
|
+
else
|
|
2921
|
+
token.extended = result >> 1;
|
|
2922
|
+
break;
|
|
2923
|
+
}
|
|
2924
|
+
}
|
|
2925
|
+
} else {
|
|
2926
|
+
token.value = 0;
|
|
2927
|
+
token.end = this.stream.clipPos(start + 1);
|
|
2928
|
+
}
|
|
2929
|
+
}
|
|
2930
|
+
putAction(action, token, end, index) {
|
|
2931
|
+
for (let i = 0; i < index; i += 3)
|
|
2932
|
+
if (this.actions[i] == action)
|
|
2933
|
+
return index;
|
|
2934
|
+
this.actions[index++] = action;
|
|
2935
|
+
this.actions[index++] = token;
|
|
2936
|
+
this.actions[index++] = end;
|
|
2937
|
+
return index;
|
|
2938
|
+
}
|
|
2939
|
+
addActions(stack, token, end, index) {
|
|
2940
|
+
let { state } = stack, { parser: parser2 } = stack.p, { data } = parser2;
|
|
2941
|
+
for (let set = 0; set < 2; set++) {
|
|
2942
|
+
for (let i = parser2.stateSlot(
|
|
2943
|
+
state,
|
|
2944
|
+
set ? 2 : 1
|
|
2945
|
+
/* ParseState.Actions */
|
|
2946
|
+
); ; i += 3) {
|
|
2947
|
+
if (data[i] == 65535) {
|
|
2948
|
+
if (data[i + 1] == 1) {
|
|
2949
|
+
i = pair(data, i + 2);
|
|
2950
|
+
} else {
|
|
2951
|
+
if (index == 0 && data[i + 1] == 2)
|
|
2952
|
+
index = this.putAction(pair(data, i + 2), token, end, index);
|
|
2953
|
+
break;
|
|
2954
|
+
}
|
|
2955
|
+
}
|
|
2956
|
+
if (data[i] == token)
|
|
2957
|
+
index = this.putAction(pair(data, i + 1), token, end, index);
|
|
2958
|
+
}
|
|
2959
|
+
}
|
|
2960
|
+
return index;
|
|
2961
|
+
}
|
|
2962
|
+
};
|
|
2963
|
+
var Rec;
|
|
2964
|
+
(function(Rec2) {
|
|
2965
|
+
Rec2[Rec2["Distance"] = 5] = "Distance";
|
|
2966
|
+
Rec2[Rec2["MaxRemainingPerStep"] = 3] = "MaxRemainingPerStep";
|
|
2967
|
+
Rec2[Rec2["MinBufferLengthPrune"] = 500] = "MinBufferLengthPrune";
|
|
2968
|
+
Rec2[Rec2["ForceReduceLimit"] = 10] = "ForceReduceLimit";
|
|
2969
|
+
Rec2[Rec2["CutDepth"] = 15e3] = "CutDepth";
|
|
2970
|
+
Rec2[Rec2["CutTo"] = 9e3] = "CutTo";
|
|
2971
|
+
Rec2[Rec2["MaxLeftAssociativeReductionCount"] = 300] = "MaxLeftAssociativeReductionCount";
|
|
2972
|
+
Rec2[Rec2["MaxStackCount"] = 12] = "MaxStackCount";
|
|
2973
|
+
})(Rec || (Rec = {}));
|
|
2974
|
+
var Parse = class {
|
|
2975
|
+
constructor(parser2, input, fragments, ranges) {
|
|
2976
|
+
this.parser = parser2;
|
|
2977
|
+
this.input = input;
|
|
2978
|
+
this.ranges = ranges;
|
|
2979
|
+
this.recovering = 0;
|
|
2980
|
+
this.nextStackID = 9812;
|
|
2981
|
+
this.minStackPos = 0;
|
|
2982
|
+
this.reused = [];
|
|
2983
|
+
this.stoppedAt = null;
|
|
2984
|
+
this.lastBigReductionStart = -1;
|
|
2985
|
+
this.lastBigReductionSize = 0;
|
|
2986
|
+
this.bigReductionCount = 0;
|
|
2987
|
+
this.stream = new InputStream(input, ranges);
|
|
2988
|
+
this.tokens = new TokenCache(parser2, this.stream);
|
|
2989
|
+
this.topTerm = parser2.top[1];
|
|
2990
|
+
let { from } = ranges[0];
|
|
2991
|
+
this.stacks = [Stack.start(this, parser2.top[0], from)];
|
|
2992
|
+
this.fragments = fragments.length && this.stream.end - from > parser2.bufferLength * 4 ? new FragmentCursor(fragments, parser2.nodeSet) : null;
|
|
2993
|
+
}
|
|
2994
|
+
get parsedPos() {
|
|
2995
|
+
return this.minStackPos;
|
|
2996
|
+
}
|
|
2997
|
+
// Move the parser forward. This will process all parse stacks at
|
|
2998
|
+
// `this.pos` and try to advance them to a further position. If no
|
|
2999
|
+
// stack for such a position is found, it'll start error-recovery.
|
|
3000
|
+
//
|
|
3001
|
+
// When the parse is finished, this will return a syntax tree. When
|
|
3002
|
+
// not, it returns `null`.
|
|
3003
|
+
advance() {
|
|
3004
|
+
let stacks = this.stacks, pos = this.minStackPos;
|
|
3005
|
+
let newStacks = this.stacks = [];
|
|
3006
|
+
let stopped, stoppedTokens;
|
|
3007
|
+
if (this.bigReductionCount > 300 && stacks.length == 1) {
|
|
3008
|
+
let [s] = stacks;
|
|
3009
|
+
while (s.forceReduce() && s.stack.length && s.stack[s.stack.length - 2] >= this.lastBigReductionStart) {
|
|
3010
|
+
}
|
|
3011
|
+
this.bigReductionCount = this.lastBigReductionSize = 0;
|
|
3012
|
+
}
|
|
3013
|
+
for (let i = 0; i < stacks.length; i++) {
|
|
3014
|
+
let stack = stacks[i];
|
|
3015
|
+
for (; ; ) {
|
|
3016
|
+
this.tokens.mainToken = null;
|
|
3017
|
+
if (stack.pos > pos) {
|
|
3018
|
+
newStacks.push(stack);
|
|
3019
|
+
} else if (this.advanceStack(stack, newStacks, stacks)) {
|
|
3020
|
+
continue;
|
|
3021
|
+
} else {
|
|
3022
|
+
if (!stopped) {
|
|
3023
|
+
stopped = [];
|
|
3024
|
+
stoppedTokens = [];
|
|
3025
|
+
}
|
|
3026
|
+
stopped.push(stack);
|
|
3027
|
+
let tok = this.tokens.getMainToken(stack);
|
|
3028
|
+
stoppedTokens.push(tok.value, tok.end);
|
|
3029
|
+
}
|
|
3030
|
+
break;
|
|
3031
|
+
}
|
|
3032
|
+
}
|
|
3033
|
+
if (!newStacks.length) {
|
|
3034
|
+
let finished = stopped && findFinished(stopped);
|
|
3035
|
+
if (finished)
|
|
3036
|
+
return this.stackToTree(finished);
|
|
3037
|
+
if (this.parser.strict) {
|
|
3038
|
+
if (verbose && stopped)
|
|
3039
|
+
console.log("Stuck with token " + (this.tokens.mainToken ? this.parser.getName(this.tokens.mainToken.value) : "none"));
|
|
3040
|
+
throw new SyntaxError("No parse at " + pos);
|
|
3041
|
+
}
|
|
3042
|
+
if (!this.recovering)
|
|
3043
|
+
this.recovering = 5;
|
|
3044
|
+
}
|
|
3045
|
+
if (this.recovering && stopped) {
|
|
3046
|
+
let finished = this.stoppedAt != null && stopped[0].pos > this.stoppedAt ? stopped[0] : this.runRecovery(stopped, stoppedTokens, newStacks);
|
|
3047
|
+
if (finished)
|
|
3048
|
+
return this.stackToTree(finished.forceAll());
|
|
3049
|
+
}
|
|
3050
|
+
if (this.recovering) {
|
|
3051
|
+
let maxRemaining = this.recovering == 1 ? 1 : this.recovering * 3;
|
|
3052
|
+
if (newStacks.length > maxRemaining) {
|
|
3053
|
+
newStacks.sort((a, b) => b.score - a.score);
|
|
3054
|
+
while (newStacks.length > maxRemaining)
|
|
3055
|
+
newStacks.pop();
|
|
3056
|
+
}
|
|
3057
|
+
if (newStacks.some((s) => s.reducePos > pos))
|
|
3058
|
+
this.recovering--;
|
|
3059
|
+
} else if (newStacks.length > 1) {
|
|
3060
|
+
outer:
|
|
3061
|
+
for (let i = 0; i < newStacks.length - 1; i++) {
|
|
3062
|
+
let stack = newStacks[i];
|
|
3063
|
+
for (let j = i + 1; j < newStacks.length; j++) {
|
|
3064
|
+
let other = newStacks[j];
|
|
3065
|
+
if (stack.sameState(other) || stack.buffer.length > 500 && other.buffer.length > 500) {
|
|
3066
|
+
if ((stack.score - other.score || stack.buffer.length - other.buffer.length) > 0) {
|
|
3067
|
+
newStacks.splice(j--, 1);
|
|
3068
|
+
} else {
|
|
3069
|
+
newStacks.splice(i--, 1);
|
|
3070
|
+
continue outer;
|
|
3071
|
+
}
|
|
3072
|
+
}
|
|
3073
|
+
}
|
|
3074
|
+
}
|
|
3075
|
+
if (newStacks.length > 12)
|
|
3076
|
+
newStacks.splice(
|
|
3077
|
+
12,
|
|
3078
|
+
newStacks.length - 12
|
|
3079
|
+
/* Rec.MaxStackCount */
|
|
3080
|
+
);
|
|
3081
|
+
}
|
|
3082
|
+
this.minStackPos = newStacks[0].pos;
|
|
3083
|
+
for (let i = 1; i < newStacks.length; i++)
|
|
3084
|
+
if (newStacks[i].pos < this.minStackPos)
|
|
3085
|
+
this.minStackPos = newStacks[i].pos;
|
|
3086
|
+
return null;
|
|
3087
|
+
}
|
|
3088
|
+
stopAt(pos) {
|
|
3089
|
+
if (this.stoppedAt != null && this.stoppedAt < pos)
|
|
3090
|
+
throw new RangeError("Can't move stoppedAt forward");
|
|
3091
|
+
this.stoppedAt = pos;
|
|
3092
|
+
}
|
|
3093
|
+
// Returns an updated version of the given stack, or null if the
|
|
3094
|
+
// stack can't advance normally. When `split` and `stacks` are
|
|
3095
|
+
// given, stacks split off by ambiguous operations will be pushed to
|
|
3096
|
+
// `split`, or added to `stacks` if they move `pos` forward.
|
|
3097
|
+
advanceStack(stack, stacks, split) {
|
|
3098
|
+
let start = stack.pos, { parser: parser2 } = this;
|
|
3099
|
+
let base = verbose ? this.stackID(stack) + " -> " : "";
|
|
3100
|
+
if (this.stoppedAt != null && start > this.stoppedAt)
|
|
3101
|
+
return stack.forceReduce() ? stack : null;
|
|
3102
|
+
if (this.fragments) {
|
|
3103
|
+
let strictCx = stack.curContext && stack.curContext.tracker.strict, cxHash = strictCx ? stack.curContext.hash : 0;
|
|
3104
|
+
for (let cached = this.fragments.nodeAt(start); cached; ) {
|
|
3105
|
+
let match = this.parser.nodeSet.types[cached.type.id] == cached.type ? parser2.getGoto(stack.state, cached.type.id) : -1;
|
|
3106
|
+
if (match > -1 && cached.length && (!strictCx || (cached.prop(NodeProp.contextHash) || 0) == cxHash)) {
|
|
3107
|
+
stack.useNode(cached, match);
|
|
3108
|
+
if (verbose)
|
|
3109
|
+
console.log(base + this.stackID(stack) + ` (via reuse of ${parser2.getName(cached.type.id)})`);
|
|
3110
|
+
return true;
|
|
3111
|
+
}
|
|
3112
|
+
if (!(cached instanceof Tree) || cached.children.length == 0 || cached.positions[0] > 0)
|
|
3113
|
+
break;
|
|
3114
|
+
let inner = cached.children[0];
|
|
3115
|
+
if (inner instanceof Tree && cached.positions[0] == 0)
|
|
3116
|
+
cached = inner;
|
|
3117
|
+
else
|
|
3118
|
+
break;
|
|
3119
|
+
}
|
|
3120
|
+
}
|
|
3121
|
+
let defaultReduce = parser2.stateSlot(
|
|
3122
|
+
stack.state,
|
|
3123
|
+
4
|
|
3124
|
+
/* ParseState.DefaultReduce */
|
|
3125
|
+
);
|
|
3126
|
+
if (defaultReduce > 0) {
|
|
3127
|
+
stack.reduce(defaultReduce);
|
|
3128
|
+
if (verbose)
|
|
3129
|
+
console.log(base + this.stackID(stack) + ` (via always-reduce ${parser2.getName(
|
|
3130
|
+
defaultReduce & 65535
|
|
3131
|
+
/* Action.ValueMask */
|
|
3132
|
+
)})`);
|
|
3133
|
+
return true;
|
|
3134
|
+
}
|
|
3135
|
+
if (stack.stack.length >= 15e3) {
|
|
3136
|
+
while (stack.stack.length > 9e3 && stack.forceReduce()) {
|
|
3137
|
+
}
|
|
3138
|
+
}
|
|
3139
|
+
let actions = this.tokens.getActions(stack);
|
|
3140
|
+
for (let i = 0; i < actions.length; ) {
|
|
3141
|
+
let action = actions[i++], term = actions[i++], end = actions[i++];
|
|
3142
|
+
let last = i == actions.length || !split;
|
|
3143
|
+
let localStack = last ? stack : stack.split();
|
|
3144
|
+
localStack.apply(action, term, end);
|
|
3145
|
+
if (verbose)
|
|
3146
|
+
console.log(base + this.stackID(localStack) + ` (via ${(action & 65536) == 0 ? "shift" : `reduce of ${parser2.getName(
|
|
3147
|
+
action & 65535
|
|
3148
|
+
/* Action.ValueMask */
|
|
3149
|
+
)}`} for ${parser2.getName(term)} @ ${start}${localStack == stack ? "" : ", split"})`);
|
|
3150
|
+
if (last)
|
|
3151
|
+
return true;
|
|
3152
|
+
else if (localStack.pos > start)
|
|
3153
|
+
stacks.push(localStack);
|
|
3154
|
+
else
|
|
3155
|
+
split.push(localStack);
|
|
3156
|
+
}
|
|
3157
|
+
return false;
|
|
3158
|
+
}
|
|
3159
|
+
// Advance a given stack forward as far as it will go. Returns the
|
|
3160
|
+
// (possibly updated) stack if it got stuck, or null if it moved
|
|
3161
|
+
// forward and was given to `pushStackDedup`.
|
|
3162
|
+
advanceFully(stack, newStacks) {
|
|
3163
|
+
let pos = stack.pos;
|
|
3164
|
+
for (; ; ) {
|
|
3165
|
+
if (!this.advanceStack(stack, null, null))
|
|
3166
|
+
return false;
|
|
3167
|
+
if (stack.pos > pos) {
|
|
3168
|
+
pushStackDedup(stack, newStacks);
|
|
3169
|
+
return true;
|
|
3170
|
+
}
|
|
3171
|
+
}
|
|
3172
|
+
}
|
|
3173
|
+
runRecovery(stacks, tokens, newStacks) {
|
|
3174
|
+
let finished = null, restarted = false;
|
|
3175
|
+
for (let i = 0; i < stacks.length; i++) {
|
|
3176
|
+
let stack = stacks[i], token = tokens[i << 1], tokenEnd = tokens[(i << 1) + 1];
|
|
3177
|
+
let base = verbose ? this.stackID(stack) + " -> " : "";
|
|
3178
|
+
if (stack.deadEnd) {
|
|
3179
|
+
if (restarted)
|
|
3180
|
+
continue;
|
|
3181
|
+
restarted = true;
|
|
3182
|
+
stack.restart();
|
|
3183
|
+
if (verbose)
|
|
3184
|
+
console.log(base + this.stackID(stack) + " (restarted)");
|
|
3185
|
+
let done = this.advanceFully(stack, newStacks);
|
|
3186
|
+
if (done)
|
|
3187
|
+
continue;
|
|
3188
|
+
}
|
|
3189
|
+
let force = stack.split(), forceBase = base;
|
|
3190
|
+
for (let j = 0; force.forceReduce() && j < 10; j++) {
|
|
3191
|
+
if (verbose)
|
|
3192
|
+
console.log(forceBase + this.stackID(force) + " (via force-reduce)");
|
|
3193
|
+
let done = this.advanceFully(force, newStacks);
|
|
3194
|
+
if (done)
|
|
3195
|
+
break;
|
|
3196
|
+
if (verbose)
|
|
3197
|
+
forceBase = this.stackID(force) + " -> ";
|
|
3198
|
+
}
|
|
3199
|
+
for (let insert of stack.recoverByInsert(token)) {
|
|
3200
|
+
if (verbose)
|
|
3201
|
+
console.log(base + this.stackID(insert) + " (via recover-insert)");
|
|
3202
|
+
this.advanceFully(insert, newStacks);
|
|
3203
|
+
}
|
|
3204
|
+
if (this.stream.end > stack.pos) {
|
|
3205
|
+
if (tokenEnd == stack.pos) {
|
|
3206
|
+
tokenEnd++;
|
|
3207
|
+
token = 0;
|
|
3208
|
+
}
|
|
3209
|
+
stack.recoverByDelete(token, tokenEnd);
|
|
3210
|
+
if (verbose)
|
|
3211
|
+
console.log(base + this.stackID(stack) + ` (via recover-delete ${this.parser.getName(token)})`);
|
|
3212
|
+
pushStackDedup(stack, newStacks);
|
|
3213
|
+
} else if (!finished || finished.score < stack.score) {
|
|
3214
|
+
finished = stack;
|
|
3215
|
+
}
|
|
3216
|
+
}
|
|
3217
|
+
return finished;
|
|
3218
|
+
}
|
|
3219
|
+
// Convert the stack's buffer to a syntax tree.
|
|
3220
|
+
stackToTree(stack) {
|
|
3221
|
+
stack.close();
|
|
3222
|
+
return Tree.build({
|
|
3223
|
+
buffer: StackBufferCursor.create(stack),
|
|
3224
|
+
nodeSet: this.parser.nodeSet,
|
|
3225
|
+
topID: this.topTerm,
|
|
3226
|
+
maxBufferLength: this.parser.bufferLength,
|
|
3227
|
+
reused: this.reused,
|
|
3228
|
+
start: this.ranges[0].from,
|
|
3229
|
+
length: stack.pos - this.ranges[0].from,
|
|
3230
|
+
minRepeatType: this.parser.minRepeatTerm
|
|
3231
|
+
});
|
|
3232
|
+
}
|
|
3233
|
+
stackID(stack) {
|
|
3234
|
+
let id = (stackIDs || (stackIDs = /* @__PURE__ */ new WeakMap())).get(stack);
|
|
3235
|
+
if (!id)
|
|
3236
|
+
stackIDs.set(stack, id = String.fromCodePoint(this.nextStackID++));
|
|
3237
|
+
return id + stack;
|
|
3238
|
+
}
|
|
3239
|
+
};
|
|
3240
|
+
function pushStackDedup(stack, newStacks) {
|
|
3241
|
+
for (let i = 0; i < newStacks.length; i++) {
|
|
3242
|
+
let other = newStacks[i];
|
|
3243
|
+
if (other.pos == stack.pos && other.sameState(stack)) {
|
|
3244
|
+
if (newStacks[i].score < stack.score)
|
|
3245
|
+
newStacks[i] = stack;
|
|
3246
|
+
return;
|
|
3247
|
+
}
|
|
3248
|
+
}
|
|
3249
|
+
newStacks.push(stack);
|
|
3250
|
+
}
|
|
3251
|
+
var Dialect = class {
|
|
3252
|
+
constructor(source, flags, disabled) {
|
|
3253
|
+
this.source = source;
|
|
3254
|
+
this.flags = flags;
|
|
3255
|
+
this.disabled = disabled;
|
|
3256
|
+
}
|
|
3257
|
+
allows(term) {
|
|
3258
|
+
return !this.disabled || this.disabled[term] == 0;
|
|
3259
|
+
}
|
|
3260
|
+
};
|
|
3261
|
+
var LRParser = class extends Parser {
|
|
3262
|
+
/// @internal
|
|
3263
|
+
constructor(spec) {
|
|
3264
|
+
super();
|
|
3265
|
+
this.wrappers = [];
|
|
3266
|
+
if (spec.version != 14)
|
|
3267
|
+
throw new RangeError(`Parser version (${spec.version}) doesn't match runtime version (${14})`);
|
|
3268
|
+
let nodeNames = spec.nodeNames.split(" ");
|
|
3269
|
+
this.minRepeatTerm = nodeNames.length;
|
|
3270
|
+
for (let i = 0; i < spec.repeatNodeCount; i++)
|
|
3271
|
+
nodeNames.push("");
|
|
3272
|
+
let topTerms = Object.keys(spec.topRules).map((r2) => spec.topRules[r2][1]);
|
|
3273
|
+
let nodeProps = [];
|
|
3274
|
+
for (let i = 0; i < nodeNames.length; i++)
|
|
3275
|
+
nodeProps.push([]);
|
|
3276
|
+
function setProp(nodeID, prop, value) {
|
|
3277
|
+
nodeProps[nodeID].push([prop, prop.deserialize(String(value))]);
|
|
3278
|
+
}
|
|
3279
|
+
if (spec.nodeProps)
|
|
3280
|
+
for (let propSpec of spec.nodeProps) {
|
|
3281
|
+
let prop = propSpec[0];
|
|
3282
|
+
if (typeof prop == "string")
|
|
3283
|
+
prop = NodeProp[prop];
|
|
3284
|
+
for (let i = 1; i < propSpec.length; ) {
|
|
3285
|
+
let next = propSpec[i++];
|
|
3286
|
+
if (next >= 0) {
|
|
3287
|
+
setProp(next, prop, propSpec[i++]);
|
|
3288
|
+
} else {
|
|
3289
|
+
let value = propSpec[i + -next];
|
|
3290
|
+
for (let j = -next; j > 0; j--)
|
|
3291
|
+
setProp(propSpec[i++], prop, value);
|
|
3292
|
+
i++;
|
|
3293
|
+
}
|
|
3294
|
+
}
|
|
3295
|
+
}
|
|
3296
|
+
this.nodeSet = new NodeSet(nodeNames.map((name, i) => NodeType.define({
|
|
3297
|
+
name: i >= this.minRepeatTerm ? void 0 : name,
|
|
3298
|
+
id: i,
|
|
3299
|
+
props: nodeProps[i],
|
|
3300
|
+
top: topTerms.indexOf(i) > -1,
|
|
3301
|
+
error: i == 0,
|
|
3302
|
+
skipped: spec.skippedNodes && spec.skippedNodes.indexOf(i) > -1
|
|
3303
|
+
})));
|
|
3304
|
+
if (spec.propSources)
|
|
3305
|
+
this.nodeSet = this.nodeSet.extend(...spec.propSources);
|
|
3306
|
+
this.strict = false;
|
|
3307
|
+
this.bufferLength = DefaultBufferLength;
|
|
3308
|
+
let tokenArray = decodeArray(spec.tokenData);
|
|
3309
|
+
this.context = spec.context;
|
|
3310
|
+
this.specializerSpecs = spec.specialized || [];
|
|
3311
|
+
this.specialized = new Uint16Array(this.specializerSpecs.length);
|
|
3312
|
+
for (let i = 0; i < this.specializerSpecs.length; i++)
|
|
3313
|
+
this.specialized[i] = this.specializerSpecs[i].term;
|
|
3314
|
+
this.specializers = this.specializerSpecs.map(getSpecializer);
|
|
3315
|
+
this.states = decodeArray(spec.states, Uint32Array);
|
|
3316
|
+
this.data = decodeArray(spec.stateData);
|
|
3317
|
+
this.goto = decodeArray(spec.goto);
|
|
3318
|
+
this.maxTerm = spec.maxTerm;
|
|
3319
|
+
this.tokenizers = spec.tokenizers.map((value) => typeof value == "number" ? new TokenGroup(tokenArray, value) : value);
|
|
3320
|
+
this.topRules = spec.topRules;
|
|
3321
|
+
this.dialects = spec.dialects || {};
|
|
3322
|
+
this.dynamicPrecedences = spec.dynamicPrecedences || null;
|
|
3323
|
+
this.tokenPrecTable = spec.tokenPrec;
|
|
3324
|
+
this.termNames = spec.termNames || null;
|
|
3325
|
+
this.maxNode = this.nodeSet.types.length - 1;
|
|
3326
|
+
this.dialect = this.parseDialect();
|
|
3327
|
+
this.top = this.topRules[Object.keys(this.topRules)[0]];
|
|
3328
|
+
}
|
|
3329
|
+
createParse(input, fragments, ranges) {
|
|
3330
|
+
let parse = new Parse(this, input, fragments, ranges);
|
|
3331
|
+
for (let w of this.wrappers)
|
|
3332
|
+
parse = w(parse, input, fragments, ranges);
|
|
3333
|
+
return parse;
|
|
3334
|
+
}
|
|
3335
|
+
/// Get a goto table entry @internal
|
|
3336
|
+
getGoto(state, term, loose = false) {
|
|
3337
|
+
let table = this.goto;
|
|
3338
|
+
if (term >= table[0])
|
|
3339
|
+
return -1;
|
|
3340
|
+
for (let pos = table[term + 1]; ; ) {
|
|
3341
|
+
let groupTag = table[pos++], last = groupTag & 1;
|
|
3342
|
+
let target = table[pos++];
|
|
3343
|
+
if (last && loose)
|
|
3344
|
+
return target;
|
|
3345
|
+
for (let end = pos + (groupTag >> 1); pos < end; pos++)
|
|
3346
|
+
if (table[pos] == state)
|
|
3347
|
+
return target;
|
|
3348
|
+
if (last)
|
|
3349
|
+
return -1;
|
|
3350
|
+
}
|
|
3351
|
+
}
|
|
3352
|
+
/// Check if this state has an action for a given terminal @internal
|
|
3353
|
+
hasAction(state, terminal) {
|
|
3354
|
+
let data = this.data;
|
|
3355
|
+
for (let set = 0; set < 2; set++) {
|
|
3356
|
+
for (let i = this.stateSlot(
|
|
3357
|
+
state,
|
|
3358
|
+
set ? 2 : 1
|
|
3359
|
+
/* ParseState.Actions */
|
|
3360
|
+
), next; ; i += 3) {
|
|
3361
|
+
if ((next = data[i]) == 65535) {
|
|
3362
|
+
if (data[i + 1] == 1)
|
|
3363
|
+
next = data[i = pair(data, i + 2)];
|
|
3364
|
+
else if (data[i + 1] == 2)
|
|
3365
|
+
return pair(data, i + 2);
|
|
3366
|
+
else
|
|
3367
|
+
break;
|
|
3368
|
+
}
|
|
3369
|
+
if (next == terminal || next == 0)
|
|
3370
|
+
return pair(data, i + 1);
|
|
3371
|
+
}
|
|
3372
|
+
}
|
|
3373
|
+
return 0;
|
|
3374
|
+
}
|
|
3375
|
+
/// @internal
|
|
3376
|
+
stateSlot(state, slot) {
|
|
3377
|
+
return this.states[state * 6 + slot];
|
|
3378
|
+
}
|
|
3379
|
+
/// @internal
|
|
3380
|
+
stateFlag(state, flag) {
|
|
3381
|
+
return (this.stateSlot(
|
|
3382
|
+
state,
|
|
3383
|
+
0
|
|
3384
|
+
/* ParseState.Flags */
|
|
3385
|
+
) & flag) > 0;
|
|
3386
|
+
}
|
|
3387
|
+
/// @internal
|
|
3388
|
+
validAction(state, action) {
|
|
3389
|
+
if (action == this.stateSlot(
|
|
3390
|
+
state,
|
|
3391
|
+
4
|
|
3392
|
+
/* ParseState.DefaultReduce */
|
|
3393
|
+
))
|
|
3394
|
+
return true;
|
|
3395
|
+
for (let i = this.stateSlot(
|
|
3396
|
+
state,
|
|
3397
|
+
1
|
|
3398
|
+
/* ParseState.Actions */
|
|
3399
|
+
); ; i += 3) {
|
|
3400
|
+
if (this.data[i] == 65535) {
|
|
3401
|
+
if (this.data[i + 1] == 1)
|
|
3402
|
+
i = pair(this.data, i + 2);
|
|
3403
|
+
else
|
|
3404
|
+
return false;
|
|
3405
|
+
}
|
|
3406
|
+
if (action == pair(this.data, i + 1))
|
|
3407
|
+
return true;
|
|
3408
|
+
}
|
|
3409
|
+
}
|
|
3410
|
+
/// Get the states that can follow this one through shift actions or
|
|
3411
|
+
/// goto jumps. @internal
|
|
3412
|
+
nextStates(state) {
|
|
3413
|
+
let result = [];
|
|
3414
|
+
for (let i = this.stateSlot(
|
|
3415
|
+
state,
|
|
3416
|
+
1
|
|
3417
|
+
/* ParseState.Actions */
|
|
3418
|
+
); ; i += 3) {
|
|
3419
|
+
if (this.data[i] == 65535) {
|
|
3420
|
+
if (this.data[i + 1] == 1)
|
|
3421
|
+
i = pair(this.data, i + 2);
|
|
3422
|
+
else
|
|
3423
|
+
break;
|
|
3424
|
+
}
|
|
3425
|
+
if ((this.data[i + 2] & 65536 >> 16) == 0) {
|
|
3426
|
+
let value = this.data[i + 1];
|
|
3427
|
+
if (!result.some((v, i2) => i2 & 1 && v == value))
|
|
3428
|
+
result.push(this.data[i], value);
|
|
3429
|
+
}
|
|
3430
|
+
}
|
|
3431
|
+
return result;
|
|
3432
|
+
}
|
|
3433
|
+
/// Configure the parser. Returns a new parser instance that has the
|
|
3434
|
+
/// given settings modified. Settings not provided in `config` are
|
|
3435
|
+
/// kept from the original parser.
|
|
3436
|
+
configure(config) {
|
|
3437
|
+
let copy = Object.assign(Object.create(LRParser.prototype), this);
|
|
3438
|
+
if (config.props)
|
|
3439
|
+
copy.nodeSet = this.nodeSet.extend(...config.props);
|
|
3440
|
+
if (config.top) {
|
|
3441
|
+
let info = this.topRules[config.top];
|
|
3442
|
+
if (!info)
|
|
3443
|
+
throw new RangeError(`Invalid top rule name ${config.top}`);
|
|
3444
|
+
copy.top = info;
|
|
3445
|
+
}
|
|
3446
|
+
if (config.tokenizers)
|
|
3447
|
+
copy.tokenizers = this.tokenizers.map((t) => {
|
|
3448
|
+
let found = config.tokenizers.find((r2) => r2.from == t);
|
|
3449
|
+
return found ? found.to : t;
|
|
3450
|
+
});
|
|
3451
|
+
if (config.specializers) {
|
|
3452
|
+
copy.specializers = this.specializers.slice();
|
|
3453
|
+
copy.specializerSpecs = this.specializerSpecs.map((s, i) => {
|
|
3454
|
+
let found = config.specializers.find((r2) => r2.from == s.external);
|
|
3455
|
+
if (!found)
|
|
3456
|
+
return s;
|
|
3457
|
+
let spec = Object.assign(Object.assign({}, s), { external: found.to });
|
|
3458
|
+
copy.specializers[i] = getSpecializer(spec);
|
|
3459
|
+
return spec;
|
|
3460
|
+
});
|
|
3461
|
+
}
|
|
3462
|
+
if (config.contextTracker)
|
|
3463
|
+
copy.context = config.contextTracker;
|
|
3464
|
+
if (config.dialect)
|
|
3465
|
+
copy.dialect = this.parseDialect(config.dialect);
|
|
3466
|
+
if (config.strict != null)
|
|
3467
|
+
copy.strict = config.strict;
|
|
3468
|
+
if (config.wrap)
|
|
3469
|
+
copy.wrappers = copy.wrappers.concat(config.wrap);
|
|
3470
|
+
if (config.bufferLength != null)
|
|
3471
|
+
copy.bufferLength = config.bufferLength;
|
|
3472
|
+
return copy;
|
|
3473
|
+
}
|
|
3474
|
+
/// Tells you whether any [parse wrappers](#lr.ParserConfig.wrap)
|
|
3475
|
+
/// are registered for this parser.
|
|
3476
|
+
hasWrappers() {
|
|
3477
|
+
return this.wrappers.length > 0;
|
|
3478
|
+
}
|
|
3479
|
+
/// Returns the name associated with a given term. This will only
|
|
3480
|
+
/// work for all terms when the parser was generated with the
|
|
3481
|
+
/// `--names` option. By default, only the names of tagged terms are
|
|
3482
|
+
/// stored.
|
|
3483
|
+
getName(term) {
|
|
3484
|
+
return this.termNames ? this.termNames[term] : String(term <= this.maxNode && this.nodeSet.types[term].name || term);
|
|
3485
|
+
}
|
|
3486
|
+
/// The eof term id is always allocated directly after the node
|
|
3487
|
+
/// types. @internal
|
|
3488
|
+
get eofTerm() {
|
|
3489
|
+
return this.maxNode + 1;
|
|
3490
|
+
}
|
|
3491
|
+
/// The type of top node produced by the parser.
|
|
3492
|
+
get topNode() {
|
|
3493
|
+
return this.nodeSet.types[this.top[1]];
|
|
3494
|
+
}
|
|
3495
|
+
/// @internal
|
|
3496
|
+
dynamicPrecedence(term) {
|
|
3497
|
+
let prec = this.dynamicPrecedences;
|
|
3498
|
+
return prec == null ? 0 : prec[term] || 0;
|
|
3499
|
+
}
|
|
3500
|
+
/// @internal
|
|
3501
|
+
parseDialect(dialect) {
|
|
3502
|
+
let values = Object.keys(this.dialects), flags = values.map(() => false);
|
|
3503
|
+
if (dialect)
|
|
3504
|
+
for (let part of dialect.split(" ")) {
|
|
3505
|
+
let id = values.indexOf(part);
|
|
3506
|
+
if (id >= 0)
|
|
3507
|
+
flags[id] = true;
|
|
3508
|
+
}
|
|
3509
|
+
let disabled = null;
|
|
3510
|
+
for (let i = 0; i < values.length; i++)
|
|
3511
|
+
if (!flags[i]) {
|
|
3512
|
+
for (let j = this.dialects[values[i]], id; (id = this.data[j++]) != 65535; )
|
|
3513
|
+
(disabled || (disabled = new Uint8Array(this.maxTerm + 1)))[id] = 1;
|
|
3514
|
+
}
|
|
3515
|
+
return new Dialect(dialect, flags, disabled);
|
|
3516
|
+
}
|
|
3517
|
+
/// Used by the output of the parser generator. Not available to
|
|
3518
|
+
/// user code. @hide
|
|
3519
|
+
static deserialize(spec) {
|
|
3520
|
+
return new LRParser(spec);
|
|
3521
|
+
}
|
|
3522
|
+
};
|
|
3523
|
+
function pair(data, off) {
|
|
3524
|
+
return data[off] | data[off + 1] << 16;
|
|
3525
|
+
}
|
|
3526
|
+
function findFinished(stacks) {
|
|
3527
|
+
let best = null;
|
|
3528
|
+
for (let stack of stacks) {
|
|
3529
|
+
let stopped = stack.p.stoppedAt;
|
|
3530
|
+
if ((stack.pos == stack.p.stream.end || stopped != null && stack.pos > stopped) && stack.p.parser.stateFlag(
|
|
3531
|
+
stack.state,
|
|
3532
|
+
2
|
|
3533
|
+
/* StateFlag.Accepting */
|
|
3534
|
+
) && (!best || best.score < stack.score))
|
|
3535
|
+
best = stack;
|
|
3536
|
+
}
|
|
3537
|
+
return best;
|
|
3538
|
+
}
|
|
3539
|
+
function getSpecializer(spec) {
|
|
3540
|
+
if (spec.external) {
|
|
3541
|
+
let mask = spec.extend ? 1 : 0;
|
|
3542
|
+
return (value, stack) => spec.external(value, stack) << 1 | mask;
|
|
3543
|
+
}
|
|
3544
|
+
return spec.get;
|
|
3545
|
+
}
|
|
3546
|
+
|
|
3547
|
+
// ../vuu-filter-parser/src/generated/filter-parser.js
|
|
3548
|
+
var parser = LRParser.deserialize({
|
|
3549
|
+
version: 14,
|
|
3550
|
+
states: "%QOVQPOOOOQO'#C_'#C_O_QQO'#C^OOQO'#DO'#DOOvQQO'#C|OOQO'#DR'#DROVQPO'#CuOOQO'#C}'#C}QOQPOOOOQO'#C`'#C`O!UQQO,58xO!dQPO,59VOVQPO,59]OVQPO,59_O!iQPO,59hO!nQQO,59aOOQO'#DQ'#DQOOQO1G.d1G.dO!UQQO1G.qO!yQQO1G.wOOQO1G.y1G.yOOQO'#Cw'#CwOOQO1G/S1G/SOOQO1G.{1G.{O#[QPO'#CnO#dQPO7+$]O!UQQO'#CxO#iQPO,59YOOQO<<Gw<<GwOOQO,59d,59dOOQO-E6v-E6v",
|
|
3551
|
+
stateData: "#q~OoOS~OsPOvUO~OTXOUXOVXOWXOXXOYXO`ZO~Of[Oh]Oj^OmpX~OZ`O[`O]`O^`O~OabO~OseO~Of[Oh]OwgO~Oh]Ofeijeimeiwei~OcjOdbX~OdlO~OcjOdba~O",
|
|
3552
|
+
goto: "#YvPPw}!TPPPPPPPPPPwPP!WPP!ZP!ZP!aP!g!jPPP!p!s!aP#P!aXROU[]XQOU[]RYQRibXTOU[]XVOU[]Rf^QkhRnkRWOQSOQ_UQc[Rd]QaYQhbRmj",
|
|
3553
|
+
nodeNames: "\u26A0 Filter ColumnValueExpression Column Operator Eq NotEq Gt Lt Starts Ends Number String True False ColumnSetExpression In LBrack Values Comma RBrack AndExpression And OrExpression Or ParenthesizedExpression As FilterName",
|
|
3554
|
+
maxTerm: 39,
|
|
3555
|
+
skippedNodes: [0],
|
|
3556
|
+
repeatNodeCount: 1,
|
|
3557
|
+
tokenData: "6p~RnXY#PYZ#P]^#Ppq#Pqr#brs#mxy$eyz$j|}$o!O!P$t!Q![%S!^!_%_!_!`%d!`!a%i!c!}%n!}#O&V#P#Q&[#R#S%n#T#U&a#U#X%n#X#Y(w#Y#Z+]#Z#]%n#]#^.]#^#c%n#c#d/e#d#g%n#g#h0m#h#i4[#i#o%n~#USo~XY#PYZ#P]^#Ppq#P~#eP!_!`#h~#mOU~~#pWOX#mZ]#m^r#mrs$Ys#O#m#P;'S#m;'S;=`$_<%lO#m~$_O[~~$bP;=`<%l#m~$jOv~~$oOw~~$tOc~~$wP!Q![$z~%PPZ~!Q![$z~%XQZ~!O!P$t!Q![%S~%dOW~~%iOT~~%nOV~P%sUsP}!O%n!O!P%n!Q![%n!c!}%n#R#S%n#T#o%n~&[Oa~~&aOd~R&fYsP}!O%n!O!P%n!Q![%n!c!}%n#R#S%n#T#b%n#b#c'U#c#g%n#g#h(^#h#o%nR'ZWsP}!O%n!O!P%n!Q![%n!c!}%n#R#S%n#T#W%n#W#X's#X#o%nR'zUfQsP}!O%n!O!P%n!Q![%n!c!}%n#R#S%n#T#o%nR(eUjQsP}!O%n!O!P%n!Q![%n!c!}%n#R#S%n#T#o%nR(|WsP}!O%n!O!P%n!Q![%n!c!}%n#R#S%n#T#b%n#b#c)f#c#o%nR)kWsP}!O%n!O!P%n!Q![%n!c!}%n#R#S%n#T#W%n#W#X*T#X#o%nR*YWsP}!O%n!O!P%n!Q![%n!c!}%n#R#S%n#T#g%n#g#h*r#h#o%nR*yUYQsP}!O%n!O!P%n!Q![%n!c!}%n#R#S%n#T#o%nR+bVsP}!O%n!O!P%n!Q![%n!c!}%n#R#S%n#T#U+w#U#o%nR+|WsP}!O%n!O!P%n!Q![%n!c!}%n#R#S%n#T#`%n#`#a,f#a#o%nR,kWsP}!O%n!O!P%n!Q![%n!c!}%n#R#S%n#T#g%n#g#h-T#h#o%nR-YWsP}!O%n!O!P%n!Q![%n!c!}%n#R#S%n#T#X%n#X#Y-r#Y#o%nR-yU^QsP}!O%n!O!P%n!Q![%n!c!}%n#R#S%n#T#o%nR.bWsP}!O%n!O!P%n!Q![%n!c!}%n#R#S%n#T#b%n#b#c.z#c#o%nR/RU`QsP}!O%n!O!P%n!Q![%n!c!}%n#R#S%n#T#o%nR/jWsP}!O%n!O!P%n!Q![%n!c!}%n#R#S%n#T#f%n#f#g0S#g#o%nR0ZUhQsP}!O%n!O!P%n!Q![%n!c!}%n#R#S%n#T#o%nR0rWsP}!O%n!O!P%n!Q![%n!c!}%n#R#S%n#T#h%n#h#i1[#i#o%nR1aVsP}!O%n!O!P%n!Q![%n!c!}%n#R#S%n#T#U1v#U#o%nR1{WsP}!O%n!O!P%n!Q![%n!c!}%n#R#S%n#T#f%n#f#g2e#g#o%nR2jWsP}!O%n!O!P%n!Q![%n!c!}%n#R#S%n#T#h%n#h#i3S#i#o%nR3XWsP}!O%n!O!P%n!Q![%n!c!}%n#R#S%n#T#g%n#g#h3q#h#o%nR3xUXQsP}!O%n!O!P%n!Q![%n!c!}%n#R#S%n#T#o%nR4aWsP}!O%n!O!P%n!Q![%n!c!}%n#R#S%n#T#f%n#f#g4y#g#o%nR5OWsP}!O%n!O!P%n!Q![%n!c!}%n#R#S%n#T#i%n#i#j5h#j#o%nR5mWsP}!O%n!O!P%n!Q![%n!c!}%n#R#S%n#T#X%n#X#Y6V#Y#o%nR6^U]QsP}!O%n!O!P%n!Q![%n!c!}%n#R#S%n#T#o%n",
|
|
3558
|
+
tokenizers: [0, 1],
|
|
3559
|
+
topRules: { "Filter": [0, 1] },
|
|
3560
|
+
tokenPrec: 0
|
|
3561
|
+
});
|
|
3562
|
+
|
|
3563
|
+
// ../vuu-filter-parser/src/FilterTreeWalker.ts
|
|
3564
|
+
var import_vuu_utils3 = require("@vuu-ui/vuu-utils");
|
|
3565
|
+
var _filter;
|
|
3566
|
+
var FilterExpression = class {
|
|
3567
|
+
constructor() {
|
|
3568
|
+
__privateAdd(this, _filter, void 0);
|
|
3569
|
+
}
|
|
3570
|
+
setFilterCombinatorOp(op, filter = __privateGet(this, _filter)) {
|
|
3571
|
+
if ((0, import_vuu_utils3.isMultiClauseFilter)(filter) && filter.op === op) {
|
|
3572
|
+
return;
|
|
3573
|
+
} else {
|
|
3574
|
+
__privateSet(this, _filter, {
|
|
3575
|
+
op,
|
|
3576
|
+
filters: [__privateGet(this, _filter)]
|
|
3577
|
+
});
|
|
3578
|
+
}
|
|
3579
|
+
}
|
|
3580
|
+
add(filter) {
|
|
3581
|
+
if (__privateGet(this, _filter) === void 0) {
|
|
3582
|
+
__privateSet(this, _filter, filter);
|
|
3583
|
+
} else if ((0, import_vuu_utils3.isMultiClauseFilter)(__privateGet(this, _filter))) {
|
|
3584
|
+
__privateGet(this, _filter).filters.push(filter);
|
|
3585
|
+
} else {
|
|
3586
|
+
throw Error(`Invalid filter passed to FilterExpression`);
|
|
3587
|
+
}
|
|
3588
|
+
}
|
|
3589
|
+
setColumn(column, filter = __privateGet(this, _filter)) {
|
|
3590
|
+
if ((0, import_vuu_utils3.isMultiClauseFilter)(filter)) {
|
|
3591
|
+
const target = filter.filters.at(-1);
|
|
3592
|
+
if (target) {
|
|
3593
|
+
this.setColumn(column, target);
|
|
3594
|
+
}
|
|
3595
|
+
} else if (filter) {
|
|
3596
|
+
filter.column = column;
|
|
3597
|
+
}
|
|
3598
|
+
}
|
|
3599
|
+
setOp(value, filter = __privateGet(this, _filter)) {
|
|
3600
|
+
if ((0, import_vuu_utils3.isMultiClauseFilter)(filter)) {
|
|
3601
|
+
const target = filter.filters.at(-1);
|
|
3602
|
+
if (target) {
|
|
3603
|
+
this.setOp(value, target);
|
|
3604
|
+
}
|
|
3605
|
+
} else if (filter) {
|
|
3606
|
+
filter.op = value;
|
|
3607
|
+
}
|
|
3608
|
+
}
|
|
3609
|
+
setValue(value, filter = __privateGet(this, _filter)) {
|
|
3610
|
+
var _a;
|
|
3611
|
+
if ((0, import_vuu_utils3.isMultiClauseFilter)(filter)) {
|
|
3612
|
+
const target = filter.filters.at(-1);
|
|
3613
|
+
if (target) {
|
|
3614
|
+
this.setValue(value, target);
|
|
3615
|
+
}
|
|
3616
|
+
} else if ((0, import_vuu_utils3.isMultiValueFilter)(filter)) {
|
|
3617
|
+
(_a = filter.values) != null ? _a : filter.values = [];
|
|
3618
|
+
filter.values.push(value);
|
|
3619
|
+
} else if ((0, import_vuu_utils3.isSingleValueFilter)(filter)) {
|
|
3620
|
+
filter.value = value;
|
|
3621
|
+
}
|
|
3622
|
+
}
|
|
3623
|
+
toJSON(filter = __privateGet(this, _filter)) {
|
|
3624
|
+
if (this.name) {
|
|
3625
|
+
return {
|
|
3626
|
+
...filter,
|
|
3627
|
+
name: this.name
|
|
3628
|
+
};
|
|
3629
|
+
} else {
|
|
3630
|
+
return filter;
|
|
3631
|
+
}
|
|
3632
|
+
}
|
|
3633
|
+
};
|
|
3634
|
+
_filter = new WeakMap();
|
|
3635
|
+
var walkTree = (tree, source) => {
|
|
3636
|
+
const filterExpression = new FilterExpression();
|
|
3637
|
+
const cursor = tree.cursor();
|
|
3638
|
+
do {
|
|
3639
|
+
const { name, from, to } = cursor;
|
|
3640
|
+
switch (name) {
|
|
3641
|
+
case "ColumnValueExpression":
|
|
3642
|
+
filterExpression.add({});
|
|
3643
|
+
break;
|
|
3644
|
+
case "ColumnSetExpression":
|
|
3645
|
+
filterExpression.add({ op: "in" });
|
|
3646
|
+
break;
|
|
3647
|
+
case "Or":
|
|
3648
|
+
case "And":
|
|
3649
|
+
filterExpression.setFilterCombinatorOp(source.substring(from, to));
|
|
3650
|
+
break;
|
|
3651
|
+
case "Column":
|
|
3652
|
+
filterExpression.setColumn(source.substring(from, to));
|
|
3653
|
+
break;
|
|
3654
|
+
case "Operator":
|
|
3655
|
+
filterExpression.setOp(source.substring(from, to));
|
|
3656
|
+
break;
|
|
3657
|
+
case "String":
|
|
3658
|
+
filterExpression.setValue(source.substring(from + 1, to - 1));
|
|
3659
|
+
break;
|
|
3660
|
+
case "Number":
|
|
3661
|
+
filterExpression.setValue(parseFloat(source.substring(from, to)));
|
|
3662
|
+
break;
|
|
3663
|
+
case "True":
|
|
3664
|
+
filterExpression.setValue(true);
|
|
3665
|
+
break;
|
|
3666
|
+
case "False":
|
|
3667
|
+
filterExpression.setValue(false);
|
|
3668
|
+
break;
|
|
3669
|
+
case "FilterName":
|
|
3670
|
+
filterExpression.name = source.substring(from, to);
|
|
3671
|
+
break;
|
|
3672
|
+
default:
|
|
3673
|
+
}
|
|
3674
|
+
} while (cursor.next());
|
|
3675
|
+
return filterExpression.toJSON();
|
|
552
3676
|
};
|
|
553
3677
|
|
|
554
|
-
//
|
|
555
|
-
var
|
|
556
|
-
var getTypeaheadFilter = (column, filterValues, isStartsWithFilter) => {
|
|
557
|
-
if (filterValues.length === 0) {
|
|
558
|
-
return void 0;
|
|
559
|
-
}
|
|
560
|
-
if (isStartsWithFilter) {
|
|
561
|
-
const startsWith = filterValues[0].substring(0, filterValues[0].length - 3);
|
|
562
|
-
return {
|
|
563
|
-
column,
|
|
564
|
-
op: "starts",
|
|
565
|
-
value: `"${startsWith}"`
|
|
566
|
-
};
|
|
567
|
-
}
|
|
568
|
-
return {
|
|
569
|
-
column,
|
|
570
|
-
op: "in",
|
|
571
|
-
values: filterValues.map((value) => `"${value}"`)
|
|
572
|
-
};
|
|
573
|
-
};
|
|
574
|
-
var getRangeFilter = (column, startValue, endValue) => {
|
|
575
|
-
const startFilter = startValue === void 0 ? void 0 : { column, op: ">", value: startValue - 1 };
|
|
576
|
-
const endFilter = endValue === void 0 ? void 0 : { column, op: "<", value: endValue + 1 };
|
|
577
|
-
if (endFilter === void 0)
|
|
578
|
-
return startFilter;
|
|
579
|
-
return addFilter(startFilter, endFilter, { combineWith: "and" });
|
|
580
|
-
};
|
|
3678
|
+
// ../vuu-filter-parser/src/FilterParser.ts
|
|
3679
|
+
var strictParser = parser.configure({ strict: true });
|
|
581
3680
|
|
|
582
|
-
// src/
|
|
583
|
-
var
|
|
584
|
-
var
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
const columnName = defaultTypeaheadParams[1];
|
|
591
|
-
const startChangeHandler = (e) => {
|
|
592
|
-
const value = parseFloat(e.target.value);
|
|
593
|
-
const newRange = {
|
|
594
|
-
start: isNaN(value) ? void 0 : value,
|
|
595
|
-
end: filterValues == null ? void 0 : filterValues.end
|
|
596
|
-
};
|
|
597
|
-
const filter = getRangeFilter(columnName, newRange.start, newRange.end);
|
|
598
|
-
onChange(newRange, filter);
|
|
599
|
-
};
|
|
600
|
-
const endChangeHandler = (e) => {
|
|
601
|
-
const value = parseFloat(e.target.value);
|
|
602
|
-
const newRange = {
|
|
603
|
-
start: filterValues == null ? void 0 : filterValues.start,
|
|
604
|
-
end: isNaN(value) ? void 0 : value
|
|
605
|
-
};
|
|
606
|
-
const filter = getRangeFilter(columnName, newRange.start, newRange.end);
|
|
607
|
-
onChange(newRange, filter);
|
|
608
|
-
};
|
|
609
|
-
return /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("div", { style: { display: "flex", flexDirection: "row" }, children: [
|
|
610
|
-
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)(import_salt_lab.ToolbarField, { label: "From", children: /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
|
|
611
|
-
import_salt_lab.Input,
|
|
612
|
-
{
|
|
613
|
-
onChange: startChangeHandler,
|
|
614
|
-
value: ((_a = filterValues == null ? void 0 : filterValues.start) == null ? void 0 : _a.toString()) || "",
|
|
615
|
-
type: "number"
|
|
616
|
-
}
|
|
617
|
-
) }),
|
|
618
|
-
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)(import_salt_lab.ToolbarField, { label: "To", children: /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
|
|
619
|
-
import_salt_lab.Input,
|
|
620
|
-
{
|
|
621
|
-
onChange: endChangeHandler,
|
|
622
|
-
value: ((_b = filterValues == null ? void 0 : filterValues.end) == null ? void 0 : _b.toString()) || "",
|
|
623
|
-
type: "number"
|
|
624
|
-
}
|
|
625
|
-
) })
|
|
626
|
-
] });
|
|
627
|
-
};
|
|
3681
|
+
// ../vuu-data-react/src/hooks/useVuuMenuActions.ts
|
|
3682
|
+
var import_vuu_utils4 = require("@vuu-ui/vuu-utils");
|
|
3683
|
+
var import_react7 = require("react");
|
|
3684
|
+
var { KEY } = import_vuu_utils4.metadataKeys;
|
|
3685
|
+
|
|
3686
|
+
// ../vuu-data-react/src/hooks/useVuuTables.ts
|
|
3687
|
+
var import_react8 = require("react");
|
|
3688
|
+
var import_vuu_data4 = require("@vuu-ui/vuu-data");
|
|
628
3689
|
|
|
629
3690
|
// src/column-filter/TypeaheadFilter.tsx
|
|
630
|
-
var import_react3 = require("react");
|
|
631
|
-
var import_vuu_data = require("@vuu-ui/vuu-data");
|
|
632
3691
|
var import_salt_lab2 = require("@heswell/salt-lab");
|
|
3692
|
+
var import_react9 = require("react");
|
|
633
3693
|
var import_jsx_runtime4 = require("react/jsx-runtime");
|
|
634
3694
|
var TypeaheadFilter = ({
|
|
635
3695
|
defaultTypeaheadParams,
|
|
@@ -637,10 +3697,10 @@ var TypeaheadFilter = ({
|
|
|
637
3697
|
onChange: onFilterChange
|
|
638
3698
|
}) => {
|
|
639
3699
|
const [tableName, columnName] = defaultTypeaheadParams;
|
|
640
|
-
const [searchValue, setSearchValue] = (0,
|
|
641
|
-
const [typeaheadValues, setTypeaheadValues] = (0,
|
|
642
|
-
const getSuggestions =
|
|
643
|
-
(0,
|
|
3700
|
+
const [searchValue, setSearchValue] = (0, import_react9.useState)("");
|
|
3701
|
+
const [typeaheadValues, setTypeaheadValues] = (0, import_react9.useState)([]);
|
|
3702
|
+
const getSuggestions = useTypeaheadSuggestions();
|
|
3703
|
+
(0, import_react9.useEffect)(() => {
|
|
644
3704
|
const params = searchValue ? [tableName, columnName, searchValue] : defaultTypeaheadParams;
|
|
645
3705
|
let isSubscribed = true;
|
|
646
3706
|
getSuggestions(params).then((options) => {
|
|
@@ -667,14 +3727,14 @@ var TypeaheadFilter = ({
|
|
|
667
3727
|
getSuggestions,
|
|
668
3728
|
defaultTypeaheadParams
|
|
669
3729
|
]);
|
|
670
|
-
const onInputChange = (0,
|
|
3730
|
+
const onInputChange = (0, import_react9.useCallback)(
|
|
671
3731
|
(evt) => {
|
|
672
3732
|
const value = evt.target.value;
|
|
673
3733
|
setSearchValue(value);
|
|
674
3734
|
},
|
|
675
3735
|
[]
|
|
676
3736
|
);
|
|
677
|
-
const onSelectionChange = (0,
|
|
3737
|
+
const onSelectionChange = (0, import_react9.useCallback)(
|
|
678
3738
|
(_evt, selected) => {
|
|
679
3739
|
setSearchValue("");
|
|
680
3740
|
if (selected === null)
|
|
@@ -707,13 +3767,13 @@ var TypeaheadFilter = ({
|
|
|
707
3767
|
};
|
|
708
3768
|
|
|
709
3769
|
// src/column-filter/ColumnListItem.tsx
|
|
710
|
-
var
|
|
3770
|
+
var import_react10 = require("react");
|
|
711
3771
|
var import_salt_lab3 = require("@heswell/salt-lab");
|
|
712
3772
|
var import_jsx_runtime5 = require("react/jsx-runtime");
|
|
713
3773
|
var ColumnListItem = (props) => {
|
|
714
3774
|
return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(MemoColumnItem, { ...props });
|
|
715
3775
|
};
|
|
716
|
-
var MemoColumnItem = (0,
|
|
3776
|
+
var MemoColumnItem = (0, import_react10.memo)(function MemoizedItem({
|
|
717
3777
|
item,
|
|
718
3778
|
itemTextHighlightPattern,
|
|
719
3779
|
...restProps
|
|
@@ -728,22 +3788,23 @@ var MemoColumnItem = (0, import_react4.memo)(function MemoizedItem({
|
|
|
728
3788
|
});
|
|
729
3789
|
|
|
730
3790
|
// src/column-filter/useColumnFilterStore.ts
|
|
731
|
-
var
|
|
3791
|
+
var import_vuu_utils5 = require("@vuu-ui/vuu-utils");
|
|
3792
|
+
var import_react11 = require("react");
|
|
732
3793
|
var addOrReplace = (array, newValue, key) => array.filter((oldValue) => oldValue[key] !== newValue[key]).concat(newValue);
|
|
733
3794
|
var useColumnFilterStore = (onFilterSubmit) => {
|
|
734
3795
|
var _a, _b;
|
|
735
|
-
const [selectedColumnName, setSelectedColumnName] = (0,
|
|
736
|
-
const [savedFilters, setSavedFilters] = (0,
|
|
737
|
-
const [rangeValues, setRangeValues] = (0,
|
|
738
|
-
const [typeaheadValues, setTypeaheadValues] = (0,
|
|
3796
|
+
const [selectedColumnName, setSelectedColumnName] = (0, import_react11.useState)("");
|
|
3797
|
+
const [savedFilters, setSavedFilters] = (0, import_react11.useState)([]);
|
|
3798
|
+
const [rangeValues, setRangeValues] = (0, import_react11.useState)([]);
|
|
3799
|
+
const [typeaheadValues, setTypeaheadValues] = (0, import_react11.useState)([]);
|
|
739
3800
|
const clear = () => {
|
|
740
3801
|
setSelectedColumnName("");
|
|
741
3802
|
setRangeValues([]);
|
|
742
3803
|
setTypeaheadValues([]);
|
|
743
3804
|
setSavedFilters([]);
|
|
744
|
-
onFilterSubmit("");
|
|
3805
|
+
onFilterSubmit({ filter: "" });
|
|
745
3806
|
};
|
|
746
|
-
const updateFilters = (0,
|
|
3807
|
+
const updateFilters = (0, import_react11.useCallback)(
|
|
747
3808
|
(newFilter) => {
|
|
748
3809
|
const newSavedFilters = addOrReplace(
|
|
749
3810
|
savedFilters,
|
|
@@ -756,12 +3817,12 @@ var useColumnFilterStore = (onFilterSubmit) => {
|
|
|
756
3817
|
return prev;
|
|
757
3818
|
return addFilter(prev, filter, { combineWith: AND });
|
|
758
3819
|
}, void 0);
|
|
759
|
-
const query = combinedFilter === void 0 ? "" : filterAsQuery(combinedFilter);
|
|
760
|
-
onFilterSubmit(query, combinedFilter);
|
|
3820
|
+
const query = combinedFilter === void 0 ? "" : (0, import_vuu_utils5.filterAsQuery)(combinedFilter);
|
|
3821
|
+
onFilterSubmit({ filter: query, filterStruct: combinedFilter });
|
|
761
3822
|
},
|
|
762
3823
|
[selectedColumnName, onFilterSubmit, savedFilters]
|
|
763
3824
|
);
|
|
764
|
-
const onTypeaheadChange = (0,
|
|
3825
|
+
const onTypeaheadChange = (0, import_react11.useCallback)(
|
|
765
3826
|
(newValues, newFilter) => {
|
|
766
3827
|
setTypeaheadValues(
|
|
767
3828
|
addOrReplace(
|
|
@@ -774,7 +3835,7 @@ var useColumnFilterStore = (onFilterSubmit) => {
|
|
|
774
3835
|
},
|
|
775
3836
|
[selectedColumnName, typeaheadValues, updateFilters]
|
|
776
3837
|
);
|
|
777
|
-
const onRangeChange = (0,
|
|
3838
|
+
const onRangeChange = (0, import_react11.useCallback)(
|
|
778
3839
|
(newValues, newFilter) => {
|
|
779
3840
|
setRangeValues(
|
|
780
3841
|
addOrReplace(
|
|
@@ -787,7 +3848,7 @@ var useColumnFilterStore = (onFilterSubmit) => {
|
|
|
787
3848
|
},
|
|
788
3849
|
[selectedColumnName, rangeValues, updateFilters]
|
|
789
3850
|
);
|
|
790
|
-
const onSelectedColumnChange = (0,
|
|
3851
|
+
const onSelectedColumnChange = (0, import_react11.useCallback)(
|
|
791
3852
|
(column) => setSelectedColumnName((column == null ? void 0 : column.name) || ""),
|
|
792
3853
|
[]
|
|
793
3854
|
);
|
|
@@ -899,182 +3960,40 @@ var ColumnFilter = ({
|
|
|
899
3960
|
var import_core2 = require("@salt-ds/core");
|
|
900
3961
|
|
|
901
3962
|
// src/filter-input/useCodeMirrorEditor.ts
|
|
902
|
-
var
|
|
3963
|
+
var import_vuu_codemirror5 = require("@vuu-ui/vuu-codemirror");
|
|
903
3964
|
var import_classnames = __toESM(require_classnames(), 1);
|
|
904
|
-
var
|
|
905
|
-
|
|
906
|
-
// src/filter-input/filter-language-parser/FilterLanguage.ts
|
|
907
|
-
var import_vuu_codemirror2 = require("@vuu-ui/vuu-codemirror");
|
|
3965
|
+
var import_react13 = require("react");
|
|
908
3966
|
|
|
909
|
-
// src/filter-input/
|
|
3967
|
+
// src/filter-input/FilterLanguage.ts
|
|
910
3968
|
var import_vuu_codemirror = require("@vuu-ui/vuu-codemirror");
|
|
911
|
-
var
|
|
912
|
-
version: 14,
|
|
913
|
-
states: "%QOVQPOOOOQO'#C_'#C_O_QQO'#C^OOQO'#DO'#DOOvQQO'#C|OOQO'#DR'#DROVQPO'#CuOOQO'#C}'#C}QOQPOOOOQO'#C`'#C`O!UQQO,58xO!dQPO,59VOVQPO,59]OVQPO,59_O!iQPO,59hO!nQQO,59aOOQO'#DQ'#DQOOQO1G.d1G.dO!UQQO1G.qO!yQQO1G.wOOQO1G.y1G.yOOQO'#Cw'#CwOOQO1G/S1G/SOOQO1G.{1G.{O#[QPO'#CnO#dQPO7+$]O!UQQO'#CxO#iQPO,59YOOQO<<Gw<<GwOOQO,59d,59dOOQO-E6v-E6v",
|
|
914
|
-
stateData: "#q~OoOS~OsPOvUO~OTXOUXOVXOWXOXXOYXO`ZO~Of[Oh]Oj^OmpX~OZ`O[`O]`O^`O~OabO~OseO~Of[Oh]OwgO~Oh]Ofeijeimeiwei~OcjOdbX~OdlO~OcjOdba~O",
|
|
915
|
-
goto: "#YvPPw}!TPPPPPPPPPPwPP!WPP!ZP!ZP!aP!g!jPPP!p!s!aP#P!aXROU[]XQOU[]RYQRibXTOU[]XVOU[]Rf^QkhRnkRWOQSOQ_UQc[Rd]QaYQhbRmj",
|
|
916
|
-
nodeNames: "\u26A0 Filter ColumnValueExpression Column Operator Eq NotEq Gt Lt Starts Ends Number String True False ColumnSetExpression In LBrack Values Comma RBrack AndExpression And OrExpression Or ParenthesizedExpression As FilterName",
|
|
917
|
-
maxTerm: 39,
|
|
918
|
-
skippedNodes: [0],
|
|
919
|
-
repeatNodeCount: 1,
|
|
920
|
-
tokenData: "6p~RnXY#PYZ#P]^#Ppq#Pqr#brs#mxy$eyz$j|}$o!O!P$t!Q![%S!^!_%_!_!`%d!`!a%i!c!}%n!}#O&V#P#Q&[#R#S%n#T#U&a#U#X%n#X#Y(w#Y#Z+]#Z#]%n#]#^.]#^#c%n#c#d/e#d#g%n#g#h0m#h#i4[#i#o%n~#USo~XY#PYZ#P]^#Ppq#P~#eP!_!`#h~#mOU~~#pWOX#mZ]#m^r#mrs$Ys#O#m#P;'S#m;'S;=`$_<%lO#m~$_O[~~$bP;=`<%l#m~$jOv~~$oOw~~$tOc~~$wP!Q![$z~%PPZ~!Q![$z~%XQZ~!O!P$t!Q![%S~%dOW~~%iOT~~%nOV~P%sUsP}!O%n!O!P%n!Q![%n!c!}%n#R#S%n#T#o%n~&[Oa~~&aOd~R&fYsP}!O%n!O!P%n!Q![%n!c!}%n#R#S%n#T#b%n#b#c'U#c#g%n#g#h(^#h#o%nR'ZWsP}!O%n!O!P%n!Q![%n!c!}%n#R#S%n#T#W%n#W#X's#X#o%nR'zUfQsP}!O%n!O!P%n!Q![%n!c!}%n#R#S%n#T#o%nR(eUjQsP}!O%n!O!P%n!Q![%n!c!}%n#R#S%n#T#o%nR(|WsP}!O%n!O!P%n!Q![%n!c!}%n#R#S%n#T#b%n#b#c)f#c#o%nR)kWsP}!O%n!O!P%n!Q![%n!c!}%n#R#S%n#T#W%n#W#X*T#X#o%nR*YWsP}!O%n!O!P%n!Q![%n!c!}%n#R#S%n#T#g%n#g#h*r#h#o%nR*yUYQsP}!O%n!O!P%n!Q![%n!c!}%n#R#S%n#T#o%nR+bVsP}!O%n!O!P%n!Q![%n!c!}%n#R#S%n#T#U+w#U#o%nR+|WsP}!O%n!O!P%n!Q![%n!c!}%n#R#S%n#T#`%n#`#a,f#a#o%nR,kWsP}!O%n!O!P%n!Q![%n!c!}%n#R#S%n#T#g%n#g#h-T#h#o%nR-YWsP}!O%n!O!P%n!Q![%n!c!}%n#R#S%n#T#X%n#X#Y-r#Y#o%nR-yU^QsP}!O%n!O!P%n!Q![%n!c!}%n#R#S%n#T#o%nR.bWsP}!O%n!O!P%n!Q![%n!c!}%n#R#S%n#T#b%n#b#c.z#c#o%nR/RU`QsP}!O%n!O!P%n!Q![%n!c!}%n#R#S%n#T#o%nR/jWsP}!O%n!O!P%n!Q![%n!c!}%n#R#S%n#T#f%n#f#g0S#g#o%nR0ZUhQsP}!O%n!O!P%n!Q![%n!c!}%n#R#S%n#T#o%nR0rWsP}!O%n!O!P%n!Q![%n!c!}%n#R#S%n#T#h%n#h#i1[#i#o%nR1aVsP}!O%n!O!P%n!Q![%n!c!}%n#R#S%n#T#U1v#U#o%nR1{WsP}!O%n!O!P%n!Q![%n!c!}%n#R#S%n#T#f%n#f#g2e#g#o%nR2jWsP}!O%n!O!P%n!Q![%n!c!}%n#R#S%n#T#h%n#h#i3S#i#o%nR3XWsP}!O%n!O!P%n!Q![%n!c!}%n#R#S%n#T#g%n#g#h3q#h#o%nR3xUXQsP}!O%n!O!P%n!Q![%n!c!}%n#R#S%n#T#o%nR4aWsP}!O%n!O!P%n!Q![%n!c!}%n#R#S%n#T#f%n#f#g4y#g#o%nR5OWsP}!O%n!O!P%n!Q![%n!c!}%n#R#S%n#T#i%n#i#j5h#j#o%nR5mWsP}!O%n!O!P%n!Q![%n!c!}%n#R#S%n#T#X%n#X#Y6V#Y#o%nR6^U]QsP}!O%n!O!P%n!Q![%n!c!}%n#R#S%n#T#o%n",
|
|
921
|
-
tokenizers: [0, 1],
|
|
922
|
-
topRules: { "Filter": [0, 1] },
|
|
923
|
-
tokenPrec: 0
|
|
924
|
-
});
|
|
925
|
-
|
|
926
|
-
// src/filter-input/filter-language-parser/FilterLanguage.ts
|
|
927
|
-
var filterLanguage = import_vuu_codemirror2.LRLanguage.define({
|
|
3969
|
+
var filterLanguage = import_vuu_codemirror.LRLanguage.define({
|
|
928
3970
|
name: "VuuFilterQuery",
|
|
929
3971
|
parser: parser.configure({
|
|
930
3972
|
props: [
|
|
931
|
-
(0,
|
|
932
|
-
Identifier:
|
|
933
|
-
String:
|
|
934
|
-
Or:
|
|
935
|
-
Operator:
|
|
3973
|
+
(0, import_vuu_codemirror.styleTags)({
|
|
3974
|
+
Identifier: import_vuu_codemirror.tags.variableName,
|
|
3975
|
+
String: import_vuu_codemirror.tags.string,
|
|
3976
|
+
Or: import_vuu_codemirror.tags.emphasis,
|
|
3977
|
+
Operator: import_vuu_codemirror.tags.operator
|
|
936
3978
|
})
|
|
937
3979
|
]
|
|
938
3980
|
})
|
|
939
3981
|
});
|
|
940
3982
|
var filterLanguageSupport = () => {
|
|
941
|
-
return new
|
|
942
|
-
};
|
|
943
|
-
|
|
944
|
-
// src/filter-input/filter-language-parser/FilterTreeWalker.ts
|
|
945
|
-
var import_vuu_utils2 = require("@vuu-ui/vuu-utils");
|
|
946
|
-
var _filter;
|
|
947
|
-
var FilterExpression = class {
|
|
948
|
-
constructor() {
|
|
949
|
-
__privateAdd(this, _filter, void 0);
|
|
950
|
-
}
|
|
951
|
-
setFilterCombinatorOp(op, filter = __privateGet(this, _filter)) {
|
|
952
|
-
if ((0, import_vuu_utils2.isMultiClauseFilter)(filter) && filter.op === op) {
|
|
953
|
-
return;
|
|
954
|
-
} else {
|
|
955
|
-
__privateSet(this, _filter, {
|
|
956
|
-
op,
|
|
957
|
-
filters: [__privateGet(this, _filter)]
|
|
958
|
-
});
|
|
959
|
-
}
|
|
960
|
-
}
|
|
961
|
-
add(filter) {
|
|
962
|
-
if (__privateGet(this, _filter) === void 0) {
|
|
963
|
-
__privateSet(this, _filter, filter);
|
|
964
|
-
} else if ((0, import_vuu_utils2.isMultiClauseFilter)(__privateGet(this, _filter))) {
|
|
965
|
-
__privateGet(this, _filter).filters.push(filter);
|
|
966
|
-
} else {
|
|
967
|
-
throw Error(`Invalid filter passed to FilterExpression`);
|
|
968
|
-
}
|
|
969
|
-
}
|
|
970
|
-
setColumn(column, filter = __privateGet(this, _filter)) {
|
|
971
|
-
if ((0, import_vuu_utils2.isMultiClauseFilter)(filter)) {
|
|
972
|
-
const target = filter.filters.at(-1);
|
|
973
|
-
if (target) {
|
|
974
|
-
this.setColumn(column, target);
|
|
975
|
-
}
|
|
976
|
-
} else if (filter) {
|
|
977
|
-
filter.column = column;
|
|
978
|
-
}
|
|
979
|
-
}
|
|
980
|
-
setOp(value, filter = __privateGet(this, _filter)) {
|
|
981
|
-
if ((0, import_vuu_utils2.isMultiClauseFilter)(filter)) {
|
|
982
|
-
const target = filter.filters.at(-1);
|
|
983
|
-
if (target) {
|
|
984
|
-
this.setOp(value, target);
|
|
985
|
-
}
|
|
986
|
-
} else if (filter) {
|
|
987
|
-
filter.op = value;
|
|
988
|
-
}
|
|
989
|
-
}
|
|
990
|
-
setValue(value, filter = __privateGet(this, _filter)) {
|
|
991
|
-
var _a;
|
|
992
|
-
if ((0, import_vuu_utils2.isMultiClauseFilter)(filter)) {
|
|
993
|
-
const target = filter.filters.at(-1);
|
|
994
|
-
if (target) {
|
|
995
|
-
this.setValue(value, target);
|
|
996
|
-
}
|
|
997
|
-
} else if ((0, import_vuu_utils2.isMultiValueFilter)(filter)) {
|
|
998
|
-
(_a = filter.values) != null ? _a : filter.values = [];
|
|
999
|
-
filter.values.push(value);
|
|
1000
|
-
} else if ((0, import_vuu_utils2.isSingleValueFilter)(filter)) {
|
|
1001
|
-
filter.value = value;
|
|
1002
|
-
}
|
|
1003
|
-
}
|
|
1004
|
-
toJSON(filter = __privateGet(this, _filter)) {
|
|
1005
|
-
if (this.name) {
|
|
1006
|
-
return {
|
|
1007
|
-
...filter,
|
|
1008
|
-
name: this.name
|
|
1009
|
-
};
|
|
1010
|
-
} else {
|
|
1011
|
-
return filter;
|
|
1012
|
-
}
|
|
1013
|
-
}
|
|
1014
|
-
};
|
|
1015
|
-
_filter = new WeakMap();
|
|
1016
|
-
var walkTree = (tree, source) => {
|
|
1017
|
-
const filterExpression = new FilterExpression();
|
|
1018
|
-
const cursor = tree.cursor();
|
|
1019
|
-
do {
|
|
1020
|
-
const { name, from, to } = cursor;
|
|
1021
|
-
switch (name) {
|
|
1022
|
-
case "ColumnValueExpression":
|
|
1023
|
-
filterExpression.add({});
|
|
1024
|
-
break;
|
|
1025
|
-
case "ColumnSetExpression":
|
|
1026
|
-
filterExpression.add({ op: "in" });
|
|
1027
|
-
break;
|
|
1028
|
-
case "Or":
|
|
1029
|
-
case "And":
|
|
1030
|
-
filterExpression.setFilterCombinatorOp(source.substring(from, to));
|
|
1031
|
-
break;
|
|
1032
|
-
case "Column":
|
|
1033
|
-
filterExpression.setColumn(source.substring(from, to));
|
|
1034
|
-
break;
|
|
1035
|
-
case "Operator":
|
|
1036
|
-
filterExpression.setOp(source.substring(from, to));
|
|
1037
|
-
break;
|
|
1038
|
-
case "String":
|
|
1039
|
-
filterExpression.setValue(source.substring(from + 1, to - 1));
|
|
1040
|
-
break;
|
|
1041
|
-
case "Number":
|
|
1042
|
-
filterExpression.setValue(parseFloat(source.substring(from, to)));
|
|
1043
|
-
break;
|
|
1044
|
-
case "True":
|
|
1045
|
-
filterExpression.setValue(true);
|
|
1046
|
-
break;
|
|
1047
|
-
case "False":
|
|
1048
|
-
filterExpression.setValue(false);
|
|
1049
|
-
break;
|
|
1050
|
-
case "FilterName":
|
|
1051
|
-
filterExpression.name = source.substring(from, to);
|
|
1052
|
-
break;
|
|
1053
|
-
default:
|
|
1054
|
-
}
|
|
1055
|
-
} while (cursor.next());
|
|
1056
|
-
return filterExpression.toJSON();
|
|
1057
|
-
};
|
|
1058
|
-
|
|
1059
|
-
// src/filter-input/filter-language-parser/FilterParser.ts
|
|
1060
|
-
var strictParser = parser.configure({ strict: true });
|
|
1061
|
-
var parseFilter = (filterQuery) => {
|
|
1062
|
-
const parseTree = strictParser.parse(filterQuery);
|
|
1063
|
-
const filter = walkTree(parseTree, filterQuery);
|
|
1064
|
-
return filter;
|
|
3983
|
+
return new import_vuu_codemirror.LanguageSupport(filterLanguage);
|
|
1065
3984
|
};
|
|
1066
3985
|
|
|
1067
3986
|
// src/filter-input/highlighting.ts
|
|
1068
|
-
var
|
|
1069
|
-
var myHighlightStyle =
|
|
1070
|
-
{ tag:
|
|
1071
|
-
{ tag:
|
|
3987
|
+
var import_vuu_codemirror2 = require("@vuu-ui/vuu-codemirror");
|
|
3988
|
+
var myHighlightStyle = import_vuu_codemirror2.HighlightStyle.define([
|
|
3989
|
+
{ tag: import_vuu_codemirror2.tags.variableName, color: "var(--vuuFilterEditor-variableColor)" },
|
|
3990
|
+
{ tag: import_vuu_codemirror2.tags.comment, color: "green", fontStyle: "italic" }
|
|
1072
3991
|
]);
|
|
1073
|
-
var vuuHighlighting = (0,
|
|
3992
|
+
var vuuHighlighting = (0, import_vuu_codemirror2.syntaxHighlighting)(myHighlightStyle);
|
|
1074
3993
|
|
|
1075
3994
|
// src/filter-input/theme.ts
|
|
1076
|
-
var
|
|
1077
|
-
var vuuTheme =
|
|
3995
|
+
var import_vuu_codemirror3 = require("@vuu-ui/vuu-codemirror");
|
|
3996
|
+
var vuuTheme = import_vuu_codemirror3.EditorView.theme(
|
|
1078
3997
|
{
|
|
1079
3998
|
"&": {
|
|
1080
3999
|
color: "var(--vuuFilterEditor-color)",
|
|
@@ -1147,21 +4066,21 @@ var vuuTheme = import_vuu_codemirror4.EditorView.theme(
|
|
|
1147
4066
|
);
|
|
1148
4067
|
|
|
1149
4068
|
// src/filter-input/useFilterAutoComplete.ts
|
|
1150
|
-
var
|
|
1151
|
-
var
|
|
4069
|
+
var import_vuu_codemirror4 = require("@vuu-ui/vuu-codemirror");
|
|
4070
|
+
var import_react12 = require("react");
|
|
1152
4071
|
var getOperator = (node, state) => {
|
|
1153
4072
|
let maybeColumnNode = node.prevSibling || node.parent;
|
|
1154
4073
|
while (maybeColumnNode && !["Column", "Operator", "In"].includes(maybeColumnNode.name)) {
|
|
1155
4074
|
maybeColumnNode = maybeColumnNode.prevSibling || maybeColumnNode.parent;
|
|
1156
4075
|
}
|
|
1157
4076
|
if ((maybeColumnNode == null ? void 0 : maybeColumnNode.name) === "In" || (maybeColumnNode == null ? void 0 : maybeColumnNode.name) === "Operator") {
|
|
1158
|
-
return (0,
|
|
4077
|
+
return (0, import_vuu_codemirror4.getValue)(maybeColumnNode, state);
|
|
1159
4078
|
} else {
|
|
1160
4079
|
return void 0;
|
|
1161
4080
|
}
|
|
1162
4081
|
};
|
|
1163
4082
|
var getPartialOperator = (maybeOperatorNode, state, columnName) => {
|
|
1164
|
-
const value = (0,
|
|
4083
|
+
const value = (0, import_vuu_codemirror4.getValue)(maybeOperatorNode, state);
|
|
1165
4084
|
if (columnName === void 0 || value === columnName) {
|
|
1166
4085
|
return;
|
|
1167
4086
|
}
|
|
@@ -1178,27 +4097,27 @@ var getClauseOperator = (node, state) => {
|
|
|
1178
4097
|
while (maybeTargetNode && maybeTargetNode.name === "\u26A0")
|
|
1179
4098
|
maybeTargetNode = maybeTargetNode.prevSibling;
|
|
1180
4099
|
if (maybeTargetNode && ["As", "Or", "And"].includes(maybeTargetNode.name)) {
|
|
1181
|
-
return (0,
|
|
4100
|
+
return (0, import_vuu_codemirror4.getValue)(maybeTargetNode, state);
|
|
1182
4101
|
} else {
|
|
1183
4102
|
return void 0;
|
|
1184
4103
|
}
|
|
1185
4104
|
};
|
|
1186
4105
|
var getFilterName = (node, state) => {
|
|
1187
4106
|
if (node.name === "FilterName") {
|
|
1188
|
-
return (0,
|
|
4107
|
+
return (0, import_vuu_codemirror4.getValue)(node, state);
|
|
1189
4108
|
} else {
|
|
1190
4109
|
let maybeTargetNode = node.prevSibling || node.parent || node.lastChild;
|
|
1191
4110
|
while (maybeTargetNode && maybeTargetNode.name !== "FilterName")
|
|
1192
4111
|
maybeTargetNode = maybeTargetNode.prevSibling;
|
|
1193
4112
|
if (maybeTargetNode && maybeTargetNode.name === "FilterName") {
|
|
1194
|
-
return (0,
|
|
4113
|
+
return (0, import_vuu_codemirror4.getValue)(node, state);
|
|
1195
4114
|
}
|
|
1196
4115
|
}
|
|
1197
4116
|
};
|
|
1198
4117
|
var getColumnName = (node, state) => {
|
|
1199
4118
|
const prevNode = node.prevSibling;
|
|
1200
4119
|
if ((prevNode == null ? void 0 : prevNode.name) === "Column") {
|
|
1201
|
-
return (0,
|
|
4120
|
+
return (0, import_vuu_codemirror4.getValue)(prevNode, state);
|
|
1202
4121
|
} else if ((prevNode == null ? void 0 : prevNode.name) === "Operator") {
|
|
1203
4122
|
return getColumnName(prevNode, state);
|
|
1204
4123
|
}
|
|
@@ -1207,7 +4126,7 @@ var getSetValues = (node, state) => {
|
|
|
1207
4126
|
let maybeTargetNode = node.lastChild;
|
|
1208
4127
|
const values = [];
|
|
1209
4128
|
while (maybeTargetNode && maybeTargetNode.name !== "In") {
|
|
1210
|
-
const value = (0,
|
|
4129
|
+
const value = (0, import_vuu_codemirror4.getValue)(maybeTargetNode, state);
|
|
1211
4130
|
if (value) {
|
|
1212
4131
|
values.push(value);
|
|
1213
4132
|
} else {
|
|
@@ -1218,7 +4137,7 @@ var getSetValues = (node, state) => {
|
|
|
1218
4137
|
return values;
|
|
1219
4138
|
};
|
|
1220
4139
|
var useAutoComplete = (suggestionProvider, onSubmit, existingFilter) => {
|
|
1221
|
-
const makeSuggestions = (0,
|
|
4140
|
+
const makeSuggestions = (0, import_react12.useCallback)(
|
|
1222
4141
|
async (context, suggestionType, optionalArgs = {}) => {
|
|
1223
4142
|
const { startsWith = "" } = optionalArgs;
|
|
1224
4143
|
const options = await suggestionProvider.getSuggestions(
|
|
@@ -1229,7 +4148,7 @@ var useAutoComplete = (suggestionProvider, onSubmit, existingFilter) => {
|
|
|
1229
4148
|
},
|
|
1230
4149
|
[suggestionProvider]
|
|
1231
4150
|
);
|
|
1232
|
-
return (0,
|
|
4151
|
+
return (0, import_react12.useCallback)(
|
|
1233
4152
|
async (context) => {
|
|
1234
4153
|
var _a, _b;
|
|
1235
4154
|
const { state, pos } = context;
|
|
@@ -1238,7 +4157,7 @@ var useAutoComplete = (suggestionProvider, onSubmit, existingFilter) => {
|
|
|
1238
4157
|
to: 0,
|
|
1239
4158
|
text: void 0
|
|
1240
4159
|
};
|
|
1241
|
-
const tree = (0,
|
|
4160
|
+
const tree = (0, import_vuu_codemirror4.syntaxTree)(state);
|
|
1242
4161
|
const nodeBefore = tree.resolveInner(pos, -1);
|
|
1243
4162
|
console.log({ nodeBeforeName: nodeBefore.name });
|
|
1244
4163
|
switch (nodeBefore.name) {
|
|
@@ -1288,7 +4207,7 @@ var useAutoComplete = (suggestionProvider, onSubmit, existingFilter) => {
|
|
|
1288
4207
|
filterName: getFilterName(nodeBefore, state)
|
|
1289
4208
|
});
|
|
1290
4209
|
case "Column": {
|
|
1291
|
-
const columnName = (0,
|
|
4210
|
+
const columnName = (0, import_vuu_codemirror4.getValue)(nodeBefore, state);
|
|
1292
4211
|
const isPartialMatch = await suggestionProvider.isPartialMatch(
|
|
1293
4212
|
"column",
|
|
1294
4213
|
void 0,
|
|
@@ -1303,7 +4222,7 @@ var useAutoComplete = (suggestionProvider, onSubmit, existingFilter) => {
|
|
|
1303
4222
|
}
|
|
1304
4223
|
}
|
|
1305
4224
|
case "\u26A0": {
|
|
1306
|
-
const columnName = (0,
|
|
4225
|
+
const columnName = (0, import_vuu_codemirror4.getNodeByName)(nodeBefore, state);
|
|
1307
4226
|
const operator = getOperator(nodeBefore, state);
|
|
1308
4227
|
const partialOperator = operator ? void 0 : getPartialOperator(nodeBefore, state, columnName);
|
|
1309
4228
|
if (partialOperator) {
|
|
@@ -1338,7 +4257,7 @@ var useAutoComplete = (suggestionProvider, onSubmit, existingFilter) => {
|
|
|
1338
4257
|
break;
|
|
1339
4258
|
case "ColumnSetExpression":
|
|
1340
4259
|
case "Values": {
|
|
1341
|
-
const columnName = (0,
|
|
4260
|
+
const columnName = (0, import_vuu_codemirror4.getNodeByName)(nodeBefore, state);
|
|
1342
4261
|
const selection = getSetValues(nodeBefore, state);
|
|
1343
4262
|
return makeSuggestions(context, "columnValue", {
|
|
1344
4263
|
columnName,
|
|
@@ -1347,7 +4266,7 @@ var useAutoComplete = (suggestionProvider, onSubmit, existingFilter) => {
|
|
|
1347
4266
|
}
|
|
1348
4267
|
case "Comma":
|
|
1349
4268
|
case "LBrack": {
|
|
1350
|
-
const columnName = (0,
|
|
4269
|
+
const columnName = (0, import_vuu_codemirror4.getNodeByName)(nodeBefore, state);
|
|
1351
4270
|
return makeSuggestions(context, "columnValue", { columnName });
|
|
1352
4271
|
}
|
|
1353
4272
|
case "ColumnValueExpression":
|
|
@@ -1355,12 +4274,12 @@ var useAutoComplete = (suggestionProvider, onSubmit, existingFilter) => {
|
|
|
1355
4274
|
const lastToken = (_b = nodeBefore.lastChild) == null ? void 0 : _b.prevSibling;
|
|
1356
4275
|
if ((lastToken == null ? void 0 : lastToken.name) === "Column") {
|
|
1357
4276
|
return makeSuggestions(context, "operator", {
|
|
1358
|
-
columnName: (0,
|
|
4277
|
+
columnName: (0, import_vuu_codemirror4.getNodeByName)(nodeBefore, state)
|
|
1359
4278
|
});
|
|
1360
4279
|
} else if ((lastToken == null ? void 0 : lastToken.name) === "Operator") {
|
|
1361
4280
|
return makeSuggestions(context, "columnValue", {
|
|
1362
|
-
columnName: (0,
|
|
1363
|
-
operator: (0,
|
|
4281
|
+
columnName: (0, import_vuu_codemirror4.getNodeByName)(lastToken, state),
|
|
4282
|
+
operator: (0, import_vuu_codemirror4.getValue)(lastToken, state)
|
|
1364
4283
|
});
|
|
1365
4284
|
}
|
|
1366
4285
|
}
|
|
@@ -1373,7 +4292,7 @@ var useAutoComplete = (suggestionProvider, onSubmit, existingFilter) => {
|
|
|
1373
4292
|
}
|
|
1374
4293
|
case "Eq": {
|
|
1375
4294
|
return makeSuggestions(context, "columnValue", {
|
|
1376
|
-
columnName: (0,
|
|
4295
|
+
columnName: (0, import_vuu_codemirror4.getNodeByName)(nodeBefore, state)
|
|
1377
4296
|
});
|
|
1378
4297
|
}
|
|
1379
4298
|
case "AndExpression":
|
|
@@ -1413,19 +4332,19 @@ var useCodeMirrorEditor = ({
|
|
|
1413
4332
|
onSubmitFilter,
|
|
1414
4333
|
suggestionProvider
|
|
1415
4334
|
}) => {
|
|
1416
|
-
const editorRef = (0,
|
|
1417
|
-
const onSubmit = (0,
|
|
1418
|
-
const viewRef = (0,
|
|
4335
|
+
const editorRef = (0, import_react13.useRef)(null);
|
|
4336
|
+
const onSubmit = (0, import_react13.useRef)(noop);
|
|
4337
|
+
const viewRef = (0, import_react13.useRef)();
|
|
1419
4338
|
const completionFn = useAutoComplete(
|
|
1420
4339
|
suggestionProvider,
|
|
1421
4340
|
onSubmit,
|
|
1422
4341
|
existingFilter
|
|
1423
4342
|
);
|
|
1424
|
-
const [createState, clearInput] = (0,
|
|
4343
|
+
const [createState, clearInput] = (0, import_react13.useMemo)(() => {
|
|
1425
4344
|
const parseFilter2 = () => {
|
|
1426
4345
|
const view = getView(viewRef);
|
|
1427
4346
|
const source = view.state.doc.toString();
|
|
1428
|
-
const tree = (0,
|
|
4347
|
+
const tree = (0, import_vuu_codemirror5.ensureSyntaxTree)(view.state, view.state.doc.length, 5e3);
|
|
1429
4348
|
if (tree) {
|
|
1430
4349
|
const filter = walkTree(tree, source);
|
|
1431
4350
|
return [filter, stripName(source), filter.name];
|
|
@@ -1442,7 +4361,7 @@ var useCodeMirrorEditor = ({
|
|
|
1442
4361
|
clearInput2();
|
|
1443
4362
|
};
|
|
1444
4363
|
const submitFilter = (key) => {
|
|
1445
|
-
return
|
|
4364
|
+
return import_vuu_codemirror5.keymap.of([
|
|
1446
4365
|
{
|
|
1447
4366
|
key,
|
|
1448
4367
|
run() {
|
|
@@ -1453,35 +4372,35 @@ var useCodeMirrorEditor = ({
|
|
|
1453
4372
|
]);
|
|
1454
4373
|
};
|
|
1455
4374
|
const showSuggestions = (key) => {
|
|
1456
|
-
return
|
|
4375
|
+
return import_vuu_codemirror5.keymap.of([
|
|
1457
4376
|
{
|
|
1458
4377
|
key,
|
|
1459
4378
|
run() {
|
|
1460
|
-
(0,
|
|
4379
|
+
(0, import_vuu_codemirror5.startCompletion)(getView(viewRef));
|
|
1461
4380
|
return true;
|
|
1462
4381
|
}
|
|
1463
4382
|
}
|
|
1464
4383
|
]);
|
|
1465
4384
|
};
|
|
1466
|
-
const createState2 = () =>
|
|
4385
|
+
const createState2 = () => import_vuu_codemirror5.EditorState.create({
|
|
1467
4386
|
doc: "",
|
|
1468
4387
|
extensions: [
|
|
1469
|
-
|
|
1470
|
-
(0,
|
|
4388
|
+
import_vuu_codemirror5.minimalSetup,
|
|
4389
|
+
(0, import_vuu_codemirror5.autocompletion)({
|
|
1471
4390
|
override: [completionFn],
|
|
1472
4391
|
optionClass: getOptionClass
|
|
1473
4392
|
}),
|
|
1474
4393
|
filterLanguageSupport(),
|
|
1475
|
-
|
|
4394
|
+
import_vuu_codemirror5.keymap.of(import_vuu_codemirror5.defaultKeymap),
|
|
1476
4395
|
submitFilter("Ctrl-Enter"),
|
|
1477
4396
|
showSuggestions("ArrowDown"),
|
|
1478
|
-
|
|
4397
|
+
import_vuu_codemirror5.EditorView.updateListener.of((v) => {
|
|
1479
4398
|
const view = getView(viewRef);
|
|
1480
4399
|
if (v.docChanged) {
|
|
1481
|
-
(0,
|
|
4400
|
+
(0, import_vuu_codemirror5.startCompletion)(view);
|
|
1482
4401
|
}
|
|
1483
4402
|
}),
|
|
1484
|
-
|
|
4403
|
+
import_vuu_codemirror5.EditorState.transactionFilter.of(
|
|
1485
4404
|
(tr) => tr.newDoc.lines > 1 ? [] : tr
|
|
1486
4405
|
),
|
|
1487
4406
|
vuuTheme,
|
|
@@ -1496,11 +4415,11 @@ var useCodeMirrorEditor = ({
|
|
|
1496
4415
|
};
|
|
1497
4416
|
return [createState2, clearInput2];
|
|
1498
4417
|
}, [completionFn, onSubmitFilter]);
|
|
1499
|
-
(0,
|
|
4418
|
+
(0, import_react13.useEffect)(() => {
|
|
1500
4419
|
if (!editorRef.current) {
|
|
1501
4420
|
throw Error("editor not in dom");
|
|
1502
4421
|
}
|
|
1503
|
-
viewRef.current = new
|
|
4422
|
+
viewRef.current = new import_vuu_codemirror5.EditorView({
|
|
1504
4423
|
state: createState(),
|
|
1505
4424
|
parent: editorRef.current
|
|
1506
4425
|
});
|
|
@@ -1550,18 +4469,17 @@ var FilterInput = ({
|
|
|
1550
4469
|
};
|
|
1551
4470
|
|
|
1552
4471
|
// src/filter-input/useFilterSuggestionProvider.ts
|
|
1553
|
-
var
|
|
1554
|
-
var
|
|
1555
|
-
var import_react8 = require("react");
|
|
4472
|
+
var import_vuu_codemirror6 = require("@vuu-ui/vuu-codemirror");
|
|
4473
|
+
var import_react14 = require("react");
|
|
1556
4474
|
|
|
1557
4475
|
// src/filter-input/filterInfo.ts
|
|
1558
|
-
var
|
|
4476
|
+
var import_vuu_utils6 = require("@vuu-ui/vuu-utils");
|
|
1559
4477
|
var filterInfo = (filterName, filterQuery) => {
|
|
1560
|
-
const rootElement = (0,
|
|
1561
|
-
const headingElement = (0,
|
|
1562
|
-
const nameElement = (0,
|
|
4478
|
+
const rootElement = (0, import_vuu_utils6.createEl)("div", "vuuFunctionDoc");
|
|
4479
|
+
const headingElement = (0, import_vuu_utils6.createEl)("div", "function-heading");
|
|
4480
|
+
const nameElement = (0, import_vuu_utils6.createEl)("span", "function-name", filterName);
|
|
1563
4481
|
headingElement.appendChild(nameElement);
|
|
1564
|
-
const child2 = (0,
|
|
4482
|
+
const child2 = (0, import_vuu_utils6.createEl)("p", void 0, filterQuery);
|
|
1565
4483
|
rootElement.appendChild(headingElement);
|
|
1566
4484
|
rootElement.appendChild(child2);
|
|
1567
4485
|
return rootElement;
|
|
@@ -1601,7 +4519,7 @@ var makeSaveOrExtendSuggestions = (onSubmit, existingFilter, withJoinSuggestions
|
|
|
1601
4519
|
boost: 6
|
|
1602
4520
|
}
|
|
1603
4521
|
];
|
|
1604
|
-
return withJoinSuggestions ? result.concat(
|
|
4522
|
+
return withJoinSuggestions ? result.concat(import_vuu_codemirror6.booleanJoinSuggestions).concat(import_vuu_codemirror6.asNameSuggestion) : result;
|
|
1605
4523
|
};
|
|
1606
4524
|
var promptToSaveOrExtend = (onSubmit, existingFilter) => makeSaveOrExtendSuggestions(onSubmit, existingFilter, true);
|
|
1607
4525
|
var promptToSave = (onSubmit) => makeSaveOrExtendSuggestions(onSubmit, void 0);
|
|
@@ -1646,11 +4564,11 @@ var useFilterSuggestionProvider = ({
|
|
|
1646
4564
|
namedFilters,
|
|
1647
4565
|
saveOptions = defaultSaveOptions,
|
|
1648
4566
|
table,
|
|
1649
|
-
typeaheadHook: useTypeahead =
|
|
4567
|
+
typeaheadHook: useTypeahead = useTypeaheadSuggestions
|
|
1650
4568
|
}) => {
|
|
1651
|
-
const latestSuggestionsRef = (0,
|
|
4569
|
+
const latestSuggestionsRef = (0, import_react14.useRef)();
|
|
1652
4570
|
const getTypeaheadSuggestions = useTypeahead();
|
|
1653
|
-
const getSuggestions = (0,
|
|
4571
|
+
const getSuggestions = (0, import_react14.useCallback)(
|
|
1654
4572
|
async (suggestionType, options = NONE) => {
|
|
1655
4573
|
const {
|
|
1656
4574
|
columnName,
|
|
@@ -1670,11 +4588,11 @@ var useFilterSuggestionProvider = ({
|
|
|
1670
4588
|
switch (column.serverDataType) {
|
|
1671
4589
|
case "string":
|
|
1672
4590
|
case "char":
|
|
1673
|
-
return withApplySpace(
|
|
4591
|
+
return withApplySpace(import_vuu_codemirror6.stringOperators, startsWith);
|
|
1674
4592
|
case "int":
|
|
1675
4593
|
case "long":
|
|
1676
4594
|
case "double":
|
|
1677
|
-
return withApplySpace(
|
|
4595
|
+
return withApplySpace(import_vuu_codemirror6.numericOperators);
|
|
1678
4596
|
}
|
|
1679
4597
|
} else {
|
|
1680
4598
|
console.warn(`'${columnName}' does not match any column name`);
|
|
@@ -1698,14 +4616,14 @@ var useFilterSuggestionProvider = ({
|
|
|
1698
4616
|
);
|
|
1699
4617
|
}
|
|
1700
4618
|
const prefix = Array.isArray(selection) ? selection.length === 0 ? "[" : "," : "";
|
|
1701
|
-
const params =
|
|
4619
|
+
const params = getTypeaheadParams(
|
|
1702
4620
|
table,
|
|
1703
4621
|
columnName,
|
|
1704
4622
|
startsWith
|
|
1705
4623
|
);
|
|
1706
4624
|
const suggestions = await getTypeaheadSuggestions(params);
|
|
1707
4625
|
const isIllustration = operator === "starts";
|
|
1708
|
-
latestSuggestionsRef.current = (0,
|
|
4626
|
+
latestSuggestionsRef.current = (0, import_vuu_codemirror6.toSuggestions)(suggestions, {
|
|
1709
4627
|
moveCursorToEnd: autoQuoted,
|
|
1710
4628
|
quoted: (column == null ? void 0 : column.serverDataType) === "string" && !autoQuoted,
|
|
1711
4629
|
suffix: autoQuoted ? "" : " ",
|
|
@@ -1733,14 +4651,14 @@ var useFilterSuggestionProvider = ({
|
|
|
1733
4651
|
});
|
|
1734
4652
|
}
|
|
1735
4653
|
case "name":
|
|
1736
|
-
return await (0,
|
|
4654
|
+
return await (0, import_vuu_codemirror6.getNamePrompt)("filter");
|
|
1737
4655
|
default:
|
|
1738
4656
|
}
|
|
1739
4657
|
return [];
|
|
1740
4658
|
},
|
|
1741
4659
|
[columns, getTypeaheadSuggestions, namedFilters, saveOptions, table]
|
|
1742
4660
|
);
|
|
1743
|
-
const isPartialMatch = (0,
|
|
4661
|
+
const isPartialMatch = (0, import_react14.useCallback)(
|
|
1744
4662
|
async (valueType, columnName, pattern) => {
|
|
1745
4663
|
const suggestions = (
|
|
1746
4664
|
// latestSuggestions && latestSuggestions.length > 0
|
|
@@ -1771,11 +4689,12 @@ var import_salt_lab8 = require("@heswell/salt-lab");
|
|
|
1771
4689
|
var import_classnames2 = __toESM(require_classnames(), 1);
|
|
1772
4690
|
|
|
1773
4691
|
// src/filter-toolbar/useFilterToolbar.tsx
|
|
4692
|
+
var import_vuu_utils7 = require("@vuu-ui/vuu-utils");
|
|
1774
4693
|
var import_salt_lab7 = require("@heswell/salt-lab");
|
|
1775
4694
|
|
|
1776
4695
|
// src/filter-toolbar/FilterDropdown.tsx
|
|
1777
4696
|
var import_salt_lab5 = require("@heswell/salt-lab");
|
|
1778
|
-
var
|
|
4697
|
+
var import_react15 = require("react");
|
|
1779
4698
|
var import_jsx_runtime8 = require("react/jsx-runtime");
|
|
1780
4699
|
var isString = (s) => typeof s === "string";
|
|
1781
4700
|
var stripQuotes = (selected) => {
|
|
@@ -1797,9 +4716,9 @@ var FilterDropdown = ({
|
|
|
1797
4716
|
}) => {
|
|
1798
4717
|
const selected = selectedProp != null ? stripQuotes(selectedProp) : void 0;
|
|
1799
4718
|
const initialValues = Array.isArray(selected) ? selected : selected != null ? [selected] : [];
|
|
1800
|
-
const [values, setValues] = (0,
|
|
4719
|
+
const [values, setValues] = (0, import_react15.useState)(initialValues);
|
|
1801
4720
|
console.log({ initialValues });
|
|
1802
|
-
const handleOpenChange = (0,
|
|
4721
|
+
const handleOpenChange = (0, import_react15.useCallback)(
|
|
1803
4722
|
async (isOpen) => {
|
|
1804
4723
|
if (isOpen) {
|
|
1805
4724
|
const values2 = await suggestionProvider.getSuggestions("columnValue", {
|
|
@@ -1824,7 +4743,7 @@ var FilterDropdown = ({
|
|
|
1824
4743
|
|
|
1825
4744
|
// src/filter-toolbar/FilterDropdownMultiSelect.tsx
|
|
1826
4745
|
var import_salt_lab6 = require("@heswell/salt-lab");
|
|
1827
|
-
var
|
|
4746
|
+
var import_react16 = require("react");
|
|
1828
4747
|
var import_jsx_runtime9 = require("react/jsx-runtime");
|
|
1829
4748
|
var isString2 = (s) => typeof s === "string";
|
|
1830
4749
|
var stripQuotes2 = (selected) => {
|
|
@@ -1848,8 +4767,8 @@ var FilterDropdownMultiSelect = ({
|
|
|
1848
4767
|
}) => {
|
|
1849
4768
|
const selected = stripQuotes2(selectedProp);
|
|
1850
4769
|
const initialValues = Array.isArray(selected) ? selected : selected != null ? [selected] : [];
|
|
1851
|
-
const [values, setValues] = (0,
|
|
1852
|
-
const handleOpenChange = (0,
|
|
4770
|
+
const [values, setValues] = (0, import_react16.useState)(initialValues);
|
|
4771
|
+
const handleOpenChange = (0, import_react16.useCallback)(
|
|
1853
4772
|
async (isOpen) => {
|
|
1854
4773
|
if (isOpen) {
|
|
1855
4774
|
const values2 = await suggestionProvider.getSuggestions("columnValue", {
|
|
@@ -1876,7 +4795,7 @@ var FilterDropdownMultiSelect = ({
|
|
|
1876
4795
|
// src/filter-toolbar/useFilterToolbar.tsx
|
|
1877
4796
|
var import_jsx_runtime10 = require("react/jsx-runtime");
|
|
1878
4797
|
var filterToControl = (filter, suggestionProvider) => {
|
|
1879
|
-
if (isNamedFilter(filter)) {
|
|
4798
|
+
if ((0, import_vuu_utils7.isNamedFilter)(filter)) {
|
|
1880
4799
|
return /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(
|
|
1881
4800
|
import_salt_lab7.ToggleButton,
|
|
1882
4801
|
{
|
|
@@ -1887,7 +4806,7 @@ var filterToControl = (filter, suggestionProvider) => {
|
|
|
1887
4806
|
}
|
|
1888
4807
|
);
|
|
1889
4808
|
}
|
|
1890
|
-
if (isSingleValueFilter(filter)) {
|
|
4809
|
+
if ((0, import_vuu_utils7.isSingleValueFilter)(filter)) {
|
|
1891
4810
|
const { column, value } = filter;
|
|
1892
4811
|
return /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(
|
|
1893
4812
|
import_salt_lab7.ToolbarField,
|
|
@@ -1910,7 +4829,7 @@ var filterToControl = (filter, suggestionProvider) => {
|
|
|
1910
4829
|
column
|
|
1911
4830
|
);
|
|
1912
4831
|
}
|
|
1913
|
-
if (isMultiValueFilter(filter)) {
|
|
4832
|
+
if ((0, import_vuu_utils7.isMultiValueFilter)(filter)) {
|
|
1914
4833
|
const values = filter.values.map((v) => v.toString());
|
|
1915
4834
|
return /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(
|
|
1916
4835
|
import_salt_lab7.ToolbarField,
|
|
@@ -1958,91 +4877,6 @@ var FilterToolbar = ({
|
|
|
1958
4877
|
const toolbarItems = useFilterToolbar({ filter, suggestionProvider });
|
|
1959
4878
|
return /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(import_salt_lab8.Toolbar, { className: (0, import_classnames2.default)("vuuFilterToolbar", className), ...props, children: toolbarItems });
|
|
1960
4879
|
};
|
|
1961
|
-
|
|
1962
|
-
// src/filter-evaluation-utils.ts
|
|
1963
|
-
var filterPredicateMap = /* @__PURE__ */ new Map();
|
|
1964
|
-
var filterReject = () => false;
|
|
1965
|
-
var getFilterPredicate = (columnMap, filterQuery) => {
|
|
1966
|
-
let predicate = filterPredicateMap.get(filterQuery);
|
|
1967
|
-
if (predicate) {
|
|
1968
|
-
return predicate;
|
|
1969
|
-
}
|
|
1970
|
-
try {
|
|
1971
|
-
const filter = parseFilter(filterQuery);
|
|
1972
|
-
predicate = filterPredicate(columnMap, filter);
|
|
1973
|
-
filterPredicateMap.set(filterQuery, predicate);
|
|
1974
|
-
return predicate;
|
|
1975
|
-
} catch (err) {
|
|
1976
|
-
console.warn(
|
|
1977
|
-
`filter-evaluation-utils, failed to parse filter "${filterQuery}"`
|
|
1978
|
-
);
|
|
1979
|
-
return filterReject;
|
|
1980
|
-
}
|
|
1981
|
-
};
|
|
1982
|
-
function filterPredicate(columnMap, filter) {
|
|
1983
|
-
switch (filter.op) {
|
|
1984
|
-
case "in":
|
|
1985
|
-
return testInclude(columnMap, filter);
|
|
1986
|
-
case "=":
|
|
1987
|
-
return testEQ(columnMap, filter);
|
|
1988
|
-
case ">":
|
|
1989
|
-
return testGT(columnMap, filter);
|
|
1990
|
-
case ">=":
|
|
1991
|
-
return testGE(columnMap, filter);
|
|
1992
|
-
case "<":
|
|
1993
|
-
return testLT(columnMap, filter);
|
|
1994
|
-
case "<=":
|
|
1995
|
-
return testLE(columnMap, filter);
|
|
1996
|
-
case "starts":
|
|
1997
|
-
return testSW(columnMap, filter);
|
|
1998
|
-
case "and":
|
|
1999
|
-
return testAND(columnMap, filter);
|
|
2000
|
-
case "or":
|
|
2001
|
-
return testOR(columnMap, filter);
|
|
2002
|
-
default:
|
|
2003
|
-
console.log(`unrecognized filter type ${filter.op}`);
|
|
2004
|
-
return () => true;
|
|
2005
|
-
}
|
|
2006
|
-
}
|
|
2007
|
-
var testInclude = (columnMap, filter) => {
|
|
2008
|
-
return (row) => filter.values.indexOf(row[columnMap[filter.column]]) !== -1;
|
|
2009
|
-
};
|
|
2010
|
-
var testEQ = (columnMap, filter) => {
|
|
2011
|
-
return (row) => row[columnMap[filter.column]] === filter.value;
|
|
2012
|
-
};
|
|
2013
|
-
var testGT = (columnMap, filter) => {
|
|
2014
|
-
return (row) => row[columnMap[filter.column]] > filter.value;
|
|
2015
|
-
};
|
|
2016
|
-
var testGE = (columnMap, filter) => {
|
|
2017
|
-
return (row) => row[columnMap[filter.column]] >= filter.value;
|
|
2018
|
-
};
|
|
2019
|
-
var testLT = (columnMap, filter) => {
|
|
2020
|
-
return (row) => row[columnMap[filter.column]] < filter.value;
|
|
2021
|
-
};
|
|
2022
|
-
var testLE = (columnMap, filter) => {
|
|
2023
|
-
return (row) => row[columnMap[filter.column]] <= filter.value;
|
|
2024
|
-
};
|
|
2025
|
-
var testSW = (columnMap, filter) => {
|
|
2026
|
-
const filterValue2 = filter.value;
|
|
2027
|
-
if (typeof filterValue2 !== "string") {
|
|
2028
|
-
throw Error("string filter applied to value of wrong type");
|
|
2029
|
-
}
|
|
2030
|
-
return (row) => {
|
|
2031
|
-
const rowValue = row[columnMap[filter.column]];
|
|
2032
|
-
if (typeof rowValue !== "string") {
|
|
2033
|
-
throw Error("string filter applied to value of wrong type");
|
|
2034
|
-
}
|
|
2035
|
-
return rowValue.toLowerCase().startsWith(filterValue2.toLowerCase());
|
|
2036
|
-
};
|
|
2037
|
-
};
|
|
2038
|
-
var testAND = (columnMap, filter) => {
|
|
2039
|
-
const filters = filter.filters.map((f1) => filterPredicate(columnMap, f1));
|
|
2040
|
-
return (row) => filters.every((fn) => fn(row));
|
|
2041
|
-
};
|
|
2042
|
-
function testOR(columnMap, filter) {
|
|
2043
|
-
const filters = filter.filters.map((f1) => filterPredicate(columnMap, f1));
|
|
2044
|
-
return (row) => filters.some((fn) => fn(row));
|
|
2045
|
-
}
|
|
2046
4880
|
/*! Bundled license information:
|
|
2047
4881
|
|
|
2048
4882
|
classnames/index.js:
|