feat(debug): dump v0.3 prose bits, inferred params, and dead binds

--dump-lines tags [decl]/[bold]/[italic]; --dump-ast prints `inferred` params
and `dead=[…]`. Migrate leftover italic-assign unit fixtures to bold/return.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
cflmyandCursor committed 2026-09-14 15:33:45 +08:00
1 parent 6994acb91d
commit 7554e45f60
12 files changed
+173 -58

No files matched your search

+1 -1
View File
@@ -308,7 +308,7 @@ mod tests {
use crate::interp::Interpreter;
use crate::parse::parse_source;
let src = "# main\n\n*`x` = 1*\n> print text=`x`\n*`x` = 2*\n> print text=`x`\n";
let src = "# main\n\n**x = 1**\n> print text=`x`\n**x = 2**\n> print text=`x`\n";
let module = parse_source(src).expect("parse");
// Line 4 is first `> print`
let ctrl = DebugController::new(HashSet::from([4u32]));
+80
View File
@@ -8,3 +8,83 @@ pub use ctrl::{
snapshot_json, DebugAction, DebugController, DebugPause, DebugSnapshot,
};
pub use trace::emit_trace;
use crate::lex::{ClassifiedLine, LineKind};
use crate::parse::{scan_prose_line, ProseBit};
/// Line dump with v0.3 prose bits (decl / bold / italic) on each line.
pub fn format_lines_dump_v03(path: &str, lines: &[ClassifiedLine]) -> String {
let mut out = String::new();
out.push_str(&format!("=== marqdo: lines ({path}) ===\n"));
for line in lines {
let preview = if line.text.len() > 80 {
format!("{}…", &line.text.chars().take(80).collect::<String>())
} else {
line.text.clone()
};
match line.kind {
LineKind::Blank => {
out.push_str(&format!("{:4} {:7}\n", line.line_no, line.kind));
}
_ => {
let tags = prose_tags(&preview);
if tags.is_empty() {
out.push_str(&format!(
"{:4} {:7} | {}\n",
line.line_no, line.kind, preview
));
} else {
out.push_str(&format!(
"{:4} {:7} | {} {}\n",
line.line_no, line.kind, preview, tags
));
}
}
}
}
out.push_str("=== marqdo: end lines ===\n");
out
}
fn prose_tags(text: &str) -> String {
let bits = scan_prose_line(text.trim_end_matches(['\r', '\n']));
if bits.is_empty() {
return String::new();
}
bits.iter()
.map(|b| match b {
ProseBit::Decl { name, default, .. } => match default {
Some(d) => format!("[decl {name}={d}]"),
None => format!("[decl {name}]"),
},
ProseBit::BoldCode { inner, .. } => format!("[bold {}]", compact(inner)),
ProseBit::ItalicReturn { inner, .. } => format!("[italic {}]", compact(inner)),
})
.collect::<Vec<_>>()
.join(" ")
}
fn compact(s: &str) -> String {
let t = s.trim();
if t.chars().count() <= 40 {
t.to_string()
} else {
format!("{}…", t.chars().take(40).collect::<String>())
}
}
#[cfg(test)]
mod tests {
use super::*;
use crate::lex::classify_source;
#[test]
fn dump_lines_tags_decl_bold_italic() {
let src = "对于输入变量`n`,我们执行操作**n=n+1**接着返回*n*。\n";
let lines = classify_source(src);
let dump = format_lines_dump_v03("t.mq.md", &lines);
assert!(dump.contains("[decl n]"), "{dump}");
assert!(dump.contains("[bold n=n+1]"), "{dump}");
assert!(dump.contains("[italic n]"), "{dump}");
}
}