nadesiko3 3.3.53 → 3.3.56

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (110) hide show
  1. package/batch/command.txt +2 -1
  2. package/batch/command_nakopad.txt +1 -0
  3. package/core/.editorconfig +6 -0
  4. package/core/.eslintrc.cjs +33 -0
  5. package/core/.github/dependabot.yml +7 -0
  6. package/core/.github/workflows/nodejs.yml +37 -0
  7. package/core/.github/workflows/super-linter.yml +61 -0
  8. package/core/.github/workflows/textlint.yml +199 -0
  9. package/core/README.md +4 -0
  10. package/core/doc/README.md +67 -0
  11. package/core/index.mjs +2 -2
  12. package/core/index.mts +21 -0
  13. package/core/package.json +1 -1
  14. package/core/src/nako3.mjs +23 -12
  15. package/core/src/nako3.mts +23 -13
  16. package/core/src/nako_core_version.mjs +2 -2
  17. package/core/src/nako_core_version.mts +2 -2
  18. package/core/src/nako_errors.mjs +1 -8
  19. package/core/src/nako_errors.mts +2 -8
  20. package/core/src/nako_gen.mjs +8 -8
  21. package/core/src/nako_gen.mts +8 -8
  22. package/core/src/nako_global.mjs +7 -4
  23. package/core/src/nako_global.mts +9 -4
  24. package/core/src/nako_lexer.mjs +4 -4
  25. package/core/src/nako_lexer.mts +4 -4
  26. package/core/src/nako_logger.mjs +6 -1
  27. package/core/src/nako_logger.mts +7 -1
  28. package/core/src/nako_parser_base.mjs +1 -1
  29. package/core/src/nako_parser_base.mts +1 -1
  30. package/core/test/array_test.mjs +34 -0
  31. package/core/test/basic_test.mjs +344 -0
  32. package/core/test/calc_test.mjs +140 -0
  33. package/core/test/core_module_test.mjs +23 -0
  34. package/core/test/debug_test.mjs +16 -0
  35. package/core/test/dncl_test.mjs +94 -0
  36. package/core/test/error_message_test.mjs +210 -0
  37. package/core/test/error_test.mjs +16 -0
  38. package/core/test/flow_test.mjs +373 -0
  39. package/core/test/func_call.mjs +163 -0
  40. package/core/test/func_test.mjs +149 -0
  41. package/core/test/indent_test.mjs +364 -0
  42. package/core/test/lex_test.mjs +168 -0
  43. package/core/test/literal_test.mjs +73 -0
  44. package/core/test/nako_lexer_test.mjs +35 -0
  45. package/core/test/nako_logger_test.mjs +76 -0
  46. package/core/test/plugin_csv_test.mjs +38 -0
  47. package/core/test/plugin_promise_test.mjs +18 -0
  48. package/core/test/plugin_system_test.mjs +630 -0
  49. package/core/test/prepare_test.mjs +96 -0
  50. package/core/test/re_test.mjs +22 -0
  51. package/core/test/side_effects_test.mjs +98 -0
  52. package/core/test/variable_scope_test.mjs +149 -0
  53. package/core/tsconfig.json +101 -0
  54. package/demo/nako3/rpn.mjs +39 -0
  55. package/demo/nako3/test.js +22 -0
  56. package/demo/nako3/test.mjs +45 -0
  57. package/doc/plugins.md +35 -0
  58. package/package.json +11 -10
  59. package/release/_hash.txt +28 -28
  60. package/release/_script-tags.txt +14 -14
  61. package/release/command.json +1 -1
  62. package/release/command.json.js +1 -1
  63. package/release/command_cnako3.json +1 -1
  64. package/release/command_list.json +1 -1
  65. package/release/editor.js +1 -1
  66. package/release/nako_gen_async.js +1 -1
  67. package/release/plugin_webworker.js +1 -1
  68. package/release/stats.json +1 -1
  69. package/release/version.js +1 -1
  70. package/release/wnako3.js +1 -1
  71. package/release/wnako3webworker.js +1 -1
  72. package/src/cnako3mod.mjs +9 -14
  73. package/src/cnako3mod.mts +9 -13
  74. package/src/nako_version.mjs +2 -2
  75. package/src/nako_version.mts +2 -2
  76. package/src/plugin_browser_hotkey.mjs +2 -1
  77. package/src/plugin_browser_in_worker.mjs +0 -1
  78. package/src/plugin_webworker.mjs +4 -2
  79. package/src/wnako3_editor.mjs +5 -21
  80. package/src/wnako3_editor.mts +14 -31
  81. package/src/wnako3mod.mjs +155 -115
  82. package/src/wnako3mod.mts +145 -111
  83. package/src/wnako3webworker.mjs +3 -4
  84. package/test/ace_editor/{karma.config.js → karma.config.cjs} +7 -4
  85. package/test/browser/{karma.config.js → karma.config.cjs} +11 -10
  86. package/test/browser/test/compare_util.js +3 -1
  87. package/test/browser/test/plugin_browser_test_ajax.js +2 -1
  88. package/test/browser/test/plugin_browser_test_color.js +1 -1
  89. package/test/browser/test/plugin_browser_test_dialog.js +1 -1
  90. package/test/browser/test/plugin_browser_test_dom_event.js +1 -1
  91. package/test/browser/test/plugin_browser_test_dom_parts.js +1 -1
  92. package/test/browser/test/plugin_browser_test_system.js +1 -2
  93. package/test/browser/test/plugin_webworker_test.js +1 -1
  94. package/test/browser/test/require_test.js +1 -1
  95. package/test/bundled/{karma.config.js → karma.config.cjs} +0 -0
  96. package/test/{karma.config.js → karma.config.cjs} +0 -0
  97. package/tools/nako3server/index.mjs +3 -0
  98. package/batch/.DS_Store +0 -0
  99. package/demo/.DS_Store +0 -0
  100. package/demo/extlib/.DS_Store +0 -0
  101. package/src/.DS_Store +0 -0
  102. package/test/.DS_Store +0 -0
  103. package/test/browser/.DS_Store +0 -0
  104. package/test/bundled/.DS_Store +0 -0
  105. package/test/bundled/test_base/.DS_Store +0 -0
  106. package/test/common/.DS_Store +0 -0
  107. package/test/node/.DS_Store +0 -0
  108. package/tools/.DS_Store +0 -0
  109. package/tools/nako3edit/.DS_Store +0 -0
  110. package/tools/nako3edit/html/.DS_Store +0 -0
package/batch/command.txt CHANGED
@@ -579,7 +579,7 @@
579
579
  | 関数 | オーディオ再生位置設定 | OBJをVに/Vへ | AudioオブジェクトOBJを指定してオーディの位置を数値Vで設定する | おーでぃおさいせい | https://github.com/kujirahand/nadesiko3/blob/master/src/plugin_browser_audio.mjs#L103
580
580
  ●ホットキー
581
581
  | 関数 | ホットキー登録 | KEYにFNAMEを/KEYで | ホットキーKEYにEVENTを登録する | ほっときーとうろく | https://github.com/kujirahand/nadesiko3/blob/master/src/plugin_browser_hotkey.mjs#L10
582
- | 関数 | ホットキー解除 | KEYを/KEYの | ホットキーKEYを解除する | ほっときーかいじょ | https://github.com/kujirahand/nadesiko3/blob/master/src/plugin_browser_hotkey.mjs#L21
582
+ | 関数 | ホットキー解除 | KEYを/KEYの | ホットキーKEYを解除する | ほっときーかいじょ | https://github.com/kujirahand/nadesiko3/blob/master/src/plugin_browser_hotkey.mjs#L22
583
583
  ●グラフ描画_CHARTJS
584
584
  | 関数 | グラフ描画 | DATAを/DATAで/DATAの | Chart.jsを利用して、DATAのグラフを描画 | ぐらふびょうが | https://github.com/kujirahand/nadesiko3/blob/master/src/plugin_browser_chart.mjs#L8
585
585
  | 定数 | グラフオプション | | {} | ぐらふおぷしょん | https://github.com/kujirahand/nadesiko3/blob/master/src/plugin_browser_chart.mjs#L30
@@ -1033,6 +1033,7 @@
1033
1033
  ■plugin_php(基本プラグイン,phpnako)
1034
1034
  ●PHP定数
1035
1035
  | 定数 | PHPバージョン | | phpversion() | PHPばーじょん | https://github.com/kujirahand/nadesiko3php/blob/master/src/plugin_php.php#L90
1036
+ | 定数 | PLUGIN_PHPバージョン | | '0.0.1' | PLUGIN_PHPばーじょん | https://github.com/kujirahand/nadesiko3php/blob/master/src/plugin_php.php#L90
1036
1037
  ●PHPシステム
1037
1038
  | 関数 | PHP取込 | FILEを/FILEの/FILEから | PHPファイルを取り込む。 | PHPとりこむ | https://github.com/kujirahand/nadesiko3php/blob/master/src/plugin_php.php#L90
1038
1039
  | 関数 | セッション開始 | | PHPセッションを開始する。 | せっしょんかいし | https://github.com/kujirahand/nadesiko3php/blob/master/src/plugin_php.php#L90
@@ -981,6 +981,7 @@
981
981
  + plugin_php(��{�v���O�C��,phpnako)
982
982
  - PHP�萔
983
983
  |PHP�o�[�W����,"","phpversion()",0,,�ϐ�,PHP�΁[�����
984
+ |PLUGIN_PHP�o�[�W����,"","'0.0.1'",0,,�ϐ�,PLUGIN_PHP�΁[�����
984
985
  - PHP�V�X�e��
985
986
  |PHP�捞,"FILE��|FILE��|FILE����","PHP�t�@�C������荞�ށB",0,,����,PHP�Ƃ肱��
986
987
  |�Z�b�V�����J�n,"","PHP�Z�b�V�������J�n����B",0,,����,��������񂩂���
@@ -0,0 +1,6 @@
1
+ [*]
2
+ charset = utf-8
3
+ end_of_line = lf
4
+ insert_final_newline = true
5
+ indent_style = space
6
+ indent_size = 2
@@ -0,0 +1,33 @@
1
+ module.exports = {
2
+ "env": {
3
+ "browser": true,
4
+ "commonjs": false,
5
+ "es2021": true
6
+ },
7
+ "extends": [
8
+ "standard",
9
+ "standard-with-typescript",
10
+ "eslint:recommended",
11
+ "plugin:@typescript-eslint/recommended"
12
+ ],
13
+ "parserOptions": {
14
+ "ecmaVersion": "latest",
15
+ "sourceType": "module",
16
+ "project": "./tsconfig.json",
17
+ "extraFileExtensions": [".mts", ".mjs"]
18
+ },
19
+ "rules": {
20
+ "quote-props": "off", // 重要
21
+ "@typescript-eslint/no-explicit-any": "off", // any型を認めないをオフ
22
+ "@typescript-eslint/explicit-module-boundary-types": "off", // 型の指定に関する警告をオフ
23
+ "@typescript-eslint/ban-ts-comment": "off", // @ts-nocheck を許さないをオフ
24
+ //"@typescript-eslint/no-unused-vars": 0,
25
+ //"@typescript-eslint/no-empty-function": 0,
26
+ // "no-unused-vars":0,
27
+ // "no-undef": 0
28
+ },
29
+ "plugins": [
30
+ "@typescript-eslint"
31
+ ],
32
+ "root": true
33
+ }
@@ -0,0 +1,7 @@
1
+ version: 2
2
+ updates:
3
+ - package-ecosystem: npm
4
+ directory: "/"
5
+ schedule:
6
+ interval: daily
7
+ open-pull-requests-limit: 10
@@ -0,0 +1,37 @@
1
+ # This workflow will do a clean install of node dependencies, build the source code and run tests across different versions of node
2
+ # For more information see: https://help.github.com/actions/language-and-framework-guides/using-nodejs-with-github-actions
3
+
4
+ # (memo)
5
+ # GitHubで頻繁にブラウザテストが失敗するので
6
+ # コミット時のテストを簡易化しています。
7
+ # ただし、リリース前には必ず全テスト実行するように
8
+ # publish用のスクリプトを追加してミスを防ぎます。
9
+ # [詳細] https://github.com/kujirahand/nadesiko3/issues/1037
10
+
11
+ name: Node.js CI
12
+
13
+ on:
14
+ push:
15
+ branches: [ master ]
16
+ pull_request:
17
+ branches: [ master ]
18
+
19
+ jobs:
20
+ build:
21
+
22
+ runs-on: ubuntu-latest
23
+
24
+ strategy:
25
+ matrix:
26
+ node-version: [16.x, 14.x, 12.x]
27
+
28
+ steps:
29
+ - uses: actions/checkout@v2
30
+ - name: Use Node.js ${{ matrix.node-version }}
31
+ uses: actions/setup-node@v1
32
+ with:
33
+ node-version: ${{ matrix.node-version }}
34
+ - run: npm install
35
+ - run: npm run build
36
+ - run: npm run test
37
+
@@ -0,0 +1,61 @@
1
+ ###########################
2
+ ###########################
3
+ ## Linter GitHub Actions ##
4
+ ###########################
5
+ ###########################
6
+ name: Lint Code Base
7
+
8
+ #
9
+ # Documentation:
10
+ # https://help.github.com/en/articles/workflow-syntax-for-github-actions
11
+ #
12
+
13
+ #############################
14
+ # Start the job on all push #
15
+ #############################
16
+ on:
17
+ push:
18
+ branches:
19
+ - master
20
+ pull_request:
21
+
22
+ ###############
23
+ # Set the Job #
24
+ ###############
25
+ jobs:
26
+ build:
27
+ # Name the Job
28
+ name: Lint Code Base
29
+ # Set the agent to run on
30
+ runs-on: ubuntu-latest
31
+
32
+ ##################
33
+ # Load all steps #
34
+ ##################
35
+ steps:
36
+ ##########################
37
+ # Checkout the code base #
38
+ ##########################
39
+ - name: Checkout Code
40
+ uses: actions/checkout@v2
41
+ with:
42
+ # Full git history is needed to get a proper list of changed files within `super-linter`
43
+ fetch-depth: 0
44
+
45
+ ################################
46
+ # Run Linter against code base #
47
+ ################################
48
+ - name: Lint Code Base
49
+ uses: github/super-linter@v4.5.1
50
+ env:
51
+ GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
52
+ # 本質でないバリデータを排除(余力があればtrueにして直す)
53
+ VALIDATE_EDITORCONFIG: true
54
+ VALIDATE_JAVASCRIPT_STANDARD: true
55
+ VALIDATE_MARKDOWN: true
56
+ VALIDATE_CSS: false
57
+ VALIDATE_BASH: false
58
+ VALIDATE_HTML: false
59
+ VALIDATE_JSCPD: false
60
+ VALIDATE_JSON: false
61
+
@@ -0,0 +1,199 @@
1
+ name: textlint CI
2
+
3
+ # pull_requestで何かあった時に起動する
4
+ on:
5
+ pull_request:
6
+
7
+ jobs:
8
+ # textlintをかけ、結果をPRにコメントとして表示する。
9
+ lint:
10
+ runs-on: ubuntu-latest
11
+ strategy:
12
+ matrix:
13
+ node-version: [ 16.x ]
14
+
15
+ steps:
16
+ - uses: actions/checkout@v2
17
+ with:
18
+ fetch-depth: 0
19
+ - name: Use Node.js ${{ matrix.node-version }}
20
+ uses: actions/setup-node@v1.4.4
21
+ with:
22
+ node-version: ${{ matrix.node-version }}
23
+ - name: Install dependencies
24
+ run: |
25
+ yarn install -D
26
+ # lintする
27
+ - name: Lint files
28
+ id: lint
29
+ run: |
30
+ result="$(yarn run textlint 2>&1)" || true
31
+ echo "$result"
32
+ result="${result//'%'/'%25'}"
33
+ result="${result//$'\n'/'%0A'}"
34
+ result="${result//$'\r'/'%0D'}"
35
+ echo "::set-output name=result::$result"
36
+ true
37
+ continue-on-error: true
38
+ # lint結果をコメントに残す
39
+ - name: Lint Comment
40
+ if: github.event.pull_request.head.repo.full_name == github.repository && steps.lint.outputs.result != ''
41
+ uses: actions/github-script@v3
42
+ with:
43
+ github-token: ${{secrets.GITHUB_TOKEN}}
44
+ script: |
45
+ const issues_listComments_params = {
46
+ issue_number: context.issue.number,
47
+ owner: context.repo.owner,
48
+ repo: context.repo.repo
49
+ }
50
+ console.log("call issues.listComments:", issues_listComments_params)
51
+ const issue_comments = (await github.paginate(github.issues.listComments, issues_listComments_params)).filter(
52
+ issue_comment => issue_comment.user.id==41898282 && issue_comment.body.startsWith('日本語の')
53
+ )
54
+
55
+ for (const issue_comment of issue_comments) {
56
+ const issues_deleteComment_params = {
57
+ comment_id: issue_comment.id,
58
+ owner: context.repo.owner,
59
+ repo: context.repo.repo
60
+ }
61
+ console.log("call issues.deleteComment:", issues_deleteComment_params)
62
+ await github.issues.deleteComment(issues_deleteComment_params)
63
+ }
64
+
65
+ const result = `${{steps.lint.outputs.result}}`
66
+ const issues_createComment_params = {
67
+ issue_number: context.issue.number,
68
+ owner: context.repo.owner,
69
+ repo: context.repo.repo,
70
+ body: "日本語のLint結果\n```\n"+result+"\n```"
71
+ }
72
+ console.log("call issues.createComment:", issues_createComment_params)
73
+ await github.issues.createComment(issues_createComment_params)
74
+ - name: Exit
75
+ if: github.event.pull_request.head.repo.full_name != github.repository && steps.lint.outcome == 'failure'
76
+ run: exit 1
77
+
78
+ # PRが来たらtextlintをかけてみて、差分があればPRを作って、エラーで落ちるjob
79
+ format:
80
+ runs-on: ubuntu-latest
81
+ if: github.event.pull_request.head.repo.full_name == github.repository
82
+ strategy:
83
+ matrix:
84
+ node-version: [ 16.x ]
85
+
86
+ steps:
87
+ - uses: actions/checkout@v2
88
+ with:
89
+ fetch-depth: 0
90
+ - name: Use Node.js ${{ matrix.node-version }}
91
+ uses: actions/setup-node@v1.4.4
92
+ with:
93
+ node-version: ${{ matrix.node-version }}
94
+ - name: Install dependencies
95
+ run: |
96
+ yarn install -D
97
+ # textlintでformatする
98
+ - name: Format files
99
+ id: format
100
+ run: |
101
+ yarn run textlint:fix
102
+ continue-on-error: true
103
+ # 差分があったときは差分を出力する
104
+ - name: Show diff
105
+ id: show_diff
106
+ run: |
107
+ echo "::set-output name=diff::$(git diff)"
108
+ # 差分があったときは、コミットを作りpushする
109
+ - name: Push
110
+ if: steps.show_diff.outputs.diff != ''
111
+ run: |
112
+ git config user.name "textlint CI"
113
+ git config user.email "textlint_ci@example.com"
114
+ git add -u
115
+ git commit -m "日本語修正"
116
+ git push -f https://${{github.actor}}:${{secrets.GITHUB_TOKEN}}@github.com/${{github.repository}}.git HEAD:refs/heads/fix-text-${{github.event.pull_request.head.ref}}
117
+ - name: Get PullRequests
118
+ uses: actions/github-script@v3
119
+ if: steps.show_diff.outputs.diff != ''
120
+ id: get_pull_requests
121
+ with:
122
+ github-token: ${{secrets.GITHUB_TOKEN}}
123
+ script: |
124
+ const pulls_list_params = {
125
+ owner: context.repo.owner,
126
+ repo: context.repo.repo,
127
+ head: "kujirahand:fix-text-${{github.event.pull_request.head.ref}}",
128
+ base: "${{github.event.pull_request.head.ref}}",
129
+ state: "open"
130
+ }
131
+ console.log("call pulls.list:", pulls_list_params)
132
+ const pulls = await github.paginate(github.pulls.list, pulls_list_params)
133
+ return pulls.length
134
+ # pushしたブランチでPRを作る
135
+ - name: Create PullRequest
136
+ uses: actions/github-script@v3
137
+ if: steps.show_diff.outputs.diff != '' && steps.get_pull_requests.outputs.result == 0
138
+ with:
139
+ github-token: ${{secrets.GITHUB_TOKEN}}
140
+ script: |
141
+ const common_params = {
142
+ owner: context.repo.owner,
143
+ repo: context.repo.repo
144
+ }
145
+ const pulls_create_params = {
146
+ head: "kujirahand:fix-text-${{github.event.pull_request.head.ref}}",
147
+ base: "${{github.event.pull_request.head.ref}}",
148
+ title: "日本語修正 (修正する場合はPRをマージしてください) #${{github.event.pull_request.number}}",
149
+ body: "日本語を修正しました。本PRをマージすると #${{github.event.pull_request.number}} に修正が適用されます。",
150
+ ...common_params
151
+ }
152
+ console.log("call pulls.create:", pulls_create_params)
153
+ const create_pull_res = (await github.pulls.create(pulls_create_params)).data
154
+ const issues_add_assignees_params = {
155
+ issue_number: create_pull_res.number,
156
+ assignees: ["${{github.event.pull_request.user.login}}"],
157
+ ...common_params
158
+ }
159
+ console.log("call issues.addAssignees:", issues_add_assignees_params)
160
+ await github.issues.addAssignees(issues_add_assignees_params)
161
+ # 既にformat修正のPRがある状態で、手動でformatを修正した場合、format修正のPRを閉じる
162
+ - name: Close PullRequest
163
+ uses: actions/github-script@v3
164
+ if: steps.show_diff.outputs.diff == ''
165
+ with:
166
+ github-token: ${{secrets.GITHUB_TOKEN}}
167
+ script: |
168
+ const head_name = "fix-text-${{github.event.pull_request.head.ref}}"
169
+ const common_params = {
170
+ owner: context.repo.owner,
171
+ repo: context.repo.repo
172
+ }
173
+ const pulls_list_params = {
174
+ head: "kujirahand:" + head_name,
175
+ base: "${{github.event.pull_request.head.ref}}",
176
+ state: "open",
177
+ ...common_params
178
+ }
179
+ console.log("call pulls.list:", pulls_list_params)
180
+ const pulls = await github.paginate(github.pulls.list,pulls_list_params)
181
+
182
+ for (const pull of pulls) {
183
+ const pulls_update_params = {
184
+ pull_number: pull.number,
185
+ state: "closed",
186
+ ...common_params
187
+ }
188
+ console.log("call pulls.update:", pulls_update_params)
189
+ await github.pulls.update(pulls_update_params)
190
+ const git_deleteRef_params = {
191
+ ref: "heads/" + head_name,
192
+ ...common_params
193
+ }
194
+ console.log("call git.deleteRef:", git_deleteRef_params)
195
+ await github.git.deleteRef(git_deleteRef_params)
196
+ }
197
+ - name: Exit
198
+ if: steps.show_diff.outputs.diff != ''
199
+ run: exit 1
package/core/README.md CHANGED
@@ -63,4 +63,8 @@ $ snako -e "1+2を表示"
63
63
  $ snako nadesiko3core/sample/hello.nako3
64
64
  ```
65
65
 
66
+ ## なでしこの内部構造について
67
+
68
+ なでしこの内部構造の仕組みについては、[こちら](/doc/README.md)に詳しく書かれています。
69
+
66
70
 
@@ -0,0 +1,67 @@
1
+ # 日本語プログラミング言語「なでしこ3」 内部構造について
2
+
3
+ なでしこ3は、altJSと呼ばれる仕組みを採用しており、なでしこのプログラムが最終的にJavaScriptに変換されて実行されます。
4
+
5
+ 大きく言って次の仕組みで実行されます。
6
+
7
+ - 1.[字句解析](/src/nako_lexer.mts)
8
+ - 2.[構文解析](/src/nako_parser3.mts)
9
+ - 3.[コード生成](/src/nako_gen.mts)
10
+ - 4.[実行](/src/nako3.mts)
11
+
12
+ ## 字句解析
13
+
14
+ [字句解析](/src/nako_lexer.mts)では、なでしこのソースコードをトークンと呼ばれる、最小の字句要素に分割します。以下のtokenizeメソッドで分割します。
15
+
16
+ - [tokenizeメソッド](https://github.com/kujirahand/nadesiko3core/blob/7db54415b74815739fdb64aa05df7da9e5ab1bdf/src/nako_lexer.mts#L404)
17
+
18
+ なお、トークンを分割するのに複数のルールを利用します。ルールは、配列形式で記述されており、上から順にソースコードにマッチするかを順に確認していきます。
19
+
20
+ - [rules配列](https://github.com/kujirahand/nadesiko3core/blob/7db54415b74815739fdb64aa05df7da9e5ab1bdf/src/nako_lex_rules.mts#L32)
21
+
22
+ ### 字句解析前の細かな処理
23
+
24
+ ただし、実際には、字句解析を行う前に、全角半角を揃えたり、特殊な記法を一般的な記法に置き換えたりと前置処理が行われます。
25
+
26
+ - [前置処理](/src/nako_prepare.mts)
27
+
28
+ また、なでしこ3では、インデント構文やDNCLモードなどをサポートしており、これは、なでしこの文法を劇的に置換する特殊モードで、字句解析の前に置換処理がおこなれます。
29
+
30
+ - [インデント構文](/src/nako_indent.mts)
31
+ - [DNCLモード](/src/nako_from_dncl.mjs)
32
+
33
+ ## 構文解析
34
+
35
+ [構文解析](/src/nako_parser3.mts)では、なでしこの文法に沿った記述があるかどうかを一つずつ確認して、ソースコードを構文木に変換します。
36
+ なでしこの構文木は、複数のノードを木構造でつなげたものです。
37
+
38
+ - [構文木のノード(Ast)](https://github.com/kujirahand/nadesiko3core/blob/7db54415b74815739fdb64aa05df7da9e5ab1bdf/src/nako_types.mts#L72)
39
+
40
+ この構文木は、[本家(nadesiko3)](https://github.com/kujirahand/nadesiko3)のcnako3コマンドで、--ast オプションを付けると確認できます。
41
+ 例えば、「2+3を表示」というプログラムは、次のような構文木に変換されます。
42
+
43
+ - block:
44
+ - func (表示):
45
+ - args:
46
+ - op(+)
47
+ - left:
48
+ - number (2)
49
+ - right:
50
+ - number (3)
51
+
52
+ ## コード生成
53
+
54
+ [コード生成](/src/nako_gen.mts)の処理では、構文解析で作成した構文木のコードを、JavaScriptのコードに変換します。
55
+ 構文木の各要素を一つずつJavaScriptに変換します。
56
+
57
+ コード変換を実際に行うのが、[_codeGenメソッド](https://github.com/kujirahand/nadesiko3core/blob/7db54415b74815739fdb64aa05df7da9e5ab1bdf/src/nako_gen.mts#L418)です。このメソッドでは、Astのtypeプロパティを調べて、各要素を一つずつ変換していきます。
58
+
59
+ - 例えば、構文木の種類が[number](https://github.com/kujirahand/nadesiko3core/blob/7db54415b74815739fdb64aa05df7da9e5ab1bdf/src/nako_gen.mts#L460)であれば、数値なのでそのまま数値を返します。
60
+ - [演算子(op)](https://github.com/kujirahand/nadesiko3core/blob/7db54415b74815739fdb64aa05df7da9e5ab1bdf/src/nako_gen.mts#L1388)の時は計算を行うJavaScriptのコードを生成します。
61
+ - [繰り返す文(for)](https://github.com/kujirahand/nadesiko3core/blob/7db54415b74815739fdb64aa05df7da9e5ab1bdf/src/nako_gen.mts#L909)であれば、必要なパラメータを取得しつつJavaScriptのfor文を生成します。
62
+
63
+ ## 実行
64
+
65
+ [実行](/src/nako3.mts)は、JavaScriptのコードを評価する[evalJS](https://github.com/kujirahand/nadesiko3core/blob/7db54415b74815739fdb64aa05df7da9e5ab1bdf/src/nako3.mts#L749)メソッドで行います。
66
+ JavaScriptの`new Function(code)`を使ってJavaScriptのコードを実行します。
67
+
package/core/index.mjs CHANGED
@@ -1,4 +1,4 @@
1
- import version from './src/nako_core_version.mjs';
1
+ import coreVersion from './src/nako_core_version.mjs';
2
2
  import { NakoCompiler } from './src/nako3.mjs';
3
3
  import { NakoLogger } from './src/nako_logger.mjs';
4
4
  import { NakoError, NakoRuntimeError, NakoImportError } from './src/nako_errors.mjs';
@@ -6,7 +6,7 @@ import { NakoParser } from './src/nako_parser3.mjs';
6
6
  import { NakoPrepare } from './src/nako_prepare.mjs';
7
7
  export default {
8
8
  // version
9
- version,
9
+ version: coreVersion,
10
10
  // compiler
11
11
  NakoCompiler,
12
12
  // loggger
package/core/index.mts ADDED
@@ -0,0 +1,21 @@
1
+ import coreVersion from './src/nako_core_version.mjs'
2
+ import { NakoCompiler } from './src/nako3.mjs'
3
+ import { NakoLogger } from './src/nako_logger.mjs'
4
+ import { NakoError, NakoRuntimeError, NakoImportError } from './src/nako_errors.mjs'
5
+ import { NakoParser } from './src/nako_parser3.mjs'
6
+ import { NakoPrepare } from './src/nako_prepare.mjs'
7
+ export default {
8
+ // version
9
+ version: coreVersion,
10
+ // compiler
11
+ NakoCompiler,
12
+ // loggger
13
+ NakoLogger,
14
+ // error
15
+ NakoError,
16
+ NakoRuntimeError,
17
+ NakoImportError,
18
+ // tools etc..
19
+ NakoParser,
20
+ NakoPrepare
21
+ }
package/core/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nadesiko3core",
3
- "version": "3.3.53",
3
+ "version": "3.3.56",
4
4
  "description": "Japanese Programming Language Nadesiko v3 core",
5
5
  "main": "index.mjs",
6
6
  "type": "module",
@@ -54,6 +54,7 @@ export class NakoCompiler {
54
54
  * @type {NakoGlobal[]}
55
55
  */
56
56
  this.__globals = []; // 生成した NakoGlobal のインスタンスを保持
57
+ this.__globalObj = null;
57
58
  /** @type {Record<string, Record<string, NakoFunction>>} */
58
59
  this.__module = {}; // requireなどで取り込んだモジュールの一覧
59
60
  this.pluginFunclist = {}; // プラグインで定義された関数
@@ -226,9 +227,9 @@ export class NakoCompiler {
226
227
  // 非同期な場合のエラーハンドリング
227
228
  if (result !== undefined) {
228
229
  result.catch((err) => {
229
- // 読み込みに失敗しても処理は続ける方針なので、失敗しても例外は投げない
230
- // たぶん、その後の構文解析でエラーになるため
231
- this.logger.warn(err.msg);
230
+ // 読み込みに失敗したら処理を中断する
231
+ this.logger.error(err.msg);
232
+ this.numFailures++;
232
233
  });
233
234
  }
234
235
  // すべてが終わってからthis.dependenciesに代入する。そうしないと、「実行」ボタンを連打した場合など、
@@ -238,17 +239,17 @@ export class NakoCompiler {
238
239
  }
239
240
  catch (err) {
240
241
  // 同期処理では素直に例外を投げる
241
- this.logger.warn('' + err);
242
+ this.logger.error('' + err);
242
243
  throw err;
243
244
  }
244
245
  }
245
246
  /**
246
247
  * コードを単語に分割する
247
- * @param {string} code なでしこのプログラム
248
- * @param {number} line なでしこのプログラムの行番号
249
- * @param {string} filename
250
- * @param {string} [preCode]
251
- * @returns {TokenWithSourceMap[]} トークンのリスト
248
+ * @param code なでしこのプログラム
249
+ * @param line なでしこのプログラムの行番号
250
+ * @param filename
251
+ * @param preCode
252
+ * @returns トークンのリスト
252
253
  */
253
254
  rawtokenize(code, line, filename, preCode = '') {
254
255
  if (!code.startsWith(preCode)) {
@@ -640,9 +641,19 @@ export class NakoCompiler {
640
641
  evalJS(code, nakoGlobal) {
641
642
  // 実行前に環境を初期化するイベントを実行(beforeRun)
642
643
  this.eventList.filter(o => o.eventName === 'beforeRun').map(e => e.callback(nakoGlobal));
643
- // eslint-disable-next-line no-new-func
644
- const f = new Function(code);
645
- f.apply(nakoGlobal);
644
+ this.__globalObj = nakoGlobal; // 現在のnakoGlobalを記録
645
+ this.__globalObj.lastJSCode = code;
646
+ try {
647
+ // eslint-disable-next-line no-new-func
648
+ const f = new Function(code);
649
+ f.apply(nakoGlobal);
650
+ }
651
+ catch (err) {
652
+ // なでしこコードのエラーは抑止してログにのみ記録
653
+ nakoGlobal.numFailures++;
654
+ this.getLogger().error(err);
655
+ throw err;
656
+ }
646
657
  // 実行後に終了イベントを実行(finish)
647
658
  this.eventList.filter(o => o.eventName === 'finish').map(e => e.callback(nakoGlobal));
648
659
  }
@@ -95,6 +95,7 @@ export class NakoCompiler {
95
95
  __v0: NakoVars;
96
96
  __v1: NakoVars;
97
97
  __globals: NakoGlobal[];
98
+ __globalObj: NakoGlobal|null; // 現在のNakoGlobalオブジェクト
98
99
  __module: Record<string, Record<string, FuncListItem>>;
99
100
  numFailures: number; // エラーレポートの数を記録
100
101
  public version: string;
@@ -120,6 +121,7 @@ export class NakoCompiler {
120
121
  * @type {NakoGlobal[]}
121
122
  */
122
123
  this.__globals = [] // 生成した NakoGlobal のインスタンスを保持
124
+ this.__globalObj = null
123
125
  /** @type {Record<string, Record<string, NakoFunction>>} */
124
126
  this.__module = {} // requireなどで取り込んだモジュールの一覧
125
127
  this.pluginFunclist = {} // プラグインで定義された関数
@@ -304,9 +306,9 @@ export class NakoCompiler {
304
306
  // 非同期な場合のエラーハンドリング
305
307
  if (result !== undefined) {
306
308
  result.catch((err) => {
307
- // 読み込みに失敗しても処理は続ける方針なので、失敗しても例外は投げない
308
- // たぶん、その後の構文解析でエラーになるため
309
- this.logger.warn(err.msg)
309
+ // 読み込みに失敗したら処理を中断する
310
+ this.logger.error(err.msg)
311
+ this.numFailures++
310
312
  })
311
313
  }
312
314
 
@@ -316,18 +318,18 @@ export class NakoCompiler {
316
318
  return result
317
319
  } catch (err) {
318
320
  // 同期処理では素直に例外を投げる
319
- this.logger.warn('' + err)
321
+ this.logger.error('' + err)
320
322
  throw err
321
323
  }
322
324
  }
323
325
 
324
326
  /**
325
327
  * コードを単語に分割する
326
- * @param {string} code なでしこのプログラム
327
- * @param {number} line なでしこのプログラムの行番号
328
- * @param {string} filename
329
- * @param {string} [preCode]
330
- * @returns {TokenWithSourceMap[]} トークンのリスト
328
+ * @param code なでしこのプログラム
329
+ * @param line なでしこのプログラムの行番号
330
+ * @param filename
331
+ * @param preCode
332
+ * @returns トークンのリスト
331
333
  */
332
334
  rawtokenize (code: string, line: number, filename: string, preCode = ''): Token[] {
333
335
  if (!code.startsWith(preCode)) {
@@ -585,7 +587,6 @@ export class NakoCompiler {
585
587
  // 関数を字句解析と構文解析に登録
586
588
  this.lexer.setFuncList(this.funclist)
587
589
  this.parser.setFuncList(this.funclist)
588
-
589
590
  const lexerOutput = this.lex(code, filename, preCode)
590
591
 
591
592
  // 構文木を作成
@@ -749,9 +750,18 @@ export class NakoCompiler {
749
750
  private evalJS (code: string, nakoGlobal: NakoGlobal): void {
750
751
  // 実行前に環境を初期化するイベントを実行(beforeRun)
751
752
  this.eventList.filter(o => o.eventName === 'beforeRun').map(e => e.callback(nakoGlobal))
752
- // eslint-disable-next-line no-new-func
753
- const f = new Function(code)
754
- f.apply(nakoGlobal)
753
+ this.__globalObj = nakoGlobal // 現在のnakoGlobalを記録
754
+ this.__globalObj.lastJSCode = code
755
+ try {
756
+ // eslint-disable-next-line no-new-func
757
+ const f = new Function(code)
758
+ f.apply(nakoGlobal)
759
+ } catch (err: any) {
760
+ // なでしこコードのエラーは抑止してログにのみ記録
761
+ nakoGlobal.numFailures++
762
+ this.getLogger().error(err)
763
+ throw err
764
+ }
755
765
  // 実行後に終了イベントを実行(finish)
756
766
  this.eventList.filter(o => o.eventName === 'finish').map(e => e.callback(nakoGlobal))
757
767
  }
@@ -1,8 +1,8 @@
1
1
  // 実際のバージョン定義 (自動生成されるので以下を編集しない)
2
2
  const coreVersion = {
3
- version: '3.3.53',
3
+ version: '3.3.56',
4
4
  major: 3,
5
5
  minor: 3,
6
- patch: 53
6
+ patch: 56
7
7
  };
8
8
  export default coreVersion;