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,106 @@
|
|
|
1
|
+
const NakoCompiler = require('../../src/nako3')
|
|
2
|
+
const assert = require('assert')
|
|
3
|
+
const CNako3 = require('../../src/cnako3')
|
|
4
|
+
const { NakoSyntaxError } = require('../../src/nako_errors')
|
|
5
|
+
const path = require('path')
|
|
6
|
+
|
|
7
|
+
describe('side_effects_test', () => {
|
|
8
|
+
it('変数の定義 - 1', () => {
|
|
9
|
+
const nako = new NakoCompiler()
|
|
10
|
+
nako.run(`A=10`, 'main.nako3')
|
|
11
|
+
assert.strictEqual(nako.run(`Aを表示`, 'main.nako3').log, `undefined`)
|
|
12
|
+
})
|
|
13
|
+
it('関数の定義 - 変数として参照', () => {
|
|
14
|
+
const nako = new NakoCompiler()
|
|
15
|
+
nako.run(`●Aとは\nここまで`, 'main.nako3')
|
|
16
|
+
assert.strictEqual(nako.run(`Aを表示`, 'main.nako3').log, `undefined`)
|
|
17
|
+
})
|
|
18
|
+
it('関数の定義 - 関数として参照', () => {
|
|
19
|
+
const nako = new NakoCompiler()
|
|
20
|
+
nako.run(`●Aとは\nここまで`, 'main.nako3')
|
|
21
|
+
assert.throws(() => nako.run(`A`, 'main.nako3'), NakoSyntaxError)
|
|
22
|
+
})
|
|
23
|
+
it('関数の定義 - 関数として定義した場合', () => {
|
|
24
|
+
const nako = new NakoCompiler()
|
|
25
|
+
nako.run(`●Aとは\nここまで`, 'main.nako3')
|
|
26
|
+
assert.strictEqual(nako.run(`●(xの)Aとは\nここまで`, 'main.nako3').log, ``)
|
|
27
|
+
})
|
|
28
|
+
it('プラグイン変数の上書き', () => {
|
|
29
|
+
const nako = new NakoCompiler()
|
|
30
|
+
nako.addPluginObject('SideEffectTestPlugin', {
|
|
31
|
+
'プラグイン変数': {type: 'var', value: 100},
|
|
32
|
+
})
|
|
33
|
+
nako.run(`プラグイン変数=20`, 'main.nako3')
|
|
34
|
+
assert.strictEqual(nako.run(`プラグイン変数を表示`, 'main.nako3').log, `100`)
|
|
35
|
+
})
|
|
36
|
+
it('プラグイン関数の上書き', () => {
|
|
37
|
+
const nako = new NakoCompiler()
|
|
38
|
+
nako.run(`●足すとは\nここまで`, 'main.nako3')
|
|
39
|
+
assert.strictEqual(nako.run(`1と2を足して表示`, 'main.nako3').log, `3`)
|
|
40
|
+
})
|
|
41
|
+
it('addFuncで設定した関数の上書き', () => {
|
|
42
|
+
const nako = new NakoCompiler()
|
|
43
|
+
nako.addFunc('hoge', [], () => 1, false)
|
|
44
|
+
assert.strictEqual(nako.run(`●hogeとは\n2を戻す\nここまで\nhogeを表示`, 'main.nako3').log, '2')
|
|
45
|
+
assert.strictEqual(nako.run(`hogeを表示`, 'main.nako3').log, '1')
|
|
46
|
+
})
|
|
47
|
+
it('プラグインの取り込み', () => {
|
|
48
|
+
const nako = new CNako3({ nostd: true })
|
|
49
|
+
nako.silent = true
|
|
50
|
+
|
|
51
|
+
// 取り込み命令ありで実行
|
|
52
|
+
const code1 = '!「plugin_csv」を取り込む。\n「1,2」のCSV取得して表示'
|
|
53
|
+
assert.strictEqual(nako.run(code1, 'main.nako3').log, `1,2`)
|
|
54
|
+
|
|
55
|
+
// 取り込み命令なしで実行
|
|
56
|
+
const code2 = '!「1,2」のCSV取得して表示'
|
|
57
|
+
assert.throws(() => nako.run(code2, 'main.nako3'), NakoSyntaxError)
|
|
58
|
+
})
|
|
59
|
+
it('ファイルの取り込み', () => {
|
|
60
|
+
const nako = new CNako3({ nostd: true })
|
|
61
|
+
nako.silent = true
|
|
62
|
+
|
|
63
|
+
// 取り込み命令ありで実行
|
|
64
|
+
const fname = path.join(__dirname, 'requiretest.nako3')
|
|
65
|
+
const code1 = `!「${fname}」を取り込む。\n痕跡を表示。3と5を痕跡演算して、表示。`
|
|
66
|
+
assert.strictEqual(nako.run(code1, 'main.nako3').log, `5\n8`)
|
|
67
|
+
|
|
68
|
+
// 取り込み命令なしで実行
|
|
69
|
+
const code2 = '痕跡を表示。3と5を痕跡演算して、表示。'
|
|
70
|
+
assert.throws(() => nako.run(code2, 'main.nako3'), NakoSyntaxError)
|
|
71
|
+
})
|
|
72
|
+
it('「初期化」と「!クリア」を呼ぶ', () => {
|
|
73
|
+
/** @type {any[]} */
|
|
74
|
+
const log = []
|
|
75
|
+
const nako = new NakoCompiler()
|
|
76
|
+
|
|
77
|
+
let count = 0
|
|
78
|
+
nako.addPluginObject('ClearTest', {
|
|
79
|
+
'初期化': {
|
|
80
|
+
type: 'func',
|
|
81
|
+
josi: [],
|
|
82
|
+
pure: true,
|
|
83
|
+
fn: (sys) => {
|
|
84
|
+
sys.x = count++
|
|
85
|
+
log.push(['初期化', sys.x])
|
|
86
|
+
}
|
|
87
|
+
},
|
|
88
|
+
'!クリア': {
|
|
89
|
+
type: 'func',
|
|
90
|
+
josi: [],
|
|
91
|
+
pure: true,
|
|
92
|
+
fn: (sys) => {
|
|
93
|
+
log.push(['!クリア', sys.x])
|
|
94
|
+
}
|
|
95
|
+
},
|
|
96
|
+
})
|
|
97
|
+
|
|
98
|
+
const process1 = nako.run('a=1', '')
|
|
99
|
+
const process2 = nako.run('a=1', '')
|
|
100
|
+
|
|
101
|
+
process1.destroy()
|
|
102
|
+
process2.destroy()
|
|
103
|
+
|
|
104
|
+
assert.deepStrictEqual(log, [['初期化', 0], ['初期化', 1], ['!クリア', 0], ['!クリア', 1]])
|
|
105
|
+
})
|
|
106
|
+
})
|
|
@@ -0,0 +1,360 @@
|
|
|
1
|
+
const assert = require('assert')
|
|
2
|
+
const NakoCompiler = require('../../src/nako3')
|
|
3
|
+
const { tokenize, LanguageFeatures, BackgroundTokenizer, AceDocument: IAceDocument, Session: ISession } = require('../../src/wnako3_editor')
|
|
4
|
+
const CNako3 = require('../../src/cnako3')
|
|
5
|
+
const path = require('path')
|
|
6
|
+
const fs = require('fs')
|
|
7
|
+
const { expect } = require('chai')
|
|
8
|
+
const { NakoLexerError } = require('../../src/nako_errors')
|
|
9
|
+
|
|
10
|
+
describe('wnako3_editor_test', () => {
|
|
11
|
+
class AceRange {
|
|
12
|
+
constructor(/** @type {number} */startLine, /** @type {number} */startColumn, /** @type {number} */endLine, /** @type {number} */endColumn) {
|
|
13
|
+
this.startLine = startLine
|
|
14
|
+
this.startColumn = startColumn
|
|
15
|
+
this.endLine = endLine
|
|
16
|
+
this.endColumn = endColumn
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
/** @implements {IAceDocument} */
|
|
20
|
+
class AceDocument {
|
|
21
|
+
constructor(/** @type {string} */text) {
|
|
22
|
+
this.lines = text.split('\n')
|
|
23
|
+
/** @type {any[]} */
|
|
24
|
+
this.log = []
|
|
25
|
+
}
|
|
26
|
+
getLine(/** @type {number} */row) { return this.lines[row] }
|
|
27
|
+
getLength() { return this.lines.length }
|
|
28
|
+
getAllLines() { return [...this.lines] }
|
|
29
|
+
insertInLine(/** @type {{ row: number, column: number }} */position, /** @type {string} */text) { this.log.push(['insertInLine', position, text]) }
|
|
30
|
+
removeInLine(/** @type {number} */row, /** @type {number} */columnStart, /** @type {number} */columnEnd) { this.log.push(['removeInLine', row, columnStart, columnEnd]) }
|
|
31
|
+
replace(/** @type {AceRange} */range, /** @type {string} */text) { this.log.push(['replace', range, text]) }
|
|
32
|
+
/** @returns {ISession} */
|
|
33
|
+
asSession() { // テスト用
|
|
34
|
+
// @ts-ignore
|
|
35
|
+
return { doc: this }
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
/** @returns {Promise<BackgroundTokenizer>} */
|
|
39
|
+
const createBackgroundTokenizer = (/** @type {string} */text, compiler = new NakoCompiler()) => {
|
|
40
|
+
return new Promise((resolve, reject) => {
|
|
41
|
+
const tokenizer = new BackgroundTokenizer(
|
|
42
|
+
new AceDocument(text),
|
|
43
|
+
compiler,
|
|
44
|
+
() => { resolve(tokenizer) }, // ok
|
|
45
|
+
(_, err) => { reject(err) }, // err
|
|
46
|
+
true,
|
|
47
|
+
)
|
|
48
|
+
})
|
|
49
|
+
}
|
|
50
|
+
describe('シンタックスハイライト', () => {
|
|
51
|
+
it('コードを分割する', () => {
|
|
52
|
+
const tokens = tokenize('A=1\nA+1を表示'.split('\n'), new NakoCompiler(), false).editorTokens
|
|
53
|
+
|
|
54
|
+
// 1行目
|
|
55
|
+
assert.strictEqual(tokens[0][0].value, 'A')
|
|
56
|
+
assert.strictEqual(tokens[0][1].value, '=')
|
|
57
|
+
assert.strictEqual(tokens[0][2].value, '1')
|
|
58
|
+
|
|
59
|
+
// 2行目
|
|
60
|
+
assert.strictEqual(tokens[1][0].value, 'A')
|
|
61
|
+
assert.strictEqual(tokens[1][1].value, '+')
|
|
62
|
+
assert.strictEqual(tokens[1][2].value, '1を')
|
|
63
|
+
assert.strictEqual(tokens[1][3].value, '表示')
|
|
64
|
+
})
|
|
65
|
+
it('scopeを割り当てる', () => {
|
|
66
|
+
const tokens = tokenize('A=1\nA+1を表示'.split('\n'), new NakoCompiler(), false).editorTokens
|
|
67
|
+
|
|
68
|
+
// 1行目
|
|
69
|
+
assert(tokens[0][0].type.includes('variable'))
|
|
70
|
+
assert(tokens[0][1].type.includes('operator'))
|
|
71
|
+
assert(tokens[0][2].type.includes('numeric'))
|
|
72
|
+
|
|
73
|
+
// 2行目
|
|
74
|
+
assert(tokens[1][0].type.includes('variable'))
|
|
75
|
+
assert(tokens[1][1].type.includes('operator'))
|
|
76
|
+
assert(tokens[1][2].type.includes('numeric'))
|
|
77
|
+
assert(tokens[1][3].type.includes('function'))
|
|
78
|
+
})
|
|
79
|
+
it('取り込み文を無視する', () => {
|
|
80
|
+
tokenize('!「http://www.example.com/non_existent_file.nako3」を取り込む。'.split('\n'), new NakoCompiler(), false)
|
|
81
|
+
})
|
|
82
|
+
it('助詞に下線を引く', () => {
|
|
83
|
+
const tokens = tokenize('「\n」を表示'.split('\n'), new NakoCompiler(), true).editorTokens
|
|
84
|
+
assert.strictEqual(tokens[1][0].value, '」')
|
|
85
|
+
assert(tokens[1][0].type.includes('string'))
|
|
86
|
+
|
|
87
|
+
assert.strictEqual(tokens[1][1].value, 'を')
|
|
88
|
+
assert(tokens[1][1].type.includes('underline'))
|
|
89
|
+
|
|
90
|
+
assert.strictEqual(tokens[1][2].value, '表示')
|
|
91
|
+
assert(tokens[1][2].type.includes('function'))
|
|
92
|
+
})
|
|
93
|
+
it('依存ファイルのキャッシュを利用する', () => {
|
|
94
|
+
const nako3 = new CNako3()
|
|
95
|
+
const code = '!「./requiretest_indirect.nako3」を取り込む\n1と2の痕跡演算'
|
|
96
|
+
const file = path.join(__dirname, 'main.nako3')
|
|
97
|
+
nako3.loadDependencies(code, file, '')
|
|
98
|
+
const tokens = tokenize(code.split('\n'), nako3, true)
|
|
99
|
+
|
|
100
|
+
// 「痕跡演算」が関数として認識されていることを確認する。
|
|
101
|
+
const token = tokens.editorTokens[1].find((token) => token.value === '痕跡演算')
|
|
102
|
+
expect(token).to.have.property('type').and.to.include('function')
|
|
103
|
+
})
|
|
104
|
+
it('シンタックスハイライトにかかる時間が依存ファイルの行数に依存しないことを確認', () => {
|
|
105
|
+
// 一時的に大きいファイルを作成
|
|
106
|
+
const largeFile = path.join(__dirname, 'large_file.nako3')
|
|
107
|
+
assert(!fs.existsSync(largeFile))
|
|
108
|
+
fs.writeFileSync(largeFile, '●(Aを)large_fileとは\nここまで\nA=1+2+3+4+5\n'.repeat(1000))
|
|
109
|
+
try {
|
|
110
|
+
// 大きいファイルを取り込むコードを実行
|
|
111
|
+
const code = '!「./large_file.nako3」を取り込む\n1をlarge_file'
|
|
112
|
+
const file = path.join(__dirname, 'main.nako3')
|
|
113
|
+
|
|
114
|
+
const nako3 = new CNako3()
|
|
115
|
+
console.time('loadDependencies')
|
|
116
|
+
nako3.loadDependencies(code, file, '') // この行は遅いが、取り込み文に変更が合った時しか呼ばれない
|
|
117
|
+
console.timeEnd('loadDependencies')
|
|
118
|
+
|
|
119
|
+
const startTime = process.hrtime.bigint()
|
|
120
|
+
console.time('tokenize')
|
|
121
|
+
const tokens = tokenize(code.split('\n'), nako3, true) // この行は速い必要がある
|
|
122
|
+
const delta = process.hrtime.bigint() - startTime
|
|
123
|
+
console.timeEnd('tokenize')
|
|
124
|
+
|
|
125
|
+
// 200ms以下で終わることを確認
|
|
126
|
+
// GitHub Actions で10〜40msくらいかかる。
|
|
127
|
+
assert(delta <= BigInt(200000000))
|
|
128
|
+
|
|
129
|
+
// 取り込みが行われたことを確認する
|
|
130
|
+
const token = tokens.editorTokens[1].find((token) => token.value === 'large_file')
|
|
131
|
+
expect(token).to.have.property('type').and.to.include('function')
|
|
132
|
+
} finally {
|
|
133
|
+
fs.unlinkSync(largeFile)
|
|
134
|
+
}
|
|
135
|
+
})
|
|
136
|
+
it('明示的に取り込んだプラグインの関数', async () => {
|
|
137
|
+
const compiler = new CNako3()
|
|
138
|
+
const code = `!「plugin_csv」を取り込む\n「1」のCSV取得`
|
|
139
|
+
compiler.loadDependencies(code, '', '')
|
|
140
|
+
const token = tokenize(code.split('\n'), compiler, false).editorTokens[1][1]
|
|
141
|
+
expect(token.type).to.include('function')
|
|
142
|
+
expect(token.docHTML).to.include('CSV取得')
|
|
143
|
+
expect(token.value).to.equal('CSV取得')
|
|
144
|
+
})
|
|
145
|
+
})
|
|
146
|
+
describe('ドキュメントのホバー', () => {
|
|
147
|
+
it('プラグイン関数の助詞のドキュメントを表示する', () => {
|
|
148
|
+
const nako3 = new NakoCompiler()
|
|
149
|
+
nako3.addPluginObject('PluginEditorTest', {
|
|
150
|
+
'プラグイン関数テスト': {
|
|
151
|
+
type: 'func',
|
|
152
|
+
josi: [['を', 'と'], ['に', 'は']],
|
|
153
|
+
fn: () => {}
|
|
154
|
+
}
|
|
155
|
+
})
|
|
156
|
+
|
|
157
|
+
const token = tokenize('XをYにプラグイン関数テスト'.split('\n'), nako3, false)
|
|
158
|
+
.editorTokens[0]
|
|
159
|
+
.find((t) => t.value === 'プラグイン関数テスト')
|
|
160
|
+
expect(token).to.have.property('docHTML').and.to.include('(Aを|Aと、Bに|Bは)')
|
|
161
|
+
expect(token).to.have.property('docHTML').and.to.include('PluginEditorTest')
|
|
162
|
+
})
|
|
163
|
+
it('ユーザー定義関数の助詞のドキュメントを表示する', () => {
|
|
164
|
+
const token = tokenize('●(Aを)Fとは\nここまで\n1をF'.split('\n'), new NakoCompiler(), false)
|
|
165
|
+
.editorTokens[2]
|
|
166
|
+
.find((t) => t.value === 'F')
|
|
167
|
+
expect(token).to.have.property('docHTML').and.to.include('(Aを)')
|
|
168
|
+
})
|
|
169
|
+
it('前回の実行結果の影響を受けない', () => {
|
|
170
|
+
const nako3 = new NakoCompiler()
|
|
171
|
+
tokenize('●(Aを)Fとは\nここまで\n1をF'.split('\n'), nako3, false)
|
|
172
|
+
const token = tokenize('1をF'.split('\n'), nako3, false)
|
|
173
|
+
.editorTokens[0]
|
|
174
|
+
.find((t) => t.value === 'F')
|
|
175
|
+
expect(token).to.have.property('docHTML').and.is.null
|
|
176
|
+
})
|
|
177
|
+
})
|
|
178
|
+
describe('行コメントのトグル', () => {
|
|
179
|
+
it('コメントアウト', () => {
|
|
180
|
+
const doc = new AceDocument('abc\n')
|
|
181
|
+
LanguageFeatures.toggleCommentLines('', doc.asSession(), 0, 1)
|
|
182
|
+
assert.deepStrictEqual(doc.log, [
|
|
183
|
+
[ 'insertInLine', { row: 0, column: 0 }, '// ' ],
|
|
184
|
+
[ 'insertInLine', { row: 1, column: 0 }, '// ' ],
|
|
185
|
+
])
|
|
186
|
+
})
|
|
187
|
+
it('アンコメント', () => {
|
|
188
|
+
const doc = new AceDocument('// abc\n\n※def')
|
|
189
|
+
LanguageFeatures.toggleCommentLines('', doc.asSession(), 0, 2)
|
|
190
|
+
assert.deepStrictEqual(doc.log, [
|
|
191
|
+
[ 'removeInLine', 0, 0, 3 ], // '// ' を削除
|
|
192
|
+
[ 'removeInLine', 2, 0, 1 ], // '※' を削除
|
|
193
|
+
])
|
|
194
|
+
})
|
|
195
|
+
it('中黒のある場合', () => {
|
|
196
|
+
const doc = new AceDocument('・・abc')
|
|
197
|
+
LanguageFeatures.toggleCommentLines('', doc.asSession(), 0, 0)
|
|
198
|
+
assert.deepStrictEqual(doc.log, [
|
|
199
|
+
[ 'insertInLine', { row: 0, column: 2 }, '// ' ], // 'abc' の直前に挿入
|
|
200
|
+
])
|
|
201
|
+
})
|
|
202
|
+
})
|
|
203
|
+
describe('auto outdent', () => {
|
|
204
|
+
it('「ここまで」を入力し終わった瞬間に発火する', () => {
|
|
205
|
+
assert(!LanguageFeatures.checkOutdent('start', ' ここ', 'ま'))
|
|
206
|
+
assert(LanguageFeatures.checkOutdent('start', ' ここま', 'で'))
|
|
207
|
+
assert(!LanguageFeatures.checkOutdent('start', ' ここまで', '\n'))
|
|
208
|
+
|
|
209
|
+
assert(!LanguageFeatures.checkOutdent('start', '・ここ', 'ま'))
|
|
210
|
+
assert(LanguageFeatures.checkOutdent('start', '・ここま', 'で'))
|
|
211
|
+
assert(!LanguageFeatures.checkOutdent('start', '・ここまで', '\n'))
|
|
212
|
+
})
|
|
213
|
+
it('1つ前の行がブロックの開始行なら、その行に合わせる', () => {
|
|
214
|
+
const doc = new AceDocument(' もしはいならば\n ここまで')
|
|
215
|
+
// 2行目にauto outdentを実行
|
|
216
|
+
new LanguageFeatures(AceRange, new NakoCompiler()).autoOutdent('start', doc.asSession(), 1)
|
|
217
|
+
// 2行目の0-8文字目が ' ' で置換される
|
|
218
|
+
assert.deepStrictEqual(doc.log, [[ 'replace', new AceRange(1, 0, 1, 8), ' ']])
|
|
219
|
+
})
|
|
220
|
+
it('1つ前の行がブロックの開始行でなければ、1段階インデントを下げる', () => {
|
|
221
|
+
const doc = new AceDocument('もしはいならば\n もしはいならば\n 1を表示\n ここまで')
|
|
222
|
+
// 4行目にauto outdentを実行
|
|
223
|
+
new LanguageFeatures(AceRange, new NakoCompiler()).autoOutdent('start', doc.asSession(), 3)
|
|
224
|
+
// 2行目の0-8文字目が ' ' で置換される
|
|
225
|
+
assert.deepStrictEqual(doc.log, [[ 'replace', new AceRange(3, 0, 3, 8), ' ']])
|
|
226
|
+
})
|
|
227
|
+
})
|
|
228
|
+
describe('auto indent', () => {
|
|
229
|
+
it('0列目の場合', () => {
|
|
230
|
+
// 1段階インデントする
|
|
231
|
+
assert.strictEqual(
|
|
232
|
+
LanguageFeatures.getNextLineIndent('start', 'もしはいならば', ' '),
|
|
233
|
+
' ',
|
|
234
|
+
)
|
|
235
|
+
})
|
|
236
|
+
it('4列目の場合', () => {
|
|
237
|
+
// 1段階インデントする
|
|
238
|
+
assert.strictEqual(
|
|
239
|
+
LanguageFeatures.getNextLineIndent('start', ' もしはいならば', ' '),
|
|
240
|
+
' ',
|
|
241
|
+
)
|
|
242
|
+
})
|
|
243
|
+
it('ブロックの開始行ではない場合', () => {
|
|
244
|
+
// 1つ前の行と同じインデント幅を返す
|
|
245
|
+
assert.strictEqual(
|
|
246
|
+
LanguageFeatures.getNextLineIndent('start', ' もしはい', ' '),
|
|
247
|
+
' ',
|
|
248
|
+
)
|
|
249
|
+
})
|
|
250
|
+
})
|
|
251
|
+
describe('バックグラウンドでコードをトークン化する', () => {
|
|
252
|
+
it('成功時', async () => {
|
|
253
|
+
const t = await createBackgroundTokenizer('1を表示')
|
|
254
|
+
// 0行目の0、1、2個目のトークン
|
|
255
|
+
expect(t.lines[0][0]).to.include({ type: 'constant.numeric', docHTML: null, value: '1' })
|
|
256
|
+
expect(t.lines[0][1]).to.include({ type: 'constant.numeric.markup.underline', value: 'を' })
|
|
257
|
+
expect(t.lines[0][2]).to.include({ type: 'entity.name.function', value: '表示' })
|
|
258
|
+
})
|
|
259
|
+
it('失敗時', async () => {
|
|
260
|
+
let ok = false
|
|
261
|
+
try {
|
|
262
|
+
await createBackgroundTokenizer('「{」')
|
|
263
|
+
} catch (err) {
|
|
264
|
+
expect(err).to.be.instanceOf(NakoLexerError)
|
|
265
|
+
ok = true
|
|
266
|
+
}
|
|
267
|
+
if (!ok) { throw new Error() }
|
|
268
|
+
})
|
|
269
|
+
})
|
|
270
|
+
describe('オートコンプリート', () => {
|
|
271
|
+
it('同一ファイル内の関数', async () => {
|
|
272
|
+
const compiler = new NakoCompiler()
|
|
273
|
+
const tokenizer = await createBackgroundTokenizer('●(Aを)テスト用関数とは\nここまで\n', compiler)
|
|
274
|
+
expect(LanguageFeatures.getCompletionItems(2, '', compiler, tokenizer)).to.deep.include({
|
|
275
|
+
caption: "(Aを)テスト用関数",
|
|
276
|
+
value: "テスト用関数",
|
|
277
|
+
meta: "関数",
|
|
278
|
+
score: 0,
|
|
279
|
+
})
|
|
280
|
+
})
|
|
281
|
+
it('同一ファイルの変数', async () => {
|
|
282
|
+
const compiler = new NakoCompiler()
|
|
283
|
+
const tokenizer = await createBackgroundTokenizer('テスト用変数=10\nここまで\n', compiler)
|
|
284
|
+
expect(LanguageFeatures.getCompletionItems(2, '', compiler, tokenizer)).to.deep.include({
|
|
285
|
+
caption: "テスト用変数",
|
|
286
|
+
value: "テスト用変数",
|
|
287
|
+
meta: "変数",
|
|
288
|
+
score: 0,
|
|
289
|
+
})
|
|
290
|
+
})
|
|
291
|
+
it('組み込みのプラグイン関数', async () => {
|
|
292
|
+
const compiler = new NakoCompiler()
|
|
293
|
+
compiler.addPluginObject('PluginEditorTest', { 'テスト用プラグイン関数': { type: 'func', josi: [['を'], ['に']], pure: true, fn: () => {} } })
|
|
294
|
+
const tokenizer = await createBackgroundTokenizer('', compiler)
|
|
295
|
+
expect(LanguageFeatures.getCompletionItems(0, '', compiler, tokenizer)).to.deep.include({
|
|
296
|
+
caption: "(Aを、Bに)テスト用プラグイン関数",
|
|
297
|
+
value: "テスト用プラグイン関数",
|
|
298
|
+
meta: "PluginEditorTest",
|
|
299
|
+
score: 0,
|
|
300
|
+
})
|
|
301
|
+
})
|
|
302
|
+
it('組み込みのプラグイン変数', async () => {
|
|
303
|
+
const compiler = new NakoCompiler()
|
|
304
|
+
compiler.addPluginObject('PluginEditorTest', { 'テスト用プラグイン変数': { type: 'var', value: 0 } })
|
|
305
|
+
const tokenizer = await createBackgroundTokenizer('', compiler)
|
|
306
|
+
expect(LanguageFeatures.getCompletionItems(0, '', compiler, tokenizer)).to.deep.include({
|
|
307
|
+
caption: "テスト用プラグイン変数",
|
|
308
|
+
value: "テスト用プラグイン変数",
|
|
309
|
+
meta: "PluginEditorTest",
|
|
310
|
+
score: 0,
|
|
311
|
+
})
|
|
312
|
+
})
|
|
313
|
+
it('別ファイルの関数', async () => {
|
|
314
|
+
const compiler = new CNako3()
|
|
315
|
+
const code = `!「${__dirname}/requiretest.nako3」を取り込む\n`
|
|
316
|
+
compiler.loadDependencies(code, '', '')
|
|
317
|
+
const tokenizer = await createBackgroundTokenizer(code, compiler)
|
|
318
|
+
const result = LanguageFeatures.getCompletionItems(0, '', compiler, tokenizer)
|
|
319
|
+
assert(result.some((v) => v.caption === '(Aと、Bを)痕跡演算'))
|
|
320
|
+
})
|
|
321
|
+
it('関数の呼び出しはmetaの値に影響を与えない', async () => {
|
|
322
|
+
const compiler = new NakoCompiler()
|
|
323
|
+
compiler.addPluginObject('PluginEditorTest', { 'テスト用プラグイン関数': { type: 'func', josi: [['を'], ['に']], pure: true, fn: () => {} } })
|
|
324
|
+
const tokenizer = await createBackgroundTokenizer('テスト用プラグイン関数\n', compiler)
|
|
325
|
+
const result = LanguageFeatures.getCompletionItems(1, '', compiler, tokenizer)
|
|
326
|
+
assert.deepStrictEqual(result.filter((v) => v.value === "テスト用プラグイン関数"), [
|
|
327
|
+
{
|
|
328
|
+
caption: '(Aを、Bに)テスト用プラグイン関数',
|
|
329
|
+
value: 'テスト用プラグイン関数',
|
|
330
|
+
meta: 'PluginEditorTest', // ここに `関数` が表示されないことを確認する
|
|
331
|
+
score: 0
|
|
332
|
+
}
|
|
333
|
+
])
|
|
334
|
+
})
|
|
335
|
+
it('同一名の関数の定義が複数あるとき、候補には1つしか表示しない', async () => {
|
|
336
|
+
const compiler = new NakoCompiler()
|
|
337
|
+
const tokenizer = await createBackgroundTokenizer('●(Aを)テスト用関数とは\nここまで\n●(Aを)テスト用関数とは\nここまで\n', compiler)
|
|
338
|
+
expect(LanguageFeatures.getCompletionItems(2, '', compiler, tokenizer)).to.deep.include({
|
|
339
|
+
caption: "(Aを)テスト用関数",
|
|
340
|
+
value: "テスト用関数",
|
|
341
|
+
meta: "関数", // `関数, 関数` にならないことを確認する
|
|
342
|
+
score: 0,
|
|
343
|
+
})
|
|
344
|
+
})
|
|
345
|
+
})
|
|
346
|
+
it('テスト定義に実行ボタンを表示する', () => {
|
|
347
|
+
const out = LanguageFeatures.getCodeLens(new AceDocument(
|
|
348
|
+
'●テスト:足すとは\n' +
|
|
349
|
+
'ここまで\n' +
|
|
350
|
+
'●(AとBを)足すとは\n' +
|
|
351
|
+
'ここまで\n' +
|
|
352
|
+
'●テスト:引くとは\n' +
|
|
353
|
+
'ここまで\n',
|
|
354
|
+
))
|
|
355
|
+
assert.deepStrictEqual(out, [
|
|
356
|
+
{ start: { row: 0 }, command: { title: 'テストを実行', id: 'runTest', arguments: ['足す'] } },
|
|
357
|
+
{ start: { row: 4 }, command: { title: 'テストを実行', id: 'runTest', arguments: ['引く'] } },
|
|
358
|
+
])
|
|
359
|
+
})
|
|
360
|
+
})
|
package/tools/README.md
ADDED
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
<!DOCTYPE html>
|
|
2
|
+
<html>
|
|
3
|
+
<head>
|
|
4
|
+
<meta charset="utf-8" />
|
|
5
|
+
<title>なでしこ3(Node版)エディタ</title>
|
|
6
|
+
<link href="/html/nako3edit.css" rel="stylesheet" type="text/css" />
|
|
7
|
+
<script defer type="text/javascript" src="/release/wnako3.js?run&v=1"></script>
|
|
8
|
+
<script defer type="text/javascript" src="/html/edit_plugin.js"></script>
|
|
9
|
+
<script type="なでしこ">
|
|
10
|
+
#-----------
|
|
11
|
+
APPKEY=""
|
|
12
|
+
HREF=WINDOW["location"]["href"]
|
|
13
|
+
P=HREFをURLパラメータ解析
|
|
14
|
+
APPKEY=P["appkey"]
|
|
15
|
+
Pを表示。
|
|
16
|
+
FNAME="無題.nako3"
|
|
17
|
+
もし、P["file"]ならば、FNAME=P["file"]
|
|
18
|
+
エディタ初期化。
|
|
19
|
+
|
|
20
|
+
●エディタ初期化
|
|
21
|
+
「エディタ初期化」を表示。
|
|
22
|
+
「#run_btn」の「onclick」に「P実行処理」をDOMイベント設定。
|
|
23
|
+
「#save_btn」の「onclick」に「P保存処理」をDOMイベント設定。
|
|
24
|
+
もし、FNAME=「new」ならば
|
|
25
|
+
FNAME="無題.nako3"
|
|
26
|
+
FILE2 = "new"
|
|
27
|
+
違えば
|
|
28
|
+
FILE2 = FNAMEをURLエンコード。
|
|
29
|
+
ここまで。
|
|
30
|
+
「#name」にFNAMEをDOMテキスト設定
|
|
31
|
+
「/load?file={FILE2}&appkey={APPKEY}」へGET送信した時には
|
|
32
|
+
「#body」に対象をDOMテキスト設定。
|
|
33
|
+
ここまで。
|
|
34
|
+
# 戻るリンクをAPPKEYを入れて初期化
|
|
35
|
+
「.backlink」のDOM要素全取得して反復
|
|
36
|
+
対象["href"] = "/html/files.html?appkey={APPKEY}"
|
|
37
|
+
ここまで。
|
|
38
|
+
ここまで。
|
|
39
|
+
|
|
40
|
+
●P実行処理
|
|
41
|
+
「実行」を表示。
|
|
42
|
+
S=「#body」のDOMテキスト取得
|
|
43
|
+
「/run」へ{
|
|
44
|
+
"file": 「#name」のDOMテキスト取得,
|
|
45
|
+
"body": 「#body」のDOMテキスト取得,
|
|
46
|
+
"appkey": APPKEY
|
|
47
|
+
}をPOST送信した時には
|
|
48
|
+
H=対象をHTML変換して改行を「<br />」に置換。
|
|
49
|
+
「#result」にHをDOMテキスト設定。
|
|
50
|
+
ここまで。
|
|
51
|
+
ここまで
|
|
52
|
+
|
|
53
|
+
●P保存処理
|
|
54
|
+
「保存」を表示。
|
|
55
|
+
S=「#body」のDOMテキスト取得
|
|
56
|
+
「/save」へ{
|
|
57
|
+
"file": 「#name」のDOMテキスト取得,
|
|
58
|
+
"body": 「#body」のDOMテキスト取得,
|
|
59
|
+
"appkey": APPKEY
|
|
60
|
+
}をPOST送信した時には
|
|
61
|
+
H=対象をHTML変換
|
|
62
|
+
「#result」にHをDOMテキスト設定。
|
|
63
|
+
ここまで。
|
|
64
|
+
ここまで
|
|
65
|
+
|
|
66
|
+
#-----------
|
|
67
|
+
</script>
|
|
68
|
+
</head>
|
|
69
|
+
<body>
|
|
70
|
+
<h1>なでしこ3(Node版)エディタ - <span class="titlemenu"><a class="backlink" href="#">[ファイル一覧]</a></span></h1>
|
|
71
|
+
<div class="editbox">
|
|
72
|
+
<div class="namebox">file: <input type="text" id="name" size="40" /></div>
|
|
73
|
+
<div><textarea id="body" rows="12" cols="60"></textarea></div>
|
|
74
|
+
<div class="cmd_btn">
|
|
75
|
+
<button id="run_btn">実行(cnako3)</button>
|
|
76
|
+
<button id="save_btn">保存</button>
|
|
77
|
+
</div>
|
|
78
|
+
<div id="result"></div>
|
|
79
|
+
</div>
|
|
80
|
+
<hr />
|
|
81
|
+
<div><a class="backlink" href="#">→ファイル一覧へ</a></div>
|
|
82
|
+
</body>
|
|
83
|
+
</html>
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
<!DOCTYPE html>
|
|
2
|
+
<html>
|
|
3
|
+
<head>
|
|
4
|
+
<meta charset="utf-8" />
|
|
5
|
+
<title>なでしこ3(Node版)エディタ - ファイル一覧</title>
|
|
6
|
+
<link href="/html/nako3edit.css" rel="stylesheet" type="text/css" />
|
|
7
|
+
<script defer type="text/javascript" src="/release/wnako3.js"></script>
|
|
8
|
+
<script defer type="text/javascript" src="/html/edit_plugin.js"></script>
|
|
9
|
+
<script type="なでしこ">
|
|
10
|
+
#-----------
|
|
11
|
+
APPKEY=""
|
|
12
|
+
HREF=WINDOW["location"]["href"]
|
|
13
|
+
HREFを表示。
|
|
14
|
+
P=HREFをURLパラメータ解析
|
|
15
|
+
Pを表示。
|
|
16
|
+
APPKEY=P["appkey"]
|
|
17
|
+
Pを表示。
|
|
18
|
+
ファイル一覧取得処理
|
|
19
|
+
|
|
20
|
+
●ファイル一覧取得処理
|
|
21
|
+
「/files?appkey={APPKEY}」へAJAX送信した時には
|
|
22
|
+
HTML=「<li><a href="/html/edit.html?file=new&appkey={APPKEY}"><span class="newfile">→新規作成</span></a></li>」
|
|
23
|
+
一覧=対象をJSONデコード
|
|
24
|
+
一覧を反復
|
|
25
|
+
F=それ
|
|
26
|
+
F2 = FをHTML変換
|
|
27
|
+
F3 = FをURLエンコード
|
|
28
|
+
HTML=HTML&「<li><a href="/html/edit.html?file={F3}&appkey={APPKEY}">{F2}</a></li>」
|
|
29
|
+
ここまで
|
|
30
|
+
「#files_ul」にHTMLをDOM_HTML設定。
|
|
31
|
+
ここまで。
|
|
32
|
+
# ---
|
|
33
|
+
AJAX失敗した時には(err)
|
|
34
|
+
errをHTML変換してERRに代入。
|
|
35
|
+
S=「<p style='color: red;'>サーバとの通信に失敗しました。<br />」&_
|
|
36
|
+
「サーバ設定かブラウザの設定を確認してください。</p><p>{ERR}</p>」
|
|
37
|
+
「#files_ul」にSをDOM_HTML設定。
|
|
38
|
+
ここまで
|
|
39
|
+
ここまで。
|
|
40
|
+
#-----------
|
|
41
|
+
</script>
|
|
42
|
+
</head>
|
|
43
|
+
<body>
|
|
44
|
+
<h1>なでしこ3(Node版) - ファイル一覧</h1>
|
|
45
|
+
<div id="filesbox">
|
|
46
|
+
<ul id="files_ul"><li>現在読み込み中です。少々お待ちください。</li></ul>
|
|
47
|
+
</div>
|
|
48
|
+
</body>
|
|
49
|
+
</html>
|