mol_db 0.0.583 → 0.0.585
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/node.d.ts +74 -28
- package/node.deps.json +1 -1
- package/node.js +346 -257
- package/node.js.map +1 -1
- package/node.mjs +346 -257
- package/node.mjs.map +1 -1
- package/node.test.js +509 -305
- package/node.test.js.map +1 -1
- package/package.json +10 -2
- package/web.deps.json +1 -1
package/node.test.js
CHANGED
|
@@ -267,248 +267,167 @@ var $;
|
|
|
267
267
|
"use strict";
|
|
268
268
|
var $;
|
|
269
269
|
(function ($) {
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
data;
|
|
274
|
-
sub;
|
|
275
|
-
baseUri;
|
|
270
|
+
class $mol_span extends $mol_object2 {
|
|
271
|
+
uri;
|
|
272
|
+
source;
|
|
276
273
|
row;
|
|
277
274
|
col;
|
|
278
275
|
length;
|
|
279
|
-
constructor(
|
|
276
|
+
constructor(uri, source, row, col, length) {
|
|
280
277
|
super();
|
|
281
|
-
this.
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
}
|
|
288
|
-
else {
|
|
289
|
-
this.data = sub[0].data;
|
|
290
|
-
this.sub = config.sub || [];
|
|
291
|
-
}
|
|
292
|
-
}
|
|
293
|
-
else {
|
|
294
|
-
this.data = config.data || '';
|
|
295
|
-
this.sub = config.sub || [];
|
|
296
|
-
}
|
|
297
|
-
this.baseUri = config.baseUri || '';
|
|
298
|
-
this.row = config.row || 0;
|
|
299
|
-
this.col = config.col || 0;
|
|
300
|
-
this.length = config.length || 0;
|
|
301
|
-
}
|
|
302
|
-
static values(str, baseUri) {
|
|
303
|
-
return str.split('\n').map((data, index) => new $mol_tree({
|
|
304
|
-
data: data,
|
|
305
|
-
baseUri: baseUri,
|
|
306
|
-
row: index + 1,
|
|
307
|
-
length: data.length,
|
|
308
|
-
}));
|
|
278
|
+
this.uri = uri;
|
|
279
|
+
this.source = source;
|
|
280
|
+
this.row = row;
|
|
281
|
+
this.col = col;
|
|
282
|
+
this.length = length;
|
|
283
|
+
this[Symbol.toStringTag] = `${this.uri}#${this.row}:${this.col}/${this.length}`;
|
|
309
284
|
}
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
row: ('row' in config) ? config.row : this.row,
|
|
317
|
-
col: ('col' in config) ? config.col : this.col,
|
|
318
|
-
length: ('length' in config) ? config.length : this.length,
|
|
319
|
-
value: config.value
|
|
320
|
-
});
|
|
285
|
+
static unknown = $mol_span.begin('?');
|
|
286
|
+
static begin(uri, source = '') {
|
|
287
|
+
return new $mol_span(uri, source, 1, 1, 0);
|
|
288
|
+
}
|
|
289
|
+
static end(uri, source) {
|
|
290
|
+
return new $mol_span(uri, source, 1, source.length + 1, length);
|
|
321
291
|
}
|
|
322
|
-
|
|
323
|
-
return new $
|
|
324
|
-
|
|
292
|
+
static entire(uri, source) {
|
|
293
|
+
return new $mol_span(uri, source, 1, 1, source.length);
|
|
294
|
+
}
|
|
295
|
+
toString() {
|
|
296
|
+
return this[Symbol.toStringTag];
|
|
297
|
+
}
|
|
298
|
+
toJSON() {
|
|
299
|
+
return {
|
|
300
|
+
uri: this.uri,
|
|
325
301
|
row: this.row,
|
|
326
302
|
col: this.col,
|
|
327
|
-
length: this.length
|
|
328
|
-
|
|
329
|
-
});
|
|
330
|
-
}
|
|
331
|
-
make_data(value, sub) {
|
|
332
|
-
return this.make({ value, sub });
|
|
333
|
-
}
|
|
334
|
-
make_struct(type, sub) {
|
|
335
|
-
return this.make({ type, sub });
|
|
336
|
-
}
|
|
337
|
-
static fromString(str, baseUri) {
|
|
338
|
-
var root = new $mol_tree({ baseUri: baseUri });
|
|
339
|
-
var stack = [root];
|
|
340
|
-
var row = 0;
|
|
341
|
-
var prefix = str.replace(/^\n?(\t*)[\s\S]*/, '$1');
|
|
342
|
-
var lines = str.replace(new RegExp('^\\t{0,' + prefix.length + '}', 'mg'), '').split('\n');
|
|
343
|
-
lines.forEach(line => {
|
|
344
|
-
++row;
|
|
345
|
-
var chunks = /^(\t*)((?:[^\n\t\\ ]+ *)*)(\\[^\n]*)?(.*?)(?:$|\n)/m.exec(line);
|
|
346
|
-
if (!chunks || chunks[4])
|
|
347
|
-
return this.$.$mol_fail(new Error(`Syntax error at ${baseUri}:${row}\n${line}`));
|
|
348
|
-
var indent = chunks[1];
|
|
349
|
-
var path = chunks[2];
|
|
350
|
-
var data = chunks[3];
|
|
351
|
-
var deep = indent.length;
|
|
352
|
-
var types = path ? path.replace(/ $/, '').split(/ +/) : [];
|
|
353
|
-
if (stack.length <= deep)
|
|
354
|
-
return this.$.$mol_fail(new Error(`Too many tabs at ${baseUri}:${row}\n${line}`));
|
|
355
|
-
stack.length = deep + 1;
|
|
356
|
-
var parent = stack[deep];
|
|
357
|
-
let col = deep;
|
|
358
|
-
types.forEach(type => {
|
|
359
|
-
if (!type)
|
|
360
|
-
return this.$.$mol_fail(new Error(`Unexpected space symbol ${baseUri}:${row}\n${line}`));
|
|
361
|
-
var next = new $mol_tree({ type, baseUri, row, col, length: type.length });
|
|
362
|
-
const parent_sub = parent.sub;
|
|
363
|
-
parent_sub.push(next);
|
|
364
|
-
parent = next;
|
|
365
|
-
col += type.length + 1;
|
|
366
|
-
});
|
|
367
|
-
if (data) {
|
|
368
|
-
var next = new $mol_tree({ data: data.substring(1), baseUri, row, col, length: data.length });
|
|
369
|
-
const parent_sub = parent.sub;
|
|
370
|
-
parent_sub.push(next);
|
|
371
|
-
parent = next;
|
|
372
|
-
}
|
|
373
|
-
stack.push(parent);
|
|
374
|
-
});
|
|
375
|
-
return root;
|
|
376
|
-
}
|
|
377
|
-
static fromJSON(json, baseUri = '') {
|
|
378
|
-
switch (true) {
|
|
379
|
-
case typeof json === 'boolean':
|
|
380
|
-
case typeof json === 'number':
|
|
381
|
-
case json === null:
|
|
382
|
-
return new $mol_tree({
|
|
383
|
-
type: String(json),
|
|
384
|
-
baseUri: baseUri
|
|
385
|
-
});
|
|
386
|
-
case typeof json === 'string':
|
|
387
|
-
return new $mol_tree({
|
|
388
|
-
value: json,
|
|
389
|
-
baseUri: baseUri
|
|
390
|
-
});
|
|
391
|
-
case Array.isArray(json):
|
|
392
|
-
return new $mol_tree({
|
|
393
|
-
type: "/",
|
|
394
|
-
sub: json.map(json => $mol_tree.fromJSON(json, baseUri))
|
|
395
|
-
});
|
|
396
|
-
case json instanceof Date:
|
|
397
|
-
return new $mol_tree({
|
|
398
|
-
value: json.toISOString(),
|
|
399
|
-
baseUri: baseUri
|
|
400
|
-
});
|
|
401
|
-
default:
|
|
402
|
-
if (typeof json[$.$mol_tree_convert] === 'function') {
|
|
403
|
-
return json[$.$mol_tree_convert]();
|
|
404
|
-
}
|
|
405
|
-
if (typeof json.toJSON === 'function') {
|
|
406
|
-
return $mol_tree.fromJSON(json.toJSON());
|
|
407
|
-
}
|
|
408
|
-
if (json instanceof Error) {
|
|
409
|
-
const { name, message, stack } = json;
|
|
410
|
-
json = { ...json, name, message, stack };
|
|
411
|
-
}
|
|
412
|
-
var sub = [];
|
|
413
|
-
for (var key in json) {
|
|
414
|
-
if (json[key] === undefined)
|
|
415
|
-
continue;
|
|
416
|
-
const subsub = $mol_tree.fromJSON(json[key], baseUri);
|
|
417
|
-
if (/^[^\n\t\\ ]+$/.test(key)) {
|
|
418
|
-
var child = new $mol_tree({
|
|
419
|
-
type: key,
|
|
420
|
-
baseUri: baseUri,
|
|
421
|
-
sub: [subsub],
|
|
422
|
-
});
|
|
423
|
-
}
|
|
424
|
-
else {
|
|
425
|
-
var child = new $mol_tree({
|
|
426
|
-
value: key,
|
|
427
|
-
baseUri: baseUri,
|
|
428
|
-
sub: [subsub],
|
|
429
|
-
});
|
|
430
|
-
}
|
|
431
|
-
sub.push(child);
|
|
432
|
-
}
|
|
433
|
-
return new $mol_tree({
|
|
434
|
-
type: "*",
|
|
435
|
-
sub: sub,
|
|
436
|
-
baseUri: baseUri
|
|
437
|
-
});
|
|
438
|
-
}
|
|
303
|
+
length: this.length
|
|
304
|
+
};
|
|
439
305
|
}
|
|
440
|
-
|
|
441
|
-
return
|
|
306
|
+
error(message, Class = Error) {
|
|
307
|
+
return new Class(`${message}${this}`);
|
|
308
|
+
}
|
|
309
|
+
span(row, col, length) {
|
|
310
|
+
return new $mol_span(this.uri, this.source, row, col, length);
|
|
311
|
+
}
|
|
312
|
+
after(length = 0) {
|
|
313
|
+
return new $mol_span(this.uri, this.source, this.row, this.col + this.length, length);
|
|
314
|
+
}
|
|
315
|
+
slice(begin, end = -1) {
|
|
316
|
+
let len = this.length;
|
|
317
|
+
if (begin < 0)
|
|
318
|
+
begin += len;
|
|
319
|
+
if (end < 0)
|
|
320
|
+
end += len;
|
|
321
|
+
if (begin < 0 || begin > len)
|
|
322
|
+
this.$.$mol_fail(`Begin value '${begin}' out of range ${this}`);
|
|
323
|
+
if (end < 0 || end > len)
|
|
324
|
+
this.$.$mol_fail(`End value '${end}' out of range ${this}`);
|
|
325
|
+
if (end < begin)
|
|
326
|
+
this.$.$mol_fail(`End value '${end}' can't be less than begin value ${this}`);
|
|
327
|
+
return this.span(this.row, this.col + begin, end - begin);
|
|
442
328
|
}
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
329
|
+
}
|
|
330
|
+
$.$mol_span = $mol_span;
|
|
331
|
+
})($ || ($ = {}));
|
|
332
|
+
//mol/span/span.ts
|
|
333
|
+
;
|
|
334
|
+
"use strict";
|
|
335
|
+
var $;
|
|
336
|
+
(function ($) {
|
|
337
|
+
function $mol_tree2_to_string(tree) {
|
|
338
|
+
let output = [];
|
|
339
|
+
function dump(tree, prefix = '') {
|
|
340
|
+
if (tree.type.length) {
|
|
446
341
|
if (!prefix.length) {
|
|
447
342
|
prefix = "\t";
|
|
448
343
|
}
|
|
449
|
-
output
|
|
450
|
-
if (
|
|
451
|
-
|
|
344
|
+
output.push(tree.type);
|
|
345
|
+
if (tree.kids.length == 1) {
|
|
346
|
+
output.push(' ');
|
|
347
|
+
dump(tree.kids[0], prefix);
|
|
348
|
+
return;
|
|
452
349
|
}
|
|
453
|
-
output
|
|
350
|
+
output.push("\n");
|
|
454
351
|
}
|
|
455
|
-
else if (
|
|
456
|
-
output
|
|
352
|
+
else if (tree.value.length || prefix.length) {
|
|
353
|
+
output.push("\\" + tree.value + "\n");
|
|
457
354
|
}
|
|
458
|
-
for (
|
|
459
|
-
output
|
|
460
|
-
|
|
355
|
+
for (const kid of tree.kids) {
|
|
356
|
+
output.push(prefix);
|
|
357
|
+
dump(kid, prefix + "\t");
|
|
461
358
|
}
|
|
462
|
-
return output;
|
|
463
359
|
}
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
360
|
+
dump(tree);
|
|
361
|
+
return output.join('');
|
|
362
|
+
}
|
|
363
|
+
$.$mol_tree2_to_string = $mol_tree2_to_string;
|
|
364
|
+
})($ || ($ = {}));
|
|
365
|
+
//mol/tree2/to/string/string.ts
|
|
366
|
+
;
|
|
367
|
+
"use strict";
|
|
368
|
+
var $;
|
|
369
|
+
(function ($) {
|
|
370
|
+
class $mol_tree2 extends Object {
|
|
371
|
+
type;
|
|
372
|
+
value;
|
|
373
|
+
kids;
|
|
374
|
+
span;
|
|
375
|
+
constructor(type, value, kids, span) {
|
|
376
|
+
super();
|
|
377
|
+
this.type = type;
|
|
378
|
+
this.value = value;
|
|
379
|
+
this.kids = kids;
|
|
380
|
+
this.span = span;
|
|
381
|
+
this[Symbol.toStringTag] = type || '\\' + value;
|
|
382
|
+
}
|
|
383
|
+
static list(kids, span = $mol_span.unknown) {
|
|
384
|
+
return new $mol_tree2('', '', kids, span);
|
|
385
|
+
}
|
|
386
|
+
list(kids) {
|
|
387
|
+
return $mol_tree2.list(kids, this.span);
|
|
388
|
+
}
|
|
389
|
+
static data(value, kids = [], span = $mol_span.unknown) {
|
|
390
|
+
const chunks = value.split('\n');
|
|
391
|
+
if (chunks.length > 1) {
|
|
392
|
+
let kid_span = span.span(span.row, span.col, 0);
|
|
393
|
+
const data = chunks.map(chunk => {
|
|
394
|
+
kid_span = kid_span.after(chunk.length);
|
|
395
|
+
return new $mol_tree2('', chunk, [], kid_span);
|
|
493
396
|
});
|
|
494
|
-
|
|
397
|
+
kids = [...data, ...kids];
|
|
398
|
+
value = '';
|
|
495
399
|
}
|
|
496
|
-
|
|
497
|
-
|
|
400
|
+
return new $mol_tree2('', value, kids, span);
|
|
401
|
+
}
|
|
402
|
+
data(value, kids = []) {
|
|
403
|
+
return $mol_tree2.data(value, kids, this.span);
|
|
404
|
+
}
|
|
405
|
+
static struct(type, kids = [], span = $mol_span.unknown) {
|
|
406
|
+
if (/[ \n\t\\]/.test(type)) {
|
|
407
|
+
$$.$mol_fail(span.error(`Wrong type ${JSON.stringify(type)}`));
|
|
498
408
|
}
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
409
|
+
return new $mol_tree2(type, '', kids, span);
|
|
410
|
+
}
|
|
411
|
+
struct(type, kids = []) {
|
|
412
|
+
return $mol_tree2.struct(type, kids, this.span);
|
|
413
|
+
}
|
|
414
|
+
clone(kids, span = this.span) {
|
|
415
|
+
return new $mol_tree2(this.type, this.value, kids, span);
|
|
503
416
|
}
|
|
504
|
-
|
|
417
|
+
text() {
|
|
505
418
|
var values = [];
|
|
506
|
-
for (var
|
|
507
|
-
if (
|
|
419
|
+
for (var kid of this.kids) {
|
|
420
|
+
if (kid.type)
|
|
508
421
|
continue;
|
|
509
|
-
values.push(
|
|
422
|
+
values.push(kid.value);
|
|
510
423
|
}
|
|
511
|
-
return this.
|
|
424
|
+
return this.value + values.join('\n');
|
|
425
|
+
}
|
|
426
|
+
static fromString(str, uri = 'unknown') {
|
|
427
|
+
return $$.$mol_tree2_from_string(str, uri);
|
|
428
|
+
}
|
|
429
|
+
toString() {
|
|
430
|
+
return $$.$mol_tree2_to_string(this);
|
|
512
431
|
}
|
|
513
432
|
insert(value, ...path) {
|
|
514
433
|
if (path.length === 0)
|
|
@@ -516,83 +435,252 @@ var $;
|
|
|
516
435
|
const type = path[0];
|
|
517
436
|
if (typeof type === 'string') {
|
|
518
437
|
let replaced = false;
|
|
519
|
-
const sub = this.
|
|
438
|
+
const sub = this.kids.map((item, index) => {
|
|
520
439
|
if (item.type !== type)
|
|
521
440
|
return item;
|
|
522
441
|
replaced = true;
|
|
523
442
|
return item.insert(value, ...path.slice(1));
|
|
524
|
-
});
|
|
525
|
-
if (!replaced)
|
|
526
|
-
sub.push(
|
|
527
|
-
|
|
443
|
+
}).filter(Boolean);
|
|
444
|
+
if (!replaced && value) {
|
|
445
|
+
sub.push(this.struct(type, []).insert(value, ...path.slice(1)));
|
|
446
|
+
}
|
|
447
|
+
return this.clone(sub);
|
|
528
448
|
}
|
|
529
449
|
else if (typeof type === 'number') {
|
|
530
|
-
const sub = this.
|
|
531
|
-
sub[type] = (sub[type] ||
|
|
532
|
-
|
|
450
|
+
const sub = this.kids.slice();
|
|
451
|
+
sub[type] = (sub[type] || this.list([]))
|
|
452
|
+
.insert(value, ...path.slice(1));
|
|
453
|
+
return this.clone(sub.filter(Boolean));
|
|
533
454
|
}
|
|
534
455
|
else {
|
|
535
|
-
|
|
456
|
+
const kids = ((this.kids.length === 0) ? [this.list([])] : this.kids)
|
|
457
|
+
.map(item => item.insert(value, ...path.slice(1)))
|
|
458
|
+
.filter(Boolean);
|
|
459
|
+
return this.clone(kids);
|
|
536
460
|
}
|
|
537
461
|
}
|
|
538
462
|
select(...path) {
|
|
539
|
-
|
|
540
|
-
for (
|
|
463
|
+
let next = [this];
|
|
464
|
+
for (const type of path) {
|
|
541
465
|
if (!next.length)
|
|
542
466
|
break;
|
|
543
|
-
|
|
467
|
+
const prev = next;
|
|
544
468
|
next = [];
|
|
545
469
|
for (var item of prev) {
|
|
546
470
|
switch (typeof (type)) {
|
|
547
471
|
case 'string':
|
|
548
|
-
for (var child of item.
|
|
549
|
-
if (
|
|
472
|
+
for (var child of item.kids) {
|
|
473
|
+
if (child.type == type) {
|
|
550
474
|
next.push(child);
|
|
551
475
|
}
|
|
552
476
|
}
|
|
553
477
|
break;
|
|
554
478
|
case 'number':
|
|
555
|
-
if (type < item.
|
|
556
|
-
next.push(item.
|
|
479
|
+
if (type < item.kids.length)
|
|
480
|
+
next.push(item.kids[type]);
|
|
557
481
|
break;
|
|
558
|
-
default: next.push(...item.
|
|
482
|
+
default: next.push(...item.kids);
|
|
559
483
|
}
|
|
560
484
|
}
|
|
561
485
|
}
|
|
562
|
-
return
|
|
486
|
+
return this.list(next);
|
|
563
487
|
}
|
|
564
488
|
filter(path, value) {
|
|
565
|
-
|
|
489
|
+
const sub = this.kids.filter(item => {
|
|
566
490
|
var found = item.select(...path);
|
|
567
|
-
if (value
|
|
568
|
-
return Boolean(found.
|
|
491
|
+
if (value === undefined) {
|
|
492
|
+
return Boolean(found.kids.length);
|
|
569
493
|
}
|
|
570
494
|
else {
|
|
571
|
-
return found.
|
|
495
|
+
return found.kids.some(child => child.value == value);
|
|
572
496
|
}
|
|
573
497
|
});
|
|
574
|
-
return
|
|
575
|
-
}
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
498
|
+
return this.clone(sub);
|
|
499
|
+
}
|
|
500
|
+
hack(belt, context = {}) {
|
|
501
|
+
return [].concat(...this.kids.map(child => {
|
|
502
|
+
let handle = belt[child.type] || belt[''];
|
|
503
|
+
if (!handle || handle === Object.prototype[child.type]) {
|
|
504
|
+
handle = (input, belt, context) => [
|
|
505
|
+
input.clone(input.hack(belt, context), context.span)
|
|
506
|
+
];
|
|
507
|
+
}
|
|
508
|
+
try {
|
|
509
|
+
return handle(child, belt, context);
|
|
510
|
+
}
|
|
511
|
+
catch (error) {
|
|
512
|
+
error.message += `\n${child.clone([])}${child.span}`;
|
|
513
|
+
$mol_fail_hidden(error);
|
|
514
|
+
}
|
|
586
515
|
}));
|
|
587
|
-
return this.clone({ sub });
|
|
588
516
|
}
|
|
589
|
-
error(message) {
|
|
590
|
-
return
|
|
517
|
+
error(message, Class = Error) {
|
|
518
|
+
return this.span.error(`${message}\n${this.clone([])}`, Class);
|
|
519
|
+
}
|
|
520
|
+
}
|
|
521
|
+
$.$mol_tree2 = $mol_tree2;
|
|
522
|
+
class $mol_tree2_empty extends $mol_tree2 {
|
|
523
|
+
constructor() {
|
|
524
|
+
super('', '', [], $mol_span.unknown);
|
|
525
|
+
}
|
|
526
|
+
}
|
|
527
|
+
$.$mol_tree2_empty = $mol_tree2_empty;
|
|
528
|
+
})($ || ($ = {}));
|
|
529
|
+
//mol/tree2/tree2.ts
|
|
530
|
+
;
|
|
531
|
+
"use strict";
|
|
532
|
+
var $;
|
|
533
|
+
(function ($) {
|
|
534
|
+
class $mol_error_syntax extends SyntaxError {
|
|
535
|
+
reason;
|
|
536
|
+
line;
|
|
537
|
+
span;
|
|
538
|
+
constructor(reason, line, span) {
|
|
539
|
+
super(`${reason}\n${span}\n${line.substring(0, span.col - 1).replace(/\S/g, ' ')}${''.padEnd(span.length, '!')}\n${line}`);
|
|
540
|
+
this.reason = reason;
|
|
541
|
+
this.line = line;
|
|
542
|
+
this.span = span;
|
|
543
|
+
}
|
|
544
|
+
}
|
|
545
|
+
$.$mol_error_syntax = $mol_error_syntax;
|
|
546
|
+
})($ || ($ = {}));
|
|
547
|
+
//mol/error/syntax/syntax.ts
|
|
548
|
+
;
|
|
549
|
+
"use strict";
|
|
550
|
+
var $;
|
|
551
|
+
(function ($) {
|
|
552
|
+
function $mol_tree2_from_string(str, uri = '?') {
|
|
553
|
+
const span = $mol_span.entire(uri, str);
|
|
554
|
+
var root = $mol_tree2.list([], span);
|
|
555
|
+
var stack = [root];
|
|
556
|
+
var pos = 0, row = 0, min_indent = 0;
|
|
557
|
+
while (str.length > pos) {
|
|
558
|
+
var indent = 0;
|
|
559
|
+
var line_start = pos;
|
|
560
|
+
row++;
|
|
561
|
+
while (str.length > pos && str[pos] == '\t') {
|
|
562
|
+
indent++;
|
|
563
|
+
pos++;
|
|
564
|
+
}
|
|
565
|
+
if (!root.kids.length) {
|
|
566
|
+
min_indent = indent;
|
|
567
|
+
}
|
|
568
|
+
indent -= min_indent;
|
|
569
|
+
if (indent < 0 || indent >= stack.length) {
|
|
570
|
+
const sp = span.span(row, 1, pos - line_start);
|
|
571
|
+
while (str.length > pos && str[pos] != '\n') {
|
|
572
|
+
pos++;
|
|
573
|
+
}
|
|
574
|
+
if (indent < 0) {
|
|
575
|
+
if (str.length > pos) {
|
|
576
|
+
this.$mol_fail(new this.$mol_error_syntax(`Too few tabs`, str.substring(line_start, pos), sp));
|
|
577
|
+
}
|
|
578
|
+
}
|
|
579
|
+
else {
|
|
580
|
+
this.$mol_fail(new this.$mol_error_syntax(`Too many tabs`, str.substring(line_start, pos), sp));
|
|
581
|
+
}
|
|
582
|
+
}
|
|
583
|
+
stack.length = indent + 1;
|
|
584
|
+
var parent = stack[indent];
|
|
585
|
+
while (str.length > pos && str[pos] != '\\' && str[pos] != '\n') {
|
|
586
|
+
var error_start = pos;
|
|
587
|
+
while (str.length > pos && (str[pos] == ' ' || str[pos] == '\t')) {
|
|
588
|
+
pos++;
|
|
589
|
+
}
|
|
590
|
+
if (pos > error_start) {
|
|
591
|
+
let line_end = str.indexOf('\n', pos);
|
|
592
|
+
if (line_end === -1)
|
|
593
|
+
line_end = str.length;
|
|
594
|
+
const sp = span.span(row, error_start - line_start, pos - error_start + 1);
|
|
595
|
+
this.$mol_fail(new this.$mol_error_syntax(`Wrong nodes separator`, str.substring(line_start, line_end), sp));
|
|
596
|
+
}
|
|
597
|
+
var type_start = pos;
|
|
598
|
+
while (str.length > pos &&
|
|
599
|
+
str[pos] != '\\' &&
|
|
600
|
+
str[pos] != ' ' &&
|
|
601
|
+
str[pos] != '\t' &&
|
|
602
|
+
str[pos] != '\n') {
|
|
603
|
+
pos++;
|
|
604
|
+
}
|
|
605
|
+
if (pos > type_start) {
|
|
606
|
+
let next = new $mol_tree2(str.slice(type_start, pos), '', [], span.span(row, type_start - line_start + 1, pos - type_start));
|
|
607
|
+
const parent_kids = parent.kids;
|
|
608
|
+
parent_kids.push(next);
|
|
609
|
+
parent = next;
|
|
610
|
+
}
|
|
611
|
+
if (str.length > pos && str[pos] == ' ') {
|
|
612
|
+
pos++;
|
|
613
|
+
}
|
|
614
|
+
}
|
|
615
|
+
if (str.length > pos && str[pos] == '\\') {
|
|
616
|
+
var data_start = pos;
|
|
617
|
+
while (str.length > pos && str[pos] != '\n') {
|
|
618
|
+
pos++;
|
|
619
|
+
}
|
|
620
|
+
let next = new $mol_tree2('', str.slice(data_start + 1, pos), [], span.span(row, data_start - line_start + 2, pos - data_start - 1));
|
|
621
|
+
const parent_kids = parent.kids;
|
|
622
|
+
parent_kids.push(next);
|
|
623
|
+
parent = next;
|
|
624
|
+
}
|
|
625
|
+
if (str.length === pos && stack.length > 0) {
|
|
626
|
+
const sp = span.span(row, pos - line_start + 1, 1);
|
|
627
|
+
this.$mol_fail(new this.$mol_error_syntax(`Undexpected EOF, LF required`, str.substring(line_start, str.length), sp));
|
|
628
|
+
}
|
|
629
|
+
stack.push(parent);
|
|
630
|
+
pos++;
|
|
631
|
+
}
|
|
632
|
+
return root;
|
|
633
|
+
}
|
|
634
|
+
$.$mol_tree2_from_string = $mol_tree2_from_string;
|
|
635
|
+
})($ || ($ = {}));
|
|
636
|
+
//mol/tree2/from/string/string.ts
|
|
637
|
+
;
|
|
638
|
+
"use strict";
|
|
639
|
+
var $;
|
|
640
|
+
(function ($) {
|
|
641
|
+
function $mol_tree2_from_json(json, span = $mol_span.unknown) {
|
|
642
|
+
if (typeof json === 'boolean' || typeof json === 'number' || json === null) {
|
|
643
|
+
return new $mol_tree2(String(json), '', [], span);
|
|
644
|
+
}
|
|
645
|
+
if (typeof json === 'string') {
|
|
646
|
+
return $mol_tree2.data(json, [], span);
|
|
647
|
+
}
|
|
648
|
+
if (Array.isArray(json)) {
|
|
649
|
+
const sub = json.map(json => $mol_tree2_from_json(json, span));
|
|
650
|
+
return new $mol_tree2('/', '', sub, span);
|
|
651
|
+
}
|
|
652
|
+
if (ArrayBuffer.isView(json)) {
|
|
653
|
+
const buf = new Uint8Array(json.buffer, json.byteOffset, json.byteLength);
|
|
654
|
+
return $mol_tree2.data(String.fromCharCode(...buf), [], span);
|
|
655
|
+
}
|
|
656
|
+
if (json instanceof Date) {
|
|
657
|
+
return new $mol_tree2('', json.toISOString(), [], span);
|
|
591
658
|
}
|
|
659
|
+
if (typeof json.toJSON === 'function') {
|
|
660
|
+
return $mol_tree2_from_json(json.toJSON());
|
|
661
|
+
}
|
|
662
|
+
if (json instanceof Error) {
|
|
663
|
+
const { name, message, stack } = json;
|
|
664
|
+
json = { ...json, name, message, stack };
|
|
665
|
+
}
|
|
666
|
+
const sub = [];
|
|
667
|
+
for (var key in json) {
|
|
668
|
+
const val = json[key];
|
|
669
|
+
if (val === undefined)
|
|
670
|
+
continue;
|
|
671
|
+
const subsub = $mol_tree2_from_json(val, span);
|
|
672
|
+
if (/^[^\n\t\\ ]+$/.test(key)) {
|
|
673
|
+
sub.push(new $mol_tree2(key, '', [subsub], span));
|
|
674
|
+
}
|
|
675
|
+
else {
|
|
676
|
+
sub.push($mol_tree2.data(key, [subsub], span));
|
|
677
|
+
}
|
|
678
|
+
}
|
|
679
|
+
return new $mol_tree2('*', '', sub, span);
|
|
592
680
|
}
|
|
593
|
-
$.$
|
|
681
|
+
$.$mol_tree2_from_json = $mol_tree2_from_json;
|
|
594
682
|
})($ || ($ = {}));
|
|
595
|
-
//mol/
|
|
683
|
+
//mol/tree2/from/json/json.ts
|
|
596
684
|
;
|
|
597
685
|
"use strict";
|
|
598
686
|
var $;
|
|
@@ -647,7 +735,8 @@ var $;
|
|
|
647
735
|
return function $mol_log3_logger(event) {
|
|
648
736
|
if (!event.time)
|
|
649
737
|
event = { time: new Date().toISOString(), ...event };
|
|
650
|
-
|
|
738
|
+
let tree = this.$mol_tree2_from_json(event);
|
|
739
|
+
tree = tree.struct(type, tree.kids);
|
|
651
740
|
let str = color(tree.toString());
|
|
652
741
|
this.console[level](str);
|
|
653
742
|
const self = this;
|
|
@@ -1834,61 +1923,176 @@ var $;
|
|
|
1834
1923
|
var $;
|
|
1835
1924
|
(function ($_1) {
|
|
1836
1925
|
$mol_test({
|
|
1837
|
-
'
|
|
1838
|
-
$
|
|
1839
|
-
|
|
1840
|
-
$mol_assert_equal(
|
|
1841
|
-
$mol_assert_equal(
|
|
1842
|
-
$mol_assert_equal(
|
|
1843
|
-
$mol_assert_equal(
|
|
1844
|
-
$mol_assert_equal($mol_tree.fromString("foo bar\n\t\\pol\n\t\\men").sub[0].sub[0].sub[1].data, "men");
|
|
1845
|
-
$mol_assert_equal($mol_tree.fromString('foo bar \\text\n').toString(), 'foo bar \\text\n');
|
|
1846
|
-
},
|
|
1847
|
-
'inserting'() {
|
|
1848
|
-
$mol_assert_equal($mol_tree.fromString('a b c d').insert(new $mol_tree, 'a', 'b', 'c').toString(), 'a b \\\n');
|
|
1849
|
-
$mol_assert_equal($mol_tree.fromString('a b').insert(new $mol_tree, 'a', 'b', 'c', 'd').toString(), 'a b c \\\n');
|
|
1850
|
-
$mol_assert_equal($mol_tree.fromString('a b c d').insert(new $mol_tree, 0, 0, 0).toString(), 'a b \\\n');
|
|
1851
|
-
$mol_assert_equal($mol_tree.fromString('a b').insert(new $mol_tree, 0, 0, 0, 0).toString(), 'a b \\\n\t\\\n');
|
|
1852
|
-
$mol_assert_equal($mol_tree.fromString('a b c d').insert(new $mol_tree, null, null, null).toString(), 'a b \\\n');
|
|
1853
|
-
$mol_assert_equal($mol_tree.fromString('a b').insert(new $mol_tree, null, null, null, null).toString(), 'a b \\\n\t\\\n');
|
|
1926
|
+
'span for same uri'($) {
|
|
1927
|
+
const span = new $mol_span('test.ts', '', 1, 3, 4);
|
|
1928
|
+
const child = span.span(4, 5, 8);
|
|
1929
|
+
$mol_assert_equal(child.uri, 'test.ts');
|
|
1930
|
+
$mol_assert_equal(child.row, 4);
|
|
1931
|
+
$mol_assert_equal(child.col, 5);
|
|
1932
|
+
$mol_assert_equal(child.length, 8);
|
|
1854
1933
|
},
|
|
1855
|
-
'
|
|
1856
|
-
$
|
|
1857
|
-
|
|
1858
|
-
$mol_assert_equal(
|
|
1859
|
-
$mol_assert_equal(
|
|
1860
|
-
$mol_assert_equal(
|
|
1861
|
-
|
|
1862
|
-
|
|
1863
|
-
|
|
1864
|
-
$
|
|
1865
|
-
|
|
1866
|
-
$mol_assert_equal(
|
|
1867
|
-
$mol_assert_equal(
|
|
1868
|
-
|
|
1869
|
-
|
|
1870
|
-
|
|
1871
|
-
|
|
1872
|
-
|
|
1934
|
+
'span after of given position'($) {
|
|
1935
|
+
const span = new $mol_span('test.ts', '', 1, 3, 4);
|
|
1936
|
+
const child = span.after(11);
|
|
1937
|
+
$mol_assert_equal(child.uri, 'test.ts');
|
|
1938
|
+
$mol_assert_equal(child.row, 1);
|
|
1939
|
+
$mol_assert_equal(child.col, 7);
|
|
1940
|
+
$mol_assert_equal(child.length, 11);
|
|
1941
|
+
},
|
|
1942
|
+
'slice span - regular'($) {
|
|
1943
|
+
const span = new $mol_span('test.ts', '', 1, 3, 5);
|
|
1944
|
+
const child = span.slice(1, 4);
|
|
1945
|
+
$mol_assert_equal(child.row, 1);
|
|
1946
|
+
$mol_assert_equal(child.col, 4);
|
|
1947
|
+
$mol_assert_equal(child.length, 3);
|
|
1948
|
+
const child2 = span.slice(2, 2);
|
|
1949
|
+
$mol_assert_equal(child2.col, 5);
|
|
1950
|
+
$mol_assert_equal(child2.length, 0);
|
|
1951
|
+
},
|
|
1952
|
+
'slice span - negative'($) {
|
|
1953
|
+
const span = new $mol_span('test.ts', '', 1, 3, 5);
|
|
1954
|
+
const child = span.slice(-3, -1);
|
|
1955
|
+
$mol_assert_equal(child.row, 1);
|
|
1956
|
+
$mol_assert_equal(child.col, 5);
|
|
1957
|
+
$mol_assert_equal(child.length, 2);
|
|
1958
|
+
},
|
|
1959
|
+
'slice span - out of range'($) {
|
|
1960
|
+
const span = new $mol_span('test.ts', '', 1, 3, 5);
|
|
1961
|
+
$mol_assert_fail(() => span.slice(-1, 3));
|
|
1962
|
+
$mol_assert_fail(() => span.slice(1, 6));
|
|
1963
|
+
$mol_assert_fail(() => span.slice(1, 10));
|
|
1964
|
+
},
|
|
1965
|
+
'error handling'($) {
|
|
1966
|
+
const span = new $mol_span('test.ts', '', 1, 3, 4);
|
|
1967
|
+
const error = span.error('Some error\n');
|
|
1968
|
+
$mol_assert_equal(error.message, 'Some error\ntest.ts#1:3/4');
|
|
1969
|
+
}
|
|
1970
|
+
});
|
|
1971
|
+
})($ || ($ = {}));
|
|
1972
|
+
//mol/span/span.test.ts
|
|
1973
|
+
;
|
|
1974
|
+
"use strict";
|
|
1975
|
+
var $;
|
|
1976
|
+
(function ($_1) {
|
|
1977
|
+
$mol_test({
|
|
1978
|
+
'inserting'($) {
|
|
1979
|
+
$mol_assert_equal($.$mol_tree2_from_string('a b c d\n')
|
|
1980
|
+
.insert($mol_tree2.struct('x'), 'a', 'b', 'c')
|
|
1981
|
+
.toString(), 'a b x\n');
|
|
1982
|
+
$mol_assert_equal($.$mol_tree2_from_string('a b\n')
|
|
1983
|
+
.insert($mol_tree2.struct('x'), 'a', 'b', 'c', 'd')
|
|
1984
|
+
.toString(), 'a b c x\n');
|
|
1985
|
+
$mol_assert_equal($.$mol_tree2_from_string('a b c d\n')
|
|
1986
|
+
.insert($mol_tree2.struct('x'), 0, 0, 0)
|
|
1987
|
+
.toString(), 'a b x\n');
|
|
1988
|
+
$mol_assert_equal($.$mol_tree2_from_string('a b\n')
|
|
1989
|
+
.insert($mol_tree2.struct('x'), 0, 0, 0, 0)
|
|
1990
|
+
.toString(), 'a b \\\n\tx\n');
|
|
1991
|
+
$mol_assert_equal($.$mol_tree2_from_string('a b c d\n')
|
|
1992
|
+
.insert($mol_tree2.struct('x'), null, null, null)
|
|
1993
|
+
.toString(), 'a b x\n');
|
|
1994
|
+
$mol_assert_equal($.$mol_tree2_from_string('a b\n')
|
|
1995
|
+
.insert($mol_tree2.struct('x'), null, null, null, null)
|
|
1996
|
+
.toString(), 'a b \\\n\tx\n');
|
|
1997
|
+
},
|
|
1998
|
+
'deleting'($) {
|
|
1999
|
+
$mol_assert_equal($.$mol_tree2_from_string('a b c d\n')
|
|
2000
|
+
.insert(null, 'a', 'b', 'c')
|
|
2001
|
+
.toString(), 'a b\n');
|
|
2002
|
+
$mol_assert_equal($.$mol_tree2_from_string('a b c d\n')
|
|
2003
|
+
.insert(null, 0, 0, 0)
|
|
2004
|
+
.toString(), 'a b\n');
|
|
2005
|
+
},
|
|
2006
|
+
'hack'($) {
|
|
2007
|
+
const res = $.$mol_tree2_from_string(`foo bar xxx\n`)
|
|
2008
|
+
.hack({
|
|
2009
|
+
'bar': (input, belt) => [input.struct('777', input.hack(belt))],
|
|
1873
2010
|
});
|
|
1874
|
-
$mol_assert_equal(res.toString(),
|
|
2011
|
+
$mol_assert_equal(res.toString(), 'foo 777 xxx\n');
|
|
2012
|
+
},
|
|
2013
|
+
});
|
|
2014
|
+
})($ || ($ = {}));
|
|
2015
|
+
//mol/tree2/tree2.test.ts
|
|
2016
|
+
;
|
|
2017
|
+
"use strict";
|
|
2018
|
+
var $;
|
|
2019
|
+
(function ($_1) {
|
|
2020
|
+
$mol_test({
|
|
2021
|
+
'tree parsing'($) {
|
|
2022
|
+
$mol_assert_equal($.$mol_tree2_from_string("foo\nbar\n").kids.length, 2);
|
|
2023
|
+
$mol_assert_equal($.$mol_tree2_from_string("foo\nbar\n").kids[1].type, "bar");
|
|
2024
|
+
$mol_assert_equal($.$mol_tree2_from_string("foo\n\n\n").kids.length, 1);
|
|
2025
|
+
$mol_assert_equal($.$mol_tree2_from_string("=foo\n\\bar\n").kids.length, 2);
|
|
2026
|
+
$mol_assert_equal($.$mol_tree2_from_string("=foo\n\\bar\n").kids[1].value, "bar");
|
|
2027
|
+
$mol_assert_equal($.$mol_tree2_from_string("foo bar \\pol\n").kids[0].kids[0].kids[0].value, "pol");
|
|
2028
|
+
$mol_assert_equal($.$mol_tree2_from_string("foo bar\n\t\\pol\n\t\\men\n").kids[0].kids[0].kids[1].value, "men");
|
|
2029
|
+
$mol_assert_equal($.$mol_tree2_from_string('foo bar \\text\n').toString(), 'foo bar \\text\n');
|
|
2030
|
+
},
|
|
2031
|
+
'Too many tabs'($) {
|
|
2032
|
+
const tree = `
|
|
2033
|
+
foo
|
|
2034
|
+
bar
|
|
2035
|
+
`;
|
|
2036
|
+
$mol_assert_fail(() => {
|
|
2037
|
+
$.$mol_tree2_from_string(tree, 'test');
|
|
2038
|
+
}, 'Too many tabs\ntest#3:1/6\n!!!!!!\n\t\t\t\t\t\tbar');
|
|
2039
|
+
},
|
|
2040
|
+
'Too few tabs'($) {
|
|
2041
|
+
const tree = `
|
|
2042
|
+
foo
|
|
2043
|
+
bar
|
|
2044
|
+
`;
|
|
2045
|
+
$mol_assert_fail(() => {
|
|
2046
|
+
$.$mol_tree2_from_string(tree, 'test');
|
|
2047
|
+
}, 'Too few tabs\ntest#3:1/4\n!!!!\n\t\t\t\tbar');
|
|
2048
|
+
},
|
|
2049
|
+
'Wrong nodes separator'($) {
|
|
2050
|
+
const tree = `foo bar\n`;
|
|
2051
|
+
$mol_assert_fail(() => {
|
|
2052
|
+
$.$mol_tree2_from_string(tree, 'test');
|
|
2053
|
+
}, 'Wrong nodes separator\ntest#1:4/2\n !!\nfoo bar');
|
|
1875
2054
|
},
|
|
1876
|
-
'
|
|
2055
|
+
'Undexpected EOF, LF required'($) {
|
|
2056
|
+
const tree = ` foo`;
|
|
2057
|
+
$mol_assert_fail(() => {
|
|
2058
|
+
$.$mol_tree2_from_string(tree, 'test');
|
|
2059
|
+
}, 'Undexpected EOF, LF required\ntest#1:5/1\n !\n foo');
|
|
2060
|
+
},
|
|
2061
|
+
'Errors skip and collect'($) {
|
|
2062
|
+
const tree = `foo bar`;
|
|
1877
2063
|
const errors = [];
|
|
1878
|
-
|
|
1879
|
-
|
|
1880
|
-
|
|
1881
|
-
|
|
1882
|
-
|
|
1883
|
-
|
|
1884
|
-
|
|
1885
|
-
|
|
1886
|
-
|
|
1887
|
-
|
|
2064
|
+
const $$ = $.$mol_ambient({
|
|
2065
|
+
$mol_fail: (error) => {
|
|
2066
|
+
errors.push(error.message);
|
|
2067
|
+
return null;
|
|
2068
|
+
}
|
|
2069
|
+
});
|
|
2070
|
+
const res = $$.$mol_tree2_from_string(tree, 'test');
|
|
2071
|
+
$mol_assert_like(errors, [
|
|
2072
|
+
'Wrong nodes separator\ntest#1:4/2\n !!\nfoo bar',
|
|
2073
|
+
'Undexpected EOF, LF required\ntest#1:9/1\n !\nfoo bar',
|
|
2074
|
+
]);
|
|
2075
|
+
$mol_assert_equal(res.toString(), 'foo bar\n');
|
|
2076
|
+
},
|
|
2077
|
+
});
|
|
2078
|
+
})($ || ($ = {}));
|
|
2079
|
+
//mol/tree2/from/string/string.test.ts
|
|
2080
|
+
;
|
|
2081
|
+
"use strict";
|
|
2082
|
+
var $;
|
|
2083
|
+
(function ($) {
|
|
2084
|
+
$mol_test({
|
|
2085
|
+
'fromJSON'() {
|
|
2086
|
+
$mol_assert_equal($mol_tree2_from_json([]).toString(), '/\n');
|
|
2087
|
+
$mol_assert_equal($mol_tree2_from_json([false, true]).toString(), '/\n\tfalse\n\ttrue\n');
|
|
2088
|
+
$mol_assert_equal($mol_tree2_from_json([0, 1, 2.3]).toString(), '/\n\t0\n\t1\n\t2.3\n');
|
|
2089
|
+
$mol_assert_equal($mol_tree2_from_json(new Uint16Array([1, 10, 256])).toString(), '\\\x01\x00\n\\\x00\x00\x01\n');
|
|
2090
|
+
$mol_assert_equal($mol_tree2_from_json(['', 'foo', 'bar\nbaz']).toString(), '/\n\t\\\n\t\\foo\n\t\\\n\t\t\\bar\n\t\t\\baz\n');
|
|
2091
|
+
$mol_assert_equal($mol_tree2_from_json({ 'foo': false, 'bar\nbaz': 'lol' }).toString(), '*\n\tfoo false\n\t\\\n\t\t\\bar\n\t\t\\baz\n\t\t\\lol\n');
|
|
1888
2092
|
},
|
|
1889
2093
|
});
|
|
1890
2094
|
})($ || ($ = {}));
|
|
1891
|
-
//mol/
|
|
2095
|
+
//mol/tree2/from/json/json.test.ts
|
|
1892
2096
|
;
|
|
1893
2097
|
"use strict";
|
|
1894
2098
|
var $;
|