@leemour/cli-messaging 0.145.0 → 0.147.0
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/README.md +1 -1
- package/THIRD_PARTY_NOTICES +34 -0
- package/dist/background/units.d.ts +1 -0
- package/dist/background/units.d.ts.map +1 -1
- package/dist/background/units.js +9 -0
- package/dist/background/units.js.map +1 -1
- package/dist/cli/bot/people.js +1 -1
- package/dist/cli/bot/people.js.map +1 -1
- package/dist/cli/index.d.ts +4 -1
- package/dist/cli/index.d.ts.map +1 -1
- package/dist/cli/index.js +4 -1
- package/dist/cli/index.js.map +1 -1
- package/dist/cli/messenger/backfill-command.d.ts.map +1 -1
- package/dist/cli/messenger/backfill-command.js +4 -0
- package/dist/cli/messenger/backfill-command.js.map +1 -1
- package/dist/cli/messenger/chats-members-command.d.ts.map +1 -1
- package/dist/cli/messenger/chats-members-command.js +35 -1
- package/dist/cli/messenger/chats-members-command.js.map +1 -1
- package/dist/cli/messenger/chats-stats-command.js +1 -1
- package/dist/cli/messenger/chats-stats-command.js.map +1 -1
- package/dist/cli/messenger/context.d.ts +2 -0
- package/dist/cli/messenger/context.d.ts.map +1 -1
- package/dist/cli/messenger/context.js.map +1 -1
- package/dist/cli/messenger/messages-search-command.d.ts.map +1 -1
- package/dist/cli/messenger/messages-search-command.js +3 -1
- package/dist/cli/messenger/messages-search-command.js.map +1 -1
- package/dist/cli/messenger/points.d.ts +2 -1
- package/dist/cli/messenger/points.d.ts.map +1 -1
- package/dist/cli/messenger/points.js +1 -0
- package/dist/cli/messenger/points.js.map +1 -1
- package/dist/cli/messenger/server-command.d.ts.map +1 -1
- package/dist/cli/messenger/server-command.js +18 -2
- package/dist/cli/messenger/server-command.js.map +1 -1
- package/dist/domain/models.d.ts +10 -0
- package/dist/domain/models.d.ts.map +1 -1
- package/dist/mcp/prompts.d.ts.map +1 -1
- package/dist/mcp/prompts.js +27 -8
- package/dist/mcp/prompts.js.map +1 -1
- package/dist/mcp/tools/chats.d.ts.map +1 -1
- package/dist/mcp/tools/chats.js +19 -1
- package/dist/mcp/tools/chats.js.map +1 -1
- package/dist/mcp/tools/inbox.d.ts +2 -0
- package/dist/mcp/tools/inbox.d.ts.map +1 -1
- package/dist/mcp/tools/inbox.js +27 -4
- package/dist/mcp/tools/inbox.js.map +1 -1
- package/dist/mcp/tools/review.d.ts.map +1 -1
- package/dist/mcp/tools/review.js +23 -2
- package/dist/mcp/tools/review.js.map +1 -1
- package/dist/replies/decide.d.ts +34 -0
- package/dist/replies/decide.d.ts.map +1 -0
- package/dist/replies/decide.js +109 -0
- package/dist/replies/decide.js.map +1 -0
- package/dist/replies/rules.d.ts +127 -0
- package/dist/replies/rules.d.ts.map +1 -0
- package/dist/replies/rules.js +119 -0
- package/dist/replies/rules.js.map +1 -0
- package/dist/replies/state.d.ts +36 -0
- package/dist/replies/state.d.ts.map +1 -0
- package/dist/replies/state.js +67 -0
- package/dist/replies/state.js.map +1 -0
- package/dist/search/search.d.ts.map +1 -1
- package/dist/search/search.js +4 -3
- package/dist/search/search.js.map +1 -1
- package/dist/search/snowball/LICENSE +29 -0
- package/dist/search/snowball/base-stemmer.js +445 -0
- package/dist/search/snowball/english-stemmer.js +775 -0
- package/dist/search/snowball/russian-stemmer.js +468 -0
- package/dist/search/snowball/spanish-stemmer.js +722 -0
- package/dist/search/stem.d.ts +35 -0
- package/dist/search/stem.d.ts.map +1 -0
- package/dist/search/stem.js +76 -0
- package/dist/search/stem.js.map +1 -0
- package/dist/services/archive.d.ts.map +1 -1
- package/dist/services/archive.js +4 -2
- package/dist/services/archive.js.map +1 -1
- package/dist/services/chat-stats.d.ts +3 -0
- package/dist/services/chat-stats.d.ts.map +1 -1
- package/dist/services/chat-stats.js +3 -0
- package/dist/services/chat-stats.js.map +1 -1
- package/dist/services/chats.d.ts +10 -0
- package/dist/services/chats.d.ts.map +1 -1
- package/dist/services/chats.js +61 -0
- package/dist/services/chats.js.map +1 -1
- package/dist/services/members-audit.d.ts +44 -0
- package/dist/services/members-audit.d.ts.map +1 -0
- package/dist/services/members-audit.js +111 -0
- package/dist/services/members-audit.js.map +1 -0
- package/dist/services/messages-search.d.ts +4 -2
- package/dist/services/messages-search.d.ts.map +1 -1
- package/dist/services/messages-search.js +13 -5
- package/dist/services/messages-search.js.map +1 -1
- package/dist/services/messages.js +1 -1
- package/dist/services/messages.js.map +1 -1
- package/dist/store/sqlite/completeness.d.ts +10 -1
- package/dist/store/sqlite/completeness.d.ts.map +1 -1
- package/dist/store/sqlite/completeness.js +15 -3
- package/dist/store/sqlite/completeness.js.map +1 -1
- package/dist/store/store.d.ts +2 -1
- package/dist/store/store.d.ts.map +1 -1
- package/dist/store/store.js +9 -2
- package/dist/store/store.js.map +1 -1
- package/package.json +2 -2
- package/parity.json +58 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"state.js","sourceRoot":"","sources":["../../src/replies/state.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,SAAS,CAAA;AAClD,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAA;AAChC,OAAO,EAAE,QAAQ,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAA;AACzE,OAAO,KAAK,CAAC,MAAM,SAAS,CAAA;AAK5B,+GAA+G;AAC/G,MAAM,CAAC,MAAM,aAAa,GAAG,IAAI,CAAA;AAEjC,MAAM,KAAK,GAAG,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,MAAM,EAAE,CAAC,CAAC,CAAA;AAEvD,MAAM,SAAS,GAAG,CAAC,CAAC,MAAM,CAAC;IACzB,MAAM,EAAE,CAAC,CAAC,OAAO,EAAE;IACnB,wCAAwC;IACxC,QAAQ,EAAE,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,MAAM,EAAE,CAAC;IAC7B,+EAA+E;IAC/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M,GAAG,CAAC,IAAY,EAAE,GAAW,EAAE,EAAE,CAC3C,IAAI,QAAQ,CAAC,qBAAqB,EAAE,mBAAmB,IAAI,oBAAoB,GAAG,0BAA0B,CAAC,CAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"search.d.ts","sourceRoot":"","sources":["../../src/search/search.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,YAAY,EAAE,SAAS,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAA;AAIxF,iFAAiF;AACjF,MAAM,MAAM,KAAK,GAAG,OAAO,GAAG,YAAY,GAAG,WAAW,GAAG,SAAS,GAAG,WAAW,GAAG,SAAS,CAAA;AAE9F,MAAM,MAAM,SAAS,GAAG,SAAS,GAAG;IAAE,KAAK,EAAE,KAAK,CAAA;CAAE,CAAA;AAEpD,MAAM,WAAW,YAAY;IAC3B,KAAK,EAAE,SAAS,EAAE,CAAA;IAClB,OAAO,EAAE,OAAO,CAAA;IAChB,WAAW,EAAE;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,EAAE,EAAE,MAAM,EAAE,CAAA;KAAE,EAAE,CAAA;IAC7C,sGAAsG;IACtG,UAAU,EAAE,OAAO,CAAA;CACpB;AAED,MAAM,MAAM,WAAW,GAAG,IAAI,CAC5B,YAAY,EACZ,kBAAkB,GAAG,YAAY,GAAG,gBAAgB,GAAG,cAAc,GAAG,YAAY,GAAG,gBAAgB,CACxG,CAAA;AAkCD;;;;GAIG;AACH,eAAO,MAAM,MAAM,UACV,WAAW,SACX,SAAS,SACT,WAAW,qBACS;IAAE,KAAK,EAAE,MAAM,CAAC;IAAC,MAAM,CAAC,EAAE,OAAO,CAAA;CAAE,KAC7D,OAAO,CAAC,YAAY,
|
|
1
|
+
{"version":3,"file":"search.d.ts","sourceRoot":"","sources":["../../src/search/search.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,YAAY,EAAE,SAAS,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAA;AAIxF,iFAAiF;AACjF,MAAM,MAAM,KAAK,GAAG,OAAO,GAAG,YAAY,GAAG,WAAW,GAAG,SAAS,GAAG,WAAW,GAAG,SAAS,CAAA;AAE9F,MAAM,MAAM,SAAS,GAAG,SAAS,GAAG;IAAE,KAAK,EAAE,KAAK,CAAA;CAAE,CAAA;AAEpD,MAAM,WAAW,YAAY;IAC3B,KAAK,EAAE,SAAS,EAAE,CAAA;IAClB,OAAO,EAAE,OAAO,CAAA;IAChB,WAAW,EAAE;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,EAAE,EAAE,MAAM,EAAE,CAAA;KAAE,EAAE,CAAA;IAC7C,sGAAsG;IACtG,UAAU,EAAE,OAAO,CAAA;CACpB;AAED,MAAM,MAAM,WAAW,GAAG,IAAI,CAC5B,YAAY,EACZ,kBAAkB,GAAG,YAAY,GAAG,gBAAgB,GAAG,cAAc,GAAG,YAAY,GAAG,gBAAgB,CACxG,CAAA;AAkCD;;;;GAIG;AACH,eAAO,MAAM,MAAM,UACV,WAAW,SACX,SAAS,SACT,WAAW,qBACS;IAAE,KAAK,EAAE,MAAM,CAAC;IAAC,MAAM,CAAC,EAAE,OAAO,CAAA;CAAE,KAC7D,OAAO,CAAC,YAAY,CAwCtB,CAAA"}
|
package/dist/search/search.js
CHANGED
|
@@ -25,9 +25,10 @@ const corrected = (query, corrections) => ({
|
|
|
25
25
|
* runs only when the one before found nothing. Until the word index is built, substring alone.
|
|
26
26
|
*/
|
|
27
27
|
export const search = async (store, query, scope, { limit, newest = false }) => {
|
|
28
|
+
const wordsReady = (await store.searchIndexState())?.ready === true;
|
|
28
29
|
const answer = (found, rest = {}) => ({
|
|
29
30
|
corrections: [],
|
|
30
|
-
wordsReady
|
|
31
|
+
wordsReady,
|
|
31
32
|
...found,
|
|
32
33
|
...rest,
|
|
33
34
|
});
|
|
@@ -35,9 +36,9 @@ export const search = async (store, query, scope, { limit, newest = false }) =>
|
|
|
35
36
|
const page = await store.matchFilters(scope, { limit });
|
|
36
37
|
return answer({ items: tagged(page, "filters"), hasMore: page.hasMore });
|
|
37
38
|
}
|
|
38
|
-
if (!
|
|
39
|
+
if (!wordsReady) {
|
|
39
40
|
const page = await store.matchSubstring(query, scope, { limit });
|
|
40
|
-
return answer({ items: tagged(page, "substring"), hasMore: page.hasMore }
|
|
41
|
+
return answer({ items: tagged(page, "substring"), hasMore: page.hasMore });
|
|
41
42
|
}
|
|
42
43
|
const options = { limit, newest };
|
|
43
44
|
const found = await everyWord(store, query, scope, options, { whole: "words", beginnings: "beginnings" });
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"search.js","sourceRoot":"","sources":["../../src/search/search.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,YAAY,EAAE,MAAM,cAAc,CAAA;AAqB3C,MAAM,MAAM,GAAG,CAAC,IAAqB,EAAE,KAAY,EAAE,EAAE,CAAC,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,CAAC,EAAE,GAAG,GAAG,EAAE,KAAK,EAAE,CAAC,CAAC,CAAA;AAEpG,kGAAkG;AAClG,MAAM,SAAS,GAAG,KAAK,EACrB,KAAkB,EAClB,KAAgB,EAChB,KAAkB,EAClB,EAAE,KAAK,EAAE,MAAM,EAAsC,EACrD,KAA0C,EACS,EAAE;IACrD,MAAM,OAAO,GAAG,EAAE,IAAI,EAAE,OAAgB,EAAE,KAAK,EAAE,MAAM,EAAE,CAAA;IACzD,MAAM,KAAK,GAAG,MAAM,KAAK,CAAC,UAAU,CAAC,KAAK,EAAE,KAAK,EAAE,EAAE,GAAG,OAAO,EAAE,UAAU,EAAE,KAAK,EAAE,CAAC,CAAA;IACrF,IAAI,KAAK,CAAC,KAAK,CAAC,MAAM,IAAI,KAAK;QAAE,OAAO,EAAE,KAAK,EAAE,MAAM,CAAC,KAAK,EAAE,KAAK,CAAC,KAAK,CAAC,EAAE,OAAO,EAAE,KAAK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;YAAE,OAAO,MAAM,CAAC,QAAQ,EAAE,EAAE,WAAW,EAAE,MAAM,EAAE,CAAC,CAAA;IACjF,CAAC;IAED,MAAM,KAAK,GAAG,KAAK,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,MAAM,GAAG,CAAC,CAAC,CAAA;IAC9D,IAAI,CAAC,KAAK,IAAI,KAAK,CAAC,QAAQ,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QACxC,MAAM,GAAG,GAAG,MAAM,KAAK,CAAC,UAAU,CAAC,KAAK,EAAE,KAAK,EAAE,EAAE,IAAI,EAAE,KAAK,EAAE,UAAU,EAAE,IAAI,EAAE,KAAK,EAAE,MAAM,EAAE,CAAC,CAAA;QAClG,IAAI,GAAG,CAAC,KAAK,CAAC,MAAM,GAAG,CAAC;YACtB,OAAO,MAAM,CAAC,EAAE,KAAK,EAAE,MAAM,CAAC,GAAG,EAAE,SAAS,CAAC,EAAE,OAAO,EAAE,GAAG,CAAC,OAAO,EAAE,EAAE,EAAE,WAAW,EAAE,MAAM,EAAE,CAAC,CAAA;IACnG,CAAC;IAED,oGAAoG;IACpG,MAAM,IAAI,GAAG,MAAM,KAAK,CAAC,cAAc,CAAC,KAAK,EAAE,KAAK,EAAE,EAAE,KAAK,EAAE,CAAC,CAAA;IAChE,OAAO,MAAM,CAAC,EAAE,KAAK,EAAE,MAAM,CAAC,IAAI,EAAE,WAAW,CAAC,EAAE,OAAO,EAAE,IAAI,CAAC,OAAO,EAAE,CAAC,CAAA;AAC5E,CAAC,CAAA"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
Copyright (c) 2001, Dr Martin Porter
|
|
2
|
+
Copyright (c) 2004,2005, Richard Boulton
|
|
3
|
+
Copyright (c) 2013, Yoshiki Shibukawa
|
|
4
|
+
Copyright (c) 2006-2025, Olly Betts
|
|
5
|
+
All rights reserved.
|
|
6
|
+
|
|
7
|
+
Redistribution and use in source and binary forms, with or without
|
|
8
|
+
modification, are permitted provided that the following conditions
|
|
9
|
+
are met:
|
|
10
|
+
|
|
11
|
+
1. Redistributions of source code must retain the above copyright notice,
|
|
12
|
+
this list of conditions and the following disclaimer.
|
|
13
|
+
2. Redistributions in binary form must reproduce the above copyright notice,
|
|
14
|
+
this list of conditions and the following disclaimer in the documentation
|
|
15
|
+
and/or other materials provided with the distribution.
|
|
16
|
+
3. Neither the name of the Snowball project nor the names of its contributors
|
|
17
|
+
may be used to endorse or promote products derived from this software
|
|
18
|
+
without specific prior written permission.
|
|
19
|
+
|
|
20
|
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
|
21
|
+
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
|
22
|
+
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
23
|
+
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
|
|
24
|
+
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
|
25
|
+
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
|
26
|
+
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
|
27
|
+
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
28
|
+
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
|
29
|
+
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
@@ -0,0 +1,445 @@
|
|
|
1
|
+
// @ts-check
|
|
2
|
+
|
|
3
|
+
export default class BaseStemmer {
|
|
4
|
+
constructor() {
|
|
5
|
+
/** @protected */
|
|
6
|
+
this.current = '';
|
|
7
|
+
this.c = 0;
|
|
8
|
+
this.limit = 0;
|
|
9
|
+
this.limit_backward = 0;
|
|
10
|
+
this.bra = 0;
|
|
11
|
+
this.ket = 0;
|
|
12
|
+
this.af = 0;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* @param {string} value
|
|
17
|
+
*/
|
|
18
|
+
setCurrent(value) {
|
|
19
|
+
this.current = value;
|
|
20
|
+
this.c = 0;
|
|
21
|
+
this.limit = this.current.length;
|
|
22
|
+
this.limit_backward = 0;
|
|
23
|
+
this.bra = this.c;
|
|
24
|
+
this.ket = this.limit;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* @return {string}
|
|
29
|
+
*/
|
|
30
|
+
getCurrent() {
|
|
31
|
+
return this.current;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* @param {BaseStemmer} other
|
|
36
|
+
*/
|
|
37
|
+
copy_from(other) {
|
|
38
|
+
/** @protected */
|
|
39
|
+
this.current = other.current;
|
|
40
|
+
this.c = other.c;
|
|
41
|
+
this.limit = other.limit;
|
|
42
|
+
this.limit_backward = other.limit_backward;
|
|
43
|
+
this.bra = other.bra;
|
|
44
|
+
this.ket = other.ket;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* @param {Array<number>} s
|
|
49
|
+
* @param {number} min
|
|
50
|
+
* @param {number} max
|
|
51
|
+
* @return {boolean}
|
|
52
|
+
*/
|
|
53
|
+
in_grouping(s, min, max) {
|
|
54
|
+
/** @protected */
|
|
55
|
+
if (this.c >= this.limit) return false;
|
|
56
|
+
let ch = this.current.charCodeAt(this.c);
|
|
57
|
+
if (ch > max || ch < min) return false;
|
|
58
|
+
ch -= min;
|
|
59
|
+
if ((s[ch >>> 3] & (0x1 << (ch & 0x7))) === 0) return false;
|
|
60
|
+
this.c++;
|
|
61
|
+
return true;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* @param {Array<number>} s
|
|
66
|
+
* @param {number} min
|
|
67
|
+
* @param {number} max
|
|
68
|
+
* @return {boolean}
|
|
69
|
+
*/
|
|
70
|
+
go_in_grouping(s, min, max) {
|
|
71
|
+
/** @protected */
|
|
72
|
+
while (this.c < this.limit) {
|
|
73
|
+
let ch = this.current.charCodeAt(this.c);
|
|
74
|
+
if (ch > max || ch < min)
|
|
75
|
+
return true;
|
|
76
|
+
ch -= min;
|
|
77
|
+
if ((s[ch >>> 3] & (0x1 << (ch & 0x7))) === 0)
|
|
78
|
+
return true;
|
|
79
|
+
this.c++;
|
|
80
|
+
}
|
|
81
|
+
return false;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* @param {Array<number>} s
|
|
86
|
+
* @param {number} min
|
|
87
|
+
* @param {number} max
|
|
88
|
+
* @return {boolean}
|
|
89
|
+
*/
|
|
90
|
+
in_grouping_b(s, min, max) {
|
|
91
|
+
/** @protected */
|
|
92
|
+
if (this.c <= this.limit_backward) return false;
|
|
93
|
+
let ch = this.current.charCodeAt(this.c - 1);
|
|
94
|
+
if (ch > max || ch < min) return false;
|
|
95
|
+
ch -= min;
|
|
96
|
+
if ((s[ch >>> 3] & (0x1 << (ch & 0x7))) === 0) return false;
|
|
97
|
+
this.c--;
|
|
98
|
+
return true;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
/**
|
|
102
|
+
* @param {Array<number>} s
|
|
103
|
+
* @param {number} min
|
|
104
|
+
* @param {number} max
|
|
105
|
+
* @return {boolean}
|
|
106
|
+
*/
|
|
107
|
+
go_in_grouping_b(s, min, max) {
|
|
108
|
+
/** @protected */
|
|
109
|
+
while (this.c > this.limit_backward) {
|
|
110
|
+
let ch = this.current.charCodeAt(this.c - 1);
|
|
111
|
+
if (ch > max || ch < min) return true;
|
|
112
|
+
ch -= min;
|
|
113
|
+
if ((s[ch >>> 3] & (0x1 << (ch & 0x7))) === 0) return true;
|
|
114
|
+
this.c--;
|
|
115
|
+
}
|
|
116
|
+
return false;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
/**
|
|
120
|
+
* @param {Array<number>} s
|
|
121
|
+
* @param {number} min
|
|
122
|
+
* @param {number} max
|
|
123
|
+
* @return {boolean}
|
|
124
|
+
*/
|
|
125
|
+
out_grouping(s, min, max) {
|
|
126
|
+
/** @protected */
|
|
127
|
+
if (this.c >= this.limit) return false;
|
|
128
|
+
let ch = this.current.charCodeAt(this.c);
|
|
129
|
+
if (ch > max || ch < min) {
|
|
130
|
+
this.c++;
|
|
131
|
+
return true;
|
|
132
|
+
}
|
|
133
|
+
ch -= min;
|
|
134
|
+
if ((s[ch >>> 3] & (0X1 << (ch & 0x7))) === 0) {
|
|
135
|
+
this.c++;
|
|
136
|
+
return true;
|
|
137
|
+
}
|
|
138
|
+
return false;
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
/**
|
|
142
|
+
* @param {Array<number>} s
|
|
143
|
+
* @param {number} min
|
|
144
|
+
* @param {number} max
|
|
145
|
+
* @return {boolean}
|
|
146
|
+
*/
|
|
147
|
+
go_out_grouping(s, min, max) {
|
|
148
|
+
/** @protected */
|
|
149
|
+
while (this.c < this.limit) {
|
|
150
|
+
let ch = this.current.charCodeAt(this.c);
|
|
151
|
+
if (ch <= max && ch >= min) {
|
|
152
|
+
ch -= min;
|
|
153
|
+
if ((s[ch >>> 3] & (0X1 << (ch & 0x7))) !== 0) {
|
|
154
|
+
return true;
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
this.c++;
|
|
158
|
+
}
|
|
159
|
+
return false;
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
/**
|
|
163
|
+
* @param {Array<number>} s
|
|
164
|
+
* @param {number} min
|
|
165
|
+
* @param {number} max
|
|
166
|
+
* @return {boolean}
|
|
167
|
+
*/
|
|
168
|
+
out_grouping_b(s, min, max) {
|
|
169
|
+
/** @protected */
|
|
170
|
+
if (this.c <= this.limit_backward) return false;
|
|
171
|
+
let ch = this.current.charCodeAt(this.c - 1);
|
|
172
|
+
if (ch > max || ch < min) {
|
|
173
|
+
this.c--;
|
|
174
|
+
return true;
|
|
175
|
+
}
|
|
176
|
+
ch -= min;
|
|
177
|
+
if ((s[ch >>> 3] & (0x1 << (ch & 0x7))) === 0) {
|
|
178
|
+
this.c--;
|
|
179
|
+
return true;
|
|
180
|
+
}
|
|
181
|
+
return false;
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
/**
|
|
185
|
+
* @param {Array<number>} s
|
|
186
|
+
* @param {number} min
|
|
187
|
+
* @param {number} max
|
|
188
|
+
* @return {boolean}
|
|
189
|
+
*/
|
|
190
|
+
go_out_grouping_b(s, min, max) {
|
|
191
|
+
/** @protected */
|
|
192
|
+
while (this.c > this.limit_backward) {
|
|
193
|
+
let ch = this.current.charCodeAt(this.c - 1);
|
|
194
|
+
if (ch <= max && ch >= min) {
|
|
195
|
+
ch -= min;
|
|
196
|
+
if ((s[ch >>> 3] & (0x1 << (ch & 0x7))) !== 0) {
|
|
197
|
+
return true;
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
this.c--;
|
|
201
|
+
}
|
|
202
|
+
return false;
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
/**
|
|
206
|
+
* @param {string} s
|
|
207
|
+
* @return {boolean}
|
|
208
|
+
*/
|
|
209
|
+
eq_s(s) {
|
|
210
|
+
/** @protected */
|
|
211
|
+
if (this.limit - this.c < s.length) return false;
|
|
212
|
+
if (!this.current.startsWith(s, this.c)) return false;
|
|
213
|
+
this.c += s.length;
|
|
214
|
+
return true;
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
/**
|
|
218
|
+
* @param {string} s
|
|
219
|
+
* @return {boolean}
|
|
220
|
+
*/
|
|
221
|
+
eq_s_b(s) {
|
|
222
|
+
/** @protected */
|
|
223
|
+
if (this.c - this.limit_backward < s.length) return false;
|
|
224
|
+
if (!this.current.endsWith(s, this.c)) return false;
|
|
225
|
+
this.c -= s.length;
|
|
226
|
+
return true;
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
/**
|
|
230
|
+
* @param {Array<Array<string|number>>} v
|
|
231
|
+
* @param {?function(): boolean} call_among_func
|
|
232
|
+
* @return {number}
|
|
233
|
+
*/
|
|
234
|
+
find_among(v, call_among_func) {
|
|
235
|
+
/** @protected */
|
|
236
|
+
let i = 0;
|
|
237
|
+
let j = v.length;
|
|
238
|
+
|
|
239
|
+
const c = this.c;
|
|
240
|
+
const l = this.limit;
|
|
241
|
+
|
|
242
|
+
let common_i = 0;
|
|
243
|
+
let common_j = 0;
|
|
244
|
+
|
|
245
|
+
let first_key_inspected = false;
|
|
246
|
+
|
|
247
|
+
while (true) {
|
|
248
|
+
const k = i + ((j - i) >>> 1);
|
|
249
|
+
let diff = 0;
|
|
250
|
+
let common = common_i < common_j ? common_i : common_j; // smaller
|
|
251
|
+
// w[0]: string, w[1]: result, w[2]: substring_i (optional), w[3]: function (optional)
|
|
252
|
+
const w = v[k];
|
|
253
|
+
let i2;
|
|
254
|
+
// @ts-expect-error: w[0] always string.
|
|
255
|
+
for (i2 = common; i2 < w[0].length; i2++) {
|
|
256
|
+
if (c + common === l) {
|
|
257
|
+
diff = -1;
|
|
258
|
+
break;
|
|
259
|
+
}
|
|
260
|
+
// @ts-expect-error: w[0] always string.
|
|
261
|
+
diff = this.current.charCodeAt(c + common) - w[0].charCodeAt(i2);
|
|
262
|
+
if (diff !== 0) break;
|
|
263
|
+
common++;
|
|
264
|
+
}
|
|
265
|
+
if (diff < 0) {
|
|
266
|
+
j = k;
|
|
267
|
+
common_j = common;
|
|
268
|
+
} else {
|
|
269
|
+
i = k;
|
|
270
|
+
common_i = common;
|
|
271
|
+
}
|
|
272
|
+
if (j - i <= 1) {
|
|
273
|
+
if (i > 0) break; // v->s has been inspected
|
|
274
|
+
if (j === i) break; // only one item in v
|
|
275
|
+
|
|
276
|
+
// - but now we need to go round once more to get
|
|
277
|
+
// v->s inspected. This looks messy, but is actually
|
|
278
|
+
// the optimal approach.
|
|
279
|
+
|
|
280
|
+
if (first_key_inspected) break;
|
|
281
|
+
first_key_inspected = true;
|
|
282
|
+
}
|
|
283
|
+
}
|
|
284
|
+
while (true) {
|
|
285
|
+
const w = v[i];
|
|
286
|
+
// @ts-expect-error: w[0] always string.
|
|
287
|
+
if (common_i >= w[0].length) {
|
|
288
|
+
// @ts-expect-error: w[0] always string.
|
|
289
|
+
this.c = c + w[0].length;
|
|
290
|
+
// @ts-expect-error: w[1] always number.
|
|
291
|
+
if (w.length < 4) return w[1];
|
|
292
|
+
// @ts-expect-error: w[3] always number.
|
|
293
|
+
this.af = w[3];
|
|
294
|
+
// @ts-expect-error: call_among_func never null here.
|
|
295
|
+
if (call_among_func.call(this)) {
|
|
296
|
+
// @ts-expect-error: w[0] always string.
|
|
297
|
+
this.c = c + w[0].length;
|
|
298
|
+
// @ts-expect-error: w[3] always number.
|
|
299
|
+
return w[1];
|
|
300
|
+
}
|
|
301
|
+
}
|
|
302
|
+
// Tests for undefined (if w.length < 2) or 0.
|
|
303
|
+
if (!w[2]) return 0;
|
|
304
|
+
// @ts-expect-error: w[2] always number.
|
|
305
|
+
i -= w[2];
|
|
306
|
+
}
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
// find_among_b is for backwards processing. Same comments apply
|
|
310
|
+
/**
|
|
311
|
+
* @param {Array<Array<string|number>>} v
|
|
312
|
+
* @param {?function(): boolean} call_among_func
|
|
313
|
+
*/
|
|
314
|
+
find_among_b(v, call_among_func) {
|
|
315
|
+
/** @protected */
|
|
316
|
+
let i = 0;
|
|
317
|
+
let j = v.length
|
|
318
|
+
|
|
319
|
+
const c = this.c;
|
|
320
|
+
const lb = this.limit_backward;
|
|
321
|
+
|
|
322
|
+
let common_i = 0;
|
|
323
|
+
let common_j = 0;
|
|
324
|
+
|
|
325
|
+
let first_key_inspected = false;
|
|
326
|
+
|
|
327
|
+
while (true) {
|
|
328
|
+
const k = i + ((j - i) >> 1);
|
|
329
|
+
let diff = 0;
|
|
330
|
+
let common = common_i < common_j ? common_i : common_j;
|
|
331
|
+
const w = v[k];
|
|
332
|
+
let i2;
|
|
333
|
+
// @ts-expect-error: w[0] always string.
|
|
334
|
+
for (i2 = w[0].length - 1 - common; i2 >= 0; i2--) {
|
|
335
|
+
if (c - common === lb) {
|
|
336
|
+
diff = -1;
|
|
337
|
+
break;
|
|
338
|
+
}
|
|
339
|
+
// @ts-expect-error: w[0] always string.
|
|
340
|
+
diff = this.current.charCodeAt(c - 1 - common) - w[0].charCodeAt(i2);
|
|
341
|
+
if (diff !== 0) break;
|
|
342
|
+
common++;
|
|
343
|
+
}
|
|
344
|
+
if (diff < 0) {
|
|
345
|
+
j = k;
|
|
346
|
+
common_j = common;
|
|
347
|
+
} else {
|
|
348
|
+
i = k;
|
|
349
|
+
common_i = common;
|
|
350
|
+
}
|
|
351
|
+
if (j - i <= 1) {
|
|
352
|
+
if (i > 0) break;
|
|
353
|
+
if (j === i) break;
|
|
354
|
+
if (first_key_inspected) break;
|
|
355
|
+
first_key_inspected = true;
|
|
356
|
+
}
|
|
357
|
+
}
|
|
358
|
+
while (true) {
|
|
359
|
+
const w = v[i];
|
|
360
|
+
// @ts-expect-error: w[0] always string.
|
|
361
|
+
if (common_i >= w[0].length) {
|
|
362
|
+
// @ts-expect-error: w[0] always string.
|
|
363
|
+
this.c = c - w[0].length;
|
|
364
|
+
if (w.length < 4) return w[1];
|
|
365
|
+
// @ts-expect-error: w[3] always number.
|
|
366
|
+
this.af = w[3];
|
|
367
|
+
// @ts-expect-error: call_among_func never null here.
|
|
368
|
+
if (call_among_func.call(this)) {
|
|
369
|
+
// @ts-expect-error: w[0] always string.
|
|
370
|
+
this.c = c - w[0].length;
|
|
371
|
+
return w[1];
|
|
372
|
+
}
|
|
373
|
+
}
|
|
374
|
+
// Tests for undefined (if w.length < 2) or 0.
|
|
375
|
+
if (!w[2]) return 0;
|
|
376
|
+
// @ts-expect-error: w[2] always number.
|
|
377
|
+
i -= w[2];
|
|
378
|
+
}
|
|
379
|
+
}
|
|
380
|
+
|
|
381
|
+
/* to replace chars between c_bra and c_ket in this.current by the
|
|
382
|
+
* chars in s.
|
|
383
|
+
*/
|
|
384
|
+
/**
|
|
385
|
+
* @param {number} c_bra
|
|
386
|
+
* @param {number} c_ket
|
|
387
|
+
* @param {string} s
|
|
388
|
+
* @return {number}
|
|
389
|
+
*/
|
|
390
|
+
#replace_s(c_bra, c_ket, s) {
|
|
391
|
+
const adjustment = s.length - (c_ket - c_bra);
|
|
392
|
+
this.current = this.current.slice(0, c_bra) + s + this.current.slice(c_ket);
|
|
393
|
+
this.limit += adjustment;
|
|
394
|
+
if (this.c >= c_ket) this.c += adjustment;
|
|
395
|
+
else if (this.c > c_bra) this.c = c_bra;
|
|
396
|
+
return adjustment;
|
|
397
|
+
}
|
|
398
|
+
|
|
399
|
+
/**
|
|
400
|
+
*/
|
|
401
|
+
#slice_check() {
|
|
402
|
+
console.assert(this.bra >= 0);
|
|
403
|
+
console.assert(this.bra <= this.ket);
|
|
404
|
+
console.assert(this.ket <= this.limit);
|
|
405
|
+
console.assert(this.limit <= this.current.length);
|
|
406
|
+
}
|
|
407
|
+
|
|
408
|
+
/**
|
|
409
|
+
* @param {string} s
|
|
410
|
+
*/
|
|
411
|
+
slice_from(s) {
|
|
412
|
+
/** @protected */
|
|
413
|
+
this.#slice_check();
|
|
414
|
+
this.#replace_s(this.bra, this.ket, s);
|
|
415
|
+
this.ket = this.bra + s.length;
|
|
416
|
+
}
|
|
417
|
+
|
|
418
|
+
/**
|
|
419
|
+
*/
|
|
420
|
+
slice_del() {
|
|
421
|
+
/** @protected */
|
|
422
|
+
this.slice_from("");
|
|
423
|
+
}
|
|
424
|
+
|
|
425
|
+
/**
|
|
426
|
+
* @param {number} c_bra
|
|
427
|
+
* @param {number} c_ket
|
|
428
|
+
* @param {string} s
|
|
429
|
+
*/
|
|
430
|
+
insert(c_bra, c_ket, s) {
|
|
431
|
+
/** @protected */
|
|
432
|
+
const adjustment = this.#replace_s(c_bra, c_ket, s);
|
|
433
|
+
if (c_bra <= this.bra) this.bra += adjustment;
|
|
434
|
+
if (c_bra <= this.ket) this.ket += adjustment;
|
|
435
|
+
}
|
|
436
|
+
|
|
437
|
+
/**
|
|
438
|
+
* @return {string}
|
|
439
|
+
*/
|
|
440
|
+
slice_to() {
|
|
441
|
+
/** @protected */
|
|
442
|
+
this.#slice_check();
|
|
443
|
+
return this.current.slice(this.bra, this.ket);
|
|
444
|
+
}
|
|
445
|
+
}
|