nadesiko3 3.3.10 → 3.3.13

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/src/index.mjs CHANGED
@@ -1,9 +1,12 @@
1
1
 
2
- import {NakoCompiler} from './nako3.mjs'
3
- import {PluginNode} from './plugin_node.mjs'
2
+ import { NakoCompiler } from './nako3.mjs'
3
+ import { CNako3 } from './cnako3mod.mjs'
4
+ import PluginNode from './plugin_node.mjs'
4
5
 
5
6
  export default {
6
- // Node.jsのモジュールモードでなでしこを利用する場合
7
+ CNako3,
8
+ NakoCompiler,
7
9
  compiler: NakoCompiler,
8
10
  PluginNode
9
11
  }
12
+
package/src/nako_gen.mjs CHANGED
@@ -188,8 +188,18 @@ export class NakoGen {
188
188
  }
189
189
  }
190
190
 
191
- /** @param {string} name */
191
+ /**
192
+ * @param {string} name
193
+ * @returns {string}
194
+ */
192
195
  static getFuncName (name) {
196
+ if (name.indexOf('__') >= 0) { // スコープがある場合
197
+ const a = name.split('__')
198
+ let scope = a[0]
199
+ const name3 = NakoGen.getFuncName(a[1])
200
+ return `${scope}__${name3}`
201
+
202
+ }
193
203
  let name2 = name.replace(/[ぁ-ん]+$/, '')
194
204
  if (name2 === '') { name2 = name }
195
205
  return name2
@@ -275,8 +275,17 @@ export class NakoParser extends NakoParserBase {
275
275
  try {
276
276
  this.funcLevel++
277
277
  this.usedAsyncFn = false
278
+ // ローカル変数を生成
279
+ const backupLocalvars = this.localvars
280
+ this.localvars = {'それ': {type: 'var', value: ''}}
281
+
278
282
  if (multiline) {
279
283
  this.saveStack()
284
+ // 関数の引数をローカル変数として登録する
285
+ for (const arg of defArgs) {
286
+ const fnName = arg.value
287
+ this.localvars[fnName] = {'type': 'var', 'value': ''}
288
+ }
280
289
  block = this.yBlock()
281
290
  if (this.check('ここまで')) { this.get() } else { throw NakoSyntaxError.fromNode('『ここまで』がありません。関数定義の末尾に必要です。', def) }
282
291
  this.loadStack()
@@ -287,6 +296,7 @@ export class NakoParser extends NakoParserBase {
287
296
  }
288
297
  this.funcLevel--
289
298
  asyncFn = this.usedAsyncFn
299
+ this.localvars = backupLocalvars
290
300
  } catch (err) {
291
301
  this.logger.debug(this.nodeToStr(funcName, { depth: 0, typeName: '関数' }, true) +
292
302
  'の定義で以下のエラーがありました。\n' + err.message, def)
@@ -1961,7 +1971,7 @@ export class NakoParser extends NakoParserBase {
1961
1971
  word.value = this.modName + '__' + word.value
1962
1972
  }
1963
1973
  }
1964
- if (f && f.scope === 'global') {
1974
+ else if (f && f.scope === 'global') {
1965
1975
  word.value = f.name
1966
1976
  }
1967
1977
  return word
@@ -25,7 +25,7 @@ export class NakoParserBase {
25
25
  /** グローバル変数・関数の確認用 */
26
26
  this.funclist = {}
27
27
  this.funcLevel = 0
28
- this.usedAsyncFn = false // funcFnの呼び出しがあるかどうか
28
+ this.usedAsyncFn = false // asyncFnの呼び出しがあるかどうか
29
29
  /** ローカル変数の確認用 */
30
30
  this.localvars = {'それ': {type: 'var', value: ''}}
31
31
  /** コード生成器の名前 */
@@ -89,7 +89,6 @@ export class NakoParserBase {
89
89
 
90
90
  loadStack () {
91
91
  this.stack = this.stackList.pop()
92
- this.localvars = {'それ': {type: 'var', value: ''}}
93
92
  }
94
93
 
95
94
  /** 変数名を探す
@@ -97,6 +96,14 @@ export class NakoParserBase {
97
96
  * @returns {any}変数名の情報
98
97
  */
99
98
  findVar(name) {
99
+ // ローカル変数?
100
+ if (this.localvars[name]) {
101
+ return {
102
+ name: name,
103
+ scope: 'local',
104
+ info: this.localvars[name]
105
+ }
106
+ }
100
107
  // モジュール名を含んでいる?
101
108
  if (name.indexOf('__') >= 0) {
102
109
  if (this.funclist[name]) {
@@ -107,14 +114,6 @@ export class NakoParserBase {
107
114
  }
108
115
  } else { return undefined }
109
116
  }
110
- // ローカル変数?
111
- if (this.localvars[name]) {
112
- return {
113
- name: name,
114
- scope: 'local',
115
- info: this.localvars[name]
116
- }
117
- }
118
117
  // グローバル変数(自身)?
119
118
  const gnameSelf = `${this.modName}__${name}`
120
119
  if (this.funclist[gnameSelf]) {
@@ -1,7 +1,7 @@
1
1
  // なでしこバージョン
2
2
  export default {
3
- version: '3.3.10',
3
+ version: '3.3.13',
4
4
  major: 3,
5
5
  minor: 3,
6
- patch: 10
6
+ patch: 13
7
7
  }
@@ -133,4 +133,28 @@ describe('関数呼び出しテスト', () => {
133
133
  NakoSyntaxError, `関数『${funcName}』呼び出しで引数の数(1)が定義(2)と違います。`
134
134
  )
135
135
  })
136
+ it('ローカル変数が解決できない1 #1210', () => {
137
+ cmp('S=「あいうえお」;A=「かきくけこ」;AをFテスト;●(Sを)Fテストとは;Sを表示;ここまで', 'かきくけこ')
138
+ })
139
+ it('ローカル変数が解決できない2 #1210', () => {
140
+ cmp('S=「あいうえお」;Fテスト;●Fテストとは;Sとは変数=30;Sを表示;ここまで', '30')
141
+ cmp('S=「あいうえお」;Fテスト;Sを表示;●Fテストとは;Sとは変数=30;ここまで', 'あいうえお')
142
+ cmp('A=10;B=20;Aを三倍処理して表示;●(Bを)三倍処理とは;Aとは変数=3;A*Bを戻す;ここまで', '30')
143
+ })
144
+ it('ローカル変数の配列が解決できない2 #1213', () => {
145
+ cmp(`
146
+ 変数 A=空配列。
147
+ B=[10,20,30]
148
+ BでAAテスト
149
+ ●(Aで)AAテスト
150
+ もし(A[0]=10)かつ(A[1]=20)ならば「OK」を表示。
151
+ 違えば,「NG」を表示。# (えっ!)
152
+ ここまで。
153
+ `, 'OK')
154
+ })
155
+ it('ひらがなだけの関数名がエラーになる #1214', () => {
156
+ cmp('あ。;●あとは;「A」と表示;ここまで', 'A')
157
+ cmp('おくら。;●おくらとは;「O」と表示;ここまで', 'O')
158
+ })
136
159
  })
160
+