nadesiko3 3.7.21 → 3.7.22

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.
Files changed (155) hide show
  1. package/batch/command.txt +370 -334
  2. package/batch/jsplugin2text.nako3 +1 -1
  3. package/batch/pickup_command.nako3 +12 -0
  4. package/core/command/snako.mts +5 -1
  5. package/core/deno/snako.ts +5 -1
  6. package/core/package-lock.json +382 -21
  7. package/core/package.json +4 -4
  8. package/core/src/nako3.mts +178 -614
  9. package/core/src/nako_basic_plugins.mts +39 -0
  10. package/core/src/nako_core_version.mts +2 -2
  11. package/core/src/nako_csv.mts +0 -1
  12. package/core/src/nako_event.mts +49 -0
  13. package/core/src/nako_gen.mts +291 -202
  14. package/core/src/nako_indent_inline.mts +2 -2
  15. package/core/src/nako_lex_rules.mts +1 -1
  16. package/core/src/nako_parser3.mts +106 -165
  17. package/core/src/nako_parser_async.mts +97 -0
  18. package/core/src/nako_parser_base.mts +4 -55
  19. package/core/src/nako_parser_message.mts +105 -0
  20. package/core/src/nako_parser_operator.mts +93 -0
  21. package/core/src/nako_plugin_manager.mts +260 -0
  22. package/core/src/nako_require.mts +292 -0
  23. package/core/src/nako_runner.mts +191 -0
  24. package/core/src/nako_tokenizer.mts +221 -0
  25. package/core/src/plugin_csv.mts +1 -1
  26. package/core/src/plugin_system.mts +34 -3259
  27. package/core/src/plugin_system_array.mts +699 -0
  28. package/core/src/plugin_system_datetime.mts +368 -0
  29. package/core/src/plugin_system_debug.mts +403 -0
  30. package/core/src/plugin_system_dict.mts +85 -0
  31. package/core/src/plugin_system_json.mts +73 -0
  32. package/core/src/plugin_system_math.mts +383 -0
  33. package/core/src/plugin_system_regexp.mts +120 -0
  34. package/core/src/plugin_system_stdio.mts +86 -0
  35. package/core/src/plugin_system_string.mts +666 -0
  36. package/core/src/plugin_system_timer.mts +152 -0
  37. package/core/src/plugin_system_types.mts +151 -0
  38. package/core/src/plugin_system_url.mts +193 -0
  39. package/core/src/plugin_toml.mts +3 -3
  40. package/core/test/fixtures/README.md +39 -0
  41. package/core/test/fixtures/make_parser_ast_golden.mjs +31 -0
  42. package/core/test/fixtures/parser_ast_golden.json +8027 -0
  43. package/core/test/fixtures/parser_corpus.mjs +120 -0
  44. package/core/test/indent_test.mjs +6 -0
  45. package/core/test/nako_basic_plugins_test.mjs +44 -0
  46. package/core/test/nako_event_test.mjs +85 -0
  47. package/core/test/nako_gen_perf_test.mjs +178 -0
  48. package/core/test/nako_parser_async_test.mjs +112 -0
  49. package/core/test/nako_parser_test.mjs +160 -0
  50. package/core/test/nako_plugin_manager_test.mjs +185 -0
  51. package/core/test/nako_require_test.mjs +153 -0
  52. package/core/test/nako_runner_test.mjs +114 -0
  53. package/core/test/nako_tokenizer_test.mjs +115 -0
  54. package/core/test/plugin_system_debug_test.mjs +141 -0
  55. package/core/test/plugin_system_split_test.mjs +179 -0
  56. package/core/test/plugin_system_test.mjs +6 -0
  57. package/core/tsconfig.json +0 -1
  58. package/package.json +17 -21
  59. package/release/_hash.txt +36 -36
  60. package/release/_script-tags.txt +16 -16
  61. package/release/command.json +1 -1
  62. package/release/command.json.js +1 -1
  63. package/release/command_cnako3.json +1 -1
  64. package/release/command_list.json +1 -1
  65. package/release/edit_main.js +6 -6
  66. package/release/edit_main.js.map +3 -3
  67. package/release/editor.js +6 -6
  68. package/release/plugin_keigo.js.map +3 -3
  69. package/release/plugin_markup.js +46 -46
  70. package/release/plugin_markup.js.map +3 -3
  71. package/release/plugin_weykturtle3d.js +1 -1
  72. package/release/plugin_weykturtle3d.js.map +3 -3
  73. package/release/version.js +2 -2
  74. package/release/version_main.js +2 -2
  75. package/release/version_main.js.map +1 -1
  76. package/release/wnako3.js +186 -213
  77. package/release/wnako3.js.map +4 -4
  78. package/release/wnako3webworker.js +172 -199
  79. package/release/wnako3webworker.js.map +4 -4
  80. package/src/cnako3mod.mjs +7 -2
  81. package/src/cnako3mod.mts +7 -2
  82. package/src/nako_version.mjs +2 -2
  83. package/src/nako_version.mts +2 -2
  84. package/src/plugin_browser_ajax.mjs +4 -4
  85. package/src/plugin_browser_ajax.mts +4 -4
  86. package/src/plugin_browser_audio.mjs +10 -10
  87. package/src/plugin_browser_audio.mts +10 -10
  88. package/src/plugin_browser_camera.mjs +4 -4
  89. package/src/plugin_browser_camera.mts +4 -4
  90. package/src/plugin_browser_canvas.mjs +2 -2
  91. package/src/plugin_browser_canvas.mts +2 -2
  92. package/src/plugin_browser_crypto.mjs +3 -3
  93. package/src/plugin_browser_crypto.mts +3 -3
  94. package/src/plugin_browser_dom_event.mjs +1 -1
  95. package/src/plugin_browser_dom_event.mts +1 -1
  96. package/src/plugin_browser_geolocation.mjs +1 -1
  97. package/src/plugin_browser_geolocation.mts +1 -1
  98. package/src/plugin_browser_hotkey.mjs +1 -1
  99. package/src/plugin_browser_hotkey.mts +1 -1
  100. package/src/plugin_browser_html.mjs +1 -1
  101. package/src/plugin_browser_html.mts +1 -1
  102. package/src/plugin_browser_location.mjs +1 -1
  103. package/src/plugin_browser_location.mts +1 -1
  104. package/src/plugin_browser_speech.mjs +1 -1
  105. package/src/plugin_browser_speech.mts +1 -1
  106. package/src/plugin_browser_storage.mjs +2 -2
  107. package/src/plugin_browser_storage.mts +2 -2
  108. package/src/plugin_httpserver.mjs +3 -3
  109. package/src/plugin_httpserver.mts +3 -3
  110. package/src/plugin_keigo.mjs +2 -2
  111. package/src/plugin_keigo.mts +2 -2
  112. package/src/plugin_node.mjs +48 -48
  113. package/src/plugin_node.mts +53 -53
  114. package/src/plugin_weykturtle3d.mjs +56 -56
  115. package/src/plugin_weykturtle3d.mts +56 -56
  116. package/src/wnako3.mjs +1 -1
  117. package/src/wnako3.mts +1 -1
  118. package/src/wnako3_editor.mjs +5 -5
  119. package/src/wnako3_editor.mts +5 -5
  120. package/src/wnako3mod.mjs +2 -2
  121. package/src/wnako3mod.mts +2 -2
  122. package/core/src/nako3.mjs +0 -1021
  123. package/core/src/nako_ast.mjs +0 -4
  124. package/core/src/nako_colors.mjs +0 -77
  125. package/core/src/nako_core_version.mjs +0 -8
  126. package/core/src/nako_csv.mjs +0 -193
  127. package/core/src/nako_errors.mjs +0 -166
  128. package/core/src/nako_from_dncl.mjs +0 -285
  129. package/core/src/nako_from_dncl2.mjs +0 -347
  130. package/core/src/nako_gen.mjs +0 -2500
  131. package/core/src/nako_global.mjs +0 -138
  132. package/core/src/nako_indent.mjs +0 -442
  133. package/core/src/nako_indent_chars.mjs +0 -29
  134. package/core/src/nako_indent_inline.mjs +0 -361
  135. package/core/src/nako_josi_list.mjs +0 -47
  136. package/core/src/nako_lex_rules.mjs +0 -319
  137. package/core/src/nako_lexer.mjs +0 -794
  138. package/core/src/nako_logger.mjs +0 -221
  139. package/core/src/nako_parser3.mjs +0 -3250
  140. package/core/src/nako_parser_base.mjs +0 -403
  141. package/core/src/nako_parser_const.mjs +0 -37
  142. package/core/src/nako_prepare.mjs +0 -329
  143. package/core/src/nako_reserved_words.mjs +0 -42
  144. package/core/src/nako_source_mapping.mjs +0 -207
  145. package/core/src/nako_test.mjs +0 -37
  146. package/core/src/nako_token.mjs +0 -1
  147. package/core/src/nako_tools.mjs +0 -53
  148. package/core/src/nako_types.mjs +0 -14
  149. package/core/src/plugin_api.mjs +0 -4
  150. package/core/src/plugin_csv.mjs +0 -97
  151. package/core/src/plugin_math.mjs +0 -352
  152. package/core/src/plugin_promise.mjs +0 -102
  153. package/core/src/plugin_system.mjs +0 -3810
  154. package/core/src/plugin_test.mjs +0 -52
  155. package/core/src/plugin_toml.mjs +0 -39
@@ -1,403 +0,0 @@
1
- import { NewEmptyToken } from './nako_types.mjs';
2
- /**
3
- * なでしこの構文解析のためのユーティリティクラス
4
- */
5
- export class NakoParserBase {
6
- constructor(logger) {
7
- this.logger = logger;
8
- this.stackList = []; // 関数定義の際にスタックが混乱しないように整理する
9
- this.tokens = [];
10
- this.usedFuncs = new Set();
11
- /** @type {import('./nako3.mjs').Ast[]} */
12
- this.stack = [];
13
- this.index = 0;
14
- /** トークン出現チェック(accept関数)に利用する
15
- * @type {import('./nako3.mjs').Ast[]}
16
- */
17
- this.y = [];
18
- /** モジュル名 @type {string} */
19
- this.modName = 'inline';
20
- this.namespaceStack = [];
21
- /**
22
- * 利用するモジュールの名前一覧
23
- * @type {Array<string>}
24
- */
25
- this.modList = [];
26
- /** グローバル変数・関数の確認用 */
27
- this.funclist = new Map();
28
- this.funcLevel = 0;
29
- this.usedAsyncFn = false; // asyncFnの呼び出しがあるかどうか
30
- /**
31
- * ローカル変数の確認用
32
- * @type {Object.<string,Object>}
33
- */
34
- this.localvars = new Map([['それ', { type: 'var', value: '' }]]);
35
- /** コード生成器の名前 @type {string} */
36
- this.genMode = 'sync'; // #637
37
- /** 配列のインデックスが先頭要素(#1140) @type {int} */
38
- this.arrayIndexFrom = 0;
39
- /** 配列のインデックス順序を反対にするか(#1140) @type {boolean} */
40
- this.flagReverseArrayIndex = false;
41
- /** 配列を自動的に初期化するか(#1140) @type {boolean} */
42
- this.flagCheckArrayInit = false;
43
- /** 最近呼び出した関数(余剰エラーの報告に使う) */
44
- this.recentlyCalledFunc = [];
45
- // 構文解析に利用する - 現在計算式を読んでいるかどうか
46
- this.isReadingCalc = false;
47
- // エクスポート設定が未設定の関数・変数に対する既定値
48
- this.isExportDefault = true;
49
- this.isExportStack = [];
50
- this.moduleExport = new Map();
51
- this.isModifiedNodes = false;
52
- this.init();
53
- }
54
- init() {
55
- this.funclist = new Map(); // 関数の一覧
56
- this.moduleExport = new Map();
57
- this.reset();
58
- }
59
- reset() {
60
- this.tokens = []; // 字句解析済みのトークンの一覧を保存
61
- this.index = 0; // tokens[] のどこまで読んだかを管理する
62
- this.stack = []; // 計算用のスタック ... 直接は操作せず、pushStack() popStack() を介して使う
63
- this.y = []; // accept()で解析済みのトークンを配列で得るときに使う
64
- this.genMode = 'sync'; // #637, #1056
65
- // 次回実行時に持ち越されないように初期化する (#1746)
66
- this.localvars = new Map([['それ', { type: 'var', value: '' }]]);
67
- this.usedFuncs = new Set();
68
- this.funcLevel = 0;
69
- this.usedAsyncFn = false;
70
- this.isReadingCalc = false;
71
- this.isExportDefault = true;
72
- this.isExportStack = [];
73
- this.namespaceStack = [];
74
- this.modList = [];
75
- this.stackList = [];
76
- this.recentlyCalledFunc = [];
77
- this.arrayIndexFrom = 0;
78
- this.flagReverseArrayIndex = false;
79
- this.flagCheckArrayInit = false;
80
- this.isModifiedNodes = false;
81
- }
82
- setFuncList(funclist) {
83
- this.funclist = funclist;
84
- }
85
- setModuleExport(moduleexport) {
86
- this.moduleExport = moduleexport;
87
- }
88
- /**
89
- * 特定の助詞を持つ要素をスタックから一つ下ろす、指定がなければ末尾を下ろす
90
- * @param {string[]} josiList 下ろしたい助詞の配列
91
- */
92
- popStack(josiList = undefined) {
93
- if (!josiList) {
94
- const t = this.stack.pop();
95
- if (t) {
96
- return t;
97
- }
98
- return null;
99
- }
100
- // josiList にマッチする助詞を探す
101
- for (let i = this.stack.length - 1; i >= 0; i--) {
102
- const t = this.stack[i];
103
- if (josiList.length === 0 || josiList.indexOf(t.josi) >= 0) {
104
- this.stack.splice(i, 1); // remove stack
105
- this.logger.trace('POP :' + JSON.stringify(t));
106
- return t;
107
- }
108
- }
109
- // 該当する助詞が見つからなかった場合
110
- return null;
111
- }
112
- /**
113
- * saveStack と loadStack は対で使う。
114
- * 関数定義などでスタックが混乱しないように配慮するためのもの
115
- */
116
- saveStack() {
117
- this.stackList.push(this.stack);
118
- this.stack = [];
119
- }
120
- loadStack() {
121
- this.stack = this.stackList.pop();
122
- }
123
- /** 変数名を探す
124
- * @param {string} name
125
- * @returns {any}変数名の情報
126
- */
127
- findVar(name) {
128
- // ローカル変数?
129
- if (this.localvars.get(name)) {
130
- return {
131
- name,
132
- scope: 'local',
133
- info: this.localvars.get(name)
134
- };
135
- }
136
- // モジュール名を含んでいる?
137
- if (name.indexOf('__') >= 0) {
138
- if (this.funclist.get(name)) {
139
- return {
140
- name,
141
- scope: 'global',
142
- info: this.funclist.get(name)
143
- };
144
- }
145
- else {
146
- return undefined;
147
- }
148
- }
149
- // グローバル変数(自身)?
150
- const gnameSelf = `${this.modName}__${name}`;
151
- if (this.funclist.get(gnameSelf)) {
152
- return {
153
- name: gnameSelf,
154
- scope: 'global',
155
- info: this.funclist.get(gnameSelf)
156
- };
157
- }
158
- // グローバル変数(モジュールを検索)?
159
- for (const mod of this.modList) {
160
- const gname = `${mod}__${name}`;
161
- const exportDefault = this.moduleExport.get(mod);
162
- const funcObj = this.funclist.get(gname);
163
- if (funcObj && (funcObj.isExport === true || (funcObj.isExport !== false && exportDefault !== false))) {
164
- return {
165
- name: gname,
166
- scope: 'global',
167
- info: this.funclist.get(gname)
168
- };
169
- }
170
- }
171
- // システム変数 (funclistを普通に検索)
172
- if (this.funclist.get(name)) {
173
- return {
174
- name,
175
- scope: 'system',
176
- info: this.funclist.get(name)
177
- };
178
- }
179
- return undefined;
180
- }
181
- /**
182
- * 計算用に要素をスタックに積む
183
- */
184
- pushStack(item) {
185
- this.logger.trace('PUSH:' + JSON.stringify(item));
186
- this.stack.push(item);
187
- }
188
- /**
189
- * トークンの末尾に達したか
190
- */
191
- isEOF() {
192
- return (this.index >= this.tokens.length);
193
- }
194
- getIndex() {
195
- return this.index;
196
- }
197
- /**
198
- * カーソル位置にある単語の型を確かめる
199
- */
200
- check(ttype) {
201
- return (this.tokens[this.index].type === ttype);
202
- }
203
- /**
204
- * カーソル位置以降にある単語の型を確かめる 2単語以上に対応
205
- * @param a [単語1の型, 単語2の型, ... ]
206
- */
207
- check2(a) {
208
- for (let i = 0; i < a.length; i++) {
209
- const idx = i + this.index;
210
- if (this.tokens.length <= idx) {
211
- return false;
212
- }
213
- if (a[i] === '*') {
214
- continue;
215
- } // ワイルドカード(どんなタイプも許容)
216
- const t = this.tokens[idx];
217
- if (a[i] instanceof Array) {
218
- if (a[i].indexOf(t.type) < 0) {
219
- return false;
220
- }
221
- continue;
222
- }
223
- if (t.type !== a[i]) {
224
- return false;
225
- }
226
- }
227
- return true;
228
- }
229
- /**
230
- * カーソル位置の型を確認するが、複数の種類を確かめられる
231
- */
232
- checkTypes(a) {
233
- const type = this.tokens[this.index].type;
234
- return (a.indexOf(type) >= 0);
235
- }
236
- /**
237
- * check2の高度なやつ、型名の他にコールバック関数を指定できる
238
- * 型にマッチしなければ false を返し、カーソルを巻き戻す
239
- */
240
- accept(types) {
241
- const y = [];
242
- const tmpIndex = this.index;
243
- const rollback = () => {
244
- this.index = tmpIndex;
245
- return false;
246
- };
247
- for (let i = 0; i < types.length; i++) {
248
- if (this.isEOF()) {
249
- return rollback();
250
- }
251
- const type = types[i];
252
- if (type === null) {
253
- return rollback();
254
- }
255
- if (typeof type === 'string') {
256
- const token = this.get();
257
- if (token && token.type !== type) {
258
- return rollback();
259
- }
260
- y[i] = token;
261
- continue;
262
- }
263
- if (typeof type === 'function') {
264
- const f = type.bind(this);
265
- const r = f(y);
266
- if (r === null) {
267
- return rollback();
268
- }
269
- y[i] = r;
270
- continue;
271
- }
272
- if (type instanceof Array) {
273
- if (!this.checkTypes(type)) {
274
- return rollback();
275
- }
276
- y[i] = this.get();
277
- continue;
278
- }
279
- throw new Error('System Error : accept broken : ' + typeof type);
280
- }
281
- this.y = y;
282
- return true;
283
- }
284
- /**
285
- * カーソル語句を取得して、カーソルを後ろに移動する
286
- */
287
- get() {
288
- if (this.isEOF()) {
289
- return null;
290
- }
291
- return this.tokens[this.index++];
292
- }
293
- /** カーソル語句を取得してカーソルを進める、取得できなければエラーを出す */
294
- getCur() {
295
- if (this.isEOF()) {
296
- throw new Error('トークンが取得できません。');
297
- }
298
- const t = this.tokens[this.index++];
299
- if (!t) {
300
- throw new Error('トークンが取得できません。');
301
- }
302
- return t;
303
- }
304
- unget() {
305
- if (this.index > 0) {
306
- this.index--;
307
- }
308
- }
309
- /** 解析中のトークンを返す */
310
- peek(i = 0) {
311
- if (this.isEOF()) {
312
- return null;
313
- }
314
- return this.tokens[this.index + i];
315
- }
316
- /** 解析中のトークンを返す、無理なら def を返す */
317
- peekDef(def = null) {
318
- if (this.isEOF()) {
319
- if (!def) {
320
- def = NewEmptyToken();
321
- }
322
- return def;
323
- }
324
- return this.tokens[this.index];
325
- }
326
- /**
327
- * 現在のカーソル語句のソースコード上の位置を取得する。
328
- */
329
- peekSourceMap(t = undefined) {
330
- const token = (t === undefined) ? this.peek() : t;
331
- if (token === null) {
332
- return { startOffset: undefined, endOffset: undefined, file: undefined, line: 0, column: 0 };
333
- }
334
- return { startOffset: token.startOffset, endOffset: token.endOffset, file: token.file, line: token.line, column: token.column };
335
- }
336
- /**
337
- * depth: 表示する深さ
338
- * typeName: 先頭のtypeの表示を上書きする場合に設定する
339
- * @param {{ depth: number, typeName?: string }} opts
340
- * @param {boolean} debugMode
341
- */
342
- nodeToStr(node, opts, debugMode) {
343
- const depth = opts.depth - 1;
344
- const typeName = (name) => (opts.typeName !== undefined) ? opts.typeName : name;
345
- const debug = debugMode ? (' debug: ' + JSON.stringify(node, null, 2)) : '';
346
- if (!node) {
347
- return '(NULL)';
348
- }
349
- switch (node.type) {
350
- case 'not':
351
- if (depth >= 0) {
352
- const subNode = node.blocks[0];
353
- return `${typeName('')}『${this.nodeToStr(subNode, { depth }, debugMode)}に演算子『not』を適用した式${debug}』`;
354
- }
355
- else {
356
- return `${typeName('演算子')}『not』`;
357
- }
358
- case 'op': {
359
- const node2 = node;
360
- let operator = node2.operator || '';
361
- const table = { eq: '=', not: '!', gt: '>', lt: '<', and: 'かつ', or: 'または' };
362
- if (operator in table) {
363
- operator = table[operator];
364
- }
365
- if (depth >= 0) {
366
- const left = this.nodeToStr(node2.blocks[0], { depth }, debugMode);
367
- const right = this.nodeToStr(node2.blocks[1], { depth }, debugMode);
368
- if (node2.operator === 'eq') {
369
- return `${typeName('')}『${left}と${right}が等しいかどうかの比較${debug}』`;
370
- }
371
- return `${typeName('')}『${left}と${right}に演算子『${operator}』を適用した式${debug}』`;
372
- }
373
- else {
374
- return `${typeName('演算子')}『${operator}${debug}』`;
375
- }
376
- }
377
- case 'number':
378
- return `${typeName('数値')}${node.value}`;
379
- case 'bigint':
380
- return `${typeName('巨大整数')}${node.value}`;
381
- case 'string':
382
- return `${typeName('文字列')}『${node.value}${debug}』`;
383
- case 'word':
384
- return `${typeName('単語')}『${node.value}${debug}』`;
385
- case 'func':
386
- return `${typeName('関数')}『${node.name || node.value}${debug}』`;
387
- case 'eol':
388
- return '行の末尾';
389
- case 'eof':
390
- return 'ファイルの末尾';
391
- default: {
392
- let name = node.name;
393
- if (name) {
394
- name = node.value;
395
- }
396
- if (typeof name !== 'string') {
397
- name = node.type;
398
- }
399
- return `${typeName('')}『${name}${debug}』`;
400
- }
401
- }
402
- }
403
- }
@@ -1,37 +0,0 @@
1
- export const opPriority = {
2
- // and or
3
- 'and': 1,
4
- 'or': 1,
5
- // compare
6
- 'eq': 2,
7
- 'noteq': 2,
8
- '===': 2,
9
- '!==': 2,
10
- 'gt': 2,
11
- 'gteq': 2,
12
- 'lt': 2,
13
- 'lteq': 2,
14
- '&': 3,
15
- // + - << >> >>>
16
- '+': 4,
17
- '-': 4,
18
- 'shift_l': 4,
19
- 'shift_r': 4,
20
- 'shift_r0': 4,
21
- // * /
22
- '*': 5,
23
- '/': 5, // 一般的な割り算
24
- '÷': 5, // 一般的な割り算
25
- '÷÷': 5, // 整数の割り算
26
- '%': 5,
27
- // ^
28
- '^': 6,
29
- '**': 6
30
- };
31
- export const RenbunJosi = [
32
- 'いて', 'えて', 'きて', 'けて', 'して', 'って', 'にて', 'みて', 'めて', 'ねて', 'には', 'んで'
33
- ];
34
- export const operatorList = [];
35
- for (const key in opPriority) {
36
- operatorList.push(key);
37
- }