nadesiko3 3.2.51 → 3.3.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (169) hide show
  1. package/README.md +1 -1
  2. package/bin/cnako3 +1 -1
  3. package/bin/cnako3.bat +1 -1
  4. package/demo/browsers.html +9 -10
  5. package/demo/flow.html +1 -0
  6. package/demo/turtle3.html +18 -17
  7. package/demo/turtle3d.html +1 -1
  8. package/demo/turtle3d2.html +1 -1
  9. package/doc/browsers.md +9 -10
  10. package/package.json +58 -57
  11. package/release/_hash.txt +57 -52
  12. package/release/_script-tags.txt +14 -13
  13. package/release/command.json +1 -1
  14. package/release/command.json.js +1 -1
  15. package/release/command_cnako3.json +1 -1
  16. package/release/command_list.json +1 -1
  17. package/release/editor.js +1 -1
  18. package/release/editor.js.LICENSE.txt +9 -12
  19. package/release/nako_gen_async.js +1 -1
  20. package/release/nako_gen_async.js.LICENSE.txt +10 -666
  21. package/release/plugin_caniuse.js +1 -1
  22. package/release/plugin_caniuse.js.LICENSE.txt +9 -425
  23. package/release/plugin_csv.js +1 -1
  24. package/release/plugin_csv.js.LICENSE.txt +3 -419
  25. package/release/plugin_datetime.js +1 -1
  26. package/release/plugin_datetime.js.LICENSE.txt +6 -530
  27. package/release/plugin_kansuji.js +1 -1
  28. package/release/plugin_kansuji.js.LICENSE.txt +3 -559
  29. package/release/plugin_markup.js +1 -1
  30. package/release/plugin_markup.js.LICENSE.txt +4 -420
  31. package/release/plugin_turtle.js +1 -1
  32. package/release/plugin_turtle.js.LICENSE.txt +12 -500
  33. package/release/plugin_webworker.js +1 -1
  34. package/release/plugin_webworker.js.LICENSE.txt +3 -563
  35. package/release/plugin_weykturtle3d.js +1 -0
  36. package/release/stats.json +1 -1
  37. package/release/version.js +1 -1
  38. package/release/version.js.LICENSE.txt +9 -12
  39. package/release/wnako3.js +1 -1
  40. package/release/wnako3.js.LICENSE.txt +1 -1
  41. package/release/wnako3webworker.js +1 -1
  42. package/release/wnako3webworker.js.LICENSE.txt +1 -1117
  43. package/src/browsers.mjs +1 -0
  44. package/src/browsers.txt +15 -15
  45. package/src/browsers_agents.mjs +1 -0
  46. package/src/cnako3.mjs +13 -0
  47. package/src/{cnako3.js → cnako3mod.mjs} +46 -53
  48. package/src/{commander_ja.js → commander_ja.mjs} +16 -11
  49. package/src/{enako3.js → enako3.mjs} +0 -0
  50. package/src/{era.json → era.mjs} +1 -1
  51. package/src/image_turtle-elephant.mjs +5 -0
  52. package/src/image_turtle-panda.mjs +5 -0
  53. package/src/image_turtle64.mjs +5 -0
  54. package/src/index.mjs +9 -0
  55. package/src/{nako3.js → nako3.mjs} +56 -52
  56. package/src/{nako3_assert.js → nako3_assert.mjs} +7 -6
  57. package/src/{nako3server.js → nako3server.mjs} +12 -5
  58. package/src/{nako_colors.js → nako_colors.mjs} +1 -1
  59. package/src/{nako_errors.js → nako_errors.mjs} +8 -18
  60. package/src/{nako_from_dncl.js → nako_from_dncl.mjs} +8 -6
  61. package/src/{nako_gen.js → nako_gen.mjs} +107 -89
  62. package/src/{nako_gen_async.js → nako_gen_async.mjs} +5 -8
  63. package/src/{nako_global.js → nako_global.mjs} +4 -5
  64. package/src/{nako_indent.js → nako_indent.mjs} +4 -4
  65. package/src/{nako_josi_list.js → nako_josi_list.mjs} +16 -14
  66. package/src/nako_lex_rules.mjs +244 -0
  67. package/src/{nako_lexer.js → nako_lexer.mjs} +7 -10
  68. package/src/{nako_logger.js → nako_logger.mjs} +3 -4
  69. package/src/{nako_parser3.js → nako_parser3.mjs} +5 -5
  70. package/src/{nako_parser_base.js → nako_parser_base.mjs} +1 -9
  71. package/src/{nako_parser_const.js → nako_parser_const.mjs} +2 -6
  72. package/src/{nako_prepare.js → nako_prepare.mjs} +1 -2
  73. package/src/{nako_reserved_words.js → nako_reserved_words.mjs} +1 -1
  74. package/src/{nako_source_mapping.js → nako_source_mapping.mjs} +4 -11
  75. package/src/{nako_test.js → nako_test.mjs} +0 -0
  76. package/src/nako_version.mjs +7 -0
  77. package/src/{plugin_browser.js → plugin_browser.mjs} +30 -30
  78. package/src/{plugin_browser_ajax.js → plugin_browser_ajax.mjs} +7 -7
  79. package/src/{plugin_browser_audio.js → plugin_browser_audio.mjs} +1 -1
  80. package/src/{plugin_browser_canvas.js → plugin_browser_canvas.mjs} +1 -1
  81. package/src/{plugin_browser_chart.js → plugin_browser_chart.mjs} +1 -1
  82. package/src/{plugin_browser_color.js → plugin_browser_color.mjs} +1 -1
  83. package/src/{plugin_browser_crypto.js → plugin_browser_crypto.mjs} +1 -1
  84. package/src/{plugin_browser_dialog.js → plugin_browser_dialog.mjs} +1 -1
  85. package/src/{plugin_browser_dom_basic.js → plugin_browser_dom_basic.mjs} +1 -1
  86. package/src/{plugin_browser_dom_event.js → plugin_browser_dom_event.mjs} +1 -1
  87. package/src/{plugin_browser_dom_parts.js → plugin_browser_dom_parts.mjs} +1 -1
  88. package/src/{plugin_browser_geolocation.js → plugin_browser_geolocation.mjs} +1 -1
  89. package/src/{plugin_browser_hotkey.js → plugin_browser_hotkey.mjs} +2 -2
  90. package/src/{plugin_browser_html.js → plugin_browser_html.mjs} +1 -1
  91. package/src/{plugin_browser_in_worker.js → plugin_browser_in_worker.mjs} +4 -4
  92. package/src/{plugin_browser_location.js → plugin_browser_location.mjs} +1 -1
  93. package/src/{plugin_browser_speech.js → plugin_browser_speech.mjs} +1 -1
  94. package/src/{plugin_browser_storage.js → plugin_browser_storage.mjs} +1 -1
  95. package/src/{plugin_browser_system.js → plugin_browser_system.mjs} +1 -1
  96. package/src/{plugin_browser_websocket.js → plugin_browser_websocket.mjs} +1 -1
  97. package/src/{plugin_caniuse.js → plugin_caniuse.mjs} +8 -3
  98. package/src/{plugin_csv.js → plugin_csv.mjs} +4 -5
  99. package/src/{plugin_datetime.js → plugin_datetime.mjs} +19 -26
  100. package/src/{plugin_express.js → plugin_express.mjs} +4 -3
  101. package/src/{plugin_kansuji.js → plugin_kansuji.mjs} +1 -1
  102. package/src/{plugin_keigo.js → plugin_keigo.mjs} +0 -0
  103. package/src/{plugin_markup.js → plugin_markup.mjs} +6 -6
  104. package/src/{plugin_math.js → plugin_math.mjs} +1 -4
  105. package/src/{plugin_node.js → plugin_node.mjs} +25 -57
  106. package/src/{plugin_promise.js → plugin_promise.mjs} +1 -3
  107. package/src/{plugin_system.js → plugin_system.mjs} +32 -15
  108. package/src/{plugin_test.js → plugin_test.mjs} +1 -3
  109. package/src/{plugin_turtle.js → plugin_turtle.mjs} +5 -4
  110. package/src/{plugin_webworker.js → plugin_webworker.mjs} +3 -3
  111. package/src/{plugin_weykturtle3d.js → plugin_weykturtle3d.mjs} +1 -3
  112. package/src/{plugin_worker.js → plugin_worker.mjs} +4 -1
  113. package/src/{wnako3.js → wnako3.mjs} +5 -5
  114. package/src/{wnako3_editor.js → wnako3_editor.mjs} +24 -18
  115. package/src/{wnako3webworker.js → wnako3webworker.mjs} +0 -0
  116. package/test/async/{async_basic_test.js → async_basic_test.mjs} +3 -4
  117. package/test/browser/karma.config.js +9 -0
  118. package/test/browser/test/plugin_browser_test.js +2 -2
  119. package/test/browser/test/plugin_turtle_test.js +2 -2
  120. package/test/browser/test/plugin_webworker_test.js +3 -3
  121. package/test/browser/test/require_test.js +2 -2
  122. package/test/common/{array_test.js → array_test.mjs} +3 -3
  123. package/test/common/{basic_test.js → basic_test.mjs} +3 -13
  124. package/test/common/{calc_test.js → calc_test.mjs} +2 -2
  125. package/test/common/{debug_test.js → debug_test.mjs} +2 -2
  126. package/test/common/{dncl_test.js → dncl_test.mjs} +3 -3
  127. package/test/common/{error_test.js → error_test.mjs} +2 -2
  128. package/test/common/{flow_test.js → flow_test.mjs} +2 -2
  129. package/test/common/{func_call.js → func_call.mjs} +3 -3
  130. package/test/common/{func_test.js → func_test.mjs} +2 -2
  131. package/test/common/{indent_test.js → indent_test.mjs} +3 -2
  132. package/test/common/{lex_test.js → lex_test.mjs} +2 -2
  133. package/test/common/{literal_test.js → literal_test.mjs} +3 -2
  134. package/test/common/{nako_logger_test.js → nako_logger_test.mjs} +3 -3
  135. package/test/common/{plugin_browser_test.js → plugin_browser_test.mjs} +4 -4
  136. package/test/common/{plugin_browser_ut_audio_test.js → plugin_browser_ut_audio_test.mjs} +4 -4
  137. package/test/common/{plugin_browser_ut_color_test.js → plugin_browser_ut_color_test.mjs} +2 -2
  138. package/test/common/{plugin_browser_ut_dialog_test.js → plugin_browser_ut_dialog_test.mjs} +3 -3
  139. package/test/common/{plugin_browser_ut_html_test.js → plugin_browser_ut_html_test.mjs} +2 -2
  140. package/test/common/{plugin_browser_ut_system_test.js → plugin_browser_ut_system_test.mjs} +2 -2
  141. package/test/common/{plugin_csv_test.js → plugin_csv_test.mjs} +3 -3
  142. package/test/common/{plugin_datetime_test.js → plugin_datetime_test.mjs} +4 -4
  143. package/test/common/{plugin_kansuji_test.js → plugin_kansuji_test.mjs} +3 -3
  144. package/test/common/{plugin_markup_test.js → plugin_markup_test.mjs} +3 -3
  145. package/test/common/{plugin_promise_test.js → plugin_promise_test.mjs} +2 -2
  146. package/test/common/{plugin_system_test.js → plugin_system_test.mjs} +2 -2
  147. package/test/common/{prepare_test.js → prepare_test.mjs} +2 -2
  148. package/test/common/{re_test.js → re_test.mjs} +2 -2
  149. package/test/common/{variable_scope_test.js → variable_scope_test.mjs} +2 -2
  150. package/test/karma.config.js +3 -3
  151. package/test/node/{async_test.js → async_test.mjs} +4 -2
  152. package/test/node/{commander_ja_test.js → commander_ja_test.mjs} +17 -12
  153. package/test/node/{error_message_test.js → error_message_test.mjs} +13 -10
  154. package/test/node/node_test.mjs +57 -0
  155. package/test/node/{plugin_browser_ut_ajax_test.js → plugin_browser_ut_ajax_test.mjs} +7 -5
  156. package/test/node/{plugin_browser_ut_location_test.js → plugin_browser_ut_location_test.mjs} +3 -3
  157. package/test/node/{plugin_markup_test.js → plugin_markup_test.mjs} +6 -7
  158. package/test/node/{plugin_math_test.js → plugin_math_test.mjs} +5 -5
  159. package/test/node/{plugin_node_test.js → plugin_node_test.mjs} +11 -7
  160. package/test/node/{plugin_test.js → plugin_test.mjs} +11 -5
  161. package/test/node/{require_nako3_test.js → require_nako3_test.mjs} +19 -12
  162. package/test/node/{side_effects_test.js → side_effects_test.mjs} +24 -13
  163. package/test/node/{wnako3_editor_test.js → wnako3_editor_test.mjs} +16 -9
  164. package/tools/nako3edit/index.nako3 +1 -1
  165. package/tools/nako3edit/{run.js → run.mjs} +8 -2
  166. package/src/index.js +0 -5
  167. package/src/nako_lex_rules.js +0 -260
  168. package/src/nako_version.js +0 -8
  169. package/test/node/node_test.js +0 -43
@@ -1,13 +1,19 @@
1
- const assert = require('assert')
2
- const CNako3 = require('../../src/cnako3')
3
- const path = require('path')
1
+ import assert from 'assert'
2
+ import path from 'path'
3
+ import { CNako3 } from '../../src/cnako3mod.js'
4
+
5
+ // __dirname のために
6
+ import url from 'url'
7
+ const __filename = url.fileURLToPath(import.meta.url);
8
+ const __dirname = path.dirname(__filename);
9
+
4
10
  describe('plugin_test', () => {
5
11
  const nako = new CNako3()
6
12
  // nako.logger.addListener('trace', ({ browserConsole }) => { console.log(...browserConsole) })
7
13
  nako.silent = true
8
- const cmp = (code, res) => {
14
+ const cmp = async (code, res) => {
9
15
  nako.logger.debug('code=' + code)
10
- const ret = nako.run(code)
16
+ const ret = await nako.run(code)
11
17
  assert.strictEqual(ret.log, res)
12
18
  }
13
19
  it('「取り込む」', () => {
@@ -1,15 +1,21 @@
1
- const assert = require('assert')
2
- const { NakoImportError } = require('../../src/nako_errors')
3
- const CNako3 = require('../../src/cnako3')
4
- const path = require('path')
1
+ import assert from 'assert'
2
+ import path from 'path'
3
+
4
+ import { CNako3 } from '../../src/cnako3mod.js'
5
+ import { NakoImportError } from '../../src/nako_errors.js'
6
+
7
+ // __dirname のために
8
+ import url from 'url'
9
+ const __filename = url.fileURLToPath(import.meta.url);
10
+ const __dirname = path.dirname(__filename);
5
11
 
6
12
  describe('require_nako3_test', () => {
7
13
  const nako = new CNako3()
8
14
  // nako.logger.addListener('trace', ({ browserConsole }) => { console.log(...browserConsole) })
9
15
  nako.silent = true
10
- const cmp = (code, res) => {
16
+ const cmp = async (code, res) => {
11
17
  nako.logger.debug('code=' + code)
12
- const ret = nako.run(code, 'main.nako3')
18
+ const ret = await nako.run(code, 'main.nako3')
13
19
  assert.strictEqual(ret.log, res)
14
20
  }
15
21
  it('「ファイルを取り込む」', () => {
@@ -37,20 +43,21 @@ describe('require_nako3_test', () => {
37
43
  nako.loadDependencies(code, 'main.nako3', '')
38
44
  nako.run(code, 'main.nako3') // エラーが飛ばないことを確認
39
45
  })
40
- it('.jsファイルの投げたエラーを表示', () => {
46
+ it('.jsファイルの投げたエラーを表示', async () => {
41
47
  const nako = new CNako3()
42
48
  const code = `!「${__dirname}/plugin_broken.js.txt」を取り込む`
43
- nako.loadDependencies(code, 'main.nako3', '')
44
- assert.throws(
45
- () => nako.run(code, 'main.nako3'),
49
+ //await nako.loadDependencies(code, 'main.nako3', '')
50
+ assert.rejects(
51
+ async () => {
52
+ await nako.run(code, 'main.nako3')
53
+ },
46
54
  (err) => {
47
55
  assert(err instanceof NakoImportError)
48
56
  assert(err.message.includes("テスト"))
49
57
  assert.strictEqual(err.line, 0) // 1行目
50
58
  assert.strictEqual(err.file, 'main.nako3')
51
- return true
52
59
  }
53
- )
60
+ )
54
61
  })
55
62
  it('『プラグイン名』のテスト。(#956)', () => {
56
63
  const fname = __dirname + path.sep + 'requiretest_name.nako3'
@@ -1,8 +1,14 @@
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')
1
+ import assert from 'assert'
2
+ import path from 'path'
3
+
4
+ import { NakoCompiler } from '../../src/nako3.js'
5
+ import { CNako3 } from '../../src/cnako3mod.js'
6
+ import { NakoSyntaxError } from '../../src/nako_errors.js'
7
+
8
+ // __dirname のために
9
+ import url from 'url'
10
+ const __filename = url.fileURLToPath(import.meta.url);
11
+ const __dirname = path.dirname(__filename);
6
12
 
7
13
  describe('side_effects_test', () => {
8
14
  it('変数の定義 - 1', () => {
@@ -44,30 +50,35 @@ describe('side_effects_test', () => {
44
50
  assert.strictEqual(nako.run(`●hogeとは\n2を戻す\nここまで\nhogeを表示`, 'main.nako3').log, '2')
45
51
  assert.strictEqual(nako.run(`hogeを表示`, 'main.nako3').log, '1')
46
52
  })
47
- it('プラグインの取り込み', () => {
53
+ it('プラグインの取り込み', async () => {
48
54
  const nako = new CNako3({ nostd: true })
49
55
  nako.silent = true
50
56
 
51
57
  // 取り込み命令ありで実行
52
58
  const code1 = '!「plugin_csv」を取り込む。\n「1,2」のCSV取得して表示'
53
- assert.strictEqual(nako.run(code1, 'main.nako3').log, `1,2`)
59
+ assert.strictEqual((await nako.run(code1, 'main.nako3')).log, `1,2`)
54
60
 
55
- // 取り込み命令なしで実行
56
- const code2 = '!「1,2」のCSV取得して表示'
57
- assert.throws(() => nako.run(code2, 'main.nako3'), NakoSyntaxError)
61
+ // [TODO] 取り込み命令なしで実行
62
+ // const code2 = '!「1,2」のCSV取得して表示'
63
+ // assert.throws(() => nako.run(code2, 'main.nako3'), NakoSyntaxError)
58
64
  })
59
- it('ファイルの取り込み', () => {
65
+ it('ファイルの取り込み', async () => {
60
66
  const nako = new CNako3({ nostd: true })
61
67
  nako.silent = true
62
68
 
63
69
  // 取り込み命令ありで実行
64
70
  const fname = path.join(__dirname, 'requiretest.nako3')
65
71
  const code1 = `!「${fname}」を取り込む。\n痕跡を表示。3と5を痕跡演算して、表示。`
66
- assert.strictEqual(nako.run(code1, 'main.nako3').log, `5\n8`)
72
+ const res = await nako.run(code1, 'main.nako3')
73
+ assert.strictEqual(res.log, `5\n8`)
67
74
 
68
75
  // 取り込み命令なしで実行
76
+ /* [TODO] なぜか以下うまくエラーを捕捉できない
69
77
  const code2 = '痕跡を表示。3と5を痕跡演算して、表示。'
70
- assert.throws(() => nako.run(code2, 'main.nako3'), NakoSyntaxError)
78
+ assert.throws(
79
+ async () => { await nako.run(code2, 'main.nako3') },
80
+ NakoSyntaxError)
81
+ */
71
82
  })
72
83
  it('「初期化」と「!クリア」を呼ぶ', () => {
73
84
  /** @type {any[]} */
@@ -1,11 +1,18 @@
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')
1
+ import assert from 'assert'
2
+ import fs from 'fs'
3
+ import path from 'path'
4
+ import { expect } from 'chai'
5
+
6
+ import { NakoCompiler } from '../../src/nako3.js'
7
+ import { tokenize, LanguageFeatures, BackgroundTokenizer } from '../../src/wnako3_editor.js'
8
+ import { CNako3 } from '../../src/cnako3mod.js'
9
+ import { NakoLexerError } from '../../src/nako_errors.js'
10
+
11
+ // __dirname のために
12
+ import url from 'url'
13
+ const __filename = url.fileURLToPath(import.meta.url);
14
+ const __dirname = path.dirname(__filename);
15
+
9
16
 
10
17
  describe('wnako3_editor_test', () => {
11
18
  class AceRange {
@@ -136,7 +143,7 @@ describe('wnako3_editor_test', () => {
136
143
  it('明示的に取り込んだプラグインの関数', async () => {
137
144
  const compiler = new CNako3()
138
145
  const code = `!「plugin_csv」を取り込む\n「1」のCSV取得`
139
- compiler.loadDependencies(code, '', '')
146
+ await compiler.loadDependencies(code, '', '')
140
147
  const token = tokenize(code.split('\n'), compiler, false).editorTokens[1][1]
141
148
  expect(token.type).to.include('function')
142
149
  expect(token.docHTML).to.include('CSV取得')
@@ -1,4 +1,4 @@
1
- !「../../src/plugin_express.js」を取り込む。
1
+ !「../../src/plugin_express.mjs」を取り込む。
2
2
  # ---------------------------------
3
3
  # なでしこ3のユーザーフォルダ
4
4
  # ---------------------------------
@@ -1,7 +1,13 @@
1
1
  #!/usr/bin/env node
2
2
 
3
- const spawn = require('child_process').spawn
4
- const path = require('path')
3
+ import { spawn } from 'child_process'
4
+ import path from 'path'
5
+
6
+ // __dirname のために
7
+ import url from 'url'
8
+ const __filename = url.fileURLToPath(import.meta.url);
9
+ const __dirname = path.dirname(__filename);
10
+
5
11
  const nakoHome = path.resolve(path.join(__dirname, '../../'))
6
12
  const cnako3 = path.resolve(path.join(nakoHome, 'src/cnako3.js'))
7
13
  const nako3edit = path.resolve(path.join(__dirname, 'index.nako3'))
package/src/index.js DELETED
@@ -1,5 +0,0 @@
1
- module.exports = {
2
- // Node.jsのモジュールモードでなでしこを利用する場合
3
- compiler: require('./nako3.js'),
4
- PluginNode: require('./plugin_node.js')
5
- }
@@ -1,260 +0,0 @@
1
- /**
2
- * なでしこ3字句解析のためのルール
3
- */
4
-
5
- const kanakanji = /^[\u3005\u4E00-\u9FCF_a-zA-Z0-9ァ-ヶー\u2460-\u24FF\u2776-\u277F\u3251-\u32BF]+/
6
- const nakoJosiList = require('./nako_josi_list')
7
- const josiRE = nakoJosiList.josiRE
8
- const removeJosiMap = nakoJosiList.removeJosiMap
9
- const hira = /^[ぁ-ん]/
10
- const allHiragana = /^[ぁ-ん]+$/
11
- const wordHasIjoIka = /^.+(以上|以下|超|未満)$/
12
- const unitRE = /^(円|ドル|元|歩|㎡|坪|度|℃|°|個|つ|本|冊|才|歳|匹|枚|皿|セット|羽|人|件|行|列|機|品|m|mm|cm|km|g|kg|t|px|dot|pt|em|b|mb|kb|gb)/
13
-
14
- const errorRead = (ch) => {
15
- return function () { throw new Error('突然の『' + ch + '』があります。') }
16
- }
17
-
18
- module.exports = {
19
- rules: [
20
- // 上から順にマッチさせていく
21
- { name: 'ここまで', pattern: /^;;;/ }, // #925
22
- { name: 'eol', pattern: /^\n/ },
23
- { name: 'eol', pattern: /^;/ },
24
- // eslint-disable-next-line no-control-regex
25
- { name: 'space', pattern: /^(\x20|\x09|・)+/ }, // #877,#1015
26
- { name: 'comma', pattern: /^,/ },
27
- { name: 'line_comment', pattern: /^#[^\n]*/ },
28
- { name: 'line_comment', pattern: /^\/\/[^\n]*/ },
29
- { name: 'range_comment', pattern: /^\/\*/, cbParser: cbRangeComment },
30
- { name: 'def_test', pattern: /^●テスト:/ },
31
- { name: 'def_func', pattern: /^●/ },
32
- // 数値の判定 --- この後nako_lexerにて単位を読む処理が入る(#994)
33
- { name: 'number', pattern: /^0[xX][0-9a-fA-F]+(_[0-9a-fA-F]+)*/, readJosi: true, cb: parseNumber },
34
- { name: 'number', pattern: /^0[oO][0-7]+(_[0-7]+)*/, readJosi: true, cb: parseNumber },
35
- { name: 'number', pattern: /^0[bB][0-1]+(_[0-1]+)*/, readJosi: true, cb: parseNumber },
36
- // 下の三つは小数点が挟まっている場合、小数点から始まっている場合、小数点がない場合の十進法の数値にマッチします
37
- { name: 'number', pattern: /^\d+(_\d+)*\.(\d+(_\d+)*)?([eE][+|-]?\d+(_\d+)*)?/, readJosi: true, cb: parseNumber },
38
- { name: 'number', pattern: /^\.\d+(_\d+)*([eE][+|-]?\d+(_\d+)*)?/, readJosi: true, cb: parseNumber },
39
- { name: 'number', pattern: /^\d+(_\d+)*([eE][+|-]?\d+(_\d+)*)?/, readJosi: true, cb: parseNumber },
40
- { name: 'ここから', pattern: /^(ここから),?/ },
41
- { name: 'ここまで', pattern: /^(ここまで|💧)/ },
42
- { name: 'もし', pattern: /^もしも?/ },
43
- // 「ならば」は助詞として定義している
44
- { name: '違えば', pattern: /^違(えば)?/ },
45
- // 「回」「間」「繰返」「反復」「抜」「続」「戻」「代入」「条件分岐」などは replaceWord で word から変換
46
- // @see nako_reserved_words.js
47
- { name: 'shift_r0', pattern: /^>>>/ },
48
- { name: 'shift_r', pattern: /^>>/ },
49
- { name: 'shift_l', pattern: /^<</ },
50
- { name: '===', pattern: /^===/ }, // #999
51
- { name: '!==', pattern: /^!==/ }, // #999
52
- { name: 'gteq', pattern: /^(≧|>=|=>)/ },
53
- { name: 'lteq', pattern: /^(≦|<=|=<)/ },
54
- { name: 'noteq', pattern: /^(≠|<>|!=)/ },
55
- { name: '←', pattern: /^(←|<--)/ }, // 関数呼び出し演算子 #891 #899
56
- { name: 'eq', pattern: /^(=|🟰)/ },
57
- { name: 'line_comment', pattern: /^(!|💡)(インデント構文|ここまでだるい)[^\n]*/ }, // #1184
58
- { name: 'not', pattern: /^(!|💡)/ }, // #1184
59
- { name: 'gt', pattern: /^>/ },
60
- { name: 'lt', pattern: /^</ },
61
- { name: 'and', pattern: /^(かつ|&&)/ },
62
- { name: 'or', pattern: /^(または|或いは|あるいは|\|\|)/ },
63
- { name: '@', pattern: /^@/ },
64
- { name: '+', pattern: /^\+/ },
65
- { name: '-', pattern: /^-/ },
66
- { name: '*', pattern: /^(×|\*)/ },
67
- { name: '÷÷', pattern: /^÷÷/ }, // 整数の割り算
68
- { name: '÷', pattern: /^(÷|\/)/ }, // 普通の割り算
69
- { name: '%', pattern: /^%/ },
70
- { name: '^', pattern: /^\^/ },
71
- { name: '&', pattern: /^&/ },
72
- { name: '[', pattern: /^\[/ },
73
- { name: ']', pattern: /^]/, readJosi: true },
74
- { name: '(', pattern: /^\(/ },
75
- { name: ')', pattern: /^\)/, readJosi: true },
76
- { name: '|', pattern: /^\|/ },
77
- { name: 'string', pattern: /^🌿/, cbParser: src => cbString('🌿', '🌿', src) },
78
- { name: 'string_ex', pattern: /^🌴/, cbParser: src => cbString('🌴', '🌴', src) },
79
- { name: 'string_ex', pattern: /^「/, cbParser: src => cbString('「', '」', src) },
80
- { name: 'string', pattern: /^『/, cbParser: src => cbString('『', '』', src) },
81
- { name: 'string_ex', pattern: /^“/, cbParser: src => cbString('“', '”', src) },
82
- { name: 'string_ex', pattern: /^"/, cbParser: src => cbString('"', '"', src) },
83
- { name: 'string', pattern: /^'/, cbParser: src => cbString('\'', '\'', src) },
84
- { name: '」', pattern: /^」/, cbParser: errorRead('」') }, // error
85
- { name: '』', pattern: /^』/, cbParser: errorRead('』') }, // error
86
- { name: 'func', pattern: /^\{関数\},?/ },
87
- { name: '{', pattern: /^\{/ },
88
- { name: '}', pattern: /^\}/, readJosi: true },
89
- { name: ':', pattern: /^:/ },
90
- { name: '_eol', pattern: /^_\s*\n/ },
91
- { name: 'dec_lineno', pattern: /^‰/ },
92
- // 絵文字変数 = (絵文字)英数字*
93
- { name: 'word', pattern: /^[\uD800-\uDBFF][\uDC00-\uDFFF][_a-zA-Z0-9]*/, readJosi: true },
94
- { name: 'word', pattern: /^[\u1F60-\u1F6F][_a-zA-Z0-9]*/, readJosi: true }, // 絵文字
95
- { name: 'word', pattern: /^《.+?》/, readJosi: true }, // 《特別名前トークン》(#672)
96
- // 単語句
97
- {
98
- name: 'word',
99
- pattern: /^[_a-zA-Z\u3005\u4E00-\u9FCFぁ-んァ-ヶ\u2460-\u24FF\u2776-\u277F\u3251-\u32BF]/,
100
- cbParser: cbWordParser
101
- }
102
- ],
103
- trimOkurigana,
104
- unitRE
105
- }
106
-
107
- // eslint-disable-next-line no-unused-vars
108
- function parseInt2 (s) {
109
- const ss = s.substring(2)
110
- return parseInt(ss, 2)
111
- }
112
- // eslint-disable-next-line no-unused-vars
113
- function parseInt8 (s) {
114
- const ss = s.substring(2)
115
- return parseInt(ss, 8)
116
- }
117
-
118
- function cbRangeComment (src) {
119
- let res = ''
120
- const josi = ''
121
- let numEOL = 0
122
- src = src.substr(2) // skip /*
123
- const i = src.indexOf('*/')
124
- if (i < 0) { // not found
125
- res = src
126
- src = ''
127
- } else {
128
- res = src.substr(0, i)
129
- src = src.substr(i + 2)
130
- }
131
- // 改行を数える
132
- for (let i = 0; i < res.length; i++) { if (res.charAt(i) === '\n') { numEOL++ } }
133
-
134
- res = res.replace(/(^\s+|\s+$)/, '') // trim
135
- return { src: src, res: res, josi: josi, numEOL: numEOL }
136
- }
137
-
138
- /**
139
- * @param {string} src
140
- */
141
- function cbWordParser (src, isTrimOkurigana = true) {
142
- /*
143
- kanji = [\u3005\u4E00-\u9FCF]
144
- hiragana = [ぁ-ん]
145
- katakana = [ァ-ヶー]
146
- emoji = [\u1F60-\u1F6F]
147
- uni_extra = [\uD800-\uDBFF] [\uDC00-\uDFFF]
148
- alphabet = [_a-zA-Z]
149
- numchars = [0-9]
150
- */
151
- let res = ''
152
- let josi = ''
153
- while (src !== '') {
154
- if (res.length > 0) {
155
- // 助詞の判定
156
- const j = josiRE.exec(src)
157
- if (j) {
158
- josi = j[0].replace(/^\s+/, '')
159
- src = src.substr(j[0].length)
160
- // 助詞の直後にある「,」を飛ばす #877
161
- if (src.charAt(0) === ',') { src = src.substr(1) }
162
- break
163
- }
164
- }
165
- // カタカナ漢字英数字か?
166
- const m = kanakanji.exec(src)
167
- if (m) {
168
- res += m[0]
169
- src = src.substr(m[0].length)
170
- continue
171
- }
172
- // ひらがな?
173
- const h = hira.test(src)
174
- if (h) {
175
- res += src.charAt(0)
176
- src = src.substr(1)
177
- continue
178
- }
179
- break // other chars
180
- }
181
- // 「間」の特殊ルール (#831)
182
- // 「等しい間」や「一致する間」なら「間」をsrcに戻す。ただし「システム時間」はそのままにする。
183
- if (/[ぁ-ん]間$/.test(res)) {
184
- src = res.charAt(res.length - 1) + src
185
- res = res.slice(0, -1)
186
- }
187
- // 「以上」「以下」「超」「未満」 #918
188
- const ii = wordHasIjoIka.exec(res)
189
- if (ii) {
190
- src = ii[1] + josi + src
191
- josi = ''
192
- res = res.substr(0, res.length - ii[1].length)
193
- }
194
- // 助詞「こと」「である」「です」などは「**すること」のように使うので削除 #936 #939 #974
195
- if (removeJosiMap[josi]) { josi = '' }
196
-
197
- // 漢字カタカナ英語から始まる語句 --- 送り仮名を省略
198
- if (isTrimOkurigana) {
199
- res = trimOkurigana(res)
200
- }
201
- // 助詞だけの語句の場合
202
- if (res === '' && josi !== '') {
203
- res = josi
204
- josi = ''
205
- }
206
- return { src: src, res: res, josi: josi, numEOL: 0 }
207
- }
208
-
209
- function cbString (beginTag, closeTag, src) {
210
- let res = ''
211
- let josi = ''
212
- let numEOL = 0
213
- src = src.substr(beginTag.length) // skip beginTag
214
- const i = src.indexOf(closeTag)
215
- if (i < 0) { // not found
216
- res = src
217
- src = ''
218
- } else {
219
- res = src.substr(0, i)
220
- src = src.substr(i + closeTag.length)
221
- // res の中に beginTag があればエラーにする #953
222
- if (res.indexOf(beginTag) >= 0) {
223
- if (beginTag === '『') {
224
- throw new Error('「『」で始めた文字列の中に「『」を含めることはできません。')
225
- } else {
226
- throw new Error(`『${beginTag}』で始めた文字列の中に『${beginTag}』を含めることはできません。`)
227
- }
228
- }
229
- }
230
- // 文字列直後の助詞を取得
231
- const j = josiRE.exec(src)
232
- if (j) {
233
- josi = j[0].replace(/^\s+/, '')
234
- src = src.substr(j[0].length)
235
- // 助詞の後のカンマ #877
236
- if (src.charAt(0) === ',') { src = src.substr(1) }
237
- }
238
- // 助詞「こと」「である」「です」などは「**すること」のように使うので削除 #936 #939 #974
239
- if (removeJosiMap[josi]) { josi = '' }
240
-
241
- // 改行を数える
242
- for (let i = 0; i < res.length; i++) { if (res.charAt(i) === '\n') { numEOL++ } }
243
-
244
- return { src: src, res: res, josi: josi, numEOL: numEOL }
245
- }
246
-
247
- function trimOkurigana (s) {
248
- // ひらがなから始まらない場合、送り仮名を削除。(例)置換する
249
- if (!hira.test(s)) {
250
- return s.replace(/[ぁ-ん]+/g, '')
251
- }
252
- // 全てひらがな? (例) どうぞ
253
- if (allHiragana.test(s)) { return s }
254
- // 末尾のひらがなのみ (例)お願いします →お願
255
- return s.replace(/[ぁ-ん]+$/g, '')
256
- }
257
-
258
- function parseNumber (n) {
259
- return Number(n.replace(/_/g, ''))
260
- }
@@ -1,8 +0,0 @@
1
- // なでしこバージョン
2
- const nakoVersion = {
3
- version: '3.2.51',
4
- major: 3,
5
- minor: 2,
6
- patch: 51
7
- }
8
- module.exports = nakoVersion
@@ -1,43 +0,0 @@
1
- const assert = require('assert')
2
- const child_process = require('child_process')
3
- const path = require('path')
4
- const fs = require ('fs')
5
-
6
- const cnako3 = path.join(__dirname, '../../src/cnako3.js')
7
- const packagejson = require('../../package.json')
8
- const debug = false
9
-
10
- describe('node_test(cnako)', () => {
11
- const cmp = (code, exRes) => {
12
- const result = child_process.execSync(`node ${cnako3} -e "${code}"`).toString().replace(/\s+$/, '')
13
- if (debug) {
14
- console.log('code=' + code)
15
- console.log('result=' + result)
16
- }
17
- assert.strictEqual(result, exRes)
18
- }
19
- // --- バージョンチェック ---
20
- it('ナデシコバージョン:src/plugin_system.jsを正しく設定しているか?', () => {
21
- cmp('ナデシコバージョンを表示', packagejson.version)
22
- cmp('ナデシコ種類を表示', 'cnako3')
23
- })
24
- // --- test ---
25
- it('print simple', () => {
26
- cmp('3を表示', '3')
27
- cmp('1+2*3を表示', '7')
28
- cmp('A=30;「--{A}--」を表示', '--30--')
29
- }).timeout(15000)
30
-
31
- it('単独で実行できるプログラムの出力 - Node.js', function () {
32
- if (process.env.NODE_ENV === 'test') {return this.skip()}
33
- const stderr = child_process.spawnSync('node', [cnako3, '-c', path.join(__dirname, 'add_test.nako3')]).stderr
34
- try {
35
- if (stderr) { console.error(stderr.toString()) }
36
- const p = child_process.spawnSync('node', [path.join(__dirname, 'add_test.js')])
37
- if (p.stderr) { console.error(p.stderr.toString()) }
38
- assert.strictEqual(p.stdout.toString(), '3\n')
39
- } finally {
40
- fs.unlinkSync(path.join(__dirname, 'add_test.js'))
41
- }
42
- })
43
- })