nadesiko3 3.3.51 → 3.3.52
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/core/package.json +1 -1
- package/core/src/nako3.mjs +32 -26
- package/core/src/nako3.mts +33 -26
- package/core/src/nako_core_version.mjs +2 -2
- package/core/src/nako_core_version.mts +2 -2
- package/core/src/nako_parser3.mjs +6 -4
- package/core/src/nako_parser3.mts +6 -4
- package/core/src/nako_parser_base.mjs +1 -0
- package/core/src/nako_parser_base.mts +2 -0
- package/core/src/nako_types.mjs +0 -12
- package/core/src/nako_types.mts +1 -8
- package/package.json +5 -5
- package/release/_hash.txt +12 -12
- package/release/_script-tags.txt +14 -14
- package/release/nako_gen_async.js +2 -1
- package/release/stats.json +1 -1
- package/release/version.js +1 -1
- package/release/wnako3.js +1 -1
- package/release/wnako3.js.LICENSE.txt +203 -1
- package/release/wnako3webworker.js +2 -1
- package/src/cnako3mod.mjs +14 -39
- package/src/cnako3mod.mts +14 -38
- package/src/nako_version.mjs +2 -2
- package/src/nako_version.mts +2 -2
- package/test/node/node_test.mjs +2 -2
package/README.md
CHANGED
|
@@ -36,7 +36,7 @@
|
|
|
36
36
|
「なでしこ3」とは、日本語のプログラミング言語です。HTML5/JavaScript(TypeScript)をベースとしているので、PC/スマホ/タブレットなど、さまざまな環境で動作させることができます。日本語プログラミング言語は、読みやすく理解しやすいのが特徴で、初めてでも楽しくプログラミングを覚えることができます。また、バッチ処理や定型処理などを手軽に記述できます。
|
|
37
37
|
|
|
38
38
|
- [なでしこのWebサイト](https://nadesi.com/)
|
|
39
|
-
- [なでしこ3のGitHub Pages
|
|
39
|
+
- [なでしこ3のGitHub Pages](https://kujirahand.github.io/nadesiko3/)
|
|
40
40
|
- [マニュアル](https://nadesi.com/v3/doc/)
|
|
41
41
|
|
|
42
42
|
## 対応機器/ブラウザ
|
package/core/package.json
CHANGED
package/core/src/nako3.mjs
CHANGED
|
@@ -1,8 +1,3 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* nadesiko v3
|
|
3
|
-
*/
|
|
4
|
-
// types
|
|
5
|
-
import { CompilerOptions } from './nako_types.mjs';
|
|
6
1
|
// parser / lexer
|
|
7
2
|
import { NakoParser } from './nako_parser3.mjs';
|
|
8
3
|
import { NakoLexer } from './nako_lexer.mjs';
|
|
@@ -24,6 +19,18 @@ import PluginCSV from './plugin_csv.mjs';
|
|
|
24
19
|
import PluginPromise from './plugin_promise.mjs';
|
|
25
20
|
import PluginTest from './plugin_test.mjs';
|
|
26
21
|
const cloneAsJSON = (x) => JSON.parse(JSON.stringify(x));
|
|
22
|
+
/** コンパイラ実行オプションを生成 */
|
|
23
|
+
export function newCompilerOptions(initObj = {}) {
|
|
24
|
+
if (typeof initObj !== 'object') {
|
|
25
|
+
initObj = {};
|
|
26
|
+
}
|
|
27
|
+
initObj.testOnly = initObj.testOnly || false;
|
|
28
|
+
initObj.resetEnv = initObj.resetEnv || false;
|
|
29
|
+
initObj.resetAll = initObj.resetAll || false;
|
|
30
|
+
initObj.preCode = initObj.preCode || '';
|
|
31
|
+
initObj.nakoGlobal = initObj.nakoGlobal || null;
|
|
32
|
+
return initObj;
|
|
33
|
+
}
|
|
27
34
|
/** なでしこコンパイラ */
|
|
28
35
|
export class NakoCompiler {
|
|
29
36
|
/**
|
|
@@ -469,10 +476,6 @@ export class NakoCompiler {
|
|
|
469
476
|
}
|
|
470
477
|
/**
|
|
471
478
|
* コードをパースしてASTにする
|
|
472
|
-
* @param code なでしこのプログラム
|
|
473
|
-
* @param filename
|
|
474
|
-
* @param [preCode]
|
|
475
|
-
* @return Ast
|
|
476
479
|
*/
|
|
477
480
|
parse(code, filename, preCode = '') {
|
|
478
481
|
// 関数を字句解析と構文解析に登録
|
|
@@ -480,7 +483,6 @@ export class NakoCompiler {
|
|
|
480
483
|
this.parser.setFuncList(this.funclist);
|
|
481
484
|
const lexerOutput = this.lex(code, filename, preCode);
|
|
482
485
|
// 構文木を作成
|
|
483
|
-
/** @type {Ast} */
|
|
484
486
|
let ast;
|
|
485
487
|
try {
|
|
486
488
|
this.parser.genMode = 'sync'; // set default
|
|
@@ -492,13 +494,12 @@ export class NakoCompiler {
|
|
|
492
494
|
}
|
|
493
495
|
throw err;
|
|
494
496
|
}
|
|
495
|
-
|
|
497
|
+
// 使用したシステム関数の一覧を this.usedFuns に入れる(エディタなどで利用される)
|
|
498
|
+
this.usedFuncs = this.parser.usedFuncs; // 全ての関数呼び出し
|
|
499
|
+
this.deleteUnNakoFuncs(); // システム関数以外を削除
|
|
496
500
|
this.logger.trace('--- ast ---\n' + JSON.stringify(ast, null, 2));
|
|
497
501
|
return ast;
|
|
498
502
|
}
|
|
499
|
-
/**
|
|
500
|
-
* @param {Ast} ast
|
|
501
|
-
*/
|
|
502
503
|
getUsedFuncs(ast) {
|
|
503
504
|
const queue = [ast];
|
|
504
505
|
this.usedFuncs = new Set();
|
|
@@ -541,17 +542,20 @@ export class NakoCompiler {
|
|
|
541
542
|
* @param preCode
|
|
542
543
|
*/
|
|
543
544
|
compile(code, filename, isTest = false, preCode = '') {
|
|
544
|
-
const opt =
|
|
545
|
+
const opt = newCompilerOptions();
|
|
545
546
|
opt.testOnly = isTest;
|
|
546
547
|
opt.preCode = preCode;
|
|
547
548
|
const res = this.compileFromCode(code, filename, opt);
|
|
548
549
|
return res.runtimeEnv;
|
|
549
550
|
}
|
|
550
551
|
/** parse & generate */
|
|
551
|
-
compileFromCode(code, filename, options) {
|
|
552
|
+
compileFromCode(code, filename, options = undefined) {
|
|
552
553
|
if (filename === '') {
|
|
553
554
|
filename = 'main.nako3';
|
|
554
555
|
}
|
|
556
|
+
if (options === undefined) {
|
|
557
|
+
options = newCompilerOptions();
|
|
558
|
+
}
|
|
555
559
|
try {
|
|
556
560
|
if (options.resetEnv) {
|
|
557
561
|
this.reset();
|
|
@@ -603,7 +607,7 @@ export class NakoCompiler {
|
|
|
603
607
|
* @param [preCode]
|
|
604
608
|
*/
|
|
605
609
|
async _run(code, fname, isReset, isTest, preCode = '') {
|
|
606
|
-
const opts =
|
|
610
|
+
const opts = newCompilerOptions({
|
|
607
611
|
resetEnv: isReset,
|
|
608
612
|
resetAll: isReset,
|
|
609
613
|
testOnly: isTest,
|
|
@@ -640,8 +644,9 @@ export class NakoCompiler {
|
|
|
640
644
|
* @param options オプション
|
|
641
645
|
* @returns 実行に利用したグローバルオブジェクト
|
|
642
646
|
*/
|
|
643
|
-
runSync(code, filename, options =
|
|
647
|
+
runSync(code, filename, options = undefined) {
|
|
644
648
|
// コンパイル
|
|
649
|
+
options = newCompilerOptions(options);
|
|
645
650
|
const out = this.compileFromCode(code, filename, options);
|
|
646
651
|
// 実行前に環境を生成
|
|
647
652
|
const nakoGlobal = this.getNakoGlobal(options, out.gen);
|
|
@@ -656,8 +661,9 @@ export class NakoCompiler {
|
|
|
656
661
|
* @param options オプション
|
|
657
662
|
* @returns 実行に利用したグローバルオブジェクト
|
|
658
663
|
*/
|
|
659
|
-
async runAsync(code, filename, options =
|
|
664
|
+
async runAsync(code, filename, options = undefined) {
|
|
660
665
|
// コンパイル
|
|
666
|
+
options = newCompilerOptions(options);
|
|
661
667
|
const out = this.compileFromCode(code, filename, options);
|
|
662
668
|
// 実行前に環境を生成
|
|
663
669
|
const nakoGlobal = this.getNakoGlobal(options, out.gen);
|
|
@@ -698,7 +704,7 @@ export class NakoCompiler {
|
|
|
698
704
|
* @param testOnly
|
|
699
705
|
*/
|
|
700
706
|
test(code, fname, preCode = '', testOnly = false) {
|
|
701
|
-
const options =
|
|
707
|
+
const options = newCompilerOptions();
|
|
702
708
|
options.preCode = preCode;
|
|
703
709
|
options.testOnly = testOnly;
|
|
704
710
|
return this.runSync(code, fname, options);
|
|
@@ -710,7 +716,7 @@ export class NakoCompiler {
|
|
|
710
716
|
* @param [preCode]
|
|
711
717
|
*/
|
|
712
718
|
run(code, fname = 'main.nako3', preCode = '') {
|
|
713
|
-
const options =
|
|
719
|
+
const options = newCompilerOptions();
|
|
714
720
|
options.preCode = preCode;
|
|
715
721
|
return this.runSync(code, fname, options);
|
|
716
722
|
}
|
|
@@ -836,12 +842,11 @@ export class NakoCompiler {
|
|
|
836
842
|
/** (非推奨) 同期的になでしこのプログラムcodeを実行する */
|
|
837
843
|
_runEx(code, filename, opts, preCode = '', nakoGlobal = undefined) {
|
|
838
844
|
// コンパイル
|
|
839
|
-
|
|
840
|
-
options.preCode = preCode;
|
|
845
|
+
opts.preCode = preCode;
|
|
841
846
|
if (nakoGlobal) {
|
|
842
|
-
|
|
847
|
+
opts.nakoGlobal = nakoGlobal;
|
|
843
848
|
}
|
|
844
|
-
return this.runSync(code, filename,
|
|
849
|
+
return this.runSync(code, filename, opts);
|
|
845
850
|
}
|
|
846
851
|
/** (非推奨) 同期的に実行
|
|
847
852
|
* @param code
|
|
@@ -859,6 +864,7 @@ export class NakoCompiler {
|
|
|
859
864
|
* @param [preCode]
|
|
860
865
|
*/
|
|
861
866
|
async runReset(code, fname = 'main.nako3', preCode = '') {
|
|
862
|
-
|
|
867
|
+
const opts = newCompilerOptions({ resetAll: true, resetEnv: true });
|
|
868
|
+
return this._runEx(code, fname, opts, preCode);
|
|
863
869
|
}
|
|
864
870
|
}
|
package/core/src/nako3.mts
CHANGED
|
@@ -61,6 +61,17 @@ export interface NakoResetOption {
|
|
|
61
61
|
needToClearPlugin: boolean
|
|
62
62
|
}
|
|
63
63
|
|
|
64
|
+
/** コンパイラ実行オプションを生成 */
|
|
65
|
+
export function newCompilerOptions (initObj: any = {}): CompilerOptions {
|
|
66
|
+
if (typeof initObj !== 'object') { initObj = {} }
|
|
67
|
+
initObj.testOnly = initObj.testOnly || false
|
|
68
|
+
initObj.resetEnv = initObj.resetEnv || false
|
|
69
|
+
initObj.resetAll = initObj.resetAll || false
|
|
70
|
+
initObj.preCode = initObj.preCode || ''
|
|
71
|
+
initObj.nakoGlobal = initObj.nakoGlobal || null
|
|
72
|
+
return initObj
|
|
73
|
+
}
|
|
74
|
+
|
|
64
75
|
/** なでしこコンパイラ */
|
|
65
76
|
export class NakoCompiler {
|
|
66
77
|
private nakoFuncList: FuncList;
|
|
@@ -567,12 +578,8 @@ export class NakoCompiler {
|
|
|
567
578
|
|
|
568
579
|
/**
|
|
569
580
|
* コードをパースしてASTにする
|
|
570
|
-
* @param code なでしこのプログラム
|
|
571
|
-
* @param filename
|
|
572
|
-
* @param [preCode]
|
|
573
|
-
* @return Ast
|
|
574
581
|
*/
|
|
575
|
-
parse (code: string, filename: string, preCode = '') {
|
|
582
|
+
parse (code: string, filename: string, preCode = ''): Ast {
|
|
576
583
|
// 関数を字句解析と構文解析に登録
|
|
577
584
|
this.lexer.setFuncList(this.funclist)
|
|
578
585
|
this.parser.setFuncList(this.funclist)
|
|
@@ -580,8 +587,7 @@ export class NakoCompiler {
|
|
|
580
587
|
const lexerOutput = this.lex(code, filename, preCode)
|
|
581
588
|
|
|
582
589
|
// 構文木を作成
|
|
583
|
-
|
|
584
|
-
let ast
|
|
590
|
+
let ast: Ast
|
|
585
591
|
try {
|
|
586
592
|
this.parser.genMode = 'sync' // set default
|
|
587
593
|
ast = this.parser.parse(lexerOutput.tokens, filename)
|
|
@@ -591,14 +597,13 @@ export class NakoCompiler {
|
|
|
591
597
|
}
|
|
592
598
|
throw err
|
|
593
599
|
}
|
|
594
|
-
|
|
600
|
+
// 使用したシステム関数の一覧を this.usedFuns に入れる(エディタなどで利用される)
|
|
601
|
+
this.usedFuncs = this.parser.usedFuncs // 全ての関数呼び出し
|
|
602
|
+
this.deleteUnNakoFuncs() // システム関数以外を削除
|
|
595
603
|
this.logger.trace('--- ast ---\n' + JSON.stringify(ast, null, 2))
|
|
596
604
|
return ast
|
|
597
605
|
}
|
|
598
606
|
|
|
599
|
-
/**
|
|
600
|
-
* @param {Ast} ast
|
|
601
|
-
*/
|
|
602
607
|
getUsedFuncs (ast: Ast): Set<string> {
|
|
603
608
|
const queue = [ast]
|
|
604
609
|
this.usedFuncs = new Set()
|
|
@@ -610,7 +615,6 @@ export class NakoCompiler {
|
|
|
610
615
|
this.getUsedAndDefFuncs(queue, JSON.parse(JSON.stringify(ast_.block)))
|
|
611
616
|
}
|
|
612
617
|
}
|
|
613
|
-
|
|
614
618
|
return this.deleteUnNakoFuncs()
|
|
615
619
|
}
|
|
616
620
|
|
|
@@ -649,7 +653,7 @@ export class NakoCompiler {
|
|
|
649
653
|
* @param preCode
|
|
650
654
|
*/
|
|
651
655
|
compile (code: string, filename: string, isTest = false, preCode = ''): string {
|
|
652
|
-
const opt =
|
|
656
|
+
const opt = newCompilerOptions()
|
|
653
657
|
opt.testOnly = isTest
|
|
654
658
|
opt.preCode = preCode
|
|
655
659
|
const res = this.compileFromCode(code, filename, opt)
|
|
@@ -657,8 +661,9 @@ export class NakoCompiler {
|
|
|
657
661
|
}
|
|
658
662
|
|
|
659
663
|
/** parse & generate */
|
|
660
|
-
compileFromCode (code: string, filename: string, options: CompilerOptions): NakoGenResult {
|
|
664
|
+
compileFromCode (code: string, filename: string, options: CompilerOptions|undefined = undefined): NakoGenResult {
|
|
661
665
|
if (filename === '') { filename = 'main.nako3' }
|
|
666
|
+
if (options === undefined) { options = newCompilerOptions() }
|
|
662
667
|
try {
|
|
663
668
|
if (options.resetEnv) { this.reset() }
|
|
664
669
|
if (options.resetAll) { this.clearPlugins() }
|
|
@@ -707,7 +712,7 @@ export class NakoCompiler {
|
|
|
707
712
|
* @param [preCode]
|
|
708
713
|
*/
|
|
709
714
|
async _run (code: string, fname: string, isReset: boolean, isTest: boolean, preCode = ''): Promise<NakoGlobal> {
|
|
710
|
-
const opts: CompilerOptions =
|
|
715
|
+
const opts: CompilerOptions = newCompilerOptions({
|
|
711
716
|
resetEnv: isReset,
|
|
712
717
|
resetAll: isReset,
|
|
713
718
|
testOnly: isTest,
|
|
@@ -747,8 +752,9 @@ export class NakoCompiler {
|
|
|
747
752
|
* @param options オプション
|
|
748
753
|
* @returns 実行に利用したグローバルオブジェクト
|
|
749
754
|
*/
|
|
750
|
-
public runSync (code: string, filename: string, options: CompilerOptions =
|
|
755
|
+
public runSync (code: string, filename: string, options: CompilerOptions|undefined = undefined): NakoGlobal {
|
|
751
756
|
// コンパイル
|
|
757
|
+
options = newCompilerOptions(options)
|
|
752
758
|
const out = this.compileFromCode(code, filename, options)
|
|
753
759
|
// 実行前に環境を生成
|
|
754
760
|
const nakoGlobal = this.getNakoGlobal(options, out.gen)
|
|
@@ -764,8 +770,9 @@ export class NakoCompiler {
|
|
|
764
770
|
* @param options オプション
|
|
765
771
|
* @returns 実行に利用したグローバルオブジェクト
|
|
766
772
|
*/
|
|
767
|
-
public async runAsync (code: string, filename: string, options: CompilerOptions =
|
|
773
|
+
public async runAsync (code: string, filename: string, options: CompilerOptions|undefined = undefined): Promise<NakoGlobal> {
|
|
768
774
|
// コンパイル
|
|
775
|
+
options = newCompilerOptions(options)
|
|
769
776
|
const out = this.compileFromCode(code, filename, options)
|
|
770
777
|
// 実行前に環境を生成
|
|
771
778
|
const nakoGlobal = this.getNakoGlobal(options, out.gen)
|
|
@@ -806,7 +813,7 @@ export class NakoCompiler {
|
|
|
806
813
|
* @param testOnly
|
|
807
814
|
*/
|
|
808
815
|
test (code: string, fname: string, preCode = '', testOnly = false) {
|
|
809
|
-
const options =
|
|
816
|
+
const options = newCompilerOptions()
|
|
810
817
|
options.preCode = preCode
|
|
811
818
|
options.testOnly = testOnly
|
|
812
819
|
return this.runSync(code, fname, options)
|
|
@@ -819,7 +826,7 @@ export class NakoCompiler {
|
|
|
819
826
|
* @param [preCode]
|
|
820
827
|
*/
|
|
821
828
|
run (code: string, fname = 'main.nako3', preCode = ''): NakoGlobal {
|
|
822
|
-
const options =
|
|
829
|
+
const options = newCompilerOptions()
|
|
823
830
|
options.preCode = preCode
|
|
824
831
|
return this.runSync(code, fname, options)
|
|
825
832
|
}
|
|
@@ -946,12 +953,11 @@ export class NakoCompiler {
|
|
|
946
953
|
}
|
|
947
954
|
|
|
948
955
|
/** (非推奨) 同期的になでしこのプログラムcodeを実行する */
|
|
949
|
-
private _runEx (code: string, filename: string, opts:
|
|
956
|
+
private _runEx (code: string, filename: string, opts: CompilerOptions, preCode = '', nakoGlobal: NakoGlobal|undefined = undefined): NakoGlobal {
|
|
950
957
|
// コンパイル
|
|
951
|
-
|
|
952
|
-
|
|
953
|
-
|
|
954
|
-
return this.runSync(code, filename, options)
|
|
958
|
+
opts.preCode = preCode
|
|
959
|
+
if (nakoGlobal) { opts.nakoGlobal = nakoGlobal }
|
|
960
|
+
return this.runSync(code, filename, opts)
|
|
955
961
|
}
|
|
956
962
|
|
|
957
963
|
/** (非推奨) 同期的に実行
|
|
@@ -960,7 +966,7 @@ export class NakoCompiler {
|
|
|
960
966
|
* @param opts
|
|
961
967
|
* @param [preCode]
|
|
962
968
|
*/
|
|
963
|
-
public runEx (code: string, fname: string, opts:
|
|
969
|
+
public runEx (code: string, fname: string, opts: CompilerOptions, preCode = '') {
|
|
964
970
|
return this._runEx(code, fname, opts, preCode)
|
|
965
971
|
}
|
|
966
972
|
|
|
@@ -971,6 +977,7 @@ export class NakoCompiler {
|
|
|
971
977
|
* @param [preCode]
|
|
972
978
|
*/
|
|
973
979
|
async runReset (code: string, fname = 'main.nako3', preCode = ''): Promise<NakoGlobal> {
|
|
974
|
-
|
|
980
|
+
const opts = newCompilerOptions({ resetAll: true, resetEnv: true })
|
|
981
|
+
return this._runEx(code, fname, opts, preCode)
|
|
975
982
|
}
|
|
976
983
|
}
|
|
@@ -12,9 +12,6 @@ import { NewEmptyToken } from './nako_types.mjs';
|
|
|
12
12
|
export class NakoParser extends NakoParserBase {
|
|
13
13
|
/**
|
|
14
14
|
* 構文解析を実行する
|
|
15
|
-
* @param {TokenWithSourceMap[]} tokens 字句解析済みのトークンの配列
|
|
16
|
-
* @param {string} filename 解析対象のモジュール名
|
|
17
|
-
* @return {Ast} AST(構文木)
|
|
18
15
|
*/
|
|
19
16
|
parse(tokens, filename) {
|
|
20
17
|
this.reset();
|
|
@@ -1481,6 +1478,7 @@ export class NakoParser extends NakoParserBase {
|
|
|
1481
1478
|
if (nullCount >= 2 && (valueCount > 0 || t.josi === '' || keizokuJosi.indexOf(t.josi) >= 0)) {
|
|
1482
1479
|
throw NakoSyntaxError.fromNode(`関数『${t.value}』の引数が不足しています。`, t);
|
|
1483
1480
|
}
|
|
1481
|
+
this.usedFuncs.add(t.value);
|
|
1484
1482
|
// 関数呼び出しのAstを構築
|
|
1485
1483
|
const funcNode = {
|
|
1486
1484
|
type: 'func',
|
|
@@ -1580,6 +1578,7 @@ export class NakoParser extends NakoParserBase {
|
|
|
1580
1578
|
throw new Error(`助詞『${josiStr}』が見当たりません。`);
|
|
1581
1579
|
});
|
|
1582
1580
|
}
|
|
1581
|
+
this.usedFuncs.add(funcName);
|
|
1583
1582
|
// funcノードを返す
|
|
1584
1583
|
return {
|
|
1585
1584
|
type: 'func',
|
|
@@ -2094,6 +2093,7 @@ export class NakoParser extends NakoParserBase {
|
|
|
2094
2093
|
throw new Error('[System Error] 正しく値が取れませんでした。');
|
|
2095
2094
|
}
|
|
2096
2095
|
const f = this.getVarNameRef(tt);
|
|
2096
|
+
this.usedFuncs.add(f.value);
|
|
2097
2097
|
return {
|
|
2098
2098
|
type: 'func',
|
|
2099
2099
|
name: f.value,
|
|
@@ -2107,9 +2107,11 @@ export class NakoParser extends NakoParserBase {
|
|
|
2107
2107
|
if (this.check2([['func', 'word'], '(']) && this.peekDef().josi === '') {
|
|
2108
2108
|
const f = this.peek();
|
|
2109
2109
|
if (this.accept([['func', 'word'], '(', this.yGetArgParen, ')'])) {
|
|
2110
|
+
const funcName = this.getVarNameRef(this.y[0]).value;
|
|
2111
|
+
this.usedFuncs.add(funcName);
|
|
2110
2112
|
return {
|
|
2111
2113
|
type: 'func',
|
|
2112
|
-
name:
|
|
2114
|
+
name: funcName,
|
|
2113
2115
|
args: this.y[2],
|
|
2114
2116
|
josi: this.y[3].josi,
|
|
2115
2117
|
...map,
|
|
@@ -13,9 +13,6 @@ import { Token, Ast, FuncListItem, FuncArgs, NewEmptyToken, SourceMap } from './
|
|
|
13
13
|
export class NakoParser extends NakoParserBase {
|
|
14
14
|
/**
|
|
15
15
|
* 構文解析を実行する
|
|
16
|
-
* @param {TokenWithSourceMap[]} tokens 字句解析済みのトークンの配列
|
|
17
|
-
* @param {string} filename 解析対象のモジュール名
|
|
18
|
-
* @return {Ast} AST(構文木)
|
|
19
16
|
*/
|
|
20
17
|
parse (tokens: Token[], filename: string): Ast {
|
|
21
18
|
this.reset()
|
|
@@ -1297,6 +1294,7 @@ export class NakoParser extends NakoParserBase {
|
|
|
1297
1294
|
if (nullCount >= 2 && (valueCount > 0 || t.josi === '' || keizokuJosi.indexOf(t.josi) >= 0)) {
|
|
1298
1295
|
throw NakoSyntaxError.fromNode(`関数『${t.value}』の引数が不足しています。`, t)
|
|
1299
1296
|
}
|
|
1297
|
+
this.usedFuncs.add(t.value)
|
|
1300
1298
|
// 関数呼び出しのAstを構築
|
|
1301
1299
|
const funcNode: Ast = {
|
|
1302
1300
|
type: 'func',
|
|
@@ -1384,6 +1382,7 @@ export class NakoParser extends NakoParserBase {
|
|
|
1384
1382
|
throw new Error(`助詞『${josiStr}』が見当たりません。`)
|
|
1385
1383
|
})
|
|
1386
1384
|
}
|
|
1385
|
+
this.usedFuncs.add(funcName)
|
|
1387
1386
|
// funcノードを返す
|
|
1388
1387
|
return {
|
|
1389
1388
|
type: 'func',
|
|
@@ -1877,6 +1876,7 @@ export class NakoParser extends NakoParserBase {
|
|
|
1877
1876
|
const tt = this.get()
|
|
1878
1877
|
if (!tt) { throw new Error('[System Error] 正しく値が取れませんでした。') }
|
|
1879
1878
|
const f = this.getVarNameRef(tt)
|
|
1879
|
+
this.usedFuncs.add(f.value)
|
|
1880
1880
|
return {
|
|
1881
1881
|
type: 'func',
|
|
1882
1882
|
name: f.value,
|
|
@@ -1890,9 +1890,11 @@ export class NakoParser extends NakoParserBase {
|
|
|
1890
1890
|
if (this.check2([['func', 'word'], '(']) && this.peekDef().josi === '') {
|
|
1891
1891
|
const f = this.peek()
|
|
1892
1892
|
if (this.accept([['func', 'word'], '(', this.yGetArgParen, ')'])) {
|
|
1893
|
+
const funcName: string = this.getVarNameRef(this.y[0]).value
|
|
1894
|
+
this.usedFuncs.add(funcName)
|
|
1893
1895
|
return {
|
|
1894
1896
|
type: 'func',
|
|
1895
|
-
name:
|
|
1897
|
+
name: funcName,
|
|
1896
1898
|
args: this.y[2],
|
|
1897
1899
|
josi: this.y[3].josi,
|
|
1898
1900
|
...map,
|
|
@@ -14,6 +14,7 @@ export class NakoParserBase {
|
|
|
14
14
|
public modName: string;
|
|
15
15
|
public modList: string[];
|
|
16
16
|
public funclist: FuncList;
|
|
17
|
+
public usedFuncs: Set<string>;
|
|
17
18
|
protected funcLevel: number;
|
|
18
19
|
protected usedAsyncFn: boolean;
|
|
19
20
|
protected localvars: FuncList;
|
|
@@ -27,6 +28,7 @@ export class NakoParserBase {
|
|
|
27
28
|
this.logger = logger
|
|
28
29
|
this.stackList = [] // 関数定義の際にスタックが混乱しないように整理する
|
|
29
30
|
this.tokens = []
|
|
31
|
+
this.usedFuncs = new Set()
|
|
30
32
|
/** @type {import('./nako3.mjs').Ast[]} */
|
|
31
33
|
this.stack = []
|
|
32
34
|
this.index = 0
|
package/core/src/nako_types.mjs
CHANGED
|
@@ -11,15 +11,3 @@ export function NewEmptyToken(type = '?', value = {}, line = 0, file = 'main.nak
|
|
|
11
11
|
josi: ''
|
|
12
12
|
};
|
|
13
13
|
}
|
|
14
|
-
/**
|
|
15
|
-
* コンパイルオプション
|
|
16
|
-
*/
|
|
17
|
-
export class CompilerOptions {
|
|
18
|
-
constructor(initObj = {}) {
|
|
19
|
-
this.testOnly = initObj.testOnly || false;
|
|
20
|
-
this.resetEnv = initObj.resetEnv || false;
|
|
21
|
-
this.resetAll = initObj.resetAll || false;
|
|
22
|
-
this.preCode = initObj.preCode || '';
|
|
23
|
-
this.nakoGlobal = initObj.nakoGlobal || null;
|
|
24
|
-
}
|
|
25
|
-
}
|
package/core/src/nako_types.mts
CHANGED
|
@@ -128,19 +128,12 @@ export interface SourceMap {
|
|
|
128
128
|
/**
|
|
129
129
|
* コンパイルオプション
|
|
130
130
|
*/
|
|
131
|
-
export
|
|
131
|
+
export interface CompilerOptions {
|
|
132
132
|
resetEnv: boolean; // 現在の環境をリセット
|
|
133
133
|
testOnly: boolean; // テストだけを実行する
|
|
134
134
|
resetAll: boolean; // 全ての環境をリセット
|
|
135
135
|
preCode: string; // 環境を構築するためのコード
|
|
136
136
|
nakoGlobal: NakoGlobal | null; // 実行に使う環境
|
|
137
|
-
constructor (initObj: any = {}) {
|
|
138
|
-
this.testOnly = initObj.testOnly || false
|
|
139
|
-
this.resetEnv = initObj.resetEnv || false
|
|
140
|
-
this.resetAll = initObj.resetAll || false
|
|
141
|
-
this.preCode = initObj.preCode || ''
|
|
142
|
-
this.nakoGlobal = initObj.nakoGlobal || null
|
|
143
|
-
}
|
|
144
137
|
}
|
|
145
138
|
|
|
146
139
|
export type NakoComEventName = 'finish' | 'beforeRun' | 'beforeGenerate' | 'afterGenerate' | 'beforeParse'
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "nadesiko3",
|
|
3
|
-
"version": "3.3.
|
|
3
|
+
"version": "3.3.52",
|
|
4
4
|
"description": "Japanese Programming Language",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "src/index.mjs",
|
|
@@ -13,11 +13,11 @@
|
|
|
13
13
|
"start": "node tools/nako3server/index.mjs",
|
|
14
14
|
"nako3server": "node tools/nako3server/index.mjs",
|
|
15
15
|
"nako3edit": "node tools/nako3edit/index.mjs",
|
|
16
|
-
"test": "
|
|
17
|
-
"test:
|
|
18
|
-
"test:
|
|
16
|
+
"test": "npm run test:core && npm run test:node && npm run test:common",
|
|
17
|
+
"test:core": "mocha core/test",
|
|
18
|
+
"test:node": "mocha test/node",
|
|
19
|
+
"test:common": "cross-env TZ=Asia/Tokyo mocha test/common",
|
|
19
20
|
"test:async": "mocha test/async -g aysnc_basic_test",
|
|
20
|
-
"test:common": "cross-env TZ=Asia/Tokyo NODE_ENV=development karma start --single-run --browsers FirefoxCustomHeadless --reporters=mocha test/karma.config.js",
|
|
21
21
|
"test:browser": "cross-env TZ=Asia/Tokyo NODE_ENV=development karma start --single-run --browsers FirefoxCustomHeadless --reporters=mocha test/browser/karma.config.js",
|
|
22
22
|
"test:bundled": "cross-env TZ=Asia/Tokyo NODE_ENV=development karma start --single-run --browsers FirefoxCustomHeadless test/bundled/karma.config.js",
|
|
23
23
|
"test:bundled:watch": "cross-env TZ=Asia/Tokyo NODE_ENV=development karma start --auto-watch --browsers FirefoxCustom test/bundled/karma.config.js",
|
package/release/_hash.txt
CHANGED
|
@@ -54,17 +54,17 @@ plugin_weykturtle3d.js:
|
|
|
54
54
|
sha256(base64): ND/1JqYrFVGTIPYsbBk+tScnF8RVzgYPM0/E2aE8GRw=
|
|
55
55
|
sha512(base64): T4B8Cvhn9j5YdMGk4rwPInfqmcXtGEjD2g6X6wSqXvYyIXuSy+t1RVf1viZ2zljHlk3wN6pwKvvg/NIJvfMAzw==
|
|
56
56
|
version.js:
|
|
57
|
-
md5(hex):
|
|
58
|
-
sha256(hex):
|
|
59
|
-
sha256(base64):
|
|
60
|
-
sha512(base64):
|
|
57
|
+
md5(hex): 604fdf2812a87745fbe574888468033b
|
|
58
|
+
sha256(hex): a590ffdefb1e2138cff1764dab3dc53dcfcb7e78a56e6d36fd3f2196b022b0f3
|
|
59
|
+
sha256(base64): pZD/3vseITjP8XZNqz3FPc/Lfnilbm02/T8hlrAisPM=
|
|
60
|
+
sha512(base64): HxiXnZmQOxwyyb4nuISDUAZDxCejv2qPrQ+TFvV+C+3roYcGr88R49rubpUFigsWmWeo6UfBBnFfurhoULB4tg==
|
|
61
61
|
wnako3.js:
|
|
62
|
-
md5(hex):
|
|
63
|
-
sha256(hex):
|
|
64
|
-
sha256(base64):
|
|
65
|
-
sha512(base64):
|
|
62
|
+
md5(hex): be991ed88d9554162a6abbb8df013232
|
|
63
|
+
sha256(hex): 0c057b81fffbe0a1031abc3e69803bdfc05bc1c116de1e1ecd9dc4e8448d6243
|
|
64
|
+
sha256(base64): DAV7gf/74KEDGrw+aYA738BbwcEW3h4ezZ3E6ESNYkM=
|
|
65
|
+
sha512(base64): Ky1VMY8s8KZH5P/EcWWU1wX9I45dz1K+Xt3/x1Ow6wzFxf1V6bICc+WKNWP/Z8IWB2WEUd0vhKnjS2ZVoGRfWg==
|
|
66
66
|
wnako3webworker.js:
|
|
67
|
-
md5(hex):
|
|
68
|
-
sha256(hex):
|
|
69
|
-
sha256(base64):
|
|
70
|
-
sha512(base64):
|
|
67
|
+
md5(hex): 0d06af5529e5ada6e084bb790699fea1
|
|
68
|
+
sha256(hex): 7885955e8cc3a0f3fe5422b1a582105d31f6370e2afc7f6c1ff53d9894c49788
|
|
69
|
+
sha256(base64): eIWVXozDoPP+VCKxpYIQXTH2Nw4q/H9sH/U9mJTEl4g=
|
|
70
|
+
sha512(base64): bRCgX7J/A34du3xGAhmOWobEeeq6En3Zcdi4GdxA4GJjjtQSsZz9yJ7/2Q0s9tMJyzcjhz0h7y9pRfrUbNttZw==
|
package/release/_script-tags.txt
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
<script defer src="https://nadesi.com/v3/cdn.php?v=3.3.
|
|
2
|
-
<script defer src="https://nadesi.com/v3/cdn.php?v=3.3.
|
|
3
|
-
<script defer src="https://nadesi.com/v3/cdn.php?v=3.3.
|
|
4
|
-
<script defer src="https://nadesi.com/v3/cdn.php?v=3.3.
|
|
5
|
-
<script defer src="https://nadesi.com/v3/cdn.php?v=3.3.
|
|
6
|
-
<script defer src="https://nadesi.com/v3/cdn.php?v=3.3.
|
|
7
|
-
<script defer src="https://nadesi.com/v3/cdn.php?v=3.3.
|
|
8
|
-
<script defer src="https://nadesi.com/v3/cdn.php?v=3.3.
|
|
9
|
-
<script defer src="https://nadesi.com/v3/cdn.php?v=3.3.
|
|
10
|
-
<script defer src="https://nadesi.com/v3/cdn.php?v=3.3.
|
|
11
|
-
<script defer src="https://nadesi.com/v3/cdn.php?v=3.3.
|
|
12
|
-
<script defer src="https://nadesi.com/v3/cdn.php?v=3.3.
|
|
13
|
-
<script defer src="https://nadesi.com/v3/cdn.php?v=3.3.
|
|
14
|
-
<script defer src="https://nadesi.com/v3/cdn.php?v=3.3.
|
|
1
|
+
<script defer src="https://nadesi.com/v3/cdn.php?v=3.3.52&f=release/command.json.js" integrity="sha512-amSpft8keA6AyQ55uzbk1L78UMyv6EA2YeESukiT4sDIbrwEo+XVNleuy2FCN2k1ANGiDrZ9mRuHtXAh2lnQFA==" crossorigin="anonymous"></script>
|
|
2
|
+
<script defer src="https://nadesi.com/v3/cdn.php?v=3.3.52&f=release/editor.js" integrity="sha512-Y6iT28EVKl6MupxHc11oiY17JLzBluHR7yJmoW2l0s9uvdWkdUywfBmviX68TAVyPkWm+E0xfx5z29IeYBOu/w==" crossorigin="anonymous"></script>
|
|
3
|
+
<script defer src="https://nadesi.com/v3/cdn.php?v=3.3.52&f=release/nako_gen_async.js" integrity="sha512-jY4vgaTISc9f3qQBt4iuixx8GMtAXL+V8h868RotnXqW8yy+aBsa8huKHA+5tTKvk5WTFZDwc/XkYr71oXWsFQ==" crossorigin="anonymous"></script>
|
|
4
|
+
<script defer src="https://nadesi.com/v3/cdn.php?v=3.3.52&f=release/plugin_caniuse.js" integrity="sha512-NbX6BKUNq1J8xwtv5CThQC54Lb/KxaPlimRpsF745nxqjYeuGD7S70j4yOgNm4Uwd7AN5FgezS6NDyhlvoJF2w==" crossorigin="anonymous"></script>
|
|
5
|
+
<script defer src="https://nadesi.com/v3/cdn.php?v=3.3.52&f=release/plugin_csv.js" integrity="sha512-mQvmj25L2Nc2L7gN1rTjayHVMMPhc7TCSiBsuKS4JKOQqN+91uj9qpLAOejzR1ib5jIOBdtrhN+secNTU9BJtw==" crossorigin="anonymous"></script>
|
|
6
|
+
<script defer src="https://nadesi.com/v3/cdn.php?v=3.3.52&f=release/plugin_datetime.js" integrity="sha512-1ADTZFkcfU6vpEEJZEYmIbqS6G2XViooDFD4198P61n7VKZ0PhEVj9l8ULFGrW7woSbDqfSPZmkZ7yvcRqPKYA==" crossorigin="anonymous"></script>
|
|
7
|
+
<script defer src="https://nadesi.com/v3/cdn.php?v=3.3.52&f=release/plugin_kansuji.js" integrity="sha512-tXC9Q6LejwYG+HUbXcwBHFmhwTsqiMHOBohLNcSx8b02hxk3waPUEQRWeNP7QxAFMv5BOAY+Grruf+XKmmU26g==" crossorigin="anonymous"></script>
|
|
8
|
+
<script defer src="https://nadesi.com/v3/cdn.php?v=3.3.52&f=release/plugin_markup.js" integrity="sha512-pvb+QYO9LMUH055nPJJ5QaWyEYR3wDkHHilV5LLNyxObs7enlHGiF7Jt3Csd93JTdJ3n9hxFbTqWa1QuzVmTfQ==" crossorigin="anonymous"></script>
|
|
9
|
+
<script defer src="https://nadesi.com/v3/cdn.php?v=3.3.52&f=release/plugin_turtle.js" integrity="sha512-3/BlAe3uVDBgJrgFWzLJa3bvNQVhAQuL343Icict5hI3LndcPjV6mAD8KoWRlxmF8A8S6n8eKnmrh6NFWTjyEw==" crossorigin="anonymous"></script>
|
|
10
|
+
<script defer src="https://nadesi.com/v3/cdn.php?v=3.3.52&f=release/plugin_webworker.js" integrity="sha512-i+Z6Tg1xuS7TmJx/NrvGlEgPRGR9VUvaN6aqi5zVu1YpdabJ2p4rXWXNx3aBj6brCQ7co+D7Y+RhLm3S3gbXPQ==" crossorigin="anonymous"></script>
|
|
11
|
+
<script defer src="https://nadesi.com/v3/cdn.php?v=3.3.52&f=release/plugin_weykturtle3d.js" integrity="sha512-T4B8Cvhn9j5YdMGk4rwPInfqmcXtGEjD2g6X6wSqXvYyIXuSy+t1RVf1viZ2zljHlk3wN6pwKvvg/NIJvfMAzw==" crossorigin="anonymous"></script>
|
|
12
|
+
<script defer src="https://nadesi.com/v3/cdn.php?v=3.3.52&f=release/version.js" integrity="sha512-HxiXnZmQOxwyyb4nuISDUAZDxCejv2qPrQ+TFvV+C+3roYcGr88R49rubpUFigsWmWeo6UfBBnFfurhoULB4tg==" crossorigin="anonymous"></script>
|
|
13
|
+
<script defer src="https://nadesi.com/v3/cdn.php?v=3.3.52&f=release/wnako3.js" integrity="sha512-Ky1VMY8s8KZH5P/EcWWU1wX9I45dz1K+Xt3/x1Ow6wzFxf1V6bICc+WKNWP/Z8IWB2WEUd0vhKnjS2ZVoGRfWg==" crossorigin="anonymous"></script>
|
|
14
|
+
<script defer src="https://nadesi.com/v3/cdn.php?v=3.3.52&f=release/wnako3webworker.js" integrity="sha512-bRCgX7J/A34du3xGAhmOWobEeeq6En3Zcdi4GdxA4GJjjtQSsZz9yJ7/2Q0s9tMJyzcjhz0h7y9pRfrUbNttZw==" crossorigin="anonymous"></script>
|