fix: harden school imports and add optional feedback diagnostics

This commit is contained in:
Codex
2026-10-15 10:37:32 +08:00
parent 674df1ceb3
commit 7299f4d8b6
25 changed files with 722 additions and 42 deletions
@@ -21,6 +21,10 @@ List<UndergraduateActivity> parseActivityData(
r'new\s+TaskActivity\s*\((.*?)\)\s*;',
dotAll: true,
).allMatches(script).toList();
if (RegExp(r'\bnew\s+TaskActivity\s*\(').allMatches(script).length !=
matches.length) {
throw const FormatException('课程活动声明不完整');
}
final result = <UndergraduateActivity>[];
for (var i = 0; i < matches.length; i++) {
final m = matches[i], args = _strings(m[1]!);
@@ -48,9 +52,17 @@ List<UndergraduateActivity> parseActivityData(
final assignments = RegExp(r'\bindex\s*=\s*([^;]+);')
.allMatches(body)
.toList();
final appends = RegExp(
final appendPattern = RegExp(
r'table\d+\.activities\[index\]\s*\[[^;]+?\]\s*=\s*activity\s*;',
).allMatches(body).length;
);
final appends = appendPattern.allMatches(body).length;
final unconsumed = body
.replaceAll(appendPattern, '')
.replaceAll(RegExp(r'\bindex\s*=\s*[^;]+;'), '');
if (RegExp(r'\btable\d+\.activities\s*\[|\bindex\s*=')
.hasMatch(unconsumed)) {
throw const FormatException('存在无法识别的课程节次赋值');
}
if (assignments.isEmpty || assignments.length != appends) {
throw const FormatException('课程节次赋值不完整');
}