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.test.js CHANGED
@@ -1777,248 +1777,167 @@ var $;
1777
1777
  "use strict";
1778
1778
  var $;
1779
1779
  (function ($) {
1780
- $.$mol_tree_convert = Symbol('$mol_tree_convert');
1781
- class $mol_tree extends $mol_object2 {
1782
- type;
1783
- data;
1784
- sub;
1785
- baseUri;
1780
+ class $mol_span extends $mol_object2 {
1781
+ uri;
1782
+ source;
1786
1783
  row;
1787
1784
  col;
1788
1785
  length;
1789
- constructor(config = {}) {
1786
+ constructor(uri, source, row, col, length) {
1790
1787
  super();
1791
- this.type = config.type || '';
1792
- if (config.value !== undefined) {
1793
- var sub = $mol_tree.values(config.value);
1794
- if (config.type || sub.length > 1) {
1795
- this.sub = [...sub, ...(config.sub || [])];
1796
- this.data = config.data || '';
1797
- }
1798
- else {
1799
- this.data = sub[0].data;
1800
- this.sub = config.sub || [];
1801
- }
1802
- }
1803
- else {
1804
- this.data = config.data || '';
1805
- this.sub = config.sub || [];
1806
- }
1807
- this.baseUri = config.baseUri || '';
1808
- this.row = config.row || 0;
1809
- this.col = config.col || 0;
1810
- this.length = config.length || 0;
1811
- }
1812
- static values(str, baseUri) {
1813
- return str.split('\n').map((data, index) => new $mol_tree({
1814
- data: data,
1815
- baseUri: baseUri,
1816
- row: index + 1,
1817
- length: data.length,
1818
- }));
1788
+ this.uri = uri;
1789
+ this.source = source;
1790
+ this.row = row;
1791
+ this.col = col;
1792
+ this.length = length;
1793
+ this[Symbol.toStringTag] = `${this.uri}#${this.row}:${this.col}/${this.length}`;
1819
1794
  }
1820
- clone(config = {}) {
1821
- return new $mol_tree({
1822
- type: ('type' in config) ? config.type : this.type,
1823
- data: ('data' in config) ? config.data : this.data,
1824
- sub: ('sub' in config) ? config.sub : this.sub,
1825
- baseUri: ('baseUri' in config) ? config.baseUri : this.baseUri,
1826
- row: ('row' in config) ? config.row : this.row,
1827
- col: ('col' in config) ? config.col : this.col,
1828
- length: ('length' in config) ? config.length : this.length,
1829
- value: config.value
1830
- });
1795
+ static unknown = $mol_span.begin('?');
1796
+ static begin(uri, source = '') {
1797
+ return new $mol_span(uri, source, 1, 1, 0);
1798
+ }
1799
+ static end(uri, source) {
1800
+ return new $mol_span(uri, source, 1, source.length + 1, length);
1801
+ }
1802
+ static entire(uri, source) {
1803
+ return new $mol_span(uri, source, 1, 1, source.length);
1831
1804
  }
1832
- make(config) {
1833
- return new $mol_tree({
1834
- baseUri: this.baseUri,
1805
+ toString() {
1806
+ return this[Symbol.toStringTag];
1807
+ }
1808
+ toJSON() {
1809
+ return {
1810
+ uri: this.uri,
1835
1811
  row: this.row,
1836
1812
  col: this.col,
1837
- length: this.length,
1838
- ...config,
1839
- });
1840
- }
1841
- make_data(value, sub) {
1842
- return this.make({ value, sub });
1843
- }
1844
- make_struct(type, sub) {
1845
- return this.make({ type, sub });
1846
- }
1847
- static fromString(str, baseUri) {
1848
- var root = new $mol_tree({ baseUri: baseUri });
1849
- var stack = [root];
1850
- var row = 0;
1851
- var prefix = str.replace(/^\n?(\t*)[\s\S]*/, '$1');
1852
- var lines = str.replace(new RegExp('^\\t{0,' + prefix.length + '}', 'mg'), '').split('\n');
1853
- lines.forEach(line => {
1854
- ++row;
1855
- var chunks = /^(\t*)((?:[^\n\t\\ ]+ *)*)(\\[^\n]*)?(.*?)(?:$|\n)/m.exec(line);
1856
- if (!chunks || chunks[4])
1857
- return this.$.$mol_fail(new Error(`Syntax error at ${baseUri}:${row}\n${line}`));
1858
- var indent = chunks[1];
1859
- var path = chunks[2];
1860
- var data = chunks[3];
1861
- var deep = indent.length;
1862
- var types = path ? path.replace(/ $/, '').split(/ +/) : [];
1863
- if (stack.length <= deep)
1864
- return this.$.$mol_fail(new Error(`Too many tabs at ${baseUri}:${row}\n${line}`));
1865
- stack.length = deep + 1;
1866
- var parent = stack[deep];
1867
- let col = deep;
1868
- types.forEach(type => {
1869
- if (!type)
1870
- return this.$.$mol_fail(new Error(`Unexpected space symbol ${baseUri}:${row}\n${line}`));
1871
- var next = new $mol_tree({ type, baseUri, row, col, length: type.length });
1872
- const parent_sub = parent.sub;
1873
- parent_sub.push(next);
1874
- parent = next;
1875
- col += type.length + 1;
1876
- });
1877
- if (data) {
1878
- var next = new $mol_tree({ data: data.substring(1), baseUri, row, col, length: data.length });
1879
- const parent_sub = parent.sub;
1880
- parent_sub.push(next);
1881
- parent = next;
1882
- }
1883
- stack.push(parent);
1884
- });
1885
- return root;
1886
- }
1887
- static fromJSON(json, baseUri = '') {
1888
- switch (true) {
1889
- case typeof json === 'boolean':
1890
- case typeof json === 'number':
1891
- case json === null:
1892
- return new $mol_tree({
1893
- type: String(json),
1894
- baseUri: baseUri
1895
- });
1896
- case typeof json === 'string':
1897
- return new $mol_tree({
1898
- value: json,
1899
- baseUri: baseUri
1900
- });
1901
- case Array.isArray(json):
1902
- return new $mol_tree({
1903
- type: "/",
1904
- sub: json.map(json => $mol_tree.fromJSON(json, baseUri))
1905
- });
1906
- case json instanceof Date:
1907
- return new $mol_tree({
1908
- value: json.toISOString(),
1909
- baseUri: baseUri
1910
- });
1911
- default:
1912
- if (typeof json[$.$mol_tree_convert] === 'function') {
1913
- return json[$.$mol_tree_convert]();
1914
- }
1915
- if (typeof json.toJSON === 'function') {
1916
- return $mol_tree.fromJSON(json.toJSON());
1917
- }
1918
- if (json instanceof Error) {
1919
- const { name, message, stack } = json;
1920
- json = { ...json, name, message, stack };
1921
- }
1922
- var sub = [];
1923
- for (var key in json) {
1924
- if (json[key] === undefined)
1925
- continue;
1926
- const subsub = $mol_tree.fromJSON(json[key], baseUri);
1927
- if (/^[^\n\t\\ ]+$/.test(key)) {
1928
- var child = new $mol_tree({
1929
- type: key,
1930
- baseUri: baseUri,
1931
- sub: [subsub],
1932
- });
1933
- }
1934
- else {
1935
- var child = new $mol_tree({
1936
- value: key,
1937
- baseUri: baseUri,
1938
- sub: [subsub],
1939
- });
1940
- }
1941
- sub.push(child);
1942
- }
1943
- return new $mol_tree({
1944
- type: "*",
1945
- sub: sub,
1946
- baseUri: baseUri
1947
- });
1948
- }
1813
+ length: this.length
1814
+ };
1949
1815
  }
1950
- get uri() {
1951
- return this.baseUri + '#' + this.row + ':' + this.col;
1816
+ error(message, Class = Error) {
1817
+ return new Class(`${message}${this}`);
1818
+ }
1819
+ span(row, col, length) {
1820
+ return new $mol_span(this.uri, this.source, row, col, length);
1821
+ }
1822
+ after(length = 0) {
1823
+ return new $mol_span(this.uri, this.source, this.row, this.col + this.length, length);
1824
+ }
1825
+ slice(begin, end = -1) {
1826
+ let len = this.length;
1827
+ if (begin < 0)
1828
+ begin += len;
1829
+ if (end < 0)
1830
+ end += len;
1831
+ if (begin < 0 || begin > len)
1832
+ this.$.$mol_fail(`Begin value '${begin}' out of range ${this}`);
1833
+ if (end < 0 || end > len)
1834
+ this.$.$mol_fail(`End value '${end}' out of range ${this}`);
1835
+ if (end < begin)
1836
+ this.$.$mol_fail(`End value '${end}' can't be less than begin value ${this}`);
1837
+ return this.span(this.row, this.col + begin, end - begin);
1952
1838
  }
1953
- toString(prefix = '') {
1954
- var output = '';
1955
- if (this.type.length) {
1839
+ }
1840
+ $.$mol_span = $mol_span;
1841
+ })($ || ($ = {}));
1842
+ //mol/span/span.ts
1843
+ ;
1844
+ "use strict";
1845
+ var $;
1846
+ (function ($) {
1847
+ function $mol_tree2_to_string(tree) {
1848
+ let output = [];
1849
+ function dump(tree, prefix = '') {
1850
+ if (tree.type.length) {
1956
1851
  if (!prefix.length) {
1957
1852
  prefix = "\t";
1958
1853
  }
1959
- output += this.type;
1960
- if (this.sub.length == 1) {
1961
- return output + ' ' + this.sub[0].toString(prefix);
1854
+ output.push(tree.type);
1855
+ if (tree.kids.length == 1) {
1856
+ output.push(' ');
1857
+ dump(tree.kids[0], prefix);
1858
+ return;
1962
1859
  }
1963
- output += "\n";
1860
+ output.push("\n");
1964
1861
  }
1965
- else if (this.data.length || prefix.length) {
1966
- output += "\\" + this.data + "\n";
1862
+ else if (tree.value.length || prefix.length) {
1863
+ output.push("\\" + tree.value + "\n");
1967
1864
  }
1968
- for (var child of this.sub) {
1969
- output += prefix;
1970
- output += child.toString(prefix + "\t");
1865
+ for (const kid of tree.kids) {
1866
+ output.push(prefix);
1867
+ dump(kid, prefix + "\t");
1971
1868
  }
1972
- return output;
1973
1869
  }
1974
- toJSON() {
1975
- if (!this.type)
1976
- return this.value;
1977
- if (this.type === 'true')
1978
- return true;
1979
- if (this.type === 'false')
1980
- return false;
1981
- if (this.type === 'null')
1982
- return null;
1983
- if (this.type === '*') {
1984
- var obj = {};
1985
- for (var child of this.sub) {
1986
- if (child.type === '-')
1987
- continue;
1988
- var key = child.type || child.clone({ sub: child.sub.slice(0, child.sub.length - 1) }).value;
1989
- var val = child.sub[child.sub.length - 1].toJSON();
1990
- if (val !== undefined)
1991
- obj[key] = val;
1992
- }
1993
- return obj;
1994
- }
1995
- if (this.type === '/') {
1996
- var res = [];
1997
- this.sub.forEach(child => {
1998
- if (child.type === '-')
1999
- return;
2000
- var val = child.toJSON();
2001
- if (val !== undefined)
2002
- res.push(val);
1870
+ dump(tree);
1871
+ return output.join('');
1872
+ }
1873
+ $.$mol_tree2_to_string = $mol_tree2_to_string;
1874
+ })($ || ($ = {}));
1875
+ //mol/tree2/to/string/string.ts
1876
+ ;
1877
+ "use strict";
1878
+ var $;
1879
+ (function ($) {
1880
+ class $mol_tree2 extends Object {
1881
+ type;
1882
+ value;
1883
+ kids;
1884
+ span;
1885
+ constructor(type, value, kids, span) {
1886
+ super();
1887
+ this.type = type;
1888
+ this.value = value;
1889
+ this.kids = kids;
1890
+ this.span = span;
1891
+ this[Symbol.toStringTag] = type || '\\' + value;
1892
+ }
1893
+ static list(kids, span = $mol_span.unknown) {
1894
+ return new $mol_tree2('', '', kids, span);
1895
+ }
1896
+ list(kids) {
1897
+ return $mol_tree2.list(kids, this.span);
1898
+ }
1899
+ static data(value, kids = [], span = $mol_span.unknown) {
1900
+ const chunks = value.split('\n');
1901
+ if (chunks.length > 1) {
1902
+ let kid_span = span.span(span.row, span.col, 0);
1903
+ const data = chunks.map(chunk => {
1904
+ kid_span = kid_span.after(chunk.length);
1905
+ return new $mol_tree2('', chunk, [], kid_span);
2003
1906
  });
2004
- return res;
1907
+ kids = [...data, ...kids];
1908
+ value = '';
2005
1909
  }
2006
- if (this.type === 'time') {
2007
- return new Date(this.value);
1910
+ return new $mol_tree2('', value, kids, span);
1911
+ }
1912
+ data(value, kids = []) {
1913
+ return $mol_tree2.data(value, kids, this.span);
1914
+ }
1915
+ static struct(type, kids = [], span = $mol_span.unknown) {
1916
+ if (/[ \n\t\\]/.test(type)) {
1917
+ $$.$mol_fail(span.error(`Wrong type ${JSON.stringify(type)}`));
2008
1918
  }
2009
- const numb = Number(this.type);
2010
- if (!Number.isNaN(numb) || this.type === 'NaN')
2011
- return numb;
2012
- throw new Error(`Unknown type (${this.type}) at ${this.uri}`);
1919
+ return new $mol_tree2(type, '', kids, span);
1920
+ }
1921
+ struct(type, kids = []) {
1922
+ return $mol_tree2.struct(type, kids, this.span);
1923
+ }
1924
+ clone(kids, span = this.span) {
1925
+ return new $mol_tree2(this.type, this.value, kids, span);
2013
1926
  }
2014
- get value() {
1927
+ text() {
2015
1928
  var values = [];
2016
- for (var child of this.sub) {
2017
- if (child.type)
1929
+ for (var kid of this.kids) {
1930
+ if (kid.type)
2018
1931
  continue;
2019
- values.push(child.value);
1932
+ values.push(kid.value);
2020
1933
  }
2021
- return this.data + values.join("\n");
1934
+ return this.value + values.join('\n');
1935
+ }
1936
+ static fromString(str, uri = 'unknown') {
1937
+ return $$.$mol_tree2_from_string(str, uri);
1938
+ }
1939
+ toString() {
1940
+ return $$.$mol_tree2_to_string(this);
2022
1941
  }
2023
1942
  insert(value, ...path) {
2024
1943
  if (path.length === 0)
@@ -2026,83 +1945,252 @@ var $;
2026
1945
  const type = path[0];
2027
1946
  if (typeof type === 'string') {
2028
1947
  let replaced = false;
2029
- const sub = this.sub.map((item, index) => {
1948
+ const sub = this.kids.map((item, index) => {
2030
1949
  if (item.type !== type)
2031
1950
  return item;
2032
1951
  replaced = true;
2033
1952
  return item.insert(value, ...path.slice(1));
2034
- });
2035
- if (!replaced)
2036
- sub.push(new $mol_tree({ type }).insert(value, ...path.slice(1)));
2037
- return this.clone({ sub });
1953
+ }).filter(Boolean);
1954
+ if (!replaced && value) {
1955
+ sub.push(this.struct(type, []).insert(value, ...path.slice(1)));
1956
+ }
1957
+ return this.clone(sub);
2038
1958
  }
2039
1959
  else if (typeof type === 'number') {
2040
- const sub = this.sub.slice();
2041
- sub[type] = (sub[type] || new $mol_tree).insert(value, ...path.slice(1));
2042
- return this.clone({ sub });
1960
+ const sub = this.kids.slice();
1961
+ sub[type] = (sub[type] || this.list([]))
1962
+ .insert(value, ...path.slice(1));
1963
+ return this.clone(sub.filter(Boolean));
2043
1964
  }
2044
1965
  else {
2045
- return this.clone({ sub: ((this.sub.length === 0) ? [new $mol_tree()] : this.sub).map(item => item.insert(value, ...path.slice(1))) });
1966
+ const kids = ((this.kids.length === 0) ? [this.list([])] : this.kids)
1967
+ .map(item => item.insert(value, ...path.slice(1)))
1968
+ .filter(Boolean);
1969
+ return this.clone(kids);
2046
1970
  }
2047
1971
  }
2048
1972
  select(...path) {
2049
- var next = [this];
2050
- for (var type of path) {
1973
+ let next = [this];
1974
+ for (const type of path) {
2051
1975
  if (!next.length)
2052
1976
  break;
2053
- var prev = next;
1977
+ const prev = next;
2054
1978
  next = [];
2055
1979
  for (var item of prev) {
2056
1980
  switch (typeof (type)) {
2057
1981
  case 'string':
2058
- for (var child of item.sub) {
2059
- if (!type || (child.type == type)) {
1982
+ for (var child of item.kids) {
1983
+ if (child.type == type) {
2060
1984
  next.push(child);
2061
1985
  }
2062
1986
  }
2063
1987
  break;
2064
1988
  case 'number':
2065
- if (type < item.sub.length)
2066
- next.push(item.sub[type]);
1989
+ if (type < item.kids.length)
1990
+ next.push(item.kids[type]);
2067
1991
  break;
2068
- default: next.push(...item.sub);
1992
+ default: next.push(...item.kids);
2069
1993
  }
2070
1994
  }
2071
1995
  }
2072
- return new $mol_tree({ sub: next });
1996
+ return this.list(next);
2073
1997
  }
2074
1998
  filter(path, value) {
2075
- var sub = this.sub.filter(function (item) {
1999
+ const sub = this.kids.filter(item => {
2076
2000
  var found = item.select(...path);
2077
- if (value == null) {
2078
- return Boolean(found.sub.length);
2001
+ if (value === undefined) {
2002
+ return Boolean(found.kids.length);
2079
2003
  }
2080
2004
  else {
2081
- return found.sub.some(child => child.value == value);
2005
+ return found.kids.some(child => child.value == value);
2082
2006
  }
2083
2007
  });
2084
- return new $mol_tree({ sub: sub });
2085
- }
2086
- transform(visit, stack = []) {
2087
- const sub_stack = [this, ...stack];
2088
- return visit(sub_stack, () => this.sub.map(node => node.transform(visit, sub_stack)).filter(n => n));
2089
- }
2090
- hack(context) {
2091
- const sub = [].concat(...this.sub.map(child => {
2092
- const handle = context[child.type] || context[''];
2093
- if (!handle)
2094
- $mol_fail(child.error('Handler not defined'));
2095
- return handle(child, context);
2008
+ return this.clone(sub);
2009
+ }
2010
+ hack(belt, context = {}) {
2011
+ return [].concat(...this.kids.map(child => {
2012
+ let handle = belt[child.type] || belt[''];
2013
+ if (!handle || handle === Object.prototype[child.type]) {
2014
+ handle = (input, belt, context) => [
2015
+ input.clone(input.hack(belt, context), context.span)
2016
+ ];
2017
+ }
2018
+ try {
2019
+ return handle(child, belt, context);
2020
+ }
2021
+ catch (error) {
2022
+ error.message += `\n${child.clone([])}${child.span}`;
2023
+ $mol_fail_hidden(error);
2024
+ }
2096
2025
  }));
2097
- return this.clone({ sub });
2098
2026
  }
2099
- error(message) {
2100
- return new Error(`${message}:\n${this} ${this.baseUri}:${this.row}:${this.col}`);
2027
+ error(message, Class = Error) {
2028
+ return this.span.error(`${message}\n${this.clone([])}`, Class);
2029
+ }
2030
+ }
2031
+ $.$mol_tree2 = $mol_tree2;
2032
+ class $mol_tree2_empty extends $mol_tree2 {
2033
+ constructor() {
2034
+ super('', '', [], $mol_span.unknown);
2035
+ }
2036
+ }
2037
+ $.$mol_tree2_empty = $mol_tree2_empty;
2038
+ })($ || ($ = {}));
2039
+ //mol/tree2/tree2.ts
2040
+ ;
2041
+ "use strict";
2042
+ var $;
2043
+ (function ($) {
2044
+ class $mol_error_syntax extends SyntaxError {
2045
+ reason;
2046
+ line;
2047
+ span;
2048
+ constructor(reason, line, span) {
2049
+ super(`${reason}\n${span}\n${line.substring(0, span.col - 1).replace(/\S/g, ' ')}${''.padEnd(span.length, '!')}\n${line}`);
2050
+ this.reason = reason;
2051
+ this.line = line;
2052
+ this.span = span;
2053
+ }
2054
+ }
2055
+ $.$mol_error_syntax = $mol_error_syntax;
2056
+ })($ || ($ = {}));
2057
+ //mol/error/syntax/syntax.ts
2058
+ ;
2059
+ "use strict";
2060
+ var $;
2061
+ (function ($) {
2062
+ function $mol_tree2_from_string(str, uri = '?') {
2063
+ const span = $mol_span.entire(uri, str);
2064
+ var root = $mol_tree2.list([], span);
2065
+ var stack = [root];
2066
+ var pos = 0, row = 0, min_indent = 0;
2067
+ while (str.length > pos) {
2068
+ var indent = 0;
2069
+ var line_start = pos;
2070
+ row++;
2071
+ while (str.length > pos && str[pos] == '\t') {
2072
+ indent++;
2073
+ pos++;
2074
+ }
2075
+ if (!root.kids.length) {
2076
+ min_indent = indent;
2077
+ }
2078
+ indent -= min_indent;
2079
+ if (indent < 0 || indent >= stack.length) {
2080
+ const sp = span.span(row, 1, pos - line_start);
2081
+ while (str.length > pos && str[pos] != '\n') {
2082
+ pos++;
2083
+ }
2084
+ if (indent < 0) {
2085
+ if (str.length > pos) {
2086
+ this.$mol_fail(new this.$mol_error_syntax(`Too few tabs`, str.substring(line_start, pos), sp));
2087
+ }
2088
+ }
2089
+ else {
2090
+ this.$mol_fail(new this.$mol_error_syntax(`Too many tabs`, str.substring(line_start, pos), sp));
2091
+ }
2092
+ }
2093
+ stack.length = indent + 1;
2094
+ var parent = stack[indent];
2095
+ while (str.length > pos && str[pos] != '\\' && str[pos] != '\n') {
2096
+ var error_start = pos;
2097
+ while (str.length > pos && (str[pos] == ' ' || str[pos] == '\t')) {
2098
+ pos++;
2099
+ }
2100
+ if (pos > error_start) {
2101
+ let line_end = str.indexOf('\n', pos);
2102
+ if (line_end === -1)
2103
+ line_end = str.length;
2104
+ const sp = span.span(row, error_start - line_start, pos - error_start + 1);
2105
+ this.$mol_fail(new this.$mol_error_syntax(`Wrong nodes separator`, str.substring(line_start, line_end), sp));
2106
+ }
2107
+ var type_start = pos;
2108
+ while (str.length > pos &&
2109
+ str[pos] != '\\' &&
2110
+ str[pos] != ' ' &&
2111
+ str[pos] != '\t' &&
2112
+ str[pos] != '\n') {
2113
+ pos++;
2114
+ }
2115
+ if (pos > type_start) {
2116
+ let next = new $mol_tree2(str.slice(type_start, pos), '', [], span.span(row, type_start - line_start + 1, pos - type_start));
2117
+ const parent_kids = parent.kids;
2118
+ parent_kids.push(next);
2119
+ parent = next;
2120
+ }
2121
+ if (str.length > pos && str[pos] == ' ') {
2122
+ pos++;
2123
+ }
2124
+ }
2125
+ if (str.length > pos && str[pos] == '\\') {
2126
+ var data_start = pos;
2127
+ while (str.length > pos && str[pos] != '\n') {
2128
+ pos++;
2129
+ }
2130
+ let next = new $mol_tree2('', str.slice(data_start + 1, pos), [], span.span(row, data_start - line_start + 2, pos - data_start - 1));
2131
+ const parent_kids = parent.kids;
2132
+ parent_kids.push(next);
2133
+ parent = next;
2134
+ }
2135
+ if (str.length === pos && stack.length > 0) {
2136
+ const sp = span.span(row, pos - line_start + 1, 1);
2137
+ this.$mol_fail(new this.$mol_error_syntax(`Undexpected EOF, LF required`, str.substring(line_start, str.length), sp));
2138
+ }
2139
+ stack.push(parent);
2140
+ pos++;
2141
+ }
2142
+ return root;
2143
+ }
2144
+ $.$mol_tree2_from_string = $mol_tree2_from_string;
2145
+ })($ || ($ = {}));
2146
+ //mol/tree2/from/string/string.ts
2147
+ ;
2148
+ "use strict";
2149
+ var $;
2150
+ (function ($) {
2151
+ function $mol_tree2_from_json(json, span = $mol_span.unknown) {
2152
+ if (typeof json === 'boolean' || typeof json === 'number' || json === null) {
2153
+ return new $mol_tree2(String(json), '', [], span);
2154
+ }
2155
+ if (typeof json === 'string') {
2156
+ return $mol_tree2.data(json, [], span);
2157
+ }
2158
+ if (Array.isArray(json)) {
2159
+ const sub = json.map(json => $mol_tree2_from_json(json, span));
2160
+ return new $mol_tree2('/', '', sub, span);
2161
+ }
2162
+ if (ArrayBuffer.isView(json)) {
2163
+ const buf = new Uint8Array(json.buffer, json.byteOffset, json.byteLength);
2164
+ return $mol_tree2.data(String.fromCharCode(...buf), [], span);
2101
2165
  }
2166
+ if (json instanceof Date) {
2167
+ return new $mol_tree2('', json.toISOString(), [], span);
2168
+ }
2169
+ if (typeof json.toJSON === 'function') {
2170
+ return $mol_tree2_from_json(json.toJSON());
2171
+ }
2172
+ if (json instanceof Error) {
2173
+ const { name, message, stack } = json;
2174
+ json = { ...json, name, message, stack };
2175
+ }
2176
+ const sub = [];
2177
+ for (var key in json) {
2178
+ const val = json[key];
2179
+ if (val === undefined)
2180
+ continue;
2181
+ const subsub = $mol_tree2_from_json(val, span);
2182
+ if (/^[^\n\t\\ ]+$/.test(key)) {
2183
+ sub.push(new $mol_tree2(key, '', [subsub], span));
2184
+ }
2185
+ else {
2186
+ sub.push($mol_tree2.data(key, [subsub], span));
2187
+ }
2188
+ }
2189
+ return new $mol_tree2('*', '', sub, span);
2102
2190
  }
2103
- $.$mol_tree = $mol_tree;
2191
+ $.$mol_tree2_from_json = $mol_tree2_from_json;
2104
2192
  })($ || ($ = {}));
2105
- //mol/tree/tree.ts
2193
+ //mol/tree2/from/json/json.ts
2106
2194
  ;
2107
2195
  "use strict";
2108
2196
  var $;
@@ -2157,7 +2245,8 @@ var $;
2157
2245
  return function $mol_log3_logger(event) {
2158
2246
  if (!event.time)
2159
2247
  event = { time: new Date().toISOString(), ...event };
2160
- const tree = this.$mol_tree.fromJSON(event).clone({ type });
2248
+ let tree = this.$mol_tree2_from_json(event);
2249
+ tree = tree.struct(type, tree.kids);
2161
2250
  let str = color(tree.toString());
2162
2251
  this.console[level](str);
2163
2252
  const self = this;
@@ -3044,61 +3133,176 @@ var $;
3044
3133
  var $;
3045
3134
  (function ($_1) {
3046
3135
  $mol_test({
3047
- 'tree parsing'() {
3048
- $mol_assert_equal($mol_tree.fromString("foo\nbar\n").sub.length, 2);
3049
- $mol_assert_equal($mol_tree.fromString("foo\nbar\n").sub[1].type, "bar");
3050
- $mol_assert_equal($mol_tree.fromString("foo\n\n\n").sub.length, 1);
3051
- $mol_assert_equal($mol_tree.fromString("=foo\n\\bar\n").sub.length, 2);
3052
- $mol_assert_equal($mol_tree.fromString("=foo\n\\bar\n").sub[1].data, "bar");
3053
- $mol_assert_equal($mol_tree.fromString("foo bar \\pol").sub[0].sub[0].sub[0].data, "pol");
3054
- $mol_assert_equal($mol_tree.fromString("foo bar\n\t\\pol\n\t\\men").sub[0].sub[0].sub[1].data, "men");
3055
- $mol_assert_equal($mol_tree.fromString('foo bar \\text\n').toString(), 'foo bar \\text\n');
3136
+ 'span for same uri'($) {
3137
+ const span = new $mol_span('test.ts', '', 1, 3, 4);
3138
+ const child = span.span(4, 5, 8);
3139
+ $mol_assert_equal(child.uri, 'test.ts');
3140
+ $mol_assert_equal(child.row, 4);
3141
+ $mol_assert_equal(child.col, 5);
3142
+ $mol_assert_equal(child.length, 8);
3056
3143
  },
3057
- 'inserting'() {
3058
- $mol_assert_equal($mol_tree.fromString('a b c d').insert(new $mol_tree, 'a', 'b', 'c').toString(), 'a b \\\n');
3059
- $mol_assert_equal($mol_tree.fromString('a b').insert(new $mol_tree, 'a', 'b', 'c', 'd').toString(), 'a b c \\\n');
3060
- $mol_assert_equal($mol_tree.fromString('a b c d').insert(new $mol_tree, 0, 0, 0).toString(), 'a b \\\n');
3061
- $mol_assert_equal($mol_tree.fromString('a b').insert(new $mol_tree, 0, 0, 0, 0).toString(), 'a b \\\n\t\\\n');
3062
- $mol_assert_equal($mol_tree.fromString('a b c d').insert(new $mol_tree, null, null, null).toString(), 'a b \\\n');
3063
- $mol_assert_equal($mol_tree.fromString('a b').insert(new $mol_tree, null, null, null, null).toString(), 'a b \\\n\t\\\n');
3144
+ 'span after of given position'($) {
3145
+ const span = new $mol_span('test.ts', '', 1, 3, 4);
3146
+ const child = span.after(11);
3147
+ $mol_assert_equal(child.uri, 'test.ts');
3148
+ $mol_assert_equal(child.row, 1);
3149
+ $mol_assert_equal(child.col, 7);
3150
+ $mol_assert_equal(child.length, 11);
3064
3151
  },
3065
- 'fromJSON'() {
3066
- $mol_assert_equal($mol_tree.fromJSON([]).toString(), '/\n');
3067
- $mol_assert_equal($mol_tree.fromJSON([false, true]).toString(), '/\n\tfalse\n\ttrue\n');
3068
- $mol_assert_equal($mol_tree.fromJSON([0, 1, 2.3]).toString(), '/\n\t0\n\t1\n\t2.3\n');
3069
- $mol_assert_equal($mol_tree.fromJSON(['', 'foo', 'bar\nbaz']).toString(), '/\n\t\\\n\t\\foo\n\t\\\n\t\t\\bar\n\t\t\\baz\n');
3070
- $mol_assert_equal($mol_tree.fromJSON({ 'foo': false, 'bar\nbaz': 'lol' }).toString(), '*\n\tfoo false\n\t\\\n\t\t\\bar\n\t\t\\baz\n\t\t\\lol\n');
3152
+ 'slice span - regular'($) {
3153
+ const span = new $mol_span('test.ts', '', 1, 3, 5);
3154
+ const child = span.slice(1, 4);
3155
+ $mol_assert_equal(child.row, 1);
3156
+ $mol_assert_equal(child.col, 4);
3157
+ $mol_assert_equal(child.length, 3);
3158
+ const child2 = span.slice(2, 2);
3159
+ $mol_assert_equal(child2.col, 5);
3160
+ $mol_assert_equal(child2.length, 0);
3071
3161
  },
3072
- 'toJSON'() {
3073
- $mol_assert_equal(JSON.stringify($mol_tree.fromString('/\n').sub[0]), '[]');
3074
- $mol_assert_equal(JSON.stringify($mol_tree.fromString('/\n\tfalse\n\ttrue\n').sub[0]), '[false,true]');
3075
- $mol_assert_equal(JSON.stringify($mol_tree.fromString('/\n\t0\n\t1\n\t2.3\n').sub[0]), '[0,1,2.3]');
3076
- $mol_assert_equal(JSON.stringify($mol_tree.fromString('/\n\t\\\n\t\\foo\n\t\\\n\t\t\\bar\n\t\t\\baz\n').sub[0]), '["","foo","bar\\nbaz"]');
3077
- $mol_assert_equal(JSON.stringify($mol_tree.fromString('*\n\tfoo false\n\t\\\n\t\t\\bar\n\t\t\\baz\n\t\t\\lol\n').sub[0]), '{"foo":false,"bar\\nbaz":"lol"}');
3162
+ 'slice span - negative'($) {
3163
+ const span = new $mol_span('test.ts', '', 1, 3, 5);
3164
+ const child = span.slice(-3, -1);
3165
+ $mol_assert_equal(child.row, 1);
3166
+ $mol_assert_equal(child.col, 5);
3167
+ $mol_assert_equal(child.length, 2);
3078
3168
  },
3079
- 'hack'() {
3080
- const res = $mol_tree.fromString(`foo bar xxx`).hack({
3081
- '': (tree, context) => [tree.hack(context)],
3082
- 'bar': (tree, context) => [tree.hack(context).clone({ type: '777' })],
3169
+ 'slice span - out of range'($) {
3170
+ const span = new $mol_span('test.ts', '', 1, 3, 5);
3171
+ $mol_assert_fail(() => span.slice(-1, 3));
3172
+ $mol_assert_fail(() => span.slice(1, 6));
3173
+ $mol_assert_fail(() => span.slice(1, 10));
3174
+ },
3175
+ 'error handling'($) {
3176
+ const span = new $mol_span('test.ts', '', 1, 3, 4);
3177
+ const error = span.error('Some error\n');
3178
+ $mol_assert_equal(error.message, 'Some error\ntest.ts#1:3/4');
3179
+ }
3180
+ });
3181
+ })($ || ($ = {}));
3182
+ //mol/span/span.test.ts
3183
+ ;
3184
+ "use strict";
3185
+ var $;
3186
+ (function ($_1) {
3187
+ $mol_test({
3188
+ 'inserting'($) {
3189
+ $mol_assert_equal($.$mol_tree2_from_string('a b c d\n')
3190
+ .insert($mol_tree2.struct('x'), 'a', 'b', 'c')
3191
+ .toString(), 'a b x\n');
3192
+ $mol_assert_equal($.$mol_tree2_from_string('a b\n')
3193
+ .insert($mol_tree2.struct('x'), 'a', 'b', 'c', 'd')
3194
+ .toString(), 'a b c x\n');
3195
+ $mol_assert_equal($.$mol_tree2_from_string('a b c d\n')
3196
+ .insert($mol_tree2.struct('x'), 0, 0, 0)
3197
+ .toString(), 'a b x\n');
3198
+ $mol_assert_equal($.$mol_tree2_from_string('a b\n')
3199
+ .insert($mol_tree2.struct('x'), 0, 0, 0, 0)
3200
+ .toString(), 'a b \\\n\tx\n');
3201
+ $mol_assert_equal($.$mol_tree2_from_string('a b c d\n')
3202
+ .insert($mol_tree2.struct('x'), null, null, null)
3203
+ .toString(), 'a b x\n');
3204
+ $mol_assert_equal($.$mol_tree2_from_string('a b\n')
3205
+ .insert($mol_tree2.struct('x'), null, null, null, null)
3206
+ .toString(), 'a b \\\n\tx\n');
3207
+ },
3208
+ 'deleting'($) {
3209
+ $mol_assert_equal($.$mol_tree2_from_string('a b c d\n')
3210
+ .insert(null, 'a', 'b', 'c')
3211
+ .toString(), 'a b\n');
3212
+ $mol_assert_equal($.$mol_tree2_from_string('a b c d\n')
3213
+ .insert(null, 0, 0, 0)
3214
+ .toString(), 'a b\n');
3215
+ },
3216
+ 'hack'($) {
3217
+ const res = $.$mol_tree2_from_string(`foo bar xxx\n`)
3218
+ .hack({
3219
+ 'bar': (input, belt) => [input.struct('777', input.hack(belt))],
3083
3220
  });
3084
- $mol_assert_equal(res.toString(), new $mol_tree({ type: 'foo 777 xxx' }).toString());
3221
+ $mol_assert_equal(res.toString(), 'foo 777 xxx\n');
3222
+ },
3223
+ });
3224
+ })($ || ($ = {}));
3225
+ //mol/tree2/tree2.test.ts
3226
+ ;
3227
+ "use strict";
3228
+ var $;
3229
+ (function ($_1) {
3230
+ $mol_test({
3231
+ 'tree parsing'($) {
3232
+ $mol_assert_equal($.$mol_tree2_from_string("foo\nbar\n").kids.length, 2);
3233
+ $mol_assert_equal($.$mol_tree2_from_string("foo\nbar\n").kids[1].type, "bar");
3234
+ $mol_assert_equal($.$mol_tree2_from_string("foo\n\n\n").kids.length, 1);
3235
+ $mol_assert_equal($.$mol_tree2_from_string("=foo\n\\bar\n").kids.length, 2);
3236
+ $mol_assert_equal($.$mol_tree2_from_string("=foo\n\\bar\n").kids[1].value, "bar");
3237
+ $mol_assert_equal($.$mol_tree2_from_string("foo bar \\pol\n").kids[0].kids[0].kids[0].value, "pol");
3238
+ $mol_assert_equal($.$mol_tree2_from_string("foo bar\n\t\\pol\n\t\\men\n").kids[0].kids[0].kids[1].value, "men");
3239
+ $mol_assert_equal($.$mol_tree2_from_string('foo bar \\text\n').toString(), 'foo bar \\text\n');
3085
3240
  },
3086
- 'errors handling'($) {
3241
+ 'Too many tabs'($) {
3242
+ const tree = `
3243
+ foo
3244
+ bar
3245
+ `;
3246
+ $mol_assert_fail(() => {
3247
+ $.$mol_tree2_from_string(tree, 'test');
3248
+ }, 'Too many tabs\ntest#3:1/6\n!!!!!!\n\t\t\t\t\t\tbar');
3249
+ },
3250
+ 'Too few tabs'($) {
3251
+ const tree = `
3252
+ foo
3253
+ bar
3254
+ `;
3255
+ $mol_assert_fail(() => {
3256
+ $.$mol_tree2_from_string(tree, 'test');
3257
+ }, 'Too few tabs\ntest#3:1/4\n!!!!\n\t\t\t\tbar');
3258
+ },
3259
+ 'Wrong nodes separator'($) {
3260
+ const tree = `foo bar\n`;
3261
+ $mol_assert_fail(() => {
3262
+ $.$mol_tree2_from_string(tree, 'test');
3263
+ }, 'Wrong nodes separator\ntest#1:4/2\n !!\nfoo bar');
3264
+ },
3265
+ 'Undexpected EOF, LF required'($) {
3266
+ const tree = ` foo`;
3267
+ $mol_assert_fail(() => {
3268
+ $.$mol_tree2_from_string(tree, 'test');
3269
+ }, 'Undexpected EOF, LF required\ntest#1:5/1\n !\n foo');
3270
+ },
3271
+ 'Errors skip and collect'($) {
3272
+ const tree = `foo bar`;
3087
3273
  const errors = [];
3088
- class Tree extends $mol_tree {
3089
- static $ = $.$mol_ambient({
3090
- $mol_fail: error => errors.push(error.message)
3091
- });
3092
- }
3093
- Tree.fromString(`
3094
- \t \tfoo
3095
- bar \\data
3096
- `, 'test');
3097
- $mol_assert_like(errors, ['Syntax error at test:2\n \tfoo']);
3274
+ const $$ = $.$mol_ambient({
3275
+ $mol_fail: (error) => {
3276
+ errors.push(error.message);
3277
+ return null;
3278
+ }
3279
+ });
3280
+ const res = $$.$mol_tree2_from_string(tree, 'test');
3281
+ $mol_assert_like(errors, [
3282
+ 'Wrong nodes separator\ntest#1:4/2\n !!\nfoo bar',
3283
+ 'Undexpected EOF, LF required\ntest#1:9/1\n !\nfoo bar',
3284
+ ]);
3285
+ $mol_assert_equal(res.toString(), 'foo bar\n');
3286
+ },
3287
+ });
3288
+ })($ || ($ = {}));
3289
+ //mol/tree2/from/string/string.test.ts
3290
+ ;
3291
+ "use strict";
3292
+ var $;
3293
+ (function ($) {
3294
+ $mol_test({
3295
+ 'fromJSON'() {
3296
+ $mol_assert_equal($mol_tree2_from_json([]).toString(), '/\n');
3297
+ $mol_assert_equal($mol_tree2_from_json([false, true]).toString(), '/\n\tfalse\n\ttrue\n');
3298
+ $mol_assert_equal($mol_tree2_from_json([0, 1, 2.3]).toString(), '/\n\t0\n\t1\n\t2.3\n');
3299
+ $mol_assert_equal($mol_tree2_from_json(new Uint16Array([1, 10, 256])).toString(), '\\\x01\x00\n\\\x00\x00\x01\n');
3300
+ $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');
3301
+ $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');
3098
3302
  },
3099
3303
  });
3100
3304
  })($ || ($ = {}));
3101
- //mol/tree/tree.test.ts
3305
+ //mol/tree2/from/json/json.test.ts
3102
3306
  ;
3103
3307
  "use strict";
3104
3308
  var $;