mol_plot_all 1.2.535 → 1.2.537
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 +846 -252
- package/node.test.js.map +1 -1
- package/package.json +10 -2
- package/web.deps.json +1 -1
package/node.test.js
CHANGED
|
@@ -1398,248 +1398,167 @@ var $;
|
|
|
1398
1398
|
"use strict";
|
|
1399
1399
|
var $;
|
|
1400
1400
|
(function ($) {
|
|
1401
|
-
|
|
1402
|
-
|
|
1403
|
-
|
|
1404
|
-
data;
|
|
1405
|
-
sub;
|
|
1406
|
-
baseUri;
|
|
1401
|
+
class $mol_span extends $mol_object2 {
|
|
1402
|
+
uri;
|
|
1403
|
+
source;
|
|
1407
1404
|
row;
|
|
1408
1405
|
col;
|
|
1409
1406
|
length;
|
|
1410
|
-
constructor(
|
|
1407
|
+
constructor(uri, source, row, col, length) {
|
|
1411
1408
|
super();
|
|
1412
|
-
this.
|
|
1413
|
-
|
|
1414
|
-
|
|
1415
|
-
|
|
1416
|
-
|
|
1417
|
-
|
|
1418
|
-
}
|
|
1419
|
-
else {
|
|
1420
|
-
this.data = sub[0].data;
|
|
1421
|
-
this.sub = config.sub || [];
|
|
1422
|
-
}
|
|
1423
|
-
}
|
|
1424
|
-
else {
|
|
1425
|
-
this.data = config.data || '';
|
|
1426
|
-
this.sub = config.sub || [];
|
|
1427
|
-
}
|
|
1428
|
-
this.baseUri = config.baseUri || '';
|
|
1429
|
-
this.row = config.row || 0;
|
|
1430
|
-
this.col = config.col || 0;
|
|
1431
|
-
this.length = config.length || 0;
|
|
1409
|
+
this.uri = uri;
|
|
1410
|
+
this.source = source;
|
|
1411
|
+
this.row = row;
|
|
1412
|
+
this.col = col;
|
|
1413
|
+
this.length = length;
|
|
1414
|
+
this[Symbol.toStringTag] = `${this.uri}#${this.row}:${this.col}/${this.length}`;
|
|
1432
1415
|
}
|
|
1433
|
-
static
|
|
1434
|
-
|
|
1435
|
-
|
|
1436
|
-
baseUri: baseUri,
|
|
1437
|
-
row: index + 1,
|
|
1438
|
-
length: data.length,
|
|
1439
|
-
}));
|
|
1416
|
+
static unknown = $mol_span.begin('?');
|
|
1417
|
+
static begin(uri, source = '') {
|
|
1418
|
+
return new $mol_span(uri, source, 1, 1, 0);
|
|
1440
1419
|
}
|
|
1441
|
-
|
|
1442
|
-
return new $
|
|
1443
|
-
type: ('type' in config) ? config.type : this.type,
|
|
1444
|
-
data: ('data' in config) ? config.data : this.data,
|
|
1445
|
-
sub: ('sub' in config) ? config.sub : this.sub,
|
|
1446
|
-
baseUri: ('baseUri' in config) ? config.baseUri : this.baseUri,
|
|
1447
|
-
row: ('row' in config) ? config.row : this.row,
|
|
1448
|
-
col: ('col' in config) ? config.col : this.col,
|
|
1449
|
-
length: ('length' in config) ? config.length : this.length,
|
|
1450
|
-
value: config.value
|
|
1451
|
-
});
|
|
1420
|
+
static end(uri, source) {
|
|
1421
|
+
return new $mol_span(uri, source, 1, source.length + 1, length);
|
|
1452
1422
|
}
|
|
1453
|
-
|
|
1454
|
-
return new $
|
|
1455
|
-
|
|
1423
|
+
static entire(uri, source) {
|
|
1424
|
+
return new $mol_span(uri, source, 1, 1, source.length);
|
|
1425
|
+
}
|
|
1426
|
+
toString() {
|
|
1427
|
+
return this[Symbol.toStringTag];
|
|
1428
|
+
}
|
|
1429
|
+
toJSON() {
|
|
1430
|
+
return {
|
|
1431
|
+
uri: this.uri,
|
|
1456
1432
|
row: this.row,
|
|
1457
1433
|
col: this.col,
|
|
1458
|
-
length: this.length
|
|
1459
|
-
|
|
1460
|
-
});
|
|
1461
|
-
}
|
|
1462
|
-
make_data(value, sub) {
|
|
1463
|
-
return this.make({ value, sub });
|
|
1434
|
+
length: this.length
|
|
1435
|
+
};
|
|
1464
1436
|
}
|
|
1465
|
-
|
|
1466
|
-
return
|
|
1437
|
+
error(message, Class = Error) {
|
|
1438
|
+
return new Class(`${message}${this}`);
|
|
1467
1439
|
}
|
|
1468
|
-
|
|
1469
|
-
|
|
1470
|
-
var stack = [root];
|
|
1471
|
-
var row = 0;
|
|
1472
|
-
var prefix = str.replace(/^\n?(\t*)[\s\S]*/, '$1');
|
|
1473
|
-
var lines = str.replace(new RegExp('^\\t{0,' + prefix.length + '}', 'mg'), '').split('\n');
|
|
1474
|
-
lines.forEach(line => {
|
|
1475
|
-
++row;
|
|
1476
|
-
var chunks = /^(\t*)((?:[^\n\t\\ ]+ *)*)(\\[^\n]*)?(.*?)(?:$|\n)/m.exec(line);
|
|
1477
|
-
if (!chunks || chunks[4])
|
|
1478
|
-
return this.$.$mol_fail(new Error(`Syntax error at ${baseUri}:${row}\n${line}`));
|
|
1479
|
-
var indent = chunks[1];
|
|
1480
|
-
var path = chunks[2];
|
|
1481
|
-
var data = chunks[3];
|
|
1482
|
-
var deep = indent.length;
|
|
1483
|
-
var types = path ? path.replace(/ $/, '').split(/ +/) : [];
|
|
1484
|
-
if (stack.length <= deep)
|
|
1485
|
-
return this.$.$mol_fail(new Error(`Too many tabs at ${baseUri}:${row}\n${line}`));
|
|
1486
|
-
stack.length = deep + 1;
|
|
1487
|
-
var parent = stack[deep];
|
|
1488
|
-
let col = deep;
|
|
1489
|
-
types.forEach(type => {
|
|
1490
|
-
if (!type)
|
|
1491
|
-
return this.$.$mol_fail(new Error(`Unexpected space symbol ${baseUri}:${row}\n${line}`));
|
|
1492
|
-
var next = new $mol_tree({ type, baseUri, row, col, length: type.length });
|
|
1493
|
-
const parent_sub = parent.sub;
|
|
1494
|
-
parent_sub.push(next);
|
|
1495
|
-
parent = next;
|
|
1496
|
-
col += type.length + 1;
|
|
1497
|
-
});
|
|
1498
|
-
if (data) {
|
|
1499
|
-
var next = new $mol_tree({ data: data.substring(1), baseUri, row, col, length: data.length });
|
|
1500
|
-
const parent_sub = parent.sub;
|
|
1501
|
-
parent_sub.push(next);
|
|
1502
|
-
parent = next;
|
|
1503
|
-
}
|
|
1504
|
-
stack.push(parent);
|
|
1505
|
-
});
|
|
1506
|
-
return root;
|
|
1440
|
+
span(row, col, length) {
|
|
1441
|
+
return new $mol_span(this.uri, this.source, row, col, length);
|
|
1507
1442
|
}
|
|
1508
|
-
|
|
1509
|
-
|
|
1510
|
-
case typeof json === 'boolean':
|
|
1511
|
-
case typeof json === 'number':
|
|
1512
|
-
case json === null:
|
|
1513
|
-
return new $mol_tree({
|
|
1514
|
-
type: String(json),
|
|
1515
|
-
baseUri: baseUri
|
|
1516
|
-
});
|
|
1517
|
-
case typeof json === 'string':
|
|
1518
|
-
return new $mol_tree({
|
|
1519
|
-
value: json,
|
|
1520
|
-
baseUri: baseUri
|
|
1521
|
-
});
|
|
1522
|
-
case Array.isArray(json):
|
|
1523
|
-
return new $mol_tree({
|
|
1524
|
-
type: "/",
|
|
1525
|
-
sub: json.map(json => $mol_tree.fromJSON(json, baseUri))
|
|
1526
|
-
});
|
|
1527
|
-
case json instanceof Date:
|
|
1528
|
-
return new $mol_tree({
|
|
1529
|
-
value: json.toISOString(),
|
|
1530
|
-
baseUri: baseUri
|
|
1531
|
-
});
|
|
1532
|
-
default:
|
|
1533
|
-
if (typeof json[$.$mol_tree_convert] === 'function') {
|
|
1534
|
-
return json[$.$mol_tree_convert]();
|
|
1535
|
-
}
|
|
1536
|
-
if (typeof json.toJSON === 'function') {
|
|
1537
|
-
return $mol_tree.fromJSON(json.toJSON());
|
|
1538
|
-
}
|
|
1539
|
-
if (json instanceof Error) {
|
|
1540
|
-
const { name, message, stack } = json;
|
|
1541
|
-
json = { ...json, name, message, stack };
|
|
1542
|
-
}
|
|
1543
|
-
var sub = [];
|
|
1544
|
-
for (var key in json) {
|
|
1545
|
-
if (json[key] === undefined)
|
|
1546
|
-
continue;
|
|
1547
|
-
const subsub = $mol_tree.fromJSON(json[key], baseUri);
|
|
1548
|
-
if (/^[^\n\t\\ ]+$/.test(key)) {
|
|
1549
|
-
var child = new $mol_tree({
|
|
1550
|
-
type: key,
|
|
1551
|
-
baseUri: baseUri,
|
|
1552
|
-
sub: [subsub],
|
|
1553
|
-
});
|
|
1554
|
-
}
|
|
1555
|
-
else {
|
|
1556
|
-
var child = new $mol_tree({
|
|
1557
|
-
value: key,
|
|
1558
|
-
baseUri: baseUri,
|
|
1559
|
-
sub: [subsub],
|
|
1560
|
-
});
|
|
1561
|
-
}
|
|
1562
|
-
sub.push(child);
|
|
1563
|
-
}
|
|
1564
|
-
return new $mol_tree({
|
|
1565
|
-
type: "*",
|
|
1566
|
-
sub: sub,
|
|
1567
|
-
baseUri: baseUri
|
|
1568
|
-
});
|
|
1569
|
-
}
|
|
1443
|
+
after(length = 0) {
|
|
1444
|
+
return new $mol_span(this.uri, this.source, this.row, this.col + this.length, length);
|
|
1570
1445
|
}
|
|
1571
|
-
|
|
1572
|
-
|
|
1446
|
+
slice(begin, end = -1) {
|
|
1447
|
+
let len = this.length;
|
|
1448
|
+
if (begin < 0)
|
|
1449
|
+
begin += len;
|
|
1450
|
+
if (end < 0)
|
|
1451
|
+
end += len;
|
|
1452
|
+
if (begin < 0 || begin > len)
|
|
1453
|
+
this.$.$mol_fail(`Begin value '${begin}' out of range ${this}`);
|
|
1454
|
+
if (end < 0 || end > len)
|
|
1455
|
+
this.$.$mol_fail(`End value '${end}' out of range ${this}`);
|
|
1456
|
+
if (end < begin)
|
|
1457
|
+
this.$.$mol_fail(`End value '${end}' can't be less than begin value ${this}`);
|
|
1458
|
+
return this.span(this.row, this.col + begin, end - begin);
|
|
1573
1459
|
}
|
|
1574
|
-
|
|
1575
|
-
|
|
1576
|
-
|
|
1460
|
+
}
|
|
1461
|
+
$.$mol_span = $mol_span;
|
|
1462
|
+
})($ || ($ = {}));
|
|
1463
|
+
//mol/span/span.ts
|
|
1464
|
+
;
|
|
1465
|
+
"use strict";
|
|
1466
|
+
var $;
|
|
1467
|
+
(function ($) {
|
|
1468
|
+
function $mol_tree2_to_string(tree) {
|
|
1469
|
+
let output = [];
|
|
1470
|
+
function dump(tree, prefix = '') {
|
|
1471
|
+
if (tree.type.length) {
|
|
1577
1472
|
if (!prefix.length) {
|
|
1578
1473
|
prefix = "\t";
|
|
1579
1474
|
}
|
|
1580
|
-
output
|
|
1581
|
-
if (
|
|
1582
|
-
|
|
1475
|
+
output.push(tree.type);
|
|
1476
|
+
if (tree.kids.length == 1) {
|
|
1477
|
+
output.push(' ');
|
|
1478
|
+
dump(tree.kids[0], prefix);
|
|
1479
|
+
return;
|
|
1583
1480
|
}
|
|
1584
|
-
output
|
|
1481
|
+
output.push("\n");
|
|
1585
1482
|
}
|
|
1586
|
-
else if (
|
|
1587
|
-
output
|
|
1483
|
+
else if (tree.value.length || prefix.length) {
|
|
1484
|
+
output.push("\\" + tree.value + "\n");
|
|
1588
1485
|
}
|
|
1589
|
-
for (
|
|
1590
|
-
output
|
|
1591
|
-
|
|
1486
|
+
for (const kid of tree.kids) {
|
|
1487
|
+
output.push(prefix);
|
|
1488
|
+
dump(kid, prefix + "\t");
|
|
1592
1489
|
}
|
|
1593
|
-
return output;
|
|
1594
1490
|
}
|
|
1595
|
-
|
|
1596
|
-
|
|
1597
|
-
|
|
1598
|
-
|
|
1599
|
-
|
|
1600
|
-
|
|
1601
|
-
|
|
1602
|
-
|
|
1603
|
-
|
|
1604
|
-
|
|
1605
|
-
|
|
1606
|
-
|
|
1607
|
-
|
|
1608
|
-
|
|
1609
|
-
|
|
1610
|
-
|
|
1611
|
-
|
|
1612
|
-
|
|
1613
|
-
|
|
1614
|
-
|
|
1615
|
-
|
|
1616
|
-
|
|
1617
|
-
|
|
1618
|
-
|
|
1619
|
-
|
|
1620
|
-
|
|
1621
|
-
|
|
1622
|
-
|
|
1623
|
-
|
|
1491
|
+
dump(tree);
|
|
1492
|
+
return output.join('');
|
|
1493
|
+
}
|
|
1494
|
+
$.$mol_tree2_to_string = $mol_tree2_to_string;
|
|
1495
|
+
})($ || ($ = {}));
|
|
1496
|
+
//mol/tree2/to/string/string.ts
|
|
1497
|
+
;
|
|
1498
|
+
"use strict";
|
|
1499
|
+
var $;
|
|
1500
|
+
(function ($) {
|
|
1501
|
+
class $mol_tree2 extends Object {
|
|
1502
|
+
type;
|
|
1503
|
+
value;
|
|
1504
|
+
kids;
|
|
1505
|
+
span;
|
|
1506
|
+
constructor(type, value, kids, span) {
|
|
1507
|
+
super();
|
|
1508
|
+
this.type = type;
|
|
1509
|
+
this.value = value;
|
|
1510
|
+
this.kids = kids;
|
|
1511
|
+
this.span = span;
|
|
1512
|
+
this[Symbol.toStringTag] = type || '\\' + value;
|
|
1513
|
+
}
|
|
1514
|
+
static list(kids, span = $mol_span.unknown) {
|
|
1515
|
+
return new $mol_tree2('', '', kids, span);
|
|
1516
|
+
}
|
|
1517
|
+
list(kids) {
|
|
1518
|
+
return $mol_tree2.list(kids, this.span);
|
|
1519
|
+
}
|
|
1520
|
+
static data(value, kids = [], span = $mol_span.unknown) {
|
|
1521
|
+
const chunks = value.split('\n');
|
|
1522
|
+
if (chunks.length > 1) {
|
|
1523
|
+
let kid_span = span.span(span.row, span.col, 0);
|
|
1524
|
+
const data = chunks.map(chunk => {
|
|
1525
|
+
kid_span = kid_span.after(chunk.length);
|
|
1526
|
+
return new $mol_tree2('', chunk, [], kid_span);
|
|
1624
1527
|
});
|
|
1625
|
-
|
|
1528
|
+
kids = [...data, ...kids];
|
|
1529
|
+
value = '';
|
|
1626
1530
|
}
|
|
1627
|
-
|
|
1628
|
-
|
|
1531
|
+
return new $mol_tree2('', value, kids, span);
|
|
1532
|
+
}
|
|
1533
|
+
data(value, kids = []) {
|
|
1534
|
+
return $mol_tree2.data(value, kids, this.span);
|
|
1535
|
+
}
|
|
1536
|
+
static struct(type, kids = [], span = $mol_span.unknown) {
|
|
1537
|
+
if (/[ \n\t\\]/.test(type)) {
|
|
1538
|
+
$$.$mol_fail(span.error(`Wrong type ${JSON.stringify(type)}`));
|
|
1629
1539
|
}
|
|
1630
|
-
|
|
1631
|
-
if (!Number.isNaN(numb) || this.type === 'NaN')
|
|
1632
|
-
return numb;
|
|
1633
|
-
throw new Error(`Unknown type (${this.type}) at ${this.uri}`);
|
|
1540
|
+
return new $mol_tree2(type, '', kids, span);
|
|
1634
1541
|
}
|
|
1635
|
-
|
|
1542
|
+
struct(type, kids = []) {
|
|
1543
|
+
return $mol_tree2.struct(type, kids, this.span);
|
|
1544
|
+
}
|
|
1545
|
+
clone(kids, span = this.span) {
|
|
1546
|
+
return new $mol_tree2(this.type, this.value, kids, span);
|
|
1547
|
+
}
|
|
1548
|
+
text() {
|
|
1636
1549
|
var values = [];
|
|
1637
|
-
for (var
|
|
1638
|
-
if (
|
|
1550
|
+
for (var kid of this.kids) {
|
|
1551
|
+
if (kid.type)
|
|
1639
1552
|
continue;
|
|
1640
|
-
values.push(
|
|
1553
|
+
values.push(kid.value);
|
|
1641
1554
|
}
|
|
1642
|
-
return this.
|
|
1555
|
+
return this.value + values.join('\n');
|
|
1556
|
+
}
|
|
1557
|
+
static fromString(str, uri = 'unknown') {
|
|
1558
|
+
return $$.$mol_tree2_from_string(str, uri);
|
|
1559
|
+
}
|
|
1560
|
+
toString() {
|
|
1561
|
+
return $$.$mol_tree2_to_string(this);
|
|
1643
1562
|
}
|
|
1644
1563
|
insert(value, ...path) {
|
|
1645
1564
|
if (path.length === 0)
|
|
@@ -1647,83 +1566,252 @@ var $;
|
|
|
1647
1566
|
const type = path[0];
|
|
1648
1567
|
if (typeof type === 'string') {
|
|
1649
1568
|
let replaced = false;
|
|
1650
|
-
const sub = this.
|
|
1569
|
+
const sub = this.kids.map((item, index) => {
|
|
1651
1570
|
if (item.type !== type)
|
|
1652
1571
|
return item;
|
|
1653
1572
|
replaced = true;
|
|
1654
1573
|
return item.insert(value, ...path.slice(1));
|
|
1655
|
-
});
|
|
1656
|
-
if (!replaced)
|
|
1657
|
-
sub.push(
|
|
1658
|
-
|
|
1574
|
+
}).filter(Boolean);
|
|
1575
|
+
if (!replaced && value) {
|
|
1576
|
+
sub.push(this.struct(type, []).insert(value, ...path.slice(1)));
|
|
1577
|
+
}
|
|
1578
|
+
return this.clone(sub);
|
|
1659
1579
|
}
|
|
1660
1580
|
else if (typeof type === 'number') {
|
|
1661
|
-
const sub = this.
|
|
1662
|
-
sub[type] = (sub[type] ||
|
|
1663
|
-
|
|
1581
|
+
const sub = this.kids.slice();
|
|
1582
|
+
sub[type] = (sub[type] || this.list([]))
|
|
1583
|
+
.insert(value, ...path.slice(1));
|
|
1584
|
+
return this.clone(sub.filter(Boolean));
|
|
1664
1585
|
}
|
|
1665
1586
|
else {
|
|
1666
|
-
|
|
1587
|
+
const kids = ((this.kids.length === 0) ? [this.list([])] : this.kids)
|
|
1588
|
+
.map(item => item.insert(value, ...path.slice(1)))
|
|
1589
|
+
.filter(Boolean);
|
|
1590
|
+
return this.clone(kids);
|
|
1667
1591
|
}
|
|
1668
1592
|
}
|
|
1669
1593
|
select(...path) {
|
|
1670
|
-
|
|
1671
|
-
for (
|
|
1594
|
+
let next = [this];
|
|
1595
|
+
for (const type of path) {
|
|
1672
1596
|
if (!next.length)
|
|
1673
1597
|
break;
|
|
1674
|
-
|
|
1598
|
+
const prev = next;
|
|
1675
1599
|
next = [];
|
|
1676
1600
|
for (var item of prev) {
|
|
1677
1601
|
switch (typeof (type)) {
|
|
1678
1602
|
case 'string':
|
|
1679
|
-
for (var child of item.
|
|
1680
|
-
if (
|
|
1603
|
+
for (var child of item.kids) {
|
|
1604
|
+
if (child.type == type) {
|
|
1681
1605
|
next.push(child);
|
|
1682
1606
|
}
|
|
1683
1607
|
}
|
|
1684
1608
|
break;
|
|
1685
1609
|
case 'number':
|
|
1686
|
-
if (type < item.
|
|
1687
|
-
next.push(item.
|
|
1610
|
+
if (type < item.kids.length)
|
|
1611
|
+
next.push(item.kids[type]);
|
|
1688
1612
|
break;
|
|
1689
|
-
default: next.push(...item.
|
|
1613
|
+
default: next.push(...item.kids);
|
|
1690
1614
|
}
|
|
1691
1615
|
}
|
|
1692
1616
|
}
|
|
1693
|
-
return
|
|
1617
|
+
return this.list(next);
|
|
1694
1618
|
}
|
|
1695
1619
|
filter(path, value) {
|
|
1696
|
-
|
|
1620
|
+
const sub = this.kids.filter(item => {
|
|
1697
1621
|
var found = item.select(...path);
|
|
1698
|
-
if (value
|
|
1699
|
-
return Boolean(found.
|
|
1622
|
+
if (value === undefined) {
|
|
1623
|
+
return Boolean(found.kids.length);
|
|
1700
1624
|
}
|
|
1701
1625
|
else {
|
|
1702
|
-
return found.
|
|
1626
|
+
return found.kids.some(child => child.value == value);
|
|
1703
1627
|
}
|
|
1704
1628
|
});
|
|
1705
|
-
return
|
|
1629
|
+
return this.clone(sub);
|
|
1630
|
+
}
|
|
1631
|
+
hack(belt, context = {}) {
|
|
1632
|
+
return [].concat(...this.kids.map(child => {
|
|
1633
|
+
let handle = belt[child.type] || belt[''];
|
|
1634
|
+
if (!handle || handle === Object.prototype[child.type]) {
|
|
1635
|
+
handle = (input, belt, context) => [
|
|
1636
|
+
input.clone(input.hack(belt, context), context.span)
|
|
1637
|
+
];
|
|
1638
|
+
}
|
|
1639
|
+
try {
|
|
1640
|
+
return handle(child, belt, context);
|
|
1641
|
+
}
|
|
1642
|
+
catch (error) {
|
|
1643
|
+
error.message += `\n${child.clone([])}${child.span}`;
|
|
1644
|
+
$mol_fail_hidden(error);
|
|
1645
|
+
}
|
|
1646
|
+
}));
|
|
1706
1647
|
}
|
|
1707
|
-
|
|
1708
|
-
|
|
1709
|
-
return visit(sub_stack, () => this.sub.map(node => node.transform(visit, sub_stack)).filter(n => n));
|
|
1648
|
+
error(message, Class = Error) {
|
|
1649
|
+
return this.span.error(`${message}\n${this.clone([])}`, Class);
|
|
1710
1650
|
}
|
|
1711
|
-
|
|
1712
|
-
|
|
1713
|
-
|
|
1714
|
-
|
|
1715
|
-
|
|
1716
|
-
return handle(child, context);
|
|
1717
|
-
}));
|
|
1718
|
-
return this.clone({ sub });
|
|
1651
|
+
}
|
|
1652
|
+
$.$mol_tree2 = $mol_tree2;
|
|
1653
|
+
class $mol_tree2_empty extends $mol_tree2 {
|
|
1654
|
+
constructor() {
|
|
1655
|
+
super('', '', [], $mol_span.unknown);
|
|
1719
1656
|
}
|
|
1720
|
-
|
|
1721
|
-
|
|
1657
|
+
}
|
|
1658
|
+
$.$mol_tree2_empty = $mol_tree2_empty;
|
|
1659
|
+
})($ || ($ = {}));
|
|
1660
|
+
//mol/tree2/tree2.ts
|
|
1661
|
+
;
|
|
1662
|
+
"use strict";
|
|
1663
|
+
var $;
|
|
1664
|
+
(function ($) {
|
|
1665
|
+
class $mol_error_syntax extends SyntaxError {
|
|
1666
|
+
reason;
|
|
1667
|
+
line;
|
|
1668
|
+
span;
|
|
1669
|
+
constructor(reason, line, span) {
|
|
1670
|
+
super(`${reason}\n${span}\n${line.substring(0, span.col - 1).replace(/\S/g, ' ')}${''.padEnd(span.length, '!')}\n${line}`);
|
|
1671
|
+
this.reason = reason;
|
|
1672
|
+
this.line = line;
|
|
1673
|
+
this.span = span;
|
|
1722
1674
|
}
|
|
1723
1675
|
}
|
|
1724
|
-
$.$
|
|
1676
|
+
$.$mol_error_syntax = $mol_error_syntax;
|
|
1725
1677
|
})($ || ($ = {}));
|
|
1726
|
-
//mol/
|
|
1678
|
+
//mol/error/syntax/syntax.ts
|
|
1679
|
+
;
|
|
1680
|
+
"use strict";
|
|
1681
|
+
var $;
|
|
1682
|
+
(function ($) {
|
|
1683
|
+
function $mol_tree2_from_string(str, uri = '?') {
|
|
1684
|
+
const span = $mol_span.entire(uri, str);
|
|
1685
|
+
var root = $mol_tree2.list([], span);
|
|
1686
|
+
var stack = [root];
|
|
1687
|
+
var pos = 0, row = 0, min_indent = 0;
|
|
1688
|
+
while (str.length > pos) {
|
|
1689
|
+
var indent = 0;
|
|
1690
|
+
var line_start = pos;
|
|
1691
|
+
row++;
|
|
1692
|
+
while (str.length > pos && str[pos] == '\t') {
|
|
1693
|
+
indent++;
|
|
1694
|
+
pos++;
|
|
1695
|
+
}
|
|
1696
|
+
if (!root.kids.length) {
|
|
1697
|
+
min_indent = indent;
|
|
1698
|
+
}
|
|
1699
|
+
indent -= min_indent;
|
|
1700
|
+
if (indent < 0 || indent >= stack.length) {
|
|
1701
|
+
const sp = span.span(row, 1, pos - line_start);
|
|
1702
|
+
while (str.length > pos && str[pos] != '\n') {
|
|
1703
|
+
pos++;
|
|
1704
|
+
}
|
|
1705
|
+
if (indent < 0) {
|
|
1706
|
+
if (str.length > pos) {
|
|
1707
|
+
this.$mol_fail(new this.$mol_error_syntax(`Too few tabs`, str.substring(line_start, pos), sp));
|
|
1708
|
+
}
|
|
1709
|
+
}
|
|
1710
|
+
else {
|
|
1711
|
+
this.$mol_fail(new this.$mol_error_syntax(`Too many tabs`, str.substring(line_start, pos), sp));
|
|
1712
|
+
}
|
|
1713
|
+
}
|
|
1714
|
+
stack.length = indent + 1;
|
|
1715
|
+
var parent = stack[indent];
|
|
1716
|
+
while (str.length > pos && str[pos] != '\\' && str[pos] != '\n') {
|
|
1717
|
+
var error_start = pos;
|
|
1718
|
+
while (str.length > pos && (str[pos] == ' ' || str[pos] == '\t')) {
|
|
1719
|
+
pos++;
|
|
1720
|
+
}
|
|
1721
|
+
if (pos > error_start) {
|
|
1722
|
+
let line_end = str.indexOf('\n', pos);
|
|
1723
|
+
if (line_end === -1)
|
|
1724
|
+
line_end = str.length;
|
|
1725
|
+
const sp = span.span(row, error_start - line_start, pos - error_start + 1);
|
|
1726
|
+
this.$mol_fail(new this.$mol_error_syntax(`Wrong nodes separator`, str.substring(line_start, line_end), sp));
|
|
1727
|
+
}
|
|
1728
|
+
var type_start = pos;
|
|
1729
|
+
while (str.length > pos &&
|
|
1730
|
+
str[pos] != '\\' &&
|
|
1731
|
+
str[pos] != ' ' &&
|
|
1732
|
+
str[pos] != '\t' &&
|
|
1733
|
+
str[pos] != '\n') {
|
|
1734
|
+
pos++;
|
|
1735
|
+
}
|
|
1736
|
+
if (pos > type_start) {
|
|
1737
|
+
let next = new $mol_tree2(str.slice(type_start, pos), '', [], span.span(row, type_start - line_start + 1, pos - type_start));
|
|
1738
|
+
const parent_kids = parent.kids;
|
|
1739
|
+
parent_kids.push(next);
|
|
1740
|
+
parent = next;
|
|
1741
|
+
}
|
|
1742
|
+
if (str.length > pos && str[pos] == ' ') {
|
|
1743
|
+
pos++;
|
|
1744
|
+
}
|
|
1745
|
+
}
|
|
1746
|
+
if (str.length > pos && str[pos] == '\\') {
|
|
1747
|
+
var data_start = pos;
|
|
1748
|
+
while (str.length > pos && str[pos] != '\n') {
|
|
1749
|
+
pos++;
|
|
1750
|
+
}
|
|
1751
|
+
let next = new $mol_tree2('', str.slice(data_start + 1, pos), [], span.span(row, data_start - line_start + 2, pos - data_start - 1));
|
|
1752
|
+
const parent_kids = parent.kids;
|
|
1753
|
+
parent_kids.push(next);
|
|
1754
|
+
parent = next;
|
|
1755
|
+
}
|
|
1756
|
+
if (str.length === pos && stack.length > 0) {
|
|
1757
|
+
const sp = span.span(row, pos - line_start + 1, 1);
|
|
1758
|
+
this.$mol_fail(new this.$mol_error_syntax(`Undexpected EOF, LF required`, str.substring(line_start, str.length), sp));
|
|
1759
|
+
}
|
|
1760
|
+
stack.push(parent);
|
|
1761
|
+
pos++;
|
|
1762
|
+
}
|
|
1763
|
+
return root;
|
|
1764
|
+
}
|
|
1765
|
+
$.$mol_tree2_from_string = $mol_tree2_from_string;
|
|
1766
|
+
})($ || ($ = {}));
|
|
1767
|
+
//mol/tree2/from/string/string.ts
|
|
1768
|
+
;
|
|
1769
|
+
"use strict";
|
|
1770
|
+
var $;
|
|
1771
|
+
(function ($) {
|
|
1772
|
+
function $mol_tree2_from_json(json, span = $mol_span.unknown) {
|
|
1773
|
+
if (typeof json === 'boolean' || typeof json === 'number' || json === null) {
|
|
1774
|
+
return new $mol_tree2(String(json), '', [], span);
|
|
1775
|
+
}
|
|
1776
|
+
if (typeof json === 'string') {
|
|
1777
|
+
return $mol_tree2.data(json, [], span);
|
|
1778
|
+
}
|
|
1779
|
+
if (Array.isArray(json)) {
|
|
1780
|
+
const sub = json.map(json => $mol_tree2_from_json(json, span));
|
|
1781
|
+
return new $mol_tree2('/', '', sub, span);
|
|
1782
|
+
}
|
|
1783
|
+
if (ArrayBuffer.isView(json)) {
|
|
1784
|
+
const buf = new Uint8Array(json.buffer, json.byteOffset, json.byteLength);
|
|
1785
|
+
return $mol_tree2.data(String.fromCharCode(...buf), [], span);
|
|
1786
|
+
}
|
|
1787
|
+
if (json instanceof Date) {
|
|
1788
|
+
return new $mol_tree2('', json.toISOString(), [], span);
|
|
1789
|
+
}
|
|
1790
|
+
if (typeof json.toJSON === 'function') {
|
|
1791
|
+
return $mol_tree2_from_json(json.toJSON());
|
|
1792
|
+
}
|
|
1793
|
+
if (json instanceof Error) {
|
|
1794
|
+
const { name, message, stack } = json;
|
|
1795
|
+
json = { ...json, name, message, stack };
|
|
1796
|
+
}
|
|
1797
|
+
const sub = [];
|
|
1798
|
+
for (var key in json) {
|
|
1799
|
+
const val = json[key];
|
|
1800
|
+
if (val === undefined)
|
|
1801
|
+
continue;
|
|
1802
|
+
const subsub = $mol_tree2_from_json(val, span);
|
|
1803
|
+
if (/^[^\n\t\\ ]+$/.test(key)) {
|
|
1804
|
+
sub.push(new $mol_tree2(key, '', [subsub], span));
|
|
1805
|
+
}
|
|
1806
|
+
else {
|
|
1807
|
+
sub.push($mol_tree2.data(key, [subsub], span));
|
|
1808
|
+
}
|
|
1809
|
+
}
|
|
1810
|
+
return new $mol_tree2('*', '', sub, span);
|
|
1811
|
+
}
|
|
1812
|
+
$.$mol_tree2_from_json = $mol_tree2_from_json;
|
|
1813
|
+
})($ || ($ = {}));
|
|
1814
|
+
//mol/tree2/from/json/json.ts
|
|
1727
1815
|
;
|
|
1728
1816
|
"use strict";
|
|
1729
1817
|
var $;
|
|
@@ -1778,7 +1866,8 @@ var $;
|
|
|
1778
1866
|
return function $mol_log3_logger(event) {
|
|
1779
1867
|
if (!event.time)
|
|
1780
1868
|
event = { time: new Date().toISOString(), ...event };
|
|
1781
|
-
|
|
1869
|
+
let tree = this.$mol_tree2_from_json(event);
|
|
1870
|
+
tree = tree.struct(type, tree.kids);
|
|
1782
1871
|
let str = color(tree.toString());
|
|
1783
1872
|
this.console[level](str);
|
|
1784
1873
|
const self = this;
|
|
@@ -8225,6 +8314,511 @@ var $;
|
|
|
8225
8314
|
;
|
|
8226
8315
|
"use strict";
|
|
8227
8316
|
var $;
|
|
8317
|
+
(function ($_1) {
|
|
8318
|
+
$mol_test({
|
|
8319
|
+
'span for same uri'($) {
|
|
8320
|
+
const span = new $mol_span('test.ts', '', 1, 3, 4);
|
|
8321
|
+
const child = span.span(4, 5, 8);
|
|
8322
|
+
$mol_assert_equal(child.uri, 'test.ts');
|
|
8323
|
+
$mol_assert_equal(child.row, 4);
|
|
8324
|
+
$mol_assert_equal(child.col, 5);
|
|
8325
|
+
$mol_assert_equal(child.length, 8);
|
|
8326
|
+
},
|
|
8327
|
+
'span after of given position'($) {
|
|
8328
|
+
const span = new $mol_span('test.ts', '', 1, 3, 4);
|
|
8329
|
+
const child = span.after(11);
|
|
8330
|
+
$mol_assert_equal(child.uri, 'test.ts');
|
|
8331
|
+
$mol_assert_equal(child.row, 1);
|
|
8332
|
+
$mol_assert_equal(child.col, 7);
|
|
8333
|
+
$mol_assert_equal(child.length, 11);
|
|
8334
|
+
},
|
|
8335
|
+
'slice span - regular'($) {
|
|
8336
|
+
const span = new $mol_span('test.ts', '', 1, 3, 5);
|
|
8337
|
+
const child = span.slice(1, 4);
|
|
8338
|
+
$mol_assert_equal(child.row, 1);
|
|
8339
|
+
$mol_assert_equal(child.col, 4);
|
|
8340
|
+
$mol_assert_equal(child.length, 3);
|
|
8341
|
+
const child2 = span.slice(2, 2);
|
|
8342
|
+
$mol_assert_equal(child2.col, 5);
|
|
8343
|
+
$mol_assert_equal(child2.length, 0);
|
|
8344
|
+
},
|
|
8345
|
+
'slice span - negative'($) {
|
|
8346
|
+
const span = new $mol_span('test.ts', '', 1, 3, 5);
|
|
8347
|
+
const child = span.slice(-3, -1);
|
|
8348
|
+
$mol_assert_equal(child.row, 1);
|
|
8349
|
+
$mol_assert_equal(child.col, 5);
|
|
8350
|
+
$mol_assert_equal(child.length, 2);
|
|
8351
|
+
},
|
|
8352
|
+
'slice span - out of range'($) {
|
|
8353
|
+
const span = new $mol_span('test.ts', '', 1, 3, 5);
|
|
8354
|
+
$mol_assert_fail(() => span.slice(-1, 3));
|
|
8355
|
+
$mol_assert_fail(() => span.slice(1, 6));
|
|
8356
|
+
$mol_assert_fail(() => span.slice(1, 10));
|
|
8357
|
+
},
|
|
8358
|
+
'error handling'($) {
|
|
8359
|
+
const span = new $mol_span('test.ts', '', 1, 3, 4);
|
|
8360
|
+
const error = span.error('Some error\n');
|
|
8361
|
+
$mol_assert_equal(error.message, 'Some error\ntest.ts#1:3/4');
|
|
8362
|
+
}
|
|
8363
|
+
});
|
|
8364
|
+
})($ || ($ = {}));
|
|
8365
|
+
//mol/span/span.test.ts
|
|
8366
|
+
;
|
|
8367
|
+
"use strict";
|
|
8368
|
+
var $;
|
|
8369
|
+
(function ($_1) {
|
|
8370
|
+
$mol_test({
|
|
8371
|
+
'inserting'($) {
|
|
8372
|
+
$mol_assert_equal($.$mol_tree2_from_string('a b c d\n')
|
|
8373
|
+
.insert($mol_tree2.struct('x'), 'a', 'b', 'c')
|
|
8374
|
+
.toString(), 'a b x\n');
|
|
8375
|
+
$mol_assert_equal($.$mol_tree2_from_string('a b\n')
|
|
8376
|
+
.insert($mol_tree2.struct('x'), 'a', 'b', 'c', 'd')
|
|
8377
|
+
.toString(), 'a b c x\n');
|
|
8378
|
+
$mol_assert_equal($.$mol_tree2_from_string('a b c d\n')
|
|
8379
|
+
.insert($mol_tree2.struct('x'), 0, 0, 0)
|
|
8380
|
+
.toString(), 'a b x\n');
|
|
8381
|
+
$mol_assert_equal($.$mol_tree2_from_string('a b\n')
|
|
8382
|
+
.insert($mol_tree2.struct('x'), 0, 0, 0, 0)
|
|
8383
|
+
.toString(), 'a b \\\n\tx\n');
|
|
8384
|
+
$mol_assert_equal($.$mol_tree2_from_string('a b c d\n')
|
|
8385
|
+
.insert($mol_tree2.struct('x'), null, null, null)
|
|
8386
|
+
.toString(), 'a b x\n');
|
|
8387
|
+
$mol_assert_equal($.$mol_tree2_from_string('a b\n')
|
|
8388
|
+
.insert($mol_tree2.struct('x'), null, null, null, null)
|
|
8389
|
+
.toString(), 'a b \\\n\tx\n');
|
|
8390
|
+
},
|
|
8391
|
+
'deleting'($) {
|
|
8392
|
+
$mol_assert_equal($.$mol_tree2_from_string('a b c d\n')
|
|
8393
|
+
.insert(null, 'a', 'b', 'c')
|
|
8394
|
+
.toString(), 'a b\n');
|
|
8395
|
+
$mol_assert_equal($.$mol_tree2_from_string('a b c d\n')
|
|
8396
|
+
.insert(null, 0, 0, 0)
|
|
8397
|
+
.toString(), 'a b\n');
|
|
8398
|
+
},
|
|
8399
|
+
'hack'($) {
|
|
8400
|
+
const res = $.$mol_tree2_from_string(`foo bar xxx\n`)
|
|
8401
|
+
.hack({
|
|
8402
|
+
'bar': (input, belt) => [input.struct('777', input.hack(belt))],
|
|
8403
|
+
});
|
|
8404
|
+
$mol_assert_equal(res.toString(), 'foo 777 xxx\n');
|
|
8405
|
+
},
|
|
8406
|
+
});
|
|
8407
|
+
})($ || ($ = {}));
|
|
8408
|
+
//mol/tree2/tree2.test.ts
|
|
8409
|
+
;
|
|
8410
|
+
"use strict";
|
|
8411
|
+
var $;
|
|
8412
|
+
(function ($_1) {
|
|
8413
|
+
$mol_test({
|
|
8414
|
+
'tree parsing'($) {
|
|
8415
|
+
$mol_assert_equal($.$mol_tree2_from_string("foo\nbar\n").kids.length, 2);
|
|
8416
|
+
$mol_assert_equal($.$mol_tree2_from_string("foo\nbar\n").kids[1].type, "bar");
|
|
8417
|
+
$mol_assert_equal($.$mol_tree2_from_string("foo\n\n\n").kids.length, 1);
|
|
8418
|
+
$mol_assert_equal($.$mol_tree2_from_string("=foo\n\\bar\n").kids.length, 2);
|
|
8419
|
+
$mol_assert_equal($.$mol_tree2_from_string("=foo\n\\bar\n").kids[1].value, "bar");
|
|
8420
|
+
$mol_assert_equal($.$mol_tree2_from_string("foo bar \\pol\n").kids[0].kids[0].kids[0].value, "pol");
|
|
8421
|
+
$mol_assert_equal($.$mol_tree2_from_string("foo bar\n\t\\pol\n\t\\men\n").kids[0].kids[0].kids[1].value, "men");
|
|
8422
|
+
$mol_assert_equal($.$mol_tree2_from_string('foo bar \\text\n').toString(), 'foo bar \\text\n');
|
|
8423
|
+
},
|
|
8424
|
+
'Too many tabs'($) {
|
|
8425
|
+
const tree = `
|
|
8426
|
+
foo
|
|
8427
|
+
bar
|
|
8428
|
+
`;
|
|
8429
|
+
$mol_assert_fail(() => {
|
|
8430
|
+
$.$mol_tree2_from_string(tree, 'test');
|
|
8431
|
+
}, 'Too many tabs\ntest#3:1/6\n!!!!!!\n\t\t\t\t\t\tbar');
|
|
8432
|
+
},
|
|
8433
|
+
'Too few tabs'($) {
|
|
8434
|
+
const tree = `
|
|
8435
|
+
foo
|
|
8436
|
+
bar
|
|
8437
|
+
`;
|
|
8438
|
+
$mol_assert_fail(() => {
|
|
8439
|
+
$.$mol_tree2_from_string(tree, 'test');
|
|
8440
|
+
}, 'Too few tabs\ntest#3:1/4\n!!!!\n\t\t\t\tbar');
|
|
8441
|
+
},
|
|
8442
|
+
'Wrong nodes separator'($) {
|
|
8443
|
+
const tree = `foo bar\n`;
|
|
8444
|
+
$mol_assert_fail(() => {
|
|
8445
|
+
$.$mol_tree2_from_string(tree, 'test');
|
|
8446
|
+
}, 'Wrong nodes separator\ntest#1:4/2\n !!\nfoo bar');
|
|
8447
|
+
},
|
|
8448
|
+
'Undexpected EOF, LF required'($) {
|
|
8449
|
+
const tree = ` foo`;
|
|
8450
|
+
$mol_assert_fail(() => {
|
|
8451
|
+
$.$mol_tree2_from_string(tree, 'test');
|
|
8452
|
+
}, 'Undexpected EOF, LF required\ntest#1:5/1\n !\n foo');
|
|
8453
|
+
},
|
|
8454
|
+
'Errors skip and collect'($) {
|
|
8455
|
+
const tree = `foo bar`;
|
|
8456
|
+
const errors = [];
|
|
8457
|
+
const $$ = $.$mol_ambient({
|
|
8458
|
+
$mol_fail: (error) => {
|
|
8459
|
+
errors.push(error.message);
|
|
8460
|
+
return null;
|
|
8461
|
+
}
|
|
8462
|
+
});
|
|
8463
|
+
const res = $$.$mol_tree2_from_string(tree, 'test');
|
|
8464
|
+
$mol_assert_like(errors, [
|
|
8465
|
+
'Wrong nodes separator\ntest#1:4/2\n !!\nfoo bar',
|
|
8466
|
+
'Undexpected EOF, LF required\ntest#1:9/1\n !\nfoo bar',
|
|
8467
|
+
]);
|
|
8468
|
+
$mol_assert_equal(res.toString(), 'foo bar\n');
|
|
8469
|
+
},
|
|
8470
|
+
});
|
|
8471
|
+
})($ || ($ = {}));
|
|
8472
|
+
//mol/tree2/from/string/string.test.ts
|
|
8473
|
+
;
|
|
8474
|
+
"use strict";
|
|
8475
|
+
var $;
|
|
8476
|
+
(function ($) {
|
|
8477
|
+
$mol_test({
|
|
8478
|
+
'fromJSON'() {
|
|
8479
|
+
$mol_assert_equal($mol_tree2_from_json([]).toString(), '/\n');
|
|
8480
|
+
$mol_assert_equal($mol_tree2_from_json([false, true]).toString(), '/\n\tfalse\n\ttrue\n');
|
|
8481
|
+
$mol_assert_equal($mol_tree2_from_json([0, 1, 2.3]).toString(), '/\n\t0\n\t1\n\t2.3\n');
|
|
8482
|
+
$mol_assert_equal($mol_tree2_from_json(new Uint16Array([1, 10, 256])).toString(), '\\\x01\x00\n\\\x00\x00\x01\n');
|
|
8483
|
+
$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');
|
|
8484
|
+
$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');
|
|
8485
|
+
},
|
|
8486
|
+
});
|
|
8487
|
+
})($ || ($ = {}));
|
|
8488
|
+
//mol/tree2/from/json/json.test.ts
|
|
8489
|
+
;
|
|
8490
|
+
"use strict";
|
|
8491
|
+
var $;
|
|
8492
|
+
(function ($) {
|
|
8493
|
+
$.$mol_tree_convert = Symbol('$mol_tree_convert');
|
|
8494
|
+
class $mol_tree extends $mol_object2 {
|
|
8495
|
+
type;
|
|
8496
|
+
data;
|
|
8497
|
+
sub;
|
|
8498
|
+
baseUri;
|
|
8499
|
+
row;
|
|
8500
|
+
col;
|
|
8501
|
+
length;
|
|
8502
|
+
constructor(config = {}) {
|
|
8503
|
+
super();
|
|
8504
|
+
this.type = config.type || '';
|
|
8505
|
+
if (config.value !== undefined) {
|
|
8506
|
+
var sub = $mol_tree.values(config.value);
|
|
8507
|
+
if (config.type || sub.length > 1) {
|
|
8508
|
+
this.sub = [...sub, ...(config.sub || [])];
|
|
8509
|
+
this.data = config.data || '';
|
|
8510
|
+
}
|
|
8511
|
+
else {
|
|
8512
|
+
this.data = sub[0].data;
|
|
8513
|
+
this.sub = config.sub || [];
|
|
8514
|
+
}
|
|
8515
|
+
}
|
|
8516
|
+
else {
|
|
8517
|
+
this.data = config.data || '';
|
|
8518
|
+
this.sub = config.sub || [];
|
|
8519
|
+
}
|
|
8520
|
+
this.baseUri = config.baseUri || '';
|
|
8521
|
+
this.row = config.row || 0;
|
|
8522
|
+
this.col = config.col || 0;
|
|
8523
|
+
this.length = config.length || 0;
|
|
8524
|
+
}
|
|
8525
|
+
static values(str, baseUri) {
|
|
8526
|
+
return str.split('\n').map((data, index) => new $mol_tree({
|
|
8527
|
+
data: data,
|
|
8528
|
+
baseUri: baseUri,
|
|
8529
|
+
row: index + 1,
|
|
8530
|
+
length: data.length,
|
|
8531
|
+
}));
|
|
8532
|
+
}
|
|
8533
|
+
clone(config = {}) {
|
|
8534
|
+
return new $mol_tree({
|
|
8535
|
+
type: ('type' in config) ? config.type : this.type,
|
|
8536
|
+
data: ('data' in config) ? config.data : this.data,
|
|
8537
|
+
sub: ('sub' in config) ? config.sub : this.sub,
|
|
8538
|
+
baseUri: ('baseUri' in config) ? config.baseUri : this.baseUri,
|
|
8539
|
+
row: ('row' in config) ? config.row : this.row,
|
|
8540
|
+
col: ('col' in config) ? config.col : this.col,
|
|
8541
|
+
length: ('length' in config) ? config.length : this.length,
|
|
8542
|
+
value: config.value
|
|
8543
|
+
});
|
|
8544
|
+
}
|
|
8545
|
+
make(config) {
|
|
8546
|
+
return new $mol_tree({
|
|
8547
|
+
baseUri: this.baseUri,
|
|
8548
|
+
row: this.row,
|
|
8549
|
+
col: this.col,
|
|
8550
|
+
length: this.length,
|
|
8551
|
+
...config,
|
|
8552
|
+
});
|
|
8553
|
+
}
|
|
8554
|
+
make_data(value, sub) {
|
|
8555
|
+
return this.make({ value, sub });
|
|
8556
|
+
}
|
|
8557
|
+
make_struct(type, sub) {
|
|
8558
|
+
return this.make({ type, sub });
|
|
8559
|
+
}
|
|
8560
|
+
static fromString(str, baseUri) {
|
|
8561
|
+
var root = new $mol_tree({ baseUri: baseUri });
|
|
8562
|
+
var stack = [root];
|
|
8563
|
+
var row = 0;
|
|
8564
|
+
var prefix = str.replace(/^\n?(\t*)[\s\S]*/, '$1');
|
|
8565
|
+
var lines = str.replace(new RegExp('^\\t{0,' + prefix.length + '}', 'mg'), '').split('\n');
|
|
8566
|
+
lines.forEach(line => {
|
|
8567
|
+
++row;
|
|
8568
|
+
var chunks = /^(\t*)((?:[^\n\t\\ ]+ *)*)(\\[^\n]*)?(.*?)(?:$|\n)/m.exec(line);
|
|
8569
|
+
if (!chunks || chunks[4])
|
|
8570
|
+
return this.$.$mol_fail(new Error(`Syntax error at ${baseUri}:${row}\n${line}`));
|
|
8571
|
+
var indent = chunks[1];
|
|
8572
|
+
var path = chunks[2];
|
|
8573
|
+
var data = chunks[3];
|
|
8574
|
+
var deep = indent.length;
|
|
8575
|
+
var types = path ? path.replace(/ $/, '').split(/ +/) : [];
|
|
8576
|
+
if (stack.length <= deep)
|
|
8577
|
+
return this.$.$mol_fail(new Error(`Too many tabs at ${baseUri}:${row}\n${line}`));
|
|
8578
|
+
stack.length = deep + 1;
|
|
8579
|
+
var parent = stack[deep];
|
|
8580
|
+
let col = deep;
|
|
8581
|
+
types.forEach(type => {
|
|
8582
|
+
if (!type)
|
|
8583
|
+
return this.$.$mol_fail(new Error(`Unexpected space symbol ${baseUri}:${row}\n${line}`));
|
|
8584
|
+
var next = new $mol_tree({ type, baseUri, row, col, length: type.length });
|
|
8585
|
+
const parent_sub = parent.sub;
|
|
8586
|
+
parent_sub.push(next);
|
|
8587
|
+
parent = next;
|
|
8588
|
+
col += type.length + 1;
|
|
8589
|
+
});
|
|
8590
|
+
if (data) {
|
|
8591
|
+
var next = new $mol_tree({ data: data.substring(1), baseUri, row, col, length: data.length });
|
|
8592
|
+
const parent_sub = parent.sub;
|
|
8593
|
+
parent_sub.push(next);
|
|
8594
|
+
parent = next;
|
|
8595
|
+
}
|
|
8596
|
+
stack.push(parent);
|
|
8597
|
+
});
|
|
8598
|
+
return root;
|
|
8599
|
+
}
|
|
8600
|
+
static fromJSON(json, baseUri = '') {
|
|
8601
|
+
switch (true) {
|
|
8602
|
+
case typeof json === 'boolean':
|
|
8603
|
+
case typeof json === 'number':
|
|
8604
|
+
case json === null:
|
|
8605
|
+
return new $mol_tree({
|
|
8606
|
+
type: String(json),
|
|
8607
|
+
baseUri: baseUri
|
|
8608
|
+
});
|
|
8609
|
+
case typeof json === 'string':
|
|
8610
|
+
return new $mol_tree({
|
|
8611
|
+
value: json,
|
|
8612
|
+
baseUri: baseUri
|
|
8613
|
+
});
|
|
8614
|
+
case Array.isArray(json):
|
|
8615
|
+
return new $mol_tree({
|
|
8616
|
+
type: "/",
|
|
8617
|
+
sub: json.map(json => $mol_tree.fromJSON(json, baseUri))
|
|
8618
|
+
});
|
|
8619
|
+
case json instanceof Date:
|
|
8620
|
+
return new $mol_tree({
|
|
8621
|
+
value: json.toISOString(),
|
|
8622
|
+
baseUri: baseUri
|
|
8623
|
+
});
|
|
8624
|
+
default:
|
|
8625
|
+
if (typeof json[$.$mol_tree_convert] === 'function') {
|
|
8626
|
+
return json[$.$mol_tree_convert]();
|
|
8627
|
+
}
|
|
8628
|
+
if (typeof json.toJSON === 'function') {
|
|
8629
|
+
return $mol_tree.fromJSON(json.toJSON());
|
|
8630
|
+
}
|
|
8631
|
+
if (json instanceof Error) {
|
|
8632
|
+
const { name, message, stack } = json;
|
|
8633
|
+
json = { ...json, name, message, stack };
|
|
8634
|
+
}
|
|
8635
|
+
var sub = [];
|
|
8636
|
+
for (var key in json) {
|
|
8637
|
+
if (json[key] === undefined)
|
|
8638
|
+
continue;
|
|
8639
|
+
const subsub = $mol_tree.fromJSON(json[key], baseUri);
|
|
8640
|
+
if (/^[^\n\t\\ ]+$/.test(key)) {
|
|
8641
|
+
var child = new $mol_tree({
|
|
8642
|
+
type: key,
|
|
8643
|
+
baseUri: baseUri,
|
|
8644
|
+
sub: [subsub],
|
|
8645
|
+
});
|
|
8646
|
+
}
|
|
8647
|
+
else {
|
|
8648
|
+
var child = new $mol_tree({
|
|
8649
|
+
value: key,
|
|
8650
|
+
baseUri: baseUri,
|
|
8651
|
+
sub: [subsub],
|
|
8652
|
+
});
|
|
8653
|
+
}
|
|
8654
|
+
sub.push(child);
|
|
8655
|
+
}
|
|
8656
|
+
return new $mol_tree({
|
|
8657
|
+
type: "*",
|
|
8658
|
+
sub: sub,
|
|
8659
|
+
baseUri: baseUri
|
|
8660
|
+
});
|
|
8661
|
+
}
|
|
8662
|
+
}
|
|
8663
|
+
get uri() {
|
|
8664
|
+
return this.baseUri + '#' + this.row + ':' + this.col;
|
|
8665
|
+
}
|
|
8666
|
+
toString(prefix = '') {
|
|
8667
|
+
var output = '';
|
|
8668
|
+
if (this.type.length) {
|
|
8669
|
+
if (!prefix.length) {
|
|
8670
|
+
prefix = "\t";
|
|
8671
|
+
}
|
|
8672
|
+
output += this.type;
|
|
8673
|
+
if (this.sub.length == 1) {
|
|
8674
|
+
return output + ' ' + this.sub[0].toString(prefix);
|
|
8675
|
+
}
|
|
8676
|
+
output += "\n";
|
|
8677
|
+
}
|
|
8678
|
+
else if (this.data.length || prefix.length) {
|
|
8679
|
+
output += "\\" + this.data + "\n";
|
|
8680
|
+
}
|
|
8681
|
+
for (var child of this.sub) {
|
|
8682
|
+
output += prefix;
|
|
8683
|
+
output += child.toString(prefix + "\t");
|
|
8684
|
+
}
|
|
8685
|
+
return output;
|
|
8686
|
+
}
|
|
8687
|
+
toJSON() {
|
|
8688
|
+
if (!this.type)
|
|
8689
|
+
return this.value;
|
|
8690
|
+
if (this.type === 'true')
|
|
8691
|
+
return true;
|
|
8692
|
+
if (this.type === 'false')
|
|
8693
|
+
return false;
|
|
8694
|
+
if (this.type === 'null')
|
|
8695
|
+
return null;
|
|
8696
|
+
if (this.type === '*') {
|
|
8697
|
+
var obj = {};
|
|
8698
|
+
for (var child of this.sub) {
|
|
8699
|
+
if (child.type === '-')
|
|
8700
|
+
continue;
|
|
8701
|
+
var key = child.type || child.clone({ sub: child.sub.slice(0, child.sub.length - 1) }).value;
|
|
8702
|
+
var val = child.sub[child.sub.length - 1].toJSON();
|
|
8703
|
+
if (val !== undefined)
|
|
8704
|
+
obj[key] = val;
|
|
8705
|
+
}
|
|
8706
|
+
return obj;
|
|
8707
|
+
}
|
|
8708
|
+
if (this.type === '/') {
|
|
8709
|
+
var res = [];
|
|
8710
|
+
this.sub.forEach(child => {
|
|
8711
|
+
if (child.type === '-')
|
|
8712
|
+
return;
|
|
8713
|
+
var val = child.toJSON();
|
|
8714
|
+
if (val !== undefined)
|
|
8715
|
+
res.push(val);
|
|
8716
|
+
});
|
|
8717
|
+
return res;
|
|
8718
|
+
}
|
|
8719
|
+
if (this.type === 'time') {
|
|
8720
|
+
return new Date(this.value);
|
|
8721
|
+
}
|
|
8722
|
+
const numb = Number(this.type);
|
|
8723
|
+
if (!Number.isNaN(numb) || this.type === 'NaN')
|
|
8724
|
+
return numb;
|
|
8725
|
+
throw new Error(`Unknown type (${this.type}) at ${this.uri}`);
|
|
8726
|
+
}
|
|
8727
|
+
get value() {
|
|
8728
|
+
var values = [];
|
|
8729
|
+
for (var child of this.sub) {
|
|
8730
|
+
if (child.type)
|
|
8731
|
+
continue;
|
|
8732
|
+
values.push(child.value);
|
|
8733
|
+
}
|
|
8734
|
+
return this.data + values.join("\n");
|
|
8735
|
+
}
|
|
8736
|
+
insert(value, ...path) {
|
|
8737
|
+
if (path.length === 0)
|
|
8738
|
+
return value;
|
|
8739
|
+
const type = path[0];
|
|
8740
|
+
if (typeof type === 'string') {
|
|
8741
|
+
let replaced = false;
|
|
8742
|
+
const sub = this.sub.map((item, index) => {
|
|
8743
|
+
if (item.type !== type)
|
|
8744
|
+
return item;
|
|
8745
|
+
replaced = true;
|
|
8746
|
+
return item.insert(value, ...path.slice(1));
|
|
8747
|
+
});
|
|
8748
|
+
if (!replaced)
|
|
8749
|
+
sub.push(new $mol_tree({ type }).insert(value, ...path.slice(1)));
|
|
8750
|
+
return this.clone({ sub });
|
|
8751
|
+
}
|
|
8752
|
+
else if (typeof type === 'number') {
|
|
8753
|
+
const sub = this.sub.slice();
|
|
8754
|
+
sub[type] = (sub[type] || new $mol_tree).insert(value, ...path.slice(1));
|
|
8755
|
+
return this.clone({ sub });
|
|
8756
|
+
}
|
|
8757
|
+
else {
|
|
8758
|
+
return this.clone({ sub: ((this.sub.length === 0) ? [new $mol_tree()] : this.sub).map(item => item.insert(value, ...path.slice(1))) });
|
|
8759
|
+
}
|
|
8760
|
+
}
|
|
8761
|
+
select(...path) {
|
|
8762
|
+
var next = [this];
|
|
8763
|
+
for (var type of path) {
|
|
8764
|
+
if (!next.length)
|
|
8765
|
+
break;
|
|
8766
|
+
var prev = next;
|
|
8767
|
+
next = [];
|
|
8768
|
+
for (var item of prev) {
|
|
8769
|
+
switch (typeof (type)) {
|
|
8770
|
+
case 'string':
|
|
8771
|
+
for (var child of item.sub) {
|
|
8772
|
+
if (!type || (child.type == type)) {
|
|
8773
|
+
next.push(child);
|
|
8774
|
+
}
|
|
8775
|
+
}
|
|
8776
|
+
break;
|
|
8777
|
+
case 'number':
|
|
8778
|
+
if (type < item.sub.length)
|
|
8779
|
+
next.push(item.sub[type]);
|
|
8780
|
+
break;
|
|
8781
|
+
default: next.push(...item.sub);
|
|
8782
|
+
}
|
|
8783
|
+
}
|
|
8784
|
+
}
|
|
8785
|
+
return new $mol_tree({ sub: next });
|
|
8786
|
+
}
|
|
8787
|
+
filter(path, value) {
|
|
8788
|
+
var sub = this.sub.filter(function (item) {
|
|
8789
|
+
var found = item.select(...path);
|
|
8790
|
+
if (value == null) {
|
|
8791
|
+
return Boolean(found.sub.length);
|
|
8792
|
+
}
|
|
8793
|
+
else {
|
|
8794
|
+
return found.sub.some(child => child.value == value);
|
|
8795
|
+
}
|
|
8796
|
+
});
|
|
8797
|
+
return new $mol_tree({ sub: sub });
|
|
8798
|
+
}
|
|
8799
|
+
transform(visit, stack = []) {
|
|
8800
|
+
const sub_stack = [this, ...stack];
|
|
8801
|
+
return visit(sub_stack, () => this.sub.map(node => node.transform(visit, sub_stack)).filter(n => n));
|
|
8802
|
+
}
|
|
8803
|
+
hack(context) {
|
|
8804
|
+
const sub = [].concat(...this.sub.map(child => {
|
|
8805
|
+
const handle = context[child.type] || context[''];
|
|
8806
|
+
if (!handle)
|
|
8807
|
+
$mol_fail(child.error('Handler not defined'));
|
|
8808
|
+
return handle(child, context);
|
|
8809
|
+
}));
|
|
8810
|
+
return this.clone({ sub });
|
|
8811
|
+
}
|
|
8812
|
+
error(message) {
|
|
8813
|
+
return new Error(`${message}:\n${this} ${this.baseUri}:${this.row}:${this.col}`);
|
|
8814
|
+
}
|
|
8815
|
+
}
|
|
8816
|
+
$.$mol_tree = $mol_tree;
|
|
8817
|
+
})($ || ($ = {}));
|
|
8818
|
+
//mol/tree/tree.ts
|
|
8819
|
+
;
|
|
8820
|
+
"use strict";
|
|
8821
|
+
var $;
|
|
8228
8822
|
(function ($_1) {
|
|
8229
8823
|
$mol_test({
|
|
8230
8824
|
'tree parsing'() {
|