nadesiko3 3.2.27
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/LICENSE +21 -0
- package/README.md +107 -0
- package/bin/cnako3 +10 -0
- package/bin/cnako3.bat +11 -0
- package/bin/nako3server.bat +6 -0
- package/demo/ace_editor.html +90 -0
- package/demo/ace_editor_tabs.html +162 -0
- package/demo/basic.html +71 -0
- package/demo/browsers.html +128 -0
- package/demo/css/basic.css +3 -0
- package/demo/css/common.css +157 -0
- package/demo/css/editor.css +8 -0
- package/demo/css/flow.css +3 -0
- package/demo/css/index.css +3 -0
- package/demo/extlib/ace@1.4.12/ace.js +17 -0
- package/demo/extlib/ace@1.4.12/ext-code_lens.min.js +1 -0
- package/demo/extlib/ace@1.4.12/ext-language_tools.min.js +1 -0
- package/demo/extlib/ace@1.4.12/ext-options.min.js +1 -0
- package/demo/extlib/ace@1.4.12/ext-settings_menu.js +8 -0
- package/demo/extlib/ace@1.4.12/keybinding-vscode.js +8 -0
- package/demo/extlib/ace@1.4.12/theme-monokai.js +8 -0
- package/demo/extlib/ace@1.4.12/theme-xcode.js +8 -0
- package/demo/extlib/chart.js@3.2.1/chart.min.js +13 -0
- package/demo/extlib/pure-min.css +11 -0
- package/demo/flow.html +97 -0
- package/demo/graph.html +53 -0
- package/demo/image/nako.png +0 -0
- package/demo/image/nakopad-icon256.png +0 -0
- package/demo/image/turtle.fla +0 -0
- package/demo/image/turtle.png +0 -0
- package/demo/index.html +134 -0
- package/demo/js/common.js +17 -0
- package/demo/js/turtle3d_test.js +44 -0
- package/demo/js/turtle_test.js +44 -0
- package/demo/runscript.html +47 -0
- package/demo/runscript2.html +33 -0
- package/demo/turtle.html +58 -0
- package/demo/turtle2.html +141 -0
- package/demo/turtle3.html +278 -0
- package/demo/turtle3d.html +58 -0
- package/demo/turtle3d2.html +107 -0
- package/demo/version.html +24 -0
- package/doc/SETUP.md +172 -0
- package/doc/about.md +34 -0
- package/doc/browsers.md +60 -0
- package/doc/docgen.md +21 -0
- package/doc/editor.md +44 -0
- package/doc/files.md +37 -0
- package/doc/plugins.md +195 -0
- package/doc/release.md +78 -0
- package/doc/win32.md +57 -0
- package/package.json +196 -0
- package/release/_hash.txt +65 -0
- package/release/_script-tags.txt +13 -0
- package/release/command.json +1 -0
- package/release/command.json.js +1 -0
- package/release/command_cnako3.json +1 -0
- package/release/command_list.json +1 -0
- package/release/editor.js +2 -0
- package/release/editor.js.LICENSE.txt +32 -0
- package/release/josi.json +48 -0
- package/release/nako_gen_async.js +1 -0
- package/release/nako_gen_async.js.LICENSE.txt +595 -0
- package/release/plugin_caniuse.js +1 -0
- package/release/plugin_caniuse.js.LICENSE.txt +411 -0
- package/release/plugin_csv.js +1 -0
- package/release/plugin_csv.js.LICENSE.txt +367 -0
- package/release/plugin_datetime.js +1 -0
- package/release/plugin_datetime.js.LICENSE.txt +471 -0
- package/release/plugin_kansuji.js +1 -0
- package/release/plugin_kansuji.js.LICENSE.txt +491 -0
- package/release/plugin_markup.js +1 -0
- package/release/plugin_markup.js.LICENSE.txt +363 -0
- package/release/plugin_turtle.js +1 -0
- package/release/plugin_turtle.js.LICENSE.txt +435 -0
- package/release/plugin_webworker.js +1 -0
- package/release/plugin_webworker.js.LICENSE.txt +491 -0
- package/release/version.js +2 -0
- package/release/version.js.LICENSE.txt +32 -0
- package/release/wnako3.js +2 -0
- package/release/wnako3.js.LICENSE.txt +1 -0
- package/release/wnako3webworker.js +1 -0
- package/release/wnako3webworker.js.LICENSE.txt +847 -0
- package/release/yoyakugo.json +30 -0
- package/src/browsers.md +60 -0
- package/src/cnako3.js +466 -0
- package/src/commander_ja.js +154 -0
- package/src/enako3.js +69 -0
- package/src/era.json +22 -0
- package/src/index.js +5 -0
- package/src/nako3.js +836 -0
- package/src/nako3_assert.js +37 -0
- package/src/nako3editorfix.sfd +106 -0
- package/src/nako3editorfix.woff +0 -0
- package/src/nako3server.js +51 -0
- package/src/nako_colors.js +86 -0
- package/src/nako_errors.js +176 -0
- package/src/nako_gen.js +1459 -0
- package/src/nako_gen_async.js +1622 -0
- package/src/nako_global.js +113 -0
- package/src/nako_indent.js +480 -0
- package/src/nako_josi_list.js +46 -0
- package/src/nako_lex_rules.js +259 -0
- package/src/nako_lexer.js +576 -0
- package/src/nako_logger.js +138 -0
- package/src/nako_parser3.js +1768 -0
- package/src/nako_parser_base.js +265 -0
- package/src/nako_parser_const.js +37 -0
- package/src/nako_prepare.js +293 -0
- package/src/nako_reserved_words.js +35 -0
- package/src/nako_source_mapping.js +251 -0
- package/src/nako_test.js +37 -0
- package/src/nako_version.js +8 -0
- package/src/plugin_browser.js +191 -0
- package/src/plugin_browser_ajax.js +352 -0
- package/src/plugin_browser_audio.js +109 -0
- package/src/plugin_browser_canvas.js +462 -0
- package/src/plugin_browser_chart.js +296 -0
- package/src/plugin_browser_color.js +49 -0
- package/src/plugin_browser_crypto.js +26 -0
- package/src/plugin_browser_dialog.js +53 -0
- package/src/plugin_browser_dom_basic.js +322 -0
- package/src/plugin_browser_dom_event.js +193 -0
- package/src/plugin_browser_dom_parts.js +163 -0
- package/src/plugin_browser_geolocation.js +51 -0
- package/src/plugin_browser_hotkey.js +25 -0
- package/src/plugin_browser_html.js +59 -0
- package/src/plugin_browser_in_worker.js +44 -0
- package/src/plugin_browser_location.js +21 -0
- package/src/plugin_browser_speech.js +111 -0
- package/src/plugin_browser_storage.js +121 -0
- package/src/plugin_browser_system.js +12 -0
- package/src/plugin_browser_websocket.js +73 -0
- package/src/plugin_caniuse.js +24 -0
- package/src/plugin_csv.js +57 -0
- package/src/plugin_datetime.js +414 -0
- package/src/plugin_express.js +212 -0
- package/src/plugin_kansuji.js +224 -0
- package/src/plugin_keigo.js +55 -0
- package/src/plugin_markup.js +32 -0
- package/src/plugin_math.js +319 -0
- package/src/plugin_node.js +1018 -0
- package/src/plugin_promise.js +94 -0
- package/src/plugin_system.js +2109 -0
- package/src/plugin_test.js +38 -0
- package/src/plugin_turtle.js +646 -0
- package/src/plugin_webworker.js +334 -0
- package/src/plugin_weykturtle3d.js +1216 -0
- package/src/plugin_worker.js +92 -0
- package/src/repl.nako3 +63 -0
- package/src/turtle-elephant.png +0 -0
- package/src/turtle-panda.png +0 -0
- package/src/turtle64.png +0 -0
- package/src/wnako3.js +162 -0
- package/src/wnako3_editor.css +215 -0
- package/src/wnako3_editor.js +1645 -0
- package/src/wnako3_editor_marker_red.png +0 -0
- package/src/wnako3_editor_marker_red.xcf +0 -0
- package/src/wnako3_editor_marker_yellow.png +0 -0
- package/src/wnako3_editor_marker_yellow.xcf +0 -0
- package/src/wnako3webworker.js +70 -0
- package/test/ace_editor/karma.config.js +94 -0
- package/test/ace_editor/test/.babelrc.json +3 -0
- package/test/ace_editor/test/ace_editor_test.js +178 -0
- package/test/ace_editor/test/html/custom_context.html +140 -0
- package/test/async/async_basic_test.js +124 -0
- package/test/browser/karma.config.js +212 -0
- package/test/browser/test/.babelrc.json +3 -0
- package/test/browser/test/compare_util.js +50 -0
- package/test/browser/test/html/canvas_basic.html +1 -0
- package/test/browser/test/html/div_basic.html +2 -0
- package/test/browser/test/html/event_dom_form.html +4 -0
- package/test/browser/test/html/event_dom_scrolldiv.html +5 -0
- package/test/browser/test/image/canvas_test1.png +0 -0
- package/test/browser/test/image/canvas_test2.png +0 -0
- package/test/browser/test/image/canvas_test3.png +0 -0
- package/test/browser/test/image/canvas_test4.png +0 -0
- package/test/browser/test/image/canvas_test7.png +0 -0
- package/test/browser/test/image/canvas_test8.png +0 -0
- package/test/browser/test/image/canvas_test_blank.png +0 -0
- package/test/browser/test/image/elephant_kana.png +0 -0
- package/test/browser/test/image/panda_kana.png +0 -0
- package/test/browser/test/image/turtle_kana.png +0 -0
- package/test/browser/test/import_plugin_checker.js +24 -0
- package/test/browser/test/plugin_browser_test.js +52 -0
- package/test/browser/test/plugin_browser_test_ajax.js +123 -0
- package/test/browser/test/plugin_browser_test_color.js +18 -0
- package/test/browser/test/plugin_browser_test_dialog.js +72 -0
- package/test/browser/test/plugin_browser_test_dom_event.js +598 -0
- package/test/browser/test/plugin_browser_test_dom_parts.js +125 -0
- package/test/browser/test/plugin_browser_test_system.js +9 -0
- package/test/browser/test/plugin_turtle_test.js +817 -0
- package/test/browser/test/plugin_webworker_test.js +87 -0
- package/test/browser/test/require_test.js +71 -0
- package/test/bundled/karma.config.base.js +117 -0
- package/test/bundled/karma.config.js +86 -0
- package/test/bundled/test/.babelrc.json +3 -0
- package/test/bundled/test/bundled_test.js +69 -0
- package/test/bundled/test/html/custom_context.html +65 -0
- package/test/bundled/test/html/custom_debug.html +66 -0
- package/test/bundled/test4b.cmd +52 -0
- package/test/bundled/test_base/.babelrc.json +3 -0
- package/test/bundled/test_base/_checktool_test.js +25 -0
- package/test/bundled/test_base/basic_ajax_test.js +56 -0
- package/test/bundled/test_base/basic_async_test.js +18 -0
- package/test/bundled/test_base/basic_test.js +153 -0
- package/test/bundled/test_base/calc_test.js +132 -0
- package/test/bundled/test_base/css/browsers_box.css +114 -0
- package/test/bundled/test_base/html/custom_context.html +69 -0
- package/test/bundled/test_base/html/custom_debug.html +71 -0
- package/test/bundled/test_base/js/browsers_box.js +72 -0
- package/test/bundled/test_base/plugin_csv_test.js +37 -0
- package/test/bundled/test_base/plugin_datetime_test.js +115 -0
- package/test/bundled/test_base/plugin_kansuji_test.js +49 -0
- package/test/bundled/test_base/plugin_system_test.js +410 -0
- package/test/bundled/test_base/plugin_webworker_test.js +53 -0
- package/test/bundled/test_base/resources/ok.txt +1 -0
- package/test/bundled/test_base/test_utils.js +191 -0
- package/test/common/array_test.js +40 -0
- package/test/common/basic_test.js +317 -0
- package/test/common/calc_test.js +139 -0
- package/test/common/debug_test.js +16 -0
- package/test/common/error_test.js +16 -0
- package/test/common/flow_test.js +360 -0
- package/test/common/func_call.js +136 -0
- package/test/common/func_test.js +149 -0
- package/test/common/indent_test.js +362 -0
- package/test/common/lex_test.js +146 -0
- package/test/common/literal_test.js +72 -0
- package/test/common/nako_logger_test.js +26 -0
- package/test/common/plugin_browser_test.js +24 -0
- package/test/common/plugin_browser_ut_audio_test.js +88 -0
- package/test/common/plugin_browser_ut_color_test.js +21 -0
- package/test/common/plugin_browser_ut_dialog_test.js +100 -0
- package/test/common/plugin_browser_ut_html_test.js +13 -0
- package/test/common/plugin_browser_ut_system_test.js +10 -0
- package/test/common/plugin_csv_test.js +39 -0
- package/test/common/plugin_datetime_test.js +120 -0
- package/test/common/plugin_kansuji_test.js +59 -0
- package/test/common/plugin_promise_test.js +18 -0
- package/test/common/plugin_system_test.js +451 -0
- package/test/common/prepare_test.js +93 -0
- package/test/common/re_test.js +20 -0
- package/test/common/variable_scope_test.js +105 -0
- package/test/jsconfig.json +19 -0
- package/test/karma.config.js +91 -0
- package/test/node/add_test.nako3 +1 -0
- package/test/node/async_test.js +80 -0
- package/test/node/commander_ja_test.js +82 -0
- package/test/node/error_message_test.js +244 -0
- package/test/node/kai_test.nako3 +6 -0
- package/test/node/node_test.js +43 -0
- package/test/node/plugin_broken.js.txt +3 -0
- package/test/node/plugin_browser_ut_ajax_test.js +355 -0
- package/test/node/plugin_browser_ut_location_test.js +32 -0
- package/test/node/plugin_markup_test.js +44 -0
- package/test/node/plugin_math_test.js +42 -0
- package/test/node/plugin_node_test.js +93 -0
- package/test/node/plugin_test.js +16 -0
- package/test/node/relative_import_test_1.nako3 +1 -0
- package/test/node/relative_import_test_2.nako3 +2 -0
- package/test/node/require_nako3_test.js +59 -0
- package/test/node/requiretest.nako3 +4 -0
- package/test/node/requiretest_indirect.nako3 +1 -0
- package/test/node/requiretest_name.nako3 +5 -0
- package/test/node/runtime_error.nako3 +2 -0
- package/test/node/side_effects_test.js +106 -0
- package/test/node/sjis.txt +5 -0
- package/test/node/syntax_error.nako3 +2 -0
- package/test/node/wnako3_editor_test.js +360 -0
- package/tools/README.md +7 -0
- package/tools/nako3edit/html/edit.html +83 -0
- package/tools/nako3edit/html/edit_plugin.js +6 -0
- package/tools/nako3edit/html/files.html +49 -0
- package/tools/nako3edit/html/nako3edit.css +66 -0
- package/tools/nako3edit/index.nako3 +145 -0
- package/tools/nako3edit/run.js +12 -0
- package/tools/nako3server/html/edit.html +104 -0
- package/tools/nako3server/html/edit_plugin.js +6 -0
- package/tools/nako3server/html/files.html +53 -0
- package/tools/nako3server/html/nako3edit.css +66 -0
- package/tools/nako3server/index.nako3 +129 -0
- package/tools/nako3server/run.js +12 -0
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
const NakoColors = require('./nako_colors')
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* ăłăłăă€ă«ăăăăȘă§ăăăźăăă°ă©ă ă§ăă°ăăŒăă«ç©șéăźthisăæăăȘăăžă§ăŻă
|
|
5
|
+
*/
|
|
6
|
+
class NakoGlobal {
|
|
7
|
+
/**
|
|
8
|
+
* @param {import('./nako3')} compiler
|
|
9
|
+
* @param {import('./nako_gen')} gen
|
|
10
|
+
*/
|
|
11
|
+
constructor (compiler, gen) {
|
|
12
|
+
// ăŠăŒă¶ăŒăźăăă°ă©ă ăăç·šéăăă〿°
|
|
13
|
+
this.__locals = {}
|
|
14
|
+
this.__varslist = [
|
|
15
|
+
{ ...compiler.__varslist[0] }, // system
|
|
16
|
+
{ ...compiler.__varslist[1] }, // global
|
|
17
|
+
{ ...compiler.__varslist[2] } // local [2][3][4][5] ...
|
|
18
|
+
]
|
|
19
|
+
this.index = 0
|
|
20
|
+
this.nextIndex = -1
|
|
21
|
+
this.__code = []
|
|
22
|
+
this.__callstack = []
|
|
23
|
+
this.__stack = []
|
|
24
|
+
this.__labels = []
|
|
25
|
+
this.__genMode = gen.genMode
|
|
26
|
+
|
|
27
|
+
// PluginSystemăšdestroy()ăăćç
§ăăăă
|
|
28
|
+
this.__module = { ...compiler.__module } // shallow copy
|
|
29
|
+
this.pluginfiles = { ...compiler.pluginfiles }
|
|
30
|
+
|
|
31
|
+
// PluginWorkeră§ăŠăŒă¶ăŒćźçŸ©éąæ°ăźJavaScriptăłăŒăăworkerăźăłăłăă€ă©ăźă€ăłăčăżăłăčăžăłăăŒăăăă
|
|
32
|
+
this.gen = gen
|
|
33
|
+
|
|
34
|
+
// 仄äžăźăĄăœăăă§äœżăăă
|
|
35
|
+
this.logger = compiler.logger
|
|
36
|
+
this.compiler = compiler
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
clearLog () {
|
|
40
|
+
this.__varslist[0]['èĄšç€șăă°'] = ''
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
get log () {
|
|
44
|
+
let s = this.__varslist[0]['èĄšç€șăă°']
|
|
45
|
+
s = s.replace(/\s+$/, '')
|
|
46
|
+
return s
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* ăăăă·ăłăćœä»€ăźăăăźăĄăœăă
|
|
51
|
+
* @param {string} code
|
|
52
|
+
* @param {string} fname
|
|
53
|
+
* @param {Partial<import('./nako3').CompilerOptions & { resetLog: boolean }>} opts
|
|
54
|
+
* @param {string} [preCode]
|
|
55
|
+
*/
|
|
56
|
+
runEx (code, fname, opts, preCode = '') {
|
|
57
|
+
// ăčăłăŒăăć
±æăăŠćźèĄ
|
|
58
|
+
return this.compiler._runEx(code, fname, opts, preCode, this)
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* ăăčăćźèĄăźăăăźăĄăœăă
|
|
63
|
+
* @param {{ name: string, f: () => void }[]} tests
|
|
64
|
+
*/
|
|
65
|
+
_runTests (tests) {
|
|
66
|
+
let text = `${NakoColors.color.bold}ăăčăăźćźèĄç”æ${NakoColors.color.reset}\n`
|
|
67
|
+
let pass = 0
|
|
68
|
+
let numFailures = 0
|
|
69
|
+
for (const t of tests) {
|
|
70
|
+
try {
|
|
71
|
+
t.f()
|
|
72
|
+
text += `${NakoColors.color.green}â${NakoColors.color.reset} ${t.name}\n`
|
|
73
|
+
pass++
|
|
74
|
+
} catch (err) {
|
|
75
|
+
text += `${NakoColors.color.red}â${NakoColors.color.reset} ${t.name}: ${err.message}\n`
|
|
76
|
+
numFailures++
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
if (numFailures > 0) {
|
|
80
|
+
text += `${NakoColors.color.green}æć ${pass}ä»¶ ${NakoColors.color.red}怱æ ${numFailures}ä»¶`
|
|
81
|
+
} else {
|
|
82
|
+
text += `${NakoColors.color.green}æć ${pass}ä»¶`
|
|
83
|
+
}
|
|
84
|
+
this.numFailures = numFailures
|
|
85
|
+
this.logger.send('stdout', text)
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
/**
|
|
89
|
+
* æŻăă©ă°ă€ăłăźă!ăŻăȘăąăéąæ°ăćźèĄ
|
|
90
|
+
*/
|
|
91
|
+
clearPlugins () {
|
|
92
|
+
const clearName = '!ăŻăȘăą'
|
|
93
|
+
for (const pname in this.pluginfiles) {
|
|
94
|
+
const po = this.__module[pname]
|
|
95
|
+
if (po[clearName] && po[clearName].fn) {
|
|
96
|
+
po[clearName].fn(this)
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
/**
|
|
102
|
+
* ćçšźăȘă»ăăćŠç
|
|
103
|
+
*/
|
|
104
|
+
reset () {
|
|
105
|
+
this.clearPlugins()
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
destroy () {
|
|
109
|
+
this.reset()
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
module.exports = NakoGlobal
|
|
@@ -0,0 +1,480 @@
|
|
|
1
|
+
const { NakoIndentError } = require('./nako_errors')
|
|
2
|
+
const NakoPrepare = require('./nako_prepare')
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* ă€ăłăăłăæ§ææćźăăăă°ăłăŒăă〿ăă
|
|
6
|
+
* @param {string} code
|
|
7
|
+
* @param {string} filename
|
|
8
|
+
* @returns {{ code: string, insertedLines: number[], deletedLines: { lineNumber: number, len: number }[] }}
|
|
9
|
+
*/
|
|
10
|
+
function convert (code, filename) {
|
|
11
|
+
// æćăź30èĄăăă§ăăŻ
|
|
12
|
+
if (isIndentSyntaxEnabled(code)) {
|
|
13
|
+
return convertGo(code, filename)
|
|
14
|
+
}
|
|
15
|
+
return { code, insertedLines: [], deletedLines: [] }
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
// ăăăăȘăæčèĄăăŒăŻăćźçŸ©
|
|
19
|
+
const SpecialRetMark = 'đđæčèĄđđs4j#WjcSbđ/FcX3đđ'
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* @param {string} code
|
|
23
|
+
* @returns {boolean}
|
|
24
|
+
*/
|
|
25
|
+
function isIndentSyntaxEnabled (code) {
|
|
26
|
+
// ăăă°ă©ă ćé ă«ă!ă€ăłăăłăæ§æăăăăă°ă€ăłăăłăæ§æăæćč
|
|
27
|
+
const keywords = ['!ă€ăłăăłăæ§æ', '!ăăăŸă§ă ăă']
|
|
28
|
+
const lines = code.split('\n', 30)
|
|
29
|
+
for (const line of lines) {
|
|
30
|
+
const s9 = line.substr(0, 8).replace('ïŒ', '!')
|
|
31
|
+
if (keywords.indexOf(s9) >= 0) {
|
|
32
|
+
return true
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
return false
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* ăœăŒăčăłăŒăăźăă1èĄăźäžăźăłăĄăłăăć
šăŠćăé€ăă
|
|
40
|
+
* äșćă«replaceRetMarkă«ăăŁăŠæććăçŻćČăłăĄăłăć
ăźæčèĄæćăçœźæăăăŠăăćż
èŠăăăă
|
|
41
|
+
* @param {string} src
|
|
42
|
+
* @return {string}
|
|
43
|
+
*/
|
|
44
|
+
function removeCommentsFromLine (src) {
|
|
45
|
+
const prepare = new NakoPrepare() // `â»`, `ïŒ/`, `ïŒïŒ` ăšăăŁăăăżăŒăłć
šăŠă«ćŻŸćżăăăăă«ćż
èŠ
|
|
46
|
+
const len = src.length
|
|
47
|
+
let result = ''
|
|
48
|
+
let eos = ''
|
|
49
|
+
let i = 0
|
|
50
|
+
let isComment = false
|
|
51
|
+
while (i < len) {
|
|
52
|
+
const c = src.charAt(i)
|
|
53
|
+
const ch2 = src.substr(i, 2)
|
|
54
|
+
const cPrepared = prepare.convert1ch(c)
|
|
55
|
+
const ch2Prepared = ch2.split('').map((c) => prepare.convert1ch(c)).join('')
|
|
56
|
+
|
|
57
|
+
// eosă?
|
|
58
|
+
if (eos !== '') {
|
|
59
|
+
// srcăźiæćçźä»„éăeosă§ć§ăŸăăȘăæććăç”äșăăăă§ăȘăăă°1æćéČăă
|
|
60
|
+
if (eos === (eos.length === 1 ? cPrepared : ch2Prepared)) {
|
|
61
|
+
if (!isComment) {
|
|
62
|
+
result += src.substr(i, eos.length)
|
|
63
|
+
}
|
|
64
|
+
i += eos.length
|
|
65
|
+
isComment = false
|
|
66
|
+
eos = ''
|
|
67
|
+
} else {
|
|
68
|
+
if (!isComment) {
|
|
69
|
+
result += c
|
|
70
|
+
}
|
|
71
|
+
i++
|
|
72
|
+
}
|
|
73
|
+
continue
|
|
74
|
+
}
|
|
75
|
+
// æććăźæčèĄăçĄèŠăă
|
|
76
|
+
switch (cPrepared) {
|
|
77
|
+
case '"':
|
|
78
|
+
case '\'':
|
|
79
|
+
eos = c
|
|
80
|
+
result += c
|
|
81
|
+
i++
|
|
82
|
+
continue
|
|
83
|
+
case 'ă':
|
|
84
|
+
eos = 'ă'
|
|
85
|
+
result += c
|
|
86
|
+
i++
|
|
87
|
+
continue
|
|
88
|
+
case 'ă':
|
|
89
|
+
eos = 'ă'
|
|
90
|
+
result += c
|
|
91
|
+
i++
|
|
92
|
+
continue
|
|
93
|
+
case 'â':
|
|
94
|
+
eos = 'â'
|
|
95
|
+
result += c
|
|
96
|
+
i++
|
|
97
|
+
continue
|
|
98
|
+
case '{':
|
|
99
|
+
eos = '}'
|
|
100
|
+
result += c
|
|
101
|
+
i++
|
|
102
|
+
continue
|
|
103
|
+
case '[':
|
|
104
|
+
eos = ']'
|
|
105
|
+
result += c
|
|
106
|
+
i++
|
|
107
|
+
continue
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
switch (ch2) {
|
|
111
|
+
case 'đŽ':
|
|
112
|
+
eos = 'đŽ'
|
|
113
|
+
result += ch2
|
|
114
|
+
i += 2
|
|
115
|
+
continue
|
|
116
|
+
case 'đż':
|
|
117
|
+
eos = 'đż'
|
|
118
|
+
result += ch2
|
|
119
|
+
i += 2
|
|
120
|
+
continue
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
// èĄăłăĄăłă
|
|
124
|
+
if (cPrepared === '#') {
|
|
125
|
+
eos = '\n'
|
|
126
|
+
isComment = true
|
|
127
|
+
i++
|
|
128
|
+
continue
|
|
129
|
+
}
|
|
130
|
+
if (ch2Prepared === '//') {
|
|
131
|
+
eos = '\n'
|
|
132
|
+
isComment = true
|
|
133
|
+
i += 2
|
|
134
|
+
continue
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
// çŻćČăłăĄăłă
|
|
138
|
+
if (ch2Prepared === '/*') {
|
|
139
|
+
eos = '*/'
|
|
140
|
+
isComment = true
|
|
141
|
+
i += 2
|
|
142
|
+
continue
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
result += c
|
|
146
|
+
i++
|
|
147
|
+
}
|
|
148
|
+
return result
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
/**
|
|
152
|
+
* @param {string} code
|
|
153
|
+
* @param {string} filename
|
|
154
|
+
* @returns {{ code: string, insertedLines: number[], deletedLines: { lineNumber: number, len: number }[] }}
|
|
155
|
+
*/
|
|
156
|
+
function convertGo (code, filename) {
|
|
157
|
+
/** @type {number[]} */
|
|
158
|
+
const insertedLines = []
|
|
159
|
+
/** @type {{ lineNumber: number, len: number }[]} */
|
|
160
|
+
const deletedLines = []
|
|
161
|
+
|
|
162
|
+
const END = 'ăăăŸă§â°'
|
|
163
|
+
const code2 = replaceRetMark(code) // æććăźäžăȘă©ăźæčèĄăçœźæ
|
|
164
|
+
const lines = code2.split('\n')
|
|
165
|
+
/** @type {string[]} */
|
|
166
|
+
const lines2 = []
|
|
167
|
+
/** @type {number[]} */
|
|
168
|
+
const indentStack = []
|
|
169
|
+
let lastIndent = 0
|
|
170
|
+
|
|
171
|
+
let lineCount = -1
|
|
172
|
+
lines.forEach((line) => {
|
|
173
|
+
lineCount += line.split(SpecialRetMark).length
|
|
174
|
+
// trim line
|
|
175
|
+
// eslint-disable-next-line no-irregular-whitespace
|
|
176
|
+
if (/^[ ăă»\t]*$/.test(line)) {
|
|
177
|
+
deletedLines.push({ lineNumber: lines2.length, len: line.length })
|
|
178
|
+
return
|
|
179
|
+
}
|
|
180
|
+
// eslint-disable-next-line no-irregular-whitespace
|
|
181
|
+
const lineTrimed = removeCommentsFromLine(line).replace(/^[ ăă»\t]+/, '').replace(/\s+$/, '')
|
|
182
|
+
if (lineTrimed === '') {
|
|
183
|
+
lines2.push(line)
|
|
184
|
+
return
|
|
185
|
+
}
|
|
186
|
+
if (lineTrimed === 'ăăăŸă§') {
|
|
187
|
+
throw new NakoIndentError('ă€ăłăăłăæ§æăæćčćăăăŠăăăšăă«ăăăăŸă§ăăäœżăăăšăŻă§ăăŸăăă', lineCount, filename)
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
// check indent
|
|
191
|
+
const indent = countIndent(line)
|
|
192
|
+
if (lastIndent === indent) {
|
|
193
|
+
lines2.push(line)
|
|
194
|
+
return
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
// indent
|
|
198
|
+
if (lastIndent < indent) {
|
|
199
|
+
indentStack.push(lastIndent)
|
|
200
|
+
lastIndent = indent
|
|
201
|
+
lines2.push(line)
|
|
202
|
+
return
|
|
203
|
+
}
|
|
204
|
+
// unindent
|
|
205
|
+
if (lastIndent > indent) {
|
|
206
|
+
// 5ć
|
|
207
|
+
// 3ć
|
|
208
|
+
// 1ăèĄšç€ș
|
|
209
|
+
// |
|
|
210
|
+
// |
|
|
211
|
+
lastIndent = indent
|
|
212
|
+
while (indentStack.length > 0) {
|
|
213
|
+
const n = indentStack.pop()
|
|
214
|
+
if (n === indent) {
|
|
215
|
+
if (lineTrimed.substr(0, 3) !== 'éăă°') {
|
|
216
|
+
insertedLines.push(lines2.length)
|
|
217
|
+
lines2.push(makeIndent(n) + END)
|
|
218
|
+
}
|
|
219
|
+
lines2.push(line)
|
|
220
|
+
return
|
|
221
|
+
}
|
|
222
|
+
if (indent < n) {
|
|
223
|
+
insertedLines.push(lines2.length)
|
|
224
|
+
lines2.push(makeIndent(n) + END)
|
|
225
|
+
continue
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
})
|
|
230
|
+
// æźăăźă€ăłăăłăăćŠç
|
|
231
|
+
while (indentStack.length > 0) {
|
|
232
|
+
const n = indentStack.pop()
|
|
233
|
+
insertedLines.push(lines2.length)
|
|
234
|
+
lines2.push(makeIndent(n) + END)
|
|
235
|
+
}
|
|
236
|
+
// çčć„ăăŒă«ăŒăæčèĄă«çœźæ
|
|
237
|
+
/** @type {string[]} */
|
|
238
|
+
const lines3 = []
|
|
239
|
+
for (let i = 0; i < lines2.length; i++) {
|
|
240
|
+
if (lines2[i].includes(SpecialRetMark)) {
|
|
241
|
+
const lines4 = lines2[i].split(SpecialRetMark)
|
|
242
|
+
|
|
243
|
+
// çœźæăăăăăŒă«ăŒăźæ°ă ăăăă仄éăźèĄæ°ăăăăă
|
|
244
|
+
// unindentă«ăăŁăŠæżć
„ăăăèĄăSpecialRetMarkăć«ăăăšăŻăȘăă
|
|
245
|
+
for (let j = 0; j < insertedLines.length; j++) {
|
|
246
|
+
if (lines3.length < insertedLines[j]) {
|
|
247
|
+
insertedLines[j] += lines4.length - 1
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
for (let j = 0; j < deletedLines.length; j++) {
|
|
251
|
+
if (lines3.length < deletedLines[j].lineNumber) {
|
|
252
|
+
deletedLines[j].lineNumber += lines4.length - 1
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
lines3.push(...lines4)
|
|
257
|
+
} else {
|
|
258
|
+
lines3.push(lines2[i])
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
return { code: lines3.join('\n'), insertedLines, deletedLines }
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
function makeIndent (count) {
|
|
266
|
+
let s = ''
|
|
267
|
+
for (let i = 0; i < count; i++) {
|
|
268
|
+
s += ' '
|
|
269
|
+
}
|
|
270
|
+
return s
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
/**
|
|
274
|
+
* ă€ăłăăłăéšćăćăćșă
|
|
275
|
+
* @param {string} line
|
|
276
|
+
* @returns {string}
|
|
277
|
+
*/
|
|
278
|
+
function getIndent (line) {
|
|
279
|
+
// @ts-ignore
|
|
280
|
+
// eslint-disable-next-line no-irregular-whitespace
|
|
281
|
+
return /^([ ăă»\t]*)/.exec(removeCommentsFromLine(line))[1]
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
/**
|
|
285
|
+
* ă€ăłăăłăăźćæ°ăæ°ăă
|
|
286
|
+
* @param {string} line
|
|
287
|
+
*/
|
|
288
|
+
function countIndent (line) {
|
|
289
|
+
let cnt = 0
|
|
290
|
+
for (let i = 0; i < line.length; i++) {
|
|
291
|
+
const ch = line.charAt(i)
|
|
292
|
+
if (ch === ' ') {
|
|
293
|
+
cnt++
|
|
294
|
+
continue
|
|
295
|
+
}
|
|
296
|
+
if (ch === 'ă') {
|
|
297
|
+
cnt += 2
|
|
298
|
+
continue
|
|
299
|
+
}
|
|
300
|
+
if (ch === 'ă»') {
|
|
301
|
+
cnt += 2
|
|
302
|
+
continue
|
|
303
|
+
}
|
|
304
|
+
if (ch === '\t') {
|
|
305
|
+
cnt += 4
|
|
306
|
+
continue
|
|
307
|
+
}
|
|
308
|
+
break
|
|
309
|
+
}
|
|
310
|
+
return cnt
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
function replaceRetMark (src) {
|
|
314
|
+
const prepare = new NakoPrepare() // `â»`, `ïŒ/`, `ïŒïŒ` ăšăăŁăăăżăŒăłć
šăŠă«ćŻŸćżăăăăă«ćż
èŠ
|
|
315
|
+
const len = src.length
|
|
316
|
+
let result = ''
|
|
317
|
+
let eos = ''
|
|
318
|
+
let i = 0
|
|
319
|
+
while (i < len) {
|
|
320
|
+
const c = src.charAt(i)
|
|
321
|
+
const ch2 = src.substr(i, 2)
|
|
322
|
+
const cPrepared = prepare.convert1ch(c)
|
|
323
|
+
const ch2Prepared = ch2.split('').map((c) => prepare.convert1ch(c)).join('')
|
|
324
|
+
|
|
325
|
+
// eosă?
|
|
326
|
+
if (eos !== '') {
|
|
327
|
+
// srcăźiæćçźä»„éăeosă§ć§ăŸăăȘăæććăç”äșăăăă§ăȘăăă°1æćéČăă
|
|
328
|
+
if (eos === (eos.length === 1 ? cPrepared : ch2Prepared)) {
|
|
329
|
+
result += src.substr(i, eos.length)
|
|
330
|
+
i += eos.length
|
|
331
|
+
eos = ''
|
|
332
|
+
} else {
|
|
333
|
+
if (c === '\n') {
|
|
334
|
+
result += SpecialRetMark
|
|
335
|
+
} else {
|
|
336
|
+
result += c
|
|
337
|
+
}
|
|
338
|
+
i++
|
|
339
|
+
}
|
|
340
|
+
continue
|
|
341
|
+
}
|
|
342
|
+
// æććăźæčèĄăçĄèŠăă
|
|
343
|
+
switch (cPrepared) {
|
|
344
|
+
case '"':
|
|
345
|
+
case '\'':
|
|
346
|
+
eos = c
|
|
347
|
+
result += c
|
|
348
|
+
i++
|
|
349
|
+
continue
|
|
350
|
+
case 'ă':
|
|
351
|
+
eos = 'ă'
|
|
352
|
+
result += c
|
|
353
|
+
i++
|
|
354
|
+
continue
|
|
355
|
+
case 'ă':
|
|
356
|
+
eos = 'ă'
|
|
357
|
+
result += c
|
|
358
|
+
i++
|
|
359
|
+
continue
|
|
360
|
+
case 'â':
|
|
361
|
+
eos = 'â'
|
|
362
|
+
result += c
|
|
363
|
+
i++
|
|
364
|
+
continue
|
|
365
|
+
case '{':
|
|
366
|
+
eos = '}'
|
|
367
|
+
result += c
|
|
368
|
+
i++
|
|
369
|
+
continue
|
|
370
|
+
case '[':
|
|
371
|
+
eos = ']'
|
|
372
|
+
result += c
|
|
373
|
+
i++
|
|
374
|
+
continue
|
|
375
|
+
}
|
|
376
|
+
|
|
377
|
+
switch (ch2) {
|
|
378
|
+
case 'đŽ':
|
|
379
|
+
eos = 'đŽ'
|
|
380
|
+
result += ch2
|
|
381
|
+
i += 2
|
|
382
|
+
continue
|
|
383
|
+
case 'đż':
|
|
384
|
+
eos = 'đż'
|
|
385
|
+
result += ch2
|
|
386
|
+
i += 2
|
|
387
|
+
continue
|
|
388
|
+
}
|
|
389
|
+
|
|
390
|
+
// èĄăłăĄăłă
|
|
391
|
+
if (cPrepared === '#') {
|
|
392
|
+
eos = '\n'
|
|
393
|
+
result += c
|
|
394
|
+
i++
|
|
395
|
+
continue
|
|
396
|
+
}
|
|
397
|
+
if (ch2Prepared === '//') {
|
|
398
|
+
eos = '\n'
|
|
399
|
+
result += ch2
|
|
400
|
+
i += 2
|
|
401
|
+
continue
|
|
402
|
+
}
|
|
403
|
+
|
|
404
|
+
// çŻćČăłăĄăłă
|
|
405
|
+
if (ch2Prepared === '/*') {
|
|
406
|
+
eos = '*/'
|
|
407
|
+
result += ch2
|
|
408
|
+
i += 2
|
|
409
|
+
continue
|
|
410
|
+
}
|
|
411
|
+
|
|
412
|
+
result += c
|
|
413
|
+
i++
|
|
414
|
+
}
|
|
415
|
+
return result
|
|
416
|
+
}
|
|
417
|
+
|
|
418
|
+
/**
|
|
419
|
+
* ăłăŒăăźă€ăłăăłăăźæ§é ăććŸăăă
|
|
420
|
+
* ç©șçœèĄăè€æ°èĄă«ăŸăăăæ§æăèæ
źăăă
|
|
421
|
+
* ă€ăłăăłăæ§æăæćčćăăăŠăăȘăć Žćă«ăäœżăăăă
|
|
422
|
+
* @param {string} code
|
|
423
|
+
*/
|
|
424
|
+
function getBlockStructure (code) {
|
|
425
|
+
/** @type {{ lines: number[], pairs: [number, number][], parents: (number | null)[], spaces: string[] }} */
|
|
426
|
+
const result = {
|
|
427
|
+
lines: [], // ćèĄăźă€ăłăăłăé
|
|
428
|
+
pairs: [],
|
|
429
|
+
parents: [], // ćèĄăźèŠȘăźèĄ
|
|
430
|
+
spaces: [] // ćèĄăźă€ăłăăłăăźæćć
|
|
431
|
+
}
|
|
432
|
+
|
|
433
|
+
const lines = replaceRetMark(code).split('\n')
|
|
434
|
+
|
|
435
|
+
/** @type {number[]} */
|
|
436
|
+
const stack = []
|
|
437
|
+
let lineCount = 0
|
|
438
|
+
let prev = countIndent(lines[0])
|
|
439
|
+
for (const line of lines) {
|
|
440
|
+
const numLines = line.split(SpecialRetMark).length
|
|
441
|
+
const line2 = removeCommentsFromLine(line)
|
|
442
|
+
// eslint-disable-next-line no-irregular-whitespace
|
|
443
|
+
const current = (line2.replace(/^[ ăă»\t]+/, '') === '')
|
|
444
|
+
? prev
|
|
445
|
+
: countIndent(line2)
|
|
446
|
+
result.lines.push(...Array(numLines).fill(current))
|
|
447
|
+
// @ts-ignore
|
|
448
|
+
result.spaces.push(...Array(numLines).fill(getIndent(line2)))
|
|
449
|
+
|
|
450
|
+
if (prev < current) {
|
|
451
|
+
stack.push(lineCount - 1)
|
|
452
|
+
} else if (prev > current) {
|
|
453
|
+
const last = stack.pop()
|
|
454
|
+
if (last !== undefined) {
|
|
455
|
+
result.pairs.push([last, lineCount])
|
|
456
|
+
}
|
|
457
|
+
}
|
|
458
|
+
|
|
459
|
+
const parent = stack[stack.length - 1] !== undefined ? stack[stack.length - 1] : null
|
|
460
|
+
result.parents.push(...Array(numLines).fill(parent))
|
|
461
|
+
|
|
462
|
+
prev = current
|
|
463
|
+
lineCount += numLines
|
|
464
|
+
}
|
|
465
|
+
|
|
466
|
+
// ăčăżăăŻăäœăŁăăăłăŒăăźæ«ć°Ÿăšăăąă«ăăă
|
|
467
|
+
for (const item of stack) {
|
|
468
|
+
result.pairs.push([item, lineCount])
|
|
469
|
+
}
|
|
470
|
+
|
|
471
|
+
return result
|
|
472
|
+
}
|
|
473
|
+
|
|
474
|
+
module.exports = {
|
|
475
|
+
convert,
|
|
476
|
+
getBlockStructure,
|
|
477
|
+
getIndent,
|
|
478
|
+
countIndent,
|
|
479
|
+
isIndentSyntaxEnabled
|
|
480
|
+
}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ć©è©ăźäžèЧ
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
const josiList = [
|
|
6
|
+
'ă«ă€ăăŠ', 'ăăă', 'ăȘăźă', 'ăŸă§ă', 'ăŸă§ăź', 'ă«ăă',
|
|
7
|
+
'ăšăŻ', 'ăă', 'ăŸă§', 'ă ă', 'ăă', 'ă»ă©', 'ăȘă©',
|
|
8
|
+
'ăăŠ', 'ăăŠ', 'ăăŠ', 'ăăŠ', 'ăăŠ', 'ăŁăŠ', 'ă«ăŠ', 'ăżăŠ',
|
|
9
|
+
'ăăŠ', 'ăăŠ', 'ă§ăŻ', 'ă«ăŻ', 'ăŻ~', 'ăă§',
|
|
10
|
+
'ăŻ', 'ă', 'ă«', 'ăž', 'ă§', 'ăš', 'ă', 'ăź'
|
|
11
|
+
]
|
|
12
|
+
|
|
13
|
+
// ăăăăæă§äœżăć©è©
|
|
14
|
+
const tararebaJosiList = [
|
|
15
|
+
'ă§ăȘăăă°', 'ăȘăăă°', 'ăȘăă°', 'ăȘă', 'ăă', 'ăă°'
|
|
16
|
+
]
|
|
17
|
+
|
|
18
|
+
// æćłăźăȘăć©è©(ćé€ăă) #936 #939 #974
|
|
19
|
+
const removeJosiList = [
|
|
20
|
+
'ăăš', 'ă§ăă', 'ă§ă', 'ăăŸă', 'ă§ăă'
|
|
21
|
+
]
|
|
22
|
+
|
|
23
|
+
// äžèЧăăăă°ă©ă ă§æ±ăăăăăăăăăă«ć€æ
|
|
24
|
+
const tararebaMap = {}
|
|
25
|
+
tararebaJosiList.forEach(josi => {
|
|
26
|
+
josiList.push(josi)
|
|
27
|
+
tararebaMap[josi] = true
|
|
28
|
+
})
|
|
29
|
+
const removeJosiMap = {}
|
|
30
|
+
removeJosiList.forEach(josi => {
|
|
31
|
+
josiList.push(josi)
|
|
32
|
+
removeJosiMap[josi] = true
|
|
33
|
+
})
|
|
34
|
+
|
|
35
|
+
// æćæ°ăźé·ăé ă«äžŠăłæżă
|
|
36
|
+
josiList.sort((a, b) => b.length - a.length)
|
|
37
|
+
|
|
38
|
+
// æŁèŠèĄšçŸă§ć©è©ăăăăă§ăăăăă«ăă
|
|
39
|
+
const josiRE = new RegExp('^[\\t ]*(' + josiList.join('|') + ')')
|
|
40
|
+
|
|
41
|
+
module.exports = {
|
|
42
|
+
josiRE,
|
|
43
|
+
tararebaMap,
|
|
44
|
+
removeJosiMap,
|
|
45
|
+
josiList
|
|
46
|
+
}
|