diff --git a/packages/parser/src/scriptParser/scriptParser.ts b/packages/parser/src/scriptParser/scriptParser.ts index aa33c6d15..022798931 100644 --- a/packages/parser/src/scriptParser/scriptParser.ts +++ b/packages/parser/src/scriptParser/scriptParser.ts @@ -56,7 +56,11 @@ export const scriptParser = ( // 没有command,说明这是一条连续对话或单条语句 if (getCommandResult === null) { commandRaw = newSentenceRaw; - parsedCommand = commandParser(commandRaw, ADD_NEXT_ARG_LIST, SCRIPT_CONFIG_MAP); + parsedCommand = commandParser( + commandRaw, + ADD_NEXT_ARG_LIST, + SCRIPT_CONFIG_MAP, + ); command = parsedCommand.type; for (const e of parsedCommand.additionalArgs) { // 由于是连续对话,所以我们去除 speaker 参数。 @@ -72,7 +76,11 @@ export const scriptParser = ( getCommandResult.index + 1, newSentenceRaw.length, ); - parsedCommand = commandParser(commandRaw, ADD_NEXT_ARG_LIST, SCRIPT_CONFIG_MAP); + parsedCommand = commandParser( + commandRaw, + ADD_NEXT_ARG_LIST, + SCRIPT_CONFIG_MAP, + ); command = parsedCommand.type; for (const e of parsedCommand.additionalArgs) { args.push(e); @@ -91,12 +99,12 @@ export const scriptParser = ( args.push(e); } } - content = contentParser(newSentenceRaw, command, assetSetter); // 将语句内容里的文件名转为相对或绝对路径 + content = contentParser(newSentenceRaw.trim(), command, assetSetter); // 将语句内容里的文件名转为相对或绝对路径 sentenceAssets = assetsScanner(command, content, args); // 扫描语句携带资源 subScene = subSceneScanner(command, content); // 扫描语句携带子场景 return { command: command, // 语句类型 - commandRaw: commandRaw, // 命令原始内容,方便调试 + commandRaw: commandRaw.trim(), // 命令原始内容,方便调试 content: content, // 语句内容 args: args, // 参数列表 sentenceAssets: sentenceAssets, // 语句携带的资源列表 diff --git a/packages/parser/test/test-resources/var.txt b/packages/parser/test/test-resources/var.txt index 33c2f0a00..7d306aba2 100644 --- a/packages/parser/test/test-resources/var.txt +++ b/packages/parser/test/test-resources/var.txt @@ -1,2 +1,8 @@ setVar:a=1; WebGAL:a=1? -when=a==1; + +;正常解析 +WebGAL:test; + +; : 异常测试 +WebGAL : test; diff --git a/packages/webgal/src/Core/controller/gamePlay/strIf.ts b/packages/webgal/src/Core/controller/gamePlay/strIf.ts index 26cb5e622..82f7d87f1 100644 --- a/packages/webgal/src/Core/controller/gamePlay/strIf.ts +++ b/packages/webgal/src/Core/controller/gamePlay/strIf.ts @@ -1,6 +1,10 @@ import { compile } from 'angular-expressions'; export function strIf(s: string) { - const res = compile(s); - return res(); + try { + const res = compile(s); + return res(); + } catch { + return false; + } }