新增 Expr::Occluded { label, payload: Option<Box<Expr>> }:
- [] 描述:自由文本,永不执行(仅用于检索/统计/过期校验)
- () 实现:唯一执行体;为空时值为 None(空载荷桩)
- 支持嵌套遮蔽、描述含空格与中文标点、\] 转义
关键决策:**模式开关,暂不切换语义**
[键](集合) 与 [描述](实现) 外形完全相同;M2 若直接改语义,全仓 506 处取元会
静默变成"遮蔽整个集合"(同形换义,文档点名的最坏一类)。
故 M2 只实现能力:
- 默认 Classic:MARQDO_MARKUP 未设 → [a](b) 仍是取元
- 纯度 Occlusion:MARQDO_MARKUP=occlusion/purity/1/on → 遮蔽
M7 才迁移语料、翻转默认、对旧形报 syntax.legacy_index 硬错误。
实现:
- ast.rs 新节点
- parse/expr.rs:Markup 枚举 + set_markup_default + parse_expr_markup(显式模式,
避免测试依赖全局) + parse_occluded(描述扫描到 ]、\] 转义、必须紧跟 (、
空载荷 → None)+ Parser.markup 字段
- interp.rs:有 payload 求值 payload,否则 None;collect_decl_reads 递归 payload
- bytecode/compile.rs:编译 payload(空则 Op::None_),双后端一致
- view/render.rs:expr_prec 渲染 [描述](payload) / [描述]()
- parse/mod.rs:pub mod expr
- main.rs:MARQDO_MARKUP 环境变量(init_markup_from_env)
测试:
- 8 个单元(值直通/空载荷/描述空格标点/转义/嵌套/classic 仍取元/缺括号报错)
- 3 个集成 tests/occlusion.rs + tests/occlusion/*.mq.md
- 全量 cargo test --release:575 passed / 0 failed(M1 后 565 + 10)
- tree 与 bytecode 双后端一致
文档:doc/design/change-m2-occlusion.md
46 lines
1.7 KiB
Rust
46 lines
1.7 KiB
Rust
//! `<TAB>` M2: occlusion syntax end-to-end (CLI + `MARQDO_MARKUP=occlusion`).
|
|
//!
|
|
//! The mode flag keeps `[键](集合)` (classic index) intact until M7 migrates the
|
|
//! corpus; these tests pin both sides of the switch.
|
|
|
|
use std::process::Command;
|
|
|
|
fn run(path: &str, markup: Option<&str>) -> (i32, String, String) {
|
|
let mut cmd = Command::new(env!("CARGO_BIN_EXE_marqdo"));
|
|
cmd.args(["run", path]);
|
|
if let Some(m) = markup {
|
|
cmd.env("MARQDO_MARKUP", m);
|
|
}
|
|
let out = cmd.output().expect("run marqdo");
|
|
(
|
|
out.status.code().unwrap_or(1),
|
|
String::from_utf8_lossy(&out.stdout).into_owned(),
|
|
String::from_utf8_lossy(&out.stderr).into_owned(),
|
|
)
|
|
}
|
|
|
|
#[test]
|
|
fn occlusion_value_is_payload() {
|
|
let (code, stdout, stderr) = run("tests/occlusion/value.mq.md", Some("occlusion"));
|
|
assert_eq!(code, 0, "stderr={stderr}");
|
|
assert_eq!(stdout.trim_end(), "a=2\nb=42\nc=True");
|
|
}
|
|
|
|
#[test]
|
|
fn occlusion_off_keeps_classic_index() {
|
|
let (code, stdout, stderr) = run("tests/occlusion/classic-index.mq.md", None);
|
|
assert_eq!(code, 0, "stderr={stderr}");
|
|
assert_eq!(stdout.trim_end(), "值");
|
|
}
|
|
|
|
#[test]
|
|
fn occlusion_mode_rejects_legacy_index_shape() {
|
|
// In occlusion mode `[键](集合)` is read as an occlusion whose payload is the
|
|
// collection — i.e. it returns the *whole* map, not the member. This is why
|
|
// M7 must migrate before flipping the default; here we only pin that the
|
|
// shape no longer means "index".
|
|
let (code, stdout, stderr) = run("tests/occlusion/classic-index.mq.md", Some("occlusion"));
|
|
assert_eq!(code, 0, "stderr={stderr}");
|
|
assert_ne!(stdout.trim_end(), "值", "occlusion mode must not index");
|
|
}
|