nadesiko3 3.2.52 → 3.3.3
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/bin/cnako3 +1 -1
- package/bin/cnako3.bat +1 -1
- package/demo/browsers.html +9 -10
- package/demo/flow.html +1 -0
- package/demo/runscript3.html +35 -0
- package/demo/turtle3.html +18 -17
- package/demo/turtle3d.html +1 -1
- package/demo/turtle3d2.html +1 -1
- package/doc/browsers.md +9 -10
- package/package.json +58 -57
- package/release/_hash.txt +57 -52
- package/release/_script-tags.txt +14 -13
- package/release/command.json +1 -1
- package/release/command.json.js +1 -1
- package/release/command_cnako3.json +1 -1
- package/release/command_list.json +1 -1
- package/release/editor.js +1 -1
- package/release/editor.js.LICENSE.txt +9 -12
- package/release/nako_gen_async.js +1 -1
- package/release/nako_gen_async.js.LICENSE.txt +10 -666
- package/release/plugin_caniuse.js +1 -1
- package/release/plugin_caniuse.js.LICENSE.txt +9 -425
- package/release/plugin_csv.js +1 -1
- package/release/plugin_csv.js.LICENSE.txt +3 -419
- package/release/plugin_datetime.js +1 -1
- package/release/plugin_datetime.js.LICENSE.txt +6 -530
- package/release/plugin_kansuji.js +1 -1
- package/release/plugin_kansuji.js.LICENSE.txt +3 -559
- package/release/plugin_markup.js +1 -1
- package/release/plugin_markup.js.LICENSE.txt +4 -420
- package/release/plugin_turtle.js +1 -1
- package/release/plugin_turtle.js.LICENSE.txt +12 -500
- package/release/plugin_webworker.js +1 -1
- package/release/plugin_webworker.js.LICENSE.txt +3 -563
- package/release/plugin_weykturtle3d.js +1 -0
- package/release/plugin_weykturtle3d.js.LICENSE.txt +3 -0
- package/release/stats.json +1 -1
- package/release/version.js +1 -1
- package/release/version.js.LICENSE.txt +9 -12
- package/release/wnako3.js +1 -1
- package/release/wnako3.js.LICENSE.txt +1 -1
- package/release/wnako3webworker.js +1 -1
- package/release/wnako3webworker.js.LICENSE.txt +1 -1117
- package/src/browsers.mjs +1 -0
- package/src/browsers.txt +15 -15
- package/src/browsers_agents.mjs +1 -0
- package/src/cnako3.mjs +13 -0
- package/src/{cnako3.js → cnako3mod.mjs} +119 -101
- package/src/{commander_ja.js → commander_ja.mjs} +16 -11
- package/src/{enako3.js → enako3.mjs} +0 -0
- package/src/{era.json → era.mjs} +1 -1
- package/src/image_turtle-elephant.mjs +5 -0
- package/src/image_turtle-panda.mjs +5 -0
- package/src/image_turtle64.mjs +5 -0
- package/src/index.mjs +9 -0
- package/src/{nako3.js → nako3.mjs} +69 -57
- package/src/{nako3_assert.js → nako3_assert.mjs} +7 -6
- package/src/{nako3server.js → nako3server.mjs} +12 -5
- package/src/{nako_colors.js → nako_colors.mjs} +1 -1
- package/src/{nako_errors.js → nako_errors.mjs} +10 -20
- package/src/{nako_from_dncl.js → nako_from_dncl.mjs} +11 -8
- package/src/{nako_gen.js → nako_gen.mjs} +93 -87
- package/src/{nako_gen_async.js → nako_gen_async.mjs} +5 -8
- package/src/{nako_global.js → nako_global.mjs} +4 -5
- package/src/{nako_indent.js → nako_indent.mjs} +29 -25
- package/src/{nako_josi_list.js → nako_josi_list.mjs} +16 -14
- package/src/nako_lex_rules.mjs +244 -0
- package/src/{nako_lexer.js → nako_lexer.mjs} +7 -10
- package/src/{nako_logger.js → nako_logger.mjs} +3 -4
- package/src/{nako_parser3.js → nako_parser3.mjs} +5 -5
- package/src/{nako_parser_base.js → nako_parser_base.mjs} +1 -9
- package/src/{nako_parser_const.js → nako_parser_const.mjs} +2 -6
- package/src/{nako_prepare.js → nako_prepare.mjs} +46 -8
- package/src/{nako_reserved_words.js → nako_reserved_words.mjs} +1 -1
- package/src/{nako_source_mapping.js → nako_source_mapping.mjs} +4 -11
- package/src/{nako_test.js → nako_test.mjs} +0 -0
- package/src/nako_version.mjs +7 -0
- package/src/{plugin_browser.js → plugin_browser.mjs} +30 -30
- package/src/{plugin_browser_ajax.js → plugin_browser_ajax.mjs} +7 -7
- package/src/{plugin_browser_audio.js → plugin_browser_audio.mjs} +1 -1
- package/src/{plugin_browser_canvas.js → plugin_browser_canvas.mjs} +1 -1
- package/src/{plugin_browser_chart.js → plugin_browser_chart.mjs} +1 -1
- package/src/{plugin_browser_color.js → plugin_browser_color.mjs} +1 -1
- package/src/{plugin_browser_crypto.js → plugin_browser_crypto.mjs} +1 -1
- package/src/{plugin_browser_dialog.js → plugin_browser_dialog.mjs} +1 -1
- package/src/{plugin_browser_dom_basic.js → plugin_browser_dom_basic.mjs} +1 -1
- package/src/{plugin_browser_dom_event.js → plugin_browser_dom_event.mjs} +1 -1
- package/src/{plugin_browser_dom_parts.js → plugin_browser_dom_parts.mjs} +1 -1
- package/src/{plugin_browser_geolocation.js → plugin_browser_geolocation.mjs} +1 -1
- package/src/{plugin_browser_hotkey.js → plugin_browser_hotkey.mjs} +2 -2
- package/src/{plugin_browser_html.js → plugin_browser_html.mjs} +1 -1
- package/src/{plugin_browser_in_worker.js → plugin_browser_in_worker.mjs} +4 -4
- package/src/{plugin_browser_location.js → plugin_browser_location.mjs} +1 -1
- package/src/{plugin_browser_speech.js → plugin_browser_speech.mjs} +1 -1
- package/src/{plugin_browser_storage.js → plugin_browser_storage.mjs} +1 -1
- package/src/{plugin_browser_system.js → plugin_browser_system.mjs} +1 -1
- package/src/{plugin_browser_websocket.js → plugin_browser_websocket.mjs} +1 -1
- package/src/{plugin_caniuse.js → plugin_caniuse.mjs} +8 -3
- package/src/{plugin_csv.js → plugin_csv.mjs} +4 -5
- package/src/{plugin_datetime.js → plugin_datetime.mjs} +19 -26
- package/src/{plugin_express.js → plugin_express.mjs} +4 -3
- package/src/{plugin_kansuji.js → plugin_kansuji.mjs} +1 -1
- package/src/{plugin_keigo.js → plugin_keigo.mjs} +1 -1
- package/src/{plugin_markup.js → plugin_markup.mjs} +6 -6
- package/src/{plugin_math.js → plugin_math.mjs} +1 -4
- package/src/{plugin_node.js → plugin_node.mjs} +25 -57
- package/src/{plugin_promise.js → plugin_promise.mjs} +1 -3
- package/src/{plugin_system.js → plugin_system.mjs} +32 -15
- package/src/{plugin_test.js → plugin_test.mjs} +1 -3
- package/src/{plugin_turtle.js → plugin_turtle.mjs} +5 -4
- package/src/{plugin_webworker.js → plugin_webworker.mjs} +3 -3
- package/src/{plugin_weykturtle3d.js → plugin_weykturtle3d.mjs} +1 -3
- package/src/{plugin_worker.js → plugin_worker.mjs} +4 -1
- package/src/{wnako3.js → wnako3.mjs} +24 -14
- package/src/{wnako3_editor.js → wnako3_editor.mjs} +28 -22
- package/src/{wnako3webworker.js → wnako3webworker.mjs} +0 -0
- package/test/async/{async_basic_test.js → async_basic_test.mjs} +3 -4
- package/test/browser/karma.config.js +9 -0
- package/test/browser/test/plugin_browser_test.js +2 -2
- package/test/browser/test/plugin_turtle_test.js +2 -2
- package/test/browser/test/plugin_webworker_test.js +3 -3
- package/test/browser/test/require_test.js +2 -2
- package/test/common/{array_test.js → array_test.mjs} +3 -3
- package/test/common/{basic_test.js → basic_test.mjs} +3 -13
- package/test/common/{calc_test.js → calc_test.mjs} +2 -2
- package/test/common/{debug_test.js → debug_test.mjs} +2 -2
- package/test/common/{dncl_test.js → dncl_test.mjs} +3 -3
- package/test/common/{error_test.js → error_test.mjs} +2 -2
- package/test/common/{flow_test.js → flow_test.mjs} +2 -2
- package/test/common/{func_call.js → func_call.mjs} +3 -3
- package/test/common/{func_test.js → func_test.mjs} +2 -2
- package/test/common/{indent_test.js → indent_test.mjs} +3 -2
- package/test/common/{lex_test.js → lex_test.mjs} +2 -2
- package/test/common/{literal_test.js → literal_test.mjs} +3 -2
- package/test/common/{nako_logger_test.js → nako_logger_test.mjs} +3 -3
- package/test/common/{plugin_browser_test.js → plugin_browser_test.mjs} +4 -4
- package/test/common/{plugin_browser_ut_audio_test.js → plugin_browser_ut_audio_test.mjs} +4 -4
- package/test/common/{plugin_browser_ut_color_test.js → plugin_browser_ut_color_test.mjs} +2 -2
- package/test/common/{plugin_browser_ut_dialog_test.js → plugin_browser_ut_dialog_test.mjs} +3 -3
- package/test/common/{plugin_browser_ut_html_test.js → plugin_browser_ut_html_test.mjs} +2 -2
- package/test/common/{plugin_browser_ut_system_test.js → plugin_browser_ut_system_test.mjs} +2 -2
- package/test/common/{plugin_csv_test.js → plugin_csv_test.mjs} +3 -3
- package/test/common/{plugin_datetime_test.js → plugin_datetime_test.mjs} +4 -4
- package/test/common/{plugin_kansuji_test.js → plugin_kansuji_test.mjs} +3 -3
- package/test/common/{plugin_markup_test.js → plugin_markup_test.mjs} +3 -3
- package/test/common/{plugin_promise_test.js → plugin_promise_test.mjs} +2 -2
- package/test/common/{plugin_system_test.js → plugin_system_test.mjs} +2 -2
- package/test/common/{prepare_test.js → prepare_test.mjs} +2 -2
- package/test/common/{re_test.js → re_test.mjs} +2 -2
- package/test/common/{variable_scope_test.js → variable_scope_test.mjs} +2 -2
- package/test/karma.config.js +3 -3
- package/test/node/{async_test.js → async_test.mjs} +4 -2
- package/test/node/{commander_ja_test.js → commander_ja_test.mjs} +17 -12
- package/test/node/{error_message_test.js → error_message_test.mjs} +13 -10
- package/test/node/node_test.mjs +57 -0
- package/test/node/{plugin_browser_ut_ajax_test.js → plugin_browser_ut_ajax_test.mjs} +7 -5
- package/test/node/{plugin_browser_ut_location_test.js → plugin_browser_ut_location_test.mjs} +3 -3
- package/test/node/{plugin_markup_test.js → plugin_markup_test.mjs} +6 -7
- package/test/node/{plugin_math_test.js → plugin_math_test.mjs} +5 -5
- package/test/node/{plugin_node_test.js → plugin_node_test.mjs} +11 -7
- package/test/node/{plugin_test.js → plugin_test.mjs} +11 -5
- package/test/node/{require_nako3_test.js → require_nako3_test.mjs} +19 -12
- package/test/node/{side_effects_test.js → side_effects_test.mjs} +24 -13
- package/test/node/{wnako3_editor_test.js → wnako3_editor_test.mjs} +16 -9
- package/tools/nako3edit/html/daisyui/LICENSE +22 -0
- package/tools/nako3edit/html/daisyui/full.css +1 -0
- package/tools/nako3edit/html/daisyui/tailwind.min.css +1 -0
- package/tools/nako3edit/html/daisyui/version_2.14.1 +1 -0
- package/tools/nako3edit/html/edit.html +104 -19
- package/tools/nako3edit/html/files.html +84 -8
- package/tools/nako3edit/html/nako3edit.css +6 -7
- package/tools/nako3edit/index.nako3 +45 -6
- package/tools/nako3edit/{run.js → run.mjs} +8 -2
- package/src/index.js +0 -5
- package/src/nako_lex_rules.js +0 -260
- package/src/nako_version.js +0 -8
- package/test/node/node_test.js +0 -43
|
@@ -2,41 +2,25 @@
|
|
|
2
2
|
/**
|
|
3
3
|
* nadesiko v3
|
|
4
4
|
*/
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
5
|
+
import { NakoParser } from './nako_parser3.mjs'
|
|
6
|
+
import { NakoLexer } from './nako_lexer.mjs'
|
|
7
|
+
import { NakoPrepare } from './nako_prepare.mjs'
|
|
8
|
+
import { NakoGen, generateJS } from './nako_gen.mjs'
|
|
9
|
+
import { NakoGenASync } from './nako_gen_async.mjs'
|
|
10
|
+
import NakoIndent from './nako_indent.mjs'
|
|
11
|
+
import { convertDNCL } from './nako_from_dncl.mjs'
|
|
12
|
+
import PluginSystem from './plugin_system.mjs'
|
|
13
|
+
import PluginMath from './plugin_math.mjs'
|
|
14
|
+
import PluginPromise from './plugin_promise.mjs'
|
|
15
|
+
import PluginTest from './plugin_test.mjs'
|
|
16
|
+
import { SourceMappingOfTokenization, SourceMappingOfIndentSyntax, OffsetToLineColumn, subtractSourceMapByPreCodeLength } from './nako_source_mapping.mjs'
|
|
17
|
+
import { NakoRuntimeError, NakoLexerError, NakoImportError, NakoSyntaxError, InternalLexerError } from './nako_errors.mjs'
|
|
18
|
+
import { NakoLogger } from './nako_logger.mjs'
|
|
19
|
+
import { NakoGlobal } from './nako_global.mjs'
|
|
19
20
|
|
|
20
21
|
/** @type {<T>(x: T) => T} */
|
|
21
22
|
const cloneAsJSON = (x) => JSON.parse(JSON.stringify(x))
|
|
22
23
|
|
|
23
|
-
// Select Code Generator #637
|
|
24
|
-
/**
|
|
25
|
-
* @type {Object}
|
|
26
|
-
*/
|
|
27
|
-
const codeGenerators = {
|
|
28
|
-
// [key: String]
|
|
29
|
-
sync: NakoGenSync
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
/**
|
|
33
|
-
* @param {String | undefined} mode
|
|
34
|
-
*/
|
|
35
|
-
function NakoGen (mode) {
|
|
36
|
-
if (codeGenerators[mode]) { return codeGenerators[mode] }
|
|
37
|
-
throw new Error(`コードジェネレータの「${mode}」はサポートされていません。`)
|
|
38
|
-
}
|
|
39
|
-
|
|
40
24
|
/**
|
|
41
25
|
* @typedef {{
|
|
42
26
|
* type: string
|
|
@@ -93,7 +77,7 @@ function NakoGen (mode) {
|
|
|
93
77
|
* } NakoFunction
|
|
94
78
|
*/
|
|
95
79
|
|
|
96
|
-
class NakoCompiler {
|
|
80
|
+
export class NakoCompiler {
|
|
97
81
|
/**
|
|
98
82
|
* @param {undefined | {'useBasicPlugin':true|false}} options
|
|
99
83
|
*/
|
|
@@ -129,8 +113,8 @@ class NakoCompiler {
|
|
|
129
113
|
this.logger = new NakoLogger()
|
|
130
114
|
|
|
131
115
|
// 必要なオブジェクトを覚えておく
|
|
132
|
-
this.prepare =
|
|
133
|
-
this.parser = new
|
|
116
|
+
this.prepare = NakoPrepare.getInstance(this.logger)
|
|
117
|
+
this.parser = new NakoParser(this.logger)
|
|
134
118
|
this.lexer = new NakoLexer(this.logger)
|
|
135
119
|
|
|
136
120
|
/**
|
|
@@ -217,7 +201,12 @@ class NakoCompiler {
|
|
|
217
201
|
const inner = (code, filename, preCode) => {
|
|
218
202
|
/** @type {Promise<unknown>[]} */
|
|
219
203
|
const tasks = []
|
|
220
|
-
|
|
204
|
+
// 取り込みが必要な情報一覧を調べる(トークン分割して、取り込みタグを得る)
|
|
205
|
+
const tags = NakoCompiler.listRequireStatements(compiler.rawtokenize(code, 0, filename, preCode))
|
|
206
|
+
// パスを解決する
|
|
207
|
+
const tagsResolvePath = tags.map((v) => ({ ...v, ...tools.resolvePath(v.value, v.firstToken) }))
|
|
208
|
+
// 取り込み開始
|
|
209
|
+
for (const item of tagsResolvePath) {
|
|
221
210
|
// 2回目以降の読み込み
|
|
222
211
|
// eslint-disable-next-line no-prototype-builtins
|
|
223
212
|
if (dependencies.hasOwnProperty(item.filePath)) {
|
|
@@ -227,14 +216,18 @@ class NakoCompiler {
|
|
|
227
216
|
|
|
228
217
|
// 初回の読み込み
|
|
229
218
|
dependencies[item.filePath] = { tokens: [], alias: new Set([item.value]), addPluginFile: () => {}, funclist: {} }
|
|
230
|
-
if (item.type === 'js') {
|
|
219
|
+
if (item.type === 'js' || item.type === 'mjs') {
|
|
231
220
|
// jsならプラグインとして読み込む。
|
|
232
221
|
const obj = tools.readJs(item.filePath, item.firstToken)
|
|
233
222
|
if (obj.sync) {
|
|
234
|
-
dependencies[item.filePath].addPluginFile = () => {
|
|
223
|
+
dependencies[item.filePath].addPluginFile = () => {
|
|
224
|
+
this.addPluginFile(item.value, item.filePath, dependencies[item.filePath].funclist = obj.value(), false)
|
|
225
|
+
}
|
|
235
226
|
} else {
|
|
236
227
|
tasks.push(obj.value.then((res) => {
|
|
237
|
-
dependencies[item.filePath].addPluginFile = () => {
|
|
228
|
+
dependencies[item.filePath].addPluginFile = () => {
|
|
229
|
+
this.addPluginFile(item.value, item.filePath, dependencies[item.filePath].funclist = res(), false)
|
|
230
|
+
}
|
|
238
231
|
}))
|
|
239
232
|
}
|
|
240
233
|
} else if (item.type === 'nako3') {
|
|
@@ -245,7 +238,7 @@ class NakoCompiler {
|
|
|
245
238
|
// シンタックスハイライトの高速化のために、事前にファイルが定義する関数名のリストを取り出しておく。
|
|
246
239
|
// preDefineFuncはトークン列に変更を加えるため、事前にクローンしておく。
|
|
247
240
|
// 「プラグイン名設定」を行う (#956)
|
|
248
|
-
code =
|
|
241
|
+
code = `『${item.filePath}』にプラグイン名設定;` + code + ';『メイン』にプラグイン名設定;'
|
|
249
242
|
const tokens = this.rawtokenize(code, 0, item.filePath)
|
|
250
243
|
dependencies[item.filePath].tokens = tokens
|
|
251
244
|
/** @type {import('./nako_lexer').FuncList} */
|
|
@@ -262,7 +255,7 @@ class NakoCompiler {
|
|
|
262
255
|
tasks.push(content.value.then((res) => registerFile(res)))
|
|
263
256
|
}
|
|
264
257
|
} else {
|
|
265
|
-
throw new NakoImportError(
|
|
258
|
+
throw new NakoImportError(`ファイル『${item.value}』を読み込めません。ファイルが存在しないか未対応の拡張子です。`, item.firstToken.file, item.firstToken.line)
|
|
266
259
|
}
|
|
267
260
|
}
|
|
268
261
|
|
|
@@ -276,15 +269,20 @@ class NakoCompiler {
|
|
|
276
269
|
|
|
277
270
|
// 非同期な場合のエラーハンドリング
|
|
278
271
|
if (result !== undefined) {
|
|
279
|
-
result.catch((err) => {
|
|
272
|
+
result.catch((err) => {
|
|
273
|
+
// 読み込みに失敗しても処理は続ける方針なので、失敗しても例外は投げない
|
|
274
|
+
// たぶん、その後の構文解析でエラーになるため
|
|
275
|
+
this.logger.warn(err.msg)
|
|
276
|
+
})
|
|
280
277
|
}
|
|
281
278
|
|
|
282
279
|
// すべてが終わってからthis.dependenciesに代入する。そうしないと、「実行」ボタンを連打した場合など、
|
|
283
280
|
// loadDependencies() が並列実行されるときに正しく動作しない。
|
|
284
281
|
this.dependencies = dependencies
|
|
285
282
|
return result
|
|
286
|
-
} catch (err) {
|
|
287
|
-
|
|
283
|
+
} catch (err) {
|
|
284
|
+
// 同期処理では素直に例外を投げる
|
|
285
|
+
this.logger.warn(err.msg)
|
|
288
286
|
throw err
|
|
289
287
|
}
|
|
290
288
|
}
|
|
@@ -304,7 +302,7 @@ class NakoCompiler {
|
|
|
304
302
|
// インデント構文 (#596)
|
|
305
303
|
const { code: code2, insertedLines, deletedLines } = NakoIndent.convert(code, filename)
|
|
306
304
|
// DNCL構文 (#1140)
|
|
307
|
-
const code3 =
|
|
305
|
+
const code3 = convertDNCL(code2, filename)
|
|
308
306
|
|
|
309
307
|
// 全角半角の統一処理
|
|
310
308
|
const preprocessed = this.prepare.convert(code3)
|
|
@@ -606,7 +604,7 @@ class NakoCompiler {
|
|
|
606
604
|
}
|
|
607
605
|
|
|
608
606
|
/**
|
|
609
|
-
*
|
|
607
|
+
* プログラムをコンパイルしてランタイム用のJavaScriptのコードを返す
|
|
610
608
|
* @param {string} code コード (なでしこ)
|
|
611
609
|
* @param {string} filename
|
|
612
610
|
* @param {boolean | string} isTest テストかどうか。stringの場合は1つのテストのみ。
|
|
@@ -614,7 +612,29 @@ class NakoCompiler {
|
|
|
614
612
|
*/
|
|
615
613
|
compile (code, filename, isTest, preCode = '') {
|
|
616
614
|
const ast = this.parse(code, filename, preCode)
|
|
617
|
-
|
|
615
|
+
const codeObj = this.generateCode(ast, isTest, preCode)
|
|
616
|
+
return codeObj.runtimeEnv
|
|
617
|
+
}
|
|
618
|
+
|
|
619
|
+
/**
|
|
620
|
+
* プログラムをコンパイルしてJavaScriptのコードオブジェクトを返す
|
|
621
|
+
* @param {AST} ast
|
|
622
|
+
* @param {boolean | string} isTest テストかどうか。stringの場合は1つのテストのみ。
|
|
623
|
+
* @param {string} [preCode]
|
|
624
|
+
* @return {Object}
|
|
625
|
+
*/
|
|
626
|
+
generateCode (ast, isTest, preCode = '') {
|
|
627
|
+
// Select Code Generator #637
|
|
628
|
+
switch (ast.genMode) {
|
|
629
|
+
// ノーマルモード
|
|
630
|
+
case 'sync':
|
|
631
|
+
return generateJS(this, ast, isTest)
|
|
632
|
+
// 『!非同期モード』は緩やかに非推奨にする
|
|
633
|
+
case '非同期モード':
|
|
634
|
+
return NakoGenASync.generate(this, ast, isTest)
|
|
635
|
+
default:
|
|
636
|
+
throw new Error(`コードジェネレータの「${ast.genMode}」はサポートされていません。`)
|
|
637
|
+
}
|
|
618
638
|
}
|
|
619
639
|
|
|
620
640
|
/**
|
|
@@ -654,7 +674,7 @@ class NakoCompiler {
|
|
|
654
674
|
if (optsAll.resetEnv) { this.reset() }
|
|
655
675
|
if (optsAll.resetAll) { this.clearPlugins() }
|
|
656
676
|
const ast = this.parse(code, fname, preCode)
|
|
657
|
-
out =
|
|
677
|
+
out = this.generateCode(ast, optsAll.testOnly)
|
|
658
678
|
} catch (e) {
|
|
659
679
|
this.logger.error(e)
|
|
660
680
|
throw e
|
|
@@ -727,7 +747,7 @@ class NakoCompiler {
|
|
|
727
747
|
*/
|
|
728
748
|
compileStandalone (code, filename, isTest, preCode = '') {
|
|
729
749
|
const ast = this.parse(code, filename, preCode)
|
|
730
|
-
return
|
|
750
|
+
return this.generateCode(ast, isTest).standalone
|
|
731
751
|
}
|
|
732
752
|
|
|
733
753
|
/**
|
|
@@ -755,6 +775,7 @@ class NakoCompiler {
|
|
|
755
775
|
readonly: (v.type === 'const')
|
|
756
776
|
}
|
|
757
777
|
} else {
|
|
778
|
+
console.error('[プラグイン追加エラー]', v)
|
|
758
779
|
throw new Error('プラグインの追加でエラー。')
|
|
759
780
|
}
|
|
760
781
|
// コマンドを登録するか?
|
|
@@ -829,14 +850,5 @@ class NakoCompiler {
|
|
|
829
850
|
return this.funclist[key]
|
|
830
851
|
}
|
|
831
852
|
|
|
832
|
-
/**
|
|
833
|
-
* コードジェネレータを追加する
|
|
834
|
-
* @param {string} mode
|
|
835
|
-
* @param {any} obj
|
|
836
|
-
*/
|
|
837
|
-
addCodeGenerator (mode, obj) {
|
|
838
|
-
codeGenerators[mode] = obj
|
|
839
|
-
}
|
|
840
853
|
}
|
|
841
854
|
|
|
842
|
-
module.exports = NakoCompiler
|
|
@@ -2,9 +2,10 @@
|
|
|
2
2
|
/**
|
|
3
3
|
* Assert対応のなでしこ
|
|
4
4
|
*/
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
5
|
+
|
|
6
|
+
import assert from 'assert'
|
|
7
|
+
import { NakoCompiler } from './nako3.mjs'
|
|
8
|
+
|
|
8
9
|
|
|
9
10
|
const PluginAssert = {
|
|
10
11
|
'初期化': {
|
|
@@ -25,13 +26,13 @@ const PluginAssert = {
|
|
|
25
26
|
}
|
|
26
27
|
}
|
|
27
28
|
|
|
28
|
-
class Nako3Assert extends NakoCompiler {
|
|
29
|
+
export class Nako3Assert extends NakoCompiler {
|
|
29
30
|
constructor () {
|
|
30
31
|
super()
|
|
31
32
|
this.silent = true
|
|
32
|
-
this.addPluginFile('PluginAssert',
|
|
33
|
+
this.addPluginFile('PluginAssert', 'nako3_assert.js', PluginAssert)
|
|
33
34
|
this.__varslist[0]['ナデシコ種類'] = 'nako3_assert'
|
|
34
35
|
}
|
|
35
36
|
}
|
|
36
37
|
|
|
37
|
-
|
|
38
|
+
|
|
@@ -1,19 +1,27 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
/** なでしこ3簡易EXPRESSサーバー */
|
|
3
3
|
|
|
4
|
-
|
|
4
|
+
import express from 'express'
|
|
5
|
+
import path from 'path'
|
|
6
|
+
import fs from 'fs'
|
|
7
|
+
import { execSync } from 'child_process'
|
|
8
|
+
import opener from 'opener'
|
|
9
|
+
|
|
10
|
+
// __dirname のために
|
|
11
|
+
import url from 'url'
|
|
12
|
+
const __filename = url.fileURLToPath(import.meta.url);
|
|
13
|
+
const __dirname = path.dirname(__filename);
|
|
14
|
+
|
|
15
|
+
|
|
5
16
|
const app = express()
|
|
6
17
|
|
|
7
18
|
// set static
|
|
8
|
-
const path = require('path')
|
|
9
19
|
const rootDir = path.resolve(path.join(__dirname, '../'))
|
|
10
20
|
app.use(express.static(rootDir))
|
|
11
21
|
console.log('documentRoot:', rootDir)
|
|
12
22
|
|
|
13
23
|
// ライブラリがあるかチェック
|
|
14
|
-
const fs = require('fs')
|
|
15
24
|
if (!fs.existsSync(path.resolve(rootDir, 'extlib/pure.min.css'))) {
|
|
16
|
-
const execSync = require('child_process').execSync;
|
|
17
25
|
execSync('npm run extlib:install')
|
|
18
26
|
}
|
|
19
27
|
|
|
@@ -26,7 +34,6 @@ app.get('/', function (req, res) {
|
|
|
26
34
|
let port = 3000
|
|
27
35
|
let server = null
|
|
28
36
|
const callbackStart = () => {
|
|
29
|
-
const opener = require('opener')
|
|
30
37
|
const port = server.address().port
|
|
31
38
|
console.log('+ サーバーを開始しました')
|
|
32
39
|
console.log('+ [URL] http://localhost:%s', port)
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
|
|
1
|
+
import nakoVersion from './nako_version.mjs'
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* なでしこ言語が投げる全てのエラーが継承するクラス
|
|
5
5
|
*/
|
|
6
|
-
class NakoError extends Error {
|
|
6
|
+
export class NakoError extends Error {
|
|
7
7
|
/**
|
|
8
8
|
* @param {string} tag
|
|
9
9
|
* @param {string} msg
|
|
@@ -19,7 +19,7 @@ class NakoError extends Error {
|
|
|
19
19
|
}
|
|
20
20
|
}
|
|
21
21
|
|
|
22
|
-
class NakoIndentError extends NakoError {
|
|
22
|
+
export class NakoIndentError extends NakoError {
|
|
23
23
|
/**
|
|
24
24
|
* @param {string} msg
|
|
25
25
|
* @param {number} line
|
|
@@ -33,7 +33,7 @@ class NakoIndentError extends NakoError {
|
|
|
33
33
|
}
|
|
34
34
|
|
|
35
35
|
// コンパイラの内部でのみ使うエラー。投げられたらtryでキャッチしてLexerErrorへ変更する。
|
|
36
|
-
class InternalLexerError extends NakoError {
|
|
36
|
+
export class InternalLexerError extends NakoError {
|
|
37
37
|
/**
|
|
38
38
|
* @param {string} msg
|
|
39
39
|
* @param {number} preprocessedCodeStartOffset
|
|
@@ -50,7 +50,7 @@ class InternalLexerError extends NakoError {
|
|
|
50
50
|
}
|
|
51
51
|
}
|
|
52
52
|
|
|
53
|
-
class NakoLexerError extends NakoError {
|
|
53
|
+
export class NakoLexerError extends NakoError {
|
|
54
54
|
/**
|
|
55
55
|
* @param {string} msg
|
|
56
56
|
* @param {number | null} startOffset
|
|
@@ -73,7 +73,7 @@ class NakoLexerError extends NakoError {
|
|
|
73
73
|
}
|
|
74
74
|
}
|
|
75
75
|
|
|
76
|
-
class NakoSyntaxError extends NakoError {
|
|
76
|
+
export class NakoSyntaxError extends NakoError {
|
|
77
77
|
/**
|
|
78
78
|
* @param {string} msg
|
|
79
79
|
* @param {import("./nako3").Ast | null | undefined} first
|
|
@@ -107,7 +107,7 @@ class NakoSyntaxError extends NakoError {
|
|
|
107
107
|
}
|
|
108
108
|
}
|
|
109
109
|
|
|
110
|
-
class NakoRuntimeError extends NakoError {
|
|
110
|
+
export class NakoRuntimeError extends NakoError {
|
|
111
111
|
/**
|
|
112
112
|
* @param {Error | string} error エラー
|
|
113
113
|
* @param {string | undefined} lineNo 発生行
|
|
@@ -152,25 +152,15 @@ class NakoRuntimeError extends NakoError {
|
|
|
152
152
|
}
|
|
153
153
|
}
|
|
154
154
|
|
|
155
|
-
class NakoImportError extends NakoError {
|
|
155
|
+
export class NakoImportError extends NakoError {
|
|
156
156
|
/**
|
|
157
157
|
* @param {string} msg
|
|
158
|
-
* @param {number} line
|
|
159
158
|
* @param {string} file
|
|
159
|
+
* @param {number} line
|
|
160
160
|
*/
|
|
161
|
-
constructor (msg,
|
|
161
|
+
constructor (msg, file, line) {
|
|
162
162
|
super('取り込みエラー', msg, file, line)
|
|
163
163
|
this.file = file
|
|
164
164
|
this.line = line
|
|
165
165
|
}
|
|
166
166
|
}
|
|
167
|
-
|
|
168
|
-
module.exports = {
|
|
169
|
-
NakoError,
|
|
170
|
-
NakoIndentError,
|
|
171
|
-
NakoLexerError,
|
|
172
|
-
InternalLexerError,
|
|
173
|
-
NakoSyntaxError,
|
|
174
|
-
NakoRuntimeError,
|
|
175
|
-
NakoImportError
|
|
176
|
-
}
|
|
@@ -1,21 +1,23 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* DNCLに対応する構文
|
|
3
3
|
*/
|
|
4
|
-
|
|
5
|
-
|
|
4
|
+
// import { NakoIndentError } from './nako_errors.mjs'
|
|
5
|
+
import { NakoPrepare, checkNakoMode } from './nako_prepare.mjs'
|
|
6
6
|
|
|
7
|
+
// DNCLモードのキーワード
|
|
7
8
|
const DNCL_KEYWORDS = ['!DNCLモード']
|
|
9
|
+
|
|
8
10
|
/**
|
|
9
11
|
* DNCLのソースコードをなでしこに変換する
|
|
10
12
|
* @param {String} src
|
|
11
13
|
* @param {String} filename
|
|
12
14
|
* @returns {String} converted soruce
|
|
13
15
|
*/
|
|
14
|
-
function
|
|
16
|
+
export function convertDNCL(src, filename) {
|
|
15
17
|
// 改行を合わせる
|
|
16
18
|
src = src.replace(/(\r\n|\r)/g, '\n')
|
|
17
19
|
// 「!DNCLモード」を使うかチェック
|
|
18
|
-
if (!
|
|
20
|
+
if (!checkNakoMode(src, DNCL_KEYWORDS)) { return src }
|
|
19
21
|
let result = dncl2nako(src, filename)
|
|
20
22
|
// console.log("=====\n" + result)
|
|
21
23
|
// process.exit()
|
|
@@ -217,7 +219,7 @@ function dncl2nako(src, filename) {
|
|
|
217
219
|
* @returns {string} converted source
|
|
218
220
|
*/
|
|
219
221
|
function conv2half(src) {
|
|
220
|
-
const prepare =
|
|
222
|
+
const prepare = NakoPrepare.getInstance(null) // `※`, `//`, `/*` といったパターン全てに対応するために必要
|
|
221
223
|
// 全角半角の統一
|
|
222
224
|
let result = ''
|
|
223
225
|
let flagStr = false
|
|
@@ -258,7 +260,8 @@ function conv2half(src) {
|
|
|
258
260
|
return result
|
|
259
261
|
}
|
|
260
262
|
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
convert
|
|
263
|
+
/** @type {Object} */
|
|
264
|
+
export const NakoDncl = {
|
|
265
|
+
convert: convertDNCL
|
|
264
266
|
}
|
|
267
|
+
|
|
@@ -4,10 +4,8 @@
|
|
|
4
4
|
* なお速度優先で忠実にJavaScriptのコードを生成する。
|
|
5
5
|
*/
|
|
6
6
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
const { NakoSyntaxError, NakoError, NakoRuntimeError } = require('./nako_errors')
|
|
10
|
-
const nakoVersion = require('./nako_version')
|
|
7
|
+
import { NakoSyntaxError, NakoError, NakoRuntimeError } from './nako_errors.mjs'
|
|
8
|
+
import nakoVersion from './nako_version.mjs'
|
|
11
9
|
const isIE11 = () => {
|
|
12
10
|
if (typeof(window) == 'object' && window.navigator && window.navigator.userAgent) {
|
|
13
11
|
return (window.navigator.userAgent.indexOf('MSIE') >= 0)
|
|
@@ -26,88 +24,7 @@ const topOfFunctionAsync = '(async function(){\n'
|
|
|
26
24
|
/**
|
|
27
25
|
* 構文木からJSのコードを生成するクラス
|
|
28
26
|
*/
|
|
29
|
-
class NakoGen {
|
|
30
|
-
/**
|
|
31
|
-
* @param {import('./nako3')} com
|
|
32
|
-
* @param {Ast} ast
|
|
33
|
-
* @param {boolean | string} isTest 文字列なら1つのテストだけを実行する
|
|
34
|
-
*/
|
|
35
|
-
static generate (com, ast, isTest) {
|
|
36
|
-
const gen = new NakoGen(com)
|
|
37
|
-
|
|
38
|
-
// ※ [関数定義に関するコード生成のヒント]
|
|
39
|
-
// ※ 関数の名前だけを(1)で登録して、(2)で実際に関数のコードを生成する。
|
|
40
|
-
// ※ ただし(2)では生成するだけなので、(3)でプログラム冒頭に関数定義のコードを記述する。
|
|
41
|
-
// この順番を変えることはできない (グローバル変数が認識できなくなったり、関数定義のタイミングがずれる)
|
|
42
|
-
|
|
43
|
-
// (1) ユーザー定義関数をシステムに登録する
|
|
44
|
-
gen.registerFunction(ast)
|
|
45
|
-
|
|
46
|
-
// (2) JSコードを生成する
|
|
47
|
-
let js = gen.convGen(ast, !!isTest)
|
|
48
|
-
|
|
49
|
-
// (3) JSコードを実行するための事前ヘッダ部分の生成
|
|
50
|
-
js = gen.getDefFuncCode(isTest) + js
|
|
51
|
-
|
|
52
|
-
// テストの実行
|
|
53
|
-
if (js && isTest) {
|
|
54
|
-
js += '\n__self._runTests(__tests);\n'
|
|
55
|
-
}
|
|
56
|
-
// async method
|
|
57
|
-
if (gen.numAsyncFn > 0) {
|
|
58
|
-
let canAsync = !isIE11()
|
|
59
|
-
if (canAsync) {
|
|
60
|
-
js = `
|
|
61
|
-
// <nadesiko3::gen::async>
|
|
62
|
-
(async () => { // async::main
|
|
63
|
-
${js}
|
|
64
|
-
}).call(this).catch(err => {
|
|
65
|
-
if (!(err instanceof this.NakoRuntimeError)) {
|
|
66
|
-
err = new this.NakoRuntimeError(err, this.__varslist[0].line);
|
|
67
|
-
}
|
|
68
|
-
this.logger.error(err);
|
|
69
|
-
throw err;
|
|
70
|
-
}); // async::main
|
|
71
|
-
// <nadesiko3::gen::async>\n`
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
// デバッグメッセージ
|
|
76
|
-
com.logger.trace('--- generate ---\n' + js)
|
|
77
|
-
|
|
78
|
-
return {
|
|
79
|
-
// なでしこの実行環境ありの場合
|
|
80
|
-
runtimeEnv: js,
|
|
81
|
-
// JavaScript単体で動かす場合
|
|
82
|
-
standalone:
|
|
83
|
-
`\
|
|
84
|
-
const nakoVersion = ${JSON.stringify(nakoVersion)};
|
|
85
|
-
${NakoError.toString()}
|
|
86
|
-
${NakoRuntimeError.toString()}
|
|
87
|
-
this.logger = {
|
|
88
|
-
error(message) { console.error(message) },
|
|
89
|
-
send(level, message) { console.log(message) },
|
|
90
|
-
};
|
|
91
|
-
this.__varslist = [{}, {}, {}];
|
|
92
|
-
this.__vars = this.__varslist[2];
|
|
93
|
-
this.__module = {};
|
|
94
|
-
this.__locals = {};
|
|
95
|
-
this.__genMode = 'sync';
|
|
96
|
-
try {
|
|
97
|
-
${gen.getVarsCode()}
|
|
98
|
-
${js}
|
|
99
|
-
} catch (err) {
|
|
100
|
-
if (!(err instanceof NakoRuntimeError)) {
|
|
101
|
-
err = new NakoRuntimeError(err, __varslist[0].line);
|
|
102
|
-
}
|
|
103
|
-
this.logger.error(err);
|
|
104
|
-
throw err;
|
|
105
|
-
}`,
|
|
106
|
-
// コード生成に使ったNakoGenのインスタンス
|
|
107
|
-
gen
|
|
108
|
-
}
|
|
109
|
-
}
|
|
110
|
-
|
|
27
|
+
export class NakoGen {
|
|
111
28
|
/**
|
|
112
29
|
* @param {import('./nako3')} com コンパイラのインスタンス
|
|
113
30
|
*/
|
|
@@ -1623,4 +1540,93 @@ try {
|
|
|
1623
1540
|
}
|
|
1624
1541
|
}
|
|
1625
1542
|
|
|
1626
|
-
|
|
1543
|
+
|
|
1544
|
+
/**
|
|
1545
|
+
* @param {import('./nako3')} com
|
|
1546
|
+
* @param {Ast} ast
|
|
1547
|
+
* @param {boolean | string} isTest 文字列なら1つのテストだけを実行する
|
|
1548
|
+
*/
|
|
1549
|
+
export function generateJS (com, ast, isTest) {
|
|
1550
|
+
const gen = new NakoGen(com)
|
|
1551
|
+
|
|
1552
|
+
// ※ [関数定義に関するコード生成のヒント]
|
|
1553
|
+
// ※ 関数の名前だけを(1)で登録して、(2)で実際に関数のコードを生成する。
|
|
1554
|
+
// ※ ただし(2)では生成するだけなので、(3)でプログラム冒頭に関数定義のコードを記述する。
|
|
1555
|
+
// この順番を変えることはできない (グローバル変数が認識できなくなったり、関数定義のタイミングがずれる)
|
|
1556
|
+
|
|
1557
|
+
// (1) ユーザー定義関数をシステムに登録する
|
|
1558
|
+
gen.registerFunction(ast)
|
|
1559
|
+
|
|
1560
|
+
// (2) JSコードを生成する
|
|
1561
|
+
let js = gen.convGen(ast, !!isTest)
|
|
1562
|
+
|
|
1563
|
+
// (3) JSコードを実行するための事前ヘッダ部分の生成
|
|
1564
|
+
js = gen.getDefFuncCode(isTest) + js
|
|
1565
|
+
|
|
1566
|
+
// テストの実行
|
|
1567
|
+
if (js && isTest) {
|
|
1568
|
+
js += '\n__self._runTests(__tests);\n'
|
|
1569
|
+
}
|
|
1570
|
+
// async method
|
|
1571
|
+
if (gen.numAsyncFn > 0) {
|
|
1572
|
+
let canAsync = !isIE11()
|
|
1573
|
+
if (canAsync) {
|
|
1574
|
+
js = `
|
|
1575
|
+
// <nadesiko3::gen::async>
|
|
1576
|
+
(async () => { // async::main
|
|
1577
|
+
${js}
|
|
1578
|
+
}).call(this).catch(err => {
|
|
1579
|
+
if (!(err instanceof this.NakoRuntimeError)) {
|
|
1580
|
+
err = new this.NakoRuntimeError(err, this.__varslist[0].line);
|
|
1581
|
+
}
|
|
1582
|
+
this.logger.error(err);
|
|
1583
|
+
throw err;
|
|
1584
|
+
}); // async::main
|
|
1585
|
+
// <nadesiko3::gen::async>\n`
|
|
1586
|
+
}
|
|
1587
|
+
}
|
|
1588
|
+
|
|
1589
|
+
// デバッグメッセージ
|
|
1590
|
+
com.logger.trace('--- generate ---\n' + js)
|
|
1591
|
+
// todo: 将来的に mjs のコードを履くように修正する
|
|
1592
|
+
const standaloneJSCode = `\
|
|
1593
|
+
// <standaloneCode>
|
|
1594
|
+
const path = require('path')
|
|
1595
|
+
const nakoVersion = ${JSON.stringify(nakoVersion)};
|
|
1596
|
+
${NakoError.toString()}
|
|
1597
|
+
${NakoRuntimeError.toString()}
|
|
1598
|
+
function __nako3safunc() {
|
|
1599
|
+
this.logger = {
|
|
1600
|
+
error: (message) => { console.error(message) },
|
|
1601
|
+
send: (level, message) => { console.log(message) },
|
|
1602
|
+
};
|
|
1603
|
+
this.__varslist = [{}, {}, {}];
|
|
1604
|
+
this.__vars = this.__varslist[2];
|
|
1605
|
+
this.__module = {};
|
|
1606
|
+
this.__locals = {};
|
|
1607
|
+
this.__genMode = 'sync';
|
|
1608
|
+
try {
|
|
1609
|
+
${gen.getVarsCode()}
|
|
1610
|
+
${js}
|
|
1611
|
+
} catch (err) {
|
|
1612
|
+
if (!(err instanceof NakoRuntimeError)) {
|
|
1613
|
+
err = new NakoRuntimeError(err, __varslist[0].line);
|
|
1614
|
+
}
|
|
1615
|
+
this.logger.error(err);
|
|
1616
|
+
throw err;
|
|
1617
|
+
}
|
|
1618
|
+
//
|
|
1619
|
+
} // end of __nako3safunc function
|
|
1620
|
+
__nako3safunc();
|
|
1621
|
+
// </standaloneCode>
|
|
1622
|
+
`
|
|
1623
|
+
|
|
1624
|
+
return {
|
|
1625
|
+
// なでしこの実行環境ありの場合
|
|
1626
|
+
runtimeEnv: js,
|
|
1627
|
+
// JavaScript単体で動かす場合
|
|
1628
|
+
standalone: standaloneJSCode,
|
|
1629
|
+
// コード生成に使ったNakoGenのインスタンス
|
|
1630
|
+
gen
|
|
1631
|
+
}
|
|
1632
|
+
}
|