feat:init

This commit is contained in:
Evan
2026-09-01 14:14:48 +08:00
parent 6a3e797a9a
commit 9c27042e27
234 changed files with 109 additions and 117 deletions

View File

@@ -771,40 +771,18 @@ export class CppCodeExecutor {
continue;
}
// 检查是否是函数调用(包括带参数的
const functionCallMatch = line.match(/(\w+)\s*\(([^)]*)\)\s*;?/);
if (functionCallMatch) {
const functionName = functionCallMatch[1];
const argumentsStr = functionCallMatch[2];
// 排除C++关键字和控制结构
const cppKeywords = [
'for', 'while', 'if', 'else', 'switch', 'case', 'return',
'int', 'string', 'bool', 'void', 'float', 'double', 'char'
];
// 检查是否是游戏API函数这些不是自定义函数
const gameApiFunctions = [
'playerMove', 'playerJump', 'turnLeft', 'turnRight',
'vehicleMove', 'turnVehicleLeft', 'turnVehicleRight',
'player_data', 'player_position', 'vehicle_position'
];
if (!cppKeywords.includes(functionName) &&
!gameApiFunctions.includes(functionName) &&
!line.includes('cout')) {
// 这是自定义函数调用
const parsedArguments = this.parseArguments(argumentsStr);
statements.push({
type: 'function_call',
functionName: functionName,
arguments: parsedArguments,
lineNumber: isMainFunction ? this.getActualLineNumber(i) : i + 1,
content: line // 保存原始内容用于行号映射
});
i++;
continue;
}
// 检查是否是自定义函数调用(包括带括号的实参,如 f((n + 1));
const customCall = this.parseCustomFunctionCall(line);
if (customCall) {
statements.push({
type: 'function_call',
functionName: customCall.functionName,
arguments: customCall.arguments,
lineNumber: isMainFunction ? this.getActualLineNumber(i) : i + 1,
content: line // 保存原始内容用于行号映射
});
i++;
continue;
}
// 解析不同类型的语句
@@ -1346,29 +1324,16 @@ export class CppCodeExecutor {
async executeSimpleStatement(content) {
debugLog(`🔍 执行简单语句: ${content}`);
// 检查是否是函数调用(包括带参数的
const functionCallMatch = content.match(/(\w+)\s*\(([^)]*)\)\s*;?/);
if (functionCallMatch) {
const functionName = functionCallMatch[1];
const argumentsStr = functionCallMatch[2];
// 排除C++关键字和控制结构
const cppKeywords = [
'for', 'while', 'if', 'else', 'switch', 'case', 'return',
'int', 'string', 'bool', 'void', 'float', 'double', 'char'
];
// 检查是否是自定义函数(排除关键字)
if (!cppKeywords.includes(functionName) && this.functions.has(functionName)) {
console.log(`📞 调用自定义函数: ${functionName}(${argumentsStr})`);
const parsedArguments = this.parseArguments(argumentsStr);
await this.executeFunctionCall({
type: 'function_call',
functionName: functionName,
arguments: parsedArguments
});
return;
}
// 检查是否是自定义函数调用(包括带括号的实参,如 f((n + 1));
const customCall = this.parseCustomFunctionCall(content);
if (customCall && this.functions.has(customCall.functionName)) {
console.log(`📞 调用自定义函数: ${customCall.functionName}(${customCall.arguments.join(', ')})`);
await this.executeFunctionCall({
type: 'function_call',
functionName: customCall.functionName,
arguments: customCall.arguments
});
return;
}
// 自增/自减语句 (如 a++; 或 ++a;)
@@ -2158,7 +2123,46 @@ export class CppCodeExecutor {
}
}
// 解析函数调用参数
// 解析自定义函数调用,正确处理实参里的嵌套括号(如 f((n + 1))
parseCustomFunctionCall(content) {
if (!content) {
return null;
}
const cppKeywords = [
'for', 'while', 'if', 'else', 'switch', 'case', 'return',
'int', 'string', 'bool', 'void', 'float', 'double', 'char'
];
const gameApiFunctions = [
'playerMove', 'playerJump', 'turnLeft', 'turnRight',
'vehicleMove', 'turnVehicleLeft', 'turnVehicleRight',
'player_data', 'player_position', 'vehicle_position'
];
const nameMatch = content.match(/(\w+)\s*\(/);
if (!nameMatch) {
return null;
}
const functionName = nameMatch[1];
if (cppKeywords.includes(functionName) ||
gameApiFunctions.includes(functionName) ||
content.includes('cout')) {
return null;
}
const parsedArguments = this.extractFunctionArguments(content, functionName);
if (parsedArguments === null) {
return null;
}
return {
functionName,
arguments: parsedArguments
};
}
// 解析函数调用参数,按逗号分割时忽略括号内的逗号
parseArguments(argumentsStr) {
const argumentsList = [];
@@ -2166,14 +2170,29 @@ export class CppCodeExecutor {
return argumentsList; // 无参数调用
}
// 分割参数,支持多个参数
const argParts = argumentsStr.split(',');
let currentArg = '';
let nestedParens = 0;
for (const argPart of argParts) {
const trimmed = argPart.trim();
if (trimmed) {
argumentsList.push(trimmed);
for (let j = 0; j < argumentsStr.length; j++) {
const char = argumentsStr[j];
if (char === '(') {
nestedParens++;
} else if (char === ')') {
nestedParens--;
} else if (char === ',' && nestedParens === 0) {
if (currentArg.trim()) {
argumentsList.push(currentArg.trim());
}
currentArg = '';
continue;
}
currentArg += char;
}
if (currentArg.trim()) {
argumentsList.push(currentArg.trim());
}
return argumentsList;
@@ -2624,35 +2643,8 @@ export class CppCodeExecutor {
return null;
}
// 解析参数
if (!argsString.trim()) {
return [];
}
// 按逗号分割参数,但要考虑括号嵌套
const args = [];
let currentArg = '';
let nestedParens = 0;
for (let j = 0; j < argsString.length; j++) {
const char = argsString[j];
if (char === '(') {
nestedParens++;
} else if (char === ')') {
nestedParens--;
} else if (char === ',' && nestedParens === 0) {
args.push(currentArg.trim());
currentArg = '';
continue;
}
currentArg += char;
}
if (currentArg.trim()) {
args.push(currentArg.trim());
}
// 解析参数,按逗号分割时忽略括号内的逗号
const args = this.parseArguments(argsString);
debugLog(`🔍 函数${functionName}提取到的参数:`, args);
return args;

View File

@@ -1,12 +1,12 @@
// config.js
// const CONFIG = {
// DataServerBaseUrl: "https://server.001code.com", // 在这里定义服务器地址
// // DataServerBaseUrl: "https://server.001code.com", // 在这里定义服务器地址
// // DataServerBaseUrl: "https://server.001code.com",
// // DataServerBaseUrl: "https://server.001code.com",
// // DataServerBaseUrl: "https://server.001code.com",
// // DataServerBaseUrl: "https://server.001code.com",
// DataServerBaseUrl: "https://test.server.001code.com", // 在这里定义服务器地址
// // DataServerBaseUrl: "https://test.server.001code.com", // 在这里定义服务器地址
// // DataServerBaseUrl: "https://test.server.001code.com",
// // DataServerBaseUrl: "https://test.server.001code.com",
// // DataServerBaseUrl: "https://test.server.001code.com",
// // DataServerBaseUrl: "https://test.server.001code.com",
// version : "2025010301",
// unitycdndir : 'https://oss-rpwqy.jjwlcdn.com/001_code_unity_res_20250826',
// unitycdnbuilddir : 'https://oss-rpwqy.jjwlcdn.com/001_code_unity_res_20250826/Build',
@@ -14,7 +14,7 @@
// // 可以根据需要添加其他配置
// disabledev: true,
// disabledev: false,
// usecdn :true, //资源走CDN
// lvlock :false, //关卡5关解锁,下一关加锁
// lvlock_normal_learn :true, //常规关起锁
@@ -78,12 +78,12 @@
// const CONFIG = {
// // DataServerBaseUrl: "https://server.001code.com", // 在这里定义服务器地址
// // DataServerBaseUrl: "https://server.001code.com", // 在这里定义服务器地址
// // DataServerBaseUrl: "https://server.001code.com",
// DataServerBaseUrl: "https://server.001code.com",
// // DataServerBaseUrl: "https://server.001code.com",
// // DataServerBaseUrl: "https://server.001code.com",
// // DataServerBaseUrl: "https://test.server.001code.com", // 在这里定义服务器地址
// // DataServerBaseUrl: "https://test.server.001code.com", // 在这里定义服务器地址
// // DataServerBaseUrl: "https://test.server.001code.com",
// DataServerBaseUrl: "https://test.server.001code.com",
// // DataServerBaseUrl: "https://test.server.001code.com",
// // DataServerBaseUrl: "https://test.server.001code.com",
// version : "2025011001",
// unitycdndir : 'https://oss-rpwqy.jjwlcdn.com/001_code_unity_res_20250826',
// unitycdnbuilddir : 'https://oss-rpwqy.jjwlcdn.com/001_code_unity_res_20250826/Build',
@@ -91,8 +91,8 @@
// // 可以根据需要添加其他配置
// // disabledev: true,
// disabledev: true,
// // disabledev: false,
// disabledev: false,
// usecdn :true, //资源走CDN
// lvlock :false, //关卡5关解锁,下一关加锁
// lvlock_normal_learn : !(typeof localStorage !== 'undefined' &&
@@ -157,12 +157,12 @@
const CONFIG = {
// DataServerBaseUrl: "https://server.001code.com", // 在这里定义服务器地址
// DataServerBaseUrl: "https://server.001code.com", // 在这里定义服务器地址
// DataServerBaseUrl: "https://server.001code.com",
DataServerBaseUrl: "https://server.001code.com",
// DataServerBaseUrl: "https://server.001code.com",
// DataServerBaseUrl: "https://server.001code.com",
// DataServerBaseUrl: "https://test.server.001code.com", // 在这里定义服务器地址
// DataServerBaseUrl: "https://test.server.001code.com", // 在这里定义服务器地址
// DataServerBaseUrl: "https://test.server.001code.com",
DataServerBaseUrl: "https://test.server.001code.com",
// DataServerBaseUrl: "https://test.server.001code.com",
// DataServerBaseUrl: "https://test.server.001code.com",
version: "2026071701",
@@ -182,7 +182,7 @@ const CONFIG = {
disabledev: true,
disabledev: false,
usecdn: false,
lvlock: false,
lvlock_normal_learn: !(typeof localStorage !== 'undefined' &&