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,361 +0,0 @@
1
- /** インデント構文を処理するモジュール */
2
- import { NakoIndentError } from '../src/nako_errors.mjs';
3
- import { NewEmptyToken } from './nako_types.mjs';
4
- import { debugTokens, newToken } from './nako_tools.mjs';
5
- const IS_DEBUG = false;
6
- function isSkipWord(t) {
7
- if (t.type === '違えば') {
8
- return true;
9
- }
10
- if (t.type === 'word' && t.value === 'エラー' && t.josi === 'ならば') {
11
- return true;
12
- }
13
- return false;
14
- }
15
- // 前処理として、JSONオブジェクト内に改行があれば削除する処理を追加
16
- function removeJsonEol(tokens) {
17
- let jsonObjLevel = 0;
18
- let jsonArrayLevel = 0;
19
- let jsonStartIndent = -1;
20
- let flagNeedResetIndent = false;
21
- for (let i = 0; i < tokens.length; i++) {
22
- const t = tokens[i];
23
- // start of JSON
24
- if (t.type === '{') {
25
- jsonObjLevel++;
26
- if (jsonStartIndent === -1) {
27
- jsonStartIndent = t.indent;
28
- }
29
- continue;
30
- }
31
- if (t.type === '[') {
32
- jsonArrayLevel++;
33
- if (jsonStartIndent === -1) {
34
- jsonStartIndent = t.indent;
35
- }
36
- continue;
37
- }
38
- // end of JSON
39
- if (t.type === '}') {
40
- jsonObjLevel--;
41
- if (jsonObjLevel === 0 && jsonArrayLevel === 0) {
42
- flagNeedResetIndent = true;
43
- }
44
- continue;
45
- }
46
- if (t.type === ']') {
47
- jsonArrayLevel--;
48
- if (jsonObjLevel === 0 && jsonArrayLevel === 0) {
49
- flagNeedResetIndent = true;
50
- }
51
- continue;
52
- }
53
- if (jsonObjLevel > 0 || jsonArrayLevel > 0) {
54
- t.indent = jsonStartIndent;
55
- if (t.type === 'eol') {
56
- // replace eol to comment
57
- t.type = 'range_comment';
58
- t.value = 'json::eol';
59
- }
60
- continue;
61
- }
62
- if (flagNeedResetIndent) {
63
- t.indent = jsonStartIndent;
64
- if (t.type === 'eol') {
65
- flagNeedResetIndent = false;
66
- jsonStartIndent = -1;
67
- }
68
- }
69
- }
70
- }
71
- /** インラインインデント構文 --- 末尾の":"をインデントを考慮して"ここまで"を挿入 (#1215) */
72
- export function convertInlineIndent(tokens) {
73
- //
74
- // 0:もし、A=0ならば:
75
- // 2: もし、B=0ならば:
76
- // 4: 「A=0,B=0」を表示。
77
- // 2: 違えば:
78
- // 4: 「A=0,B!=0」を表示。
79
- // 5:違えば:
80
- // 6: 「A!=0」を表示。
81
- // 前処理
82
- removeJsonEol(tokens);
83
- // 一行ずつ処理する
84
- const lines = splitTokens(tokens, 'eol');
85
- const blockIndents = [];
86
- let checkICount = -1;
87
- for (let i = 0; i < lines.length; i++) {
88
- const line = lines[i];
89
- // 空行は飛ばす || コメント行だけの行も飛ばす
90
- if (IsEmptyLine(line)) {
91
- continue;
92
- }
93
- const leftToken = GetLeftTokens(line);
94
- // インデントの終了を確認する必要があるか?
95
- if (checkICount >= 0) {
96
- const lineICount = leftToken.indent;
97
- while (checkICount >= lineICount) {
98
- const tFirst = leftToken;
99
- // console.log('@@', lineICount, '>>', checkICount, tFirst.type)
100
- if (isSkipWord(tFirst) && (checkICount === lineICount)) { // 「違えば」や「エラーならば」
101
- // 「ここまで」の挿入不要 / ただしネストした際の「違えば」(上記の5の状態なら必要)
102
- }
103
- else {
104
- // ここまでを挿入する
105
- lines[i - 1].push(newToken('ここまで', 'ここまで', tFirst));
106
- lines[i - 1].push(newToken('eol', '\n', tFirst));
107
- }
108
- blockIndents.pop();
109
- if (blockIndents.length > 0) {
110
- checkICount = blockIndents[blockIndents.length - 1];
111
- }
112
- else {
113
- checkICount = -1;
114
- break;
115
- }
116
- }
117
- }
118
- // 末尾の「:」をチェック
119
- const tLast = getLastTokenWithoutEOL(line);
120
- if (tLast.type === ':') {
121
- // 末尾の「:」を削除
122
- lines[i] = lines[i].filter(t => t !== tLast);
123
- checkICount = tLast.indent;
124
- blockIndents.push(checkICount);
125
- }
126
- }
127
- if (lines.length > 0 && blockIndents.length > 0) {
128
- // トークン情報を得るため、直近のトークンを得る
129
- let t = tokens[0];
130
- for (let i = lines.length - 1; i >= 0; i--) {
131
- const line = lines[i];
132
- if (line.length > 0) {
133
- t = line[line.length - 1];
134
- break;
135
- }
136
- }
137
- // ここまでを差し込む
138
- for (let i = 0; i < blockIndents.length; i++) {
139
- lines[lines.length - 1].push(newToken('ここまで', 'ここまで', t));
140
- lines[lines.length - 1].push(newToken('eol', '\n', t));
141
- }
142
- }
143
- const result = joinTokenLines(lines);
144
- if (IS_DEBUG) {
145
- console.log('###', debugTokens(result));
146
- }
147
- return result;
148
- }
149
- /** 行ごとに分割していたトークンをくっつける */
150
- export function joinTokenLines(lines) {
151
- const r = [];
152
- for (const line of lines) {
153
- for (const t of line) {
154
- r.push(t);
155
- }
156
- }
157
- return r;
158
- }
159
- // トークン行の最後のトークンを取得する
160
- function getLastTokenWithoutEOL(line) {
161
- const len = line.length;
162
- let res = NewEmptyToken('?');
163
- if (len === 0) {
164
- return res;
165
- }
166
- // 改行やコメントならば、前のトークンを取得
167
- for (let i = 0; i < len; i++) {
168
- // 行末のトークンを取得
169
- res = line[len - i - 1];
170
- if (res.type === 'eol') {
171
- continue;
172
- }
173
- if (res.type === 'line_comment' || res.type === 'range_comment') {
174
- continue;
175
- }
176
- break;
177
- }
178
- return res;
179
- }
180
- export function splitTokens(tokens, delimiter) {
181
- const result = [];
182
- let line = [];
183
- let kakko = 0;
184
- for (const t of tokens) {
185
- line.push(t);
186
- if (t.type === '{') {
187
- kakko++;
188
- }
189
- else if (t.type === '}') {
190
- kakko--;
191
- }
192
- else if (kakko === 0 && t.type === delimiter) {
193
- result.push(line);
194
- line = [];
195
- }
196
- }
197
- if (line.length > 0) {
198
- result.push(line);
199
- }
200
- return result;
201
- }
202
- /** トークン行が空かどうか調べる */
203
- function IsEmptyLine(line) {
204
- if (line.length === 0) {
205
- return true;
206
- }
207
- for (let j = 0; j < line.length; j++) {
208
- const ty = line[j].type;
209
- if (ty === 'eol' || ty === 'line_comment' || ty === 'range_comment') {
210
- continue;
211
- }
212
- return false;
213
- }
214
- return true;
215
- }
216
- /** コメントを除去した最初のトークンを返す */
217
- function GetLeftTokens(line) {
218
- for (let i = 0; i < line.length; i++) {
219
- const t = line[i].type;
220
- if (t === 'eol' || t === 'line_comment' || t === 'range_comment') {
221
- continue;
222
- }
223
- return line[i];
224
- }
225
- return line[0];
226
- }
227
- // インデント構文のキーワード
228
- const INDENT_MODE_KEYWORDS = ['!インデント構文', '!ここまでだるい', '💡インデント構文', '💡ここまでだるい'];
229
- /** インデント構文 --- インデントを見て"ここまで"を自動挿入 (#596) */
230
- export function convertIndentSyntax(tokens) {
231
- // インデント構文の変換が必要か?
232
- if (!useIndentSynax(tokens)) {
233
- return tokens;
234
- }
235
- // 『ここまで』があったらエラーを出す
236
- for (const t of tokens) {
237
- if (t.type === 'ここまで') {
238
- // エラーを出す
239
- throw new NakoIndentError('インデント構文が有効化されているときに『ここまで』を使うことはできません。', t.line, t.file);
240
- }
241
- }
242
- // JSON構文のチェック
243
- let jsonObjLevel = 0;
244
- let jsonArrayLevel = 0;
245
- const checkJsonSyntax = (line) => {
246
- // JSONのオブジェクトがあるか?
247
- line.forEach((t) => {
248
- if (t.type === '{') {
249
- jsonObjLevel++;
250
- }
251
- if (t.type === '}') {
252
- jsonObjLevel--;
253
- }
254
- if (t.type === '[') {
255
- jsonArrayLevel++;
256
- }
257
- if (t.type === ']') {
258
- jsonArrayLevel--;
259
- }
260
- });
261
- };
262
- // 行ごとにトークンを分割
263
- const blockIndents = [];
264
- const lines = splitTokens(tokens, 'eol');
265
- let lastI = 0;
266
- // 各行を確認する
267
- for (let i = 0; i < lines.length; i++) {
268
- const line = lines[i];
269
- // 空行は飛ばす || コメント行だけの行も飛ばす
270
- if (IsEmptyLine(line)) {
271
- continue;
272
- }
273
- // JSON構文のチェック
274
- if (jsonArrayLevel > 0 || jsonObjLevel > 0) {
275
- checkJsonSyntax(line);
276
- continue;
277
- }
278
- const leftToken = GetLeftTokens(line);
279
- const curI = leftToken.indent;
280
- if (curI === lastI) {
281
- continue;
282
- }
283
- // ブロックの終了?
284
- // 0: 3回
285
- // 2: もし、1 > 1ならば
286
- // 4: 1を表示
287
- // 2: 違えば
288
- // 4: 2を表示
289
- // 0:
290
- // ブロックの終了?
291
- if (lastI >= 0) {
292
- while (lastI > curI) {
293
- const blockIndentTopLast = blockIndents[blockIndents.length - 1][1];
294
- // console.log('@@[', i, ']', lastI, '>', curI, '@', blockIndentTopLast, leftToken.type)
295
- if (isSkipWord(leftToken) && blockIndentTopLast === curI) {
296
- // 「違えば」などなら不要 (ただし、違えばがネストしている場合は必要)
297
- }
298
- else {
299
- const t = lines[i - 1][0];
300
- lines[i - 1].push(newToken('ここまで', 'ここまで', t));
301
- lines[i - 1].push(newToken('eol', '\n', t));
302
- }
303
- blockIndents.pop();
304
- if (blockIndents.length > 0) {
305
- lastI = blockIndents[blockIndents.length - 1][0];
306
- }
307
- else {
308
- lastI = 0;
309
- break;
310
- }
311
- }
312
- }
313
- if (jsonArrayLevel > 0 || jsonObjLevel > 0) {
314
- continue;
315
- }
316
- // JSON構文のチェック
317
- checkJsonSyntax(line);
318
- // ブロックの開始?
319
- if (curI > lastI) {
320
- blockIndents.push([curI, lastI]);
321
- lastI = curI;
322
- continue;
323
- }
324
- }
325
- // 末尾に「ここまで」を追加する
326
- for (let i = 0; i < blockIndents.length; i++) {
327
- // トークン情報を得るため、直近のトークンを得る
328
- let t = tokens[0];
329
- for (let i = lines.length - 1; i >= 0; i--) {
330
- const line = lines[i];
331
- if (line.length > 0) {
332
- // テンプレートとなるトークンを行の後方から順に探す
333
- for (let j = 0; j < line.length; j++) {
334
- const tt = line[line.length - j - 1];
335
- if (tt.line > 0) {
336
- t = tt;
337
- break;
338
- }
339
- }
340
- break;
341
- }
342
- }
343
- lines[lines.length - 1].push(newToken('ここまで', 'ここまで', t));
344
- lines[lines.length - 1].push(newToken('eol', '\n', t));
345
- }
346
- const result = joinTokenLines(lines);
347
- return result;
348
- }
349
- function useIndentSynax(tokens) {
350
- // インデント構文が必要かチェック (最初の100個をチェック)
351
- for (let i = 0; i < tokens.length; i++) {
352
- if (i > 100) {
353
- break;
354
- }
355
- const t = tokens[i];
356
- if (t.type === 'line_comment' && (INDENT_MODE_KEYWORDS.indexOf(t.value) >= 0)) {
357
- return true;
358
- }
359
- }
360
- return false;
361
- }
@@ -1,47 +0,0 @@
1
- /**
2
- * 助詞の一覧
3
- */
4
- // 基本的な助詞の一覧
5
- export const josiList = [
6
- 'について', 'くらい', 'なのか', 'までを', 'までの', 'による', 'として',
7
- 'とは', 'から', 'まで', 'だけ', 'より', 'ほど', 'など',
8
- 'いて', 'えて', 'きて', 'けて', 'して', 'って', 'にて', 'みて',
9
- 'めて', 'ねて', 'では', 'には', 'んで', 'ずつ',
10
- 'は', 'を', 'に', 'へ', 'で', 'と', 'が', 'の'
11
- ];
12
- // 「もし」文で使う助詞
13
- export const tararebaJosiList = [
14
- 'でなければ', 'なければ', 'ならば', 'なら', 'たら', 'れば'
15
- ];
16
- // 意味のない助詞(削除する) #936 #939 #974
17
- export const removeJosiList = [
18
- 'こと', 'である', 'です', 'します', 'でした', 'にゃん'
19
- ];
20
- /**
21
- * 「もし」文で使う「たら」「れば」などの一覧をプログラムで扱いやすいようマップに変換したもの
22
- */
23
- export const tararebaMap = {};
24
- tararebaJosiList.forEach(josi => {
25
- josiList.push(josi);
26
- tararebaMap[josi] = true;
27
- });
28
- /**
29
- * 意味のない助詞(削除する)をマップに変換したもの
30
- */
31
- export const removeJosiMap = {};
32
- removeJosiList.forEach(josi => {
33
- josiList.push(josi);
34
- removeJosiMap[josi] = true;
35
- });
36
- // 「もの」構文 (#1614)
37
- const josiListMono = [];
38
- for (const jo of josiList) {
39
- josiListMono.push('もの' + jo);
40
- josiListMono.push(jo);
41
- }
42
- // 文字数の長い順に並び替え
43
- josiListMono.sort((a, b) => b.length - a.length);
44
- // 正規表現で助詞をマッチできるようにする
45
- const pat = '^[\\t  ]*(' + josiListMono.join('|') + ')';
46
- export const josiRE = new RegExp(pat);
47
- export const josiListExport = josiList;