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