nadesiko3 3.7.21 → 3.7.23

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 (212) hide show
  1. package/README.md +20 -1
  2. package/batch/command.txt +370 -334
  3. package/batch/generate_command_list.mjs +102 -0
  4. package/batch/jsplugin2text.nako3 +1 -1
  5. package/batch/pickup_command.nako3 +12 -0
  6. package/batch/search_command.mjs +34 -0
  7. package/batch/search_command.nako3 +430 -0
  8. package/core/command/snako.mts +5 -1
  9. package/core/deno/snako.ts +5 -1
  10. package/core/package-lock.json +382 -21
  11. package/core/package.json +7 -4
  12. package/core/sample/algorithms/README.md +43 -0
  13. package/core/sample/algorithms/graph/dijkstra.nako3 +47 -0
  14. package/core/sample/algorithms/graph/kruskal.nako3 +69 -0
  15. package/core/sample/algorithms/math/euclidean_gcd.nako3 +15 -0
  16. package/core/sample/algorithms/math/sieve_of_eratosthenes.nako3 +26 -0
  17. package/core/sample/algorithms/search/binary_search.nako3 +17 -0
  18. package/core/sample/algorithms/search/breadth_first_search.nako3 +33 -0
  19. package/core/sample/algorithms/search/depth_first_search.nako3 +25 -0
  20. package/core/sample/algorithms/sort/heap_sort.nako3 +37 -0
  21. package/core/sample/algorithms/sort/insertion_sort.nako3 +18 -0
  22. package/core/sample/algorithms/sort/merge_sort.nako3 +40 -0
  23. package/core/sample/algorithms/sort/quick_sort.nako3 +36 -0
  24. package/core/sample/algorithms/string/knuth_morris_pratt.nako3 +50 -0
  25. package/core/sample/algorithms/string/run_length_encoding.nako3 +25 -0
  26. package/core/src/nako3.mts +178 -614
  27. package/core/src/nako_basic_plugins.mts +39 -0
  28. package/core/src/nako_core_version.mts +2 -2
  29. package/core/src/nako_csv.mts +0 -1
  30. package/core/src/nako_event.mts +49 -0
  31. package/core/src/nako_gen.mts +320 -209
  32. package/core/src/nako_global.mts +18 -0
  33. package/core/src/nako_indent_inline.mts +2 -2
  34. package/core/src/nako_lex_rules.mts +1 -1
  35. package/core/src/nako_parser3.mts +111 -166
  36. package/core/src/nako_parser_async.mts +165 -0
  37. package/core/src/nako_parser_base.mts +4 -55
  38. package/core/src/nako_parser_message.mts +105 -0
  39. package/core/src/nako_parser_operator.mts +93 -0
  40. package/core/src/nako_plugin_manager.mts +260 -0
  41. package/core/src/nako_require.mts +292 -0
  42. package/core/src/nako_runner.mts +208 -0
  43. package/core/src/nako_tokenizer.mts +221 -0
  44. package/core/src/plugin_csv.mts +1 -1
  45. package/core/src/plugin_system.mts +34 -3259
  46. package/core/src/plugin_system_array.mts +699 -0
  47. package/core/src/plugin_system_datetime.mts +368 -0
  48. package/core/src/plugin_system_debug.mts +403 -0
  49. package/core/src/plugin_system_dict.mts +85 -0
  50. package/core/src/plugin_system_json.mts +73 -0
  51. package/core/src/plugin_system_math.mts +383 -0
  52. package/core/src/plugin_system_regexp.mts +120 -0
  53. package/core/src/plugin_system_stdio.mts +86 -0
  54. package/core/src/plugin_system_string.mts +666 -0
  55. package/core/src/plugin_system_timer.mts +152 -0
  56. package/core/src/plugin_system_types.mts +151 -0
  57. package/core/src/plugin_system_url.mts +193 -0
  58. package/core/src/plugin_toml.mts +3 -3
  59. package/core/test/algorithm_samples_test.mjs +58 -0
  60. package/core/test/algorithms/graph/dijkstra_test.nako3 +21 -0
  61. package/core/test/algorithms/graph/kruskal_test.nako3 +21 -0
  62. package/core/test/algorithms/helper.mjs +13 -0
  63. package/core/test/algorithms/math/euclidean_gcd_test.nako3 +13 -0
  64. package/core/test/algorithms/math/sieve_of_eratosthenes_test.nako3 +10 -0
  65. package/core/test/algorithms/search/binary_search_test.nako3 +15 -0
  66. package/core/test/algorithms/search/breadth_first_search_test.nako3 +13 -0
  67. package/core/test/algorithms/search/depth_first_search_test.nako3 +13 -0
  68. package/core/test/algorithms/sort/heap_sort_test.nako3 +13 -0
  69. package/core/test/algorithms/sort/insertion_sort_test.nako3 +13 -0
  70. package/core/test/algorithms/sort/merge_sort_test.nako3 +18 -0
  71. package/core/test/algorithms/sort/quick_sort_test.nako3 +34 -0
  72. package/core/test/algorithms/string/knuth_morris_pratt_test.nako3 +16 -0
  73. package/core/test/algorithms/string/run_length_encoding_test.nako3 +13 -0
  74. package/core/test/array_test.mjs +3 -0
  75. package/core/test/fixtures/README.md +39 -0
  76. package/core/test/fixtures/make_parser_ast_golden.mjs +31 -0
  77. package/core/test/fixtures/parser_ast_golden.json +8027 -0
  78. package/core/test/fixtures/parser_corpus.mjs +120 -0
  79. package/core/test/func_call.mjs +18 -0
  80. package/core/test/func_test.mjs +28 -0
  81. package/core/test/indent_test.mjs +6 -0
  82. package/core/test/nako_basic_plugins_test.mjs +44 -0
  83. package/core/test/nako_event_test.mjs +127 -0
  84. package/core/test/nako_gen_perf_test.mjs +178 -0
  85. package/core/test/nako_parser_async_test.mjs +385 -0
  86. package/core/test/nako_parser_test.mjs +160 -0
  87. package/core/test/nako_plugin_manager_test.mjs +185 -0
  88. package/core/test/nako_require_test.mjs +153 -0
  89. package/core/test/nako_runner_test.mjs +174 -0
  90. package/core/test/nako_tokenizer_test.mjs +115 -0
  91. package/core/test/plugin_system_debug_test.mjs +138 -0
  92. package/core/test/plugin_system_split_test.mjs +179 -0
  93. package/core/test/plugin_system_test.mjs +6 -0
  94. package/core/tsconfig.json +0 -1
  95. package/demo/browsers.html +1 -1
  96. package/doc/SETUP.md +1 -1
  97. package/doc/ai-code-generation.md +136 -0
  98. package/doc/browsers.md +1 -1
  99. package/doc/command_list.json +16842 -0
  100. package/doc/search_command.md +222 -0
  101. package/doc/syntax-nako3.md +344 -0
  102. package/package.json +29 -26
  103. package/release/_hash.txt +40 -40
  104. package/release/_script-tags.txt +16 -16
  105. package/release/command.json +1 -1
  106. package/release/command.json.js +1 -1
  107. package/release/command_cnako3.json +1 -1
  108. package/release/command_list.json +1 -1
  109. package/release/edit_main.js +6 -6
  110. package/release/edit_main.js.map +3 -3
  111. package/release/editor.js +6 -6
  112. package/release/plugin_caniuse.js +1 -1
  113. package/release/plugin_caniuse.js.map +2 -2
  114. package/release/plugin_keigo.js.map +3 -3
  115. package/release/plugin_markup.js +46 -46
  116. package/release/plugin_markup.js.map +3 -3
  117. package/release/plugin_weykturtle3d.js +1 -1
  118. package/release/plugin_weykturtle3d.js.map +3 -3
  119. package/release/version.js +2 -2
  120. package/release/version_main.js +2 -2
  121. package/release/version_main.js.map +1 -1
  122. package/release/wnako3.js +219 -230
  123. package/release/wnako3.js.map +4 -4
  124. package/release/wnako3webworker.js +193 -204
  125. package/release/wnako3webworker.js.map +4 -4
  126. package/src/browsers.mjs +1 -1
  127. package/src/browsers.txt +0 -1
  128. package/src/cnako3mod.mjs +7 -2
  129. package/src/cnako3mod.mts +7 -2
  130. package/src/nako_version.mjs +2 -2
  131. package/src/nako_version.mts +2 -2
  132. package/src/plugin_browser_ajax.mjs +4 -4
  133. package/src/plugin_browser_ajax.mts +4 -4
  134. package/src/plugin_browser_audio.mjs +10 -10
  135. package/src/plugin_browser_audio.mts +10 -10
  136. package/src/plugin_browser_camera.mjs +4 -4
  137. package/src/plugin_browser_camera.mts +4 -4
  138. package/src/plugin_browser_canvas.mjs +2 -2
  139. package/src/plugin_browser_canvas.mts +2 -2
  140. package/src/plugin_browser_crypto.mjs +3 -3
  141. package/src/plugin_browser_crypto.mts +3 -3
  142. package/src/plugin_browser_dom_event.mjs +1 -1
  143. package/src/plugin_browser_dom_event.mts +1 -1
  144. package/src/plugin_browser_geolocation.mjs +1 -1
  145. package/src/plugin_browser_geolocation.mts +1 -1
  146. package/src/plugin_browser_hotkey.mjs +1 -1
  147. package/src/plugin_browser_hotkey.mts +1 -1
  148. package/src/plugin_browser_html.mjs +1 -1
  149. package/src/plugin_browser_html.mts +1 -1
  150. package/src/plugin_browser_location.mjs +1 -1
  151. package/src/plugin_browser_location.mts +1 -1
  152. package/src/plugin_browser_speech.mjs +1 -1
  153. package/src/plugin_browser_speech.mts +1 -1
  154. package/src/plugin_browser_storage.mjs +2 -2
  155. package/src/plugin_browser_storage.mts +2 -2
  156. package/src/plugin_httpserver.mjs +3 -3
  157. package/src/plugin_httpserver.mts +3 -3
  158. package/src/plugin_keigo.mjs +2 -2
  159. package/src/plugin_keigo.mts +2 -2
  160. package/src/plugin_node.mjs +48 -48
  161. package/src/plugin_node.mts +53 -53
  162. package/src/plugin_weykturtle3d.mjs +56 -56
  163. package/src/plugin_weykturtle3d.mts +56 -56
  164. package/src/wnako3.mjs +1 -1
  165. package/src/wnako3.mts +1 -1
  166. package/src/wnako3_editor.mjs +5 -5
  167. package/src/wnako3_editor.mts +5 -5
  168. package/src/wnako3mod.mjs +2 -2
  169. package/src/wnako3mod.mts +2 -2
  170. package/test/nako3edit/index_nako3_test.mjs +282 -0
  171. package/test/nako3server/index_nako3_test.mjs +239 -0
  172. package/test/node/ai_code_generation_guide_test.mjs +29 -0
  173. package/test/node/node_version_support_test.mjs +45 -0
  174. package/test/node/search_command_test.mjs +174 -0
  175. package/tools/nako3edit/AGENTS.md +23 -0
  176. package/tools/nako3edit/index.nako3 +404 -0
  177. package/tools/nako3server/AGENTS.md +23 -0
  178. package/tools/nako3server/index.nako3 +156 -23
  179. package/core/src/nako3.mjs +0 -1021
  180. package/core/src/nako_ast.mjs +0 -4
  181. package/core/src/nako_colors.mjs +0 -77
  182. package/core/src/nako_core_version.mjs +0 -8
  183. package/core/src/nako_csv.mjs +0 -193
  184. package/core/src/nako_errors.mjs +0 -166
  185. package/core/src/nako_from_dncl.mjs +0 -285
  186. package/core/src/nako_from_dncl2.mjs +0 -347
  187. package/core/src/nako_gen.mjs +0 -2500
  188. package/core/src/nako_global.mjs +0 -138
  189. package/core/src/nako_indent.mjs +0 -442
  190. package/core/src/nako_indent_chars.mjs +0 -29
  191. package/core/src/nako_indent_inline.mjs +0 -361
  192. package/core/src/nako_josi_list.mjs +0 -47
  193. package/core/src/nako_lex_rules.mjs +0 -319
  194. package/core/src/nako_lexer.mjs +0 -794
  195. package/core/src/nako_logger.mjs +0 -221
  196. package/core/src/nako_parser3.mjs +0 -3250
  197. package/core/src/nako_parser_base.mjs +0 -403
  198. package/core/src/nako_parser_const.mjs +0 -37
  199. package/core/src/nako_prepare.mjs +0 -329
  200. package/core/src/nako_reserved_words.mjs +0 -42
  201. package/core/src/nako_source_mapping.mjs +0 -207
  202. package/core/src/nako_test.mjs +0 -37
  203. package/core/src/nako_token.mjs +0 -1
  204. package/core/src/nako_tools.mjs +0 -53
  205. package/core/src/nako_types.mjs +0 -14
  206. package/core/src/plugin_api.mjs +0 -4
  207. package/core/src/plugin_csv.mjs +0 -97
  208. package/core/src/plugin_math.mjs +0 -352
  209. package/core/src/plugin_promise.mjs +0 -102
  210. package/core/src/plugin_system.mjs +0 -3810
  211. package/core/src/plugin_test.mjs +0 -52
  212. package/core/src/plugin_toml.mjs +0 -39
@@ -1,221 +0,0 @@
1
- /** NakoLogger */
2
- import { NakoError, NakoRuntimeError } from './nako_errors.mjs';
3
- import { NakoColors } from './nako_colors.mjs';
4
- /**
5
- * ログレベル - 数字が高いほど優先度が高い。
6
- */
7
- export class LogLevel {
8
- // string to level no
9
- static fromS(levelStr) {
10
- let level = LogLevel.trace;
11
- switch (levelStr) {
12
- case 'all':
13
- level = LogLevel.all;
14
- break;
15
- case 'trace':
16
- level = LogLevel.trace;
17
- break;
18
- case 'debug':
19
- level = LogLevel.debug;
20
- break;
21
- case 'info':
22
- level = LogLevel.info;
23
- break;
24
- case 'warn':
25
- level = LogLevel.warn;
26
- break;
27
- case 'error':
28
- level = LogLevel.error;
29
- break;
30
- case 'stdout':
31
- level = LogLevel.stdout;
32
- break;
33
- default:
34
- throw new Error('[NakoLogger] unknown logger level:' + levelStr);
35
- }
36
- return level;
37
- }
38
- static toString(level) {
39
- const levels = ['all', 'trace', 'debug', 'info', 'warn', 'error', 'stdout'];
40
- return levels[level];
41
- }
42
- }
43
- // level no
44
- LogLevel.all = 0;
45
- LogLevel.trace = 1;
46
- LogLevel.debug = 2;
47
- LogLevel.info = 3;
48
- LogLevel.warn = 4;
49
- LogLevel.error = 5;
50
- LogLevel.stdout = 6;
51
- /**
52
- * エラー位置を日本語で表示する。
53
- * たとえば `stringifyPosition({ file: "foo.txt", line: 5 })` は `"foo.txt(6行目):"` を出力する。
54
- */
55
- function stringifyPosition(p) {
56
- if (!p) {
57
- return '';
58
- }
59
- return `${p.file || ''}${p.line === undefined ? '' : `(${p.line + 1}行目): `}`;
60
- }
61
- export function parsePosition(line) {
62
- const m = line.match(/^l(\d+):(.+)/);
63
- let lineNo = 0;
64
- let fileName = 'main.nako3';
65
- if (m) {
66
- lineNo = parseInt(m[1], 10);
67
- fileName = m[2];
68
- }
69
- return {
70
- startOffset: 0,
71
- endOffset: 0,
72
- line: lineNo,
73
- file: fileName
74
- };
75
- }
76
- /**
77
- * コンパイラのログ情報を出力するためのクラス。
78
- * trace(), debug(), info(), warn(), error() はそれぞれメッセージに `[警告]` などのタグとエラー位置の日本語表現を付けて表示する。
79
- * error() は引数にエラーオブジェクトを受け取ることもでき、その場合エラーオブジェクトからエラーメッセージとエラー位置が取り出される。
80
- */
81
- export class NakoLogger {
82
- constructor() {
83
- this.listeners = [];
84
- this.logs = '';
85
- this.position = '';
86
- }
87
- getErrorLogs() {
88
- return [this.logs.replace(/\s+$/, ''), this.position];
89
- }
90
- clear() {
91
- this.logs = '';
92
- this.position = '';
93
- }
94
- /**
95
- * sendメソッドで送られた情報を受け取るコールバックを設定する。
96
- * @param levelStr
97
- * @param callback
98
- */
99
- addListener(levelStr, callback) {
100
- const level = LogLevel.fromS(levelStr);
101
- this.listeners.push({ level, callback });
102
- }
103
- /**
104
- * addListenerメソッドで設定したコールバックを取り外す。
105
- * @param {LogListener} callback
106
- */
107
- removeListener(callback) {
108
- this.listeners = this.listeners.filter((l) => l.callback !== callback);
109
- }
110
- /** 本体開発時のデバッグ情報(debugより更に詳細な情報)
111
- * @param {string} message
112
- * @param {Position | null} position
113
- */
114
- trace(message, position = null) {
115
- this.sendI(LogLevel.trace, `${NakoColors.color.bold}[デバッグ情報(詳細)]${NakoColors.color.reset}${stringifyPosition(position)}${message}`, position);
116
- }
117
- /** 本体開発時のデバッグ情報
118
- * @param {string} message
119
- * @param {Position | null} position
120
- */
121
- debug(message, position = null) {
122
- this.sendI(LogLevel.debug, `${NakoColors.color.bold}[デバッグ情報]${NakoColors.color.reset}${stringifyPosition(position)}${message}`, position);
123
- }
124
- /** ユーザープログラムのデバッグ情報(あまり重要ではないもの)
125
- * @param {string} message
126
- * @param {Position | null} position
127
- */
128
- info(message, position = null) {
129
- this.sendI(LogLevel.info, `${NakoColors.color.bold}${NakoColors.color.blue}[情報]${NakoColors.color.reset}${stringifyPosition(position)}${message}`, position);
130
- }
131
- /** ユーザープログラムのデバッグ情報(重要なもの)
132
- * @param {string} message
133
- * @param {Position | null} position
134
- */
135
- warn(message, position = null) {
136
- this.sendI(LogLevel.warn, `${NakoColors.color.bold}${NakoColors.color.green}[警告]${NakoColors.color.reset}${stringifyPosition(position)}${message}`, position);
137
- }
138
- /** エラーメッセージ
139
- * @param {string | Error} message
140
- * @param {Position | null} position
141
- */
142
- error(message, position = null) {
143
- // NakoErrorか判定 (`message instanceof NakoError`では判定できない場合がある)
144
- if (message instanceof Error && typeof message.type === 'string') {
145
- // NakoErrorか
146
- const etype = message.type;
147
- switch (etype) {
148
- case 'NakoRuntimeError':
149
- case 'NakoError':
150
- if (message instanceof NakoError) {
151
- const e = message;
152
- let pos = position;
153
- if (pos === null || pos === undefined) {
154
- pos = { file: e.file, line: e.line || 0, startOffset: 0, endOffset: 0 };
155
- }
156
- this.sendI(LogLevel.error, e.message, pos);
157
- return;
158
- }
159
- }
160
- }
161
- if (message instanceof Error) {
162
- // 一般のエラーの場合は、messageのみ取得できる。
163
- message = message.message;
164
- }
165
- this.sendI(LogLevel.error, `${NakoColors.color.bold}${NakoColors.color.red}[エラー]${NakoColors.color.reset}${stringifyPosition(position)}${message}`, position);
166
- }
167
- /** RuntimeErrorを生成する */
168
- runtimeError(error, posStr) {
169
- const e = new NakoRuntimeError(error, posStr);
170
- return e;
171
- }
172
- /** ユーザープログラムのデバッグ情報(すべて)
173
- * @param {string} message
174
- * @param {Position | null} position
175
- */
176
- stdout(message, position = null) {
177
- this.sendI(LogLevel.stdout, `${message}`, position);
178
- }
179
- /** 指定したlevelのlistenerにメッセージを送る。htmlやbrowserConsoleは無ければnodeConsoleから生成する。 */
180
- send(levelStr, nodeConsole, position, html = null, browserConsole = null) {
181
- const i = LogLevel.fromS(levelStr);
182
- this.sendI(i, nodeConsole, position, html, browserConsole);
183
- }
184
- /** 指定したlevelのlistenerにメッセージを送る。htmlやbrowserConsoleは無ければnodeConsoleから生成する。 */
185
- sendI(level, nodeConsole, position, html = null, browserConsole = null) {
186
- const makeData = () => {
187
- // nodeConsoleからnoColor, nodeCondoleなどの形式を生成する。
188
- const formats = NakoColors.convertColorTextFormat(nodeConsole);
189
- // ログが複数行から構成される場合は、htmlでの表現にborderを設定する。
190
- let style = '';
191
- if (nodeConsole.includes('\n')) {
192
- style += 'border-top: 1px solid #8080806b; border-bottom: 1px solid #8080806b;';
193
- }
194
- // 各イベントリスナーが受け取るデータ
195
- const data = {
196
- noColor: formats.noColor,
197
- nodeConsole: formats.nodeConsole,
198
- browserConsole: browserConsole || formats.browserConsole,
199
- html: `<div style="${style}">` + (html || formats.html) + '</div>', // 各行を style: block で表示するために、<div>で囲む。
200
- level: LogLevel.toString(level),
201
- position
202
- };
203
- return data;
204
- };
205
- // エラーならログに追加
206
- if (level === LogLevel.error) {
207
- const data = makeData();
208
- this.logs += data.noColor + '\n';
209
- if (position && this.position !== null) {
210
- this.position = `l${position.line}:${position.file || 'unknown'}`;
211
- }
212
- }
213
- // 登録したリスナーに通知する
214
- for (const l of this.listeners) {
215
- if (l.level <= level) {
216
- const data = makeData();
217
- l.callback(data);
218
- }
219
- }
220
- }
221
- }