Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

オブジェクト記法の後ろの配列アクセスがエラーを修正 #1858 #1875

Merged
merged 1 commit into from
Dec 20, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
オブジェクト記法の後ろの配列アクセスがエラーを修正 #1858
kujirahand committed Dec 20, 2024
commit 297c558f4988a0500ee3a95778ce3eac1549eee8
21 changes: 20 additions & 1 deletion core/src/nako_parser3.mts
Original file line number Diff line number Diff line change
@@ -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 {
9 changes: 7 additions & 2 deletions core/test/array_test.mjs
Original file line number Diff line number Diff line change
@@ -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')
})
})