nadesiko3 3.7.13 → 3.7.15
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/batch/command.txt +384 -388
- package/batch/jsplugin2text.nako3 +2 -0
- package/batch/pickup_command.nako3 +1 -1
- package/core/package.json +1 -1
- package/core/src/nako3.mjs +2 -5
- package/core/src/nako3.mts +57 -56
- package/core/src/nako_ast.mjs +0 -1
- package/core/src/nako_ast.mts +1 -1
- package/core/src/nako_colors.mjs +0 -1
- package/core/src/nako_colors.mts +1 -1
- package/core/src/nako_core_version.mjs +2 -2
- package/core/src/nako_core_version.mts +2 -2
- package/core/src/nako_csv.mjs +0 -1
- package/core/src/nako_csv.mts +9 -9
- package/core/src/nako_errors.mts +8 -8
- package/core/src/nako_from_dncl.mts +5 -5
- package/core/src/nako_from_dncl2.mjs +0 -1
- package/core/src/nako_from_dncl2.mts +5 -5
- package/core/src/nako_gen.mjs +16 -17
- package/core/src/nako_gen.mts +230 -223
- package/core/src/nako_global.mts +11 -11
- package/core/src/nako_indent.mts +92 -92
- package/core/src/nako_indent_chars.mts +1 -1
- package/core/src/nako_indent_inline.mjs +11 -11
- package/core/src/nako_indent_inline.mts +20 -20
- package/core/src/nako_lex_rules.mjs +0 -1
- package/core/src/nako_lex_rules.mts +8 -8
- package/core/src/nako_lexer.mjs +0 -1
- package/core/src/nako_lexer.mts +23 -23
- package/core/src/nako_logger.mjs +1 -1
- package/core/src/nako_logger.mts +38 -38
- package/core/src/nako_parser3.mjs +4 -5
- package/core/src/nako_parser3.mts +79 -79
- package/core/src/nako_parser_base.mjs +1 -1
- package/core/src/nako_parser_base.mts +68 -68
- package/core/src/nako_parser_const.mjs +0 -1
- package/core/src/nako_parser_const.mts +1 -1
- package/core/src/nako_prepare.mts +12 -12
- package/core/src/nako_source_mapping.mts +9 -9
- package/core/src/nako_token.mjs +0 -1
- package/core/src/nako_token.mts +2 -2
- package/core/src/nako_tools.mjs +0 -1
- package/core/src/nako_tools.mts +4 -4
- package/core/src/nako_types.mjs +0 -1
- package/core/src/nako_types.mts +3 -3
- package/core/src/plugin_api.mjs +0 -1
- package/core/src/plugin_api.mts +1 -1
- package/core/src/plugin_csv.mjs +0 -1
- package/core/src/plugin_csv.mts +7 -7
- package/core/src/plugin_math.mjs +0 -1
- package/core/src/plugin_math.mts +39 -40
- package/core/src/plugin_promise.mjs +1 -1
- package/core/src/plugin_promise.mts +9 -9
- package/core/src/plugin_system.mjs +43 -21
- package/core/src/plugin_system.mts +366 -336
- package/core/src/plugin_test.mjs +0 -2
- package/core/src/plugin_test.mts +6 -6
- package/core/src/plugin_toml.mjs +1 -1
- package/core/src/plugin_toml.mts +4 -4
- package/core/test/flow_test.mjs +22 -0
- package/core/test/plugin_system_test.mjs +11 -7
- package/core/test/side_effects_test.mjs +1 -1
- package/package.json +32 -35
- package/release/_hash.txt +28 -28
- package/release/_script-tags.txt +16 -16
- 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/edit_main.js +33 -21
- package/release/edit_main.js.map +4 -4
- package/release/editor.js +33 -21
- package/release/plugin_keigo.js.map +2 -2
- package/release/plugin_turtle.js.map +2 -2
- package/release/plugin_weykturtle3d.js.map +2 -2
- package/release/version.js +29 -17
- package/release/version_main.js +29 -17
- package/release/version_main.js.map +4 -4
- package/release/wnako3.js +64 -57
- package/release/wnako3.js.map +3 -3
- package/release/wnako3webworker.js +50 -43
- package/release/wnako3webworker.js.map +3 -3
- package/src/cnako3.mts +1 -1
- package/src/cnako3mod.mjs +4 -7
- package/src/cnako3mod.mts +24 -24
- package/src/commander_ja.mts +8 -8
- package/src/deno_wrapper.mjs +0 -1
- package/src/deno_wrapper.mts +5 -5
- package/src/nako_version.mjs +2 -2
- package/src/nako_version.mts +2 -2
- package/src/plugin_browser.mjs +21 -29
- package/src/plugin_browser.mts +30 -35
- package/src/plugin_browser_ajax.mts +27 -27
- package/src/plugin_browser_audio.mjs +0 -1
- package/src/plugin_browser_audio.mts +11 -11
- package/src/plugin_browser_camera.mts +8 -8
- package/src/plugin_browser_canvas.mjs +0 -2
- package/src/plugin_browser_canvas.mts +34 -34
- package/src/plugin_browser_chart.mjs +0 -1
- package/src/plugin_browser_chart.mts +13 -13
- package/src/plugin_browser_color.mts +2 -2
- package/src/plugin_browser_crypto.mts +5 -5
- package/src/plugin_browser_dialog.mts +4 -4
- package/src/plugin_browser_dom_basic.mts +42 -42
- package/src/plugin_browser_dom_event.mjs +0 -1
- package/src/plugin_browser_dom_event.mts +27 -28
- package/src/plugin_browser_dom_parts.mjs +0 -2
- package/src/plugin_browser_dom_parts.mts +31 -31
- package/src/plugin_browser_geolocation.mts +3 -3
- package/src/plugin_browser_hotkey.mts +3 -3
- package/src/plugin_browser_html.mts +4 -4
- package/src/plugin_browser_in_worker.mts +1 -1
- package/src/plugin_browser_location.mts +2 -2
- package/src/plugin_browser_speech.mts +7 -7
- package/src/plugin_browser_storage.mts +11 -11
- package/src/plugin_browser_system.mts +2 -2
- package/src/plugin_browser_websocket.mts +6 -6
- package/src/plugin_httpserver.mts +17 -17
- package/src/plugin_keigo.mts +5 -5
- package/src/plugin_node.mjs +7 -48
- package/src/plugin_node.mts +114 -145
- package/src/plugin_turtle.mts +143 -143
- package/src/plugin_weykturtle3d.mjs +0 -3
- package/src/plugin_weykturtle3d.mts +135 -135
- package/src/plugin_weykturtle3d_three.mjs +0 -1
- package/src/plugin_weykturtle3d_three.mts +1 -1
- package/src/plugin_weykturtle3d_threeutil.mts +3 -3
- package/src/wnako3.mjs +0 -1
- package/src/wnako3.mts +1 -1
- package/src/wnako3_editor.mjs +0 -2
- package/src/wnako3_editor.mts +132 -132
- package/src/wnako3mod.mjs +0 -5
- package/src/wnako3mod.mts +19 -19
|
@@ -48,8 +48,8 @@ CORE="core/src"
|
|
|
48
48
|
['nadesiko3-postgresql/src/plugin_postgresql.js', 'cnako'],
|
|
49
49
|
['nadesiko3php/src/plugin_php.php', 'phpnako'],
|
|
50
50
|
['nadesiko3electron/src/plugin_electron_node.mjs', 'enako'],
|
|
51
|
-
['nadesiko3-toml/src/nadesiko3-toml.js', 'wnako,cnako'],
|
|
52
51
|
['nadesiko3-drone/nadesiko3-drone.js', 'cnako'], # ドローン制御
|
|
52
|
+
# ['nadesiko3-toml/src/nadesiko3-toml.js', 'wnako,cnako'],
|
|
53
53
|
]
|
|
54
54
|
# サポートしない
|
|
55
55
|
# 'nadesiko3-firebase/plugin_firebase.js',
|
package/core/package.json
CHANGED
package/core/src/nako3.mjs
CHANGED
|
@@ -250,7 +250,6 @@ export class NakoCompiler {
|
|
|
250
250
|
continue;
|
|
251
251
|
}
|
|
252
252
|
// 初回の読み込み
|
|
253
|
-
// eslint-disable-next-line @typescript-eslint/no-empty-function
|
|
254
253
|
dependencies[item.filePath] = { tokens: [], alias: new Set([item.value]), addPluginFile: () => { }, funclist: {}, moduleExport: {} };
|
|
255
254
|
if (item.type === 'js' || item.type === 'mjs') {
|
|
256
255
|
loadJS(item, tasks);
|
|
@@ -626,7 +625,8 @@ export class NakoCompiler {
|
|
|
626
625
|
// onBeforeGenerate
|
|
627
626
|
this.eventList.filter(o => o.eventName === 'beforeGenerate').map(e => e.callback(ast));
|
|
628
627
|
// generate
|
|
629
|
-
const
|
|
628
|
+
const genOptions = new NakoGenOptions(options.testOnly);
|
|
629
|
+
const outCode = this.generateCode(ast, genOptions);
|
|
630
630
|
// onAfterGenerate
|
|
631
631
|
this.eventList.filter(o => o.eventName === 'afterGenerate').map(e => e.callback(outCode));
|
|
632
632
|
return outCode;
|
|
@@ -671,7 +671,6 @@ export class NakoCompiler {
|
|
|
671
671
|
* @param [preCode]
|
|
672
672
|
* @deprecated 代わりにrunAsyncメソッドを使ってください。(core #52)
|
|
673
673
|
*/
|
|
674
|
-
// eslint-disable-next-line @typescript-eslint/require-await
|
|
675
674
|
async _run(code, fname, isReset, isTest, preCode = '') {
|
|
676
675
|
const opts = newCompilerOptions({
|
|
677
676
|
resetEnv: isReset,
|
|
@@ -705,7 +704,6 @@ export class NakoCompiler {
|
|
|
705
704
|
// 実行前に環境を初期化するイベントを実行(beforeRun)
|
|
706
705
|
this.eventList.filter(o => o.eventName === 'beforeRun').map(e => e.callback(nakoGlobal));
|
|
707
706
|
try {
|
|
708
|
-
// eslint-disable-next-line no-new-func, @typescript-eslint/no-implied-eval
|
|
709
707
|
const f = new Function(nakoGlobal.lastJSCode);
|
|
710
708
|
f.apply(nakoGlobal);
|
|
711
709
|
}
|
|
@@ -743,7 +741,6 @@ export class NakoCompiler {
|
|
|
743
741
|
* @param options オプション
|
|
744
742
|
* @returns 実行に利用したグローバルオブジェクト
|
|
745
743
|
*/
|
|
746
|
-
// eslint-disable-next-line @typescript-eslint/require-await
|
|
747
744
|
async runAsync(code, filename, options = undefined) {
|
|
748
745
|
// コンパイル
|
|
749
746
|
options = newCompilerOptions(options);
|
package/core/src/nako3.mts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
|
|
2
|
+
|
|
3
|
+
|
|
4
4
|
// deno-lint-ignore-file no-explicit-any
|
|
5
5
|
/**
|
|
6
6
|
* nadesiko v3
|
|
@@ -70,7 +70,7 @@ export interface NakoResetOption {
|
|
|
70
70
|
}
|
|
71
71
|
|
|
72
72
|
/** コンパイラ実行オプションを生成 */
|
|
73
|
-
export function newCompilerOptions
|
|
73
|
+
export function newCompilerOptions(initObj: Partial<CompilerOptions> = {}): CompilerOptions {
|
|
74
74
|
if (typeof initObj !== 'object') { initObj = {} }
|
|
75
75
|
initObj.testOnly = initObj.testOnly || false
|
|
76
76
|
initObj.resetEnv = initObj.resetEnv || false
|
|
@@ -99,7 +99,7 @@ export class NakoCompiler {
|
|
|
99
99
|
// global objects
|
|
100
100
|
__varslist: NakoVars[]
|
|
101
101
|
__locals: NakoVars
|
|
102
|
-
|
|
102
|
+
|
|
103
103
|
__self: NakoCompiler
|
|
104
104
|
__vars: NakoVars
|
|
105
105
|
__v0: NakoVars
|
|
@@ -117,7 +117,7 @@ export class NakoCompiler {
|
|
|
117
117
|
/**
|
|
118
118
|
* @param {undefined | {'useBasicPlugin':true|false}} options
|
|
119
119
|
*/
|
|
120
|
-
constructor
|
|
120
|
+
constructor(options: NakoCompilerOption | undefined = undefined) {
|
|
121
121
|
if (options === undefined) {
|
|
122
122
|
options = { useBasicPlugin: true }
|
|
123
123
|
}
|
|
@@ -172,30 +172,30 @@ export class NakoCompiler {
|
|
|
172
172
|
}
|
|
173
173
|
|
|
174
174
|
/** モジュール(名前空間)の一覧を取得する */
|
|
175
|
-
getModList
|
|
175
|
+
getModList(): string[] {
|
|
176
176
|
return this.lexer.modList
|
|
177
177
|
}
|
|
178
178
|
|
|
179
|
-
getLogger
|
|
179
|
+
getLogger(): NakoLogger {
|
|
180
180
|
return this.logger
|
|
181
181
|
}
|
|
182
182
|
|
|
183
|
-
getNakoFuncList
|
|
183
|
+
getNakoFuncList(): FuncList {
|
|
184
184
|
return this.nakoFuncList
|
|
185
185
|
}
|
|
186
186
|
|
|
187
|
-
getNakoFunc
|
|
187
|
+
getNakoFunc(name: string): FuncListItem|undefined {
|
|
188
188
|
return this.nakoFuncList.get(name)
|
|
189
189
|
}
|
|
190
190
|
|
|
191
|
-
getPluginfiles
|
|
191
|
+
getPluginfiles(): Record<string, any> {
|
|
192
192
|
return this.pluginfiles
|
|
193
193
|
}
|
|
194
194
|
|
|
195
195
|
/**
|
|
196
196
|
* 基本的なプラグインを追加する
|
|
197
197
|
*/
|
|
198
|
-
addBasicPlugins
|
|
198
|
+
addBasicPlugins() {
|
|
199
199
|
this.addPlugin(PluginSystem)
|
|
200
200
|
this.addPlugin(PluginMath)
|
|
201
201
|
this.addPlugin(PluginPromise)
|
|
@@ -207,7 +207,7 @@ export class NakoCompiler {
|
|
|
207
207
|
/**
|
|
208
208
|
* loggerを新しいインスタンスで置き換える。
|
|
209
209
|
*/
|
|
210
|
-
replaceLogger
|
|
210
|
+
replaceLogger() {
|
|
211
211
|
const logger = this.lexer.logger = this.parser.logger = this.logger = new NakoLogger()
|
|
212
212
|
return logger
|
|
213
213
|
}
|
|
@@ -216,7 +216,7 @@ export class NakoCompiler {
|
|
|
216
216
|
* ファイル内のrequire文の位置を列挙する。出力の配列はstartでソートされている。
|
|
217
217
|
* @param {Token[]} tokens rawtokenizeの出力
|
|
218
218
|
*/
|
|
219
|
-
static listRequireStatements
|
|
219
|
+
static listRequireStatements(tokens: Token[]): Token[] {
|
|
220
220
|
const requireStatements: Token[] = []
|
|
221
221
|
for (let i = 0; i + 2 < tokens.length; i++) {
|
|
222
222
|
// not (string|string_ex) '取り込み'
|
|
@@ -283,7 +283,7 @@ export class NakoCompiler {
|
|
|
283
283
|
* @returns {Promise<unknown> | void}
|
|
284
284
|
* @protected
|
|
285
285
|
*/
|
|
286
|
-
_loadDependencies
|
|
286
|
+
_loadDependencies(code: string, filename: string, preCode: string, tools: LoaderTool) {
|
|
287
287
|
const dependencies: Dependencies = {}
|
|
288
288
|
const compiler = new NakoCompiler({ useBasicPlugin: true })
|
|
289
289
|
/**
|
|
@@ -339,7 +339,7 @@ export class NakoCompiler {
|
|
|
339
339
|
}
|
|
340
340
|
|
|
341
341
|
// 初回の読み込み
|
|
342
|
-
|
|
342
|
+
|
|
343
343
|
dependencies[item.filePath] = { tokens: [], alias: new Set([item.value]), addPluginFile: ():void => {}, funclist: {}, moduleExport: {} }
|
|
344
344
|
if (item.type === 'js' || item.type === 'mjs') {
|
|
345
345
|
loadJS(item, tasks)
|
|
@@ -387,7 +387,7 @@ export class NakoCompiler {
|
|
|
387
387
|
* @param preCode
|
|
388
388
|
* @returns トークンのリスト
|
|
389
389
|
*/
|
|
390
|
-
rawtokenize
|
|
390
|
+
rawtokenize(code: string, line: number, filename: string, preCode = ''): Token[] {
|
|
391
391
|
if (!code.startsWith(preCode)) {
|
|
392
392
|
throw new Error('codeの先頭にはpreCodeを含める必要があります。')
|
|
393
393
|
}
|
|
@@ -458,7 +458,7 @@ export class NakoCompiler {
|
|
|
458
458
|
* @param {string} filename
|
|
459
459
|
* @returns コード (なでしこ)
|
|
460
460
|
*/
|
|
461
|
-
converttoken
|
|
461
|
+
converttoken(tokens: Token[], isFirst: boolean, filename: string): Token[] {
|
|
462
462
|
const tok = this.lexer.replaceTokens(tokens, isFirst, filename)
|
|
463
463
|
return tok
|
|
464
464
|
}
|
|
@@ -467,7 +467,7 @@ export class NakoCompiler {
|
|
|
467
467
|
* 環境のリセット
|
|
468
468
|
* {NakoResetOption|undefined}
|
|
469
469
|
*/
|
|
470
|
-
reset
|
|
470
|
+
reset(options: NakoResetOption|undefined = undefined) {
|
|
471
471
|
if (!options || options.needToClearPlugin) {
|
|
472
472
|
// (メモ) #1245
|
|
473
473
|
// 通常、リセット処理では、プラグインの!クリアを呼ぶ。
|
|
@@ -518,7 +518,7 @@ export class NakoCompiler {
|
|
|
518
518
|
* @returns
|
|
519
519
|
* @private
|
|
520
520
|
*/
|
|
521
|
-
lexCodeToken
|
|
521
|
+
lexCodeToken(code: string, line: number, filename: string, startOffset: number|null): {commentTokens: Token[], tokens: Token[]} {
|
|
522
522
|
// 単語に分割
|
|
523
523
|
let tokens = this.rawtokenize(code, line, filename, '')
|
|
524
524
|
|
|
@@ -555,7 +555,7 @@ export class NakoCompiler {
|
|
|
555
555
|
* @param {Set<string>} [includeGuard]
|
|
556
556
|
* @returns {Token[]} 削除された取り込み文のトークン
|
|
557
557
|
*/
|
|
558
|
-
replaceRequireStatements
|
|
558
|
+
replaceRequireStatements(tokens: Token[], includeGuard:Set<string> = new Set()): Token[] {
|
|
559
559
|
/** @type {TokenWithSourceMap[]} */
|
|
560
560
|
const deletedTokens = []
|
|
561
561
|
for (const r of NakoCompiler.listRequireStatements(tokens).reverse()) {
|
|
@@ -586,7 +586,7 @@ export class NakoCompiler {
|
|
|
586
586
|
* @param {TokenWithSourceMap[]} tokens
|
|
587
587
|
* @returns {TokenWithSourceMap[]} 削除された取り込み文のトークン
|
|
588
588
|
*/
|
|
589
|
-
removeRequireStatements
|
|
589
|
+
removeRequireStatements(tokens: Token[]): Token[] {
|
|
590
590
|
/** @type {TokenWithSourceMap[]} */
|
|
591
591
|
const deletedTokens = []
|
|
592
592
|
for (const r of NakoCompiler.listRequireStatements(tokens).reverse()) {
|
|
@@ -603,7 +603,7 @@ export class NakoCompiler {
|
|
|
603
603
|
}
|
|
604
604
|
|
|
605
605
|
/** 字句解析を行う */
|
|
606
|
-
lex
|
|
606
|
+
lex(code: string, filename = 'main.nako3', preCode = '', syntaxHighlighting = false): LexResult {
|
|
607
607
|
// 単語に分割
|
|
608
608
|
let tokens = this.rawtokenize(code, 0, filename, preCode)
|
|
609
609
|
|
|
@@ -649,7 +649,7 @@ export class NakoCompiler {
|
|
|
649
649
|
/**
|
|
650
650
|
* コードをパースしてASTにする
|
|
651
651
|
*/
|
|
652
|
-
parse
|
|
652
|
+
parse(code: string, filename: string, preCode = ''): Ast {
|
|
653
653
|
// 関数リストを字句解析と構文解析に登録
|
|
654
654
|
this.lexer.setFuncList(this.funclist)
|
|
655
655
|
this.parser.setFuncList(this.funclist)
|
|
@@ -677,13 +677,13 @@ export class NakoCompiler {
|
|
|
677
677
|
return ast
|
|
678
678
|
}
|
|
679
679
|
|
|
680
|
-
getUsedFuncs
|
|
680
|
+
getUsedFuncs(ast: Ast): Set<string> {
|
|
681
681
|
this.usedFuncs = new Set()
|
|
682
682
|
this._getUsedFuncs(ast)
|
|
683
683
|
return this.deleteUnNakoFuncs()
|
|
684
684
|
}
|
|
685
685
|
|
|
686
|
-
_getUsedFuncs
|
|
686
|
+
_getUsedFuncs(ast: Ast): void {
|
|
687
687
|
if (!ast) { return }
|
|
688
688
|
if ((ast.type === 'func' || ast.type === 'func_pointer') && ast.name) {
|
|
689
689
|
this.usedFuncs.add(ast.name as string)
|
|
@@ -694,7 +694,7 @@ export class NakoCompiler {
|
|
|
694
694
|
}
|
|
695
695
|
}
|
|
696
696
|
|
|
697
|
-
deleteUnNakoFuncs
|
|
697
|
+
deleteUnNakoFuncs(): Set<string> {
|
|
698
698
|
for (const func of this.usedFuncs) {
|
|
699
699
|
if (!this.commandlist.has(func)) {
|
|
700
700
|
this.usedFuncs.delete(func)
|
|
@@ -710,7 +710,7 @@ export class NakoCompiler {
|
|
|
710
710
|
* @param isTest テストかどうか
|
|
711
711
|
* @param preCode
|
|
712
712
|
*/
|
|
713
|
-
compile
|
|
713
|
+
compile(code: string, filename: string, isTest = false, preCode = ''): string {
|
|
714
714
|
const opt = newCompilerOptions()
|
|
715
715
|
opt.testOnly = isTest
|
|
716
716
|
opt.preCode = preCode
|
|
@@ -719,7 +719,7 @@ export class NakoCompiler {
|
|
|
719
719
|
}
|
|
720
720
|
|
|
721
721
|
/** parse & generate */
|
|
722
|
-
compileFromCode
|
|
722
|
+
compileFromCode(code: string, filename: string, options: CompilerOptions|undefined = undefined): NakoGenResult {
|
|
723
723
|
if (filename === '') { filename = 'main.nako3' }
|
|
724
724
|
if (options === undefined) { options = newCompilerOptions() }
|
|
725
725
|
try {
|
|
@@ -732,7 +732,8 @@ export class NakoCompiler {
|
|
|
732
732
|
// onBeforeGenerate
|
|
733
733
|
this.eventList.filter(o => o.eventName === 'beforeGenerate').map(e => e.callback(ast))
|
|
734
734
|
// generate
|
|
735
|
-
const
|
|
735
|
+
const genOptions = new NakoGenOptions(options.testOnly)
|
|
736
|
+
const outCode = this.generateCode(ast, genOptions)
|
|
736
737
|
// onAfterGenerate
|
|
737
738
|
this.eventList.filter(o => o.eventName === 'afterGenerate').map(e => e.callback(outCode))
|
|
738
739
|
return outCode
|
|
@@ -748,7 +749,7 @@ export class NakoCompiler {
|
|
|
748
749
|
* @param opt テストかどうか
|
|
749
750
|
* @param mode 一般的に 'sync' を指定
|
|
750
751
|
*/
|
|
751
|
-
generateCode
|
|
752
|
+
generateCode(ast: Ast, opt: NakoGenOptions, mode = 'sync'): NakoGenResult {
|
|
752
753
|
// Select Code Generator #637
|
|
753
754
|
// normal mode
|
|
754
755
|
if (mode === 'sync') {
|
|
@@ -767,7 +768,7 @@ export class NakoCompiler {
|
|
|
767
768
|
}
|
|
768
769
|
|
|
769
770
|
/** コードジェネレータを追加する */
|
|
770
|
-
addCodeGenerator
|
|
771
|
+
addCodeGenerator(mode: string, obj: any) {
|
|
771
772
|
this.codeGenerateor[mode] = obj
|
|
772
773
|
}
|
|
773
774
|
|
|
@@ -779,8 +780,8 @@ export class NakoCompiler {
|
|
|
779
780
|
* @param [preCode]
|
|
780
781
|
* @deprecated 代わりにrunAsyncメソッドを使ってください。(core #52)
|
|
781
782
|
*/
|
|
782
|
-
|
|
783
|
-
async _run
|
|
783
|
+
|
|
784
|
+
async _run(code: string, fname: string, isReset: boolean, isTest: boolean, preCode = ''): Promise<NakoGlobal> {
|
|
784
785
|
const opts: CompilerOptions = newCompilerOptions({
|
|
785
786
|
resetEnv: isReset,
|
|
786
787
|
resetAll: isReset,
|
|
@@ -791,7 +792,7 @@ export class NakoCompiler {
|
|
|
791
792
|
}
|
|
792
793
|
|
|
793
794
|
/** 各プラグインをリセットする */
|
|
794
|
-
clearPlugins
|
|
795
|
+
clearPlugins() {
|
|
795
796
|
// 他に実行している「なでしこ」があればクリアする
|
|
796
797
|
this.__globals.forEach((sys: NakoGlobal) => {
|
|
797
798
|
if (!sys) { return }
|
|
@@ -807,13 +808,13 @@ export class NakoCompiler {
|
|
|
807
808
|
* @param code JavaScriptのコード
|
|
808
809
|
* @param nakoGlobal 実行環境
|
|
809
810
|
*/
|
|
810
|
-
private evalJS
|
|
811
|
+
private evalJS(code: string, nakoGlobal: NakoGlobal): void {
|
|
811
812
|
this.__globalObj = nakoGlobal // 現在のnakoGlobalを記録
|
|
812
813
|
this.__globalObj.lastJSCode = code
|
|
813
814
|
// 実行前に環境を初期化するイベントを実行(beforeRun)
|
|
814
815
|
this.eventList.filter(o => o.eventName === 'beforeRun').map(e => e.callback(nakoGlobal))
|
|
815
816
|
try {
|
|
816
|
-
|
|
817
|
+
|
|
817
818
|
const f = new Function(nakoGlobal.lastJSCode)
|
|
818
819
|
f.apply(nakoGlobal)
|
|
819
820
|
} catch (err: any) {
|
|
@@ -834,7 +835,7 @@ export class NakoCompiler {
|
|
|
834
835
|
* @returns 実行に利用したグローバルオブジェクト
|
|
835
836
|
* @deprecated 代わりにrunAsyncメソッドを使ってください。(core #52)
|
|
836
837
|
*/
|
|
837
|
-
public runSync
|
|
838
|
+
public runSync(code: string, filename: string, options: CompilerOptions|undefined = undefined): NakoGlobal {
|
|
838
839
|
// コンパイル
|
|
839
840
|
options = newCompilerOptions(options)
|
|
840
841
|
const out = this.compileFromCode(code, filename, options)
|
|
@@ -852,8 +853,8 @@ export class NakoCompiler {
|
|
|
852
853
|
* @param options オプション
|
|
853
854
|
* @returns 実行に利用したグローバルオブジェクト
|
|
854
855
|
*/
|
|
855
|
-
|
|
856
|
-
public async runAsync
|
|
856
|
+
|
|
857
|
+
public async runAsync(code: string, filename: string, options: CompilerOptions|undefined = undefined): Promise<NakoGlobal> {
|
|
857
858
|
// コンパイル
|
|
858
859
|
options = newCompilerOptions(options)
|
|
859
860
|
const compiledCode = this.compileFromCode(code, filename, options)
|
|
@@ -864,7 +865,7 @@ export class NakoCompiler {
|
|
|
864
865
|
return nakoGlobal
|
|
865
866
|
}
|
|
866
867
|
|
|
867
|
-
private getNakoGlobal
|
|
868
|
+
private getNakoGlobal(options: CompilerOptions, gen: NakoGen, filename: string): NakoGlobal {
|
|
868
869
|
// オプションを参照
|
|
869
870
|
let g: NakoGlobal|null = options.nakoGlobal
|
|
870
871
|
if (!g) {
|
|
@@ -886,7 +887,7 @@ export class NakoCompiler {
|
|
|
886
887
|
* @param eventName イベント名
|
|
887
888
|
* @param callback コールバック関数
|
|
888
889
|
*/
|
|
889
|
-
addListener
|
|
890
|
+
addListener(eventName: NakoComEventName, callback: (event:any) => void) {
|
|
890
891
|
this.eventList.push({ eventName, callback })
|
|
891
892
|
}
|
|
892
893
|
|
|
@@ -897,7 +898,7 @@ export class NakoCompiler {
|
|
|
897
898
|
* @param preCode
|
|
898
899
|
* @param testOnly
|
|
899
900
|
*/
|
|
900
|
-
test
|
|
901
|
+
test(code: string, fname: string, preCode = '', testOnly = false) {
|
|
901
902
|
const options = newCompilerOptions()
|
|
902
903
|
options.preCode = preCode
|
|
903
904
|
options.testOnly = testOnly
|
|
@@ -911,7 +912,7 @@ export class NakoCompiler {
|
|
|
911
912
|
* @param [preCode]
|
|
912
913
|
* @deprecated 代わりに runAsync を使ってください。
|
|
913
914
|
*/
|
|
914
|
-
run
|
|
915
|
+
run(code: string, fname = 'main.nako3', preCode = ''): NakoGlobal {
|
|
915
916
|
const options = newCompilerOptions()
|
|
916
917
|
options.preCode = preCode
|
|
917
918
|
return this.runSync(code, fname, options)
|
|
@@ -923,7 +924,7 @@ export class NakoCompiler {
|
|
|
923
924
|
* @param filename
|
|
924
925
|
* @param opt? オプション
|
|
925
926
|
*/
|
|
926
|
-
compileStandalone
|
|
927
|
+
compileStandalone(code: string, filename: string, options?: NakoGenOptions): string {
|
|
927
928
|
if (options === undefined) { options = new NakoGenOptions() }
|
|
928
929
|
const ast = this.parse(code, filename)
|
|
929
930
|
return this.generateCode(ast, options).standalone
|
|
@@ -935,7 +936,7 @@ export class NakoCompiler {
|
|
|
935
936
|
* @param persistent falseのとき、次以降の実行では使えない
|
|
936
937
|
* @param fpath ファイルパス
|
|
937
938
|
*/
|
|
938
|
-
addPlugin
|
|
939
|
+
addPlugin(po: {[key: string]: any}, persistent = true, fpath = ''): void {
|
|
939
940
|
// __v0を取得
|
|
940
941
|
const __v0 = this.__varslist[0]
|
|
941
942
|
// プラグインのメタ情報をチェック (#1034) (#1647)
|
|
@@ -1035,7 +1036,7 @@ export class NakoCompiler {
|
|
|
1035
1036
|
* @param po 関数リスト
|
|
1036
1037
|
* @param persistent falseのとき、次以降の実行では使えない
|
|
1037
1038
|
*/
|
|
1038
|
-
addPluginObject
|
|
1039
|
+
addPluginObject(objName: string, po: {[key: string]: any}, persistent = true): void {
|
|
1039
1040
|
// metaプロパティがなければ互換性のため適当に追加
|
|
1040
1041
|
if (po.meta === undefined) {
|
|
1041
1042
|
po.meta = { type: 'const', value: { pluginName: objName, nakoVersion: '0.0.0' } }
|
|
@@ -1051,7 +1052,7 @@ export class NakoCompiler {
|
|
|
1051
1052
|
* @param persistent falseのとき、次以降の実行では使えない
|
|
1052
1053
|
* @deprecated 利用は非推奨
|
|
1053
1054
|
*/
|
|
1054
|
-
addPluginFile
|
|
1055
|
+
addPluginFile(_objName: string, fpath: string, po: {[key: string]: any}, persistent = true): void {
|
|
1055
1056
|
this.addPluginFromFile(fpath, po, persistent)
|
|
1056
1057
|
}
|
|
1057
1058
|
|
|
@@ -1061,7 +1062,7 @@ export class NakoCompiler {
|
|
|
1061
1062
|
* @param po 登録するオブジェクト
|
|
1062
1063
|
* @param persistent falseのとき、次以降の実行では使えない
|
|
1063
1064
|
*/
|
|
1064
|
-
addPluginFromFile
|
|
1065
|
+
addPluginFromFile(fpath: string, po: { [key: string]: any }, persistent = true): void {
|
|
1065
1066
|
this.addPlugin(po, persistent, fpath)
|
|
1066
1067
|
}
|
|
1067
1068
|
|
|
@@ -1073,7 +1074,7 @@ export class NakoCompiler {
|
|
|
1073
1074
|
* @param {boolean} returnNone 値を返す関数の場合はfalseを指定
|
|
1074
1075
|
* @param {boolean} asyncFn Promiseを返す関数かを指定
|
|
1075
1076
|
*/
|
|
1076
|
-
addFunc
|
|
1077
|
+
addFunc(key: string, josi: FuncArgs, fn: any, returnNone = true, asyncFn = false): void {
|
|
1077
1078
|
const funcObj: FuncListItem = { josi, fn, type: 'func', return_none: returnNone, asyncFn, pure: true }
|
|
1078
1079
|
this.funclist.set(key, funcObj)
|
|
1079
1080
|
this.pluginFunclist[key] = cloneAsJSON(funcObj)
|
|
@@ -1083,7 +1084,7 @@ export class NakoCompiler {
|
|
|
1083
1084
|
/** (非推奨) 互換性のため ... 関数を追加する
|
|
1084
1085
|
* @deprecated 代わりにaddFuncを使ってください
|
|
1085
1086
|
*/
|
|
1086
|
-
public setFunc
|
|
1087
|
+
public setFunc(key: string, josi: FuncArgs, fn: any, returnNone = true, asyncFn = false): void {
|
|
1087
1088
|
this.addFunc(key, josi, fn, returnNone, asyncFn)
|
|
1088
1089
|
}
|
|
1089
1090
|
|
|
@@ -1092,14 +1093,14 @@ export class NakoCompiler {
|
|
|
1092
1093
|
* @param key プラグイン関数の関数名
|
|
1093
1094
|
* @returns プラグイン・オブジェクト
|
|
1094
1095
|
*/
|
|
1095
|
-
getFunc
|
|
1096
|
+
getFunc(key: string): FuncListItem|undefined {
|
|
1096
1097
|
return this.funclist.get(key)
|
|
1097
1098
|
}
|
|
1098
1099
|
|
|
1099
1100
|
/** 同期的になでしこのプログラムcodeを実行する
|
|
1100
1101
|
* @deprecated 代わりにrunAsyncメソッドを使ってください。(core #52)
|
|
1101
1102
|
*/
|
|
1102
|
-
private _runEx
|
|
1103
|
+
private _runEx(code: string, filename: string, opts: CompilerOptions, preCode = '', nakoGlobal: NakoGlobal|undefined = undefined): NakoGlobal {
|
|
1103
1104
|
// コンパイル
|
|
1104
1105
|
opts.preCode = preCode
|
|
1105
1106
|
if (nakoGlobal) { opts.nakoGlobal = nakoGlobal }
|
|
@@ -1113,7 +1114,7 @@ export class NakoCompiler {
|
|
|
1113
1114
|
* @param [preCode]
|
|
1114
1115
|
* @deprecated 代わりにrunAsyncメソッドを使ってください。(core #52)
|
|
1115
1116
|
*/
|
|
1116
|
-
public runEx
|
|
1117
|
+
public runEx(code: string, fname: string, opts: CompilerOptions, preCode = '') {
|
|
1117
1118
|
return this._runEx(code, fname, opts, preCode)
|
|
1118
1119
|
}
|
|
1119
1120
|
|
|
@@ -1123,7 +1124,7 @@ export class NakoCompiler {
|
|
|
1123
1124
|
* @param fname
|
|
1124
1125
|
* @param [preCode]
|
|
1125
1126
|
*/
|
|
1126
|
-
async runReset
|
|
1127
|
+
async runReset(code: string, fname = 'main.nako3', preCode = ''): Promise<NakoGlobal> {
|
|
1127
1128
|
const opts = newCompilerOptions({ resetAll: true, resetEnv: true, preCode })
|
|
1128
1129
|
return this.runAsync(code, fname, opts)
|
|
1129
1130
|
}
|
|
@@ -1132,7 +1133,7 @@ export class NakoCompiler {
|
|
|
1132
1133
|
* 新規のなでしこ変数管理オブジェクトを生成
|
|
1133
1134
|
* @returns 変数管理オブジェクト
|
|
1134
1135
|
*/
|
|
1135
|
-
newVaiables
|
|
1136
|
+
newVaiables(initVars?: Map<string, any>): Map<string, any> {
|
|
1136
1137
|
return new Map(initVars)
|
|
1137
1138
|
}
|
|
1138
1139
|
}
|
package/core/src/nako_ast.mjs
CHANGED
package/core/src/nako_ast.mts
CHANGED
package/core/src/nako_colors.mjs
CHANGED
|
@@ -48,7 +48,6 @@ const convertColorTextFormat = (text) => {
|
|
|
48
48
|
let htmlColor = 'inherit'; // 文字色
|
|
49
49
|
let htmlFontWeight = 'inherit'; // 文字の太さ
|
|
50
50
|
// textが色情報を含まないならそれをそのまま使い、含むなら全体を <span>で囲んで、更に、ANSI escape code で囲まれた部分を対応する style を付けた <span> で囲む。
|
|
51
|
-
// eslint-disable-next-line multiline-ternary
|
|
52
51
|
const html = text === noColor ? noColor : ('<span>' + escapeHTML(text)
|
|
53
52
|
// eslint-disable-next-line no-control-regex
|
|
54
53
|
.replace(/\x1b\[(\d+)m/g, (_, m1str) => {
|
package/core/src/nako_colors.mts
CHANGED
|
@@ -54,7 +54,7 @@ const convertColorTextFormat = (text: string) => {
|
|
|
54
54
|
let htmlColor = 'inherit' // 文字色
|
|
55
55
|
let htmlFontWeight = 'inherit' // 文字の太さ
|
|
56
56
|
// textが色情報を含まないならそれをそのまま使い、含むなら全体を <span>で囲んで、更に、ANSI escape code で囲まれた部分を対応する style を付けた <span> で囲む。
|
|
57
|
-
|
|
57
|
+
|
|
58
58
|
const html = text === noColor ? noColor : ('<span>' + escapeHTML(text)
|
|
59
59
|
// eslint-disable-next-line no-control-regex
|
|
60
60
|
.replace(/\x1b\[(\d+)m/g, (_, m1str) => { // ANSI escape code(の一部)にマッチして置換
|
package/core/src/nako_csv.mjs
CHANGED
package/core/src/nako_csv.mts
CHANGED
|
@@ -11,19 +11,19 @@ export const options: CSVOptions = {
|
|
|
11
11
|
auto_convert_number: true
|
|
12
12
|
}
|
|
13
13
|
|
|
14
|
-
export function resetEnv
|
|
14
|
+
export function resetEnv(): void {
|
|
15
15
|
options.delimiter = ','
|
|
16
16
|
options.eol = '\r\n'
|
|
17
17
|
options.auto_convert_number = true
|
|
18
18
|
}
|
|
19
19
|
|
|
20
20
|
/// 文字列が数値化どうか判定する関数
|
|
21
|
-
|
|
22
|
-
function is_numeric
|
|
21
|
+
|
|
22
|
+
function is_numeric(str: string): boolean {
|
|
23
23
|
return /^-?\d+(\.\d+)?([eE][-+]?\d+)?$/.test(str)
|
|
24
24
|
}
|
|
25
25
|
|
|
26
|
-
export function parse
|
|
26
|
+
export function parse(txt: string, delimiter: string|undefined = undefined): (string|number)[][] {
|
|
27
27
|
// delimiter
|
|
28
28
|
if (delimiter === undefined) {
|
|
29
29
|
delimiter = options.delimiter
|
|
@@ -38,7 +38,7 @@ export function parse (txt: string, delimiter: string|undefined = undefined): (s
|
|
|
38
38
|
const patToDelim = '^(.*?)([\\' + delimiter + '\\n])'
|
|
39
39
|
const reToDelim = new RegExp(patToDelim)
|
|
40
40
|
// if value is number then convert to float
|
|
41
|
-
const convType = function
|
|
41
|
+
const convType = function(v: string) {
|
|
42
42
|
let result: string|number = v
|
|
43
43
|
if (typeof (v) === 'string') {
|
|
44
44
|
if (options.auto_convert_number && is_numeric(v)) {
|
|
@@ -150,7 +150,7 @@ export function parse (txt: string, delimiter: string|undefined = undefined): (s
|
|
|
150
150
|
}
|
|
151
151
|
|
|
152
152
|
// convert 2D array to CSV string
|
|
153
|
-
export function stringify
|
|
153
|
+
export function stringify(ary: string[][], delimiter: string|undefined = undefined, eol: string|undefined = undefined): string {
|
|
154
154
|
// check arguments
|
|
155
155
|
if (delimiter === undefined) {
|
|
156
156
|
delimiter = options.delimiter
|
|
@@ -176,15 +176,15 @@ export function stringify (ary: string[][], delimiter: string|undefined = undefi
|
|
|
176
176
|
return r
|
|
177
177
|
}
|
|
178
178
|
|
|
179
|
-
export function replaceEolMark
|
|
179
|
+
export function replaceEolMark(eol: string): string {
|
|
180
180
|
eol = eol.replace(/\n\r/g, '[CRLF]')
|
|
181
181
|
eol = eol.replace(/\r/g, '[CR]')
|
|
182
182
|
eol = eol.replace(/\n/g, '[LF]')
|
|
183
183
|
return eol
|
|
184
184
|
}
|
|
185
185
|
|
|
186
|
-
function genValueConverter
|
|
187
|
-
return function
|
|
186
|
+
function genValueConverter(delimiter: string) {
|
|
187
|
+
return function(s: string) {
|
|
188
188
|
s = '' + s
|
|
189
189
|
let fQuot = false
|
|
190
190
|
if (s.indexOf('\n') >= 0 || s.indexOf('\r') >= 0) { fQuot = true }
|