feat(check): M4 L1 引用一致性 — 描述里的反引号实体必须可解析(label.ref_dangling)
规则:描述里的 `名字` = 断言,必须能解析 —— 要么 () 的实现用到它,要么文档定义了它(函数/参数/import 绑定/frontmatter 键), 要么是内置函数。否则报 label.ref_dangling(error)。 只认反引号(可证伪原则):普通汉字不参与判定,避免海量假阳性; 代价是作者不写反引号就得不到保护,这是刻意的——机器只校验它看得懂的断言。 实现: - refs(label):扫描成对反引号取内部(未闭合/空串忽略,不 panic) - payload_idents(payload):Var / callee / path 段 / receiver / [k] 变量键 / 插值变量 - module_symbols(module):函数与子函数、参数、import/use 绑定、frontmatter 键 - 内置函数用 crate::host::HostFn::from_name 判定 - OcclusionSite 增加 payload_idents,collect 阶段一次算好 实测: 悬空 → "描述引用了不存在的实体:`税率` ..." 1 error, exit 1 可解析(payload 变量 / len 内置 / `> 加 1 2` 行内调用)→ 零诊断 测试:3 个单测(抽取/多引用与散文混排/未闭合不 panic) + 2 个集成(悬空 exit 1;三类可解析零诊断) 全量 cargo test --release:583 passed / 0 failed(M2.5 后 578 + 5) 文档:doc/design/change-m4-label-refs.md
This commit is contained in:
1 parent
1a94cc8490
commit
6dd0ce47b1
5 files changed
+297
No files matched your search
@@ -83,3 +83,19 @@ fn label_ok_has_no_diagnostics() {
|
||||
assert!(!text.contains("空载荷"), "text={text}");
|
||||
assert!(!text.contains("缺少描述"), "text={text}");
|
||||
}
|
||||
|
||||
// ---- M4: L1 reference consistency (`label.ref_dangling`) ----
|
||||
|
||||
#[test]
|
||||
fn label_ref_dangling_is_an_error() {
|
||||
let (code, text) = check("tests/occlusion/ref-dangling.mq.md", "occlusion");
|
||||
assert_eq!(code, 1, "text={text}");
|
||||
assert!(text.contains("描述引用了不存在的实体"), "text={text}");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn label_refs_that_resolve_are_fine() {
|
||||
let (code, text) = check("tests/occlusion/ref-ok.mq.md", "occlusion");
|
||||
assert_eq!(code, 0, "text={text}");
|
||||
assert!(!text.contains("不存在的实体"), "text={text}");
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
---
|
||||
title: dangling label ref
|
||||
---
|
||||
|
||||
# main
|
||||
|
||||
**a = [按 `税率` 计算](100 * 0.1)**
|
||||
> print text=`a`
|
||||
@@ -0,0 +1,20 @@
|
||||
---
|
||||
title: resolvable label refs
|
||||
---
|
||||
|
||||
# main
|
||||
|
||||
`税率` = 0.1
|
||||
|
||||
**a = [按 `税率` 算](100 * `税率`)**
|
||||
**b = [取长度](len("abc"))**
|
||||
**c = [用 `加` 求和](> 加 1 2)**
|
||||
> print text=`a`
|
||||
> print text=`b`
|
||||
> print text=`c`
|
||||
|
||||
## 加
|
||||
+ `x`
|
||||
+ `y`
|
||||
|
||||
*`x` + `y`*
|
||||
Reference in new issue
Block a user