Skip to content

Commit a8a9b61

Browse files
Merge pull request #781 from HardyNLee/fix-parser
fix: parser trim behavior
2 parents ddef38f + 18c3f28 commit a8a9b61

3 files changed

Lines changed: 8 additions & 6 deletions

File tree

packages/parser/src/sceneParser.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ export const sceneParser = (
2929
ADD_NEXT_ARG_LIST: commandType[],
3030
SCRIPT_CONFIG_MAP: ConfigMap,
3131
): IScene => {
32-
const rawSentenceList = rawScene.split('\n'); // 原始句子列表
32+
const rawSentenceList = rawScene.replaceAll('\r', '').split('\n'); // 原始句子列表
3333

3434
// 去分号留到后面去做了,现在注释要单独处理
3535
const rawSentenceListWithoutEmpty = rawSentenceList;

packages/parser/src/scriptParser/argsParser.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,10 @@ export function argsParser(
2323
});
2424
rawArgsList.forEach((e) => {
2525
const equalSignIndex = e.indexOf('=');
26-
let argName = e.slice(0, equalSignIndex);
27-
let argValue: string | undefined = e.slice(equalSignIndex + 1);
26+
let argName = e.slice(0, equalSignIndex).trim();
27+
let argValue: string | undefined = e.slice(equalSignIndex + 1).trim();
2828
if (equalSignIndex < 0) {
29-
argName = e;
29+
argName = e.trim();
3030
argValue = undefined;
3131
}
3232
// 判断是不是语音参数

packages/parser/src/scriptParser/scriptParser.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,14 +36,16 @@ export const scriptParser = (
3636
// 正式开始解析
3737

3838
// 去分号
39-
let newSentenceRaw = sentenceRaw.split(/(?<!\\);/)[0];
39+
const commentSplit = sentenceRaw.split(/(?<!\\);/);
40+
let newSentenceRaw = commentSplit[0].trim();
4041
newSentenceRaw = newSentenceRaw.replaceAll('\\;',';');
42+
const sentenceComment = commentSplit[1] ?? '';
4143
if (newSentenceRaw === '') {
4244
// 注释提前返回
4345
return {
4446
command: commandType.comment, // 语句类型
4547
commandRaw: 'comment', // 命令原始内容,方便调试
46-
content: sentenceRaw.split(';')[1] ?? '', // 语句内容
48+
content: sentenceComment.trim(), // 语句内容
4749
args: [{ key: 'next', value: true }], // 参数列表
4850
sentenceAssets: [], // 语句携带的资源列表
4951
subScene: [], // 语句携带的子场景

0 commit comments

Comments
 (0)