fix(AST): f-string 规则从上线起就没生效过;加 check:ast 把这类静默错判变成机器检查
Some checks failed
Deploy / deploy (push) Has been cancelled
Some checks failed
Deploy / deploy (push) Has been cancelled
## check:ast
判题机拿 target 的 node 去比 tree-sitter 节点类型,**对不上不报错**:collectNodes 一个
都收不到,于是「必须使用 X」永远失败、「不能使用 X」永远通过,两头不报错,只有学生
受着。上一个提交把两张表合成一张,杜绝了「漏配」,但「配错」照样静默 —— 所以加一个
检查,逐个 target 去问语法:这个节点类型你到底有没有。
bun run --filter '@oj2/api' check:ast
升级 tree-sitter-* 之后必须跑:语法改节点名是常事,后果全静默。它只验节点类型存在,
不验语义对不对(把 while_loop 配成 for_statement 这种两个都存在,机器看不出来)。
## 它抓出来的那个
56 个 target 里坏了一个:Python3 的 f_string 一直配的是 format_string,而这个版本的
tree-sitter-python **根本没有这种节点** —— f-string 是一个 string,靠 string_start 为
f" 和内部的 interpolation 子节点来认。也就是说「不能使用 f-string」这条规则从上线起
就一直判成通过,「必须使用 f-string」一直判成失败。
改成 interpolation。实测:带占位符的 f-string(单双引号都有)命中,而 % 格式化、
.format()、普通字符串、字符串拼接都不误伤。代价是 f"abc" 这种没有占位符的 f-string
认不出来 —— 它确实不含 interpolation,但没占位符的 f-string 本来也没意义,比起原来
「一个都认不出来」是严格的改善。这条写在表里的注释上了。
## 验证
给题目 1004 配「必须有 for 循环 + 不能用 f-string」两条规则实跑:
- 有 for、用了 f-string → 修复前 ACCEPTED(0),修复后 AST_CHECK_FAILED(10),
ast_results 为「必须使用 for 循环/通过」「不能使用 f-string/不通过」;
- 有 for、不用 f-string → ACCEPTED(0);
- check:ast 修复前 exit 1 并指出这一条,修复后 56 个全过、exit 0。
tsc、check:routes、vue-tsc、vite build、单二进制编译均通过。
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_012j1vgeDqay8wKCh8dPgPcH
This commit is contained in:
@@ -200,7 +200,18 @@ export const AST_NODE_TARGETS_BY_LANGUAGE: Record<string, Record<string, AstNode
|
||||
list_literal: { label: "列表", node: "list" },
|
||||
dict_literal: { label: "字典", node: "dictionary" },
|
||||
set_literal: { label: "集合", node: "set" },
|
||||
f_string: { label: "f-string", node: "format_string" },
|
||||
/**
|
||||
* f-string 认的是 `interpolation`(`f"{x}"` 里的 `{x}`),不是 `format_string` ——
|
||||
* 这个版本的 tree-sitter-python 里**没有** format_string 这种节点,f-string 是
|
||||
* 一个 `string`,靠 `string_start` 为 `f"` 和内部的 interpolation 子节点来认。
|
||||
* 配成 format_string 的那阵子,「不能使用 f-string」从上线起就一直判成通过。
|
||||
*
|
||||
* 代价是 `f"abc"` 这种**没有占位符**的 f-string 认不出来(它确实不含
|
||||
* interpolation)。没占位符的 f-string 本来也没有意义,而且比起「一个都认不出来」
|
||||
* 这已经是严格的改善。实测 `%` 格式化、`.format()`、普通字符串、字符串拼接
|
||||
* 都不会误伤。
|
||||
*/
|
||||
f_string: { label: "f-string", node: "interpolation" },
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user