From 6994acb91d5df3714767bffc0505a90d03ef4952 Mon Sep 17 00:00:00 2001 From: cflmy Date: Mon, 14 Sep 2026 15:25:26 +0800 Subject: [PATCH] fix(prose): mid-line italic emphasis is not a return MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Skip *very important* / *foo.bar* / *code-as-docs* so narrative emphasis cannot end a function; keep whole-line *n* and 返回*n*. Co-authored-by: Cursor --- doc/design/markdown-mapping-v0.3.md | 5 ++-- doc/roadmap/markup-v0.3.md | 5 +++- src/parse/prose.rs | 45 +++++++++++++++++----------- tests/markup-v03/soft-emphasis.mq.md | 3 +- 4 files changed, 36 insertions(+), 22 deletions(-) diff --git a/doc/design/markdown-mapping-v0.3.md b/doc/design/markdown-mapping-v0.3.md index d7690e1..99fafb3 100644 --- a/doc/design/markdown-mapping-v0.3.md +++ b/doc/design/markdown-mapping-v0.3.md @@ -9,7 +9,8 @@ | 路线 | [markup-v0.3.md](../roadmap/markup-v0.3.md) | | 相关 | [code-vs-comment.md](code-vs-comment.md) · [return-hr-and-code-surface.md](return-hr-and-code-surface.md) · [call-arguments.md](call-arguments.md) · [objects.md](objects.md) · [keywords.md](keywords.md) | -> **v0.3 为唯一 Markup 映射。** 不做 v0.2 双模式 / `--markup` 版本身份。摸索阶段允许破坏性变更;旧 `.mq.md`(`*语句*` / `**返回**`)须改写。金样例见 `tests/markup-v03/`。 +> **名词:** 本文「Markup」指 Marqdo **如何把 Markdown 标记映射成语法**(`**` 代码、`*` 返回、`` `名` `` 声明),不是另一个语言。产品仍是 Marqdo。 +> **v0.3 为唯一映射。** 不做 v0.2 双模式 / `--markup` 版本身份。摸索阶段允许破坏性变更;旧 `.mq.md`(`*语句*` / `**返回**`)须改写。金样例见 `tests/markup-v03/`。 --- @@ -568,7 +569,7 @@ FnDef.params: | 2 | 提及性反引号 | **已决议** | §4.4:一律视作变量;未使用不报错、不升参;不设提及前缀 | | 3 | 粗体内调用 vs 赋值 | **已落地** | §6.2:可赋值左值 → 赋值;否则表达式优先、再裸调用;`**n + 1**` = ExprStmt | | 4 | `` `n`+1 `` 误声明 | **已落地** | Decl 名须为标识符;`` `n+1` `` 不升 Decl | -| 5 | 叙述强调斜体 vs 返回 | 建议 | 函数体内合法返回表达式才当返回;否则当文字 | +| 5 | 叙述强调斜体 vs 返回 | **已落地** | 整行 / `返回*…*` / 表达式形才当返回;`*only*` `*very important*` `*foo.bar*` 为叙述 | | 6 | 一行多 `**…**` | **建议采纳** | 允许,按出现序执行(M0 钉死为是) | | 7 | view 展示 prose Decl | **已落地** | Structure / Functions 大纲:`inferred` 形参标注(`chip inferred`) | diff --git a/doc/roadmap/markup-v0.3.md b/doc/roadmap/markup-v0.3.md index 0f58bec..b2badd5 100644 --- a/doc/roadmap/markup-v0.3.md +++ b/doc/roadmap/markup-v0.3.md @@ -1,4 +1,6 @@ -# 路线图:Markup 映射 v0.3(叙述统一) +# 路线图:Marqdo Markdown 语法映射 v0.3(叙述统一) + +「Markup」= Marqdo 把 Markdown 标记当成语法的那一层(不是另一个产品)。v0.3 = 现行映射:粗体代码、斜体返回。 | | | |---|---| @@ -56,6 +58,7 @@ - [x] 诊断:必选缺失、未知 callee(已有 errors 金样);死变量不报错 - [x] 残缺粗体:与 GAP-06/07「未闭合后恢复」冲突,保持 Comment 跳过恢复,不硬报错 - [x] 粗体内表达式语句:`**n + 1**` 求值后丢弃(非误判为调用) +- [x] 叙述斜体:仅整行 / `返回*…*` / 表达式形当返回(`*very important*` 不收束函数) **出门:** `tests/markup-v03/*` 覆盖设计 §9 示例。 diff --git a/src/parse/prose.rs b/src/parse/prose.rs index a1e4cc0..9684fd9 100644 --- a/src/parse/prose.rs +++ b/src/parse/prose.rs @@ -80,6 +80,9 @@ pub fn scan_prose_line(line: &str) -> Vec { } /// Whether `*inner*` is a return (vs mid-prose English/CJK emphasis). +/// +/// Design §12 #5: mid-line italic is return only for whole-line, `返回*…*`, +/// or an expression-shaped span — not `*very important*` / `*foo.bar*`. fn looks_like_italic_return(line: &str, at: usize, after: usize, inner: &str) -> bool { let t = inner.trim(); if t.is_empty() @@ -90,14 +93,7 @@ fn looks_like_italic_return(line: &str, at: usize, after: usize, inner: &str) -> { return true; } - if t.starts_with('>') - || t.contains('=') - || t.chars() - .any(|c| matches!(c, '+' | '-' | '*' | '/' | '(' | ')' | '[' | ']')) - { - return true; - } - // Whole-line return: only ws outside the italic span. + // Whole-line return: only ws outside the italic span (`*n*` / `*总额*`). let before = line[..at].trim(); let after_s = line.get(after..).unwrap_or("").trim(); if before.is_empty() && after_s.is_empty() { @@ -107,20 +103,22 @@ fn looks_like_italic_return(line: &str, at: usize, after: usize, inner: &str) -> if before.ends_with("返回") || before.ends_with("return") || before.ends_with("Return") { return true; } - // Mid-prose simple word → soft emphasis (G2). - if is_simple_emphasis_word(t) { + // Mid-prose: expression-shaped only (`*n + 1*` / `*x=1*`); not hyphenated emphasis. + if is_hyphenated_emphasis(t) { return false; } - // Multi-token or dotted id mid-line: keep as return (rare). - true + t.starts_with('>') + || t.contains('=') + || t.chars() + .any(|c| matches!(c, '+' | '-' | '*' | '/' | '(' | ')' | '[' | ']')) } -fn is_simple_emphasis_word(t: &str) -> bool { - if t.chars().any(|c| c.is_whitespace()) { - return false; - } - t.chars() - .all(|c| c.is_alphanumeric() || c == '_' || !c.is_ascii()) +fn is_hyphenated_emphasis(t: &str) -> bool { + !t.chars().any(char::is_whitespace) + && t.contains('-') + && !t + .chars() + .any(|c| matches!(c, '+' | '*' | '/' | '(' | ')' | '[' | ']' | '=')) } fn scan_backtick_decl(line: &str, start: usize) -> Option<(ProseBit, usize)> { @@ -225,11 +223,22 @@ mod tests { fn soft_italic_emphasis_skipped() { let bits = scan_prose_line("When soft=True, *only* FIND continues."); assert!(bits.is_empty(), "{bits:?}"); + let bits = scan_prose_line("This is *very important* documentation."); + assert!(bits.is_empty(), "multi-word italic is emphasis: {bits:?}"); + let bits = scan_prose_line("See *foo.bar* in the text."); + assert!(bits.is_empty(), "dotted italic is emphasis: {bits:?}"); + let bits = scan_prose_line("Use *code-as-docs* style."); + assert!(bits.is_empty(), "hyphenated italic is emphasis: {bits:?}"); let bits = scan_prose_line("*总额*"); assert!( matches!(&bits[..], [ProseBit::ItalicReturn { inner, .. }] if inner == "总额"), "{bits:?}" ); + let bits = scan_prose_line("接着返回*n*。"); + assert!( + matches!(&bits[..], [ProseBit::ItalicReturn { inner, .. }] if inner == "n"), + "{bits:?}" + ); } #[test] diff --git a/tests/markup-v03/soft-emphasis.mq.md b/tests/markup-v03/soft-emphasis.mq.md index 7405d3b..a4516d9 100644 --- a/tests/markup-v03/soft-emphasis.mq.md +++ b/tests/markup-v03/soft-emphasis.mq.md @@ -1,12 +1,13 @@ --- title: G2 叙述强调不执行 -description: 句中 **说明** / *only* 为装饰;像代码的粗体与整行斜体仍执行 +description: 句中 **说明** / *only* / *very important* 为装饰;像代码的粗体与整行斜体仍执行 markup: v0.3 --- # main 本段既是**说明**也是**程序**;英文里也有 *only* 这类强调词。 +This is *very important* documentation, see *foo.bar* and *code-as-docs*. **n = 1** **n = n + 1**