From 14016ef7c94a2055b9700fef495b784d5da58bd0 Mon Sep 17 00:00:00 2001 From: ruchirguitar Date: Sun, 29 Nov 2026 00:25:25 +0530 Subject: [PATCH 1/7] proof: hyphenate Bengali, Assamese, Punjabi, Odia, Tamil, Telugu, Kannada and Malayalam between aksharas Script tables for Bengali, Gurmukhi, Odia, Tamil, Telugu, Kannada and Malayalam on the shared Brahmic layout, each listing only where it differs. Dead consonants written as letters of their own (khanda ta, chillus, nakaara pollu) end the syllable before. Tamil, which joins no conjuncts, breaks after the pulli; KSSA stays whole. Script::of maps the pack languages bn, as, pa (Gurmukhi only), or, ta, te, kn and ml. Part of storytold/vectorcraft#4947. --- crates/proof/README.md | 2 +- crates/proof/src/hyphen.rs | 15 ++- crates/proof/src/hyphen/tests.rs | 21 +++ crates/proof/src/indic.rs | 224 +++++++++++++++++++++++++------ 4 files changed, 216 insertions(+), 46 deletions(-) diff --git a/crates/proof/README.md b/crates/proof/README.md index b838a66211..1a31426ab8 100644 --- a/crates/proof/README.md +++ b/crates/proof/README.md @@ -20,7 +20,7 @@ craft-proof = { git = "https://github.com/storytold/craft-libs", rev = " | German | — | — | TeX patterns (embedded, or a Language pack) | | Bulgarian | — | — | syllable rules | | Gujarati, Hindi | the installed Hunspell dictionary (Hindi: nukta letters spelled either way) | generic checks | akshara rules (or a Language pack) | -| Marathi (mr) | its Language pack or Hunspell dictionary, as any pack language | — | akshara rules (or a Language pack) | +| Marathi (mr), Bengali (bn), Assamese (as), Punjabi in Gurmukhi (pa), Odia (or), Tamil (ta), Telugu (te), Kannada (kn), Malayalam (ml) | its Language pack or Hunspell dictionary, as any pack language | — | akshara rules (or a Language pack) | Grammar rules, suggestion tuning and the rule-based hyphenation are code: they work in every build. diff --git a/crates/proof/src/hyphen.rs b/crates/proof/src/hyphen.rs index f8569a194c..ac4d5f76ee 100644 --- a/crates/proof/src/hyphen.rs +++ b/crates/proof/src/hyphen.rs @@ -15,9 +15,10 @@ //! //! **Bulgarian**: the Bulgarian syllable rules ([`crate::bg`]); no pattern file or word list. //! -//! **Gujarati, Hindi and Marathi**: breaks between aksharas, never inside a conjunct or between a -//! consonant and its vowel sign ([`crate::indic`], rules from the script's Unicode encoding); no -//! pattern file. +//! **Indic languages** (Gujarati, Hindi, Marathi, Bengali, Assamese, Punjabi, Odia, Tamil, Telugu, +//! Kannada, Malayalam): breaks between aksharas, never inside a conjunct or between a consonant +//! and its vowel sign ([`crate::indic`], rules from the script's Unicode encoding); no pattern +//! file. //! //! **German**: the TeX German patterns for the reformed spelling ([`Patterns::de`]), also for //! Swiss text, whose `ss` the patterns split like any double consonant (`Stras-se`). @@ -120,7 +121,7 @@ pub enum Source { Patterns, /// A heuristic for a language without a dictionary or patterns. Heuristic, - /// A language's syllable rules (Bulgarian [`crate::bg`], Turkish, Gujarati, Hindi and Marathi [`crate::indic`]). + /// A language's syllable rules (Bulgarian [`crate::bg`], Turkish, the Indic languages [`crate::indic`]). Rules, /// No break points: the word is too short or no source applies. None, @@ -167,7 +168,7 @@ fn core_breaks(core: &[char], lang: ProofLang) -> (Vec, Source) { if lang == ProofLang::Bg && core.iter().all(|&c| crate::bg::is_letter(c)) { return (crate::bg::points(core), Source::Rules); } - // Gujarati, Hindi and Marathi words break between aksharas ([`crate::indic`]); other words in their runs + // Words of the Indic languages break between aksharas ([`crate::indic`]); other words in their runs // (`WordCraft`) are hyphenated as English. if let Some(script) = crate::indic::Script::of(lang) && core.iter().all(|&c| script.is_letter(c)) @@ -242,8 +243,8 @@ fn composed_chars(core: &[char]) -> (Vec, Vec>) { (nfc, starts) } -/// Does a pack's `pats` hyphenate `core` in `lang`? Russian, Bulgarian, Turkish, Gujarati, Hindi -/// and Marathi: a word in their script (the guard their rules use; for the Indic ones, the script's +/// Does a pack's `pats` hyphenate `core` in `lang`? Russian, Bulgarian, Turkish and the Indic +/// languages: a word in their script (the guard their rules use; for the Indic ones, the script's /// letters and marks and the joiners inside a conjunct, [`crate::indic`]) whose letters the /// patterns know, so a word with a letter the pack never mentions goes on to the fallback rules. Polish, Portuguese, Italian /// and German: every word, as their embedded patterns do. Any other language: a word whose letters diff --git a/crates/proof/src/hyphen/tests.rs b/crates/proof/src/hyphen/tests.rs index 124c265c45..994fcda21f 100644 --- a/crates/proof/src/hyphen/tests.rs +++ b/crates/proof/src/hyphen/tests.rs @@ -244,3 +244,24 @@ fn marathi_breaks_between_aksharas() { assert_eq!(hyphenate_word_in("महाराष्ट्र", &Limits::default(), mr), "महा-रा-ष्ट्र"); assert_eq!(word_breaks_in("महाराष्ट्र", mr).1, Source::Rules); } + +/// storytold/vectorcraft#4947: the other Indic pack languages break between aksharas within the +/// paragraph's limits, where they used to fall to the English rules and get no break at all. +#[test] +fn indic_pack_languages_break_between_aksharas() { + let cases = [ + ("bn-IN", "বিদ্যাল\u{09AF}\u{09BC}", "বি-দ্যা-ল\u{09AF}\u{09BC}"), + ("as", "অসমী\u{09AF}\u{09BC}া", "অস-মী-\u{09AF}\u{09BC}া"), + ("pa", "ਗੁਰਮੁਖੀ", "ਗੁ-ਰ-ਮੁ-ਖੀ"), + ("or", "ବିଦ୍ୟାଳୟ", "ବି-ଦ୍ୟା-ଳୟ"), + ("ta-IN", "தமிழ்நாடு", "தமிழ்-நா-டு"), + ("te", "తెలుగు", "తె-లు-గు"), + ("kn", "ಕನ್ನಡಿಗ", "ಕನ್ನ-ಡಿಗ"), + ("ml", "മലയാളം", "മല-യാ-ളം"), + ]; + for (tag, word, want) in cases { + let lang = ProofLang::from_tag(Some(tag)); + assert_eq!(hyphenate_word_in(word, &Limits::default(), lang), want, "{tag}"); + assert_eq!(word_breaks_in(word, lang).1, Source::Rules, "{tag}"); + } +} diff --git a/crates/proof/src/indic.rs b/crates/proof/src/indic.rs index 313e9c38bd..0dbc1a9897 100644 --- a/crates/proof/src/indic.rs +++ b/crates/proof/src/indic.rs @@ -14,9 +14,18 @@ //! The rules come from the scripts' Unicode encoding alone; no pattern file or word list is //! read (and none is borrowed). The Brahmic blocks share one layout (the ISCII order), so a //! script is its block's start and a few script-specific code points (`Script::kind`). -//! Gujarati ([`ProofLang::Gu`]), Hindi ([`ProofLang::Hi`]) and Marathi (the pack language `mr`) -//! use them, Hindi and Marathi with [`Script::Devanagari`]; -//! another language written in one of these scripts is one more line in [`Script::of`]. +//! Gujarati ([`ProofLang::Gu`]) and Hindi ([`ProofLang::Hi`]) use them, and so do these pack +//! languages: Marathi (`mr`), Bengali (`bn`) and Assamese (`as`), Punjabi in Gurmukhi (`pa`), +//! Odia (`or`), Tamil (`ta`), Telugu (`te`), Kannada (`kn`) and Malayalam (`ml`). Another +//! language written in one of these scripts is one more line in [`Script::of`]. +//! +//! A dead consonant written as a letter of its own — Bengali's khanda ta (`ৎ`), Malayalam's chillus +//! (`ൻ`, `ർ`), Telugu's and Kannada's nakaara pollu — ends the syllable before, as a mark does: +//! `উৎ-সব`, `കർ-മ്മം`. Gurmukhi's addak (`ੱ`) and tippi (`ੰ`) are marks too: `ਪੱ-ਕਾ`. +//! +//! **Tamil** joins no conjuncts: a consonant with a visible virama (pulli) closes the syllable +//! before it, so the break goes after the pulli, not before the consonant (`பக்-கம்`, `தமிழ்-நா-டு`). +//! The one conjunct, KSSA (`க்ஷ`), stays whole. //! //! A single akshara left at the end or start of a line is ruled out by the paragraph's //! [`Limits`](crate::hyphen::Limits), which count letters (vowel signs and anusvara count, @@ -30,8 +39,22 @@ use crate::ProofLang; pub enum Script { /// Devanagari (U+0900..=U+097F): Hindi, Marathi, Nepali… Devanagari, + /// Bengali (U+0980..=U+09FF): Bengali, Assamese. + Bengali, + /// Gurmukhi (U+0A00..=U+0A7F): Punjabi. + Gurmukhi, /// Gujarati (U+0A80..=U+0AFF). Gujarati, + /// Odia (U+0B00..=U+0B7F). + Odia, + /// Tamil (U+0B80..=U+0BFF). + Tamil, + /// Telugu (U+0C00..=U+0C7F). + Telugu, + /// Kannada (U+0C80..=U+0CFF). + Kannada, + /// Malayalam (U+0D00..=U+0D7F). + Malayalam, } /// What a code point is in an akshara. @@ -62,9 +85,20 @@ impl Script { match lang { ProofLang::Gu => Some(Script::Gujarati), ProofLang::Hi => Some(Script::Devanagari), - // Marathi has no proofing language of its own: `mr`, `mr-IN` and `mar` are pack - // languages, spelled from their pack or Hunspell dictionary. - ProofLang::Pack(l) if matches!(l.primary(), "mr" | "mar") => Some(Script::Devanagari), + // The others have no proofing language of their own: their tags (`mr`, `mr-IN`, + // `mar`…) are pack languages, spelled from their pack or Hunspell dictionary. + ProofLang::Pack(l) => match l.primary() { + "mr" | "mar" => Some(Script::Devanagari), + "bn" | "ben" | "as" | "asm" => Some(Script::Bengali), + // Punjabi in Gurmukhi, its default script; Shahmukhi (`pa-Arab`) is not Brahmic. + "pa" | "pan" if crate::lang::effective_script(l.as_str()).is_none_or(|s| s == "guru") => Some(Script::Gurmukhi), + "or" | "ori" | "ory" => Some(Script::Odia), + "ta" | "tam" => Some(Script::Tamil), + "te" | "tel" => Some(Script::Telugu), + "kn" | "kan" => Some(Script::Kannada), + "ml" | "mal" => Some(Script::Malayalam), + _ => None, + }, _ => None, } } @@ -73,7 +107,14 @@ impl Script { fn base(self) -> u32 { match self { Script::Devanagari => 0x0900, + Script::Bengali => 0x0980, + Script::Gurmukhi => 0x0A00, Script::Gujarati => 0x0A80, + Script::Odia => 0x0B00, + Script::Tamil => 0x0B80, + Script::Telugu => 0x0C00, + Script::Kannada => 0x0C80, + Script::Malayalam => 0x0D00, } } @@ -84,29 +125,57 @@ impl Script { return Some(Kind::Joiner); } let o = u32::from(c).checked_sub(self.base()).filter(|&o| o < 0x80)?; - let dev = self == Script::Devanagari; - Some(match o { - // Candrabindu, anusvara, visarga (and Devanagari's inverted candrabindu). - 0x00..=0x03 => Kind::Mark, - 0x04..=0x14 => Kind::Vowel, - 0x15..=0x39 => Kind::Consonant, - // Devanagari's vowel signs OE and OOE, the nukta, the avagraha, the vowel signs. - 0x3A..=0x4C => Kind::Mark, - 0x4D => Kind::Virama, - // Devanagari's vowel signs PRISHTHAMATRA E and AW, stress signs and vowel signs. - 0x4E..=0x4F | 0x51..=0x57 if dev => Kind::Mark, - // Devanagari's consonants with nukta (`क़`, `ज़`, `फ़`…). - 0x58..=0x5F if dev => Kind::Consonant, - // Vocalic RR and LL. - 0x60..=0x61 => Kind::Vowel, - 0x62..=0x63 => Kind::Mark, - // Devanagari's vowels for Marathi, Kashmiri and Bihari languages, and consonants for - // Sindhi, Marwari and others. - 0x72..=0x77 if dev => Kind::Vowel, - 0x78..=0x7F if dev => Kind::Consonant, - // Gujarati ZHA, and the nuktas and signs for transliterating Arabic. - 0x79 => Kind::Consonant, - 0x7A..=0x7F => Kind::Mark, + self.own_kind(o).or(match o { + // Candrabindu, anusvara, visarga; the nukta, the avagraha and the vowel signs; vocalic + // L and LL vowel signs. + 0x00..=0x03 | 0x3A..=0x4C | 0x62..=0x63 => Some(Kind::Mark), + // The independent vowels, vocalic RR and LL among them. + 0x05..=0x14 | 0x60..=0x61 => Some(Kind::Vowel), + 0x15..=0x39 => Some(Kind::Consonant), + 0x4D => Some(Kind::Virama), + _ => None, + }) + } + + /// What the code point at offset `o` in the block is in this script where the scripts differ + /// from their shared layout; `None` where they don't. + fn own_kind(self, o: u32) -> Option { + use Script::{Bengali, Devanagari, Gujarati, Gurmukhi, Kannada, Malayalam, Odia, Tamil, Telugu}; + Some(match (self, o) { + // Short A, the vowels for Marathi, Kashmiri and Bihari languages; consonants with + // nukta (`क़`, `ज़`) and for Sindhi, Marwari and others; vowel signs PRISHTHAMATRA E + // and AW, stress signs and more vowel signs. + (Devanagari, 0x04 | 0x72..=0x77) => Kind::Vowel, + (Devanagari, 0x58..=0x5F | 0x78..=0x7F) => Kind::Consonant, + (Devanagari, 0x4E..=0x4F | 0x51..=0x57) => Kind::Mark, + // Khanda ta (a dead consonant), the AU length mark, the Vedic anusvara, the sandhi + // mark; RRA, RHA, YYA, and Assamese RA and WA (`ৰ`, `ৱ`). + (Bengali, 0x4E | 0x57 | 0x7C | 0x7E) => Kind::Mark, + (Bengali, 0x5C..=0x5D | 0x5F | 0x70..=0x71) => Kind::Consonant, + // Udaat, tippi, addak, yakash; consonants with nukta; the vowel bearers IRI and URA. + (Gurmukhi, 0x51 | 0x70..=0x71 | 0x75) => Kind::Mark, + (Gurmukhi, 0x59..=0x5E) => Kind::Consonant, + (Gurmukhi, 0x72..=0x73) => Kind::Vowel, + // ZHA, and the nuktas and signs for transliterating Arabic. + (Gujarati, 0x79) => Kind::Consonant, + (Gujarati, 0x7A..=0x7F) => Kind::Mark, + // Length marks; RRA, RHA, YYA, WA. + (Odia, 0x55..=0x57) => Kind::Mark, + (Odia, 0x5C..=0x5D | 0x5F | 0x71) => Kind::Consonant, + (Tamil, 0x57) => Kind::Mark, + // Combining anusvara above, length marks, nakaara pollu (a dead consonant); the + // archaic consonants. + (Telugu, 0x04 | 0x55..=0x56 | 0x5D) => Kind::Mark, + (Telugu, 0x58..=0x5A) => Kind::Consonant, + // Length marks, nakaara pollu, jihvamuliya, upadhmaniya, the anusvara above right; FA. + (Kannada, 0x55..=0x56 | 0x5D | 0x71..=0x73) => Kind::Mark, + (Kannada, 0x5E) => Kind::Consonant, + // The Vedic anusvara, the chillus (dead consonants), the AU length mark; TTTA; the + // vertical-bar and circular viramas and the dot reph, which join like a virama; II. + (Malayalam, 0x04 | 0x54..=0x57 | 0x7A..=0x7F) => Kind::Mark, + (Malayalam, 0x3A) => Kind::Consonant, + (Malayalam, 0x3B..=0x3C | 0x4E) => Kind::Virama, + (Malayalam, 0x5F) => Kind::Vowel, _ => return None, }) } @@ -119,8 +188,8 @@ impl Script { } /// Break points of one `word` in `script` (char indices; a hyphen goes before that char): before -/// each akshara but the first, except a dead consonant. Empty for anything that is not entirely -/// the script's letters and marks. +/// each akshara but the first, except a dead consonant (in Tamil, after each pulli instead). +/// Empty for anything that is not entirely the script's letters and marks. pub fn points(script: Script, word: &[char]) -> Vec { let Some(kinds) = word.iter().map(|&c| script.kind(c)).collect::>>() else { return Vec::new(); @@ -150,9 +219,21 @@ pub fn points(script: Script, word: &[char]) -> Vec { } } }; - (1..word.len()) - .filter(|&i| matches!(at(i), Some(Kind::Vowel | Kind::Consonant)) && !matches!(at(i - 1), Some(Kind::Virama | Kind::Joiner)) && live(i)) - .collect() + let starts = |i: usize| match script { + Script::Tamil => tamil_starts(word, &kinds, i), + _ => at(i - 1) != Some(Kind::Virama) && live(i), + }; + (1..word.len()).filter(|&i| matches!(at(i), Some(Kind::Vowel | Kind::Consonant)) && at(i - 1) != Some(Kind::Joiner) && starts(i)).collect() +} + +/// Does a syllable start at `i`, a consonant or vowel, in a Tamil word? Not at a consonant with a +/// pulli, which closes the syllable before (`பக்-கம்`), nor inside KSSA (`க்ஷ`), one akshara. +fn tamil_starts(word: &[char], kinds: &[Kind], i: usize) -> bool { + const KA: char = '\u{0B95}'; + const SSA: char = '\u{0BB7}'; + let kssa = |k: usize| word.get(k) == Some(&KA) && kinds.get(k + 1) == Some(&Kind::Virama) && word.get(k + 2) == Some(&SSA); + let closes = kinds.get(i + 1) == Some(&Kind::Virama) && !kssa(i); + !closes && !(i >= 2 && kssa(i - 2)) } #[cfg(test)] @@ -247,15 +328,82 @@ mod tests { assert_eq!(hi("क्\u{200D}षमा"), "क्\u{200D}ष-मा"); } - /// Gujarati, Hindi and Marathi (a pack language, by any of its tags) are mapped to their - /// scripts, other languages (another pack language among them) to none. + /// Bengali and Assamese: conjuncts stay whole; khanda ta ends the syllable before; Assamese RA. + #[test] + fn bengali_script_breaks_between_aksharas() { + let bn = |w: &str| split(Script::Bengali, w); + assert_eq!(bn("বাংলা"), "বাং-লা"); + assert_eq!(bn("বিদ্যাল\u{09AF}\u{09BC}"), "বি-দ্যা-ল-\u{09AF}\u{09BC}", "YA with nukta"); + assert_eq!(bn("বিদ্যাল\u{09DF}"), "বি-দ্যা-ল-\u{09DF}", "precomposed YYA"); + assert_eq!(bn("উৎসব"), "উৎ-স-ব"); + assert_eq!(bn("ৰাজ্য"), "ৰা-জ্য"); + } + + /// Gurmukhi: tippi and addak stay with the akshara before them. + #[test] + fn gurmukhi_breaks_between_aksharas() { + let pa = |w: &str| split(Script::Gurmukhi, w); + assert_eq!(pa("ਪੰਜਾਬੀ"), "ਪੰ-ਜਾ-ਬੀ"); + assert_eq!(pa("ਪੱਕਾ"), "ਪੱ-ਕਾ"); + assert_eq!(pa("ਗੁਰਮੁਖੀ"), "ਗੁ-ਰ-ਮੁ-ਖੀ"); + } + + /// Odia, Telugu and Kannada: the shared rules, conjuncts whole, nukta and anusvara attached. + #[test] + fn odia_telugu_and_kannada_break_between_aksharas() { + let or = |w: &str| split(Script::Odia, w); + assert_eq!(or("\u{0B13}\u{0B21}\u{0B3C}\u{0B3F}\u{0B06}"), "\u{0B13}-\u{0B21}\u{0B3C}\u{0B3F}-\u{0B06}"); + assert_eq!(or("ବିଦ୍ୟାଳୟ"), "ବି-ଦ୍ୟା-ଳ-ୟ"); + let te = |w: &str| split(Script::Telugu, w); + assert_eq!(te("తెలుగు"), "తె-లు-గు"); + assert_eq!(te("విద్యార్థి"), "వి-ద్యా-ర్థి"); + let kn = |w: &str| split(Script::Kannada, w); + assert_eq!(kn("ಕನ್ನಡ"), "ಕ-ನ್ನ-ಡ"); + assert_eq!(kn("ಸಂಸ್ಕೃತ"), "ಸಂ-ಸ್ಕೃ-ತ"); + } + + /// Malayalam: conjuncts whole; a chillu ends the syllable before. + #[test] + fn malayalam_breaks_between_aksharas() { + let ml = |w: &str| split(Script::Malayalam, w); + assert_eq!(ml("മലയാളം"), "മ-ല-യാ-ളം"); + assert_eq!(ml("അവൻ"), "അ-വൻ"); + assert_eq!(ml("കർമ്മം"), "കർ-മ്മം"); + } + + /// Tamil: the break goes after a pulli, never before a consonant that carries one; KSSA is + /// one akshara. + #[test] + fn tamil_breaks_after_the_pulli() { + let ta = |w: &str| split(Script::Tamil, w); + assert_eq!(ta("தமிழ்"), "த-மிழ்"); + assert_eq!(ta("பக்கம்"), "பக்-கம்"); + assert_eq!(ta("தமிழ்நாடு"), "த-மிழ்-நா-டு"); + assert_eq!(ta("அக்ஷரம்"), "அ-க்ஷ-ரம்"); + } + + /// Gujarati, Hindi and the pack languages written in these scripts (by any of their tags) are + /// mapped to their scripts, other languages (another pack language among them) to none. #[test] fn languages_map_to_their_script() { assert_eq!(Script::of(ProofLang::Gu), Some(Script::Gujarati)); assert_eq!(Script::of(ProofLang::Hi), Some(Script::Devanagari)); - for tag in ["mr", "mr-IN", "mar"] { - assert_eq!(Script::of(ProofLang::from_tag(Some(tag))), Some(Script::Devanagari), "{tag}"); + let packs = [ + (Script::Devanagari, &["mr", "mr-IN", "mar"][..]), + (Script::Bengali, &["bn", "bn-BD", "ben", "as", "as-IN", "asm"]), + (Script::Gurmukhi, &["pa", "pa-IN", "pa-Guru", "pan"]), + (Script::Odia, &["or", "or-IN", "ori", "ory"]), + (Script::Tamil, &["ta", "ta-LK", "tam"]), + (Script::Telugu, &["te", "tel"]), + (Script::Kannada, &["kn", "kan"]), + (Script::Malayalam, &["ml", "mal"]), + ]; + for (script, tags) in packs { + for tag in tags { + assert_eq!(Script::of(ProofLang::from_tag(Some(tag))), Some(script), "{tag}"); + } } + assert_eq!(Script::of(ProofLang::from_tag(Some("pa-Arab"))), None, "Shahmukhi"); assert_eq!(Script::of(ProofLang::from_tag(Some("ne"))), None); assert_eq!(Script::of(ProofLang::En), None); assert_eq!(Script::of(ProofLang::Bg), None); From c9f53a3f7eacedc96f7c9826fa149fed1b094bca Mon Sep 17 00:00:00 2001 From: ruchirguitar Date: Sun, 29 Nov 2026 00:29:55 +0530 Subject: [PATCH 2/7] proof: Malayalam chillus written with a joiner, Tamil SHRII and a dead KSSA A Malayalam consonant, virama and ZWJ is a chillu and ends the syllable before, as a chillu letter does. Tamil keeps SHRII (with SA or SHA) whole, and a KSSA with a pulli closes the syllable before. Found by a local CodeRabbit review. --- crates/proof/src/indic.rs | 46 +++++++++++++++++++++++++++++---------- 1 file changed, 35 insertions(+), 11 deletions(-) diff --git a/crates/proof/src/indic.rs b/crates/proof/src/indic.rs index 0dbc1a9897..005b5ab97f 100644 --- a/crates/proof/src/indic.rs +++ b/crates/proof/src/indic.rs @@ -21,11 +21,12 @@ //! //! A dead consonant written as a letter of its own — Bengali's khanda ta (`ৎ`), Malayalam's chillus //! (`ൻ`, `ർ`), Telugu's and Kannada's nakaara pollu — ends the syllable before, as a mark does: -//! `উৎ-সব`, `കർ-മ്മം`. Gurmukhi's addak (`ੱ`) and tippi (`ੰ`) are marks too: `ਪੱ-ਕਾ`. +//! `উৎ-সব`, `കർ-മ്മം`. So does a chillu written the older way, as a consonant, the virama and a +//! zero-width joiner (`ന്` U+200D): the one place a break follows a joiner. Gurmukhi's addak (`ੱ`) and tippi (`ੰ`) are marks too: `ਪੱ-ਕਾ`. //! //! **Tamil** joins no conjuncts: a consonant with a visible virama (pulli) closes the syllable //! before it, so the break goes after the pulli, not before the consonant (`பக்-கம்`, `தமிழ்-நா-டு`). -//! The one conjunct, KSSA (`க்ஷ`), stays whole. +//! Its two conjuncts, KSSA (`க்ஷ`) and SHRII (`ஸ்ரீ`), stay whole. //! //! A single akshara left at the end or start of a line is ruled out by the paragraph's //! [`Limits`](crate::hyphen::Limits), which count letters (vowel signs and anusvara count, @@ -219,21 +220,37 @@ pub fn points(script: Script, word: &[char]) -> Vec { } } }; + let chillu = |k: usize| script == Script::Malayalam && legacy_chillu(word, &kinds, k); let starts = |i: usize| match script { - Script::Tamil => tamil_starts(word, &kinds, i), - _ => at(i - 1) != Some(Kind::Virama) && live(i), + Script::Tamil => at(i - 1) != Some(Kind::Joiner) && tamil_starts(word, &kinds, i), + _ if chillu(i) => false, + _ => (i >= 3 && chillu(i - 3)) || (!matches!(at(i - 1), Some(Kind::Virama | Kind::Joiner)) && live(i)), }; - (1..word.len()).filter(|&i| matches!(at(i), Some(Kind::Vowel | Kind::Consonant)) && at(i - 1) != Some(Kind::Joiner) && starts(i)).collect() + (1..word.len()).filter(|&i| matches!(at(i), Some(Kind::Vowel | Kind::Consonant)) && starts(i)).collect() +} + +/// Is a Malayalam chillu written the older way, as a consonant, the virama and a zero-width joiner +/// (`ന്` U+200D), at `k`? Like a chillu letter (`ൻ`), it ends the syllable before. +fn legacy_chillu(word: &[char], kinds: &[Kind], k: usize) -> bool { + kinds.get(k) == Some(&Kind::Consonant) && kinds.get(k + 1) == Some(&Kind::Virama) && word.get(k + 2) == Some(&'\u{200D}') } /// Does a syllable start at `i`, a consonant or vowel, in a Tamil word? Not at a consonant with a -/// pulli, which closes the syllable before (`பக்-கம்`), nor inside KSSA (`க்ஷ`), one akshara. +/// pulli, which closes the syllable before (`பக்-கம்`), nor inside one of the two conjuncts Tamil +/// writes, KSSA (`க்ஷ`) and SHRII (`ஸ்ரீ`, `ஶ்ரீ`); a KSSA with a pulli closes the syllable too. fn tamil_starts(word: &[char], kinds: &[Kind], i: usize) -> bool { - const KA: char = '\u{0B95}'; - const SSA: char = '\u{0BB7}'; - let kssa = |k: usize| word.get(k) == Some(&KA) && kinds.get(k + 1) == Some(&Kind::Virama) && word.get(k + 2) == Some(&SSA); - let closes = kinds.get(i + 1) == Some(&Kind::Virama) && !kssa(i); - !closes && !(i >= 2 && kssa(i - 2)) + let conjunct = |k: usize| { + kinds.get(k + 1) == Some(&Kind::Virama) + && match (word.get(k).copied(), word.get(k + 2).copied()) { + // KA, SSA. + (Some('\u{0B95}'), Some('\u{0BB7}')) => true, + // SA or SHA, RA, and the vowel sign II. + (Some('\u{0BB8}' | '\u{0BB6}'), Some('\u{0BB0}')) => word.get(k + 3) == Some(&'\u{0BC0}'), + _ => false, + } + }; + let closes = kinds.get(i + 1) == Some(&Kind::Virama) && !(conjunct(i) && kinds.get(i + 3) != Some(&Kind::Virama)); + !closes && !(i >= 2 && conjunct(i - 2)) } #[cfg(test)] @@ -369,6 +386,10 @@ mod tests { assert_eq!(ml("മലയാളം"), "മ-ല-യാ-ളം"); assert_eq!(ml("അവൻ"), "അ-വൻ"); assert_eq!(ml("കർമ്മം"), "കർ-മ്മം"); + assert_eq!(ml("വൻമരം"), "വൻ-മ-രം"); + assert_eq!(ml("വന്\u{200D}മരം"), "വന്\u{200D}-മ-രം", "a chillu written with a joiner"); + assert_eq!(ml("അവന്\u{200D}"), "അ-വന്\u{200D}"); + assert_eq!(ml("കല\u{200D}മ"), "ക-ല\u{200D}മ", "a joiner after no virama still binds"); } /// Tamil: the break goes after a pulli, never before a consonant that carries one; KSSA is @@ -380,6 +401,9 @@ mod tests { assert_eq!(ta("பக்கம்"), "பக்-கம்"); assert_eq!(ta("தமிழ்நாடு"), "த-மிழ்-நா-டு"); assert_eq!(ta("அக்ஷரம்"), "அ-க்ஷ-ரம்"); + assert_eq!(ta("லக்ஷ்மி"), "லக்ஷ்-மி", "a KSSA with a pulli closes the syllable"); + assert_eq!(ta("ஸ்ரீலங்கா"), "ஸ்ரீ-லங்-கா", "SHRII with SA"); + assert_eq!(ta("ஶ்ரீலங்கா"), "ஶ்ரீ-லங்-கா", "SHRII with SHA"); } /// Gujarati, Hindi and the pack languages written in these scripts (by any of their tags) are From ef851c9669121e57837957d4954bdffad6a598c4 Mon Sep 17 00:00:00 2001 From: ruchirguitar Date: Sun, 29 Nov 2026 08:28:24 +0530 Subject: [PATCH 3/7] proof: Malayalam dot reph leads its akshara; legacy chillus only on chillu consonants The dot reph starts an akshara with the consonant it joins instead of acting as a virama. A consonant, virama and ZWJ is a chillu only for the six chillu consonants, and a break after one still needs a live akshara. Found by a local CodeRabbit review. --- crates/proof/src/indic.rs | 27 +++++++++++++++++++-------- 1 file changed, 19 insertions(+), 8 deletions(-) diff --git a/crates/proof/src/indic.rs b/crates/proof/src/indic.rs index 005b5ab97f..34dc70c938 100644 --- a/crates/proof/src/indic.rs +++ b/crates/proof/src/indic.rs @@ -72,6 +72,9 @@ enum Kind { Mark, /// A zero-width joiner or non-joiner: shapes the conjunct around it, in the same akshara. Joiner, + /// Malayalam's dot reph: a RA written before the consonant it joins, so it starts an akshara + /// with that consonant and no break follows it. + Reph, } /// Is `c` a zero-width joiner or non-joiner (U+200D, U+200C)? Inside an Indic word it shapes a @@ -172,10 +175,11 @@ impl Script { (Kannada, 0x55..=0x56 | 0x5D | 0x71..=0x73) => Kind::Mark, (Kannada, 0x5E) => Kind::Consonant, // The Vedic anusvara, the chillus (dead consonants), the AU length mark; TTTA; the - // vertical-bar and circular viramas and the dot reph, which join like a virama; II. + // vertical-bar and circular viramas; the dot reph; II. (Malayalam, 0x04 | 0x54..=0x57 | 0x7A..=0x7F) => Kind::Mark, (Malayalam, 0x3A) => Kind::Consonant, - (Malayalam, 0x3B..=0x3C | 0x4E) => Kind::Virama, + (Malayalam, 0x3B..=0x3C) => Kind::Virama, + (Malayalam, 0x4E) => Kind::Reph, (Malayalam, 0x5F) => Kind::Vowel, _ => return None, }) @@ -199,7 +203,8 @@ pub fn points(script: Script, word: &[char]) -> Vec { // Has the akshara starting at `i` a vowel (independent, a sign, or the inherent one)? Only a // consonant cluster ending in a virama (`ક્`, `ન્ત્`, with or without a joiner) has none. let live = |i: usize| { - let mut j = i; + // A dot reph leads the cluster it joins. + let mut j = if at(i) == Some(Kind::Reph) { i + 1 } else { i }; loop { if at(j) != Some(Kind::Consonant) { return true; @@ -224,15 +229,18 @@ pub fn points(script: Script, word: &[char]) -> Vec { let starts = |i: usize| match script { Script::Tamil => at(i - 1) != Some(Kind::Joiner) && tamil_starts(word, &kinds, i), _ if chillu(i) => false, - _ => (i >= 3 && chillu(i - 3)) || (!matches!(at(i - 1), Some(Kind::Virama | Kind::Joiner)) && live(i)), + _ => ((i >= 3 && chillu(i - 3)) || !matches!(at(i - 1), Some(Kind::Virama | Kind::Joiner | Kind::Reph))) && live(i), }; - (1..word.len()).filter(|&i| matches!(at(i), Some(Kind::Vowel | Kind::Consonant)) && starts(i)).collect() + (1..word.len()).filter(|&i| matches!(at(i), Some(Kind::Vowel | Kind::Consonant | Kind::Reph)) && starts(i)).collect() } -/// Is a Malayalam chillu written the older way, as a consonant, the virama and a zero-width joiner -/// (`ന്` U+200D), at `k`? Like a chillu letter (`ൻ`), it ends the syllable before. +/// Is a Malayalam chillu written the older way, as the consonant of one of the six chillu letters +/// (KA, NNA, NA, RA, LA, LLA), the virama and a zero-width joiner (`ന്` U+200D), at `k`? Like a +/// chillu letter (`ൻ`), it ends the syllable before. fn legacy_chillu(word: &[char], kinds: &[Kind], k: usize) -> bool { - kinds.get(k) == Some(&Kind::Consonant) && kinds.get(k + 1) == Some(&Kind::Virama) && word.get(k + 2) == Some(&'\u{200D}') + matches!(word.get(k), Some('\u{0D15}' | '\u{0D23}' | '\u{0D28}' | '\u{0D30}' | '\u{0D32}' | '\u{0D33}')) + && kinds.get(k + 1) == Some(&Kind::Virama) + && word.get(k + 2) == Some(&'\u{200D}') } /// Does a syllable start at `i`, a consonant or vowel, in a Tamil word? Not at a consonant with a @@ -390,6 +398,9 @@ mod tests { assert_eq!(ml("വന്\u{200D}മരം"), "വന്\u{200D}-മ-രം", "a chillu written with a joiner"); assert_eq!(ml("അവന്\u{200D}"), "അ-വന്\u{200D}"); assert_eq!(ml("കല\u{200D}മ"), "ക-ല\u{200D}മ", "a joiner after no virama still binds"); + assert_eq!(ml("അസ്\u{200D}മ"), "അ-സ്\u{200D}മ", "SA has no chillu: a conjunct"); + assert_eq!(ml("പാര്\u{200D}ക്ക്"), "പാര്\u{200D}ക്ക്", "nor is a dead cluster carried over"); + assert_eq!(ml("ഭാ\u{0D4E}യ"), "ഭാ-\u{0D4E}യ", "a dot reph leads its akshara"); } /// Tamil: the break goes after a pulli, never before a consonant that carries one; KSSA is From 2dbb39ec936c049b2dd036f2623460e398cd0880 Mon Sep 17 00:00:00 2001 From: ruchirguitar Date: Sun, 29 Nov 2026 08:32:09 +0530 Subject: [PATCH 4/7] proof: a Malayalam chillu can lead a conjunct; KA has no legacy chillu A chillu followed by a virama starts a conjunct, as its consonant would (NTA written with chillu N). Only NNA, NA, RA, LA and LLA have the older consonant, virama and ZWJ spelling of a chillu. Found by a local CodeRabbit review. --- crates/proof/src/indic.rs | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/crates/proof/src/indic.rs b/crates/proof/src/indic.rs index 34dc70c938..67248d0e8f 100644 --- a/crates/proof/src/indic.rs +++ b/crates/proof/src/indic.rs @@ -196,9 +196,17 @@ impl Script { /// each akshara but the first, except a dead consonant (in Tamil, after each pulli instead). /// Empty for anything that is not entirely the script's letters and marks. pub fn points(script: Script, word: &[char]) -> Vec { - let Some(kinds) = word.iter().map(|&c| script.kind(c)).collect::>>() else { + let Some(mut kinds) = word.iter().map(|&c| script.kind(c)).collect::>>() else { return Vec::new(); }; + // A Malayalam chillu with a virama after it leads a conjunct (`ൻ്റ`), as its consonant would. + if script == Script::Malayalam { + for k in 0..word.len().saturating_sub(1) { + if matches!(word[k], '\u{0D54}'..='\u{0D56}' | '\u{0D7A}'..='\u{0D7F}') && kinds[k + 1] == Kind::Virama { + kinds[k] = Kind::Consonant; + } + } + } let at = |i: usize| kinds.get(i).copied(); // Has the akshara starting at `i` a vowel (independent, a sign, or the inherent one)? Only a // consonant cluster ending in a virama (`ક્`, `ન્ત્`, with or without a joiner) has none. @@ -234,11 +242,10 @@ pub fn points(script: Script, word: &[char]) -> Vec { (1..word.len()).filter(|&i| matches!(at(i), Some(Kind::Vowel | Kind::Consonant | Kind::Reph)) && starts(i)).collect() } -/// Is a Malayalam chillu written the older way, as the consonant of one of the six chillu letters -/// (KA, NNA, NA, RA, LA, LLA), the virama and a zero-width joiner (`ന്` U+200D), at `k`? Like a -/// chillu letter (`ൻ`), it ends the syllable before. +/// Is a Malayalam chillu written the older way, as NNA, NA, RA, LA or LLA, the virama and a +/// zero-width joiner (`ന്` U+200D), at `k`? Like a chillu letter (`ൻ`), it ends the syllable before. fn legacy_chillu(word: &[char], kinds: &[Kind], k: usize) -> bool { - matches!(word.get(k), Some('\u{0D15}' | '\u{0D23}' | '\u{0D28}' | '\u{0D30}' | '\u{0D32}' | '\u{0D33}')) + matches!(word.get(k), Some('\u{0D23}' | '\u{0D28}' | '\u{0D30}' | '\u{0D32}' | '\u{0D33}')) && kinds.get(k + 1) == Some(&Kind::Virama) && word.get(k + 2) == Some(&'\u{200D}') } @@ -401,6 +408,8 @@ mod tests { assert_eq!(ml("അസ്\u{200D}മ"), "അ-സ്\u{200D}മ", "SA has no chillu: a conjunct"); assert_eq!(ml("പാര്\u{200D}ക്ക്"), "പാര്\u{200D}ക്ക്", "nor is a dead cluster carried over"); assert_eq!(ml("ഭാ\u{0D4E}യ"), "ഭാ-\u{0D4E}യ", "a dot reph leads its akshara"); + assert_eq!(ml("അക്\u{200D}കര"), "അ-ക്\u{200D}ക-ര", "KA has no legacy chillu: a conjunct"); + assert_eq!(ml("അവ\u{0D7B}\u{0D4D}\u{0D31}\u{0D46}"), "അ-വ-\u{0D7B}\u{0D4D}\u{0D31}\u{0D46}", "a chillu leading a conjunct"); } /// Tamil: the break goes after a pulli, never before a consonant that carries one; KSSA is From 657e0fca468886bcc18675eda3b8a09d0aa5708c Mon Sep 17 00:00:00 2001 From: ruchirguitar Date: Sun, 29 Nov 2026 09:12:42 +0530 Subject: [PATCH 5/7] proof: Bengali khanda ta written with a joiner; a cluster ending in an older chillu is dead TA, virama and ZWJ is khanda ta and ends the syllable before, as the letter does. A consonant cluster that ends in a chillu or khanda ta written the older way has no vowel, so no break carries it to the next line. From CodeRabbit on #4207. --- crates/proof/src/indic.rs | 35 ++++++++++++++++++++++++----------- 1 file changed, 24 insertions(+), 11 deletions(-) diff --git a/crates/proof/src/indic.rs b/crates/proof/src/indic.rs index 67248d0e8f..4d4d1ca67e 100644 --- a/crates/proof/src/indic.rs +++ b/crates/proof/src/indic.rs @@ -21,8 +21,9 @@ //! //! A dead consonant written as a letter of its own — Bengali's khanda ta (`ৎ`), Malayalam's chillus //! (`ൻ`, `ർ`), Telugu's and Kannada's nakaara pollu — ends the syllable before, as a mark does: -//! `উৎ-সব`, `കർ-മ്മം`. So does a chillu written the older way, as a consonant, the virama and a -//! zero-width joiner (`ന്` U+200D): the one place a break follows a joiner. Gurmukhi's addak (`ੱ`) and tippi (`ੰ`) are marks too: `ਪੱ-ਕਾ`. +//! `উৎ-সব`, `കർ-മ്മം`. So does a chillu or khanda ta written the older way, as its consonant, the +//! virama and a zero-width joiner (`ന്` U+200D, `ত্` U+200D): the one place a break follows a +//! joiner. Gurmukhi's addak (`ੱ`) and tippi (`ੰ`) are marks too: `ਪੱ-ਕਾ`. //! //! **Tamil** joins no conjuncts: a consonant with a visible virama (pulli) closes the syllable //! before it, so the break goes after the pulli, not before the consonant (`பக்-கம்`, `தமிழ்-நா-டு`). @@ -210,6 +211,7 @@ pub fn points(script: Script, word: &[char]) -> Vec { let at = |i: usize| kinds.get(i).copied(); // Has the akshara starting at `i` a vowel (independent, a sign, or the inherent one)? Only a // consonant cluster ending in a virama (`ક્`, `ન્ત્`, with or without a joiner) has none. + let legacy = |k: usize| legacy_dead_letter(script, word, &kinds, k); let live = |i: usize| { // A dot reph leads the cluster it joins. let mut j = if at(i) == Some(Kind::Reph) { i + 1 } else { i }; @@ -217,6 +219,10 @@ pub fn points(script: Script, word: &[char]) -> Vec { if at(j) != Some(Kind::Consonant) { return true; } + // A dead letter written the older way ends the cluster, whatever follows it. + if legacy(j) { + return false; + } j += 1; while matches!(at(j), Some(Kind::Mark | Kind::Joiner)) { j += 1; @@ -233,21 +239,24 @@ pub fn points(script: Script, word: &[char]) -> Vec { } } }; - let chillu = |k: usize| script == Script::Malayalam && legacy_chillu(word, &kinds, k); let starts = |i: usize| match script { Script::Tamil => at(i - 1) != Some(Kind::Joiner) && tamil_starts(word, &kinds, i), - _ if chillu(i) => false, - _ => ((i >= 3 && chillu(i - 3)) || !matches!(at(i - 1), Some(Kind::Virama | Kind::Joiner | Kind::Reph))) && live(i), + _ if legacy(i) => false, + _ => ((i >= 3 && legacy(i - 3)) || !matches!(at(i - 1), Some(Kind::Virama | Kind::Joiner | Kind::Reph))) && live(i), }; (1..word.len()).filter(|&i| matches!(at(i), Some(Kind::Vowel | Kind::Consonant | Kind::Reph)) && starts(i)).collect() } -/// Is a Malayalam chillu written the older way, as NNA, NA, RA, LA or LLA, the virama and a -/// zero-width joiner (`ന്` U+200D), at `k`? Like a chillu letter (`ൻ`), it ends the syllable before. -fn legacy_chillu(word: &[char], kinds: &[Kind], k: usize) -> bool { - matches!(word.get(k), Some('\u{0D23}' | '\u{0D28}' | '\u{0D30}' | '\u{0D32}' | '\u{0D33}')) - && kinds.get(k + 1) == Some(&Kind::Virama) - && word.get(k + 2) == Some(&'\u{200D}') +/// Is a dead letter written the older way, as its consonant, the virama and a zero-width joiner +/// (`ന്` U+200D), at `k`: a Malayalam chillu (NNA, NA, RA, LA or LLA) or Bengali khanda ta (TA)? +/// Like the letter itself (`ൻ`, `ৎ`), it ends the syllable before. +fn legacy_dead_letter(script: Script, word: &[char], kinds: &[Kind], k: usize) -> bool { + let base = match script { + Script::Malayalam => matches!(word.get(k), Some('\u{0D23}' | '\u{0D28}' | '\u{0D30}' | '\u{0D32}' | '\u{0D33}')), + Script::Bengali => word.get(k) == Some(&'\u{09A4}'), + _ => false, + }; + base && kinds.get(k + 1) == Some(&Kind::Virama) && word.get(k + 2) == Some(&'\u{200D}') } /// Does a syllable start at `i`, a consonant or vowel, in a Tamil word? Not at a consonant with a @@ -368,6 +377,9 @@ mod tests { assert_eq!(bn("বিদ্যাল\u{09AF}\u{09BC}"), "বি-দ্যা-ল-\u{09AF}\u{09BC}", "YA with nukta"); assert_eq!(bn("বিদ্যাল\u{09DF}"), "বি-দ্যা-ল-\u{09DF}", "precomposed YYA"); assert_eq!(bn("উৎসব"), "উৎ-স-ব"); + assert_eq!(bn("মহোত\u{09CD}\u{200D}সব"), "ম-হোত\u{09CD}\u{200D}-স-ব", "khanda ta written with a joiner"); + assert_eq!(bn("মহোৎসব"), "ম-হোৎ-স-ব", "as with the khanda ta letter"); + assert_eq!(bn("উদ\u{09CD}\u{200D}যম"), "উ-দ\u{09CD}\u{200D}য-ম", "DA has no khanda form: a conjunct"); assert_eq!(bn("ৰাজ্য"), "ৰা-জ্য"); } @@ -407,6 +419,7 @@ mod tests { assert_eq!(ml("കല\u{200D}മ"), "ക-ല\u{200D}മ", "a joiner after no virama still binds"); assert_eq!(ml("അസ്\u{200D}മ"), "അ-സ്\u{200D}മ", "SA has no chillu: a conjunct"); assert_eq!(ml("പാര്\u{200D}ക്ക്"), "പാര്\u{200D}ക്ക്", "nor is a dead cluster carried over"); + assert_eq!(ml("അന്ന്\u{200D}മ"), "അന്ന്\u{200D}-മ", "a cluster ending in a chillu is dead"); assert_eq!(ml("ഭാ\u{0D4E}യ"), "ഭാ-\u{0D4E}യ", "a dot reph leads its akshara"); assert_eq!(ml("അക്\u{200D}കര"), "അ-ക്\u{200D}ക-ര", "KA has no legacy chillu: a conjunct"); assert_eq!(ml("അവ\u{0D7B}\u{0D4D}\u{0D31}\u{0D46}"), "അ-വ-\u{0D7B}\u{0D4D}\u{0D31}\u{0D46}", "a chillu leading a conjunct"); From de89cc0e309410436e43f05374e9303b3148a84e Mon Sep 17 00:00:00 2001 From: ruchirguitar Date: Sun, 29 Nov 2026 19:37:08 +0530 Subject: [PATCH 6/7] proof: Kannada jihvamuliya and upadhmaniya lead their akshara; Malayalam samvruthokaram is a vowel --- crates/proof/src/indic.rs | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/crates/proof/src/indic.rs b/crates/proof/src/indic.rs index 4d4d1ca67e..ad6a52cc80 100644 --- a/crates/proof/src/indic.rs +++ b/crates/proof/src/indic.rs @@ -73,8 +73,8 @@ enum Kind { Mark, /// A zero-width joiner or non-joiner: shapes the conjunct around it, in the same akshara. Joiner, - /// Malayalam's dot reph: a RA written before the consonant it joins, so it starts an akshara - /// with that consonant and no break follows it. + /// A sign written before the consonant it joins (Malayalam's dot reph, Kannada's jihvamuliya + /// and upadhmaniya), so it starts an akshara with that consonant and no break follows it. Reph, } @@ -172,9 +172,11 @@ impl Script { // archaic consonants. (Telugu, 0x04 | 0x55..=0x56 | 0x5D) => Kind::Mark, (Telugu, 0x58..=0x5A) => Kind::Consonant, - // Length marks, nakaara pollu, jihvamuliya, upadhmaniya, the anusvara above right; FA. - (Kannada, 0x55..=0x56 | 0x5D | 0x71..=0x73) => Kind::Mark, + // Length marks, nakaara pollu, the anusvara above right; FA; jihvamuliya and + // upadhmaniya, which stack on the stop after them. + (Kannada, 0x55..=0x56 | 0x5D | 0x73) => Kind::Mark, (Kannada, 0x5E) => Kind::Consonant, + (Kannada, 0x71..=0x72) => Kind::Reph, // The Vedic anusvara, the chillus (dead consonants), the AU length mark; TTTA; the // vertical-bar and circular viramas; the dot reph; II. (Malayalam, 0x04 | 0x54..=0x57 | 0x7A..=0x7F) => Kind::Mark, @@ -212,6 +214,9 @@ pub fn points(script: Script, word: &[char]) -> Vec { // Has the akshara starting at `i` a vowel (independent, a sign, or the inherent one)? Only a // consonant cluster ending in a virama (`ક્`, `ન્ત્`, with or without a joiner) has none. let legacy = |k: usize| legacy_dead_letter(script, word, &kinds, k); + // Malayalam's samvruthokaram, the U sign and a virama (`ക്കു്`), is a vowel: the virama after + // it kills nothing and joins nothing. + let vowel_virama = |v: usize| script == Script::Malayalam && v > 0 && word[v] == '\u{0D4D}' && word[v - 1] == '\u{0D41}'; let live = |i: usize| { // A dot reph leads the cluster it joins. let mut j = if at(i) == Some(Kind::Reph) { i + 1 } else { i }; @@ -227,7 +232,7 @@ pub fn points(script: Script, word: &[char]) -> Vec { while matches!(at(j), Some(Kind::Mark | Kind::Joiner)) { j += 1; } - if at(j) != Some(Kind::Virama) { + if at(j) != Some(Kind::Virama) || vowel_virama(j) { return true; } j += 1; @@ -242,7 +247,7 @@ pub fn points(script: Script, word: &[char]) -> Vec { let starts = |i: usize| match script { Script::Tamil => at(i - 1) != Some(Kind::Joiner) && tamil_starts(word, &kinds, i), _ if legacy(i) => false, - _ => ((i >= 3 && legacy(i - 3)) || !matches!(at(i - 1), Some(Kind::Virama | Kind::Joiner | Kind::Reph))) && live(i), + _ => ((i >= 3 && legacy(i - 3)) || vowel_virama(i - 1) || !matches!(at(i - 1), Some(Kind::Virama | Kind::Joiner | Kind::Reph))) && live(i), }; (1..word.len()).filter(|&i| matches!(at(i), Some(Kind::Vowel | Kind::Consonant | Kind::Reph)) && starts(i)).collect() } @@ -404,6 +409,8 @@ mod tests { let kn = |w: &str| split(Script::Kannada, w); assert_eq!(kn("ಕನ್ನಡ"), "ಕ-ನ್ನ-ಡ"); assert_eq!(kn("ಸಂಸ್ಕೃತ"), "ಸಂ-ಸ್ಕೃ-ತ"); + assert_eq!(kn("ಅ\u{0CF1}ಕಿ"), "ಅ-\u{0CF1}ಕಿ", "jihvamuliya stacks on the stop after it"); + assert_eq!(kn("ಅ\u{0CF2}ಪ"), "ಅ-\u{0CF2}ಪ", "upadhmaniya too"); } /// Malayalam: conjuncts whole; a chillu ends the syllable before. @@ -422,6 +429,9 @@ mod tests { assert_eq!(ml("അന്ന്\u{200D}മ"), "അന്ന്\u{200D}-മ", "a cluster ending in a chillu is dead"); assert_eq!(ml("ഭാ\u{0D4E}യ"), "ഭാ-\u{0D4E}യ", "a dot reph leads its akshara"); assert_eq!(ml("അക്\u{200D}കര"), "അ-ക്\u{200D}ക-ര", "KA has no legacy chillu: a conjunct"); + assert_eq!(ml("അവൾക്കു്"), "അ-വൾ-ക്കു്", "samvruthokaram is a vowel"); + assert_eq!(ml("അതു്മാത്രം"), "അ-തു്-മാ-ത്രം", "and joins no conjunct"); + assert_eq!(ml("കു\u{200D}മ"), "കു\u{200D}മ", "a joiner after the U sign still binds"); assert_eq!(ml("അവ\u{0D7B}\u{0D4D}\u{0D31}\u{0D46}"), "അ-വ-\u{0D7B}\u{0D4D}\u{0D31}\u{0D46}", "a chillu leading a conjunct"); } From a482a595109aa4ecc61e6a3e2d9ca17e35d01a1b Mon Sep 17 00:00:00 2001 From: ruchirguitar Date: Sun, 29 Nov 2026 20:22:55 +0530 Subject: [PATCH 7/7] proof: Malayalam's vertical-bar and circular viramas join no conjunct --- crates/proof/src/indic.rs | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/crates/proof/src/indic.rs b/crates/proof/src/indic.rs index ad6a52cc80..35a8116fd7 100644 --- a/crates/proof/src/indic.rs +++ b/crates/proof/src/indic.rs @@ -217,6 +217,8 @@ pub fn points(script: Script, word: &[char]) -> Vec { // Malayalam's samvruthokaram, the U sign and a virama (`ക്കു്`), is a vowel: the virama after // it kills nothing and joins nothing. let vowel_virama = |v: usize| script == Script::Malayalam && v > 0 && word[v] == '\u{0D4D}' && word[v - 1] == '\u{0D41}'; + // Malayalam's vertical-bar and circular viramas only kill the vowel: they join no conjunct. + let killer = |v: usize| script == Script::Malayalam && matches!(word.get(v), Some('\u{0D3B}' | '\u{0D3C}')); let live = |i: usize| { // A dot reph leads the cluster it joins. let mut j = if at(i) == Some(Kind::Reph) { i + 1 } else { i }; @@ -235,6 +237,9 @@ pub fn points(script: Script, word: &[char]) -> Vec { if at(j) != Some(Kind::Virama) || vowel_virama(j) { return true; } + if killer(j) { + return false; + } j += 1; while at(j) == Some(Kind::Joiner) { j += 1; @@ -247,7 +252,13 @@ pub fn points(script: Script, word: &[char]) -> Vec { let starts = |i: usize| match script { Script::Tamil => at(i - 1) != Some(Kind::Joiner) && tamil_starts(word, &kinds, i), _ if legacy(i) => false, - _ => ((i >= 3 && legacy(i - 3)) || vowel_virama(i - 1) || !matches!(at(i - 1), Some(Kind::Virama | Kind::Joiner | Kind::Reph))) && live(i), + _ => { + ((i >= 3 && legacy(i - 3)) + || vowel_virama(i - 1) + || killer(i - 1) + || !matches!(at(i - 1), Some(Kind::Virama | Kind::Joiner | Kind::Reph))) + && live(i) + } }; (1..word.len()).filter(|&i| matches!(at(i), Some(Kind::Vowel | Kind::Consonant | Kind::Reph)) && starts(i)).collect() } @@ -432,6 +443,8 @@ mod tests { assert_eq!(ml("അവൾക്കു്"), "അ-വൾ-ക്കു്", "samvruthokaram is a vowel"); assert_eq!(ml("അതു്മാത്രം"), "അ-തു്-മാ-ത്രം", "and joins no conjunct"); assert_eq!(ml("കു\u{200D}മ"), "കു\u{200D}മ", "a joiner after the U sign still binds"); + assert_eq!(ml("അക\u{0D3B}മാ"), "അക\u{0D3B}-മാ", "the vertical-bar virama only kills the vowel"); + assert_eq!(ml("അക\u{0D3C}മാ"), "അക\u{0D3C}-മാ", "so does the circular virama"); assert_eq!(ml("അവ\u{0D7B}\u{0D4D}\u{0D31}\u{0D46}"), "അ-വ-\u{0D7B}\u{0D4D}\u{0D31}\u{0D46}", "a chillu leading a conjunct"); }