mol_crypto_lib 0.0.642 → 0.0.644
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 +345 -256
- package/node.js.map +1 -1
- package/node.mjs +345 -256
- 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.js
CHANGED
|
@@ -269,248 +269,167 @@ var $;
|
|
|
269
269
|
"use strict";
|
|
270
270
|
var $;
|
|
271
271
|
(function ($) {
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
data;
|
|
276
|
-
sub;
|
|
277
|
-
baseUri;
|
|
272
|
+
class $mol_span extends $mol_object2 {
|
|
273
|
+
uri;
|
|
274
|
+
source;
|
|
278
275
|
row;
|
|
279
276
|
col;
|
|
280
277
|
length;
|
|
281
|
-
constructor(
|
|
278
|
+
constructor(uri, source, row, col, length) {
|
|
282
279
|
super();
|
|
283
|
-
this.
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
}
|
|
290
|
-
else {
|
|
291
|
-
this.data = sub[0].data;
|
|
292
|
-
this.sub = config.sub || [];
|
|
293
|
-
}
|
|
294
|
-
}
|
|
295
|
-
else {
|
|
296
|
-
this.data = config.data || '';
|
|
297
|
-
this.sub = config.sub || [];
|
|
298
|
-
}
|
|
299
|
-
this.baseUri = config.baseUri || '';
|
|
300
|
-
this.row = config.row || 0;
|
|
301
|
-
this.col = config.col || 0;
|
|
302
|
-
this.length = config.length || 0;
|
|
303
|
-
}
|
|
304
|
-
static values(str, baseUri) {
|
|
305
|
-
return str.split('\n').map((data, index) => new $mol_tree({
|
|
306
|
-
data: data,
|
|
307
|
-
baseUri: baseUri,
|
|
308
|
-
row: index + 1,
|
|
309
|
-
length: data.length,
|
|
310
|
-
}));
|
|
280
|
+
this.uri = uri;
|
|
281
|
+
this.source = source;
|
|
282
|
+
this.row = row;
|
|
283
|
+
this.col = col;
|
|
284
|
+
this.length = length;
|
|
285
|
+
this[Symbol.toStringTag] = `${this.uri}#${this.row}:${this.col}/${this.length}`;
|
|
311
286
|
}
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
row: ('row' in config) ? config.row : this.row,
|
|
319
|
-
col: ('col' in config) ? config.col : this.col,
|
|
320
|
-
length: ('length' in config) ? config.length : this.length,
|
|
321
|
-
value: config.value
|
|
322
|
-
});
|
|
287
|
+
static unknown = $mol_span.begin('?');
|
|
288
|
+
static begin(uri, source = '') {
|
|
289
|
+
return new $mol_span(uri, source, 1, 1, 0);
|
|
290
|
+
}
|
|
291
|
+
static end(uri, source) {
|
|
292
|
+
return new $mol_span(uri, source, 1, source.length + 1, length);
|
|
323
293
|
}
|
|
324
|
-
|
|
325
|
-
return new $
|
|
326
|
-
|
|
294
|
+
static entire(uri, source) {
|
|
295
|
+
return new $mol_span(uri, source, 1, 1, source.length);
|
|
296
|
+
}
|
|
297
|
+
toString() {
|
|
298
|
+
return this[Symbol.toStringTag];
|
|
299
|
+
}
|
|
300
|
+
toJSON() {
|
|
301
|
+
return {
|
|
302
|
+
uri: this.uri,
|
|
327
303
|
row: this.row,
|
|
328
304
|
col: this.col,
|
|
329
|
-
length: this.length
|
|
330
|
-
|
|
331
|
-
});
|
|
305
|
+
length: this.length
|
|
306
|
+
};
|
|
332
307
|
}
|
|
333
|
-
|
|
334
|
-
return
|
|
335
|
-
}
|
|
336
|
-
make_struct(type, sub) {
|
|
337
|
-
return this.make({ type, sub });
|
|
338
|
-
}
|
|
339
|
-
static fromString(str, baseUri) {
|
|
340
|
-
var root = new $mol_tree({ baseUri: baseUri });
|
|
341
|
-
var stack = [root];
|
|
342
|
-
var row = 0;
|
|
343
|
-
var prefix = str.replace(/^\n?(\t*)[\s\S]*/, '$1');
|
|
344
|
-
var lines = str.replace(new RegExp('^\\t{0,' + prefix.length + '}', 'mg'), '').split('\n');
|
|
345
|
-
lines.forEach(line => {
|
|
346
|
-
++row;
|
|
347
|
-
var chunks = /^(\t*)((?:[^\n\t\\ ]+ *)*)(\\[^\n]*)?(.*?)(?:$|\n)/m.exec(line);
|
|
348
|
-
if (!chunks || chunks[4])
|
|
349
|
-
return this.$.$mol_fail(new Error(`Syntax error at ${baseUri}:${row}\n${line}`));
|
|
350
|
-
var indent = chunks[1];
|
|
351
|
-
var path = chunks[2];
|
|
352
|
-
var data = chunks[3];
|
|
353
|
-
var deep = indent.length;
|
|
354
|
-
var types = path ? path.replace(/ $/, '').split(/ +/) : [];
|
|
355
|
-
if (stack.length <= deep)
|
|
356
|
-
return this.$.$mol_fail(new Error(`Too many tabs at ${baseUri}:${row}\n${line}`));
|
|
357
|
-
stack.length = deep + 1;
|
|
358
|
-
var parent = stack[deep];
|
|
359
|
-
let col = deep;
|
|
360
|
-
types.forEach(type => {
|
|
361
|
-
if (!type)
|
|
362
|
-
return this.$.$mol_fail(new Error(`Unexpected space symbol ${baseUri}:${row}\n${line}`));
|
|
363
|
-
var next = new $mol_tree({ type, baseUri, row, col, length: type.length });
|
|
364
|
-
const parent_sub = parent.sub;
|
|
365
|
-
parent_sub.push(next);
|
|
366
|
-
parent = next;
|
|
367
|
-
col += type.length + 1;
|
|
368
|
-
});
|
|
369
|
-
if (data) {
|
|
370
|
-
var next = new $mol_tree({ data: data.substring(1), baseUri, row, col, length: data.length });
|
|
371
|
-
const parent_sub = parent.sub;
|
|
372
|
-
parent_sub.push(next);
|
|
373
|
-
parent = next;
|
|
374
|
-
}
|
|
375
|
-
stack.push(parent);
|
|
376
|
-
});
|
|
377
|
-
return root;
|
|
378
|
-
}
|
|
379
|
-
static fromJSON(json, baseUri = '') {
|
|
380
|
-
switch (true) {
|
|
381
|
-
case typeof json === 'boolean':
|
|
382
|
-
case typeof json === 'number':
|
|
383
|
-
case json === null:
|
|
384
|
-
return new $mol_tree({
|
|
385
|
-
type: String(json),
|
|
386
|
-
baseUri: baseUri
|
|
387
|
-
});
|
|
388
|
-
case typeof json === 'string':
|
|
389
|
-
return new $mol_tree({
|
|
390
|
-
value: json,
|
|
391
|
-
baseUri: baseUri
|
|
392
|
-
});
|
|
393
|
-
case Array.isArray(json):
|
|
394
|
-
return new $mol_tree({
|
|
395
|
-
type: "/",
|
|
396
|
-
sub: json.map(json => $mol_tree.fromJSON(json, baseUri))
|
|
397
|
-
});
|
|
398
|
-
case json instanceof Date:
|
|
399
|
-
return new $mol_tree({
|
|
400
|
-
value: json.toISOString(),
|
|
401
|
-
baseUri: baseUri
|
|
402
|
-
});
|
|
403
|
-
default:
|
|
404
|
-
if (typeof json[$.$mol_tree_convert] === 'function') {
|
|
405
|
-
return json[$.$mol_tree_convert]();
|
|
406
|
-
}
|
|
407
|
-
if (typeof json.toJSON === 'function') {
|
|
408
|
-
return $mol_tree.fromJSON(json.toJSON());
|
|
409
|
-
}
|
|
410
|
-
if (json instanceof Error) {
|
|
411
|
-
const { name, message, stack } = json;
|
|
412
|
-
json = { ...json, name, message, stack };
|
|
413
|
-
}
|
|
414
|
-
var sub = [];
|
|
415
|
-
for (var key in json) {
|
|
416
|
-
if (json[key] === undefined)
|
|
417
|
-
continue;
|
|
418
|
-
const subsub = $mol_tree.fromJSON(json[key], baseUri);
|
|
419
|
-
if (/^[^\n\t\\ ]+$/.test(key)) {
|
|
420
|
-
var child = new $mol_tree({
|
|
421
|
-
type: key,
|
|
422
|
-
baseUri: baseUri,
|
|
423
|
-
sub: [subsub],
|
|
424
|
-
});
|
|
425
|
-
}
|
|
426
|
-
else {
|
|
427
|
-
var child = new $mol_tree({
|
|
428
|
-
value: key,
|
|
429
|
-
baseUri: baseUri,
|
|
430
|
-
sub: [subsub],
|
|
431
|
-
});
|
|
432
|
-
}
|
|
433
|
-
sub.push(child);
|
|
434
|
-
}
|
|
435
|
-
return new $mol_tree({
|
|
436
|
-
type: "*",
|
|
437
|
-
sub: sub,
|
|
438
|
-
baseUri: baseUri
|
|
439
|
-
});
|
|
440
|
-
}
|
|
308
|
+
error(message, Class = Error) {
|
|
309
|
+
return new Class(`${message}${this}`);
|
|
441
310
|
}
|
|
442
|
-
|
|
443
|
-
return this.
|
|
311
|
+
span(row, col, length) {
|
|
312
|
+
return new $mol_span(this.uri, this.source, row, col, length);
|
|
444
313
|
}
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
314
|
+
after(length = 0) {
|
|
315
|
+
return new $mol_span(this.uri, this.source, this.row, this.col + this.length, length);
|
|
316
|
+
}
|
|
317
|
+
slice(begin, end = -1) {
|
|
318
|
+
let len = this.length;
|
|
319
|
+
if (begin < 0)
|
|
320
|
+
begin += len;
|
|
321
|
+
if (end < 0)
|
|
322
|
+
end += len;
|
|
323
|
+
if (begin < 0 || begin > len)
|
|
324
|
+
this.$.$mol_fail(`Begin value '${begin}' out of range ${this}`);
|
|
325
|
+
if (end < 0 || end > len)
|
|
326
|
+
this.$.$mol_fail(`End value '${end}' out of range ${this}`);
|
|
327
|
+
if (end < begin)
|
|
328
|
+
this.$.$mol_fail(`End value '${end}' can't be less than begin value ${this}`);
|
|
329
|
+
return this.span(this.row, this.col + begin, end - begin);
|
|
330
|
+
}
|
|
331
|
+
}
|
|
332
|
+
$.$mol_span = $mol_span;
|
|
333
|
+
})($ || ($ = {}));
|
|
334
|
+
//mol/span/span.ts
|
|
335
|
+
;
|
|
336
|
+
"use strict";
|
|
337
|
+
var $;
|
|
338
|
+
(function ($) {
|
|
339
|
+
function $mol_tree2_to_string(tree) {
|
|
340
|
+
let output = [];
|
|
341
|
+
function dump(tree, prefix = '') {
|
|
342
|
+
if (tree.type.length) {
|
|
448
343
|
if (!prefix.length) {
|
|
449
344
|
prefix = "\t";
|
|
450
345
|
}
|
|
451
|
-
output
|
|
452
|
-
if (
|
|
453
|
-
|
|
346
|
+
output.push(tree.type);
|
|
347
|
+
if (tree.kids.length == 1) {
|
|
348
|
+
output.push(' ');
|
|
349
|
+
dump(tree.kids[0], prefix);
|
|
350
|
+
return;
|
|
454
351
|
}
|
|
455
|
-
output
|
|
352
|
+
output.push("\n");
|
|
456
353
|
}
|
|
457
|
-
else if (
|
|
458
|
-
output
|
|
354
|
+
else if (tree.value.length || prefix.length) {
|
|
355
|
+
output.push("\\" + tree.value + "\n");
|
|
459
356
|
}
|
|
460
|
-
for (
|
|
461
|
-
output
|
|
462
|
-
|
|
357
|
+
for (const kid of tree.kids) {
|
|
358
|
+
output.push(prefix);
|
|
359
|
+
dump(kid, prefix + "\t");
|
|
463
360
|
}
|
|
464
|
-
return output;
|
|
465
361
|
}
|
|
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
|
-
|
|
493
|
-
|
|
494
|
-
|
|
362
|
+
dump(tree);
|
|
363
|
+
return output.join('');
|
|
364
|
+
}
|
|
365
|
+
$.$mol_tree2_to_string = $mol_tree2_to_string;
|
|
366
|
+
})($ || ($ = {}));
|
|
367
|
+
//mol/tree2/to/string/string.ts
|
|
368
|
+
;
|
|
369
|
+
"use strict";
|
|
370
|
+
var $;
|
|
371
|
+
(function ($) {
|
|
372
|
+
class $mol_tree2 extends Object {
|
|
373
|
+
type;
|
|
374
|
+
value;
|
|
375
|
+
kids;
|
|
376
|
+
span;
|
|
377
|
+
constructor(type, value, kids, span) {
|
|
378
|
+
super();
|
|
379
|
+
this.type = type;
|
|
380
|
+
this.value = value;
|
|
381
|
+
this.kids = kids;
|
|
382
|
+
this.span = span;
|
|
383
|
+
this[Symbol.toStringTag] = type || '\\' + value;
|
|
384
|
+
}
|
|
385
|
+
static list(kids, span = $mol_span.unknown) {
|
|
386
|
+
return new $mol_tree2('', '', kids, span);
|
|
387
|
+
}
|
|
388
|
+
list(kids) {
|
|
389
|
+
return $mol_tree2.list(kids, this.span);
|
|
390
|
+
}
|
|
391
|
+
static data(value, kids = [], span = $mol_span.unknown) {
|
|
392
|
+
const chunks = value.split('\n');
|
|
393
|
+
if (chunks.length > 1) {
|
|
394
|
+
let kid_span = span.span(span.row, span.col, 0);
|
|
395
|
+
const data = chunks.map(chunk => {
|
|
396
|
+
kid_span = kid_span.after(chunk.length);
|
|
397
|
+
return new $mol_tree2('', chunk, [], kid_span);
|
|
495
398
|
});
|
|
496
|
-
|
|
399
|
+
kids = [...data, ...kids];
|
|
400
|
+
value = '';
|
|
497
401
|
}
|
|
498
|
-
|
|
499
|
-
|
|
402
|
+
return new $mol_tree2('', value, kids, span);
|
|
403
|
+
}
|
|
404
|
+
data(value, kids = []) {
|
|
405
|
+
return $mol_tree2.data(value, kids, this.span);
|
|
406
|
+
}
|
|
407
|
+
static struct(type, kids = [], span = $mol_span.unknown) {
|
|
408
|
+
if (/[ \n\t\\]/.test(type)) {
|
|
409
|
+
$$.$mol_fail(span.error(`Wrong type ${JSON.stringify(type)}`));
|
|
500
410
|
}
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
411
|
+
return new $mol_tree2(type, '', kids, span);
|
|
412
|
+
}
|
|
413
|
+
struct(type, kids = []) {
|
|
414
|
+
return $mol_tree2.struct(type, kids, this.span);
|
|
505
415
|
}
|
|
506
|
-
|
|
416
|
+
clone(kids, span = this.span) {
|
|
417
|
+
return new $mol_tree2(this.type, this.value, kids, span);
|
|
418
|
+
}
|
|
419
|
+
text() {
|
|
507
420
|
var values = [];
|
|
508
|
-
for (var
|
|
509
|
-
if (
|
|
421
|
+
for (var kid of this.kids) {
|
|
422
|
+
if (kid.type)
|
|
510
423
|
continue;
|
|
511
|
-
values.push(
|
|
424
|
+
values.push(kid.value);
|
|
512
425
|
}
|
|
513
|
-
return this.
|
|
426
|
+
return this.value + values.join('\n');
|
|
427
|
+
}
|
|
428
|
+
static fromString(str, uri = 'unknown') {
|
|
429
|
+
return $$.$mol_tree2_from_string(str, uri);
|
|
430
|
+
}
|
|
431
|
+
toString() {
|
|
432
|
+
return $$.$mol_tree2_to_string(this);
|
|
514
433
|
}
|
|
515
434
|
insert(value, ...path) {
|
|
516
435
|
if (path.length === 0)
|
|
@@ -518,83 +437,252 @@ var $;
|
|
|
518
437
|
const type = path[0];
|
|
519
438
|
if (typeof type === 'string') {
|
|
520
439
|
let replaced = false;
|
|
521
|
-
const sub = this.
|
|
440
|
+
const sub = this.kids.map((item, index) => {
|
|
522
441
|
if (item.type !== type)
|
|
523
442
|
return item;
|
|
524
443
|
replaced = true;
|
|
525
444
|
return item.insert(value, ...path.slice(1));
|
|
526
|
-
});
|
|
527
|
-
if (!replaced)
|
|
528
|
-
sub.push(
|
|
529
|
-
|
|
445
|
+
}).filter(Boolean);
|
|
446
|
+
if (!replaced && value) {
|
|
447
|
+
sub.push(this.struct(type, []).insert(value, ...path.slice(1)));
|
|
448
|
+
}
|
|
449
|
+
return this.clone(sub);
|
|
530
450
|
}
|
|
531
451
|
else if (typeof type === 'number') {
|
|
532
|
-
const sub = this.
|
|
533
|
-
sub[type] = (sub[type] ||
|
|
534
|
-
|
|
452
|
+
const sub = this.kids.slice();
|
|
453
|
+
sub[type] = (sub[type] || this.list([]))
|
|
454
|
+
.insert(value, ...path.slice(1));
|
|
455
|
+
return this.clone(sub.filter(Boolean));
|
|
535
456
|
}
|
|
536
457
|
else {
|
|
537
|
-
|
|
458
|
+
const kids = ((this.kids.length === 0) ? [this.list([])] : this.kids)
|
|
459
|
+
.map(item => item.insert(value, ...path.slice(1)))
|
|
460
|
+
.filter(Boolean);
|
|
461
|
+
return this.clone(kids);
|
|
538
462
|
}
|
|
539
463
|
}
|
|
540
464
|
select(...path) {
|
|
541
|
-
|
|
542
|
-
for (
|
|
465
|
+
let next = [this];
|
|
466
|
+
for (const type of path) {
|
|
543
467
|
if (!next.length)
|
|
544
468
|
break;
|
|
545
|
-
|
|
469
|
+
const prev = next;
|
|
546
470
|
next = [];
|
|
547
471
|
for (var item of prev) {
|
|
548
472
|
switch (typeof (type)) {
|
|
549
473
|
case 'string':
|
|
550
|
-
for (var child of item.
|
|
551
|
-
if (
|
|
474
|
+
for (var child of item.kids) {
|
|
475
|
+
if (child.type == type) {
|
|
552
476
|
next.push(child);
|
|
553
477
|
}
|
|
554
478
|
}
|
|
555
479
|
break;
|
|
556
480
|
case 'number':
|
|
557
|
-
if (type < item.
|
|
558
|
-
next.push(item.
|
|
481
|
+
if (type < item.kids.length)
|
|
482
|
+
next.push(item.kids[type]);
|
|
559
483
|
break;
|
|
560
|
-
default: next.push(...item.
|
|
484
|
+
default: next.push(...item.kids);
|
|
561
485
|
}
|
|
562
486
|
}
|
|
563
487
|
}
|
|
564
|
-
return
|
|
488
|
+
return this.list(next);
|
|
565
489
|
}
|
|
566
490
|
filter(path, value) {
|
|
567
|
-
|
|
491
|
+
const sub = this.kids.filter(item => {
|
|
568
492
|
var found = item.select(...path);
|
|
569
|
-
if (value
|
|
570
|
-
return Boolean(found.
|
|
493
|
+
if (value === undefined) {
|
|
494
|
+
return Boolean(found.kids.length);
|
|
571
495
|
}
|
|
572
496
|
else {
|
|
573
|
-
return found.
|
|
497
|
+
return found.kids.some(child => child.value == value);
|
|
574
498
|
}
|
|
575
499
|
});
|
|
576
|
-
return
|
|
577
|
-
}
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
500
|
+
return this.clone(sub);
|
|
501
|
+
}
|
|
502
|
+
hack(belt, context = {}) {
|
|
503
|
+
return [].concat(...this.kids.map(child => {
|
|
504
|
+
let handle = belt[child.type] || belt[''];
|
|
505
|
+
if (!handle || handle === Object.prototype[child.type]) {
|
|
506
|
+
handle = (input, belt, context) => [
|
|
507
|
+
input.clone(input.hack(belt, context), context.span)
|
|
508
|
+
];
|
|
509
|
+
}
|
|
510
|
+
try {
|
|
511
|
+
return handle(child, belt, context);
|
|
512
|
+
}
|
|
513
|
+
catch (error) {
|
|
514
|
+
error.message += `\n${child.clone([])}${child.span}`;
|
|
515
|
+
$mol_fail_hidden(error);
|
|
516
|
+
}
|
|
588
517
|
}));
|
|
589
|
-
return this.clone({ sub });
|
|
590
518
|
}
|
|
591
|
-
error(message) {
|
|
592
|
-
return
|
|
519
|
+
error(message, Class = Error) {
|
|
520
|
+
return this.span.error(`${message}\n${this.clone([])}`, Class);
|
|
521
|
+
}
|
|
522
|
+
}
|
|
523
|
+
$.$mol_tree2 = $mol_tree2;
|
|
524
|
+
class $mol_tree2_empty extends $mol_tree2 {
|
|
525
|
+
constructor() {
|
|
526
|
+
super('', '', [], $mol_span.unknown);
|
|
527
|
+
}
|
|
528
|
+
}
|
|
529
|
+
$.$mol_tree2_empty = $mol_tree2_empty;
|
|
530
|
+
})($ || ($ = {}));
|
|
531
|
+
//mol/tree2/tree2.ts
|
|
532
|
+
;
|
|
533
|
+
"use strict";
|
|
534
|
+
var $;
|
|
535
|
+
(function ($) {
|
|
536
|
+
class $mol_error_syntax extends SyntaxError {
|
|
537
|
+
reason;
|
|
538
|
+
line;
|
|
539
|
+
span;
|
|
540
|
+
constructor(reason, line, span) {
|
|
541
|
+
super(`${reason}\n${span}\n${line.substring(0, span.col - 1).replace(/\S/g, ' ')}${''.padEnd(span.length, '!')}\n${line}`);
|
|
542
|
+
this.reason = reason;
|
|
543
|
+
this.line = line;
|
|
544
|
+
this.span = span;
|
|
545
|
+
}
|
|
546
|
+
}
|
|
547
|
+
$.$mol_error_syntax = $mol_error_syntax;
|
|
548
|
+
})($ || ($ = {}));
|
|
549
|
+
//mol/error/syntax/syntax.ts
|
|
550
|
+
;
|
|
551
|
+
"use strict";
|
|
552
|
+
var $;
|
|
553
|
+
(function ($) {
|
|
554
|
+
function $mol_tree2_from_string(str, uri = '?') {
|
|
555
|
+
const span = $mol_span.entire(uri, str);
|
|
556
|
+
var root = $mol_tree2.list([], span);
|
|
557
|
+
var stack = [root];
|
|
558
|
+
var pos = 0, row = 0, min_indent = 0;
|
|
559
|
+
while (str.length > pos) {
|
|
560
|
+
var indent = 0;
|
|
561
|
+
var line_start = pos;
|
|
562
|
+
row++;
|
|
563
|
+
while (str.length > pos && str[pos] == '\t') {
|
|
564
|
+
indent++;
|
|
565
|
+
pos++;
|
|
566
|
+
}
|
|
567
|
+
if (!root.kids.length) {
|
|
568
|
+
min_indent = indent;
|
|
569
|
+
}
|
|
570
|
+
indent -= min_indent;
|
|
571
|
+
if (indent < 0 || indent >= stack.length) {
|
|
572
|
+
const sp = span.span(row, 1, pos - line_start);
|
|
573
|
+
while (str.length > pos && str[pos] != '\n') {
|
|
574
|
+
pos++;
|
|
575
|
+
}
|
|
576
|
+
if (indent < 0) {
|
|
577
|
+
if (str.length > pos) {
|
|
578
|
+
this.$mol_fail(new this.$mol_error_syntax(`Too few tabs`, str.substring(line_start, pos), sp));
|
|
579
|
+
}
|
|
580
|
+
}
|
|
581
|
+
else {
|
|
582
|
+
this.$mol_fail(new this.$mol_error_syntax(`Too many tabs`, str.substring(line_start, pos), sp));
|
|
583
|
+
}
|
|
584
|
+
}
|
|
585
|
+
stack.length = indent + 1;
|
|
586
|
+
var parent = stack[indent];
|
|
587
|
+
while (str.length > pos && str[pos] != '\\' && str[pos] != '\n') {
|
|
588
|
+
var error_start = pos;
|
|
589
|
+
while (str.length > pos && (str[pos] == ' ' || str[pos] == '\t')) {
|
|
590
|
+
pos++;
|
|
591
|
+
}
|
|
592
|
+
if (pos > error_start) {
|
|
593
|
+
let line_end = str.indexOf('\n', pos);
|
|
594
|
+
if (line_end === -1)
|
|
595
|
+
line_end = str.length;
|
|
596
|
+
const sp = span.span(row, error_start - line_start, pos - error_start + 1);
|
|
597
|
+
this.$mol_fail(new this.$mol_error_syntax(`Wrong nodes separator`, str.substring(line_start, line_end), sp));
|
|
598
|
+
}
|
|
599
|
+
var type_start = pos;
|
|
600
|
+
while (str.length > pos &&
|
|
601
|
+
str[pos] != '\\' &&
|
|
602
|
+
str[pos] != ' ' &&
|
|
603
|
+
str[pos] != '\t' &&
|
|
604
|
+
str[pos] != '\n') {
|
|
605
|
+
pos++;
|
|
606
|
+
}
|
|
607
|
+
if (pos > type_start) {
|
|
608
|
+
let next = new $mol_tree2(str.slice(type_start, pos), '', [], span.span(row, type_start - line_start + 1, pos - type_start));
|
|
609
|
+
const parent_kids = parent.kids;
|
|
610
|
+
parent_kids.push(next);
|
|
611
|
+
parent = next;
|
|
612
|
+
}
|
|
613
|
+
if (str.length > pos && str[pos] == ' ') {
|
|
614
|
+
pos++;
|
|
615
|
+
}
|
|
616
|
+
}
|
|
617
|
+
if (str.length > pos && str[pos] == '\\') {
|
|
618
|
+
var data_start = pos;
|
|
619
|
+
while (str.length > pos && str[pos] != '\n') {
|
|
620
|
+
pos++;
|
|
621
|
+
}
|
|
622
|
+
let next = new $mol_tree2('', str.slice(data_start + 1, pos), [], span.span(row, data_start - line_start + 2, pos - data_start - 1));
|
|
623
|
+
const parent_kids = parent.kids;
|
|
624
|
+
parent_kids.push(next);
|
|
625
|
+
parent = next;
|
|
626
|
+
}
|
|
627
|
+
if (str.length === pos && stack.length > 0) {
|
|
628
|
+
const sp = span.span(row, pos - line_start + 1, 1);
|
|
629
|
+
this.$mol_fail(new this.$mol_error_syntax(`Undexpected EOF, LF required`, str.substring(line_start, str.length), sp));
|
|
630
|
+
}
|
|
631
|
+
stack.push(parent);
|
|
632
|
+
pos++;
|
|
633
|
+
}
|
|
634
|
+
return root;
|
|
635
|
+
}
|
|
636
|
+
$.$mol_tree2_from_string = $mol_tree2_from_string;
|
|
637
|
+
})($ || ($ = {}));
|
|
638
|
+
//mol/tree2/from/string/string.ts
|
|
639
|
+
;
|
|
640
|
+
"use strict";
|
|
641
|
+
var $;
|
|
642
|
+
(function ($) {
|
|
643
|
+
function $mol_tree2_from_json(json, span = $mol_span.unknown) {
|
|
644
|
+
if (typeof json === 'boolean' || typeof json === 'number' || json === null) {
|
|
645
|
+
return new $mol_tree2(String(json), '', [], span);
|
|
646
|
+
}
|
|
647
|
+
if (typeof json === 'string') {
|
|
648
|
+
return $mol_tree2.data(json, [], span);
|
|
649
|
+
}
|
|
650
|
+
if (Array.isArray(json)) {
|
|
651
|
+
const sub = json.map(json => $mol_tree2_from_json(json, span));
|
|
652
|
+
return new $mol_tree2('/', '', sub, span);
|
|
653
|
+
}
|
|
654
|
+
if (ArrayBuffer.isView(json)) {
|
|
655
|
+
const buf = new Uint8Array(json.buffer, json.byteOffset, json.byteLength);
|
|
656
|
+
return $mol_tree2.data(String.fromCharCode(...buf), [], span);
|
|
657
|
+
}
|
|
658
|
+
if (json instanceof Date) {
|
|
659
|
+
return new $mol_tree2('', json.toISOString(), [], span);
|
|
660
|
+
}
|
|
661
|
+
if (typeof json.toJSON === 'function') {
|
|
662
|
+
return $mol_tree2_from_json(json.toJSON());
|
|
663
|
+
}
|
|
664
|
+
if (json instanceof Error) {
|
|
665
|
+
const { name, message, stack } = json;
|
|
666
|
+
json = { ...json, name, message, stack };
|
|
667
|
+
}
|
|
668
|
+
const sub = [];
|
|
669
|
+
for (var key in json) {
|
|
670
|
+
const val = json[key];
|
|
671
|
+
if (val === undefined)
|
|
672
|
+
continue;
|
|
673
|
+
const subsub = $mol_tree2_from_json(val, span);
|
|
674
|
+
if (/^[^\n\t\\ ]+$/.test(key)) {
|
|
675
|
+
sub.push(new $mol_tree2(key, '', [subsub], span));
|
|
676
|
+
}
|
|
677
|
+
else {
|
|
678
|
+
sub.push($mol_tree2.data(key, [subsub], span));
|
|
679
|
+
}
|
|
593
680
|
}
|
|
681
|
+
return new $mol_tree2('*', '', sub, span);
|
|
594
682
|
}
|
|
595
|
-
$.$
|
|
683
|
+
$.$mol_tree2_from_json = $mol_tree2_from_json;
|
|
596
684
|
})($ || ($ = {}));
|
|
597
|
-
//mol/
|
|
685
|
+
//mol/tree2/from/json/json.ts
|
|
598
686
|
;
|
|
599
687
|
"use strict";
|
|
600
688
|
var $;
|
|
@@ -649,7 +737,8 @@ var $;
|
|
|
649
737
|
return function $mol_log3_logger(event) {
|
|
650
738
|
if (!event.time)
|
|
651
739
|
event = { time: new Date().toISOString(), ...event };
|
|
652
|
-
|
|
740
|
+
let tree = this.$mol_tree2_from_json(event);
|
|
741
|
+
tree = tree.struct(type, tree.kids);
|
|
653
742
|
let str = color(tree.toString());
|
|
654
743
|
this.console[level](str);
|
|
655
744
|
const self = this;
|