nadesiko3 3.7.21 → 3.7.23
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 +20 -1
- package/batch/command.txt +370 -334
- package/batch/generate_command_list.mjs +102 -0
- package/batch/jsplugin2text.nako3 +1 -1
- package/batch/pickup_command.nako3 +12 -0
- package/batch/search_command.mjs +34 -0
- package/batch/search_command.nako3 +430 -0
- package/core/command/snako.mts +5 -1
- package/core/deno/snako.ts +5 -1
- package/core/package-lock.json +382 -21
- package/core/package.json +7 -4
- package/core/sample/algorithms/README.md +43 -0
- package/core/sample/algorithms/graph/dijkstra.nako3 +47 -0
- package/core/sample/algorithms/graph/kruskal.nako3 +69 -0
- package/core/sample/algorithms/math/euclidean_gcd.nako3 +15 -0
- package/core/sample/algorithms/math/sieve_of_eratosthenes.nako3 +26 -0
- package/core/sample/algorithms/search/binary_search.nako3 +17 -0
- package/core/sample/algorithms/search/breadth_first_search.nako3 +33 -0
- package/core/sample/algorithms/search/depth_first_search.nako3 +25 -0
- package/core/sample/algorithms/sort/heap_sort.nako3 +37 -0
- package/core/sample/algorithms/sort/insertion_sort.nako3 +18 -0
- package/core/sample/algorithms/sort/merge_sort.nako3 +40 -0
- package/core/sample/algorithms/sort/quick_sort.nako3 +36 -0
- package/core/sample/algorithms/string/knuth_morris_pratt.nako3 +50 -0
- package/core/sample/algorithms/string/run_length_encoding.nako3 +25 -0
- package/core/src/nako3.mts +178 -614
- package/core/src/nako_basic_plugins.mts +39 -0
- package/core/src/nako_core_version.mts +2 -2
- package/core/src/nako_csv.mts +0 -1
- package/core/src/nako_event.mts +49 -0
- package/core/src/nako_gen.mts +320 -209
- package/core/src/nako_global.mts +18 -0
- package/core/src/nako_indent_inline.mts +2 -2
- package/core/src/nako_lex_rules.mts +1 -1
- package/core/src/nako_parser3.mts +111 -166
- package/core/src/nako_parser_async.mts +165 -0
- package/core/src/nako_parser_base.mts +4 -55
- package/core/src/nako_parser_message.mts +105 -0
- package/core/src/nako_parser_operator.mts +93 -0
- package/core/src/nako_plugin_manager.mts +260 -0
- package/core/src/nako_require.mts +292 -0
- package/core/src/nako_runner.mts +208 -0
- package/core/src/nako_tokenizer.mts +221 -0
- package/core/src/plugin_csv.mts +1 -1
- package/core/src/plugin_system.mts +34 -3259
- package/core/src/plugin_system_array.mts +699 -0
- package/core/src/plugin_system_datetime.mts +368 -0
- package/core/src/plugin_system_debug.mts +403 -0
- package/core/src/plugin_system_dict.mts +85 -0
- package/core/src/plugin_system_json.mts +73 -0
- package/core/src/plugin_system_math.mts +383 -0
- package/core/src/plugin_system_regexp.mts +120 -0
- package/core/src/plugin_system_stdio.mts +86 -0
- package/core/src/plugin_system_string.mts +666 -0
- package/core/src/plugin_system_timer.mts +152 -0
- package/core/src/plugin_system_types.mts +151 -0
- package/core/src/plugin_system_url.mts +193 -0
- package/core/src/plugin_toml.mts +3 -3
- package/core/test/algorithm_samples_test.mjs +58 -0
- package/core/test/algorithms/graph/dijkstra_test.nako3 +21 -0
- package/core/test/algorithms/graph/kruskal_test.nako3 +21 -0
- package/core/test/algorithms/helper.mjs +13 -0
- package/core/test/algorithms/math/euclidean_gcd_test.nako3 +13 -0
- package/core/test/algorithms/math/sieve_of_eratosthenes_test.nako3 +10 -0
- package/core/test/algorithms/search/binary_search_test.nako3 +15 -0
- package/core/test/algorithms/search/breadth_first_search_test.nako3 +13 -0
- package/core/test/algorithms/search/depth_first_search_test.nako3 +13 -0
- package/core/test/algorithms/sort/heap_sort_test.nako3 +13 -0
- package/core/test/algorithms/sort/insertion_sort_test.nako3 +13 -0
- package/core/test/algorithms/sort/merge_sort_test.nako3 +18 -0
- package/core/test/algorithms/sort/quick_sort_test.nako3 +34 -0
- package/core/test/algorithms/string/knuth_morris_pratt_test.nako3 +16 -0
- package/core/test/algorithms/string/run_length_encoding_test.nako3 +13 -0
- package/core/test/array_test.mjs +3 -0
- package/core/test/fixtures/README.md +39 -0
- package/core/test/fixtures/make_parser_ast_golden.mjs +31 -0
- package/core/test/fixtures/parser_ast_golden.json +8027 -0
- package/core/test/fixtures/parser_corpus.mjs +120 -0
- package/core/test/func_call.mjs +18 -0
- package/core/test/func_test.mjs +28 -0
- package/core/test/indent_test.mjs +6 -0
- package/core/test/nako_basic_plugins_test.mjs +44 -0
- package/core/test/nako_event_test.mjs +127 -0
- package/core/test/nako_gen_perf_test.mjs +178 -0
- package/core/test/nako_parser_async_test.mjs +385 -0
- package/core/test/nako_parser_test.mjs +160 -0
- package/core/test/nako_plugin_manager_test.mjs +185 -0
- package/core/test/nako_require_test.mjs +153 -0
- package/core/test/nako_runner_test.mjs +174 -0
- package/core/test/nako_tokenizer_test.mjs +115 -0
- package/core/test/plugin_system_debug_test.mjs +138 -0
- package/core/test/plugin_system_split_test.mjs +179 -0
- package/core/test/plugin_system_test.mjs +6 -0
- package/core/tsconfig.json +0 -1
- package/demo/browsers.html +1 -1
- package/doc/SETUP.md +1 -1
- package/doc/ai-code-generation.md +136 -0
- package/doc/browsers.md +1 -1
- package/doc/command_list.json +16842 -0
- package/doc/search_command.md +222 -0
- package/doc/syntax-nako3.md +344 -0
- package/package.json +29 -26
- package/release/_hash.txt +40 -40
- 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 +6 -6
- package/release/edit_main.js.map +3 -3
- package/release/editor.js +6 -6
- package/release/plugin_caniuse.js +1 -1
- package/release/plugin_caniuse.js.map +2 -2
- package/release/plugin_keigo.js.map +3 -3
- package/release/plugin_markup.js +46 -46
- package/release/plugin_markup.js.map +3 -3
- package/release/plugin_weykturtle3d.js +1 -1
- package/release/plugin_weykturtle3d.js.map +3 -3
- package/release/version.js +2 -2
- package/release/version_main.js +2 -2
- package/release/version_main.js.map +1 -1
- package/release/wnako3.js +219 -230
- package/release/wnako3.js.map +4 -4
- package/release/wnako3webworker.js +193 -204
- package/release/wnako3webworker.js.map +4 -4
- package/src/browsers.mjs +1 -1
- package/src/browsers.txt +0 -1
- package/src/cnako3mod.mjs +7 -2
- package/src/cnako3mod.mts +7 -2
- package/src/nako_version.mjs +2 -2
- package/src/nako_version.mts +2 -2
- package/src/plugin_browser_ajax.mjs +4 -4
- package/src/plugin_browser_ajax.mts +4 -4
- package/src/plugin_browser_audio.mjs +10 -10
- package/src/plugin_browser_audio.mts +10 -10
- package/src/plugin_browser_camera.mjs +4 -4
- package/src/plugin_browser_camera.mts +4 -4
- package/src/plugin_browser_canvas.mjs +2 -2
- package/src/plugin_browser_canvas.mts +2 -2
- package/src/plugin_browser_crypto.mjs +3 -3
- package/src/plugin_browser_crypto.mts +3 -3
- package/src/plugin_browser_dom_event.mjs +1 -1
- package/src/plugin_browser_dom_event.mts +1 -1
- package/src/plugin_browser_geolocation.mjs +1 -1
- package/src/plugin_browser_geolocation.mts +1 -1
- package/src/plugin_browser_hotkey.mjs +1 -1
- package/src/plugin_browser_hotkey.mts +1 -1
- package/src/plugin_browser_html.mjs +1 -1
- package/src/plugin_browser_html.mts +1 -1
- package/src/plugin_browser_location.mjs +1 -1
- package/src/plugin_browser_location.mts +1 -1
- package/src/plugin_browser_speech.mjs +1 -1
- package/src/plugin_browser_speech.mts +1 -1
- package/src/plugin_browser_storage.mjs +2 -2
- package/src/plugin_browser_storage.mts +2 -2
- package/src/plugin_httpserver.mjs +3 -3
- package/src/plugin_httpserver.mts +3 -3
- package/src/plugin_keigo.mjs +2 -2
- package/src/plugin_keigo.mts +2 -2
- package/src/plugin_node.mjs +48 -48
- package/src/plugin_node.mts +53 -53
- package/src/plugin_weykturtle3d.mjs +56 -56
- package/src/plugin_weykturtle3d.mts +56 -56
- package/src/wnako3.mjs +1 -1
- package/src/wnako3.mts +1 -1
- package/src/wnako3_editor.mjs +5 -5
- package/src/wnako3_editor.mts +5 -5
- package/src/wnako3mod.mjs +2 -2
- package/src/wnako3mod.mts +2 -2
- package/test/nako3edit/index_nako3_test.mjs +282 -0
- package/test/nako3server/index_nako3_test.mjs +239 -0
- package/test/node/ai_code_generation_guide_test.mjs +29 -0
- package/test/node/node_version_support_test.mjs +45 -0
- package/test/node/search_command_test.mjs +174 -0
- package/tools/nako3edit/AGENTS.md +23 -0
- package/tools/nako3edit/index.nako3 +404 -0
- package/tools/nako3server/AGENTS.md +23 -0
- package/tools/nako3server/index.nako3 +156 -23
- package/core/src/nako3.mjs +0 -1021
- package/core/src/nako_ast.mjs +0 -4
- package/core/src/nako_colors.mjs +0 -77
- package/core/src/nako_core_version.mjs +0 -8
- package/core/src/nako_csv.mjs +0 -193
- package/core/src/nako_errors.mjs +0 -166
- package/core/src/nako_from_dncl.mjs +0 -285
- package/core/src/nako_from_dncl2.mjs +0 -347
- package/core/src/nako_gen.mjs +0 -2500
- package/core/src/nako_global.mjs +0 -138
- package/core/src/nako_indent.mjs +0 -442
- package/core/src/nako_indent_chars.mjs +0 -29
- package/core/src/nako_indent_inline.mjs +0 -361
- package/core/src/nako_josi_list.mjs +0 -47
- package/core/src/nako_lex_rules.mjs +0 -319
- package/core/src/nako_lexer.mjs +0 -794
- package/core/src/nako_logger.mjs +0 -221
- package/core/src/nako_parser3.mjs +0 -3250
- package/core/src/nako_parser_base.mjs +0 -403
- package/core/src/nako_parser_const.mjs +0 -37
- package/core/src/nako_prepare.mjs +0 -329
- package/core/src/nako_reserved_words.mjs +0 -42
- package/core/src/nako_source_mapping.mjs +0 -207
- package/core/src/nako_test.mjs +0 -37
- package/core/src/nako_token.mjs +0 -1
- package/core/src/nako_tools.mjs +0 -53
- package/core/src/nako_types.mjs +0 -14
- package/core/src/plugin_api.mjs +0 -4
- package/core/src/plugin_csv.mjs +0 -97
- package/core/src/plugin_math.mjs +0 -352
- package/core/src/plugin_promise.mjs +0 -102
- package/core/src/plugin_system.mjs +0 -3810
- package/core/src/plugin_test.mjs +0 -52
- package/core/src/plugin_toml.mjs +0 -39
|
@@ -1,403 +0,0 @@
|
|
|
1
|
-
import { NewEmptyToken } from './nako_types.mjs';
|
|
2
|
-
/**
|
|
3
|
-
* なでしこの構文解析のためのユーティリティクラス
|
|
4
|
-
*/
|
|
5
|
-
export class NakoParserBase {
|
|
6
|
-
constructor(logger) {
|
|
7
|
-
this.logger = logger;
|
|
8
|
-
this.stackList = []; // 関数定義の際にスタックが混乱しないように整理する
|
|
9
|
-
this.tokens = [];
|
|
10
|
-
this.usedFuncs = new Set();
|
|
11
|
-
/** @type {import('./nako3.mjs').Ast[]} */
|
|
12
|
-
this.stack = [];
|
|
13
|
-
this.index = 0;
|
|
14
|
-
/** トークン出現チェック(accept関数)に利用する
|
|
15
|
-
* @type {import('./nako3.mjs').Ast[]}
|
|
16
|
-
*/
|
|
17
|
-
this.y = [];
|
|
18
|
-
/** モジュル名 @type {string} */
|
|
19
|
-
this.modName = 'inline';
|
|
20
|
-
this.namespaceStack = [];
|
|
21
|
-
/**
|
|
22
|
-
* 利用するモジュールの名前一覧
|
|
23
|
-
* @type {Array<string>}
|
|
24
|
-
*/
|
|
25
|
-
this.modList = [];
|
|
26
|
-
/** グローバル変数・関数の確認用 */
|
|
27
|
-
this.funclist = new Map();
|
|
28
|
-
this.funcLevel = 0;
|
|
29
|
-
this.usedAsyncFn = false; // asyncFnの呼び出しがあるかどうか
|
|
30
|
-
/**
|
|
31
|
-
* ローカル変数の確認用
|
|
32
|
-
* @type {Object.<string,Object>}
|
|
33
|
-
*/
|
|
34
|
-
this.localvars = new Map([['それ', { type: 'var', value: '' }]]);
|
|
35
|
-
/** コード生成器の名前 @type {string} */
|
|
36
|
-
this.genMode = 'sync'; // #637
|
|
37
|
-
/** 配列のインデックスが先頭要素(#1140) @type {int} */
|
|
38
|
-
this.arrayIndexFrom = 0;
|
|
39
|
-
/** 配列のインデックス順序を反対にするか(#1140) @type {boolean} */
|
|
40
|
-
this.flagReverseArrayIndex = false;
|
|
41
|
-
/** 配列を自動的に初期化するか(#1140) @type {boolean} */
|
|
42
|
-
this.flagCheckArrayInit = false;
|
|
43
|
-
/** 最近呼び出した関数(余剰エラーの報告に使う) */
|
|
44
|
-
this.recentlyCalledFunc = [];
|
|
45
|
-
// 構文解析に利用する - 現在計算式を読んでいるかどうか
|
|
46
|
-
this.isReadingCalc = false;
|
|
47
|
-
// エクスポート設定が未設定の関数・変数に対する既定値
|
|
48
|
-
this.isExportDefault = true;
|
|
49
|
-
this.isExportStack = [];
|
|
50
|
-
this.moduleExport = new Map();
|
|
51
|
-
this.isModifiedNodes = false;
|
|
52
|
-
this.init();
|
|
53
|
-
}
|
|
54
|
-
init() {
|
|
55
|
-
this.funclist = new Map(); // 関数の一覧
|
|
56
|
-
this.moduleExport = new Map();
|
|
57
|
-
this.reset();
|
|
58
|
-
}
|
|
59
|
-
reset() {
|
|
60
|
-
this.tokens = []; // 字句解析済みのトークンの一覧を保存
|
|
61
|
-
this.index = 0; // tokens[] のどこまで読んだかを管理する
|
|
62
|
-
this.stack = []; // 計算用のスタック ... 直接は操作せず、pushStack() popStack() を介して使う
|
|
63
|
-
this.y = []; // accept()で解析済みのトークンを配列で得るときに使う
|
|
64
|
-
this.genMode = 'sync'; // #637, #1056
|
|
65
|
-
// 次回実行時に持ち越されないように初期化する (#1746)
|
|
66
|
-
this.localvars = new Map([['それ', { type: 'var', value: '' }]]);
|
|
67
|
-
this.usedFuncs = new Set();
|
|
68
|
-
this.funcLevel = 0;
|
|
69
|
-
this.usedAsyncFn = false;
|
|
70
|
-
this.isReadingCalc = false;
|
|
71
|
-
this.isExportDefault = true;
|
|
72
|
-
this.isExportStack = [];
|
|
73
|
-
this.namespaceStack = [];
|
|
74
|
-
this.modList = [];
|
|
75
|
-
this.stackList = [];
|
|
76
|
-
this.recentlyCalledFunc = [];
|
|
77
|
-
this.arrayIndexFrom = 0;
|
|
78
|
-
this.flagReverseArrayIndex = false;
|
|
79
|
-
this.flagCheckArrayInit = false;
|
|
80
|
-
this.isModifiedNodes = false;
|
|
81
|
-
}
|
|
82
|
-
setFuncList(funclist) {
|
|
83
|
-
this.funclist = funclist;
|
|
84
|
-
}
|
|
85
|
-
setModuleExport(moduleexport) {
|
|
86
|
-
this.moduleExport = moduleexport;
|
|
87
|
-
}
|
|
88
|
-
/**
|
|
89
|
-
* 特定の助詞を持つ要素をスタックから一つ下ろす、指定がなければ末尾を下ろす
|
|
90
|
-
* @param {string[]} josiList 下ろしたい助詞の配列
|
|
91
|
-
*/
|
|
92
|
-
popStack(josiList = undefined) {
|
|
93
|
-
if (!josiList) {
|
|
94
|
-
const t = this.stack.pop();
|
|
95
|
-
if (t) {
|
|
96
|
-
return t;
|
|
97
|
-
}
|
|
98
|
-
return null;
|
|
99
|
-
}
|
|
100
|
-
// josiList にマッチする助詞を探す
|
|
101
|
-
for (let i = this.stack.length - 1; i >= 0; i--) {
|
|
102
|
-
const t = this.stack[i];
|
|
103
|
-
if (josiList.length === 0 || josiList.indexOf(t.josi) >= 0) {
|
|
104
|
-
this.stack.splice(i, 1); // remove stack
|
|
105
|
-
this.logger.trace('POP :' + JSON.stringify(t));
|
|
106
|
-
return t;
|
|
107
|
-
}
|
|
108
|
-
}
|
|
109
|
-
// 該当する助詞が見つからなかった場合
|
|
110
|
-
return null;
|
|
111
|
-
}
|
|
112
|
-
/**
|
|
113
|
-
* saveStack と loadStack は対で使う。
|
|
114
|
-
* 関数定義などでスタックが混乱しないように配慮するためのもの
|
|
115
|
-
*/
|
|
116
|
-
saveStack() {
|
|
117
|
-
this.stackList.push(this.stack);
|
|
118
|
-
this.stack = [];
|
|
119
|
-
}
|
|
120
|
-
loadStack() {
|
|
121
|
-
this.stack = this.stackList.pop();
|
|
122
|
-
}
|
|
123
|
-
/** 変数名を探す
|
|
124
|
-
* @param {string} name
|
|
125
|
-
* @returns {any}変数名の情報
|
|
126
|
-
*/
|
|
127
|
-
findVar(name) {
|
|
128
|
-
// ローカル変数?
|
|
129
|
-
if (this.localvars.get(name)) {
|
|
130
|
-
return {
|
|
131
|
-
name,
|
|
132
|
-
scope: 'local',
|
|
133
|
-
info: this.localvars.get(name)
|
|
134
|
-
};
|
|
135
|
-
}
|
|
136
|
-
// モジュール名を含んでいる?
|
|
137
|
-
if (name.indexOf('__') >= 0) {
|
|
138
|
-
if (this.funclist.get(name)) {
|
|
139
|
-
return {
|
|
140
|
-
name,
|
|
141
|
-
scope: 'global',
|
|
142
|
-
info: this.funclist.get(name)
|
|
143
|
-
};
|
|
144
|
-
}
|
|
145
|
-
else {
|
|
146
|
-
return undefined;
|
|
147
|
-
}
|
|
148
|
-
}
|
|
149
|
-
// グローバル変数(自身)?
|
|
150
|
-
const gnameSelf = `${this.modName}__${name}`;
|
|
151
|
-
if (this.funclist.get(gnameSelf)) {
|
|
152
|
-
return {
|
|
153
|
-
name: gnameSelf,
|
|
154
|
-
scope: 'global',
|
|
155
|
-
info: this.funclist.get(gnameSelf)
|
|
156
|
-
};
|
|
157
|
-
}
|
|
158
|
-
// グローバル変数(モジュールを検索)?
|
|
159
|
-
for (const mod of this.modList) {
|
|
160
|
-
const gname = `${mod}__${name}`;
|
|
161
|
-
const exportDefault = this.moduleExport.get(mod);
|
|
162
|
-
const funcObj = this.funclist.get(gname);
|
|
163
|
-
if (funcObj && (funcObj.isExport === true || (funcObj.isExport !== false && exportDefault !== false))) {
|
|
164
|
-
return {
|
|
165
|
-
name: gname,
|
|
166
|
-
scope: 'global',
|
|
167
|
-
info: this.funclist.get(gname)
|
|
168
|
-
};
|
|
169
|
-
}
|
|
170
|
-
}
|
|
171
|
-
// システム変数 (funclistを普通に検索)
|
|
172
|
-
if (this.funclist.get(name)) {
|
|
173
|
-
return {
|
|
174
|
-
name,
|
|
175
|
-
scope: 'system',
|
|
176
|
-
info: this.funclist.get(name)
|
|
177
|
-
};
|
|
178
|
-
}
|
|
179
|
-
return undefined;
|
|
180
|
-
}
|
|
181
|
-
/**
|
|
182
|
-
* 計算用に要素をスタックに積む
|
|
183
|
-
*/
|
|
184
|
-
pushStack(item) {
|
|
185
|
-
this.logger.trace('PUSH:' + JSON.stringify(item));
|
|
186
|
-
this.stack.push(item);
|
|
187
|
-
}
|
|
188
|
-
/**
|
|
189
|
-
* トークンの末尾に達したか
|
|
190
|
-
*/
|
|
191
|
-
isEOF() {
|
|
192
|
-
return (this.index >= this.tokens.length);
|
|
193
|
-
}
|
|
194
|
-
getIndex() {
|
|
195
|
-
return this.index;
|
|
196
|
-
}
|
|
197
|
-
/**
|
|
198
|
-
* カーソル位置にある単語の型を確かめる
|
|
199
|
-
*/
|
|
200
|
-
check(ttype) {
|
|
201
|
-
return (this.tokens[this.index].type === ttype);
|
|
202
|
-
}
|
|
203
|
-
/**
|
|
204
|
-
* カーソル位置以降にある単語の型を確かめる 2単語以上に対応
|
|
205
|
-
* @param a [単語1の型, 単語2の型, ... ]
|
|
206
|
-
*/
|
|
207
|
-
check2(a) {
|
|
208
|
-
for (let i = 0; i < a.length; i++) {
|
|
209
|
-
const idx = i + this.index;
|
|
210
|
-
if (this.tokens.length <= idx) {
|
|
211
|
-
return false;
|
|
212
|
-
}
|
|
213
|
-
if (a[i] === '*') {
|
|
214
|
-
continue;
|
|
215
|
-
} // ワイルドカード(どんなタイプも許容)
|
|
216
|
-
const t = this.tokens[idx];
|
|
217
|
-
if (a[i] instanceof Array) {
|
|
218
|
-
if (a[i].indexOf(t.type) < 0) {
|
|
219
|
-
return false;
|
|
220
|
-
}
|
|
221
|
-
continue;
|
|
222
|
-
}
|
|
223
|
-
if (t.type !== a[i]) {
|
|
224
|
-
return false;
|
|
225
|
-
}
|
|
226
|
-
}
|
|
227
|
-
return true;
|
|
228
|
-
}
|
|
229
|
-
/**
|
|
230
|
-
* カーソル位置の型を確認するが、複数の種類を確かめられる
|
|
231
|
-
*/
|
|
232
|
-
checkTypes(a) {
|
|
233
|
-
const type = this.tokens[this.index].type;
|
|
234
|
-
return (a.indexOf(type) >= 0);
|
|
235
|
-
}
|
|
236
|
-
/**
|
|
237
|
-
* check2の高度なやつ、型名の他にコールバック関数を指定できる
|
|
238
|
-
* 型にマッチしなければ false を返し、カーソルを巻き戻す
|
|
239
|
-
*/
|
|
240
|
-
accept(types) {
|
|
241
|
-
const y = [];
|
|
242
|
-
const tmpIndex = this.index;
|
|
243
|
-
const rollback = () => {
|
|
244
|
-
this.index = tmpIndex;
|
|
245
|
-
return false;
|
|
246
|
-
};
|
|
247
|
-
for (let i = 0; i < types.length; i++) {
|
|
248
|
-
if (this.isEOF()) {
|
|
249
|
-
return rollback();
|
|
250
|
-
}
|
|
251
|
-
const type = types[i];
|
|
252
|
-
if (type === null) {
|
|
253
|
-
return rollback();
|
|
254
|
-
}
|
|
255
|
-
if (typeof type === 'string') {
|
|
256
|
-
const token = this.get();
|
|
257
|
-
if (token && token.type !== type) {
|
|
258
|
-
return rollback();
|
|
259
|
-
}
|
|
260
|
-
y[i] = token;
|
|
261
|
-
continue;
|
|
262
|
-
}
|
|
263
|
-
if (typeof type === 'function') {
|
|
264
|
-
const f = type.bind(this);
|
|
265
|
-
const r = f(y);
|
|
266
|
-
if (r === null) {
|
|
267
|
-
return rollback();
|
|
268
|
-
}
|
|
269
|
-
y[i] = r;
|
|
270
|
-
continue;
|
|
271
|
-
}
|
|
272
|
-
if (type instanceof Array) {
|
|
273
|
-
if (!this.checkTypes(type)) {
|
|
274
|
-
return rollback();
|
|
275
|
-
}
|
|
276
|
-
y[i] = this.get();
|
|
277
|
-
continue;
|
|
278
|
-
}
|
|
279
|
-
throw new Error('System Error : accept broken : ' + typeof type);
|
|
280
|
-
}
|
|
281
|
-
this.y = y;
|
|
282
|
-
return true;
|
|
283
|
-
}
|
|
284
|
-
/**
|
|
285
|
-
* カーソル語句を取得して、カーソルを後ろに移動する
|
|
286
|
-
*/
|
|
287
|
-
get() {
|
|
288
|
-
if (this.isEOF()) {
|
|
289
|
-
return null;
|
|
290
|
-
}
|
|
291
|
-
return this.tokens[this.index++];
|
|
292
|
-
}
|
|
293
|
-
/** カーソル語句を取得してカーソルを進める、取得できなければエラーを出す */
|
|
294
|
-
getCur() {
|
|
295
|
-
if (this.isEOF()) {
|
|
296
|
-
throw new Error('トークンが取得できません。');
|
|
297
|
-
}
|
|
298
|
-
const t = this.tokens[this.index++];
|
|
299
|
-
if (!t) {
|
|
300
|
-
throw new Error('トークンが取得できません。');
|
|
301
|
-
}
|
|
302
|
-
return t;
|
|
303
|
-
}
|
|
304
|
-
unget() {
|
|
305
|
-
if (this.index > 0) {
|
|
306
|
-
this.index--;
|
|
307
|
-
}
|
|
308
|
-
}
|
|
309
|
-
/** 解析中のトークンを返す */
|
|
310
|
-
peek(i = 0) {
|
|
311
|
-
if (this.isEOF()) {
|
|
312
|
-
return null;
|
|
313
|
-
}
|
|
314
|
-
return this.tokens[this.index + i];
|
|
315
|
-
}
|
|
316
|
-
/** 解析中のトークンを返す、無理なら def を返す */
|
|
317
|
-
peekDef(def = null) {
|
|
318
|
-
if (this.isEOF()) {
|
|
319
|
-
if (!def) {
|
|
320
|
-
def = NewEmptyToken();
|
|
321
|
-
}
|
|
322
|
-
return def;
|
|
323
|
-
}
|
|
324
|
-
return this.tokens[this.index];
|
|
325
|
-
}
|
|
326
|
-
/**
|
|
327
|
-
* 現在のカーソル語句のソースコード上の位置を取得する。
|
|
328
|
-
*/
|
|
329
|
-
peekSourceMap(t = undefined) {
|
|
330
|
-
const token = (t === undefined) ? this.peek() : t;
|
|
331
|
-
if (token === null) {
|
|
332
|
-
return { startOffset: undefined, endOffset: undefined, file: undefined, line: 0, column: 0 };
|
|
333
|
-
}
|
|
334
|
-
return { startOffset: token.startOffset, endOffset: token.endOffset, file: token.file, line: token.line, column: token.column };
|
|
335
|
-
}
|
|
336
|
-
/**
|
|
337
|
-
* depth: 表示する深さ
|
|
338
|
-
* typeName: 先頭のtypeの表示を上書きする場合に設定する
|
|
339
|
-
* @param {{ depth: number, typeName?: string }} opts
|
|
340
|
-
* @param {boolean} debugMode
|
|
341
|
-
*/
|
|
342
|
-
nodeToStr(node, opts, debugMode) {
|
|
343
|
-
const depth = opts.depth - 1;
|
|
344
|
-
const typeName = (name) => (opts.typeName !== undefined) ? opts.typeName : name;
|
|
345
|
-
const debug = debugMode ? (' debug: ' + JSON.stringify(node, null, 2)) : '';
|
|
346
|
-
if (!node) {
|
|
347
|
-
return '(NULL)';
|
|
348
|
-
}
|
|
349
|
-
switch (node.type) {
|
|
350
|
-
case 'not':
|
|
351
|
-
if (depth >= 0) {
|
|
352
|
-
const subNode = node.blocks[0];
|
|
353
|
-
return `${typeName('')}『${this.nodeToStr(subNode, { depth }, debugMode)}に演算子『not』を適用した式${debug}』`;
|
|
354
|
-
}
|
|
355
|
-
else {
|
|
356
|
-
return `${typeName('演算子')}『not』`;
|
|
357
|
-
}
|
|
358
|
-
case 'op': {
|
|
359
|
-
const node2 = node;
|
|
360
|
-
let operator = node2.operator || '';
|
|
361
|
-
const table = { eq: '=', not: '!', gt: '>', lt: '<', and: 'かつ', or: 'または' };
|
|
362
|
-
if (operator in table) {
|
|
363
|
-
operator = table[operator];
|
|
364
|
-
}
|
|
365
|
-
if (depth >= 0) {
|
|
366
|
-
const left = this.nodeToStr(node2.blocks[0], { depth }, debugMode);
|
|
367
|
-
const right = this.nodeToStr(node2.blocks[1], { depth }, debugMode);
|
|
368
|
-
if (node2.operator === 'eq') {
|
|
369
|
-
return `${typeName('')}『${left}と${right}が等しいかどうかの比較${debug}』`;
|
|
370
|
-
}
|
|
371
|
-
return `${typeName('')}『${left}と${right}に演算子『${operator}』を適用した式${debug}』`;
|
|
372
|
-
}
|
|
373
|
-
else {
|
|
374
|
-
return `${typeName('演算子')}『${operator}${debug}』`;
|
|
375
|
-
}
|
|
376
|
-
}
|
|
377
|
-
case 'number':
|
|
378
|
-
return `${typeName('数値')}${node.value}`;
|
|
379
|
-
case 'bigint':
|
|
380
|
-
return `${typeName('巨大整数')}${node.value}`;
|
|
381
|
-
case 'string':
|
|
382
|
-
return `${typeName('文字列')}『${node.value}${debug}』`;
|
|
383
|
-
case 'word':
|
|
384
|
-
return `${typeName('単語')}『${node.value}${debug}』`;
|
|
385
|
-
case 'func':
|
|
386
|
-
return `${typeName('関数')}『${node.name || node.value}${debug}』`;
|
|
387
|
-
case 'eol':
|
|
388
|
-
return '行の末尾';
|
|
389
|
-
case 'eof':
|
|
390
|
-
return 'ファイルの末尾';
|
|
391
|
-
default: {
|
|
392
|
-
let name = node.name;
|
|
393
|
-
if (name) {
|
|
394
|
-
name = node.value;
|
|
395
|
-
}
|
|
396
|
-
if (typeof name !== 'string') {
|
|
397
|
-
name = node.type;
|
|
398
|
-
}
|
|
399
|
-
return `${typeName('')}『${name}${debug}』`;
|
|
400
|
-
}
|
|
401
|
-
}
|
|
402
|
-
}
|
|
403
|
-
}
|
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
export const opPriority = {
|
|
2
|
-
// and or
|
|
3
|
-
'and': 1,
|
|
4
|
-
'or': 1,
|
|
5
|
-
// compare
|
|
6
|
-
'eq': 2,
|
|
7
|
-
'noteq': 2,
|
|
8
|
-
'===': 2,
|
|
9
|
-
'!==': 2,
|
|
10
|
-
'gt': 2,
|
|
11
|
-
'gteq': 2,
|
|
12
|
-
'lt': 2,
|
|
13
|
-
'lteq': 2,
|
|
14
|
-
'&': 3,
|
|
15
|
-
// + - << >> >>>
|
|
16
|
-
'+': 4,
|
|
17
|
-
'-': 4,
|
|
18
|
-
'shift_l': 4,
|
|
19
|
-
'shift_r': 4,
|
|
20
|
-
'shift_r0': 4,
|
|
21
|
-
// * /
|
|
22
|
-
'*': 5,
|
|
23
|
-
'/': 5, // 一般的な割り算
|
|
24
|
-
'÷': 5, // 一般的な割り算
|
|
25
|
-
'÷÷': 5, // 整数の割り算
|
|
26
|
-
'%': 5,
|
|
27
|
-
// ^
|
|
28
|
-
'^': 6,
|
|
29
|
-
'**': 6
|
|
30
|
-
};
|
|
31
|
-
export const RenbunJosi = [
|
|
32
|
-
'いて', 'えて', 'きて', 'けて', 'して', 'って', 'にて', 'みて', 'めて', 'ねて', 'には', 'んで'
|
|
33
|
-
];
|
|
34
|
-
export const operatorList = [];
|
|
35
|
-
for (const key in opPriority) {
|
|
36
|
-
operatorList.push(key);
|
|
37
|
-
}
|