mol_wire_lib 1.0.511 → 1.0.513
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 +506 -302
- package/node.test.js.map +1 -1
- package/package.json +10 -2
- package/web.deps.json +1 -1
package/node.mjs
CHANGED
|
@@ -1785,248 +1785,167 @@ var $;
|
|
|
1785
1785
|
"use strict";
|
|
1786
1786
|
var $;
|
|
1787
1787
|
(function ($) {
|
|
1788
|
-
|
|
1789
|
-
|
|
1790
|
-
|
|
1791
|
-
data;
|
|
1792
|
-
sub;
|
|
1793
|
-
baseUri;
|
|
1788
|
+
class $mol_span extends $mol_object2 {
|
|
1789
|
+
uri;
|
|
1790
|
+
source;
|
|
1794
1791
|
row;
|
|
1795
1792
|
col;
|
|
1796
1793
|
length;
|
|
1797
|
-
constructor(
|
|
1794
|
+
constructor(uri, source, row, col, length) {
|
|
1798
1795
|
super();
|
|
1799
|
-
this.
|
|
1800
|
-
|
|
1801
|
-
|
|
1802
|
-
|
|
1803
|
-
|
|
1804
|
-
|
|
1805
|
-
}
|
|
1806
|
-
else {
|
|
1807
|
-
this.data = sub[0].data;
|
|
1808
|
-
this.sub = config.sub || [];
|
|
1809
|
-
}
|
|
1810
|
-
}
|
|
1811
|
-
else {
|
|
1812
|
-
this.data = config.data || '';
|
|
1813
|
-
this.sub = config.sub || [];
|
|
1814
|
-
}
|
|
1815
|
-
this.baseUri = config.baseUri || '';
|
|
1816
|
-
this.row = config.row || 0;
|
|
1817
|
-
this.col = config.col || 0;
|
|
1818
|
-
this.length = config.length || 0;
|
|
1819
|
-
}
|
|
1820
|
-
static values(str, baseUri) {
|
|
1821
|
-
return str.split('\n').map((data, index) => new $mol_tree({
|
|
1822
|
-
data: data,
|
|
1823
|
-
baseUri: baseUri,
|
|
1824
|
-
row: index + 1,
|
|
1825
|
-
length: data.length,
|
|
1826
|
-
}));
|
|
1796
|
+
this.uri = uri;
|
|
1797
|
+
this.source = source;
|
|
1798
|
+
this.row = row;
|
|
1799
|
+
this.col = col;
|
|
1800
|
+
this.length = length;
|
|
1801
|
+
this[Symbol.toStringTag] = `${this.uri}#${this.row}:${this.col}/${this.length}`;
|
|
1827
1802
|
}
|
|
1828
|
-
|
|
1829
|
-
|
|
1830
|
-
|
|
1831
|
-
data: ('data' in config) ? config.data : this.data,
|
|
1832
|
-
sub: ('sub' in config) ? config.sub : this.sub,
|
|
1833
|
-
baseUri: ('baseUri' in config) ? config.baseUri : this.baseUri,
|
|
1834
|
-
row: ('row' in config) ? config.row : this.row,
|
|
1835
|
-
col: ('col' in config) ? config.col : this.col,
|
|
1836
|
-
length: ('length' in config) ? config.length : this.length,
|
|
1837
|
-
value: config.value
|
|
1838
|
-
});
|
|
1803
|
+
static unknown = $mol_span.begin('?');
|
|
1804
|
+
static begin(uri, source = '') {
|
|
1805
|
+
return new $mol_span(uri, source, 1, 1, 0);
|
|
1839
1806
|
}
|
|
1840
|
-
|
|
1841
|
-
return new $
|
|
1842
|
-
|
|
1807
|
+
static end(uri, source) {
|
|
1808
|
+
return new $mol_span(uri, source, 1, source.length + 1, length);
|
|
1809
|
+
}
|
|
1810
|
+
static entire(uri, source) {
|
|
1811
|
+
return new $mol_span(uri, source, 1, 1, source.length);
|
|
1812
|
+
}
|
|
1813
|
+
toString() {
|
|
1814
|
+
return this[Symbol.toStringTag];
|
|
1815
|
+
}
|
|
1816
|
+
toJSON() {
|
|
1817
|
+
return {
|
|
1818
|
+
uri: this.uri,
|
|
1843
1819
|
row: this.row,
|
|
1844
1820
|
col: this.col,
|
|
1845
|
-
length: this.length
|
|
1846
|
-
|
|
1847
|
-
});
|
|
1848
|
-
}
|
|
1849
|
-
make_data(value, sub) {
|
|
1850
|
-
return this.make({ value, sub });
|
|
1851
|
-
}
|
|
1852
|
-
make_struct(type, sub) {
|
|
1853
|
-
return this.make({ type, sub });
|
|
1854
|
-
}
|
|
1855
|
-
static fromString(str, baseUri) {
|
|
1856
|
-
var root = new $mol_tree({ baseUri: baseUri });
|
|
1857
|
-
var stack = [root];
|
|
1858
|
-
var row = 0;
|
|
1859
|
-
var prefix = str.replace(/^\n?(\t*)[\s\S]*/, '$1');
|
|
1860
|
-
var lines = str.replace(new RegExp('^\\t{0,' + prefix.length + '}', 'mg'), '').split('\n');
|
|
1861
|
-
lines.forEach(line => {
|
|
1862
|
-
++row;
|
|
1863
|
-
var chunks = /^(\t*)((?:[^\n\t\\ ]+ *)*)(\\[^\n]*)?(.*?)(?:$|\n)/m.exec(line);
|
|
1864
|
-
if (!chunks || chunks[4])
|
|
1865
|
-
return this.$.$mol_fail(new Error(`Syntax error at ${baseUri}:${row}\n${line}`));
|
|
1866
|
-
var indent = chunks[1];
|
|
1867
|
-
var path = chunks[2];
|
|
1868
|
-
var data = chunks[3];
|
|
1869
|
-
var deep = indent.length;
|
|
1870
|
-
var types = path ? path.replace(/ $/, '').split(/ +/) : [];
|
|
1871
|
-
if (stack.length <= deep)
|
|
1872
|
-
return this.$.$mol_fail(new Error(`Too many tabs at ${baseUri}:${row}\n${line}`));
|
|
1873
|
-
stack.length = deep + 1;
|
|
1874
|
-
var parent = stack[deep];
|
|
1875
|
-
let col = deep;
|
|
1876
|
-
types.forEach(type => {
|
|
1877
|
-
if (!type)
|
|
1878
|
-
return this.$.$mol_fail(new Error(`Unexpected space symbol ${baseUri}:${row}\n${line}`));
|
|
1879
|
-
var next = new $mol_tree({ type, baseUri, row, col, length: type.length });
|
|
1880
|
-
const parent_sub = parent.sub;
|
|
1881
|
-
parent_sub.push(next);
|
|
1882
|
-
parent = next;
|
|
1883
|
-
col += type.length + 1;
|
|
1884
|
-
});
|
|
1885
|
-
if (data) {
|
|
1886
|
-
var next = new $mol_tree({ data: data.substring(1), baseUri, row, col, length: data.length });
|
|
1887
|
-
const parent_sub = parent.sub;
|
|
1888
|
-
parent_sub.push(next);
|
|
1889
|
-
parent = next;
|
|
1890
|
-
}
|
|
1891
|
-
stack.push(parent);
|
|
1892
|
-
});
|
|
1893
|
-
return root;
|
|
1894
|
-
}
|
|
1895
|
-
static fromJSON(json, baseUri = '') {
|
|
1896
|
-
switch (true) {
|
|
1897
|
-
case typeof json === 'boolean':
|
|
1898
|
-
case typeof json === 'number':
|
|
1899
|
-
case json === null:
|
|
1900
|
-
return new $mol_tree({
|
|
1901
|
-
type: String(json),
|
|
1902
|
-
baseUri: baseUri
|
|
1903
|
-
});
|
|
1904
|
-
case typeof json === 'string':
|
|
1905
|
-
return new $mol_tree({
|
|
1906
|
-
value: json,
|
|
1907
|
-
baseUri: baseUri
|
|
1908
|
-
});
|
|
1909
|
-
case Array.isArray(json):
|
|
1910
|
-
return new $mol_tree({
|
|
1911
|
-
type: "/",
|
|
1912
|
-
sub: json.map(json => $mol_tree.fromJSON(json, baseUri))
|
|
1913
|
-
});
|
|
1914
|
-
case json instanceof Date:
|
|
1915
|
-
return new $mol_tree({
|
|
1916
|
-
value: json.toISOString(),
|
|
1917
|
-
baseUri: baseUri
|
|
1918
|
-
});
|
|
1919
|
-
default:
|
|
1920
|
-
if (typeof json[$.$mol_tree_convert] === 'function') {
|
|
1921
|
-
return json[$.$mol_tree_convert]();
|
|
1922
|
-
}
|
|
1923
|
-
if (typeof json.toJSON === 'function') {
|
|
1924
|
-
return $mol_tree.fromJSON(json.toJSON());
|
|
1925
|
-
}
|
|
1926
|
-
if (json instanceof Error) {
|
|
1927
|
-
const { name, message, stack } = json;
|
|
1928
|
-
json = { ...json, name, message, stack };
|
|
1929
|
-
}
|
|
1930
|
-
var sub = [];
|
|
1931
|
-
for (var key in json) {
|
|
1932
|
-
if (json[key] === undefined)
|
|
1933
|
-
continue;
|
|
1934
|
-
const subsub = $mol_tree.fromJSON(json[key], baseUri);
|
|
1935
|
-
if (/^[^\n\t\\ ]+$/.test(key)) {
|
|
1936
|
-
var child = new $mol_tree({
|
|
1937
|
-
type: key,
|
|
1938
|
-
baseUri: baseUri,
|
|
1939
|
-
sub: [subsub],
|
|
1940
|
-
});
|
|
1941
|
-
}
|
|
1942
|
-
else {
|
|
1943
|
-
var child = new $mol_tree({
|
|
1944
|
-
value: key,
|
|
1945
|
-
baseUri: baseUri,
|
|
1946
|
-
sub: [subsub],
|
|
1947
|
-
});
|
|
1948
|
-
}
|
|
1949
|
-
sub.push(child);
|
|
1950
|
-
}
|
|
1951
|
-
return new $mol_tree({
|
|
1952
|
-
type: "*",
|
|
1953
|
-
sub: sub,
|
|
1954
|
-
baseUri: baseUri
|
|
1955
|
-
});
|
|
1956
|
-
}
|
|
1821
|
+
length: this.length
|
|
1822
|
+
};
|
|
1957
1823
|
}
|
|
1958
|
-
|
|
1959
|
-
return
|
|
1824
|
+
error(message, Class = Error) {
|
|
1825
|
+
return new Class(`${message}${this}`);
|
|
1826
|
+
}
|
|
1827
|
+
span(row, col, length) {
|
|
1828
|
+
return new $mol_span(this.uri, this.source, row, col, length);
|
|
1829
|
+
}
|
|
1830
|
+
after(length = 0) {
|
|
1831
|
+
return new $mol_span(this.uri, this.source, this.row, this.col + this.length, length);
|
|
1832
|
+
}
|
|
1833
|
+
slice(begin, end = -1) {
|
|
1834
|
+
let len = this.length;
|
|
1835
|
+
if (begin < 0)
|
|
1836
|
+
begin += len;
|
|
1837
|
+
if (end < 0)
|
|
1838
|
+
end += len;
|
|
1839
|
+
if (begin < 0 || begin > len)
|
|
1840
|
+
this.$.$mol_fail(`Begin value '${begin}' out of range ${this}`);
|
|
1841
|
+
if (end < 0 || end > len)
|
|
1842
|
+
this.$.$mol_fail(`End value '${end}' out of range ${this}`);
|
|
1843
|
+
if (end < begin)
|
|
1844
|
+
this.$.$mol_fail(`End value '${end}' can't be less than begin value ${this}`);
|
|
1845
|
+
return this.span(this.row, this.col + begin, end - begin);
|
|
1960
1846
|
}
|
|
1961
|
-
|
|
1962
|
-
|
|
1963
|
-
|
|
1847
|
+
}
|
|
1848
|
+
$.$mol_span = $mol_span;
|
|
1849
|
+
})($ || ($ = {}));
|
|
1850
|
+
//mol/span/span.ts
|
|
1851
|
+
;
|
|
1852
|
+
"use strict";
|
|
1853
|
+
var $;
|
|
1854
|
+
(function ($) {
|
|
1855
|
+
function $mol_tree2_to_string(tree) {
|
|
1856
|
+
let output = [];
|
|
1857
|
+
function dump(tree, prefix = '') {
|
|
1858
|
+
if (tree.type.length) {
|
|
1964
1859
|
if (!prefix.length) {
|
|
1965
1860
|
prefix = "\t";
|
|
1966
1861
|
}
|
|
1967
|
-
output
|
|
1968
|
-
if (
|
|
1969
|
-
|
|
1862
|
+
output.push(tree.type);
|
|
1863
|
+
if (tree.kids.length == 1) {
|
|
1864
|
+
output.push(' ');
|
|
1865
|
+
dump(tree.kids[0], prefix);
|
|
1866
|
+
return;
|
|
1970
1867
|
}
|
|
1971
|
-
output
|
|
1868
|
+
output.push("\n");
|
|
1972
1869
|
}
|
|
1973
|
-
else if (
|
|
1974
|
-
output
|
|
1870
|
+
else if (tree.value.length || prefix.length) {
|
|
1871
|
+
output.push("\\" + tree.value + "\n");
|
|
1975
1872
|
}
|
|
1976
|
-
for (
|
|
1977
|
-
output
|
|
1978
|
-
|
|
1873
|
+
for (const kid of tree.kids) {
|
|
1874
|
+
output.push(prefix);
|
|
1875
|
+
dump(kid, prefix + "\t");
|
|
1979
1876
|
}
|
|
1980
|
-
return output;
|
|
1981
1877
|
}
|
|
1982
|
-
|
|
1983
|
-
|
|
1984
|
-
|
|
1985
|
-
|
|
1986
|
-
|
|
1987
|
-
|
|
1988
|
-
|
|
1989
|
-
|
|
1990
|
-
|
|
1991
|
-
|
|
1992
|
-
|
|
1993
|
-
|
|
1994
|
-
|
|
1995
|
-
|
|
1996
|
-
|
|
1997
|
-
|
|
1998
|
-
|
|
1999
|
-
|
|
2000
|
-
|
|
2001
|
-
|
|
2002
|
-
|
|
2003
|
-
|
|
2004
|
-
|
|
2005
|
-
|
|
2006
|
-
|
|
2007
|
-
|
|
2008
|
-
|
|
2009
|
-
|
|
2010
|
-
|
|
1878
|
+
dump(tree);
|
|
1879
|
+
return output.join('');
|
|
1880
|
+
}
|
|
1881
|
+
$.$mol_tree2_to_string = $mol_tree2_to_string;
|
|
1882
|
+
})($ || ($ = {}));
|
|
1883
|
+
//mol/tree2/to/string/string.ts
|
|
1884
|
+
;
|
|
1885
|
+
"use strict";
|
|
1886
|
+
var $;
|
|
1887
|
+
(function ($) {
|
|
1888
|
+
class $mol_tree2 extends Object {
|
|
1889
|
+
type;
|
|
1890
|
+
value;
|
|
1891
|
+
kids;
|
|
1892
|
+
span;
|
|
1893
|
+
constructor(type, value, kids, span) {
|
|
1894
|
+
super();
|
|
1895
|
+
this.type = type;
|
|
1896
|
+
this.value = value;
|
|
1897
|
+
this.kids = kids;
|
|
1898
|
+
this.span = span;
|
|
1899
|
+
this[Symbol.toStringTag] = type || '\\' + value;
|
|
1900
|
+
}
|
|
1901
|
+
static list(kids, span = $mol_span.unknown) {
|
|
1902
|
+
return new $mol_tree2('', '', kids, span);
|
|
1903
|
+
}
|
|
1904
|
+
list(kids) {
|
|
1905
|
+
return $mol_tree2.list(kids, this.span);
|
|
1906
|
+
}
|
|
1907
|
+
static data(value, kids = [], span = $mol_span.unknown) {
|
|
1908
|
+
const chunks = value.split('\n');
|
|
1909
|
+
if (chunks.length > 1) {
|
|
1910
|
+
let kid_span = span.span(span.row, span.col, 0);
|
|
1911
|
+
const data = chunks.map(chunk => {
|
|
1912
|
+
kid_span = kid_span.after(chunk.length);
|
|
1913
|
+
return new $mol_tree2('', chunk, [], kid_span);
|
|
2011
1914
|
});
|
|
2012
|
-
|
|
1915
|
+
kids = [...data, ...kids];
|
|
1916
|
+
value = '';
|
|
2013
1917
|
}
|
|
2014
|
-
|
|
2015
|
-
|
|
1918
|
+
return new $mol_tree2('', value, kids, span);
|
|
1919
|
+
}
|
|
1920
|
+
data(value, kids = []) {
|
|
1921
|
+
return $mol_tree2.data(value, kids, this.span);
|
|
1922
|
+
}
|
|
1923
|
+
static struct(type, kids = [], span = $mol_span.unknown) {
|
|
1924
|
+
if (/[ \n\t\\]/.test(type)) {
|
|
1925
|
+
$$.$mol_fail(span.error(`Wrong type ${JSON.stringify(type)}`));
|
|
2016
1926
|
}
|
|
2017
|
-
|
|
2018
|
-
|
|
2019
|
-
|
|
2020
|
-
|
|
1927
|
+
return new $mol_tree2(type, '', kids, span);
|
|
1928
|
+
}
|
|
1929
|
+
struct(type, kids = []) {
|
|
1930
|
+
return $mol_tree2.struct(type, kids, this.span);
|
|
1931
|
+
}
|
|
1932
|
+
clone(kids, span = this.span) {
|
|
1933
|
+
return new $mol_tree2(this.type, this.value, kids, span);
|
|
2021
1934
|
}
|
|
2022
|
-
|
|
1935
|
+
text() {
|
|
2023
1936
|
var values = [];
|
|
2024
|
-
for (var
|
|
2025
|
-
if (
|
|
1937
|
+
for (var kid of this.kids) {
|
|
1938
|
+
if (kid.type)
|
|
2026
1939
|
continue;
|
|
2027
|
-
values.push(
|
|
1940
|
+
values.push(kid.value);
|
|
2028
1941
|
}
|
|
2029
|
-
return this.
|
|
1942
|
+
return this.value + values.join('\n');
|
|
1943
|
+
}
|
|
1944
|
+
static fromString(str, uri = 'unknown') {
|
|
1945
|
+
return $$.$mol_tree2_from_string(str, uri);
|
|
1946
|
+
}
|
|
1947
|
+
toString() {
|
|
1948
|
+
return $$.$mol_tree2_to_string(this);
|
|
2030
1949
|
}
|
|
2031
1950
|
insert(value, ...path) {
|
|
2032
1951
|
if (path.length === 0)
|
|
@@ -2034,83 +1953,252 @@ var $;
|
|
|
2034
1953
|
const type = path[0];
|
|
2035
1954
|
if (typeof type === 'string') {
|
|
2036
1955
|
let replaced = false;
|
|
2037
|
-
const sub = this.
|
|
1956
|
+
const sub = this.kids.map((item, index) => {
|
|
2038
1957
|
if (item.type !== type)
|
|
2039
1958
|
return item;
|
|
2040
1959
|
replaced = true;
|
|
2041
1960
|
return item.insert(value, ...path.slice(1));
|
|
2042
|
-
});
|
|
2043
|
-
if (!replaced)
|
|
2044
|
-
sub.push(
|
|
2045
|
-
|
|
1961
|
+
}).filter(Boolean);
|
|
1962
|
+
if (!replaced && value) {
|
|
1963
|
+
sub.push(this.struct(type, []).insert(value, ...path.slice(1)));
|
|
1964
|
+
}
|
|
1965
|
+
return this.clone(sub);
|
|
2046
1966
|
}
|
|
2047
1967
|
else if (typeof type === 'number') {
|
|
2048
|
-
const sub = this.
|
|
2049
|
-
sub[type] = (sub[type] ||
|
|
2050
|
-
|
|
1968
|
+
const sub = this.kids.slice();
|
|
1969
|
+
sub[type] = (sub[type] || this.list([]))
|
|
1970
|
+
.insert(value, ...path.slice(1));
|
|
1971
|
+
return this.clone(sub.filter(Boolean));
|
|
2051
1972
|
}
|
|
2052
1973
|
else {
|
|
2053
|
-
|
|
1974
|
+
const kids = ((this.kids.length === 0) ? [this.list([])] : this.kids)
|
|
1975
|
+
.map(item => item.insert(value, ...path.slice(1)))
|
|
1976
|
+
.filter(Boolean);
|
|
1977
|
+
return this.clone(kids);
|
|
2054
1978
|
}
|
|
2055
1979
|
}
|
|
2056
1980
|
select(...path) {
|
|
2057
|
-
|
|
2058
|
-
for (
|
|
1981
|
+
let next = [this];
|
|
1982
|
+
for (const type of path) {
|
|
2059
1983
|
if (!next.length)
|
|
2060
1984
|
break;
|
|
2061
|
-
|
|
1985
|
+
const prev = next;
|
|
2062
1986
|
next = [];
|
|
2063
1987
|
for (var item of prev) {
|
|
2064
1988
|
switch (typeof (type)) {
|
|
2065
1989
|
case 'string':
|
|
2066
|
-
for (var child of item.
|
|
2067
|
-
if (
|
|
1990
|
+
for (var child of item.kids) {
|
|
1991
|
+
if (child.type == type) {
|
|
2068
1992
|
next.push(child);
|
|
2069
1993
|
}
|
|
2070
1994
|
}
|
|
2071
1995
|
break;
|
|
2072
1996
|
case 'number':
|
|
2073
|
-
if (type < item.
|
|
2074
|
-
next.push(item.
|
|
1997
|
+
if (type < item.kids.length)
|
|
1998
|
+
next.push(item.kids[type]);
|
|
2075
1999
|
break;
|
|
2076
|
-
default: next.push(...item.
|
|
2000
|
+
default: next.push(...item.kids);
|
|
2077
2001
|
}
|
|
2078
2002
|
}
|
|
2079
2003
|
}
|
|
2080
|
-
return
|
|
2004
|
+
return this.list(next);
|
|
2081
2005
|
}
|
|
2082
2006
|
filter(path, value) {
|
|
2083
|
-
|
|
2007
|
+
const sub = this.kids.filter(item => {
|
|
2084
2008
|
var found = item.select(...path);
|
|
2085
|
-
if (value
|
|
2086
|
-
return Boolean(found.
|
|
2009
|
+
if (value === undefined) {
|
|
2010
|
+
return Boolean(found.kids.length);
|
|
2087
2011
|
}
|
|
2088
2012
|
else {
|
|
2089
|
-
return found.
|
|
2013
|
+
return found.kids.some(child => child.value == value);
|
|
2090
2014
|
}
|
|
2091
2015
|
});
|
|
2092
|
-
return
|
|
2093
|
-
}
|
|
2094
|
-
|
|
2095
|
-
|
|
2096
|
-
|
|
2097
|
-
|
|
2098
|
-
|
|
2099
|
-
|
|
2100
|
-
|
|
2101
|
-
|
|
2102
|
-
|
|
2103
|
-
|
|
2016
|
+
return this.clone(sub);
|
|
2017
|
+
}
|
|
2018
|
+
hack(belt, context = {}) {
|
|
2019
|
+
return [].concat(...this.kids.map(child => {
|
|
2020
|
+
let handle = belt[child.type] || belt[''];
|
|
2021
|
+
if (!handle || handle === Object.prototype[child.type]) {
|
|
2022
|
+
handle = (input, belt, context) => [
|
|
2023
|
+
input.clone(input.hack(belt, context), context.span)
|
|
2024
|
+
];
|
|
2025
|
+
}
|
|
2026
|
+
try {
|
|
2027
|
+
return handle(child, belt, context);
|
|
2028
|
+
}
|
|
2029
|
+
catch (error) {
|
|
2030
|
+
error.message += `\n${child.clone([])}${child.span}`;
|
|
2031
|
+
$mol_fail_hidden(error);
|
|
2032
|
+
}
|
|
2104
2033
|
}));
|
|
2105
|
-
return this.clone({ sub });
|
|
2106
2034
|
}
|
|
2107
|
-
error(message) {
|
|
2108
|
-
return
|
|
2035
|
+
error(message, Class = Error) {
|
|
2036
|
+
return this.span.error(`${message}\n${this.clone([])}`, Class);
|
|
2037
|
+
}
|
|
2038
|
+
}
|
|
2039
|
+
$.$mol_tree2 = $mol_tree2;
|
|
2040
|
+
class $mol_tree2_empty extends $mol_tree2 {
|
|
2041
|
+
constructor() {
|
|
2042
|
+
super('', '', [], $mol_span.unknown);
|
|
2043
|
+
}
|
|
2044
|
+
}
|
|
2045
|
+
$.$mol_tree2_empty = $mol_tree2_empty;
|
|
2046
|
+
})($ || ($ = {}));
|
|
2047
|
+
//mol/tree2/tree2.ts
|
|
2048
|
+
;
|
|
2049
|
+
"use strict";
|
|
2050
|
+
var $;
|
|
2051
|
+
(function ($) {
|
|
2052
|
+
class $mol_error_syntax extends SyntaxError {
|
|
2053
|
+
reason;
|
|
2054
|
+
line;
|
|
2055
|
+
span;
|
|
2056
|
+
constructor(reason, line, span) {
|
|
2057
|
+
super(`${reason}\n${span}\n${line.substring(0, span.col - 1).replace(/\S/g, ' ')}${''.padEnd(span.length, '!')}\n${line}`);
|
|
2058
|
+
this.reason = reason;
|
|
2059
|
+
this.line = line;
|
|
2060
|
+
this.span = span;
|
|
2061
|
+
}
|
|
2062
|
+
}
|
|
2063
|
+
$.$mol_error_syntax = $mol_error_syntax;
|
|
2064
|
+
})($ || ($ = {}));
|
|
2065
|
+
//mol/error/syntax/syntax.ts
|
|
2066
|
+
;
|
|
2067
|
+
"use strict";
|
|
2068
|
+
var $;
|
|
2069
|
+
(function ($) {
|
|
2070
|
+
function $mol_tree2_from_string(str, uri = '?') {
|
|
2071
|
+
const span = $mol_span.entire(uri, str);
|
|
2072
|
+
var root = $mol_tree2.list([], span);
|
|
2073
|
+
var stack = [root];
|
|
2074
|
+
var pos = 0, row = 0, min_indent = 0;
|
|
2075
|
+
while (str.length > pos) {
|
|
2076
|
+
var indent = 0;
|
|
2077
|
+
var line_start = pos;
|
|
2078
|
+
row++;
|
|
2079
|
+
while (str.length > pos && str[pos] == '\t') {
|
|
2080
|
+
indent++;
|
|
2081
|
+
pos++;
|
|
2082
|
+
}
|
|
2083
|
+
if (!root.kids.length) {
|
|
2084
|
+
min_indent = indent;
|
|
2085
|
+
}
|
|
2086
|
+
indent -= min_indent;
|
|
2087
|
+
if (indent < 0 || indent >= stack.length) {
|
|
2088
|
+
const sp = span.span(row, 1, pos - line_start);
|
|
2089
|
+
while (str.length > pos && str[pos] != '\n') {
|
|
2090
|
+
pos++;
|
|
2091
|
+
}
|
|
2092
|
+
if (indent < 0) {
|
|
2093
|
+
if (str.length > pos) {
|
|
2094
|
+
this.$mol_fail(new this.$mol_error_syntax(`Too few tabs`, str.substring(line_start, pos), sp));
|
|
2095
|
+
}
|
|
2096
|
+
}
|
|
2097
|
+
else {
|
|
2098
|
+
this.$mol_fail(new this.$mol_error_syntax(`Too many tabs`, str.substring(line_start, pos), sp));
|
|
2099
|
+
}
|
|
2100
|
+
}
|
|
2101
|
+
stack.length = indent + 1;
|
|
2102
|
+
var parent = stack[indent];
|
|
2103
|
+
while (str.length > pos && str[pos] != '\\' && str[pos] != '\n') {
|
|
2104
|
+
var error_start = pos;
|
|
2105
|
+
while (str.length > pos && (str[pos] == ' ' || str[pos] == '\t')) {
|
|
2106
|
+
pos++;
|
|
2107
|
+
}
|
|
2108
|
+
if (pos > error_start) {
|
|
2109
|
+
let line_end = str.indexOf('\n', pos);
|
|
2110
|
+
if (line_end === -1)
|
|
2111
|
+
line_end = str.length;
|
|
2112
|
+
const sp = span.span(row, error_start - line_start, pos - error_start + 1);
|
|
2113
|
+
this.$mol_fail(new this.$mol_error_syntax(`Wrong nodes separator`, str.substring(line_start, line_end), sp));
|
|
2114
|
+
}
|
|
2115
|
+
var type_start = pos;
|
|
2116
|
+
while (str.length > pos &&
|
|
2117
|
+
str[pos] != '\\' &&
|
|
2118
|
+
str[pos] != ' ' &&
|
|
2119
|
+
str[pos] != '\t' &&
|
|
2120
|
+
str[pos] != '\n') {
|
|
2121
|
+
pos++;
|
|
2122
|
+
}
|
|
2123
|
+
if (pos > type_start) {
|
|
2124
|
+
let next = new $mol_tree2(str.slice(type_start, pos), '', [], span.span(row, type_start - line_start + 1, pos - type_start));
|
|
2125
|
+
const parent_kids = parent.kids;
|
|
2126
|
+
parent_kids.push(next);
|
|
2127
|
+
parent = next;
|
|
2128
|
+
}
|
|
2129
|
+
if (str.length > pos && str[pos] == ' ') {
|
|
2130
|
+
pos++;
|
|
2131
|
+
}
|
|
2132
|
+
}
|
|
2133
|
+
if (str.length > pos && str[pos] == '\\') {
|
|
2134
|
+
var data_start = pos;
|
|
2135
|
+
while (str.length > pos && str[pos] != '\n') {
|
|
2136
|
+
pos++;
|
|
2137
|
+
}
|
|
2138
|
+
let next = new $mol_tree2('', str.slice(data_start + 1, pos), [], span.span(row, data_start - line_start + 2, pos - data_start - 1));
|
|
2139
|
+
const parent_kids = parent.kids;
|
|
2140
|
+
parent_kids.push(next);
|
|
2141
|
+
parent = next;
|
|
2142
|
+
}
|
|
2143
|
+
if (str.length === pos && stack.length > 0) {
|
|
2144
|
+
const sp = span.span(row, pos - line_start + 1, 1);
|
|
2145
|
+
this.$mol_fail(new this.$mol_error_syntax(`Undexpected EOF, LF required`, str.substring(line_start, str.length), sp));
|
|
2146
|
+
}
|
|
2147
|
+
stack.push(parent);
|
|
2148
|
+
pos++;
|
|
2149
|
+
}
|
|
2150
|
+
return root;
|
|
2151
|
+
}
|
|
2152
|
+
$.$mol_tree2_from_string = $mol_tree2_from_string;
|
|
2153
|
+
})($ || ($ = {}));
|
|
2154
|
+
//mol/tree2/from/string/string.ts
|
|
2155
|
+
;
|
|
2156
|
+
"use strict";
|
|
2157
|
+
var $;
|
|
2158
|
+
(function ($) {
|
|
2159
|
+
function $mol_tree2_from_json(json, span = $mol_span.unknown) {
|
|
2160
|
+
if (typeof json === 'boolean' || typeof json === 'number' || json === null) {
|
|
2161
|
+
return new $mol_tree2(String(json), '', [], span);
|
|
2162
|
+
}
|
|
2163
|
+
if (typeof json === 'string') {
|
|
2164
|
+
return $mol_tree2.data(json, [], span);
|
|
2165
|
+
}
|
|
2166
|
+
if (Array.isArray(json)) {
|
|
2167
|
+
const sub = json.map(json => $mol_tree2_from_json(json, span));
|
|
2168
|
+
return new $mol_tree2('/', '', sub, span);
|
|
2169
|
+
}
|
|
2170
|
+
if (ArrayBuffer.isView(json)) {
|
|
2171
|
+
const buf = new Uint8Array(json.buffer, json.byteOffset, json.byteLength);
|
|
2172
|
+
return $mol_tree2.data(String.fromCharCode(...buf), [], span);
|
|
2173
|
+
}
|
|
2174
|
+
if (json instanceof Date) {
|
|
2175
|
+
return new $mol_tree2('', json.toISOString(), [], span);
|
|
2176
|
+
}
|
|
2177
|
+
if (typeof json.toJSON === 'function') {
|
|
2178
|
+
return $mol_tree2_from_json(json.toJSON());
|
|
2179
|
+
}
|
|
2180
|
+
if (json instanceof Error) {
|
|
2181
|
+
const { name, message, stack } = json;
|
|
2182
|
+
json = { ...json, name, message, stack };
|
|
2183
|
+
}
|
|
2184
|
+
const sub = [];
|
|
2185
|
+
for (var key in json) {
|
|
2186
|
+
const val = json[key];
|
|
2187
|
+
if (val === undefined)
|
|
2188
|
+
continue;
|
|
2189
|
+
const subsub = $mol_tree2_from_json(val, span);
|
|
2190
|
+
if (/^[^\n\t\\ ]+$/.test(key)) {
|
|
2191
|
+
sub.push(new $mol_tree2(key, '', [subsub], span));
|
|
2192
|
+
}
|
|
2193
|
+
else {
|
|
2194
|
+
sub.push($mol_tree2.data(key, [subsub], span));
|
|
2195
|
+
}
|
|
2109
2196
|
}
|
|
2197
|
+
return new $mol_tree2('*', '', sub, span);
|
|
2110
2198
|
}
|
|
2111
|
-
$.$
|
|
2199
|
+
$.$mol_tree2_from_json = $mol_tree2_from_json;
|
|
2112
2200
|
})($ || ($ = {}));
|
|
2113
|
-
//mol/
|
|
2201
|
+
//mol/tree2/from/json/json.ts
|
|
2114
2202
|
;
|
|
2115
2203
|
"use strict";
|
|
2116
2204
|
var $;
|
|
@@ -2165,7 +2253,8 @@ var $;
|
|
|
2165
2253
|
return function $mol_log3_logger(event) {
|
|
2166
2254
|
if (!event.time)
|
|
2167
2255
|
event = { time: new Date().toISOString(), ...event };
|
|
2168
|
-
|
|
2256
|
+
let tree = this.$mol_tree2_from_json(event);
|
|
2257
|
+
tree = tree.struct(type, tree.kids);
|
|
2169
2258
|
let str = color(tree.toString());
|
|
2170
2259
|
this.console[level](str);
|
|
2171
2260
|
const self = this;
|