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,41 +771,19 @@ export class CppCodeExecutor {
continue; continue;
} }
// 检查是否是函数调用(包括带参数的 // 检查是否是自定义函数调用(包括带括号的实参,如 f((n + 1));
const functionCallMatch = line.match(/(\w+)\s*\(([^)]*)\)\s*;?/); const customCall = this.parseCustomFunctionCall(line);
if (functionCallMatch) { if (customCall) {
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({ statements.push({
type: 'function_call', type: 'function_call',
functionName: functionName, functionName: customCall.functionName,
arguments: parsedArguments, arguments: customCall.arguments,
lineNumber: isMainFunction ? this.getActualLineNumber(i) : i + 1, lineNumber: isMainFunction ? this.getActualLineNumber(i) : i + 1,
content: line // 保存原始内容用于行号映射 content: line // 保存原始内容用于行号映射
}); });
i++; i++;
continue; continue;
} }
}
// 解析不同类型的语句 // 解析不同类型的语句
if (line.startsWith('for')) { if (line.startsWith('for')) {
@@ -1346,30 +1324,17 @@ export class CppCodeExecutor {
async executeSimpleStatement(content) { async executeSimpleStatement(content) {
debugLog(`🔍 执行简单语句: ${content}`); debugLog(`🔍 执行简单语句: ${content}`);
// 检查是否是函数调用(包括带参数的 // 检查是否是自定义函数调用(包括带括号的实参,如 f((n + 1));
const functionCallMatch = content.match(/(\w+)\s*\(([^)]*)\)\s*;?/); const customCall = this.parseCustomFunctionCall(content);
if (functionCallMatch) { if (customCall && this.functions.has(customCall.functionName)) {
const functionName = functionCallMatch[1]; console.log(`📞 调用自定义函数: ${customCall.functionName}(${customCall.arguments.join(', ')})`);
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({ await this.executeFunctionCall({
type: 'function_call', type: 'function_call',
functionName: functionName, functionName: customCall.functionName,
arguments: parsedArguments arguments: customCall.arguments
}); });
return; return;
} }
}
// 自增/自减语句 (如 a++; 或 ++a;) // 自增/自减语句 (如 a++; 或 ++a;)
if (content.includes('++') || content.includes('--')) { if (content.includes('++') || content.includes('--')) {
@@ -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) { parseArguments(argumentsStr) {
const argumentsList = []; const argumentsList = [];
@@ -2166,14 +2170,29 @@ export class CppCodeExecutor {
return argumentsList; // 无参数调用 return argumentsList; // 无参数调用
} }
// 分割参数,支持多个参数 let currentArg = '';
const argParts = argumentsStr.split(','); let nestedParens = 0;
for (const argPart of argParts) { for (let j = 0; j < argumentsStr.length; j++) {
const trimmed = argPart.trim(); const char = argumentsStr[j];
if (trimmed) {
argumentsList.push(trimmed); 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; return argumentsList;
@@ -2624,35 +2643,8 @@ export class CppCodeExecutor {
return null; return null;
} }
// 解析参数 // 解析参数,按逗号分割时忽略括号内的逗号
if (!argsString.trim()) { const args = this.parseArguments(argsString);
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());
}
debugLog(`🔍 函数${functionName}提取到的参数:`, args); debugLog(`🔍 函数${functionName}提取到的参数:`, args);
return args; return args;

View File

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

Some files were not shown because too many files have changed in this diff Show More