mol_time_all 1.1.510 → 1.1.512
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.deps.json +1 -1
- package/node.test.js +508 -304
- package/node.test.js.map +1 -1
- package/package.json +1 -1
- package/web.deps.json +1 -1
package/node.test.js
CHANGED
|
@@ -887,7 +887,8 @@ var $;
|
|
|
887
887
|
return function $mol_log3_logger(event) {
|
|
888
888
|
if (!event.time)
|
|
889
889
|
event = { time: new Date().toISOString(), ...event };
|
|
890
|
-
|
|
890
|
+
let tree = this.$mol_tree2_from_json(event);
|
|
891
|
+
tree = tree.struct(type, tree.kids);
|
|
891
892
|
let str = color(tree.toString());
|
|
892
893
|
this.console[level](str);
|
|
893
894
|
const self = this;
|
|
@@ -1835,248 +1836,219 @@ var $;
|
|
|
1835
1836
|
"use strict";
|
|
1836
1837
|
var $;
|
|
1837
1838
|
(function ($) {
|
|
1838
|
-
|
|
1839
|
-
|
|
1840
|
-
|
|
1841
|
-
data;
|
|
1842
|
-
sub;
|
|
1843
|
-
baseUri;
|
|
1839
|
+
class $mol_span extends $mol_object2 {
|
|
1840
|
+
uri;
|
|
1841
|
+
source;
|
|
1844
1842
|
row;
|
|
1845
1843
|
col;
|
|
1846
1844
|
length;
|
|
1847
|
-
constructor(
|
|
1845
|
+
constructor(uri, source, row, col, length) {
|
|
1848
1846
|
super();
|
|
1849
|
-
this.
|
|
1850
|
-
|
|
1851
|
-
|
|
1852
|
-
|
|
1853
|
-
|
|
1854
|
-
|
|
1855
|
-
}
|
|
1856
|
-
else {
|
|
1857
|
-
this.data = sub[0].data;
|
|
1858
|
-
this.sub = config.sub || [];
|
|
1859
|
-
}
|
|
1860
|
-
}
|
|
1861
|
-
else {
|
|
1862
|
-
this.data = config.data || '';
|
|
1863
|
-
this.sub = config.sub || [];
|
|
1864
|
-
}
|
|
1865
|
-
this.baseUri = config.baseUri || '';
|
|
1866
|
-
this.row = config.row || 0;
|
|
1867
|
-
this.col = config.col || 0;
|
|
1868
|
-
this.length = config.length || 0;
|
|
1869
|
-
}
|
|
1870
|
-
static values(str, baseUri) {
|
|
1871
|
-
return str.split('\n').map((data, index) => new $mol_tree({
|
|
1872
|
-
data: data,
|
|
1873
|
-
baseUri: baseUri,
|
|
1874
|
-
row: index + 1,
|
|
1875
|
-
length: data.length,
|
|
1876
|
-
}));
|
|
1847
|
+
this.uri = uri;
|
|
1848
|
+
this.source = source;
|
|
1849
|
+
this.row = row;
|
|
1850
|
+
this.col = col;
|
|
1851
|
+
this.length = length;
|
|
1852
|
+
this[Symbol.toStringTag] = `${this.uri}#${this.row}:${this.col}/${this.length}`;
|
|
1877
1853
|
}
|
|
1878
|
-
|
|
1879
|
-
|
|
1880
|
-
|
|
1881
|
-
data: ('data' in config) ? config.data : this.data,
|
|
1882
|
-
sub: ('sub' in config) ? config.sub : this.sub,
|
|
1883
|
-
baseUri: ('baseUri' in config) ? config.baseUri : this.baseUri,
|
|
1884
|
-
row: ('row' in config) ? config.row : this.row,
|
|
1885
|
-
col: ('col' in config) ? config.col : this.col,
|
|
1886
|
-
length: ('length' in config) ? config.length : this.length,
|
|
1887
|
-
value: config.value
|
|
1888
|
-
});
|
|
1854
|
+
static unknown = $mol_span.begin('?');
|
|
1855
|
+
static begin(uri, source = '') {
|
|
1856
|
+
return new $mol_span(uri, source, 1, 1, 0);
|
|
1889
1857
|
}
|
|
1890
|
-
|
|
1891
|
-
return new $
|
|
1892
|
-
|
|
1858
|
+
static end(uri, source) {
|
|
1859
|
+
return new $mol_span(uri, source, 1, source.length + 1, length);
|
|
1860
|
+
}
|
|
1861
|
+
static entire(uri, source) {
|
|
1862
|
+
return new $mol_span(uri, source, 1, 1, source.length);
|
|
1863
|
+
}
|
|
1864
|
+
toString() {
|
|
1865
|
+
return this[Symbol.toStringTag];
|
|
1866
|
+
}
|
|
1867
|
+
toJSON() {
|
|
1868
|
+
return {
|
|
1869
|
+
uri: this.uri,
|
|
1893
1870
|
row: this.row,
|
|
1894
1871
|
col: this.col,
|
|
1895
|
-
length: this.length
|
|
1896
|
-
|
|
1897
|
-
});
|
|
1872
|
+
length: this.length
|
|
1873
|
+
};
|
|
1898
1874
|
}
|
|
1899
|
-
|
|
1900
|
-
return
|
|
1901
|
-
}
|
|
1902
|
-
|
|
1903
|
-
return this.
|
|
1904
|
-
}
|
|
1905
|
-
|
|
1906
|
-
|
|
1907
|
-
|
|
1908
|
-
|
|
1909
|
-
|
|
1910
|
-
|
|
1911
|
-
|
|
1912
|
-
|
|
1913
|
-
|
|
1914
|
-
|
|
1915
|
-
|
|
1916
|
-
|
|
1917
|
-
|
|
1918
|
-
|
|
1919
|
-
|
|
1920
|
-
|
|
1921
|
-
if (stack.length <= deep)
|
|
1922
|
-
return this.$.$mol_fail(new Error(`Too many tabs at ${baseUri}:${row}\n${line}`));
|
|
1923
|
-
stack.length = deep + 1;
|
|
1924
|
-
var parent = stack[deep];
|
|
1925
|
-
let col = deep;
|
|
1926
|
-
types.forEach(type => {
|
|
1927
|
-
if (!type)
|
|
1928
|
-
return this.$.$mol_fail(new Error(`Unexpected space symbol ${baseUri}:${row}\n${line}`));
|
|
1929
|
-
var next = new $mol_tree({ type, baseUri, row, col, length: type.length });
|
|
1930
|
-
const parent_sub = parent.sub;
|
|
1931
|
-
parent_sub.push(next);
|
|
1932
|
-
parent = next;
|
|
1933
|
-
col += type.length + 1;
|
|
1934
|
-
});
|
|
1935
|
-
if (data) {
|
|
1936
|
-
var next = new $mol_tree({ data: data.substring(1), baseUri, row, col, length: data.length });
|
|
1937
|
-
const parent_sub = parent.sub;
|
|
1938
|
-
parent_sub.push(next);
|
|
1939
|
-
parent = next;
|
|
1940
|
-
}
|
|
1941
|
-
stack.push(parent);
|
|
1942
|
-
});
|
|
1943
|
-
return root;
|
|
1944
|
-
}
|
|
1945
|
-
static fromJSON(json, baseUri = '') {
|
|
1946
|
-
switch (true) {
|
|
1947
|
-
case typeof json === 'boolean':
|
|
1948
|
-
case typeof json === 'number':
|
|
1949
|
-
case json === null:
|
|
1950
|
-
return new $mol_tree({
|
|
1951
|
-
type: String(json),
|
|
1952
|
-
baseUri: baseUri
|
|
1953
|
-
});
|
|
1954
|
-
case typeof json === 'string':
|
|
1955
|
-
return new $mol_tree({
|
|
1956
|
-
value: json,
|
|
1957
|
-
baseUri: baseUri
|
|
1958
|
-
});
|
|
1959
|
-
case Array.isArray(json):
|
|
1960
|
-
return new $mol_tree({
|
|
1961
|
-
type: "/",
|
|
1962
|
-
sub: json.map(json => $mol_tree.fromJSON(json, baseUri))
|
|
1963
|
-
});
|
|
1964
|
-
case json instanceof Date:
|
|
1965
|
-
return new $mol_tree({
|
|
1966
|
-
value: json.toISOString(),
|
|
1967
|
-
baseUri: baseUri
|
|
1968
|
-
});
|
|
1969
|
-
default:
|
|
1970
|
-
if (typeof json[$.$mol_tree_convert] === 'function') {
|
|
1971
|
-
return json[$.$mol_tree_convert]();
|
|
1972
|
-
}
|
|
1973
|
-
if (typeof json.toJSON === 'function') {
|
|
1974
|
-
return $mol_tree.fromJSON(json.toJSON());
|
|
1975
|
-
}
|
|
1976
|
-
if (json instanceof Error) {
|
|
1977
|
-
const { name, message, stack } = json;
|
|
1978
|
-
json = { ...json, name, message, stack };
|
|
1979
|
-
}
|
|
1980
|
-
var sub = [];
|
|
1981
|
-
for (var key in json) {
|
|
1982
|
-
if (json[key] === undefined)
|
|
1983
|
-
continue;
|
|
1984
|
-
const subsub = $mol_tree.fromJSON(json[key], baseUri);
|
|
1985
|
-
if (/^[^\n\t\\ ]+$/.test(key)) {
|
|
1986
|
-
var child = new $mol_tree({
|
|
1987
|
-
type: key,
|
|
1988
|
-
baseUri: baseUri,
|
|
1989
|
-
sub: [subsub],
|
|
1990
|
-
});
|
|
1991
|
-
}
|
|
1992
|
-
else {
|
|
1993
|
-
var child = new $mol_tree({
|
|
1994
|
-
value: key,
|
|
1995
|
-
baseUri: baseUri,
|
|
1996
|
-
sub: [subsub],
|
|
1997
|
-
});
|
|
1998
|
-
}
|
|
1999
|
-
sub.push(child);
|
|
2000
|
-
}
|
|
2001
|
-
return new $mol_tree({
|
|
2002
|
-
type: "*",
|
|
2003
|
-
sub: sub,
|
|
2004
|
-
baseUri: baseUri
|
|
2005
|
-
});
|
|
2006
|
-
}
|
|
1875
|
+
error(message, Class = Error) {
|
|
1876
|
+
return new Class(`${message}${this}`);
|
|
1877
|
+
}
|
|
1878
|
+
span(row, col, length) {
|
|
1879
|
+
return new $mol_span(this.uri, this.source, row, col, length);
|
|
1880
|
+
}
|
|
1881
|
+
after(length = 0) {
|
|
1882
|
+
return new $mol_span(this.uri, this.source, this.row, this.col + this.length, length);
|
|
1883
|
+
}
|
|
1884
|
+
slice(begin, end = -1) {
|
|
1885
|
+
let len = this.length;
|
|
1886
|
+
if (begin < 0)
|
|
1887
|
+
begin += len;
|
|
1888
|
+
if (end < 0)
|
|
1889
|
+
end += len;
|
|
1890
|
+
if (begin < 0 || begin > len)
|
|
1891
|
+
this.$.$mol_fail(`Begin value '${begin}' out of range ${this}`);
|
|
1892
|
+
if (end < 0 || end > len)
|
|
1893
|
+
this.$.$mol_fail(`End value '${end}' out of range ${this}`);
|
|
1894
|
+
if (end < begin)
|
|
1895
|
+
this.$.$mol_fail(`End value '${end}' can't be less than begin value ${this}`);
|
|
1896
|
+
return this.span(this.row, this.col + begin, end - begin);
|
|
2007
1897
|
}
|
|
2008
|
-
|
|
2009
|
-
|
|
1898
|
+
}
|
|
1899
|
+
$.$mol_span = $mol_span;
|
|
1900
|
+
})($ || ($ = {}));
|
|
1901
|
+
//mol/span/span.ts
|
|
1902
|
+
;
|
|
1903
|
+
"use strict";
|
|
1904
|
+
var $;
|
|
1905
|
+
(function ($_1) {
|
|
1906
|
+
$mol_test({
|
|
1907
|
+
'span for same uri'($) {
|
|
1908
|
+
const span = new $mol_span('test.ts', '', 1, 3, 4);
|
|
1909
|
+
const child = span.span(4, 5, 8);
|
|
1910
|
+
$mol_assert_equal(child.uri, 'test.ts');
|
|
1911
|
+
$mol_assert_equal(child.row, 4);
|
|
1912
|
+
$mol_assert_equal(child.col, 5);
|
|
1913
|
+
$mol_assert_equal(child.length, 8);
|
|
1914
|
+
},
|
|
1915
|
+
'span after of given position'($) {
|
|
1916
|
+
const span = new $mol_span('test.ts', '', 1, 3, 4);
|
|
1917
|
+
const child = span.after(11);
|
|
1918
|
+
$mol_assert_equal(child.uri, 'test.ts');
|
|
1919
|
+
$mol_assert_equal(child.row, 1);
|
|
1920
|
+
$mol_assert_equal(child.col, 7);
|
|
1921
|
+
$mol_assert_equal(child.length, 11);
|
|
1922
|
+
},
|
|
1923
|
+
'slice span - regular'($) {
|
|
1924
|
+
const span = new $mol_span('test.ts', '', 1, 3, 5);
|
|
1925
|
+
const child = span.slice(1, 4);
|
|
1926
|
+
$mol_assert_equal(child.row, 1);
|
|
1927
|
+
$mol_assert_equal(child.col, 4);
|
|
1928
|
+
$mol_assert_equal(child.length, 3);
|
|
1929
|
+
const child2 = span.slice(2, 2);
|
|
1930
|
+
$mol_assert_equal(child2.col, 5);
|
|
1931
|
+
$mol_assert_equal(child2.length, 0);
|
|
1932
|
+
},
|
|
1933
|
+
'slice span - negative'($) {
|
|
1934
|
+
const span = new $mol_span('test.ts', '', 1, 3, 5);
|
|
1935
|
+
const child = span.slice(-3, -1);
|
|
1936
|
+
$mol_assert_equal(child.row, 1);
|
|
1937
|
+
$mol_assert_equal(child.col, 5);
|
|
1938
|
+
$mol_assert_equal(child.length, 2);
|
|
1939
|
+
},
|
|
1940
|
+
'slice span - out of range'($) {
|
|
1941
|
+
const span = new $mol_span('test.ts', '', 1, 3, 5);
|
|
1942
|
+
$mol_assert_fail(() => span.slice(-1, 3));
|
|
1943
|
+
$mol_assert_fail(() => span.slice(1, 6));
|
|
1944
|
+
$mol_assert_fail(() => span.slice(1, 10));
|
|
1945
|
+
},
|
|
1946
|
+
'error handling'($) {
|
|
1947
|
+
const span = new $mol_span('test.ts', '', 1, 3, 4);
|
|
1948
|
+
const error = span.error('Some error\n');
|
|
1949
|
+
$mol_assert_equal(error.message, 'Some error\ntest.ts#1:3/4');
|
|
2010
1950
|
}
|
|
2011
|
-
|
|
2012
|
-
|
|
2013
|
-
|
|
1951
|
+
});
|
|
1952
|
+
})($ || ($ = {}));
|
|
1953
|
+
//mol/span/span.test.ts
|
|
1954
|
+
;
|
|
1955
|
+
"use strict";
|
|
1956
|
+
var $;
|
|
1957
|
+
(function ($) {
|
|
1958
|
+
function $mol_tree2_to_string(tree) {
|
|
1959
|
+
let output = [];
|
|
1960
|
+
function dump(tree, prefix = '') {
|
|
1961
|
+
if (tree.type.length) {
|
|
2014
1962
|
if (!prefix.length) {
|
|
2015
1963
|
prefix = "\t";
|
|
2016
1964
|
}
|
|
2017
|
-
output
|
|
2018
|
-
if (
|
|
2019
|
-
|
|
1965
|
+
output.push(tree.type);
|
|
1966
|
+
if (tree.kids.length == 1) {
|
|
1967
|
+
output.push(' ');
|
|
1968
|
+
dump(tree.kids[0], prefix);
|
|
1969
|
+
return;
|
|
2020
1970
|
}
|
|
2021
|
-
output
|
|
1971
|
+
output.push("\n");
|
|
2022
1972
|
}
|
|
2023
|
-
else if (
|
|
2024
|
-
output
|
|
1973
|
+
else if (tree.value.length || prefix.length) {
|
|
1974
|
+
output.push("\\" + tree.value + "\n");
|
|
2025
1975
|
}
|
|
2026
|
-
for (
|
|
2027
|
-
output
|
|
2028
|
-
|
|
1976
|
+
for (const kid of tree.kids) {
|
|
1977
|
+
output.push(prefix);
|
|
1978
|
+
dump(kid, prefix + "\t");
|
|
2029
1979
|
}
|
|
2030
|
-
return output;
|
|
2031
1980
|
}
|
|
2032
|
-
|
|
2033
|
-
|
|
2034
|
-
|
|
2035
|
-
|
|
2036
|
-
|
|
2037
|
-
|
|
2038
|
-
|
|
2039
|
-
|
|
2040
|
-
|
|
2041
|
-
|
|
2042
|
-
|
|
2043
|
-
|
|
2044
|
-
|
|
2045
|
-
|
|
2046
|
-
|
|
2047
|
-
|
|
2048
|
-
|
|
2049
|
-
|
|
2050
|
-
|
|
2051
|
-
|
|
2052
|
-
|
|
2053
|
-
|
|
2054
|
-
|
|
2055
|
-
|
|
2056
|
-
|
|
2057
|
-
|
|
2058
|
-
|
|
2059
|
-
|
|
2060
|
-
|
|
1981
|
+
dump(tree);
|
|
1982
|
+
return output.join('');
|
|
1983
|
+
}
|
|
1984
|
+
$.$mol_tree2_to_string = $mol_tree2_to_string;
|
|
1985
|
+
})($ || ($ = {}));
|
|
1986
|
+
//mol/tree2/to/string/string.ts
|
|
1987
|
+
;
|
|
1988
|
+
"use strict";
|
|
1989
|
+
var $;
|
|
1990
|
+
(function ($) {
|
|
1991
|
+
class $mol_tree2 extends Object {
|
|
1992
|
+
type;
|
|
1993
|
+
value;
|
|
1994
|
+
kids;
|
|
1995
|
+
span;
|
|
1996
|
+
constructor(type, value, kids, span) {
|
|
1997
|
+
super();
|
|
1998
|
+
this.type = type;
|
|
1999
|
+
this.value = value;
|
|
2000
|
+
this.kids = kids;
|
|
2001
|
+
this.span = span;
|
|
2002
|
+
this[Symbol.toStringTag] = type || '\\' + value;
|
|
2003
|
+
}
|
|
2004
|
+
static list(kids, span = $mol_span.unknown) {
|
|
2005
|
+
return new $mol_tree2('', '', kids, span);
|
|
2006
|
+
}
|
|
2007
|
+
list(kids) {
|
|
2008
|
+
return $mol_tree2.list(kids, this.span);
|
|
2009
|
+
}
|
|
2010
|
+
static data(value, kids = [], span = $mol_span.unknown) {
|
|
2011
|
+
const chunks = value.split('\n');
|
|
2012
|
+
if (chunks.length > 1) {
|
|
2013
|
+
let kid_span = span.span(span.row, span.col, 0);
|
|
2014
|
+
const data = chunks.map(chunk => {
|
|
2015
|
+
kid_span = kid_span.after(chunk.length);
|
|
2016
|
+
return new $mol_tree2('', chunk, [], kid_span);
|
|
2061
2017
|
});
|
|
2062
|
-
|
|
2018
|
+
kids = [...data, ...kids];
|
|
2019
|
+
value = '';
|
|
2063
2020
|
}
|
|
2064
|
-
|
|
2065
|
-
|
|
2021
|
+
return new $mol_tree2('', value, kids, span);
|
|
2022
|
+
}
|
|
2023
|
+
data(value, kids = []) {
|
|
2024
|
+
return $mol_tree2.data(value, kids, this.span);
|
|
2025
|
+
}
|
|
2026
|
+
static struct(type, kids = [], span = $mol_span.unknown) {
|
|
2027
|
+
if (/[ \n\t\\]/.test(type)) {
|
|
2028
|
+
$$.$mol_fail(span.error(`Wrong type ${JSON.stringify(type)}`));
|
|
2066
2029
|
}
|
|
2067
|
-
|
|
2068
|
-
|
|
2069
|
-
|
|
2070
|
-
|
|
2030
|
+
return new $mol_tree2(type, '', kids, span);
|
|
2031
|
+
}
|
|
2032
|
+
struct(type, kids = []) {
|
|
2033
|
+
return $mol_tree2.struct(type, kids, this.span);
|
|
2071
2034
|
}
|
|
2072
|
-
|
|
2035
|
+
clone(kids, span = this.span) {
|
|
2036
|
+
return new $mol_tree2(this.type, this.value, kids, span);
|
|
2037
|
+
}
|
|
2038
|
+
text() {
|
|
2073
2039
|
var values = [];
|
|
2074
|
-
for (var
|
|
2075
|
-
if (
|
|
2040
|
+
for (var kid of this.kids) {
|
|
2041
|
+
if (kid.type)
|
|
2076
2042
|
continue;
|
|
2077
|
-
values.push(
|
|
2043
|
+
values.push(kid.value);
|
|
2078
2044
|
}
|
|
2079
|
-
return this.
|
|
2045
|
+
return this.value + values.join('\n');
|
|
2046
|
+
}
|
|
2047
|
+
static fromString(str, uri = 'unknown') {
|
|
2048
|
+
return $$.$mol_tree2_from_string(str, uri);
|
|
2049
|
+
}
|
|
2050
|
+
toString() {
|
|
2051
|
+
return $$.$mol_tree2_to_string(this);
|
|
2080
2052
|
}
|
|
2081
2053
|
insert(value, ...path) {
|
|
2082
2054
|
if (path.length === 0)
|
|
@@ -2084,143 +2056,375 @@ var $;
|
|
|
2084
2056
|
const type = path[0];
|
|
2085
2057
|
if (typeof type === 'string') {
|
|
2086
2058
|
let replaced = false;
|
|
2087
|
-
const sub = this.
|
|
2059
|
+
const sub = this.kids.map((item, index) => {
|
|
2088
2060
|
if (item.type !== type)
|
|
2089
2061
|
return item;
|
|
2090
2062
|
replaced = true;
|
|
2091
2063
|
return item.insert(value, ...path.slice(1));
|
|
2092
|
-
});
|
|
2093
|
-
if (!replaced)
|
|
2094
|
-
sub.push(
|
|
2095
|
-
|
|
2064
|
+
}).filter(Boolean);
|
|
2065
|
+
if (!replaced && value) {
|
|
2066
|
+
sub.push(this.struct(type, []).insert(value, ...path.slice(1)));
|
|
2067
|
+
}
|
|
2068
|
+
return this.clone(sub);
|
|
2096
2069
|
}
|
|
2097
2070
|
else if (typeof type === 'number') {
|
|
2098
|
-
const sub = this.
|
|
2099
|
-
sub[type] = (sub[type] ||
|
|
2100
|
-
|
|
2071
|
+
const sub = this.kids.slice();
|
|
2072
|
+
sub[type] = (sub[type] || this.list([]))
|
|
2073
|
+
.insert(value, ...path.slice(1));
|
|
2074
|
+
return this.clone(sub.filter(Boolean));
|
|
2101
2075
|
}
|
|
2102
2076
|
else {
|
|
2103
|
-
|
|
2077
|
+
const kids = ((this.kids.length === 0) ? [this.list([])] : this.kids)
|
|
2078
|
+
.map(item => item.insert(value, ...path.slice(1)))
|
|
2079
|
+
.filter(Boolean);
|
|
2080
|
+
return this.clone(kids);
|
|
2104
2081
|
}
|
|
2105
2082
|
}
|
|
2106
2083
|
select(...path) {
|
|
2107
|
-
|
|
2108
|
-
for (
|
|
2084
|
+
let next = [this];
|
|
2085
|
+
for (const type of path) {
|
|
2109
2086
|
if (!next.length)
|
|
2110
2087
|
break;
|
|
2111
|
-
|
|
2088
|
+
const prev = next;
|
|
2112
2089
|
next = [];
|
|
2113
2090
|
for (var item of prev) {
|
|
2114
2091
|
switch (typeof (type)) {
|
|
2115
2092
|
case 'string':
|
|
2116
|
-
for (var child of item.
|
|
2117
|
-
if (
|
|
2093
|
+
for (var child of item.kids) {
|
|
2094
|
+
if (child.type == type) {
|
|
2118
2095
|
next.push(child);
|
|
2119
2096
|
}
|
|
2120
2097
|
}
|
|
2121
2098
|
break;
|
|
2122
2099
|
case 'number':
|
|
2123
|
-
if (type < item.
|
|
2124
|
-
next.push(item.
|
|
2100
|
+
if (type < item.kids.length)
|
|
2101
|
+
next.push(item.kids[type]);
|
|
2125
2102
|
break;
|
|
2126
|
-
default: next.push(...item.
|
|
2103
|
+
default: next.push(...item.kids);
|
|
2127
2104
|
}
|
|
2128
2105
|
}
|
|
2129
2106
|
}
|
|
2130
|
-
return
|
|
2107
|
+
return this.list(next);
|
|
2131
2108
|
}
|
|
2132
2109
|
filter(path, value) {
|
|
2133
|
-
|
|
2110
|
+
const sub = this.kids.filter(item => {
|
|
2134
2111
|
var found = item.select(...path);
|
|
2135
|
-
if (value
|
|
2136
|
-
return Boolean(found.
|
|
2112
|
+
if (value === undefined) {
|
|
2113
|
+
return Boolean(found.kids.length);
|
|
2137
2114
|
}
|
|
2138
2115
|
else {
|
|
2139
|
-
return found.
|
|
2116
|
+
return found.kids.some(child => child.value == value);
|
|
2140
2117
|
}
|
|
2141
2118
|
});
|
|
2142
|
-
return
|
|
2143
|
-
}
|
|
2144
|
-
|
|
2145
|
-
|
|
2146
|
-
|
|
2147
|
-
|
|
2148
|
-
|
|
2149
|
-
|
|
2150
|
-
|
|
2151
|
-
|
|
2152
|
-
|
|
2153
|
-
|
|
2119
|
+
return this.clone(sub);
|
|
2120
|
+
}
|
|
2121
|
+
hack(belt, context = {}) {
|
|
2122
|
+
return [].concat(...this.kids.map(child => {
|
|
2123
|
+
let handle = belt[child.type] || belt[''];
|
|
2124
|
+
if (!handle || handle === Object.prototype[child.type]) {
|
|
2125
|
+
handle = (input, belt, context) => [
|
|
2126
|
+
input.clone(input.hack(belt, context), context.span)
|
|
2127
|
+
];
|
|
2128
|
+
}
|
|
2129
|
+
try {
|
|
2130
|
+
return handle(child, belt, context);
|
|
2131
|
+
}
|
|
2132
|
+
catch (error) {
|
|
2133
|
+
error.message += `\n${child.clone([])}${child.span}`;
|
|
2134
|
+
$mol_fail_hidden(error);
|
|
2135
|
+
}
|
|
2154
2136
|
}));
|
|
2155
|
-
return this.clone({ sub });
|
|
2156
2137
|
}
|
|
2157
|
-
error(message) {
|
|
2158
|
-
return
|
|
2138
|
+
error(message, Class = Error) {
|
|
2139
|
+
return this.span.error(`${message}\n${this.clone([])}`, Class);
|
|
2140
|
+
}
|
|
2141
|
+
}
|
|
2142
|
+
$.$mol_tree2 = $mol_tree2;
|
|
2143
|
+
class $mol_tree2_empty extends $mol_tree2 {
|
|
2144
|
+
constructor() {
|
|
2145
|
+
super('', '', [], $mol_span.unknown);
|
|
2159
2146
|
}
|
|
2160
2147
|
}
|
|
2161
|
-
$.$
|
|
2148
|
+
$.$mol_tree2_empty = $mol_tree2_empty;
|
|
2162
2149
|
})($ || ($ = {}));
|
|
2163
|
-
//mol/
|
|
2150
|
+
//mol/tree2/tree2.ts
|
|
2164
2151
|
;
|
|
2165
2152
|
"use strict";
|
|
2166
2153
|
var $;
|
|
2167
2154
|
(function ($_1) {
|
|
2168
2155
|
$mol_test({
|
|
2169
|
-
'
|
|
2170
|
-
$mol_assert_equal(
|
|
2171
|
-
|
|
2172
|
-
|
|
2173
|
-
$mol_assert_equal(
|
|
2174
|
-
|
|
2175
|
-
|
|
2176
|
-
$mol_assert_equal(
|
|
2177
|
-
|
|
2178
|
-
|
|
2179
|
-
|
|
2180
|
-
|
|
2181
|
-
|
|
2182
|
-
$mol_assert_equal(
|
|
2183
|
-
|
|
2184
|
-
|
|
2185
|
-
$mol_assert_equal(
|
|
2186
|
-
|
|
2187
|
-
|
|
2188
|
-
|
|
2189
|
-
|
|
2190
|
-
$mol_assert_equal(
|
|
2191
|
-
|
|
2192
|
-
|
|
2193
|
-
|
|
2194
|
-
|
|
2195
|
-
|
|
2196
|
-
|
|
2197
|
-
|
|
2198
|
-
|
|
2199
|
-
|
|
2200
|
-
|
|
2201
|
-
'hack'() {
|
|
2202
|
-
const res = $mol_tree.fromString(`foo bar xxx`).hack({
|
|
2203
|
-
'': (tree, context) => [tree.hack(context)],
|
|
2204
|
-
'bar': (tree, context) => [tree.hack(context).clone({ type: '777' })],
|
|
2156
|
+
'inserting'($) {
|
|
2157
|
+
$mol_assert_equal($.$mol_tree2_from_string('a b c d\n')
|
|
2158
|
+
.insert($mol_tree2.struct('x'), 'a', 'b', 'c')
|
|
2159
|
+
.toString(), 'a b x\n');
|
|
2160
|
+
$mol_assert_equal($.$mol_tree2_from_string('a b\n')
|
|
2161
|
+
.insert($mol_tree2.struct('x'), 'a', 'b', 'c', 'd')
|
|
2162
|
+
.toString(), 'a b c x\n');
|
|
2163
|
+
$mol_assert_equal($.$mol_tree2_from_string('a b c d\n')
|
|
2164
|
+
.insert($mol_tree2.struct('x'), 0, 0, 0)
|
|
2165
|
+
.toString(), 'a b x\n');
|
|
2166
|
+
$mol_assert_equal($.$mol_tree2_from_string('a b\n')
|
|
2167
|
+
.insert($mol_tree2.struct('x'), 0, 0, 0, 0)
|
|
2168
|
+
.toString(), 'a b \\\n\tx\n');
|
|
2169
|
+
$mol_assert_equal($.$mol_tree2_from_string('a b c d\n')
|
|
2170
|
+
.insert($mol_tree2.struct('x'), null, null, null)
|
|
2171
|
+
.toString(), 'a b x\n');
|
|
2172
|
+
$mol_assert_equal($.$mol_tree2_from_string('a b\n')
|
|
2173
|
+
.insert($mol_tree2.struct('x'), null, null, null, null)
|
|
2174
|
+
.toString(), 'a b \\\n\tx\n');
|
|
2175
|
+
},
|
|
2176
|
+
'deleting'($) {
|
|
2177
|
+
$mol_assert_equal($.$mol_tree2_from_string('a b c d\n')
|
|
2178
|
+
.insert(null, 'a', 'b', 'c')
|
|
2179
|
+
.toString(), 'a b\n');
|
|
2180
|
+
$mol_assert_equal($.$mol_tree2_from_string('a b c d\n')
|
|
2181
|
+
.insert(null, 0, 0, 0)
|
|
2182
|
+
.toString(), 'a b\n');
|
|
2183
|
+
},
|
|
2184
|
+
'hack'($) {
|
|
2185
|
+
const res = $.$mol_tree2_from_string(`foo bar xxx\n`)
|
|
2186
|
+
.hack({
|
|
2187
|
+
'bar': (input, belt) => [input.struct('777', input.hack(belt))],
|
|
2205
2188
|
});
|
|
2206
|
-
$mol_assert_equal(res.toString(),
|
|
2189
|
+
$mol_assert_equal(res.toString(), 'foo 777 xxx\n');
|
|
2207
2190
|
},
|
|
2208
|
-
|
|
2191
|
+
});
|
|
2192
|
+
})($ || ($ = {}));
|
|
2193
|
+
//mol/tree2/tree2.test.ts
|
|
2194
|
+
;
|
|
2195
|
+
"use strict";
|
|
2196
|
+
var $;
|
|
2197
|
+
(function ($) {
|
|
2198
|
+
class $mol_error_syntax extends SyntaxError {
|
|
2199
|
+
reason;
|
|
2200
|
+
line;
|
|
2201
|
+
span;
|
|
2202
|
+
constructor(reason, line, span) {
|
|
2203
|
+
super(`${reason}\n${span}\n${line.substring(0, span.col - 1).replace(/\S/g, ' ')}${''.padEnd(span.length, '!')}\n${line}`);
|
|
2204
|
+
this.reason = reason;
|
|
2205
|
+
this.line = line;
|
|
2206
|
+
this.span = span;
|
|
2207
|
+
}
|
|
2208
|
+
}
|
|
2209
|
+
$.$mol_error_syntax = $mol_error_syntax;
|
|
2210
|
+
})($ || ($ = {}));
|
|
2211
|
+
//mol/error/syntax/syntax.ts
|
|
2212
|
+
;
|
|
2213
|
+
"use strict";
|
|
2214
|
+
var $;
|
|
2215
|
+
(function ($) {
|
|
2216
|
+
function $mol_tree2_from_string(str, uri = '?') {
|
|
2217
|
+
const span = $mol_span.entire(uri, str);
|
|
2218
|
+
var root = $mol_tree2.list([], span);
|
|
2219
|
+
var stack = [root];
|
|
2220
|
+
var pos = 0, row = 0, min_indent = 0;
|
|
2221
|
+
while (str.length > pos) {
|
|
2222
|
+
var indent = 0;
|
|
2223
|
+
var line_start = pos;
|
|
2224
|
+
row++;
|
|
2225
|
+
while (str.length > pos && str[pos] == '\t') {
|
|
2226
|
+
indent++;
|
|
2227
|
+
pos++;
|
|
2228
|
+
}
|
|
2229
|
+
if (!root.kids.length) {
|
|
2230
|
+
min_indent = indent;
|
|
2231
|
+
}
|
|
2232
|
+
indent -= min_indent;
|
|
2233
|
+
if (indent < 0 || indent >= stack.length) {
|
|
2234
|
+
const sp = span.span(row, 1, pos - line_start);
|
|
2235
|
+
while (str.length > pos && str[pos] != '\n') {
|
|
2236
|
+
pos++;
|
|
2237
|
+
}
|
|
2238
|
+
if (indent < 0) {
|
|
2239
|
+
if (str.length > pos) {
|
|
2240
|
+
this.$mol_fail(new this.$mol_error_syntax(`Too few tabs`, str.substring(line_start, pos), sp));
|
|
2241
|
+
}
|
|
2242
|
+
}
|
|
2243
|
+
else {
|
|
2244
|
+
this.$mol_fail(new this.$mol_error_syntax(`Too many tabs`, str.substring(line_start, pos), sp));
|
|
2245
|
+
}
|
|
2246
|
+
}
|
|
2247
|
+
stack.length = indent + 1;
|
|
2248
|
+
var parent = stack[indent];
|
|
2249
|
+
while (str.length > pos && str[pos] != '\\' && str[pos] != '\n') {
|
|
2250
|
+
var error_start = pos;
|
|
2251
|
+
while (str.length > pos && (str[pos] == ' ' || str[pos] == '\t')) {
|
|
2252
|
+
pos++;
|
|
2253
|
+
}
|
|
2254
|
+
if (pos > error_start) {
|
|
2255
|
+
let line_end = str.indexOf('\n', pos);
|
|
2256
|
+
if (line_end === -1)
|
|
2257
|
+
line_end = str.length;
|
|
2258
|
+
const sp = span.span(row, error_start - line_start, pos - error_start + 1);
|
|
2259
|
+
this.$mol_fail(new this.$mol_error_syntax(`Wrong nodes separator`, str.substring(line_start, line_end), sp));
|
|
2260
|
+
}
|
|
2261
|
+
var type_start = pos;
|
|
2262
|
+
while (str.length > pos &&
|
|
2263
|
+
str[pos] != '\\' &&
|
|
2264
|
+
str[pos] != ' ' &&
|
|
2265
|
+
str[pos] != '\t' &&
|
|
2266
|
+
str[pos] != '\n') {
|
|
2267
|
+
pos++;
|
|
2268
|
+
}
|
|
2269
|
+
if (pos > type_start) {
|
|
2270
|
+
let next = new $mol_tree2(str.slice(type_start, pos), '', [], span.span(row, type_start - line_start + 1, pos - type_start));
|
|
2271
|
+
const parent_kids = parent.kids;
|
|
2272
|
+
parent_kids.push(next);
|
|
2273
|
+
parent = next;
|
|
2274
|
+
}
|
|
2275
|
+
if (str.length > pos && str[pos] == ' ') {
|
|
2276
|
+
pos++;
|
|
2277
|
+
}
|
|
2278
|
+
}
|
|
2279
|
+
if (str.length > pos && str[pos] == '\\') {
|
|
2280
|
+
var data_start = pos;
|
|
2281
|
+
while (str.length > pos && str[pos] != '\n') {
|
|
2282
|
+
pos++;
|
|
2283
|
+
}
|
|
2284
|
+
let next = new $mol_tree2('', str.slice(data_start + 1, pos), [], span.span(row, data_start - line_start + 2, pos - data_start - 1));
|
|
2285
|
+
const parent_kids = parent.kids;
|
|
2286
|
+
parent_kids.push(next);
|
|
2287
|
+
parent = next;
|
|
2288
|
+
}
|
|
2289
|
+
if (str.length === pos && stack.length > 0) {
|
|
2290
|
+
const sp = span.span(row, pos - line_start + 1, 1);
|
|
2291
|
+
this.$mol_fail(new this.$mol_error_syntax(`Undexpected EOF, LF required`, str.substring(line_start, str.length), sp));
|
|
2292
|
+
}
|
|
2293
|
+
stack.push(parent);
|
|
2294
|
+
pos++;
|
|
2295
|
+
}
|
|
2296
|
+
return root;
|
|
2297
|
+
}
|
|
2298
|
+
$.$mol_tree2_from_string = $mol_tree2_from_string;
|
|
2299
|
+
})($ || ($ = {}));
|
|
2300
|
+
//mol/tree2/from/string/string.ts
|
|
2301
|
+
;
|
|
2302
|
+
"use strict";
|
|
2303
|
+
var $;
|
|
2304
|
+
(function ($_1) {
|
|
2305
|
+
$mol_test({
|
|
2306
|
+
'tree parsing'($) {
|
|
2307
|
+
$mol_assert_equal($.$mol_tree2_from_string("foo\nbar\n").kids.length, 2);
|
|
2308
|
+
$mol_assert_equal($.$mol_tree2_from_string("foo\nbar\n").kids[1].type, "bar");
|
|
2309
|
+
$mol_assert_equal($.$mol_tree2_from_string("foo\n\n\n").kids.length, 1);
|
|
2310
|
+
$mol_assert_equal($.$mol_tree2_from_string("=foo\n\\bar\n").kids.length, 2);
|
|
2311
|
+
$mol_assert_equal($.$mol_tree2_from_string("=foo\n\\bar\n").kids[1].value, "bar");
|
|
2312
|
+
$mol_assert_equal($.$mol_tree2_from_string("foo bar \\pol\n").kids[0].kids[0].kids[0].value, "pol");
|
|
2313
|
+
$mol_assert_equal($.$mol_tree2_from_string("foo bar\n\t\\pol\n\t\\men\n").kids[0].kids[0].kids[1].value, "men");
|
|
2314
|
+
$mol_assert_equal($.$mol_tree2_from_string('foo bar \\text\n').toString(), 'foo bar \\text\n');
|
|
2315
|
+
},
|
|
2316
|
+
'Too many tabs'($) {
|
|
2317
|
+
const tree = `
|
|
2318
|
+
foo
|
|
2319
|
+
bar
|
|
2320
|
+
`;
|
|
2321
|
+
$mol_assert_fail(() => {
|
|
2322
|
+
$.$mol_tree2_from_string(tree, 'test');
|
|
2323
|
+
}, 'Too many tabs\ntest#3:1/6\n!!!!!!\n\t\t\t\t\t\tbar');
|
|
2324
|
+
},
|
|
2325
|
+
'Too few tabs'($) {
|
|
2326
|
+
const tree = `
|
|
2327
|
+
foo
|
|
2328
|
+
bar
|
|
2329
|
+
`;
|
|
2330
|
+
$mol_assert_fail(() => {
|
|
2331
|
+
$.$mol_tree2_from_string(tree, 'test');
|
|
2332
|
+
}, 'Too few tabs\ntest#3:1/4\n!!!!\n\t\t\t\tbar');
|
|
2333
|
+
},
|
|
2334
|
+
'Wrong nodes separator'($) {
|
|
2335
|
+
const tree = `foo bar\n`;
|
|
2336
|
+
$mol_assert_fail(() => {
|
|
2337
|
+
$.$mol_tree2_from_string(tree, 'test');
|
|
2338
|
+
}, 'Wrong nodes separator\ntest#1:4/2\n !!\nfoo bar');
|
|
2339
|
+
},
|
|
2340
|
+
'Undexpected EOF, LF required'($) {
|
|
2341
|
+
const tree = ` foo`;
|
|
2342
|
+
$mol_assert_fail(() => {
|
|
2343
|
+
$.$mol_tree2_from_string(tree, 'test');
|
|
2344
|
+
}, 'Undexpected EOF, LF required\ntest#1:5/1\n !\n foo');
|
|
2345
|
+
},
|
|
2346
|
+
'Errors skip and collect'($) {
|
|
2347
|
+
const tree = `foo bar`;
|
|
2209
2348
|
const errors = [];
|
|
2210
|
-
|
|
2211
|
-
|
|
2212
|
-
|
|
2213
|
-
|
|
2349
|
+
const $$ = $.$mol_ambient({
|
|
2350
|
+
$mol_fail: (error) => {
|
|
2351
|
+
errors.push(error.message);
|
|
2352
|
+
return null;
|
|
2353
|
+
}
|
|
2354
|
+
});
|
|
2355
|
+
const res = $$.$mol_tree2_from_string(tree, 'test');
|
|
2356
|
+
$mol_assert_like(errors, [
|
|
2357
|
+
'Wrong nodes separator\ntest#1:4/2\n !!\nfoo bar',
|
|
2358
|
+
'Undexpected EOF, LF required\ntest#1:9/1\n !\nfoo bar',
|
|
2359
|
+
]);
|
|
2360
|
+
$mol_assert_equal(res.toString(), 'foo bar\n');
|
|
2361
|
+
},
|
|
2362
|
+
});
|
|
2363
|
+
})($ || ($ = {}));
|
|
2364
|
+
//mol/tree2/from/string/string.test.ts
|
|
2365
|
+
;
|
|
2366
|
+
"use strict";
|
|
2367
|
+
var $;
|
|
2368
|
+
(function ($) {
|
|
2369
|
+
function $mol_tree2_from_json(json, span = $mol_span.unknown) {
|
|
2370
|
+
if (typeof json === 'boolean' || typeof json === 'number' || json === null) {
|
|
2371
|
+
return new $mol_tree2(String(json), '', [], span);
|
|
2372
|
+
}
|
|
2373
|
+
if (typeof json === 'string') {
|
|
2374
|
+
return $mol_tree2.data(json, [], span);
|
|
2375
|
+
}
|
|
2376
|
+
if (Array.isArray(json)) {
|
|
2377
|
+
const sub = json.map(json => $mol_tree2_from_json(json, span));
|
|
2378
|
+
return new $mol_tree2('/', '', sub, span);
|
|
2379
|
+
}
|
|
2380
|
+
if (ArrayBuffer.isView(json)) {
|
|
2381
|
+
const buf = new Uint8Array(json.buffer, json.byteOffset, json.byteLength);
|
|
2382
|
+
return $mol_tree2.data(String.fromCharCode(...buf), [], span);
|
|
2383
|
+
}
|
|
2384
|
+
if (json instanceof Date) {
|
|
2385
|
+
return new $mol_tree2('', json.toISOString(), [], span);
|
|
2386
|
+
}
|
|
2387
|
+
if (typeof json.toJSON === 'function') {
|
|
2388
|
+
return $mol_tree2_from_json(json.toJSON());
|
|
2389
|
+
}
|
|
2390
|
+
if (json instanceof Error) {
|
|
2391
|
+
const { name, message, stack } = json;
|
|
2392
|
+
json = { ...json, name, message, stack };
|
|
2393
|
+
}
|
|
2394
|
+
const sub = [];
|
|
2395
|
+
for (var key in json) {
|
|
2396
|
+
const val = json[key];
|
|
2397
|
+
if (val === undefined)
|
|
2398
|
+
continue;
|
|
2399
|
+
const subsub = $mol_tree2_from_json(val, span);
|
|
2400
|
+
if (/^[^\n\t\\ ]+$/.test(key)) {
|
|
2401
|
+
sub.push(new $mol_tree2(key, '', [subsub], span));
|
|
2402
|
+
}
|
|
2403
|
+
else {
|
|
2404
|
+
sub.push($mol_tree2.data(key, [subsub], span));
|
|
2214
2405
|
}
|
|
2215
|
-
|
|
2216
|
-
|
|
2217
|
-
|
|
2218
|
-
|
|
2219
|
-
|
|
2406
|
+
}
|
|
2407
|
+
return new $mol_tree2('*', '', sub, span);
|
|
2408
|
+
}
|
|
2409
|
+
$.$mol_tree2_from_json = $mol_tree2_from_json;
|
|
2410
|
+
})($ || ($ = {}));
|
|
2411
|
+
//mol/tree2/from/json/json.ts
|
|
2412
|
+
;
|
|
2413
|
+
"use strict";
|
|
2414
|
+
var $;
|
|
2415
|
+
(function ($) {
|
|
2416
|
+
$mol_test({
|
|
2417
|
+
'fromJSON'() {
|
|
2418
|
+
$mol_assert_equal($mol_tree2_from_json([]).toString(), '/\n');
|
|
2419
|
+
$mol_assert_equal($mol_tree2_from_json([false, true]).toString(), '/\n\tfalse\n\ttrue\n');
|
|
2420
|
+
$mol_assert_equal($mol_tree2_from_json([0, 1, 2.3]).toString(), '/\n\t0\n\t1\n\t2.3\n');
|
|
2421
|
+
$mol_assert_equal($mol_tree2_from_json(new Uint16Array([1, 10, 256])).toString(), '\\\x01\x00\n\\\x00\x00\x01\n');
|
|
2422
|
+
$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');
|
|
2423
|
+
$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');
|
|
2220
2424
|
},
|
|
2221
2425
|
});
|
|
2222
2426
|
})($ || ($ = {}));
|
|
2223
|
-
//mol/
|
|
2427
|
+
//mol/tree2/from/json/json.test.ts
|
|
2224
2428
|
;
|
|
2225
2429
|
"use strict";
|
|
2226
2430
|
var $;
|