From 4454fd7160dbb8a2cb7e30423c518d93c964dc4d Mon Sep 17 00:00:00 2001 From: ChangeSuger Date: Thu, 18 Jun 2026 00:00:07 +0800 Subject: [PATCH] fix(parser): preserve semicolons in inline comments - Keep all text after the first unescaped semicolon when parsing inline comments, instead of only taking the first split segment. - Add tests for normal inline comments and comment-only lines with multiple semicolons. --- .../parser/src/scriptParser/scriptParser.ts | 2 +- packages/parser/test/parser.test.ts | 38 +++++++++++++++++++ 2 files changed, 39 insertions(+), 1 deletion(-) diff --git a/packages/parser/src/scriptParser/scriptParser.ts b/packages/parser/src/scriptParser/scriptParser.ts index 4ecb68e73..0fd07d93e 100644 --- a/packages/parser/src/scriptParser/scriptParser.ts +++ b/packages/parser/src/scriptParser/scriptParser.ts @@ -40,7 +40,7 @@ export const scriptParser = ( const commentSplit = sentenceRaw.split(/(? { + const parser = new SceneParser((assetList) => { + }, (fileName, assetType) => { + return fileName; + }, ADD_NEXT_ARG_LIST, SCRIPT_CONFIG); + + const result = parser.parse(`say:123; first; second; third`, 'test', 'test'); + const expectSentenceItem: ISentence = { + command: commandType.say, + commandRaw: "say", + content: "123", + args: [], + sentenceAssets: [], + subScene: [], + inlineComment: "first; second; third" + }; + expect(result.sentenceList).toContainEqual(expectSentenceItem); +}); + test("comment-only line keeps comment in content", async () => { const parser = new SceneParser((assetList) => { }, (fileName, assetType) => { @@ -344,3 +363,22 @@ test("comment-only line keeps comment in content", async () => { }; expect(result.sentenceList).toContainEqual(expectSentenceItem); }); + +test("comment-only line preserves following semicolons", async () => { + const parser = new SceneParser((assetList) => { + }, (fileName, assetType) => { + return fileName; + }, ADD_NEXT_ARG_LIST, SCRIPT_CONFIG); + + const result = parser.parse(`; first; second; third`, 'test', 'test'); + const expectSentenceItem: ISentence = { + command: commandType.comment, + commandRaw: "comment", + content: "first; second; third", + args: [{ key: 'next', value: true }], + sentenceAssets: [], + subScene: [], + inlineComment: "" + }; + expect(result.sentenceList).toContainEqual(expectSentenceItem); +});