From 401cf9e07e7f1b74965c9db24e5f0040523a6c03 Mon Sep 17 00:00:00 2001 From: Meta Vens Date: Fri, 20 Nov 2026 14:26:09 +0100 Subject: [PATCH] K1 fix-up: a line that is the head or tail of a quoted paragraph loses the one mark it holds (Soul K1 break; I16.2) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - `unmarked` strips each standalone quotation's opening mark when it lies in the run and its closing mark when it lies in the run, independently. Before, it stripped only a quotation wholly inside the run, so citing `"No.` + `Not yet.` posted `"No. Not yet.` and the tail case kept its closing mark. - `quotations` pairs marks through one table (`closers`): double marks pair across straight and curly (a straight opening closed by a curly mark, and back), `„` closes with either curly mark, guillemets `«…»`, and curly single `‘…’` whose closing mark is never an apostrophe inside a word (`don’t`). A straight single quote is not read as a mark: `'cause`, `'90s` and `the Minds' room` cannot be told from a quotation's marks by position, so it is left alone. - Framed quotations are unchanged: `"Dune" is the best book.` keeps its marks. The test helper `texts` now holds a line to paired marks with none wrapping the whole line, so a framed title at a line's start passes. - Tests: head, tail, one-sentence head and tail, and whole, for straight, curly, straight-open/curly-close, `„“`, `«»` and `‘’`; an apostrophe inside `‘…’`; a straight single quote left alone; framed titles at the start of a line. Co-Authored-By: Claude Opus 5.5 --- crates/mind-body/src/projection/interpret.rs | 45 ++++++++++++------- .../src/projection/interpret/tests.rs | 33 ++++++++++++-- 2 files changed, 60 insertions(+), 18 deletions(-) diff --git a/crates/mind-body/src/projection/interpret.rs b/crates/mind-body/src/projection/interpret.rs index c460ba6..3d638c4 100644 --- a/crates/mind-body/src/projection/interpret.rs +++ b/crates/mind-body/src/projection/interpret.rs @@ -107,21 +107,34 @@ struct Quotation { close: usize, } -/// Her quotations, paired in order: a straight double quote with the next one, a curly opening mark with the next curly -/// closing one. And the opening mark left unclosed, if one is (a budget cut her prose inside a quotation), with its -/// length. +/// The marks that close a quotation opened by `open`, or None when `open` opens none. Double marks pair across straight +/// and curly, since a model mixes them ("…” after a straight opening); `„` closes with either curly mark. A curly single +/// quotation `‘…’` counts, its closing mark only where it is not an apostrophe inside a word (`don’t`). A straight single +/// quote does not: `'cause`, `'90s` and `the Minds' room` cannot be told from a quotation's marks by position alone. +fn closers(open: char) -> Option<&'static [char]> { + match open { + '"' | '\u{201C}' => Some(&['"', '\u{201D}']), + '\u{201E}' => Some(&['\u{201C}', '\u{201D}', '"']), + '\u{2018}' => Some(&['\u{2019}']), + '\u{AB}' => Some(&['\u{BB}']), + _ => None, + } +} + +/// Her quotations, paired in order: each opening mark with the next mark that closes it (`closers`). And the opening mark +/// left unclosed, if one is (a budget cut her prose inside a quotation), with its length. fn quotations(prose: &str) -> (Vec, Option<(usize, usize)>) { let mut out = Vec::new(); - let mut open: Option<(usize, usize, char)> = None; - for (at, c) in prose.char_indices() { + let mut open: Option<(usize, usize, &[char])> = None; + let mut chars = prose.char_indices().peekable(); + while let Some((at, c)) = chars.next() { match open { - None if c == '"' => open = Some((at, c.len_utf8(), '"')), - None if c == '\u{201C}' => open = Some((at, c.len_utf8(), '\u{201D}')), - Some((mark, len, close)) if c == close => { + None => open = closers(c).map(|closes| (at, c.len_utf8(), closes)), + Some((mark, len, closes)) if closes.contains(&c) && !(c == '\u{2019}' && chars.peek().is_some_and(|(_, next)| next.is_alphanumeric())) => { out.push(Quotation { open: mark, inside: (mark + len, at), close: at + c.len_utf8() }); open = None; } - _ => {} + Some(_) => {} } } (out, open.map(|(mark, len, _)| (mark, len))) @@ -172,15 +185,17 @@ fn read(prose: &str) -> Reading { Reading { lists, standalone, framed } } -/// `prose[first..end]` without the marks of the standalone quotations inside it (I16.2): her marks say a paragraph is -/// speech, and the line is the speech. What lies between two quotations, a paragraph break, stays. +/// `prose[first..end]` without the marks of the standalone quotations it reaches (I16.2): her marks say a paragraph is +/// speech, and the line is the speech. Each mark goes on its own: an opening mark inside the run, and a closing mark +/// inside it, so a line that is the head or the tail of a quoted paragraph loses the one mark it holds. What lies between +/// two quotations, a paragraph break, stays. fn unmarked(prose: &str, first: usize, end: usize, standalone: &[Quotation]) -> String { + let marks = standalone.iter().flat_map(|quote| [(quote.open, quote.inside.0), (quote.inside.1, quote.close)]).filter(|(from, to)| first <= *from && *to <= end); let mut line = String::new(); let mut at = first; - for quote in standalone.iter().filter(|quote| first <= quote.open && quote.close <= end) { - line.push_str(&prose[at..quote.open]); - line.push_str(&prose[quote.inside.0..quote.inside.1]); - at = quote.close; + for (from, to) in marks { + line.push_str(&prose[at..from]); + at = to; } line.push_str(&prose[at..end]); line diff --git a/crates/mind-body/src/projection/interpret/tests.rs b/crates/mind-body/src/projection/interpret/tests.rs index 7a5171a..61f29ae 100644 --- a/crates/mind-body/src/projection/interpret/tests.rs +++ b/crates/mind-body/src/projection/interpret/tests.rs @@ -58,12 +58,15 @@ fn decided(prose: &str, say: serde_json::Value) -> Value { decided_in(&packet(), prose, say) } -/// The lines said. Every line any test here says is held to I16.2: no speech mark at either end. +/// The lines said. Every line any test here says is held to I16.2: no speech mark of hers is left in it. Its double marks +/// and guillemets pair up, and none is a quotation wrapping the whole line; a framed title at its start ("\"Dune\" is +/// the best book.") is hers and passes. fn texts(decision: &Value) -> Vec { let said: Vec = decision["said"].as_array().unwrap().iter().map(|line| line["text"].as_str().unwrap().to_owned()).collect(); for line in &said { - let marks = ['"', '\u{201C}', '\u{201D}']; - assert!(!line.starts_with(marks) && !line.ends_with(marks), "a posted line keeps a speech mark: {line:?}"); + let marks: Vec = line.char_indices().filter(|(_, c)| ['"', '\u{201C}', '\u{201D}', '\u{201E}', '\u{AB}', '\u{BB}'].contains(c)).map(|(at, _)| at).collect(); + let wraps = marks.first() == Some(&0) && marks.get(1).is_some_and(|close| line[*close..].chars().count() == 1); + assert!(marks.len().is_multiple_of(2) && !wraps, "a posted line keeps a speech mark: {line:?}"); } said } @@ -127,6 +130,30 @@ fn a_run_of_quoted_paragraphs_posts_each_inside_and_what_lies_between() { assert_eq!(says("\"Yes.\" Kiko's \"plan\" is a mess.", &["\"Yes.\"", "Kiko's \"plan\" is a mess."]).0, ["Yes. Kiko's \"plan\" is a mess."]); } +#[test] +fn soul_k1_the_head_or_tail_of_a_quoted_paragraph_loses_the_one_mark_it_holds() { + for (open, close) in [("\"", "\""), ("\u{201C}", "\u{201D}"), ("\"", "\u{201D}"), ("\u{201E}", "\u{201C}"), ("\u{AB}", "\u{BB}"), ("\u{2018}", "\u{2019}")] { + let prose = format!("{open}No. Not yet. Ask me tomorrow.{close} I wait."); + let pair = format!("{open} {close}"); + assert_eq!(says(&prose, &[&format!("{open}No."), "Not yet."]).0, ["No. Not yet."], "head, {pair}"); + assert_eq!(says(&prose, &["Not yet.", &format!("Ask me tomorrow.{close}")]).0, ["Not yet. Ask me tomorrow."], "tail, {pair}"); + assert_eq!(says(&prose, &[&format!("{open}No.")]).0, ["No."], "one-sentence head, {pair}"); + assert_eq!(says(&prose, &[&format!("Ask me tomorrow.{close}")]).0, ["Ask me tomorrow."], "one-sentence tail, {pair}"); + assert_eq!(says(&prose, &[&format!("{open}No. Not yet. Ask me tomorrow.{close}")]).0, ["No. Not yet. Ask me tomorrow."], "whole, {pair}"); + } + // An apostrophe inside a curly single quotation is not its closing mark. + assert_eq!(says("\u{2018}I don\u{2019}t know. Maybe.\u{2019} I shrug.", &["\u{2018}I don\u{2019}t know.", "Maybe.\u{2019}"]).0, ["I don\u{2019}t know. Maybe."]); + // A straight single quote is not read as a mark: an apostrophe cannot be told from it by position. + assert_eq!(says("'Fine.' I nod.", &["'Fine.'"]).0, ["'Fine.'"]); +} + +#[test] +fn soul_k1_a_framed_quotation_keeps_its_marks_even_at_the_start_of_the_line() { + assert_eq!(says("\"Dune\" is the best book. I said it.", &["\"Dune\" is the best book."]).0, ["\"Dune\" is the best book."]); + assert_eq!(says("\u{201C}Dune\u{201D} is the best book. I said it.", &["\u{201C}Dune\u{201D} is the best book."]).0, ["\u{201C}Dune\u{201D} is the best book."]); + assert_eq!(says("I like Kiko's \"plan\". Truly.", &["I like Kiko's \"plan\"."]).0, ["I like Kiko's \"plan\"."]); +} + /// Whether citing `spans` of `prose` says anything, and why not. fn says(prose: &str, spans: &[&str]) -> (Vec, String) { let decision = decided(prose, json!([{ "spans": spans }]));