fix(lex): glued ` name=default …prose ` is Decl, not assign

Trailing text after a glued default (same terminators as prose Decl) keeps the line narrative so `` `礼貌`=False 时… `` no longer binds a mangled text value.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
cflmyandCursor committed 2026-09-14 14:31:12 +08:00
1 parent 8846f5f070
commit 95a49697f7
2 files changed
+40 -4

No files matched your search

+35 -3
View File
@@ -44,7 +44,11 @@ fn is_code_starter(c: char) -> bool {
}
/// Whole-line backtick bind `` `name` = … `` (empty RHS / fence / table OK).
/// Narrative decls like `` `捕获=True` 时… `` or `` `n`,我们… `` are **not** binds.
///
/// Narrative decls are **not** binds:
/// - `` `捕获=True` 时… `` (`=` inside ticks)
/// - `` `n`,我们… `` (no `=` after ticks)
/// - `` `礼貌`=False 时… `` (glued default + trailing prose; same shape as prose Decl)
fn looks_like_backtick_assign(trimmed: &str) -> bool {
let t = trimmed.trim();
if !t.starts_with('`') {
@@ -58,8 +62,26 @@ fn looks_like_backtick_assign(trimmed: &str) -> bool {
if name.is_empty() || name.chars().any(|c| c.is_whitespace()) {
return false;
}
let after = rest[end + 1..].trim_start();
after.starts_with('=')
let after_tick = &rest[end + 1..];
let after = after_tick.trim_start();
if !after.starts_with('=') {
return false;
}
// Glued `` `name`=default …prose `` → Decl, not assign (prose.rs default terminator).
let glued = after_tick.starts_with('=');
if glued {
let stripped = &after[1..];
let def_end = stripped
.find(|c: char| {
c.is_whitespace()
|| matches!(c, ',' | '。' | ';' | '、' | ',' | ';' | '*' | '`')
})
.unwrap_or(stripped.len());
if !stripped[def_end..].trim_start().is_empty() {
return false;
}
}
true
}
/// `*` / `**` lines that are Marqdo executable (statement / return / else), not narrative Markdown.
@@ -401,6 +423,16 @@ mod tests {
"leading decl in narrative"
);
assert_eq!(classify_line("`礼貌`=False"), LineKind::Code);
assert_eq!(
classify_line("`礼貌`=False 时用短称呼。"),
LineKind::Comment,
"glued default + trailing prose is Decl"
);
assert_eq!(
classify_line("`礼貌` = False"),
LineKind::Code,
"spaced = is backtick assign"
);
}
#[test]
+5 -1
View File
@@ -1,12 +1,16 @@
---
title: leading backtick decl is narrative
description: `` `名`… `` / `` `捕获=True` 时… `` are Decl prose, not statements
description: >-
`` `名`… `` / `` `捕获=True` 时… `` / `` `礼貌`=False 时… `` are Decl prose,
not backtick assigns
---
# main
`捕获=True` 时返回映射 `{code, stdout, stderr}`。
`礼貌`=False 时用短称呼。
向`谁`问好。
> print text=ok