Skip to content

Commit

Permalink
Merge pull request #1875 from kujirahand/fix_array_sytax_ref_array
Browse files Browse the repository at this point in the history
オブジェクト記法の後ろの配列アクセスがエラーを修正 #1858
  • Loading branch information
kujirahand authored Dec 20, 2024
2 parents 11da558 + 297c558 commit 08278c6
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 3 deletions.
21 changes: 20 additions & 1 deletion core/src/nako_parser3.mts
Original file line number Diff line number Diff line change
Expand Up @@ -2448,8 +2448,27 @@ export class NakoParser extends NakoParserBase {
return a
}

yJSONObject(): AstBlocks | Ast | null {
const a = this.yJSONObjectRaw()
if (!a) { return null }
// 配列の直後に@や[]があるか?助詞がある場合には、別の引数の可能性があるので無視。 (例) [0,1,2]を[3,4,5]に配列***
if (a.josi === '' && this.checkTypes(['@', '['])) {
const ast: Ast = {
type: 'ref_array',
name: '__ARRAY__',
index: [a],
josi: '',
line: a.line,
end: this.peekSourceMap()
}
this.yValueWordGetIndex(ast)
return ast
}
return a
}

/** @returns {Ast | null} */
yJSONObject (): AstBlocks | null {
yJSONObjectRaw (): AstBlocks | null {
const map = this.peekSourceMap()
if (this.accept(['{', '}'])) {
return {
Expand Down
9 changes: 7 additions & 2 deletions core/test/array_test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -66,14 +66,19 @@ describe('array_test', async () => {
await cmp('A=[[0,1],[2,3]]。A[1]と[2]を連続表示', '2,32')
await cmp('A=[[0,1],[2,3]]。0にA[1]の[9,9]を配列一括挿入してJSONエンコードして表示', '[9,9,2,3]')
})
it('『["a","b","c","d"]@2を表示』がエラー #1858', async () => {
it('配列記法の後ろの配列アクセスがエラー #1858 @', async () => {
await cmp('[0,1,2,3,4,5]@2を表示', '2')
await cmp('["a","b","c"]@2を表示', 'c')
await cmp('[[0,1,2],[3,4,5]]@1,0を表示', '3')
})
it('『["a","b","c","d"]@2を表示』がエラー #1858', async () => {
it('配列記法の後ろの配列アクセスがエラー #1858 []', async () => {
await cmp('[0,1,2,3,4,5][2]を表示', '2')
await cmp('["a","b","c"][2]を表示', 'c')
await cmp('[[0,1,2],[3,4,5]][1,0]を表示', '3')
})
it('オブジェクト記法の後ろの配列アクセスがエラー #1858 @', async () => {
await cmp('{"a":1, "b":2}["b"]を表示', '2')
await cmp('{"a":1, "b":2}@"b"を表示', '2')
await cmp('[{"a":1, "b":2}]@0,"a"を表示', '1')
})
})

0 comments on commit 08278c6

Please sign in to comment.