nadesiko3 3.3.48 → 3.3.49
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/core/.editorconfig +6 -0
- package/core/.eslintrc.cjs +33 -0
- package/core/.github/dependabot.yml +7 -0
- package/core/.github/workflows/nodejs.yml +37 -0
- package/core/.github/workflows/super-linter.yml +61 -0
- package/core/.github/workflows/textlint.yml +199 -0
- package/core/LICENSE +21 -0
- package/core/README.md +66 -0
- package/core/batch/build_nako_version.nako3 +42 -0
- package/core/command/snako.mjs +105 -0
- package/core/command/snako.mts +116 -0
- package/core/index.mjs +21 -0
- package/core/index.mts +21 -0
- package/core/package.json +47 -0
- package/core/sample/hello.nako3 +7 -0
- package/core/sample/hoge.mjs +4 -0
- package/core/sample/hoge.mts +6 -0
- package/core/src/nako3.mjs +858 -0
- package/core/src/nako3.mts +967 -0
- package/core/src/nako_colors.mjs +78 -0
- package/core/src/nako_colors.mts +86 -0
- package/core/src/nako_core_version.mjs +8 -0
- package/core/src/nako_core_version.mts +19 -0
- package/core/src/nako_csv.mjs +185 -0
- package/core/src/nako_csv.mts +188 -0
- package/core/src/nako_errors.mjs +173 -0
- package/core/src/nako_errors.mts +197 -0
- package/core/src/nako_from_dncl.mjs +255 -0
- package/core/src/nako_from_dncl.mts +250 -0
- package/core/src/nako_gen.mjs +1648 -0
- package/core/src/nako_gen.mts +1719 -0
- package/core/src/nako_gen_async.mjs +1659 -0
- package/core/src/nako_gen_async.mts +1732 -0
- package/core/src/nako_global.mjs +107 -0
- package/core/src/nako_global.mts +138 -0
- package/core/src/nako_indent.mjs +445 -0
- package/core/src/nako_indent.mts +492 -0
- package/core/src/nako_josi_list.mjs +38 -0
- package/core/src/nako_josi_list.mts +45 -0
- package/core/src/nako_lex_rules.mjs +253 -0
- package/core/src/nako_lex_rules.mts +260 -0
- package/core/src/nako_lexer.mjs +609 -0
- package/core/src/nako_lexer.mts +612 -0
- package/core/src/nako_logger.mjs +199 -0
- package/core/src/nako_logger.mts +232 -0
- package/core/src/nako_parser3.mjs +2439 -0
- package/core/src/nako_parser3.mts +2195 -0
- package/core/src/nako_parser_base.mjs +370 -0
- package/core/src/nako_parser_base.mts +370 -0
- package/core/src/nako_parser_const.mjs +37 -0
- package/core/src/nako_parser_const.mts +37 -0
- package/core/src/nako_prepare.mjs +304 -0
- package/core/src/nako_prepare.mts +315 -0
- package/core/src/nako_reserved_words.mjs +38 -0
- package/core/src/nako_reserved_words.mts +38 -0
- package/core/src/nako_source_mapping.mjs +207 -0
- package/core/src/nako_source_mapping.mts +262 -0
- package/core/src/nako_test.mjs +37 -0
- package/core/src/nako_types.mjs +25 -0
- package/core/src/nako_types.mts +151 -0
- package/core/src/plugin_csv.mjs +49 -0
- package/core/src/plugin_csv.mts +50 -0
- package/core/src/plugin_math.mjs +328 -0
- package/core/src/plugin_math.mts +326 -0
- package/core/src/plugin_promise.mjs +91 -0
- package/core/src/plugin_promise.mts +91 -0
- package/core/src/plugin_system.mjs +2832 -0
- package/core/src/plugin_system.mts +2690 -0
- package/core/src/plugin_test.mjs +34 -0
- package/core/src/plugin_test.mts +34 -0
- package/core/test/array_test.mjs +34 -0
- package/core/test/basic_test.mjs +344 -0
- package/core/test/calc_test.mjs +140 -0
- package/core/test/core_module_test.mjs +23 -0
- package/core/test/debug_test.mjs +16 -0
- package/core/test/dncl_test.mjs +94 -0
- package/core/test/error_message_test.mjs +210 -0
- package/core/test/error_test.mjs +16 -0
- package/core/test/flow_test.mjs +373 -0
- package/core/test/func_call.mjs +160 -0
- package/core/test/func_test.mjs +149 -0
- package/core/test/indent_test.mjs +364 -0
- package/core/test/lex_test.mjs +168 -0
- package/core/test/literal_test.mjs +73 -0
- package/core/test/nako_lexer_test.mjs +35 -0
- package/core/test/nako_logger_test.mjs +76 -0
- package/core/test/nako_logger_test.mts +78 -0
- package/core/test/plugin_csv_test.mjs +38 -0
- package/core/test/plugin_promise_test.mjs +18 -0
- package/core/test/plugin_system_test.mjs +630 -0
- package/core/test/prepare_test.mjs +96 -0
- package/core/test/re_test.mjs +22 -0
- package/core/test/side_effects_test.mjs +92 -0
- package/core/test/variable_scope_test.mjs +149 -0
- package/core/tsconfig.json +101 -0
- package/package.json +4 -2
- package/release/_hash.txt +12 -12
- package/release/_script-tags.txt +14 -14
- package/release/editor.js +1 -1
- package/release/stats.json +1 -1
- package/release/version.js +1 -1
- package/release/wnako3.js +1 -1
- package/src/nako_version.mjs +2 -2
- package/src/nako_version.mts +2 -2
- package/test/async/async_basic_test.mjs +3 -3
|
@@ -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,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/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2022 kujirahand
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/core/README.md
ADDED
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
# 日本語プログラミング言語「なでしこ3」言語エンジン
|
|
2
|
+
|
|
3
|
+
[](LICENSE)
|
|
4
|
+
[](https://www.npmjs.com/package/nadesiko3core)
|
|
5
|
+
|
|
6
|
+
## 「なでしこ3」とは
|
|
7
|
+
|
|
8
|
+
「なでしこ3」とは、日本語のプログラミング言語です。HTML5/JavaScript(TypeScript)をベースとしているので、PC/スマホ/タブレットなど、さまざまな環境で動作させることができます。日本語プログラミング言語は、読みやすく理解しやすいのが特徴で、初めてでも楽しくプログラミングを覚えることができます。
|
|
9
|
+
|
|
10
|
+
- [なでしこ3開発リポジトリ - nadesiko3](https://github.com/kujirahand/nadesiko3)
|
|
11
|
+
- [なでしこのWebサイト](https://nadesi.com/top/)
|
|
12
|
+
|
|
13
|
+
## 本リポジトリについて
|
|
14
|
+
|
|
15
|
+
本リポジトリは、なでしこ3の言語エンジンのみを取り出したものです。最小限の構成となっています。
|
|
16
|
+
言語機能と最小限のプラグインのみを備えています。
|
|
17
|
+
|
|
18
|
+
- [なでしこの基本文法(外部サイト)](https://nadesi.com/v3/doc/index.php?%E6%96%87%E6%B3%95)
|
|
19
|
+
|
|
20
|
+
最小限のプラグイン構成
|
|
21
|
+
|
|
22
|
+
- [plugin_system](./src/plugin_system.mts) --- 言語機能の補助など基本的な関数群
|
|
23
|
+
- [plugin_math](./src/plugin_math.mts) --- 数学関数群
|
|
24
|
+
- [plugin_csv](./src/plugin_csv.mts)--- CSV処理のための関数群
|
|
25
|
+
- [plugin_promise](./src/plugin_promise.mts) --- プロミス機能を実現するための関数群
|
|
26
|
+
- [plugin_test](./src/plugin_test.mts) --- テストを記述するための関数群
|
|
27
|
+
|
|
28
|
+
# 本ライブラリの使い方
|
|
29
|
+
|
|
30
|
+
例えば、`npm install nadesiko3core`でなでしこ3言語エンジンをインストールしたら、以下のプログラムを記述します。
|
|
31
|
+
`hoge.mjs`という名前で保存します。そして、以下のようなプログラムを記述します。
|
|
32
|
+
|
|
33
|
+
```js
|
|
34
|
+
import core from 'nadesiko3core'
|
|
35
|
+
const com = new core.NakoCompiler()
|
|
36
|
+
const g = com.run('1 + 2 * 3を表示') // ← ここになでしこのプログラム
|
|
37
|
+
console.log(g.log) // ← 「表示」した内容がlogに入っている
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
プログラムを実行するには、`node hoge.mjs`と記述すれば実行できます。
|
|
41
|
+
|
|
42
|
+
## コマンドラインから実行したい場合
|
|
43
|
+
|
|
44
|
+
コマンドラインからなでしこのプログラムを実行したい場合には、[nadesiko3](https://github.com/kujirahand/nadesiko3)リポジトリを利用してください。nadesiko3リポジトリには、コマンドライン版のなでしこ(cnako3)が含まれています。
|
|
45
|
+
|
|
46
|
+
なお、本リポジトリにも、[簡易版のコマンドラインツール(snako)](/command/snako.mts)を収録しています。以下は簡単な使い方です。
|
|
47
|
+
|
|
48
|
+
```
|
|
49
|
+
# ファイル sample/hello.nako3 を実行
|
|
50
|
+
$ node command/snako.mjs sample/hello.nako3
|
|
51
|
+
|
|
52
|
+
# その場でコードを実行
|
|
53
|
+
$ node command/snako.mjs -e "1+2を表示"
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
### 簡易コマンドラインをグローバルインストールして使う場合
|
|
57
|
+
|
|
58
|
+
簡易コマンドライン(snako)を手軽に利用したい場合は、次のように実行します。
|
|
59
|
+
|
|
60
|
+
```
|
|
61
|
+
$ npm install -g nadesiko3core
|
|
62
|
+
$ snako -e "1+2を表示"
|
|
63
|
+
$ snako nadesiko3core/sample/hello.nako3
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
#!/usr/bin/env cnako3
|
|
2
|
+
# -----------------------------------------------------
|
|
3
|
+
# なでしこのバージョン情報を自動生成する
|
|
4
|
+
# -----------------------------------------------------
|
|
5
|
+
# ●説明
|
|
6
|
+
# package.json の内容を読んで ./src/nako_core_version.mts を生成
|
|
7
|
+
# -----------------------------------------------------
|
|
8
|
+
母艦パス取得してパス抽出して基本パスに代入。
|
|
9
|
+
「{基本パス}/package.json」を読んでJSONデコードして、Pに代入。
|
|
10
|
+
VER=P@"version"
|
|
11
|
+
定数[MAJOR,MINOR,PATCH]=(VERを「.」で区切る)
|
|
12
|
+
QS=『{』
|
|
13
|
+
QE=『}』
|
|
14
|
+
VS=「/**
|
|
15
|
+
* なでしこのバージョン情報
|
|
16
|
+
* package.json から自動的に作成されます。このファイルを編集しないでください。
|
|
17
|
+
*/
|
|
18
|
+
// 型定義
|
|
19
|
+
export interface NakoCoreVersion {QS}
|
|
20
|
+
version: string;
|
|
21
|
+
major: number;
|
|
22
|
+
minor: number;
|
|
23
|
+
patch: number;
|
|
24
|
+
{QE}
|
|
25
|
+
// 実際のバージョン定義 (自動生成されるので以下を編集しない)
|
|
26
|
+
const coreVersion: NakoCoreVersion = {QS}
|
|
27
|
+
version: '{VER}',
|
|
28
|
+
major: {MAJOR},
|
|
29
|
+
minor: {MINOR},
|
|
30
|
+
patch: {PATCH}
|
|
31
|
+
{QE}
|
|
32
|
+
export default coreVersion
|
|
33
|
+
」
|
|
34
|
+
保存先=「{基本パス}/src/nako_core_version.mts」
|
|
35
|
+
VSを保存先へ保存。
|
|
36
|
+
「
|
|
37
|
+
# ---------------------------------------------
|
|
38
|
+
# ● なでしこのバージョン情報を更新しました。
|
|
39
|
+
# version {VER}
|
|
40
|
+
# file: {保存先}
|
|
41
|
+
# ---------------------------------------------
|
|
42
|
+
」を表示。
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import fs from 'fs';
|
|
3
|
+
import path from 'path';
|
|
4
|
+
import com from '../index.mjs';
|
|
5
|
+
import * as url from 'url';
|
|
6
|
+
import { NakoGenOptions } from '../src/nako_gen.mjs';
|
|
7
|
+
const __dirname = url.fileURLToPath(new URL('.', import.meta.url));
|
|
8
|
+
/** コマンドラインオプション */
|
|
9
|
+
class CommandOptions {
|
|
10
|
+
constructor() {
|
|
11
|
+
this.nodePath = '';
|
|
12
|
+
this.scriptPath = '';
|
|
13
|
+
this.filename = '';
|
|
14
|
+
this.evalStr = '';
|
|
15
|
+
this.isDebug = false;
|
|
16
|
+
this.flagConvert = false;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
/** メイン処理 */
|
|
20
|
+
function main(argvOrg) {
|
|
21
|
+
// コマンドラインオプションを確認
|
|
22
|
+
const argv = [...argvOrg];
|
|
23
|
+
const opt = new CommandOptions();
|
|
24
|
+
opt.nodePath = argv.shift() || '';
|
|
25
|
+
opt.scriptPath = argv.shift() || '';
|
|
26
|
+
while (argv.length > 0) {
|
|
27
|
+
const arg = argv.shift() || '';
|
|
28
|
+
if (arg === '-d' || arg === '--debug') {
|
|
29
|
+
opt.isDebug = true;
|
|
30
|
+
continue;
|
|
31
|
+
}
|
|
32
|
+
if (arg === '-e' || arg === '--eval') {
|
|
33
|
+
opt.evalStr = argv.shift() || '';
|
|
34
|
+
continue;
|
|
35
|
+
}
|
|
36
|
+
if (arg === '-c' || arg === '--convert') {
|
|
37
|
+
opt.flagConvert = true;
|
|
38
|
+
continue;
|
|
39
|
+
}
|
|
40
|
+
if (opt.filename === '') {
|
|
41
|
+
opt.filename = arg;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
// なでしこのコンパイラを生成
|
|
45
|
+
const nako = new com.NakoCompiler();
|
|
46
|
+
// 実行前にイベントを挟みたいとき
|
|
47
|
+
nako.addListener('beforeRun', (g) => {
|
|
48
|
+
g.__varslist[0]['ナデシコ種類'] = 'snako';
|
|
49
|
+
});
|
|
50
|
+
// logger を設定 --- リスナーを登録することでデバッグレベルを指定
|
|
51
|
+
const logger = nako.getLogger();
|
|
52
|
+
if (opt.isDebug) {
|
|
53
|
+
logger.addListener('trace', (data) => {
|
|
54
|
+
console.log(data.nodeConsole);
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
logger.addListener('stdout', (data) => {
|
|
58
|
+
console.log(data.noColor);
|
|
59
|
+
});
|
|
60
|
+
// -e オプションを実行したとき
|
|
61
|
+
if (opt.evalStr) {
|
|
62
|
+
nako.run(opt.evalStr);
|
|
63
|
+
return;
|
|
64
|
+
}
|
|
65
|
+
// パラメータが空だったとき
|
|
66
|
+
if (opt.filename === '') {
|
|
67
|
+
showHelp();
|
|
68
|
+
return;
|
|
69
|
+
}
|
|
70
|
+
// ソースコードをファイルから読み込む
|
|
71
|
+
const code = fs.readFileSync(opt.filename, 'utf-8');
|
|
72
|
+
// -c オプションが指定されたとき
|
|
73
|
+
if (opt.flagConvert) {
|
|
74
|
+
convert(nako, code, opt);
|
|
75
|
+
}
|
|
76
|
+
// 実行
|
|
77
|
+
nako.run(code, opt.filename);
|
|
78
|
+
}
|
|
79
|
+
// -c オプションを指定したとき
|
|
80
|
+
function convert(nako, code, opt) {
|
|
81
|
+
// オプションを指定
|
|
82
|
+
const genOpt = new NakoGenOptions(false, ['nako_errors.mjs', 'nako_core_version.mjs', 'plugin_system.mjs'], 'self.__varslist[0][\'ナデシコ種類\'] = \'snako\'');
|
|
83
|
+
// スタンドアロンコードを生成
|
|
84
|
+
const js = nako.compileStandalone(code, opt.filename, genOpt);
|
|
85
|
+
const jsFilename = opt.filename + '.js';
|
|
86
|
+
fs.writeFileSync(jsFilename, js, { encoding: 'utf-8' });
|
|
87
|
+
// 必要なライブラリをコピー
|
|
88
|
+
const runtimeDir = path.join(path.dirname(jsFilename), 'nako3runtime');
|
|
89
|
+
const srcDir = path.join(__dirname, '..', 'src');
|
|
90
|
+
if (!fs.existsSync(runtimeDir)) {
|
|
91
|
+
fs.mkdirSync(runtimeDir);
|
|
92
|
+
}
|
|
93
|
+
for (const f of genOpt.importFiles) {
|
|
94
|
+
fs.copyFileSync(path.join(srcDir, f), path.join(runtimeDir, f));
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
/** 使い方を表示 */
|
|
98
|
+
function showHelp() {
|
|
99
|
+
console.log('●なでしこ(簡易版) # v.' + com.version.version);
|
|
100
|
+
console.log('[使い方] node snako.mjs [--debug|-d] (filename)');
|
|
101
|
+
console.log('[使い方] node snako.mjs [--eval|-e] (source)');
|
|
102
|
+
console.log('[使い方] node snako.mjs [-c] (source) ... convert');
|
|
103
|
+
}
|
|
104
|
+
/** メイン処理を実行 */
|
|
105
|
+
main(process.argv);
|