From 9441bbd770d39186c1439d35045d9fcc6831b608 Mon Sep 17 00:00:00 2001 From: Arun Prasad Date: Sun, 29 Oct 2023 11:41:12 -0700 Subject: [PATCH] [prakriya] Clean up various code Changes include: - Rename two `Prakriya` methods: `op` to `run` and `op_term` to `run_at`. - Standardize on `CharPrakriya` when working with characters. - Reduce use of `has_tag` in favor of methods like `has_abhyasa`. - Simplify various testing functions for readability and ease of use. - Add more docstrings and comments. - Add other small fixes. --- Cargo.lock | 36 +- vidyut-prakriya/Cargo.toml | 2 +- vidyut-prakriya/Makefile | 2 +- vidyut-prakriya/README.md | 8 +- vidyut-prakriya/src/ac_sandhi.rs | 188 ++++--- vidyut-prakriya/src/angasya.rs | 415 ++++++++------- vidyut-prakriya/src/angasya/abhyasasya.rs | 101 ++-- vidyut-prakriya/src/angasya/asiddhavat.rs | 263 +++++----- vidyut-prakriya/src/angasya/guna_vrddhi.rs | 275 ++++++---- vidyut-prakriya/src/angasya/sup_adesha.rs | 57 +-- vidyut-prakriya/src/ardhadhatuka.rs | 40 +- vidyut-prakriya/src/args/krt.rs | 6 + vidyut-prakriya/src/ashtadhyayi.rs | 6 + vidyut-prakriya/src/atidesha.rs | 20 +- vidyut-prakriya/src/atmanepada.rs | 12 +- vidyut-prakriya/src/bin/explain_subanta.rs | 2 +- vidyut-prakriya/src/char_view.rs | 225 ++++---- vidyut-prakriya/src/dhatu_karya.rs | 34 +- vidyut-prakriya/src/dvitva.rs | 12 +- vidyut-prakriya/src/it_agama.rs | 16 +- vidyut-prakriya/src/it_samjna.rs | 2 +- vidyut-prakriya/src/krt/basic.rs | 20 +- vidyut-prakriya/src/krt/unadi_sutras.rs | 29 +- vidyut-prakriya/src/krt/utils.rs | 6 +- vidyut-prakriya/src/lib.rs | 2 +- vidyut-prakriya/src/misc.rs | 2 +- vidyut-prakriya/src/operators.rs | 7 + vidyut-prakriya/src/prakriya.rs | 83 ++- vidyut-prakriya/src/pratipadika_karya.rs | 4 +- vidyut-prakriya/src/samjna.rs | 46 +- vidyut-prakriya/src/samprasarana.rs | 20 +- vidyut-prakriya/src/sanadi.rs | 12 +- .../src/taddhita/matvartha_prakarana.rs | 4 +- vidyut-prakriya/src/taddhita/pragdishiya.rs | 9 +- vidyut-prakriya/src/taddhita/pragdivyatiya.rs | 16 +- vidyut-prakriya/src/taddhita/pragvahatiya.rs | 2 +- vidyut-prakriya/src/taddhita/prakkritiya.rs | 2 +- .../src/taddhita/svarthika_prakarana.rs | 4 +- vidyut-prakriya/src/taddhita/utils.rs | 2 +- vidyut-prakriya/src/term.rs | 9 + vidyut-prakriya/src/tin_pratyaya.rs | 41 +- vidyut-prakriya/src/tripadi/pada_8_2.rs | 124 +++-- vidyut-prakriya/src/tripadi/pada_8_3.rs | 80 ++- vidyut-prakriya/src/tripadi/pada_8_4.rs | 274 +++++----- vidyut-prakriya/src/uttarapade.rs | 22 +- vidyut-prakriya/src/vikarana.rs | 105 ++-- vidyut-prakriya/src/wasm.rs | 55 +- vidyut-prakriya/test_utils/src/lib.rs | 152 +++--- vidyut-prakriya/tests/kashika_1_1.rs | 152 +++--- vidyut-prakriya/tests/kashika_1_2.rs | 20 +- vidyut-prakriya/tests/kashika_1_3.rs | 20 +- vidyut-prakriya/tests/kashika_1_4.rs | 94 ++-- vidyut-prakriya/tests/kashika_2_3.rs | 32 +- vidyut-prakriya/tests/kashika_3_2.rs | 5 +- vidyut-prakriya/tests/kashika_3_4.rs | 6 +- vidyut-prakriya/tests/kashika_4_1.rs | 300 ++++++----- vidyut-prakriya/tests/kashika_6_1.rs | 128 +++-- vidyut-prakriya/tests/kashika_6_4.rs | 270 +++++----- vidyut-prakriya/tests/kashika_7_1.rs | 480 +++++++++--------- vidyut-prakriya/tests/kashika_7_2.rs | 307 +++++------ vidyut-prakriya/tests/kashika_7_3.rs | 252 ++++----- vidyut-prakriya/tests/kashika_7_4.rs | 7 +- vidyut-prakriya/tests/kashika_8_2.rs | 82 ++- vidyut-prakriya/tests/kashika_8_3.rs | 38 +- vidyut-prakriya/tests/kashika_8_4.rs | 56 +- vidyut-prakriya/tests/kaumudi_10.rs | 48 ++ vidyut-prakriya/tests/kaumudi_60.rs | 14 + vidyut-prakriya/tests/kaumudi_65.rs | 45 ++ vidyut-prakriya/tests/kaumudi_67.rs | 95 +++- vidyut-prakriya/tests/kaumudi_9.rs | 101 +++- vidyut-prakriya/www/static/app.js | 109 +++- vidyut-prakriya/www/templates/index.html | 4 +- 72 files changed, 2909 insertions(+), 2610 deletions(-) create mode 100644 vidyut-prakriya/tests/kaumudi_10.rs create mode 100644 vidyut-prakriya/tests/kaumudi_65.rs diff --git a/Cargo.lock b/Cargo.lock index b1df985..25042cf 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -235,9 +235,9 @@ dependencies = [ [[package]] name = "darling" -version = "0.14.4" +version = "0.20.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7b750cb3417fd1b327431a470f388520309479ab0bf5e323505daf0290cd3850" +checksum = "0209d94da627ab5605dcccf08bb18afa5009cfbef48d8a8b7d7bdbc79be25c5e" dependencies = [ "darling_core", "darling_macro", @@ -245,26 +245,26 @@ dependencies = [ [[package]] name = "darling_core" -version = "0.14.4" +version = "0.20.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "109c1ca6e6b7f82cc233a97004ea8ed7ca123a9af07a8230878fcfda9b158bf0" +checksum = "177e3443818124b357d8e76f53be906d60937f0d3a90773a664fa63fa253e621" dependencies = [ "fnv", "ident_case", "proc-macro2", "quote", - "syn 1.0.109", + "syn 2.0.16", ] [[package]] name = "darling_macro" -version = "0.14.4" +version = "0.20.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a4aab4dbc9f7611d8b55048a3a16d2d010c2c8334e46304b40ac1cc14bf3b48e" +checksum = "836a9bbc7ad63342d6d6e7b815ccab164bc77a2d95d84bc3117a8c0d5c98e2d5" dependencies = [ "darling_core", "quote", - "syn 1.0.109", + "syn 2.0.16", ] [[package]] @@ -294,9 +294,9 @@ checksum = "7fcaabb2fef8c910e7f4c7ce9f67a1283a1715879a7c230ca9d6d1ae31f16d91" [[package]] name = "enumset" -version = "1.0.12" +version = "1.1.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "19be8061a06ab6f3a6cf21106c873578bf01bd42ad15e0311a9c76161cb1c753" +checksum = "226c0da7462c13fb57e5cc9e0dc8f0635e7d27f276a3a7fd30054647f669007d" dependencies = [ "enumset_derive", "serde", @@ -304,14 +304,14 @@ dependencies = [ [[package]] name = "enumset_derive" -version = "0.6.1" +version = "0.8.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "03e7b551eba279bf0fa88b83a46330168c1560a52a94f5126f892f0b364ab3e0" +checksum = "e08b6c6ab82d70f08844964ba10c7babb716de2ecaeab9be5717918a5177d3af" dependencies = [ "darling", "proc-macro2", "quote", - "syn 1.0.109", + "syn 2.0.16", ] [[package]] @@ -662,9 +662,9 @@ dependencies = [ [[package]] name = "proc-macro2" -version = "1.0.52" +version = "1.0.69" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1d0e1ae9e836cc3beddd63db0df682593d7e2d3d891ae8c9083d2113e1744224" +checksum = "134c189feb4956b20f6f547d2cf727d4c0fe06722b20a0eec87ed445a97f92da" dependencies = [ "unicode-ident", ] @@ -822,7 +822,7 @@ checksum = "e801c1712f48475582b7696ac71e0ca34ebb30e09338425384269d9717c62cad" dependencies = [ "proc-macro2", "quote", - "syn 2.0.4", + "syn 2.0.16", ] [[package]] @@ -884,9 +884,9 @@ dependencies = [ [[package]] name = "syn" -version = "2.0.4" +version = "2.0.16" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2c622ae390c9302e214c31013517c2061ecb2699935882c60a9b37f82f8625ae" +checksum = "a6f671d4b5ffdb8eadec19c0ae67fe2639df8684bd7bc4b83d986b8db549cf01" dependencies = [ "proc-macro2", "quote", diff --git a/vidyut-prakriya/Cargo.toml b/vidyut-prakriya/Cargo.toml index 41a2be3..196029c 100644 --- a/vidyut-prakriya/Cargo.toml +++ b/vidyut-prakriya/Cargo.toml @@ -14,7 +14,7 @@ edition = "2021" clap = { version = "4.0.12", features = ["derive"] } compact_str = { version = "0.6.1", features = ["serde"] } csv = "1.1.6" -enumset = { version = "1.0.12", features = ["serde"] } +enumset = { version = "1.1.3", features = ["serde"] } lazy_static = "1.4.0" serde = { version = "1.0.150", features = ["derive"] } sha2 = "0.10.6" diff --git a/vidyut-prakriya/Makefile b/vidyut-prakriya/Makefile index df0bac6..e5bf45c 100644 --- a/vidyut-prakriya/Makefile +++ b/vidyut-prakriya/Makefile @@ -90,7 +90,7 @@ check_rule_coverage: # Profiles the program's execution time on OSX. This command will probably not # work on other operating systems. profile-time-osx: - cargo instruments -t time --release --bin create_test_files + cargo instruments -t time --release --bin create_test_file # Other diff --git a/vidyut-prakriya/README.md b/vidyut-prakriya/README.md index ea90312..08f911c 100644 --- a/vidyut-prakriya/README.md +++ b/vidyut-prakriya/README.md @@ -239,13 +239,13 @@ fn rules(p: &mut Prakriya, i: usize) -> Option<()> { if base.has_tag(T::Abhyasta) { // juhvati - p.op_term("7.1.4", i, op::adi("at")); + p.run_at("7.1.4", i, op::adi("at")); } else if !base.has_antya('a') && tin.has_tag(T::Atmanepada) { // kurvate - p.op_term("7.1.5", i, op::adi("at")); + p.run_at("7.1.5", i, op::adi("at")); } else { // Bavanti - p.op_term("7.1.3", i, op::adi("ant")); + p.run_at("7.1.3", i, op::adi("ant")); } Some(()) @@ -266,7 +266,7 @@ they don't sacrifice readability. Some notes on our naming conventions: Notes on our API: -- `p.op_term("my-rule", i, fn)` applies the `fn` function to the term at index `i` +- `p.run_at("my-rule", i, fn)` applies the `fn` function to the term at index `i` of `p` and associates that operation with `"my-rule"`. - `op::adi(s)` returns a function. The returned function accepts a `Term` and replaces its first sound with `s`. If you haven't worked with [first-class diff --git a/vidyut-prakriya/src/ac_sandhi.rs b/vidyut-prakriya/src/ac_sandhi.rs index 65df1f0..bc34a56 100644 --- a/vidyut-prakriya/src/ac_sandhi.rs +++ b/vidyut-prakriya/src/ac_sandhi.rs @@ -2,7 +2,7 @@ //! ========= //! (6.1.66 - 6.1.101) -use crate::char_view::{char_rule, get_at, get_index_at, set_at, xy}; +use crate::char_view::{get_at, xy, CharPrakriya}; use crate::it_samjna; use crate::iterators::xy_rule; use crate::operators as op; @@ -26,8 +26,8 @@ lazy_static! { } pub fn try_lopo_vyor_vali(p: &mut Prakriya) { - char_rule( - p, + let mut cp = CharPrakriya::new(p); + cp.for_chars( |p, text, i| { let x = text.as_bytes()[i] as char; let y = match text.as_bytes().get(i + 1) { @@ -49,8 +49,7 @@ pub fn try_lopo_vyor_vali(p: &mut Prakriya) { vyor_vali && !is_upadesha_adi && !t.is_pratipadika() }, |p, _, i| { - set_at(p, i, ""); - p.step("6.1.66"); + p.run("6.1.66", |p| p.set_char_at(i, "")); true }, ); @@ -60,7 +59,7 @@ fn try_ver_aprktasya(p: &mut Prakriya) -> Option<()> { let i = p.find_last(T::Pratyaya)?; let last = p.get(i)?; if last.has_text("v") { - p.op_term("6.1.67", i, op::lopa); + p.run_at("6.1.67", i, op::lopa); } Some(()) @@ -68,37 +67,36 @@ fn try_ver_aprktasya(p: &mut Prakriya) -> Option<()> { /// Runs various general rules of vowel sandhi. pub fn apply_general_ac_sandhi(p: &mut Prakriya) { - char_rule(p, xy(|x, y| x == 'a' && al::is_guna(y)), |p, _, i| { - // HACK: clean up - let i_x = get_index_at(p, i).expect("valid"); - let i_y = get_index_at(p, i + 1).expect("valid"); - if i_x != i_y && (p.is_pada(i_x) || p.has(i_x, |t| t.is_upasarga())) { - false - } else { - set_at(p, i, ""); - p.step("6.1.97"); - true - } - }); - - char_rule( - p, - xy(|x, y| EC.contains(x) && AC.contains(y)), - |p, text, i| { - let x = text.as_bytes()[i] as char; - let sub = match x { - 'e' => "ay", - 'E' => "Ay", - 'o' => "av", - 'O' => "Av", - _ => panic!("Unexpected sub"), - }; - set_at(p, i, sub); - p.step("6.1.78"); - true + let mut cp = CharPrakriya::new(p); + cp.for_chars( + // [dummy comment for rust fmt] + xy(|x, y| x == 'a' && al::is_guna(y)), + |p, _, i| { + // HACK: clean up + let i_x = p.find_for_char_at(i).expect("valid"); + let i_y = p.find_for_char_at(i + 1).expect("valid"); + if i_x != i_y && (p.is_pada(i_x) || p.has(i_x, |t| t.is_upasarga())) { + false + } else { + p.run("6.1.97", |p| p.set_char_at(i, "")); + true + } }, ); + cp.for_chars(xy(|x, y| EC.contains(x) && AC.contains(y)), |p, text, i| { + let x = text.as_bytes()[i] as char; + let sub = match x { + 'e' => "ay", + 'E' => "Ay", + 'o' => "av", + 'O' => "Av", + _ => panic!("Unexpected sub"), + }; + p.run("6.1.78", |p| p.set_char_at(i, sub)); + true + }); + // HACK: ignore sandhi between upasarga and dhatu so that we can correctly derive prARinat, // etc. fn is_upasarga_sanadi_dhatu(p: &Prakriya, i: usize) -> bool { @@ -106,8 +104,7 @@ pub fn apply_general_ac_sandhi(p: &mut Prakriya) { && p.terms().last().expect("present").is_dhatu() } - char_rule( - p, + cp.for_chars( xy(|x, y| AK.contains(x) && AK.contains(y) && al::savarna(x).contains(y)), |p, text, i| { if is_upasarga_sanadi_dhatu(p, i) { @@ -115,34 +112,29 @@ pub fn apply_general_ac_sandhi(p: &mut Prakriya) { } let x = text.as_bytes()[i] as char; - set_at(p, i, &al::to_dirgha(x).expect("should be ac").to_string()); - set_at(p, i + 1, ""); - p.step("6.1.101"); + p.run("6.1.101", |p| { + p.set_char_at(i, &al::to_dirgha(x).expect("should be ac").to_string()); + p.set_char_at(i + 1, ""); + }); true }, ); - char_rule( - p, - xy(|x, y| IK.contains(x) && AC.contains(y)), - |p, text, i| { - let x = text.as_bytes()[i] as char; - let res = match x { - 'i' | 'I' => "y", - 'u' | 'U' => "v", - 'f' | 'F' => "r", - 'x' | 'X' => "l", - _ => panic!("Unexpected res"), - }; - set_at(p, i, res); - p.step("6.1.77"); - true - }, - ); + cp.for_chars(xy(|x, y| IK.contains(x) && AC.contains(y)), |p, text, i| { + let x = text.as_bytes()[i] as char; + let res = match x { + 'i' | 'I' => "y", + 'u' | 'U' => "v", + 'f' | 'F' => "r", + 'x' | 'X' => "l", + _ => panic!("Unexpected res"), + }; + p.run("6.1.77", |p| p.set_char_at(i, res)); + true + }); // upa + fcCati -> upArcCati - xy_rule( - p, + cp.for_terms( |x, y| x.is_upasarga() && x.has_antya(&*A) && y.is_dhatu() && y.has_adi('f'), |p, i, j| { p.set(i, |t| t.set_antya("")); @@ -152,8 +144,7 @@ pub fn apply_general_ac_sandhi(p: &mut Prakriya) { ); // upa + eti -> upEti - xy_rule( - p, + cp.for_terms( |x, y| { x.is_upasarga() && x.has_antya(&*A) @@ -164,22 +155,20 @@ pub fn apply_general_ac_sandhi(p: &mut Prakriya) { let y = p.get(j).expect("ok"); let adi = y.adi().expect("ok"); let sub = al::to_vrddhi(adi).expect("ok"); - p.op_term("6.1.89", j, |t| t.set_adi(sub)); + p.run_at("6.1.89", j, |t| t.set_adi(sub)); }, ); // HACK for KOnAti - xy_rule( - p, + cp.for_terms( |x, _| x.has_text("KaU"), |p, i, _| { - p.op_term("6.1.89", i, |t| t.set_text("KO")); + p.run_at("6.1.89", i, |t| t.set_text("KO")); }, ); // upa + elayati -> upelayati - xy_rule( - p, + cp.for_terms( |x, y| x.is_upasarga() && x.has_antya(&*A) && y.is_dhatu() && y.has_adi(&*EN), |p, i, _j| { p.set(i, |t| t.set_antya("")); @@ -188,8 +177,8 @@ pub fn apply_general_ac_sandhi(p: &mut Prakriya) { ); // General guna/vrddhi rules. - char_rule( - p, + cp.for_chars( + // [dummy comment for cargo fmt] xy(|x, y| A.contains(x) && AC.contains(y)), |p, text, i| { if is_upasarga_sanadi_dhatu(p, i) { @@ -200,13 +189,15 @@ pub fn apply_general_ac_sandhi(p: &mut Prakriya) { let y = text.as_bytes()[i + 1] as char; if EC.contains(y) { - set_at(p, j, al::to_vrddhi(y).expect("should have vrddhi")); - set_at(p, i, ""); - p.step("6.1.88"); + p.run("6.1.88", |p| { + p.set_char_at(j, al::to_vrddhi(y).expect("should have vrddhi")); + p.set_char_at(i, ""); + }); } else { - set_at(p, j, al::to_guna(y).expect("should have guna")); - set_at(p, i, ""); - p.step("6.1.87"); + p.run("6.1.87", |p| { + p.set_char_at(j, al::to_guna(y).expect("should have guna")); + p.set_char_at(i, ""); + }); } true }, @@ -219,7 +210,7 @@ pub fn try_sup_sandhi_before_angasya(p: &mut Prakriya) -> Option<()> { if sup.is_sup() { let purva = p.get(i - 1)?; if purva.has_antya('o') && sup.has_u_in(&["am", "Sas"]) { - p.op("6.1.93", |p| { + p.run("6.1.93", |p| { p.set(i - 1, op::antya("A")); p.set(i, op::adi("")); }); @@ -238,33 +229,33 @@ fn try_sup_sandhi_after_angasya_for_term(p: &mut Prakriya, i_sup: usize) -> Opti if anga.has_antya(&*AK) && sup.has_tag_in(&[T::V1, T::V2]) { if sup.has_text("am") { - p.op_term("6.1.107", i_sup, op::adi("")); + p.run_at("6.1.107", i_sup, op::adi("")); } else if anga.has_antya('a') && sup.has_adi(&*IC) { p.step("6.1.104"); } else if anga.is_dirgha() && (sup.has_adi(&*IC) || sup.has_u("jas")) { p.step("6.1.105"); } else if sup.has_adi(&*AC) { let sub = al::to_dirgha(anga.antya()?)?; - p.op_term("6.1.102", i_sup, op::adi(&sub.to_string())); + p.run_at("6.1.102", i_sup, op::adi(&sub.to_string())); let sup = p.get(i_sup)?; if p.has_tag(T::Pum) && sup.has_u("Sas") { - p.op_term("6.1.103", i_sup, op::antya("n")); + p.run_at("6.1.103", i_sup, op::antya("n")); } } } else if sup.has_u_in(&["Nasi~", "Nas"]) { if anga.has_antya(&*EN) { // muneH, guroH - p.op_term("6.1.110", i_sup, op::adi("")); + p.run_at("6.1.110", i_sup, op::adi("")); } else if anga.has_antya('f') { // pituH - p.op("6.1.111", |p| { + p.run("6.1.111", |p| { p.set(i_anga, op::antya("ur")); p.set(i_sup, op::adi("")); }); } else if anga.has_text("saKi") || anga.has_text("pati") { // saKyuH, patyuH - p.op_term("6.1.112", i_sup, op::text("us")); + p.run_at("6.1.112", i_sup, op::text("us")); } } @@ -288,27 +279,30 @@ fn apply_ac_sandhi_at_term_boundary(p: &mut Prakriya, i: usize) -> Option<()> { let x = p.get(i)?; let y = p.get(j)?; - let ni_ap = x.has_tag(T::StriNyap) || x.has_u_in(&["wAp", "cAp", "dAp", "NIp", "NIz"]); + // HACK: since we don't support ekaH pUrvaparayoh properly, check for nyAp in either the + // current term or the next term. + let ni_ap = + x.has_tag(T::StriNyap) || x.is_nyap_pratyaya() || p.has(i + 1, |t| t.is_nyap_pratyaya()); // Check for Agama to avoid lopa on yAs + t. let hal_ni_ap_dirgha = x.has_antya(&*HAL) || (ni_ap && x.is_dirgha()) && !x.is_agama(); if hal_ni_ap_dirgha && y.is_aprkta() && y.has_u_in(&["su~", "tip", "sip"]) { - p.op_term("6.1.68", j, op::lopa); + p.run_at("6.1.68", j, op::lopa); } let x = p.get(i)?; let y = p.get(j)?; if (x.is_hrasva() || x.has_antya(&*EN)) && y.has_tag(T::Sambuddhi) { - p.op_term("6.1.69", j, op::lopa); + p.run_at("6.1.69", j, op::lopa); } let mut had_vrddhi = false; let x = p.get(i)?; let y = p.get(j)?; if (x.has_antya('a') || x.has_antya('A')) && y.has_text("us") { - p.op_term("6.1.96", i, op::antya("")); + p.run_at("6.1.96", i, op::antya("")); } else if x.has_u("Aw") && y.has_adi(&*AC) { let sub = al::to_vrddhi(y.adi()?)?; - p.op("6.1.90", |p| { + p.run("6.1.90", |p| { // ekaH pUrvapara (6.1.84) p.set(i, op::text("")); p.set(j, op::adi(sub)); @@ -329,7 +323,7 @@ fn apply_ac_sandhi_at_term_boundary(p: &mut Prakriya, i: usize) -> Option<()> { p.step("6.1.80"); } else { let sub = if t.has_antya('o') { "av" } else { "Av" }; - p.op_term("6.1.79", i, op::antya(sub)); + p.run_at("6.1.79", i, op::antya(sub)); } }, ); @@ -349,25 +343,25 @@ fn try_sut_kat_purva(p: &mut Prakriya) -> Option<()> { })?; let prev = p.get(i_prev)?; - let optional_add_sut = |rule, p: &mut Prakriya, i_dhatu: usize| { - if p.op_optional(rule, |p| op::insert_agama_before(p, i_dhatu, "su~w")) { + let optional_add_sut_agama = |rule, p: &mut Prakriya, i_dhatu: usize| { + if p.run_optional(rule, |p| op::insert_agama_before(p, i_dhatu, "su~w")) { it_samjna::run(p, i_dhatu).expect("ok"); } }; if prev.has_u_in(&["sam", "pari", "upa"]) && dhatu.has_u("qukf\\Y") { - optional_add_sut("6.1.137", p, i_dhatu); + optional_add_sut_agama("6.1.137", p, i_dhatu); // Ignore 6.1.139, which creates the same result as 6.1.137. } else if dhatu.has_u("kF") { if prev.has_u("upa") { - optional_add_sut("6.1.140", p, i_dhatu); + optional_add_sut_agama("6.1.140", p, i_dhatu); } else if prev.has_u("prati") { - optional_add_sut("6.1.141", p, i_dhatu); + optional_add_sut_agama("6.1.141", p, i_dhatu); } else if prev.has_u("apa") { - optional_add_sut("6.1.142", p, i_dhatu); + optional_add_sut_agama("6.1.142", p, i_dhatu); } } else if prev.has_u("pra") && dhatu.has_u("tunpa~") { - optional_add_sut("6.1.157", p, i_dhatu); + optional_add_sut_agama("6.1.157", p, i_dhatu); // TODO: implement others. } Some(()) @@ -381,9 +375,9 @@ fn hacky_apply_ni_asiddhavat_rules(p: &mut Prakriya) -> Option<()> { // HACK: duplicate 6.4.92 from the asiddhavat section for ci -> cAy, cap if x.has_tag(T::mit) && x.has_text_in(&["cAy", "cA"]) && y.has_u_in(&["Ric", "pu~k"]) { if x.has_text("cA") { - p.op_term("6.4.92", i, op::antya("a")); + p.run_at("6.4.92", i, op::antya("a")); } else { - p.op_term("6.4.92", i, op::upadha("a")); + p.run_at("6.4.92", i, op::upadha("a")); } } } @@ -406,7 +400,7 @@ pub fn run_antaranga(p: &mut Prakriya) -> Option<()> { 'x' | 'X' => "l", _ => panic!("Unexpected res"), }; - p.op_term("6.1.77", i, |t| t.set_upadha(res)); + p.run_at("6.1.77", i, |t| t.set_upadha(res)); } } diff --git a/vidyut-prakriya/src/angasya.rs b/vidyut-prakriya/src/angasya.rs index 0b8f63b..1b1da1c 100644 --- a/vidyut-prakriya/src/angasya.rs +++ b/vidyut-prakriya/src/angasya.rs @@ -21,7 +21,7 @@ pub use asiddhavat::try_cinvat_for_bhave_and_karmani_prayoga; use crate::ac_sandhi; use crate::args::Gana::*; -use crate::char_view::{char_rule, get_at, set_at, xy}; +use crate::char_view::{get_at, xy, CharPrakriya}; use crate::dhatu_gana as gana; use crate::filters as f; use crate::it_samjna; @@ -73,10 +73,10 @@ fn try_do_dirgha(p: &mut Prakriya, i_anga: usize) -> Option<()> { if anga.is_hrasva() && anga.has_upadha(&*HAL) && anga.has_tag(T::FlagSamprasarana) { // hUta, jIna, ... let sub = al::to_dirgha(anga.antya()?)?; - p.op_term("6.4.2", i_anga, |t| t.set_antya(&sub.to_string())); + p.run_at("6.4.2", i_anga, |t| t.set_antya(&sub.to_string())); } else if anga.has_u("kramu~") && n.has_u("ktvA") { // krantvA, krAntvA - p.op_optional("6.4.18", op::t(i_anga, |t| t.set_upadha("A"))); + p.run_optional_at("6.4.18", i_anga, |t| t.set_upadha("A")); } else if (anga.has_antya(&*AC) || anga.has_u_in(&["ha\\na~", "ga\\mx~", "gami~"])) && n.has_u("san") { @@ -84,17 +84,17 @@ fn try_do_dirgha(p: &mut Prakriya, i_anga: usize) -> Option<()> { let code = "6.4.16"; if anga.has_antya(&*AC) { let sub = al::to_dirgha(anga.antya()?)?; - p.op_term(code, i_anga, |t| t.set_antya(&sub.to_string())); + p.run_at(code, i_anga, |t| t.set_antya(&sub.to_string())); } else { - p.op_term(code, i_anga, |t| t.set_upadha("A")); + p.run_at(code, i_anga, |t| t.set_upadha("A")); } } else if anga.has_u("tanu~^") && n.has_u("san") { - p.op_optional("6.4.17", op::t(i_anga, |t| t.set_upadha("A"))); + p.run_optional_at("6.4.17", i_anga, |t| t.set_upadha("A")); } else if anga.has_antya(&*ANUNASIKA) && (n.has_u("kvi~p") || jhal_knit()) { let blocked = anga.has_tag(T::FlagNoDirgha); if let Some(sub) = al::to_dirgha(anga.upadha()?) { if !blocked { - p.op_term("6.4.15", i_anga, |t| t.set_upadha(&sub.to_string())); + p.run_at("6.4.15", i_anga, |t| t.set_upadha(&sub.to_string())); } } } @@ -117,12 +117,12 @@ fn try_cchvoh(p: &mut Prakriya) -> Option<()> { // Check for 'U' explicitly since the dhatu might have been processed in an earlier round // (e.g. when creating the sanAdyanta-dhAtu). if kvi_jhaloh_kniti && anga.has_u_in(JVARA_ADI) && !anga.text.contains('U') { - p.op_term("6.4.20", i, |t| { + p.run_at("6.4.20", i, |t| { t.set_upadha(""); t.find_and_replace_text("v", "U"); }); } else if kvi_jhaloh_kniti && (anga.text.ends_with("rv") || anga.text.ends_with("rC")) { - p.op_term("6.4.21", i, |t| { + p.run_at("6.4.21", i, |t| { if t.text.ends_with("rC") { t.set_antya("") } else { @@ -130,7 +130,7 @@ fn try_cchvoh(p: &mut Prakriya) -> Option<()> { } }); } else if is_cchvoh && (kvi_jhaloh_kniti || anunasike) { - p.op_term("6.4.19", i, |t| { + p.run_at("6.4.19", i, |t| { if t.has_antya('v') { t.set_antya("U"); } else { @@ -156,20 +156,20 @@ pub fn try_run_dirgha_for_sarvanamasthane_asambuddhau( let sub = al::to_dirgha(anga.upadha()?)?; if sup.has_u("Si") { // yogIni - p.op_term("6.4.12", i, op::upadha(&sub.to_string())); + p.run_at("6.4.12", i, op::upadha(&sub.to_string())); } else if sau { // yogI - p.op_term("6.4.13", i, op::upadha(&sub.to_string())); + p.run_at("6.4.13", i, op::upadha(&sub.to_string())); } } else { // PalAni let sub = al::to_dirgha(anga.upadha()?)?; - p.op_term("6.4.8", i, op::upadha(&sub.to_string())); + p.run_at("6.4.8", i, op::upadha(&sub.to_string())); } } else if (anga.ends_with("ns") && anga.text.len() >= 3) || anga.has_text("mahant") { let c = anga.text.len() - 3; let sub = al::to_dirgha(anga.get_at(c)?)?; - p.op_term("6.4.10", i, |t| { + p.run_at("6.4.10", i, |t| { t.set_at(c, &sub.to_string()); }); } else if anga.has_text("ap") @@ -179,7 +179,7 @@ pub fn try_run_dirgha_for_sarvanamasthane_asambuddhau( ]) { let sub = al::to_dirgha(anga.upadha()?)?; - p.op_term("6.4.11", i, op::upadha(&sub.to_string())); + p.run_at("6.4.11", i, op::upadha(&sub.to_string())); } Some(()) @@ -201,7 +201,7 @@ fn try_dirgha_adesha_before_num_agama(p: &mut Prakriya) -> Option<()> { if sup.has_tag(T::Sarvanamasthana) && !sup.has_tag(T::Sambuddhi) { if (is_atu || anga.ends_with("as")) && sau && !anga.is_dhatu() { let sub = al::to_dirgha(anga.upadha()?)?; - p.op_term("6.4.14", i_anga, op::upadha(&sub.to_string())); + p.run_at("6.4.14", i_anga, op::upadha(&sub.to_string())); } } @@ -230,13 +230,13 @@ fn try_dirgha_adesha_for_sup(p: &mut Prakriya) -> Option<()> { } else if anga.has_text("nf") { // nfRAm, nFRAm let sub = al::to_dirgha(anga.antya()?)?; - p.op_optional("6.4.6", op::t(i_anga, op::antya(&sub.to_string()))); + p.run_optional_at("6.4.6", i_anga, op::antya(&sub.to_string())); } else if anga.has_antya('n') { let sub = al::to_dirgha(anga.upadha()?)?; - p.op_term("6.4.7", i_anga, op::upadha(&sub.to_string())); + p.run_at("6.4.7", i_anga, op::upadha(&sub.to_string())); } else if anga.has_antya(&*AC) { let sub = al::to_dirgha(anga.antya()?)?; - p.op_term("6.4.3", i_anga, op::antya(&sub.to_string())); + p.run_at("6.4.3", i_anga, op::antya(&sub.to_string())); } } else if sup.has_tag(T::Sarvanamasthana) && !sup.has_tag(T::Sambuddhi) { try_run_dirgha_for_sarvanamasthane_asambuddhau(p, i_anga, i_sup); @@ -257,13 +257,13 @@ pub fn maybe_do_jha_adesha(p: &mut Prakriya) -> Option<()> { if base.has_tag(T::Abhyasta) { // juhvati - p.op_term("7.1.4", i, op::adi("at")); + p.run_at("7.1.4", i, op::adi("at")); } else if !base.has_antya('a') && tin.is_atmanepada() { // kurvate - p.op_term("7.1.5", i, op::adi("at")); + p.run_at("7.1.5", i, op::adi("at")); } else { // Bavanti - p.op_term("7.1.3", i, op::adi("ant")); + p.run_at("7.1.3", i, op::adi("ant")); } let base = p.get(i_base)?; @@ -271,11 +271,11 @@ pub fn maybe_do_jha_adesha(p: &mut Prakriya) -> Option<()> { let add_rut = |p: &mut Prakriya| op::insert_agama_before(p, i, "ru~w"); if base.has_u("SIN") { // Serate - p.op("7.1.6", add_rut); + p.run("7.1.6", add_rut); it_samjna::run(p, i).ok()?; } else if base.has_u("vida~") && base.has_gana(Adadi) { // vidate, vidrate - if p.op_optional("7.1.7", add_rut) { + if p.run_optional("7.1.7", add_rut) { it_samjna::run(p, i).ok()?; } } @@ -317,18 +317,18 @@ pub fn try_pratyaya_adesha(p: &mut Prakriya) -> Option<()> { if last.has_text_in(&["yu~", "vu~"]) { if last.has_text("yu~") { - p.op_term("7.1.1", i, op::text("ana")); + p.run_at("7.1.1", i, op::text("ana")); } else { - p.op_term("7.1.1", i, op::text("aka")); + p.run_at("7.1.1", i, op::text("aka")); } } else if let Some(sub) = replace_pha_dha_and_others(last) { - p.op_term("7.1.2", i, op::adi(sub)); + p.run_at("7.1.2", i, op::adi(sub)); } else if last.has_adi('W') { // Run 7.3.50 and 7.3.51 because they have no clear place otherwise. if prev.has_suffix_in(&["is", "us", "t"]) || prev.has_antya(&*UK) { - p.op_term("7.3.51", i, |t| t.set_adi("k")); + p.run_at("7.3.51", i, |t| t.set_adi("k")); } else { - p.op_term("7.3.50", i, |t| t.set_adi("ik")); + p.run_at("7.3.50", i, |t| t.set_adi("ik")); } // 7.1.34 (daDyA -> daDyO) happens later on after the dhatu's vowel change (DyE -> DyA) @@ -374,15 +374,15 @@ fn try_shiti(p: &mut Prakriya) -> Option<()> { if anga.has_antya('o') && n.has_u("Syan") { // Syati - p.op_term("7.3.71", i, op::antya("")); + p.run_at("7.3.71", i, op::antya("")); } else if anga.has_u_in(gana::SHAM_ADI) && n.has_u("Syan") && anga.has_gana(Divadi) { // Check ganas to avoid `Bramu~ anavasTAne` (BrAmyati). - p.op_term("7.3.74", i, op::upadha("A")); + p.run_at("7.3.74", i, op::upadha("A")); } else if anga.has_u_in(&["zWivu~", "klamu~"]) || (anga.has_u("camu~") && i > 0 && p.has(i - 1, |t| t.has_u("AN"))) { // zWIvati, kAmati, AcAmati - p.op_term("7.3.75", i, |t| { + p.run_at("7.3.75", i, |t| { match t.text.as_str() { "zWiv" => t.text.replace_range(.., "zWIv"), "klam" => t.text.replace_range(.., "klAm"), @@ -392,10 +392,10 @@ fn try_shiti(p: &mut Prakriya) -> Option<()> { }); } else if anga.has_text("kram") && last.is_parasmaipada() { // krAmati - p.op_term("7.3.76", i, op::text("krAm")); + p.run_at("7.3.76", i, op::text("krAm")); } else if anga.has_u_in(&["izu~", "ga\\mx~", "ya\\ma~"]) { // icCati, gacCati, yacCati - p.op_term("7.3.77", i, op::antya("C")); + p.run_at("7.3.77", i, op::antya("C")); } else if anga.has_u_in(pa_ghra) && !anga.has_gana(Adadi) && !anga.has_gana(Juhotyadi) { // Check ganas above to avoid `pA rakzaRe` (pAti), `f gatO` (iyarti) let to_piba_jighra = |p: &mut Prakriya| { @@ -414,15 +414,15 @@ fn try_shiti(p: &mut Prakriya) -> Option<()> { if anga.has_u("sf\\") { // sartervegitāyāṃ gatau dhāvādeśam icchanti। anyatra sarati, anusarati // ityeva bhavati. (kAzikA) - can_run = !p.op_optional(Rule::Kashika("7.3.78"), |_| {}); + can_run = !p.run_optional(Rule::Kashika("7.3.78"), |_| {}); } if can_run { // pibati, jiGrati, Damati, ... - p.op("7.3.78", to_piba_jighra); + p.run("7.3.78", to_piba_jighra); } } else if anga.has_u_in(&["jYA\\", "janI~\\"]) { // jAnAti, jAyate - p.op_term("7.3.79", i, op::text("jA")); + p.run_at("7.3.79", i, op::text("jA")); } Some(()) @@ -437,7 +437,7 @@ fn try_pvadinam_hrasva(p: &mut Prakriya) -> Option<()> { if anga.has_u_in(gana::PU_ADI) && anga.has_gana(Kryadi) { // punAti, stfRAti, riRAti // All of these dhatus end in vowels. - p.op_term("7.3.80", i, |t| { + p.run_at("7.3.80", i, |t| { t.find_and_replace_text("U", "u"); t.find_and_replace_text("F", "f"); t.find_and_replace_text("I", "i"); @@ -455,12 +455,12 @@ fn try_add_num_agama_for_sarvanamasthana(p: &mut Prakriya) -> Option<()> { if sup.has_tag(T::Sarvanamasthana) { if anga.has_tag_in(&[T::udit, T::fdit]) && !anga.is_dhatu() { - p.op_term("7.1.70", i, op::mit("n")); + p.run_at("7.1.70", i, op::mit("n")); } else if napum && (anga.has_antya(&*JHAL) || anga.has_antya(&*AC)) { - p.op_term("7.1.72", i, op::mit("n")); + p.run_at("7.1.72", i, op::mit("n")); } } else if napum && anga.has_antya(&*IK) && sup.has_adi(&*AC) && sup.has_tag(T::Vibhakti) { - p.op_term("7.1.73", i, op::mit("n")); + p.run_at("7.1.73", i, op::mit("n")); } Some(()) @@ -475,17 +475,14 @@ fn try_add_agamas_to_sup(p: &mut Prakriya) -> Option<()> { let i_anga = i_last - 1; let anga = p.get(i_last - 1)?; if anga.has_tag(T::Sarvanama) { - p.op("7.1.52", |p| op::insert_agama_before(p, i_last, "su~w")); - it_samjna::run(p, i_last).ok()?; + op::insert_agama_at("7.1.52", p, i_last, "su~w"); } else if anga.has_text("tri") { // trayaH - p.op_term("7.1.53", i_anga, op::text("traya")); + p.run_at("7.1.53", i_anga, op::text("traya")); } else if anga.is_hrasva() || anga.has_tag(T::Nadi) || anga.has_tag(T::StriNyap) { - p.op("7.1.54", |p| op::insert_agama_before(p, i_last, "nu~w")); - it_samjna::run(p, i_last).ok()?; + op::insert_agama_at("7.1.54", p, i_last, "nu~w"); } else if anga.has_tag(T::Sat) || anga.has_text("catur") { - p.op("7.1.55", |p| op::insert_agama_before(p, i_last, "nu~w")); - it_samjna::run(p, i_last).ok()?; + op::insert_agama_at("7.1.55", p, i_last, "nu~w"); } } @@ -498,7 +495,7 @@ fn try_add_num_agama_for_dhatu_before_asiddhavat(p: &mut Prakriya) -> Option<()> let n = p.view(i + 1)?; if anga.has_text_in(&["masj", "naS"]) && n.has_adi(&*JHAL) { - p.op_term("7.1.60", i, |t| { + p.run_at("7.1.60", i, |t| { if t.has_text("masj") { // "masjerantyāt pūrva numam icchanti anuṣaṅgādilopārtham।" (KV). t.set_text("masnj"); @@ -524,9 +521,10 @@ fn try_add_num_agama_for_dhatu(p: &mut Prakriya) -> Option<()> { let n = p.view(i + 1)?; if anga.has_u_in(gana::MUC_ADI) && n.has_u("Sa") { // muYcati - p.op_term("7.1.59", i, op::mit("n")); + p.run_at("7.1.59", i, op::mit("n")); } else if anga.has_u_in(gana::TRMPH_ADI) && n.has_u("Sa") { - p.op_term("7.1.59.v1", i, op::mit("n")); + // tfmPati, ... + p.run_at("7.1.59.v1", i, op::mit("n")); } let anga = p.get(i)?; @@ -542,27 +540,27 @@ fn try_add_num_agama_for_dhatu(p: &mut Prakriya) -> Option<()> { } else if n.has_u_in(&["Kal", "GaY"]) { if has_upasarga { // pralamBa, ... - p.op_term("7.1.67", i, op::mit("n")); + p.run_at("7.1.67", i, op::mit("n")); } // Otherwise, we get lABa, etc. } else if !has_upasarga && n.has_u_in(&["ciR", "Ramu~l"]) { - p.op_optional("7.1.69", op::t(i, op::mit("n"))); + p.run_optional_at("7.1.69", i, op::mit("n")); } else if n.has_adi(&*AC) && !n.has_u("Sap") && !liti { - p.op_term("7.1.64", i, op::mit("n")); + p.run_at("7.1.64", i, op::mit("n")); } else if yi && i > 0 && p.has(i - 1, |t| t.has_u("AN")) { - p.op_term("7.1.65", i, op::mit("n")); + p.run_at("7.1.65", i, op::mit("n")); } else if yi && i > 0 && p.has(i - 1, |t| t.has_u("upa")) { - p.op_optional("7.1.66", op::t(i, op::mit("n"))); + p.run_optional_at("7.1.66", i, op::mit("n")); } } else if n.has_adi(&*AC) { if anga.has_text("raD") || (anga.has_text("jaB") && anga.has_u("jaBI~\\")) { if anga.has_u("ra\\Da~") && n.first()?.is_it_agama() && !liti { p.step("7.1.62"); } else { - p.op_term("7.1.61", i, op::mit("n")); + p.run_at("7.1.61", i, op::mit("n")); } } else if anga.has_u("ra\\Ba~\\") && anga.has_text("raB") && !n.has_u("Sap") && !liti { - p.op_term("7.1.63", i, op::mit("n")); + p.run_at("7.1.63", i, op::mit("n")); } } @@ -610,8 +608,7 @@ pub fn try_add_iit_agama(p: &mut Prakriya) -> Option<()> { } if let Some(rule) = rule { - p.op(rule, |p| op::insert_agama_before(p, i_pratyaya_start, "Iw")); - it_samjna::run(p, i_pratyaya_start).ok()?; + op::insert_agama_at(rule, p, i_pratyaya_start, "Iw"); } } @@ -638,7 +635,7 @@ fn try_sarvadhatuke(p: &mut Prakriya) -> Option<()> { let contains_s = |t: &Term| t.text.contains('s'); if contains_s(agama) || contains_s(sarva) { - p.op("7.2.79", |p| { + p.run("7.2.79", |p| { let agama = p.get_mut(i_agama).expect("present"); agama.text.retain(|c| c != 's'); @@ -656,19 +653,19 @@ fn try_sarvadhatuke(p: &mut Prakriya) -> Option<()> { let anga = p.get(i_anga)?; let agama = p.get(i_agama)?; if anga.has_antya('a') && agama.has_text("yA") { - p.op_term("7.2.80", i_agama, op::text("iy")); + p.run_at("7.2.80", i_agama, op::text("iy")); } } else { // TODO: not sure where to put this. Not lin. if anga.has_text("As") && sarva.has_text("Ana") { // AsIna - p.op_term("7.2.83", i, op::adi("I")); + p.run_at("7.2.83", i, op::adi("I")); } else if anga.has_antya('a') && sarva.has_text("Ana") { // pacamAna, ... op::append_agama("7.2.80", p, i_anga, "mu~k"); } else if anga.has_antya('a') && sarva.has_adi('A') && sarva.has_tag(T::Nit) { // pacayAt --> pacet - p.op_term("7.2.81", i, op::adi("iy")); + p.run_at("7.2.81", i, op::adi("iy")); } } @@ -687,20 +684,20 @@ fn try_change_anga_before_y(p: &mut Prakriya) -> Option<()> { let yi_kniti = n.has_adi('y') && n.is_knit(); if anga.has_u("SIN") && n.has_tag(T::Sarvadhatuka) { - p.op_term("7.4.21", i, op::text("Se")); + p.run_at("7.4.21", i, op::text("Se")); } else if anga.has_u("SIN") && yi_kniti { - p.op_term("7.4.22", i, op::text("Say")); + p.run_at("7.4.22", i, op::text("Say")); p.set(i, |t| t.force_save_sthanivat()); } else if has_upasarga && yi_kniti && anga.has_u("Uha~\\") { // Example: sam[u]hyate - p.op_term("7.4.23", i, op::adi("u")); + p.run_at("7.4.23", i, op::adi("u")); } else if has_upasarga && yi_kniti && anga.has_u("i\\R") && p.terms().last()?.has_lakshana("li~N") { // Example: ud[i]yAt - p.op_term("7.4.24", i, op::adi("i")); + p.run_at("7.4.24", i, op::adi("i")); } else if anga.has_antya('f') { let dhatu = p.get(i)?; let n = p.view(i_n)?; @@ -716,27 +713,27 @@ fn try_change_anga_before_y(p: &mut Prakriya) -> Option<()> { if dhatu.is_samyogadi() || dhatu.has_text("f") { if n.has_u("yaN") { // arAryate - p.op_term("7.4.30", i, op::antya("ar")); + p.run_at("7.4.30", i, op::antya("ar")); } else if is_sha_yak_lin { // smaryate, aryate, ... - p.op_term("7.4.29", i, op::antya("ar")); + p.run_at("7.4.29", i, op::antya("ar")); } } else if is_sha_yak_lin { // kriyate, kriyAt, ... - p.op_term("7.4.28", i, op::antya("ri")); + p.run_at("7.4.28", i, op::antya("ri")); } else if akrt_sarva && (n.has_adi('y') || n.has_u("cvi")) { // mantrIyati - p.op_term("7.4.27", i, op::antya("rI")); + p.run_at("7.4.27", i, op::antya("rI")); } } else if anga.has_u("ha\\na~") && n.has_u("yaN") { - p.op_optional("7.4.30.v1", op::t(i, op::text("GnI"))); + p.run_optional_at("7.4.30.v1", i, op::text("GnI")); } else if anga.has_u_in(&["GrA\\", "DmA\\"]) && n.has_u("yaN") { - p.op_term("7.4.31", i, op::antya("I")); + p.run_at("7.4.31", i, op::antya("I")); } else if n.has_adi('y') { let sub = al::to_dirgha(anga.antya()?)?; if akrt_sarva && n.is_knit() { // suKAyate - p.op_term("7.4.25", i, op::antya(&sub.to_string())); + p.run_at("7.4.25", i, op::antya(&sub.to_string())); } } @@ -744,10 +741,10 @@ fn try_change_anga_before_y(p: &mut Prakriya) -> Option<()> { let n = p.get(i + 1)?; if n.has_u("cvi~") { if anga.has_antya(&*AA) { - p.op_term("7.4.32", i, op::antya("I")); + p.run_at("7.4.32", i, op::antya("I")); } else { let sub = al::to_dirgha(anga.antya()?)?; - p.op_term("7.4.26", i, op::antya(&sub.to_string())); + p.run_at("7.4.26", i, op::antya(&sub.to_string())); } } @@ -762,7 +759,7 @@ fn try_anga_changes_to_t(p: &mut Prakriya, i_anga: usize) -> Option<()> { let anga = p.get(i_anga)?; let n = p.view(i_anga + 1)?; if anga.has_antya('s') && n.has_adi('s') && n.last()?.is_ardhadhatuka() { - p.op_term("7.4.49", i_anga, op::antya("t")); + p.run_at("7.4.49", i_anga, op::antya("t")); } let anga = p.get(i_anga)?; @@ -770,28 +767,28 @@ fn try_anga_changes_to_t(p: &mut Prakriya, i_anga: usize) -> Option<()> { if anga.has_text_in(&["dyut", "mA", "sA", "sTA"]) { let code = "7.4.40"; if anga.has_text("dyut") { - p.op_term(code, i_anga, op::upadha("i")); + p.run_at(code, i_anga, op::upadha("i")); } else { - p.op_term(code, i_anga, op::antya("i")); + p.run_at(code, i_anga, op::antya("i")); } } else if anga.has_text_in(&["SA", "CA"]) { - p.op_optional("7.4.41", op::t(i_anga, op::antya("i"))); + p.run_optional_at("7.4.41", i_anga, op::antya("i")); } else if anga.has_u("quDA\\Y") { - p.op_term("7.4.42", i_anga, op::text("hi")); + p.run_at("7.4.42", i_anga, op::text("hi")); } else if anga.has_u("o~hA\\k") && next.has_u("ktvA") { // Only `o~hA\\k`. ("jahāternideśāt jihīterna bhavati। hātvā" -- KV) - p.op_term("7.4.43", i_anga, op::text("hi")); + p.run_at("7.4.43", i_anga, op::text("hi")); } else if anga.has_tag(T::Ghu) && anga.has_adi('d') { if i_anga > 0 && p.has(i_anga - 1, |t| t.is_upasarga() && t.has_antya(&*AC)) { - p.op_term("7.4.47", i_anga, op::text("t")); + p.run_at("7.4.47", i_anga, op::text("t")); } else { - p.op_term("7.4.46", i_anga, op::text("dat")); + p.run_at("7.4.46", i_anga, op::text("dat")); } } } else { let next = p.get(i_anga + 1)?; if anga.has_text("ap") && next.has_adi('B') { - p.op_term("7.4.48", i_anga, op::text("at")); + p.run_at("7.4.48", i_anga, op::text("at")); } } @@ -809,18 +806,15 @@ pub fn try_add_or_remove_nit(p: &mut Prakriya) -> Option<()> { let last = p.get(i)?; if anga.has_text("go") && last.is_sarvanamasthana() { - p.op_term("7.1.90", i, op::add_tag(T::Rit)); + p.run_at("7.1.90", i, op::add_tag(T::Rit)); } else if anga.has_antya('o') && last.is_sarvanamasthana() { - p.op_term("7.1.90.v1", i, op::add_tag(T::Rit)); + p.run_at("7.1.90.v1", i, op::add_tag(T::Rit)); } else if last.has_u("Ral") && last.has_tag(T::Uttama) { - p.op_optional( - "7.1.91", - op::t(i, |t| { - t.remove_tag(T::Rit); - }), - ); + p.run_optional_at("7.1.91", i, |t| { + t.remove_tag(T::Rit); + }); } else if anga.has_text("saKi") && last.is_sarvanamasthana() && !last.has_tag(T::Sambuddhi) { - p.op_term("7.1.92", i, op::add_tag(T::Rit)); + p.run_at("7.1.92", i, op::add_tag(T::Rit)); } Some(()) @@ -836,13 +830,13 @@ fn try_tas_asti_lopa(p: &mut Prakriya, i: usize) -> Option<()> { let n = p.get(i_n)?; if n.has_adi('s') { // kartAsi, asi - p.op_term("7.4.50", i, op::antya("")); + p.run_at("7.4.50", i, op::antya("")); } else if n.has_adi('r') { // kartArO - p.op_term("7.4.51", i, op::antya("")); + p.run_at("7.4.51", i, op::antya("")); } else if n.has_adi('e') && !n.has_u("eS") { // kartAhe - p.op_term("7.4.52", i, op::antya("h")); + p.run_at("7.4.52", i, op::antya("h")); } } @@ -856,11 +850,11 @@ fn unknown(p: &mut Prakriya, i: usize) -> Option<()> { if anga.has_u("SIN") && anga.has_text("SI") { if n.is_knit() && n.has_adi('y') { - p.op_term("7.4.22", i, op::antya("ay")); + p.run_at("7.4.22", i, op::antya("ay")); p.set(i, |t| t.force_save_sthanivat()); } else if n.has_tag(T::Sarvadhatuka) { let sub = al::to_guna(anga.antya()?)?; - p.op_term("7.4.22", i, op::antya(sub)); + p.run_at("7.4.22", i, op::antya(sub)); p.set(i, |t| t.force_save_sthanivat()); } } @@ -876,8 +870,7 @@ fn try_add_piti_krti_tuk(p: &mut Prakriya) -> Option<()> { for i in 0..p.terms().len() { let cur = p.get(i)?; if cur.is_hrasva() && p.has(i + 1, |t| t.has_all_tags(&[T::pit, T::Krt])) { - p.op("6.1.71", |p| op::insert_agama_after(p, i, "tu~k")); - it_samjna::run(p, i + 1).expect("ok"); + op::insert_agama_at("6.1.71", p, i + 1, "tu~k"); } } @@ -885,25 +878,29 @@ fn try_add_piti_krti_tuk(p: &mut Prakriya) -> Option<()> { } fn try_add_tuk_agama(p: &mut Prakriya) -> Option<()> { - char_rule(p, xy(|x, y| al::is_ac(x) && y == 'C'), |p, text, i| { - // tena cicchidatuḥ, cicchiduḥ ityatra tukabhyāsasya grahaṇena na - // gṛhyate iti halādiḥśeṣeṇa na nivartyate - // -- kAzikA - if let Some(t) = get_at(p, i + 1) { - if t.has_tag(T::Abhyasa) { - return false; + let mut cp = CharPrakriya::new(p); + cp.for_chars( + // [dummy comment for cargo fmt] + xy(|x, y| al::is_ac(x) && y == 'C'), + |p, text, i| { + // tena cicchidatuḥ, cicchiduḥ ityatra tukabhyāsasya grahaṇena na + // gṛhyate iti halādiḥśeṣeṇa na nivartyate + // -- kAzikA + if let Some(t) = get_at(p, i + 1) { + if t.is_abhyasa() { + return false; + } } - } - let x = text.as_bytes()[i] as char; - set_at(p, i + 1, "tC"); - if al::is_dirgha(x) { - p.step("6.1.73"); - } else { - p.step("6.1.72"); - } - true - }); + let x = text.as_bytes()[i] as char; + if al::is_dirgha(x) { + p.run("6.1.75", |p| p.set_char_at(i + 1, "tC")); + } else { + p.run("6.1.73", |p| p.set_char_at(i + 1, "tC")); + } + true + }, + ); Some(()) } @@ -937,7 +934,7 @@ fn try_change_cu_to_ku(p: &mut Prakriya, i: usize) -> Option<()> { p.step("7.3.60"); true } else if anga.has_u("vancu~") { - p.op_optional("7.3.63", |_| {}) + p.run_optional("7.3.63", |_| {}) } else if n.has_u("Ryat") { if anga.has_u_in(&["ya\\ja~^", "quyAcf~^", "ruca~\\", "fca~"]) || (anga.has_u("va\\ca~") && has_upasarga("pra")) @@ -945,13 +942,13 @@ fn try_change_cu_to_ku(p: &mut Prakriya, i: usize) -> Option<()> { p.step("7.3.66"); true } else if anga.has_u("va\\ca~") { - p.op_optional("7.3.67", |_| {}) + p.run_optional("7.3.67", |_| {}) } else if anga.has_u("yu\\ji~^r") && (has_upasarga("pra") || has_upasarga("ni")) { - p.op_optional("7.3.68", |_| {}) + p.run_optional("7.3.68", |_| {}) } else if anga.has_u("Bu\\ja~") { - p.op_optional("7.3.69", |_| {}) + p.run_optional("7.3.69", |_| {}) } else if has_c_j_antya { - p.op_optional("7.3.65", |_| {}) + p.run_optional("7.3.65", |_| {}) } else { false } @@ -965,19 +962,19 @@ fn try_change_cu_to_ku(p: &mut Prakriya, i: usize) -> Option<()> { // Skip } else if has_c_j_antya && (n.has_tag(T::Git) || n.has_u("Ryat")) { let sub = convert(anga.antya()?)?; - p.op_term("7.3.52", i, op::antya(sub)); + p.run_at("7.3.52", i, op::antya(sub)); } else if anga.has_u("ha\\na~") && anga.has_adi('h') { if anga.has_tag(T::Abhyasta) { - p.op_term("7.3.55", i, op::adi("G")); + p.run_at("7.3.55", i, op::adi("G")); } else if n.has_tag_in(&[T::Yit, T::Rit]) || anga.has_text("hn") { - p.op_term("7.3.54", i, op::adi("G")); + p.run_at("7.3.54", i, op::adi("G")); } } else if anga.has_u("hi\\") && anga.has_tag(T::Abhyasta) && !n.has_u("caN") { - p.op_term("7.3.56", i, op::adi("G")); + p.run_at("7.3.56", i, op::adi("G")); } else if sanlitoh && anga.has_u("ji\\") && anga.has_gana(Bhvadi) { - p.op_term("7.3.57", i, op::adi("g")); + p.run_at("7.3.57", i, op::adi("g")); } else if sanlitoh && anga.has_u("ci\\Y") { - p.op_optional("7.3.58", op::t(i, op::adi("k"))); + p.run_optional_at("7.3.58", i, op::adi("k")); } Some(()) @@ -988,12 +985,12 @@ fn try_dhatu_rt_adesha(p: &mut Prakriya, i: usize) -> Option<()> { if dhatu.has_antya('F') { if dhatu.has_upadha(&*OSHTHYA) { - p.op_term("7.1.102", i, op::antya("ur")); + p.run_at("7.1.102", i, op::antya("ur")); } else { - p.op_term("7.1.100", i, op::antya("ir")); + p.run_at("7.1.100", i, op::antya("ir")); } } else if dhatu.has_upadha('F') { - p.op_term("7.1.101", i, op::upadha("ir")); + p.run_at("7.1.101", i, op::upadha("ir")); } else { return None; } @@ -1007,18 +1004,22 @@ fn try_dhatu_rt_adesha(p: &mut Prakriya, i: usize) -> Option<()> { /// /// (7.3.101 - 7.3.111) fn try_ato_dirgha(p: &mut Prakriya, i: usize) -> Option<()> { - let n = p.view(i + 1)?; + // HACK: work around lack of support for "ekah pUrvaparayoH" by skipping empty wAp-pratyaya. + let i_next = p.find_next_where(i, |t| !t.is_empty())?; + + let n = p.view(i_next)?; let ends_in_a = |t: &Term| t.has_antya('a'); if n.has_tag(T::Sarvadhatuka) { if p.has(i, ends_in_a) && n.has_adi(&*YANY) { - p.op_term("7.3.101", i, op::antya("A")); + p.run_at("7.3.101", i, op::antya("A")); } } else if n.has_tag(T::Sup) { let anga = p.get(i)?; - let sup = p.view(i + 1)?; - let is_aap = anga.has_antya('A') && anga.has_tag(T::StriNyap); + let sup = p.view(i_next)?; + let is_aap = (anga.has_antya('A') && anga.has_tag(T::StriNyap)) + || p.has(i + 1, |t| t.has_u_in(&["wAp"])); let is_sambuddhi = sup.has_tag(T::Sambuddhi); // > bhyamādeśe kṛte śeṣelope ca bahuvacane jhalyet iti etvaṃ prāpnoti, tadaṅgavṛtte @@ -1028,35 +1029,35 @@ fn try_ato_dirgha(p: &mut Prakriya, i: usize) -> Option<()> { if anga.has_antya('a') && !purva_anga_vrtti { if sup.has_tag(T::Bahuvacana) && sup.has_adi(&*JHAL) { // deveByaH - p.op_term("7.3.103", i, op::antya("e")); + p.run_at("7.3.103", i, op::antya("e")); } else if sup.has_adi(&*YANY) { - p.op_term("7.3.102", i, op::antya("A")); + p.run_at("7.3.102", i, op::antya("A")); } else if sup.last()?.has_text("os") { // devayoH - p.op_term("7.3.104", i, op::antya("e")); + p.run_at("7.3.104", i, op::antya("e")); } } else if is_aap && (sup.last()?.has_text("os") || sup.has_u("wA")) { // senayoH - p.op_term("7.3.105", i, op::antya("e")); + p.run_at("7.3.105", i, op::antya("e")); } else if is_sambuddhi && (anga.has_text_in(&["ambA", "akkA", "allA"]) || anga.has_tag(T::Nadi)) { // amba, alla, akka, nadi let sub = al::to_hrasva(anga.antya()?)?; - p.op_term("7.3.107", i, op::antya(&sub.to_string())); + p.run_at("7.3.107", i, op::antya(&sub.to_string())); } else if is_sambuddhi && is_aap { // sene - p.op_term("7.3.106", i, op::antya("e")); + p.run_at("7.3.106", i, op::antya("e")); } else { let anga = p.get(i)?; if al::is_hrasva(anga.antya()?) && !anga.has_antya('a') { let sub = al::to_guna(anga.antya()?)?; if sup.has_tag(T::Sambuddhi) { // agne, vAyo - p.op_term("7.3.108", i, op::antya(sub)); + p.run_at("7.3.108", i, op::antya(sub)); } else if sup.has_u("jas") { // agnayaH, vAyavaH - p.op_term("7.3.109", i, op::antya(sub)); + p.run_at("7.3.109", i, op::antya(sub)); } } } @@ -1107,10 +1108,10 @@ fn try_sic_vrddhi(p: &mut Prakriya) -> Option<()> { if dhatu.has_upadha('a') && (dhatu.has_antya('l') | dhatu.has_antya('r')) { let sub = al::to_vrddhi(dhatu.upadha()?)?; // apavAda to 7.2.7 below, so run this first. - p.op_term("7.2.2", i, op::upadha(sub)); + p.run_at("7.2.2", i, op::upadha(sub)); } else if dhatu.has_u_in(&["vada~", "vraja~"]) { // For the second half of 7.2.3, see further beelow. - p.op_term("7.2.3", i, op::upadha("A")); + p.run_at("7.2.3", i, op::upadha("A")); } let mut block = None; @@ -1143,11 +1144,11 @@ fn try_sic_vrddhi(p: &mut Prakriya) -> Option<()> { let dhatu = p.get(i)?; if dhatu.has_antya(&*AC) { let sub = al::to_vrddhi(dhatu.antya()?)?; - p.op_term("7.2.1", i, op::antya(sub)); + p.run_at("7.2.1", i, op::antya(sub)); } else if dhatu.is_samyoganta() { // 7.2.3 applies to the final vowel generally, even if samyoganta let n_3 = dhatu.get_at(dhatu.text.len() - 3)?; - p.op_term("7.2.3", i, |t| { + p.run_at("7.2.3", i, |t| { if let Some(sub) = al::to_vrddhi(n_3) { let i = t.text.len() - 3; t.text.replace_range(i..=i, sub); @@ -1158,7 +1159,7 @@ fn try_sic_vrddhi(p: &mut Prakriya) -> Option<()> { }); } else { let sub = al::to_vrddhi(dhatu.upadha()?)?; - p.op_term("7.2.3", i, op::upadha(sub)); + p.run_at("7.2.3", i, op::upadha(sub)); } Some(()) @@ -1184,13 +1185,10 @@ fn try_cani_before_guna(p: &mut Prakriya) -> Option<()> { // 7.4.7 blocks guna. if dhatu.has_upadha(&*FF) && is_nici && (is_cani || will_be_cani) { - p.op_optional( - "7.4.7", - op::t(i, |t| { - t.set_upadha("f"); - t.add_tag(T::FlagGunaApavada); - }), - ); + p.run_optional_at("7.4.7", i, |t| { + t.set_upadha("f"); + t.add_tag(T::FlagGunaApavada); + }); } Some(()) @@ -1221,7 +1219,7 @@ fn try_cani_after_guna(p: &mut Prakriya) -> Option<()> { "pIqa~", ]) { let sub = al::to_hrasva(dhatu.upadha()?)?; - p.op_optional("7.4.3", op::t(i, op::upadha(&sub.to_string()))); + p.run_optional_at("7.4.3", i, op::upadha(&sub.to_string())); return Some(()); } @@ -1229,18 +1227,18 @@ fn try_cani_after_guna(p: &mut Prakriya) -> Option<()> { let mut done = false; if i > 0 && dhatu.has_u("pA\\") && dhatu.has_gana(Bhvadi) { // apIpyat - p.op("7.4.4", |p| { + p.run("7.4.4", |p| { p.set(i, |t| t.set_antya("")); p.set(i - 1, |t| t.set_antya("I")); }); done = true; } else if i > 0 && dhatu.has_u("zWA\\") { // atizWapat - p.op_term("7.4.5", i, |t| t.set_antya("i")); + p.run_at("7.4.5", i, |t| t.set_antya("i")); done = true; } else if i > 0 && dhatu.has_u("GrA\\") { // ajiGripat, ajiGrapat - done = p.op_optional("7.4.6", op::t(i, |t| t.set_antya("i"))); + done = p.run_optional_at("7.4.6", i, |t| t.set_antya("i")); } if done { @@ -1254,13 +1252,13 @@ fn try_cani_after_guna(p: &mut Prakriya) -> Option<()> { if dhatu.has_tag_in(&[T::FlagAtLopa, T::fdit]) || dhatu.has_text("SAs") { p.step("7.4.2"); } else if !dhatu.has_upadha(sub) { - p.op_term("7.4.1", i, op::upadha(&sub.to_string())); + p.run_at("7.4.1", i, op::upadha(&sub.to_string())); } } else if p.has(i + 1, |t| t.is_agama()) && dhatu.has_antya(&*AC) { // HACK for puk-agama. let sub = al::to_hrasva(dhatu.antya()?)?; if !dhatu.has_antya(sub) { - p.op_term("7.4.1", i, op::antya(&sub.to_string())); + p.run_at("7.4.1", i, op::antya(&sub.to_string())); } } @@ -1281,25 +1279,25 @@ fn try_change_anga_before_an(p: &mut Prakriya) -> Option<()> { if dhatu.has_antya(&*FF) || dhatu.has_text("dfS") { // asarat, adarSat if dhatu.has_text("dfS") { - p.op_term("7.4.16", i, op::text("darS")); + p.run_at("7.4.16", i, op::text("darS")); } else { - p.op_term("7.4.16", i, op::antya("ar")); + p.run_at("7.4.16", i, op::antya("ar")); } } else if dhatu.has_u("asu~") { // AsTat - p.op("7.4.17", |p| { + p.run("7.4.17", |p| { p.insert_after(i, Term::make_agama("Tu~k")); it_samjna::run(p, i + 1).expect("ok"); }); } else if dhatu.has_text("Svi") { // aSvat - p.op_term("7.4.18", i, op::antya("a")); + p.run_at("7.4.18", i, op::antya("a")); } else if dhatu.has_text("pat") { // apaptat - p.op_term("7.4.19", i, op::mit("p")); + p.run_at("7.4.19", i, op::mit("p")); } else if dhatu.has_text("vac") { // avocat - p.op_term("7.4.20", i, op::mit("u")); + p.run_at("7.4.20", i, op::mit("u")); } Some(()) @@ -1316,13 +1314,13 @@ fn try_ksa_lopa(p: &mut Prakriya) -> Option<()> { if vikarana.has_u("ksa") { if tin.has_adi(&*AC) { - p.op_term("7.3.72", i, op::antya("")); + p.run_at("7.3.72", i, op::antya("")); } else if dhatu.has_text_in(&["duh", "dih", "lih", "guh"]) && tin.is_atmanepada() && tin.has_adi(&*DANTYA) { // aduhvahi/aDukzAvahi, adugDA/aDukzata, ... - p.op_optional("7.3.73", op::t(i, op::luk)); + p.run_optional_at("7.3.73", i, op::luk); } } @@ -1345,7 +1343,7 @@ fn try_add_agama_before_ni(p: &mut Prakriya) -> Option<()> { } let optional_append_agama = |rule, p: &mut Prakriya, i, sub| -> bool { - if p.op_optional(rule, |p| op::insert_agama_after(p, i, sub)) { + if p.run_optional(rule, |p| op::insert_agama_after(p, i, sub)) { it_samjna::run(p, i + 1).expect("ok"); true } else { @@ -1380,11 +1378,11 @@ fn try_add_agama_before_ni(p: &mut Prakriya) -> Option<()> { } else if dhatu.has_u("YiBI\\") && p.has_tag(T::FlagHetuBhaya) { op::append_agama("7.3.40", p, i, "zu~k"); } else if dhatu.has_text("sPAy") { - p.op_term("7.3.41", i, op::antya("v")); + p.run_at("7.3.41", i, op::antya("v")); } else if dhatu.has_text("Sad") { - p.op_optional("7.3.42", op::t(i, op::antya("t"))); + p.run_optional_at("7.3.42", i, op::antya("t")); } else if dhatu.has_text("ruh") { - p.op_optional("7.3.43", op::t(i, op::antya("p"))); + p.run_optional_at("7.3.43", i, op::antya("p")); } Some(()) @@ -1394,35 +1392,35 @@ fn try_add_agama_before_ni(p: &mut Prakriya) -> Option<()> { /// sound. fn try_maparyanta_for_asmad_and_yusmad(p: &mut Prakriya) -> Option<()> { let i = p.find_first_where(|t| t.has_u_in(&["asmad", "yuzmad"]))?; - let sup = p.get_if(i + 1, |t| t.has_tag(T::Vibhakti))?; + let sup = p.get_if(i + 1, |t| t.is_vibhakti())?; if sup.has_tag(T::Dvivacana) { - p.op_term("7.2.92", i, |t| { + p.run_at("7.2.92", i, |t| { t.find_and_replace_text("yuzm", "yuva"); t.find_and_replace_text("asm", "Ava"); }); } else if sup.has_lakshana("jas") { - p.op_term("7.2.93", i, |t| { + p.run_at("7.2.93", i, |t| { t.find_and_replace_text("yuzm", "yUya"); t.find_and_replace_text("asm", "vaya"); }); } else if sup.has_lakshana("su~") { - p.op_term("7.2.94", i, |t| { + p.run_at("7.2.94", i, |t| { t.find_and_replace_text("yuzm", "tva"); t.find_and_replace_text("asm", "aha"); }); } else if sup.has_lakshana("Ne") { - p.op_term("7.2.95", i, |t| { + p.run_at("7.2.95", i, |t| { t.find_and_replace_text("yuzm", "tuBya"); t.find_and_replace_text("asm", "mahya"); }); } else if sup.has_lakshana("Nas") { - p.op_term("7.2.96", i, |t| { + p.run_at("7.2.96", i, |t| { t.find_and_replace_text("yuzm", "tava"); t.find_and_replace_text("asm", "mama"); }); } else if sup.has_tag(T::Ekavacana) { - p.op_term("7.2.97", i, |t| { + p.run_at("7.2.97", i, |t| { t.find_and_replace_text("yuzm", "tva"); t.find_and_replace_text("asm", "ma"); }); @@ -1442,24 +1440,21 @@ fn try_anga_adesha_before_vibhakti_changes(p: &mut Prakriya) -> Option<()> { if anga.has_text("azwan") && v.is_vibhakti() { // Optional per Kashika. - p.op_optional( - "7.2.84", - op::t(i, |t| { - t.set_antya(""); - t.set_antya("A"); - }), - ); + p.run_optional_at("7.2.84", i, |t| { + t.set_antya(""); + t.set_antya("A"); + }); } else if anga.has_text_in(&["tri", "catur"]) && p.has_tag(T::Stri) { - p.op_term("7.2.99", i, |t| { + p.run_at("7.2.99", i, |t| { t.find_and_replace_text("tri", "tisf"); t.find_and_replace_text("catur", "catasf"); }); let v = p.get(i + 1)?; if v.has_adi(&*AC) { - p.op_term("7.2.100", i, op::antya("r")); + p.run_at("7.2.100", i, op::antya("r")); } } else if anga.has_text("jarA") && v.has_adi(&*AC) { - p.op_optional("7.2.101", op::t(i, op::text("jaras"))); + p.run_optional_at("7.2.101", i, op::text("jaras")); } else if anga.has_u_in(stem_gana::TYAD_ADI) { let i_v = i + 1; let anga = p.get(i)?; @@ -1468,7 +1463,7 @@ fn try_anga_adesha_before_vibhakti_changes(p: &mut Prakriya) -> Option<()> { if sau && anga.has_u("adas") { // asO - p.op("7.2.107", |p| { + p.run("7.2.107", |p| { p.set(i, |t| t.set_antya("O")); p.set(i + 1, op::lopa); }); @@ -1476,31 +1471,31 @@ fn try_anga_adesha_before_vibhakti_changes(p: &mut Prakriya) -> Option<()> { // check for `!v.is_empty()` to allow `idam`. p.step("7.2.108"); if p.has_tag(T::Pum) { - p.op_term("7.2.111", i, |t| t.set_text("ayam")); + p.run_at("7.2.111", i, |t| t.set_text("ayam")); } else { - p.op_term("7.2.110", i, |t| t.set_text("iyam")); + p.run_at("7.2.110", i, |t| t.set_text("iyam")); } } else if v.is_vibhakti() & &!v.is_empty() { // tyaH, tyO, tye, ... - p.op_term("7.2.102", i, op::antya("a")); + p.run_at("7.2.102", i, op::antya("a")); } // 7.2.109 - 7.2.112 are in the other function. let anga = p.get(i)?; if sau && !anga.has_antya('d') && !anga.has_antya('t') { - p.op_term("7.2.106", i, |t| { + p.run_at("7.2.106", i, |t| { t.find_and_replace_text("d", "s"); t.find_and_replace_text("t", "s"); }); } } else if anga.has_text("kim") { if v.has_adi('t') || v.has_adi('h') { - p.op_term("7.2.104", i, op::text("ku")); + p.run_at("7.2.104", i, op::text("ku")); } else if v.has_u("at") { - p.op_term("7.2.105", i, op::text("kva")); + p.run_at("7.2.105", i, op::text("kva")); } else if v.is_vibhakti() && !v.is_empty() { - p.op_term("7.2.103", i, op::text("ka")); + p.run_at("7.2.103", i, op::text("ka")); } } @@ -1517,34 +1512,34 @@ fn try_anga_adesha_after_vibhakti_changes(p: &mut Prakriya) -> Option<()> { } if anga.has_text("rE") && sup.has_adi(&*HAL) { - p.op_term("7.2.85", i, op::antya("A")); + p.run_at("7.2.85", i, op::antya("A")); } else if anga.has_text_in(&["yuzmad", "asmad"]) { let anadesha = !sup.last()?.has_any_lakshana(); if sup.has_adi(&*AC) && anadesha { // mayA, tvayA - p.op_term("7.2.89", i, op::antya("y")); + p.run_at("7.2.89", i, op::antya("y")); } else if anadesha { - p.op_term("7.2.86", i, op::antya("A")); + p.run_at("7.2.86", i, op::antya("A")); } else if sup.has_tag(T::V2) { - p.op_term("7.2.87", i, op::antya("A")); + p.run_at("7.2.87", i, op::antya("A")); } else if sup.last()?.has_all_tags(&[T::V1, T::Dvivacana]) { - p.op_term("7.2.88", i, op::antya("A")); + p.run_at("7.2.88", i, op::antya("A")); } else { - p.op_term("7.2.90", i, op::antya("")); + p.run_at("7.2.90", i, op::antya("")); } } else if anga.has_text("idaa") { if sup.has_tag_in(&[T::V1, T::V2]) { // imam - p.op_term("7.2.109", i, |t| t.set_text("ima")); + p.run_at("7.2.109", i, |t| t.set_text("ima")); } else { // Other vibhaktis if sup.has_adi(&*HAL) { // asya - p.op_term("7.2.113", i, |t| t.find_and_replace_text("id", "")); + p.run_at("7.2.113", i, |t| t.find_and_replace_text("id", "")); } else { // anena - p.op_term("7.2.112", i, |t| t.set_text("ana")); + p.run_at("7.2.112", i, |t| t.set_text("ana")); } } } @@ -1560,7 +1555,7 @@ fn try_didhi_vevi_lopa(p: &mut Prakriya, i: usize) -> Option<()> { let anga = p.get(i)?; let n = p.view(i_n)?; if anga.has_u_in(&["dIDIN", "vevIN"]) && (n.has_adi(&*II) || n.has_adi('y')) { - p.op_term("7.4.53", i, op::antya("")); + p.run_at("7.4.53", i, op::antya("")); } Some(()) diff --git a/vidyut-prakriya/src/angasya/abhyasasya.rs b/vidyut-prakriya/src/angasya/abhyasasya.rs index 50e0ae6..8b3408b 100644 --- a/vidyut-prakriya/src/angasya/abhyasasya.rs +++ b/vidyut-prakriya/src/angasya/abhyasasya.rs @@ -69,7 +69,7 @@ fn try_abhyasa_lopa_and_dhatu_change_before_san(p: &mut Prakriya) -> Option<()> return None; } - let i_abhyasa = p.find_prev_where(i, |t| t.has_tag(T::Abhyasa))?; + let i_abhyasa = p.find_prev_where(i, |t| t.is_abhyasa())?; let mut do_abhyasa_lopa = true; let dhatu = p.get(i)?; @@ -80,28 +80,28 @@ fn try_abhyasa_lopa_and_dhatu_change_before_san(p: &mut Prakriya) -> Option<()> // mitsati, ripsati, lipsati, Sikzati, pitsati, ... let code = "7.4.54"; if dhatu.has_upadha(&*AC) { - p.op_term(code, i, op::upadha("is")); + p.run_at(code, i, op::upadha("is")); } else { - p.op_term(code, i, op::antya("is")); + p.run_at(code, i, op::antya("is")); } } else if dhatu.has_text("rAD") { - do_abhyasa_lopa = p.op_optional("7.4.54.v1", op::t(i, op::upadha("is"))); + do_abhyasa_lopa = p.run_optional_at("7.4.54.v1", i, op::upadha("is")); } else if dhatu.has_u_in(&["A\\px~", "jYapa~", "fDu~"]) { // Ipsati, jYIpsati, Irtsati let code = "7.4.55"; if dhatu.has_text("fD") { - p.op_term(code, i, op::upadha("Ir")); + p.run_at(code, i, op::upadha("Ir")); } else { - p.op_term(code, i, op::upadha("I")); + p.run_at(code, i, op::upadha("I")); } } else if dhatu.has_text("danB") { // Dipsati, DIpsati - if !p.op_optional("7.4.56.1", op::t(i, |t| t.set_at(1, "i"))) { - p.op_term("7.4.56.2", i, |t| t.set_at(1, "I")); + if !p.run_optional_at("7.4.56.1", i, |t| t.set_at(1, "i")) { + p.run_at("7.4.56.2", i, |t| t.set_at(1, "I")); } } else if dhatu.has_text("muc") && p.has_tag(T::Atmanepada) { // mokzate, mumukzate - do_abhyasa_lopa = p.op_optional("7.4.57", |p| { + do_abhyasa_lopa = p.run_optional("7.4.57", |p| { p.set(i, op::text("moc")); }); } else { @@ -109,9 +109,9 @@ fn try_abhyasa_lopa_and_dhatu_change_before_san(p: &mut Prakriya) -> Option<()> } if do_abhyasa_lopa { - p.op_term("7.4.58", i_abhyasa, op::lopa); + p.run_at("7.4.58", i_abhyasa, op::lopa); // HACK: also apply "halantAcca" here. - p.op_term("1.2.10", i + 1, |t| t.add_tag(T::kit)); + p.run_at("1.2.10", i + 1, |t| t.add_tag(T::kit)); } Some(()) @@ -131,7 +131,7 @@ fn run_for_sani_or_cani_at_index(p: &mut Prakriya, i: usize) -> Option<()> { "spaSa~", ]; - let i_abhyasta = p.find_next_where(i, |t| t.has_tag(T::Abhyasta))?; + let i_abhyasta = p.find_next_where(i, |t| t.is_abhyasta())?; let anga = p.get(i_abhyasta)?; @@ -153,18 +153,18 @@ fn run_for_sani_or_cani_at_index(p: &mut Prakriya, i: usize) -> Option<()> { let dhatu = p.get(i + 1)?; if dhatu.has_u_in(SMR_DR) && is_cani { // asasmarat, adadarat, - p.op_term("7.4.95", i, op::antya("a")); + p.run_at("7.4.95", i, op::antya("a")); } else { if is_sanvat { // Run rules that generally apply to san. if abhyasa.has_antya('a') { - p.op_term("7.4.79", i, op::antya("i")); + p.run_at("7.4.79", i, op::antya("i")); } else if abhyasa.has_antya(&*UU) && anga.has_adi(&*PU_YAN_J) && anga.has_at(1, &*AA) { - p.op_term("7.4.80", i, op::antya("i")); + p.run_at("7.4.80", i, op::antya("i")); } else if anga.has_u_in(SRU_ADI) && p.has(i + 2, |t| !t.has_u("san")) { // Example: sru -> sisrAvayizyati // Note that this rule must run after guna for the upadha check to be meaningful. - p.op_optional("7.4.81", op::t(i, op::antya("i"))); + p.run_optional_at("7.4.81", i, op::antya("i")); } } @@ -172,13 +172,13 @@ fn run_for_sani_or_cani_at_index(p: &mut Prakriya, i: usize) -> Option<()> { let abhyasa = p.get(i)?; let dhatu = p.get(i + 1)?; if has_at_lopa && dhatu.has_u("gaRa") { - p.op_optional("7.4.97", op::t(i, op::antya("I"))); + p.run_optional_at("7.4.97", i, op::antya("I")); } else if dhatu.has_text_in(&["vezw", "cezw"]) { - p.op_optional("7.4.96", op::t(i, op::antya("a"))); + p.run_optional_at("7.4.96", i, op::antya("a")); } else if is_laghu_cani { if !dhatu.is_samyogadi() { if let Some(sub) = al::to_dirgha(abhyasa.antya()?) { - p.op_term("7.4.94", i, op::antya(&sub.to_string())); + p.run_at("7.4.94", i, op::antya(&sub.to_string())); } } } @@ -190,7 +190,7 @@ fn run_for_sani_or_cani_at_index(p: &mut Prakriya, i: usize) -> Option<()> { // TODO: scope of this? Sarvadhatuka only? if anga.has_u_in(gana::MAN_BADHA) { let sub = al::to_dirgha(abhyasa.antya()?)?; - p.op_term("3.1.6", i, op::antya(&sub.to_string())); + p.run_at("3.1.6", i, op::antya(&sub.to_string())); } Some(()) @@ -205,7 +205,7 @@ pub fn run_for_sani_or_cani(p: &mut Prakriya) -> Option<()> { let mut i = p.find_first(T::Abhyasa)?; loop { run_for_sani_or_cani_at_index(p, i); - i = p.find_next_where(i, |t| t.has_tag(T::Abhyasa))?; + i = p.find_next_where(i, |t| t.is_abhyasa())?; } } @@ -215,7 +215,7 @@ fn try_general_rules(p: &mut Prakriya, i: usize) -> Option<()> { let dhatu = p.get(i_dhatu)?; if dhatu.has_u("zWivu~") { - p.op_optional(Rule::Kashika("6.1.64"), |p| { + p.run_optional(Rule::Kashika("6.1.64"), |p| { p.set(i, |t| t.find_and_replace_text("zW", "zT")) }); } @@ -226,14 +226,14 @@ fn try_general_rules(p: &mut Prakriya, i: usize) -> Option<()> { // Hacky samprasArana. if dhatu.has_text("svAp") { // suzvApayizati - p.op_term("7.4.67", i, op::text("sup")); + p.run_at("7.4.67", i, op::text("sup")); } else { // vididyute - p.op_term("7.4.67", i, op::text("dit")); + p.run_at("7.4.67", i, op::text("dit")); } } else if dhatu.has_text("vyaT") && last.has_lakshana("li~w") { // TODO: move this to `try_rules_for_lit`? - p.op_term("7.4.68", i, op::text("viT")); + p.run_at("7.4.68", i, op::text("viT")); } let abhyasa = p.get(i)?; @@ -260,25 +260,25 @@ fn try_general_rules(p: &mut Prakriya, i: usize) -> Option<()> { if dhatu.has_u("ku\\N") && dhatu.has_gana(Gana::Bhvadi) && n.has_u("yaN") { p.step("7.4.63"); } else { - p.op_term("7.4.62", i, op::adi(&val.to_string())); + p.run_at("7.4.62", i, op::adi(&val.to_string())); } } let abhyasa = p.get(i)?; if al::is_dirgha(abhyasa.antya()?) { let val = al::to_hrasva(abhyasa.antya()?)?; - p.op_term("7.4.59", i, op::antya(&val.to_string())); + p.run_at("7.4.59", i, op::antya(&val.to_string())); } if p.has(i, |t| t.has_antya('f')) { - p.op_term("7.4.66", i, op::antya("a")); + p.run_at("7.4.66", i, op::antya("a")); } let dhatu = p.get(i_dhatu)?; let last = p.terms().last()?; if dhatu.has_u("i\\R") && last.has_tag(T::kit) && last.has_lakshana("li~w") { // IyatuH, IyuH - p.op_term("7.4.69", i, op::adi("I")); + p.run_at("7.4.69", i, op::adi("I")); } Some(()) @@ -300,9 +300,7 @@ fn try_rules_for_lit(p: &mut Prakriya, i: usize) -> Option<()> { let last = p.terms().last()?; fn add_nut_agama(rule: impl Into, p: &mut Prakriya, i: usize) { - op::insert_agama_before(p, i, "nu~w"); - p.step(rule.into()); - it_samjna::run(p, i).expect("ok"); + op::insert_agama_at(rule.into(), p, i, "nu~w"); } if !last.has_lakshana("li~w") { @@ -310,7 +308,7 @@ fn try_rules_for_lit(p: &mut Prakriya, i: usize) -> Option<()> { } if abhyasa.has_text("a") { - p.op_term("7.4.70", i, op::text("A")); + p.run_at("7.4.70", i, op::text("A")); // From the Kashika-vrtti: // @@ -340,7 +338,7 @@ fn try_rules_for_lit(p: &mut Prakriya, i: usize) -> Option<()> { // // We check gana 1 for `BU` and gana 2 for `as` replaced by `BU`. This check excludes BU // with gana 10. - p.op_term("7.4.73", i, op::text("ba")); + p.run_at("7.4.73", i, op::text("ba")); // TODO: 7.4.74 } @@ -366,18 +364,18 @@ fn try_rules_for_slu(p: &mut Prakriya, i: usize) -> Option<()> { if dhatu.has_u_in(&["Ri\\ji~^r", "vi\\ji~^r", "vi\\zx~^"]) { // nenekti, vevekti, vevezwi let sub = al::to_guna(abhyasa.antya()?)?; - p.op_term("7.4.75", i, op::antya(sub)); + p.run_at("7.4.75", i, op::antya(sub)); } else if dhatu.has_u_in(&["quBf\\Y", "mA\\N", "o~hA\\N"]) { // biBarti, mimIte, jihIte - p.op_term("7.4.76", i, op::antya("i")); + p.run_at("7.4.76", i, op::antya("i")); } else if dhatu.has_u_in(&["f\\", "pf", "pF"]) && dhatu.has_gana(Gana::Juhotyadi) { // iyarti, piparti (allowed by both `pf` and `pF`) - p.op_term("7.4.77", i, op::antya("i")); + p.run_at("7.4.77", i, op::antya("i")); } else if dhatu.has_u("gA\\") && dhatu.has_gana(Gana::Juhotyadi) { // jigAti // (This is a chAndasa rule, but the SK applies it to derive jigAti from gA, which is a // Vedic root.) - p.op_term("7.4.78", i, op::antya("i")); + p.run_at("7.4.78", i, op::antya("i")); } Some(()) @@ -398,16 +396,11 @@ fn try_rules_for_yan(p: &mut Prakriya, i_abhyasa: usize) -> Option<()> { if !abhyasa.has_antya('a') { // Avoid guna for 'a' because it causes no change to the result. let sub = al::to_guna(abhyasa.antya()?)?; - p.op_term("7.4.82", i_abhyasa, op::antya(sub)); + p.run_at("7.4.82", i_abhyasa, op::antya(sub)); } - let add_agama = |rule, p: &mut Prakriya, i_dhatu, agama| { - p.op(rule, |p| op::insert_agama_before(p, i_dhatu, agama)); - it_samjna::run(p, i_dhatu).ok(); - }; - let optional_add_agama = |rule, p: &mut Prakriya, i_dhatu, agama| -> bool { - let added = p.op_optional(rule, |p| op::insert_agama_before(p, i_dhatu, agama)); + let added = p.run_optional(rule, |p| op::insert_agama_before(p, i_dhatu, agama)); if added { it_samjna::run(p, i_dhatu).ok(); } @@ -432,12 +425,12 @@ fn try_rules_for_yan(p: &mut Prakriya, i_abhyasa: usize) -> Option<()> { ]; if dhatu.has_u_in(VANCU_SRANSU) { - add_agama("7.4.84", p, i_dhatu, "nIk"); + op::insert_agama_at("7.4.84", p, i_dhatu, "nIk"); } else if abhyasa.has_antya('a') && dhatu.has_antya(&*ANUNASIKA) && !dhatu.has_upadha('A') { // Per commentaries, this rule applies only if the abhyasa ended with "A" before being shortened by 7.4.59. Here, we check for that condition by seeing if the dhatu has an A. // Should treat as anusvAra per commentaries, otherwise we can't derive yaMyamyate. - add_agama("7.4.85", p, i_dhatu, "Mu~k"); + op::insert_agama_at("7.4.85", p, i_dhatu, "Mu~k"); } else if dhatu.has_u_in(JAPA_JABHA) { if dhatu.has_u("da\\nSa~") { // > daśīti daśa iti daṃśiḥ ayaṃ nakāralopārtham eva nirdiṣṭaḥ। tena yaṅlukyapi @@ -447,15 +440,15 @@ fn try_rules_for_yan(p: &mut Prakriya, i_abhyasa: usize) -> Option<()> { // TODO: not sure where to put this. p.set(i_dhatu, |t| t.set_text("daS")); } - add_agama("7.4.86", p, i_dhatu, "nu~k"); + op::insert_agama_at("7.4.86", p, i_dhatu, "nu~k"); } else if dhatu.has_u_in(&["cara~", "Pala~", "YiPalA~"]) { - add_agama("7.4.87", p, i_dhatu, "nu~k"); + op::insert_agama_at("7.4.87", p, i_dhatu, "nu~k"); // Use `i_dhatu + 1` because 7.4.87 above shifted the index. let i_dhatu = i_dhatu + 1; let dhatu = p.get(i_dhatu)?; if dhatu.has_upadha('a') { - p.op_term("7.4.88", i_dhatu, op::upadha("u")); + p.run_at("7.4.88", i_dhatu, op::upadha("u")); } } else if dhatu.text.contains('f') { // varIvfScyate, ... @@ -471,15 +464,15 @@ fn try_rules_for_yan(p: &mut Prakriya, i_abhyasa: usize) -> Option<()> { let dhatu = p.get(i_dhatu)?; if dhatu.has_upadha('f') { // varIvftyate, varIvftIti, ... - add_agama("7.4.90", p, i_dhatu, "rIk"); + op::insert_agama_at("7.4.90", p, i_dhatu, "rIk"); } else if dhatu.has_antya('f') { - add_agama("7.4.92", p, i_dhatu, "rIk"); + op::insert_agama_at("7.4.92", p, i_dhatu, "rIk"); } else { - add_agama("7.4.90.v1", p, i_dhatu, "rIk"); + op::insert_agama_at("7.4.90.v1", p, i_dhatu, "rIk"); } } } else if abhyasa.has_antya('a') { - p.op_term("7.4.83", i_abhyasa, op::antya("A")); + p.run_at("7.4.83", i_abhyasa, op::antya("A")); } Some(()) diff --git a/vidyut-prakriya/src/angasya/asiddhavat.rs b/vidyut-prakriya/src/angasya/asiddhavat.rs index 5e0900d..6db97d9 100644 --- a/vidyut-prakriya/src/angasya/asiddhavat.rs +++ b/vidyut-prakriya/src/angasya/asiddhavat.rs @@ -136,7 +136,7 @@ pub fn try_cinvat_for_bhave_and_karmani_prayoga(p: &mut Prakriya) -> Option<()> let ac_hana_graha_drza = upadesha_ac || hana_graha_drza; if sya_sic_siyut_tasi && bhavakarmanoh && ac_hana_graha_drza { - let ran = p.op_optional("6.4.62", |p| { + let ran = p.run_optional("6.4.62", |p| { p.set(i_n, |t| { t.add_tag(T::cit); t.add_tag(T::Rit); @@ -178,18 +178,18 @@ fn run_for_kniti_ardhadhatuke_after_guna(p: &mut Prakriya, i: usize) -> Option<( if n.has_adi(&*HAL) && ghu_ma && !dhatu.has_tag(T::FlagNaLopa) { if n.has_lakshana("li~N") { // deyAt, DeyAt, meyAt, ... - p.op_term("6.4.67", i, op::antya("e")); + p.run_at("6.4.67", i, op::antya("e")); } else if n.has_u("lyap") { if dhatu.has_u("me\\N") { // apamitya, apamAya - p.op_optional("6.4.70", op::t(i, op::antya("i"))); + p.run_optional_at("6.4.70", i, op::antya("i")); } else { // pradAya p.step("6.4.69"); } } else { // deya - p.op_term("6.4.66", i, op::antya("I")); + p.run_at("6.4.66", i, op::antya("I")); } } else if dhatu.is_samyogadi() { // HACK: skip dhatus with agama. `k` indicates a following agama. @@ -203,7 +203,7 @@ fn run_for_kniti_ardhadhatuke_after_guna(p: &mut Prakriya, i: usize) -> Option<( p.step("6.4.69"); } else if n.has_lakshana("li~N") { // gleyAt/glAyAt;, mleyAt/mlAyAt, ... - p.op_optional("6.4.68", op::t(i, op::antya("e"))); + p.run_optional_at("6.4.68", i, op::antya("e")); } } } @@ -225,7 +225,7 @@ fn run_for_kniti_ardhadhatuke_after_dvitva(p: &mut Prakriya, i: usize) -> Option if aat && n.has_adi(&*AC) && (kniti_ardha || n.first()?.is_it_agama()) { // papiTa, tastTita, ... // By 1.1.59 (dvirvacane 'ci), this rule should be applied after dvitva. - p.op_term("6.4.64", i, op::antya("")); + p.run_at("6.4.64", i, op::antya("")); // 6.4.65 runs before guNa (dIya -> deya). } @@ -246,15 +246,15 @@ fn try_run_kniti_for_dhatu(p: &mut Prakriya, i: usize) -> Option<()> { let next_is_hi = n.first()?.has_text("hi"); if anga.has_text_in(&["gam", "han", "jan", "Kan", "Gas"]) && n.has_adi(&*AC) && !n.has_u("aN") { - p.op_term("6.4.98", i, op::upadha("")); + p.run_at("6.4.98", i, op::upadha("")); } else if anga.has_u("Basa~") { // TODO: rule is chAndasa, but SK applies it generally? - p.op_term("6.4.100", i, op::upadha("")); + p.run_at("6.4.100", i, op::upadha("")); } else if (anga.has_text("hu") || anga.has_antya(&*JHAL) || anga.has_u("SAsu~")) && next_is_hi { // HACK to allow SAsu~ so that we can derive SADi. - p.op_term("6.4.101", n.start(), op::text("Di")); + p.run_at("6.4.101", n.start(), op::text("Di")); } else if anga.has_u("ciR") { - p.op_term("6.4.104", n.start(), op::luk); + p.run_at("6.4.104", n.start(), op::luk); } Some(()) @@ -275,7 +275,7 @@ fn try_run_kniti(p: &mut Prakriya, i: usize) -> Option<()> { let next_is_hi = n.first()?.has_text("hi"); if has_antya_a_asiddhavat(anga) && n.first()?.has_text("hi") { // Bavahi -> Bava - p.op_term("6.4.105", n.start(), op::luk); + p.run_at("6.4.105", n.start(), op::luk); } else if anga.has_antya('u') && anga.is_pratyaya() { let dhatu = p.get(i - 1)?; let n = p.view(j)?; @@ -283,15 +283,15 @@ fn try_run_kniti(p: &mut Prakriya, i: usize) -> Option<()> { if !is_samyogapurva(p, i) && next_is_hi { // kuruhi -> kuru - p.op_term("6.4.106", n.start(), op::luk); + p.run_at("6.4.106", n.start(), op::luk); } else if dhatu.has_text_in(&["kar", "kur"]) { if n_is_mv { - p.op_term("6.4.108", i, op::luk); + p.run_at("6.4.108", i, op::luk); } else if n.has_adi('y') { - p.op_term("6.4.109", i, op::luk); + p.run_at("6.4.109", i, op::luk); } } else if n_is_mv && !is_samyogapurva(p, i) { - p.op_optional("6.4.107", op::t(i, op::antya(""))); + p.run_optional_at("6.4.107", i, op::antya("")); } } @@ -311,21 +311,21 @@ fn try_run_kniti_sarvadhatuke_for_shna_and_abhyasta(p: &mut Prakriya, i: usize) let n_is_haladi = n.has_adi(&*HAL); if anga.has_text("daridrA") && n_is_haladi { - p.op_term("6.4.114", i, op::antya("i")); + p.run_at("6.4.114", i, op::antya("i")); } else if anga.has_u("YiBI\\") && n_is_haladi { - p.op_optional("6.4.115", op::t(i, op::antya("i"))); + p.run_optional_at("6.4.115", i, op::antya("i")); } else if anga.has_antya('A') { let mut changed = false; if anga.has_u("o~hA\\k") && n_is_haladi { if n.has_adi('y') { - p.op_term("6.4.118", i, op::antya("")); + p.run_at("6.4.118", i, op::antya("")); } else { if n.last()?.has_text("hi") { - changed = p.op_optional("6.4.117", op::t(i, op::antya("A"))); + changed = p.run_optional_at("6.4.117", i, op::antya("A")); } // Run 6.4.116 only if 6.4.117 was not run. if !changed { - changed = p.op_optional("6.4.116", op::t(i, op::antya("i"))); + changed = p.run_optional_at("6.4.116", i, op::antya("i")); } } } @@ -335,9 +335,9 @@ fn try_run_kniti_sarvadhatuke_for_shna_and_abhyasta(p: &mut Prakriya, i: usize) // HACK to ignore SAsu~ so that we can derive SADi. if anga.has_antya('A') && !anga.has_u("SAsu~") { if !anga.has_tag(T::Ghu) && n_is_haladi { - p.op_term("6.4.113", i, op::antya("I")); + p.run_at("6.4.113", i, op::antya("I")); } else { - p.op_term("6.4.112", i, op::antya("")); + p.run_at("6.4.112", i, op::antya("")); } } } @@ -357,7 +357,7 @@ fn try_run_kniti_sarvadhatuke(p: &mut Prakriya, i: usize) -> Option<()> { // Must come before 6.4.111. if (anga.has_u("asa~") || anga.has_tag(T::Ghu)) && n.has_u("hi") { - p.op("6.4.119", |p| { + p.run("6.4.119", |p| { if let Some(a) = p.find_first(T::Abhyasa) { p.set(a, op::text("")); } @@ -367,11 +367,11 @@ fn try_run_kniti_sarvadhatuke(p: &mut Prakriya, i: usize) -> Option<()> { let anga = p.get(i)?; if anga.has_tag(T::Snam) { - p.op_term("6.4.111", i, |t| { + p.run_at("6.4.111", i, |t| { t.find_and_replace_text("na", "n"); }); } else if anga.has_u("asa~") { - p.op_term("6.4.111", i, op::adi("")); + p.run_at("6.4.111", i, op::adi("")); } else { try_run_kniti_sarvadhatuke_for_shna_and_abhyasta(p, i); } @@ -391,7 +391,7 @@ fn try_et_adesha_and_abhyasa_lopa_for_lit(p: &mut Prakriya, i: usize) -> Option< } let dhatu = p.get_if(i, |t| t.has_all_tags(&[T::Dhatu, T::Abhyasta]))?; - let abhyasa = p.get_if(i - 1, |t| t.has_tag(T::Abhyasa))?; + let abhyasa = p.get_if(i - 1, |t| t.is_abhyasa())?; let n = p.view(i + 1)?; let kniti = n.is_knit(); @@ -408,25 +408,25 @@ fn try_et_adesha_and_abhyasa_lopa_for_lit(p: &mut Prakriya, i: usize) -> Option< if dhatu.has_text("daB") && dhatu.has_u("danBu~") { // varttika stated before 6.4.121, so Tal is excluded. if !thali_seti { - p.op("6.4.120.v1", op_et_abhyasa_lopa); + p.run("6.4.120.v1", op_et_abhyasa_lopa); } } else if (dhatu.has_u("tF") && dhatu.has_text("tar")) || dhatu.has_text_in(&["Pal", "Baj", "trap"]) { // teratuH, PelatuH, BejatuH, trepatuH - p.op("6.4.122", op_et_abhyasa_lopa); + p.run("6.4.122", op_et_abhyasa_lopa); } else if dhatu.has_text("SraT") && dhatu.has_u("SranTa~") { - p.op("6.4.122.v1", op_et_abhyasa_lopa); + p.run("6.4.122.v1", op_et_abhyasa_lopa); } else if dhatu.has_text("graT") { // TODO: attested, but can't find the rule for it. - p.op("???", op_et_abhyasa_lopa); + p.run("???", op_et_abhyasa_lopa); } else if dhatu.has_text("rAD") && dhatu.has_gana(Gana::Svadi) { // TODO: why svAdi? For now, just follow what ashtadhyayi.com does. - p.op("6.4.123", op_et_abhyasa_lopa); + p.run("6.4.123", op_et_abhyasa_lopa); } else if dhatu.has_u("jFz") || dhatu.has_text_in(&["Bram", "tras"]) { - p.op_optional("6.4.124", op_et_abhyasa_lopa); + p.run_optional("6.4.124", op_et_abhyasa_lopa); } else if dhatu.has_u_in(gana::PHAN_ADI) { - p.op_optional("6.4.125", op_et_abhyasa_lopa); + p.run_optional("6.4.125", op_et_abhyasa_lopa); } else if dhatu.has_text_in(&["Sas", "dad"]) || dhatu.has_adi('v') || dhatu.has_tag(T::FlagGuna) { // No change. @@ -444,10 +444,10 @@ fn try_et_adesha_and_abhyasa_lopa_for_lit(p: &mut Prakriya, i: usize) -> Option< if is_eka_hal_madhya && is_a && is_lit && is_anadeshadi { if kniti { // lalaBe -> leBe - p.op("6.4.120", op_et_abhyasa_lopa); + p.run("6.4.120", op_et_abhyasa_lopa); } else { // SaSakiTa -> SekiTa - p.op("6.4.121", op_et_abhyasa_lopa); + p.run("6.4.121", op_et_abhyasa_lopa); } } } @@ -470,7 +470,7 @@ fn try_ardhadhatuke(p: &mut Prakriya, i: usize) -> Option<()> { } // HACK to avoid abhyasa-at-lopa - if anga.has_tag(T::Abhyasa) { + if anga.is_abhyasa() { return None; } @@ -488,16 +488,16 @@ fn try_ardhadhatuke(p: &mut Prakriya, i: usize) -> Option<()> { }; if anga.has_text("Brasj") { - p.op_optional("6.4.47", op::t(i, op::text("Barj"))); + p.run_optional_at("6.4.47", i, op::text("Barj")); } else if anga.text.ends_with("ya") && is_halah(p, i) { - p.op("6.4.49", |p| { + p.run("6.4.49", |p| { p.set(i, op::antya("")); p.set(i, op::antya("")); p.set(i, op::add_tag(T::FlagAtLopa)); p.add_tag(T::FlagAtLopa); }); } else if has_antya_a_asiddhavat(anga) { - p.op("6.4.48", |p| { + p.run("6.4.48", |p| { p.set(i, op::antya("")); p.set(i, op::add_tag(T::FlagAtLopa)); p.add_tag(T::FlagAtLopa); @@ -511,7 +511,7 @@ fn try_upadha_nalopa(p: &mut Prakriya, i: usize) -> Option<()> { let anga = p.get(i)?; if anga.has_tag(T::Snam) && anga.has_upadha('n') { - p.op_term("6.4.23", i, op::upadha("")); + p.run_at("6.4.23", i, op::upadha("")); } let anga = p.get(i)?; @@ -525,9 +525,9 @@ fn try_upadha_nalopa(p: &mut Prakriya, i: usize) -> Option<()> { && (anga.has_antya('j') || anga.has_text("nanS")) && n.has_u("ktvA") { - p.op_optional("6.4.32", op::t(i, op::upadha(""))); + p.run_optional_at("6.4.32", i, op::upadha("")); } else if anga.has_u("Ba\\njo~") && n.has_u("ciR") { - p.op_optional("6.4.33", op::t(i, op::upadha(""))); + p.run_optional_at("6.4.33", i, op::upadha("")); } else if anidit_hal && is_kniti && anga.has_upadha('n') { let mut can_run = true; // ancu gati-pUjanayoH @@ -541,32 +541,32 @@ fn try_upadha_nalopa(p: &mut Prakriya, i: usize) -> Option<()> { } } if can_run { - p.op_term("6.4.24", i, op::upadha("")); + p.run_at("6.4.24", i, op::upadha("")); } } else if anga.has_text("ranj") { if n.first()?.is_ni_pratyaya() { // "rañjerṇau mṛgaramaṇa upasaṅkhyānaṃ kartavyam" - p.op_optional("6.4.24.v2", op::t(i, op::upadha(""))); + p.run_optional_at("6.4.24.v2", i, op::upadha("")); } else if n.first()?.has_u("Ginu~R") { // "ghinuṇi ca rañjerupasaṅkhyānaṃ kartavyam" - p.op_term("6.4.24.v3", i, op::upadha("")); + p.run_at("6.4.24.v3", i, op::upadha("")); } else if n.has_u("Sap") { - p.op_term("6.4.26", i, op::upadha("")); + p.run_at("6.4.26", i, op::upadha("")); } else if n.has_u("GaY") { - p.op_optional("6.4.27", op::t(i, op::upadha(""))); + p.run_optional_at("6.4.27", i, op::upadha("")); } } else if anga.has_text_in(&["danS", "sanj", "svanj"]) && n.has_u("Sap") { // daSati - p.op_term("6.4.25", i, op::upadha("")); + p.run_at("6.4.25", i, op::upadha("")); } else if anga.has_text("syand") && n.has_u("GaY") { - p.op_optional("6.4.28", op::nipatana("syada")); + p.run_optional("6.4.28", op::nipatana("syada")); } else if anga.has_u("SAsu~") { if n.last()?.has_text("hi") { // SAs + hi -> SAhi (-> SADi) - p.op_term("6.4.35", i, op::text("SA")); + p.run_at("6.4.35", i, op::text("SA")); } else if is_kniti && (n.has_u("aN") || n.has_adi(&*HAL)) { // "āṅaḥ śāsu icchāyām iti asya na bhavati" -- kashika - p.op_term("6.4.34", i, op::upadha("i")); + p.run_at("6.4.34", i, op::upadha("i")); } } @@ -594,51 +594,48 @@ fn try_antya_nalopa(p: &mut Prakriya, i: usize) -> Option<()> { if anga.has_u("ha\\na~") && n.last()?.has_text("hi") { // jahi - p.op_term("6.4.36", i, op::text("ja")); + p.run_at("6.4.36", i, op::text("ja")); } else if anga.has_text("gam") && n.has_u("kvip") { // TODO: other kvi-pratyayas? - p.op_term("6.4.40", i, op::antya("")); + p.run_at("6.4.40", i, op::antya("")); } else if anga.has_u_in(&["jana~", "janI~\\", "zaRa~", "zaRu~^", "Kanu~^"]) { if n.has_adi('y') && kniti { // sanyAt, sAyAt // "janeḥ śyani 'jñājanorjā' (7.3.79) iti nityaṃ jādeśo bhavati." // - kashikavrtti if !(anga.has_text("jan") && n.has_u("Syan")) { - p.op_optional( - "6.4.43", - op::t(i, |t| { - t.set_antya("A"); - }), - ); + p.run_optional_at("6.4.43", i, |t| { + t.set_antya("A"); + }); } } else if jhali_kniti || n.has_u("san") { - p.op_term("6.4.42", i, op::antya("A")); + p.run_at("6.4.42", i, op::antya("A")); } } else if anga.has_text("tan") && n.has_u("yak") { // tanyate, tAyate - p.op_optional("6.4.44", op::t(i, op::antya("A"))); + p.run_optional_at("6.4.44", i, op::antya("A")); } else if anga.has_text("san") && n.has_u("ktic") { - let used = p.op_optional("6.4.45.b", op::t(i, op::antya(""))); + let used = p.run_optional_at("6.4.45.b", i, op::antya("")); if !used { - p.op_optional("6.4.45.a", op::t(i, op::antya("A"))); + p.run_optional_at("6.4.45.a", i, op::antya("A")); } } else if is_anudatta || is_tanadi || anga.has_text("van") { if jhali_kniti { // General case if n.has_u("ktic") { // TODO: also prevent 6.4.15; - p.op_term("6.4.39", i, |t| t.add_tag(T::FlagNoDirgha)); + p.run_at("6.4.39", i, |t| t.add_tag(T::FlagNoDirgha)); } else { - p.op_term("6.4.37", i, op::antya("")); + p.run_at("6.4.37", i, op::antya("")); } } else if n.has_u("lyap") { // vyavasthita-vibhasha -- optional only if ends in m. // TODO: why? let code = "6.4.38"; if anga.has_antya('m') { - p.op_optional(code, op::t(i, op::antya(""))); + p.run_optional_at(code, i, op::antya("")); } else { - p.op_term(code, i, op::antya("")); + p.run_at(code, i, op::antya("")); } } } @@ -688,13 +685,9 @@ fn try_add_a_agama(p: &mut Prakriya) -> Option<()> { } if p.has(i_start, |t| t.has_adi(&*AC)) { - op::insert_agama_before(p, i_start, "Aw"); - p.step("6.4.72"); - it_samjna::run(p, i_start).expect("ok"); + op::insert_agama_at("6.4.72", p, i_start, "Aw"); } else { - op::insert_agama_before(p, i_start, "aw"); - p.step("6.4.71"); - it_samjna::run(p, i_start).expect("ok"); + op::insert_agama_at("6.4.71", p, i_start, "aw"); } Some(()) @@ -718,29 +711,23 @@ pub fn run_before_guna(p: &mut Prakriya, i: usize) -> Option<()> { op::append_agama("6.4.88", p, i, "vu~k"); } else if anga.has_u("guhU~^") && n.has_adi(&*AC) && !n.is_knit() { // gUhati, agUhat -- but juguhatuH due to Nit on the pratyaya. - p.op( - "6.4.89", - op::t(i, |t| { + p.run_at("6.4.89", i, |t| { + t.set_upadha("U"); + t.add_tag(T::FlagGunaApavada); + }); + } else if anga.has_u("du\\za~") && n.first()?.is_ni_pratyaya() { + if !p.run_optional("6.4.91", |_| {}) { + p.run_at("6.4.90", i, |t| { t.set_upadha("U"); t.add_tag(T::FlagGunaApavada); - }), - ); - } else if anga.has_u("du\\za~") && n.first()?.is_ni_pratyaya() { - if !p.op_optional("6.4.91", |_| {}) { - p.op( - "6.4.90", - op::t(i, |t| { - t.set_upadha("U"); - t.add_tag(T::FlagGunaApavada); - }), - ); + }); } } else if anga.has_u("ciR") && n.last()?.has_text("ta") { - p.op_term("6.4.101", n.end(), op::luk); + p.run_at("6.4.104", n.end(), op::luk); } else if anga.has_u("daridrA") && n.has_tag(T::Ardhadhatuka) { if p.terms().last()?.has_lakshana("lu~N") { // Varttika. - if p.op_optional("6.4.114.v2", |_| {}) { + if p.run_optional("6.4.114.v2", |_| {}) { return None; } } @@ -748,14 +735,14 @@ pub fn run_before_guna(p: &mut Prakriya, i: usize) -> Option<()> { // Should replace just the last sound, but sak-Agama causes issues // here. // TODO: what is the correct prakriya here? - p.op_term("6.4.114.v1", i, op::text("daridr")); + p.run_at("6.4.114.v1", i, op::text("daridr")); } let dhatu = p.get(i)?; let n = p.view(i + 1)?; let aat = dhatu.has_antya('A'); if aat && n.has_u("yat") { - p.op_term("6.4.65", i, op::antya("I")); + p.run_at("6.4.65", i, op::antya("I")); } Some(()) @@ -786,9 +773,9 @@ fn run_for_final_i_or_u(p: &mut Prakriya, i: usize) -> Option<()> { let n = p.view(j)?; if anga.has_text("strI") && n.last()?.is_pratyaya() { if n.last()?.has_u_in(&["am", "Sas"]) { - p.op_optional("6.4.80", op::t(i, op::antya("iy"))); + p.run_optional_at("6.4.80", i, op::antya("iy")); } else { - p.op_term("6.4.79", i, op::antya("iy")); + p.run_at("6.4.79", i, op::antya("iy")); } } else if anga.has_u_in(&["i\\R", "i\\k"]) { // Also applies to 'ik' according to some: @@ -800,13 +787,13 @@ fn run_for_final_i_or_u(p: &mut Prakriya, i: usize) -> Option<()> { // // [1]: https://archive.org/details/237131938MadhaviyaDhatuVrtti/page/n412/mode/1up if anga.has_u("i\\k") { - let used = p.op_optional("6.4.81", op::t(i, op::antya("y"))); + let used = p.run_optional_at("6.4.81", i, op::antya("y")); if !used { // Copied from below for better control flow. - p.op("6.4.77", |p| to_iy_uv(p, i)); + p.run("6.4.77", |p| to_iy_uv(p, i)); } } else { - p.op_term("6.4.81", i, op::antya("y")); + p.run_at("6.4.81", i, op::antya("y")); } } else if anga.has_antya(&*II) && is_anekac(p, i) && anga.is_dhatu() && is_asamyogapurva { // `Dhatu` is understood here even if not stated in the rule. @@ -814,7 +801,7 @@ fn run_for_final_i_or_u(p: &mut Prakriya, i: usize) -> Option<()> { if anga.has_text("suDI") { p.step("6.4.85"); } else { - p.op_term("6.4.82", i, op::antya("y")); + p.run_at("6.4.82", i, op::antya("y")); } } else if anga.has_antya(&*UU) && anga.is_dhatu() @@ -825,22 +812,22 @@ fn run_for_final_i_or_u(p: &mut Prakriya, i: usize) -> Option<()> { if anga.has_text("BU") { p.step("6.4.85"); } else { - p.op_term("6.4.83", i, op::antya("v")); + p.run_at("6.4.83", i, op::antya("v")); } } else if anga.has_text("varzABU") { - p.op_term("6.4.84", i, op::antya("v")); + p.run_at("6.4.84", i, op::antya("v")); } else if anga.has_u_in(&["hu\\", "Snu"]) && n.has_tag(T::Sarvadhatuka) && is_asamyogapurva { - p.op_term("6.4.87", i, op::antya("v")); + p.run_at("6.4.87", i, op::antya("v")); } else if anga.is_dhatu() || anga.has_u("Snu") || anga.has_text("BrU") { - p.op("6.4.77", |p| to_iy_uv(p, i)); + p.run("6.4.77", |p| to_iy_uv(p, i)); } else { - let abhyasa = p.get_if(i, |t| t.has_tag(T::Abhyasa))?; + let abhyasa = p.get_if(i, |t| t.is_abhyasa())?; let next = p.get(j)?; let x = abhyasa.antya()?; let y = next.adi()?; // HACKY implementation of asavarna if al::to_dirgha(x) != al::to_dirgha(y) { - p.op("6.4.78", |p| to_iy_uv(p, i)); + p.run("6.4.78", |p| to_iy_uv(p, i)); } } @@ -865,19 +852,19 @@ pub fn run_for_ni(p: &mut Prakriya) -> Option<()> { .has_text_in(&["Am", "anta", "Alu", "Ayya", "itnu", "iznu"]) { // corayAm, spfhayAlu, etc. - p.op_term("6.4.55", i_ni, op::antya("ay")); + p.run_at("6.4.55", i_ni, op::antya("ay")); } else if n.has_u("lyap") && dhatu.has_upadha(&*LAGHU) { // praRamayya, pratamayya, ... - p.op_term("6.4.56", i_ni, op::antya("ay")); + p.run_at("6.4.56", i_ni, op::antya("ay")); } else if n.has_tag(T::Nistha) && iti { // corita, kArita, ... - p.op_term("6.4.52", i_ni, op::antya("")); + p.run_at("6.4.52", i_ni, op::antya("")); } else if !iti || n.has_tag(T::Cinvat) { // Apply ac_sandhi before lopa, since later rules depend on this // being done (e.g. cayyAt) // TODO: implement this excluding "ni" from the sandhi rules. ac_sandhi::apply_general_ac_sandhi(p); - p.op_term("6.4.51", i_ni, op::lopa); + p.run_at("6.4.51", i_ni, op::lopa); } } @@ -886,26 +873,26 @@ pub fn run_for_ni(p: &mut Prakriya) -> Option<()> { let ni = p.get(i_ni)?; if ni.has_u("Ric") { if n.has_u("Kac") { - p.op_term("6.4.94", i_dhatu, op::upadha_hrasva); + p.run_at("6.4.94", i_dhatu, op::upadha_hrasva); } else if dhatu.has_u("hlAdI~\\") && n.has_tag(T::Nistha) { - p.op_term("6.4.95", i_dhatu, op::upadha_hrasva); + p.run_at("6.4.95", i_dhatu, op::upadha_hrasva); } else if dhatu.has_u("Cada~") { let num_upasargas = p.terms()[..i_dhatu] .iter() .filter(|t| t.is_upasarga()) .count(); if n.has_u("Ga") && num_upasargas < 2 { - p.op_term("6.4.96", i_dhatu, op::upadha_hrasva); + p.run_at("6.4.96", i_dhatu, op::upadha_hrasva); } else if n.has_u_in(&["isi~", "mani~n", "zwran", "kvi~p"]) { - p.op_term("6.4.97", i_dhatu, op::upadha_hrasva); + p.run_at("6.4.97", i_dhatu, op::upadha_hrasva); } } else if dhatu.has_tag(T::mit) && dhatu.has_upadha(&*AC) { let mut run = true; if n.has_u_in(&["ciR", "Ramu~l"]) { - run = p.op_optional("6.4.93", |_| {}); + run = p.run_optional("6.4.93", |_| {}); } if run { - p.op_term("6.4.92", i_dhatu, op::upadha_hrasva); + p.run_at("6.4.92", i_dhatu, op::upadha_hrasva); } } } @@ -920,9 +907,9 @@ fn try_kr_rule(p: &mut Prakriya, i: usize) -> Option<()> { let n = p.view(i_n)?; let last = p.terms().last()?; - let sarva_kniti = last.has_tag(T::Sarvadhatuka) && last.is_knit(); + let sarva_kniti = last.is_sarvadhatuka() && last.is_knit(); if anga.has_u("qukf\\Y") && anga.has_text("kar") && n.has_adi('u') && sarva_kniti { - p.op_term("6.4.110", i, op::text("kur")); + p.run_at("6.4.110", i, op::text("kur")); } Some(()) @@ -956,7 +943,7 @@ pub fn bhasya(p: &mut Prakriya) -> Option<()> { if next.has_u_in(&["izWan", "imani~c", "Iyasu~n"]) { if bha.has_text_in(&["sTUla", "dUra", "yuvan", "hrasva", "kzipra", "kzudra"]) { // sTavizWa, ... - p.op_term("6.4.156", i, |t| { + p.run_at("6.4.156", i, |t| { // `rfind` to match the 'v' of `yuvan` instead of the 'y'. let i_yan = t.text.rfind(|c| YAN.contains(c)).expect("ok"); t.text.replace_range(i_yan.., ""); @@ -966,11 +953,11 @@ pub fn bhasya(p: &mut Prakriya) -> Option<()> { }); } else if let Some(sub) = op::yatha(&bha.text, PRIYA_ADI, PRA_ADI) { // priya -> prezWa, ... - p.op_term("6.4.157", i, op::text(sub)); + p.run_at("6.4.157", i, op::text(sub)); } else if bha.has_text("bahu") { // BUyAn, ... let istha = p.has(i + 1, |t| t.has_u("izWan")); - p.op("6.4.158", |p| { + p.run("6.4.158", |p| { p.set(i, |t| t.set_text("BU")); if !istha { p.set(i + 1, |t| t.set_adi("")); @@ -978,31 +965,29 @@ pub fn bhasya(p: &mut Prakriya) -> Option<()> { }); if istha { // BUyizWa - op::insert_agama_before(p, i + 1, "yi~w"); - p.step("6.4.159"); - it_samjna::run(p, i + 1).expect("ok"); + op::insert_agama_at("6.4.159", p, i + 1, "yi~w"); } } else if bha.has_text("jya") { // jyAyas - p.op_term("6.4.160", i + 1, |t| t.set_adi("A")); + p.run_at("6.4.160", i + 1, |t| t.set_adi("A")); } else { // pawu -> pawizWa, pawiman, ... - p.op_term("6.4.155", i, op::ti("")); + p.run_at("6.4.155", i, op::ti("")); let bha = p.get(i)?; if bha.has_adi(&*HAL) && bha.is_laghu() && bha.text.contains('f') { // pfTu -> praTizWa, praTiman, ... - p.op_term("6.4.161", i, |t| t.find_and_replace_text("f", "ra")); + p.run_at("6.4.161", i, |t| t.find_and_replace_text("f", "ra")); } } } else if bha.has_text("pAd") { - p.op_term("6.4.130", i, op::text("pad")); + p.run_at("6.4.130", i, op::text("pad")); } else if bha.has_u("kvasu~") { - p.op_term("6.4.131", i, op::text("us")); + p.run_at("6.4.131", i, op::text("us")); } else if bha.has_text("vAh") { op::adesha("6.4.132", p, i, "Uh"); } else if bha.has_text_in(&["Svan", "yuvan", "maGavan"]) && !next.has_tag(T::Taddhita) { - p.op_term("6.4.133", i, |t| t.find_and_replace_text("va", "u")); + p.run_at("6.4.133", i, |t| t.find_and_replace_text("va", "u")); } else if bha.has_antya('n') { if taddhita { let ani = next.has_u("aR"); @@ -1019,7 +1004,7 @@ pub fn bhasya(p: &mut Prakriya) -> Option<()> { "sukarasadman", "suparvan", ]) { - p.op_term("6.4.144.v1", i, op::ti("")); + p.run_at("6.4.144.v1", i, op::ti("")); } else if ani && bha.ends_with("in") { let n = bha.text.len(); if bha.has_text_in(&["gATin", "vidaTin", "keSin", "gaRin", "paRin"]) { @@ -1038,11 +1023,11 @@ pub fn bhasya(p: &mut Prakriya) -> Option<()> { p.step("6.4.169"); } else if bha.has_text("ahan") { if next.has_u_in(&["wac", "KA"]) { - p.op_term("6.4.145", i, op::ti("")); + p.run_at("6.4.145", i, op::ti("")); } } else { // This takes priority over 6.4.134 below. - p.op_term("6.4.144", i, op::ti("")); + p.run_at("6.4.144", i, op::ti("")); } } else if bha.ends_with("an") { let mut blocked = false; @@ -1054,14 +1039,14 @@ pub fn bhasya(p: &mut Prakriya) -> Option<()> { p.step("6.4.137"); blocked = true; } else if next.has_u_in(&["Ni", "SI"]) { - blocked = p.op_optional("6.4.135", |_| {}); + blocked = p.run_optional("6.4.135", |_| {}); } if !blocked { - p.op_term("6.4.134", i, op::upadha("")); + p.run_at("6.4.134", i, op::upadha("")); } } } else if bha.has_antya('A') && bha.is_dhatu() { - p.op_term("6.4.140", i, op::antya("")); + p.run_at("6.4.140", i, op::antya("")); } else if (bha.has_u("daRqin") && next.has_u("Pak")) || (bha.has_u("hastin") && next.has_u("Pak")) || (bha.has_u("aTarvan") && next.has_u("Wak")) @@ -1098,24 +1083,24 @@ pub fn bhasya(p: &mut Prakriya) -> Option<()> { } else { "hiraRmaya" }; - p.op(code, op::nipatana(sub)); + p.run(code, op::nipatana(sub)); } else if bha.has_antya(&*UU) && taddhita { if next.has_tag(T::Qit) && !bha.has_text("kadrU") { - p.op_term("6.4.147", i, |t| t.set_antya("")); + p.run_at("6.4.147", i, |t| t.set_antya("")); } else { - p.op_term("6.4.146", i, |t| t.set_antya("o")); + p.run_at("6.4.146", i, |t| t.set_antya("o")); } } else if (bha.has_antya(&*AA) || bha.has_antya(&*II)) && (taddhita || next.has_adi('I')) { if next.has_u("SI") { // Pale, ... p.step("6.4.148.v1"); } else if bha.has_text_in(&["sUrya", "tizya", "agastya", "matsya"]) { - p.op_term("6.4.149", i, |t| { + p.run_at("6.4.149", i, |t| { t.set_antya(""); t.set_antya(""); }); } else { - p.op_term("6.4.148", i, |t| t.set_antya("")); + p.run_at("6.4.148", i, |t| t.set_antya("")); } } @@ -1146,7 +1131,7 @@ pub fn run_final(p: &mut Prakriya, i: usize) -> Option<()> { let n = p.view(i + 1)?; if n.has_tag(T::qit) { - p.op_term("6.4.143", i, op::ti("")); + p.run_at("6.4.143", i, op::ti("")); } Some(()) diff --git a/vidyut-prakriya/src/angasya/guna_vrddhi.rs b/vidyut-prakriya/src/angasya/guna_vrddhi.rs index 940dbba..02bfb12 100644 --- a/vidyut-prakriya/src/angasya/guna_vrddhi.rs +++ b/vidyut-prakriya/src/angasya/guna_vrddhi.rs @@ -1,10 +1,10 @@ use crate::args::Gana; use crate::operators as op; -use crate::prakriya::Prakriya; +use crate::prakriya::{Code, Prakriya}; use crate::sounds as al; use crate::sounds::{s, Set}; use crate::tag::Tag as T; -use crate::term::Term; +use crate::term::{Term, TermView}; use lazy_static::lazy_static; lazy_static! { @@ -14,43 +14,124 @@ lazy_static! { static ref HAL: Set = s("hal"); } -fn op_antya_guna(t: &mut Term) { - if let Some(a) = t.antya() { - if let Some(sub) = al::to_guna(a) { - t.set_antya(sub); - t.add_tag(T::FlagGuna); +impl Term { + /// Tries guna of the term's penultimate sound. + fn try_upadha_guna(&mut self) { + if let Some(a) = self.upadha() { + if let Some(sub) = al::to_guna(a) { + self.set_upadha(sub); + self.add_tag(T::FlagGuna); + } } } -} -/// Tests whether a term can use guna and vrddhi in the general case. -fn can_use_guna_or_vrddhi_opt(p: &Prakriya, i_anga: usize) -> Option { - let anga = p.get(i_anga)?; - let i_next = p.find_next_where(i_anga, |t| !t.is_empty() && !t.has_u("pu~k"))?; - let n = p.view(i_next)?; + /// Tries guna of the term's last sound. + fn try_antya_guna(&mut self) { + if let Some(a) = self.antya() { + if let Some(sub) = al::to_guna(a) { + self.set_antya(sub); + self.add_tag(T::FlagGuna); + } + } + } - if anga.has_tag_in(&[T::FlagAtLopa, T::FlagGunaApavada]) { - Some(false) - } else if p.has(i_anga + 1, |t| { - t.is_dhatu() && t.is_empty() && t.has_tag(T::FlagAtLopa) - }) && n.has_tag(T::Ardhadhatuka) - { - // 1.1.4 na DAtulopa ArDaDAtuke - Some(false) - } else if n.is_knit() { - // 1.1.5 kNiti ca - Some(false) - } else if anga.has_u_in(&["dIDIN", "vevIN"]) || anga.is_it_agama() { - // 1.1.6 dIdhI-vevI-iTAm - Some(false) - } else { - // Otherwise, 1.1.3 iko guNavRddhI - Some(n.has_tag(T::Pratyaya)) + /// Tries vrddhi of the term's penultimate sound. + fn try_upadha_vrddhi(&mut self) { + if let Some(a) = self.upadha() { + if let Some(sub) = al::to_vrddhi(a) { + self.set_upadha(sub); + } + } + } + + /// Tries vrddhi of the term's last sound. + fn try_antya_vrddhi(&mut self) { + if let Some(a) = self.antya() { + if let Some(sub) = al::to_vrddhi(a) { + self.set_antya(sub); + } + } } } -fn can_use_guna_or_vrddhi(p: &Prakriya, i: usize) -> bool { - return can_use_guna_or_vrddhi_opt(p, i).unwrap_or(true); +struct GunaVrddhiPrakriya<'a> { + p: &'a mut Prakriya, + /// The index of the term that potentially receives guna. + i_anga: usize, + /// The index of the term that potentially conditions guna. + i_next: usize, + /// Whether guna/vrddhi has been decided for this anga. + done: bool, +} + +impl<'a> GunaVrddhiPrakriya<'a> { + /// Creates a new prakriya wrapper that specializes in guna/vrddhi changes. + fn new(p: &'a mut Prakriya, i_anga: usize, i_next: usize) -> Self { + Self { + p, + i_anga, + i_next, + done: false, + } + } + + /// Returns the anga that might receive guna/vrddhi. + fn anga(&self) -> &Term { + self.p.get(self.i_anga).expect("ok") + } + + /// Returns the term that might condition guna/vrddhi. + fn next(&self) -> TermView { + self.p.view(self.i_next).expect("ok") + } + + /// Checks a standard list of rules that block guna/vrddhi + fn check_guna_vrddhi_blocks(&mut self) { + if self.done { + return; + } + + let anga = self.anga(); + let n = self.next(); + + if anga.has_tag_in(&[T::FlagAtLopa, T::FlagGunaApavada]) { + self.done = true; + } else if self.p.has(self.i_anga + 1, |t| { + t.is_dhatu() && t.is_empty() && t.has_tag(T::FlagAtLopa) + }) && n.has_tag(T::Ardhadhatuka) + { + self.block("1.1.4"); + } else if n.is_knit() { + self.block("1.1.5"); + } else if anga.has_u_in(&["dIDIN", "vevIN"]) || anga.is_it_agama() { + self.block("1.1.6"); + } else { + if !n.has_tag(T::Pratyaya) { + self.done = true; + } + } + } + + /// Blocks guna/vrddhi with the given `rule`. + fn block(&mut self, rule: Code) { + self.try_run(rule, |_| {}); + } + + /// Tries `func` and blocks further guna/vrddhi changes if it succeeds. + fn try_run(&mut self, rule: Code, func: impl Fn(&mut Term)) { + if !self.done { + self.p.run_at(rule, self.i_anga, func); + self.done = true; + } + } + + /// Tries `func` optionally and blocks further guna/vrddhi changes if it succeeds. + fn run_optional(&mut self, rule: Code, func: impl Fn(&mut Term)) { + if !self.done { + let ran = self.p.run_optional_at(rule, self.i_anga, func); + self.done = ran; + } + } } /// Tries rules that cause vrddhi when a taddhita-pratyaya follows. @@ -74,30 +155,30 @@ fn try_taddhita_vrddhi(p: &mut Prakriya, i: usize) -> Option<()> { if anga.has_text_in(&["devikA", "SiMSapA", "dityavAh", "dIrGasatra", "Sreyas"]) { // dAvikA, ... let adi_ac = anga.text.find(al::is_ac)?; - p.op_term("7.3.1", i, |t| t.set_at(adi_ac, "A")); + p.run_at("7.3.1", i, |t| t.set_at(adi_ac, "A")); } else if anga.has_text_in(&["kekaya", "mitrayu", "pralaya"]) { - p.op_term("7.3.2", i, |t| t.find_and_replace_text("y", "iy")); + p.run_at("7.3.2", i, |t| t.find_and_replace_text("y", "iy")); } else if anga.text.starts_with("vy") { // HACK: should properly be only with vi-upasarga. // TODO: also apply for sv-, .etc. - p.op_term("7.3.3", i, |t| t.text.replace_range(..2, "vEy")); + p.run_at("7.3.3", i, |t| t.text.replace_range(..2, "vEy")); } else if anga.has_u_in(DVARA_ADI) { // dvAra -> dOvArika, ... - p.op_term("7.3.4", i, |t| { + p.run_at("7.3.4", i, |t| { let i_yan = t.text.rfind(|c| c == 'y' || c == 'v').expect("ok"); - if t.text.get(i_yan..i_yan + 1) == Some("y") { + if t.get_at(i_yan) == Some('y') { t.text.insert(i_yan, 'E'); } else { t.text.insert(i_yan, 'O'); } }); } else if anga.has_text("nyagroDa") { - p.op_term("7.3.5", i, |t| t.text.replace_range(..2, "nEy")); + p.run_at("7.3.5", i, |t| t.text.replace_range(..2, "nEy")); } else { let adi_ac = anga.text.find(al::is_ac)?; let ac = anga.get_at(adi_ac)?; let vrddhi = al::to_vrddhi(ac)?; - p.op_term(rule, i, |t| { + p.run_at(rule, i, |t| { t.set_at(adi_ac, vrddhi); }); } @@ -110,18 +191,23 @@ fn try_taddhita_vrddhi(p: &mut Prakriya, i: usize) -> Option<()> { /// (7.2.115 - 7.3.35) /// Taddhita rules: 7.2.117 - 7.3.31 fn try_nnit_vrddhi(p: &mut Prakriya, i: usize) -> Option<()> { - let anga = p.get(i)?; let i_next = p.find_next_where(i, |t| !t.is_empty())?; - let n = p.view(i_next)?; - if !n.has_tag_in(&[T::Yit, T::Rit]) || !can_use_guna_or_vrddhi(p, i) { - // Allow RiN even though it is Nit. Without this check, RiN will be excluded by - // `can_use_guna_or_vrddhi`. - if !n.has_u("RiN") { - return None; - } + let mut gp = GunaVrddhiPrakriya::new(p, i, i_next); + let n = gp.next(); + let is_nnit = n.has_tag_in(&[T::Yit, T::Rit]); + // Allow RiN even though it is Nit. Without this check, RiN will be excluded by + // `can_use_guna_or_vrddhi`. + if !n.has_u("RiN") { + gp.check_guna_vrddhi_blocks(); + } + + if !is_nnit || gp.done { + return None; } + let anga = p.get(i)?; + let n = p.view(i_next)?; let is_cin = n.has_u("ciR") || n.has_tag(T::Cinvat); let is_cin_krt = is_cin || n.has_tag(T::Krt); let has_udatta = !anga.has_tag(T::Anudatta); @@ -142,7 +228,7 @@ fn try_nnit_vrddhi(p: &mut Prakriya, i: usize) -> Option<()> { } else if is_cin_krt && anga.has_antya('A') { op::append_agama("7.3.33", p, i, "yu~k"); } else if anga.has_u("ha\\na~") && !is_cin && !n.has_u("Ral") { - p.op("7.3.32", |p| { + p.run("7.3.32", |p| { p.set(i, op::upadha("A")); p.set(i, op::antya("t")); }); @@ -153,7 +239,7 @@ fn try_nnit_vrddhi(p: &mut Prakriya, i: usize) -> Option<()> { let antya = anga.antya()?; if !al::is_vrddhi(antya) { let sub = al::to_vrddhi(antya)?; - p.op_term("7.2.115", i, op::antya(sub)); + p.run_at("7.2.115", i, op::antya(sub)); } } else if anga.has_upadha('a') { if anga.has_u_in(&["kamu~\\", "wuvama~"]) { @@ -162,7 +248,7 @@ fn try_nnit_vrddhi(p: &mut Prakriya, i: usize) -> Option<()> { } // pAcayati - p.op_term("7.2.116", i, op::upadha("A")); + p.run_at("7.2.116", i, op::upadha("A")); } Some(()) @@ -177,9 +263,9 @@ fn try_vrddhi_adesha(p: &mut Prakriya, i: usize) -> Option<()> { let n = p.view(i_n)?; if dhatu.has_text("mfj") && !n.is_knit() { - if can_use_guna_or_vrddhi(p, i) { - p.op_term("7.2.114", i, op::text("mArj")); - } + let mut gp = GunaVrddhiPrakriya::new(p, i, i_n); + gp.check_guna_vrddhi_blocks(); + gp.try_run("7.2.114", |t| t.try_upadha_vrddhi()); } else if n.first()?.is_taddhita() { try_taddhita_vrddhi(p, i); } else { @@ -201,89 +287,83 @@ fn try_guna_adesha(p: &mut Prakriya, i: usize) -> Option<()> { let piti_sarvadhatuke = n.all(&[T::pit, T::Sarvadhatuka]); let is_ik = anga.has_antya(&*IK); - let anga = p.get_if(i, |t| !t.is_agama() && !t.has_tag(T::FlagGunaApavada))?; - let n = p.view(j)?; + let mut gp = GunaVrddhiPrakriya::new(p, i, j); + let anga = gp.anga(); + let n = gp.next(); if anga.has_u_in(&["Divi~", "kfvi~"]) { // Per commentary on 3.1.81, these roots don't take guna. } else if anga.has_text("mid") && n.has_tag(T::Sit) { // medyati - p.op_term("7.3.82", i, |t| { - t.text.replace_range(.., "med"); - t.add_tag(T::FlagGuna); - }); + gp.try_run("7.3.82", |t| t.try_upadha_guna()); } else if is_ik && n.has_u("jus") { - p.op_term("7.3.83", i, op_antya_guna); + gp.try_run("7.3.83", |t| t.try_antya_guna()); } else if anga.has_text("tfnah") && n.has_adi(&*HAL) && piti_sarvadhatuke && !n.has_tag(T::Nit) { // tfneQi; otherwise, tfRahAni, tfRQaH. // HACK: check for absence of `Nit` on first term to prevent tfnhyAt -> tfRihyAt - p.op_term("7.3.92", i, op::mit("i")); + p.run_at("7.3.92", i, op::mit("i")); } else if is_sarva_ardha { - let can_use_guna = can_use_guna_or_vrddhi(p, i); - // Exceptions if anga.has_text_in(&["BU", "sU"]) && n.has_tag(T::Tin) && piti_sarvadhatuke { - // e.g. aBUt - p.step("7.3.88"); - return None; - } else if anga.has_antya('u') && n.has_adi(&*HAL) && piti_sarvadhatuke && can_use_guna { - let anga = p.get(i)?; - let n = p.view(j)?; + // aBUt, ... + gp.block("7.3.88"); + } else if anga.has_antya('u') && n.has_adi(&*HAL) && piti_sarvadhatuke { + gp.check_guna_vrddhi_blocks(); + + let anga = gp.anga(); + let n = gp.next(); let sub = al::to_vrddhi(anga.antya()?)?; if anga.has_u("UrRuY") { if n.last()?.is_aprkta() { // prOrRot - p.op_term("7.3.91", i, op_antya_guna); + gp.try_run("7.3.91", |t| t.try_antya_guna()); } else { // UrROti, UrRoti // If vrddhi is declined, UrRu will take guna by 7.3.84 below. - p.op_optional("7.3.90", op::t(i, op::antya(sub))); + gp.run_optional("7.3.90", op::antya(sub)); } - } else if p.get(i + 1)?.has_tag(T::Luk) && !anga.has_tag(T::Abhyasta) { + } else if gp.p.get(i + 1)?.has_tag(T::Luk) && !anga.has_tag(T::Abhyasta) { // Why check for abhyasta? // // > na abhyastasya ityetadiha anuvartate, yoyoti, roroti ityevamādyartham. // // -- KV on 7.3.89. - p.op_term("7.3.89", i, op::antya(sub)); + gp.try_run("7.3.89", |t| t.try_antya_vrddhi()); }; } // Main guna rules. - let anga = p.get(i)?; - let n = p.get(j)?; + let anga = gp.anga(); + let n = gp.next(); let is_laghu_upadha = anga.has_upadha(&*HRASVA); - let is_puganta = p.has(i + 1, |t| t.has_u("pu~k")); + let is_puganta = gp.p.has(i + 1, |t| t.has_u("pu~k")); // HACK to ignore antya A and avoid applying guna to it. - if can_use_guna && (is_puganta || is_laghu_upadha) { + if is_puganta || is_laghu_upadha { if anga.is_abhyasta() && piti_sarvadhatuke && n.has_adi(&*AC) { // e.g. nenijAma - p.step("7.3.87"); + gp.block("7.3.87"); } else { let code = "7.3.86"; if is_puganta { let sub = al::to_guna(anga.antya()?)?; // Ignore 'a/A' by "iko gunavRddhI" if !(sub == "a" || sub == "A") { - p.op_term(code, i, |t| { - t.set_antya(sub); - t.add_tag(T::FlagGuna); - }); + gp.check_guna_vrddhi_blocks(); + gp.try_run(code, |t| t.try_antya_guna()); } } else { let sub = al::to_guna(anga.upadha()?)?; if !(sub == "a" || sub == "A") { - p.op_term(code, i, |t| { - t.set_upadha(sub); - t.add_tag(T::FlagGuna); - }); + gp.check_guna_vrddhi_blocks(); + gp.try_run(code, |t| t.try_upadha_guna()); } } } - } else if is_ik && can_use_guna { - p.op_term("7.3.84", i, op_antya_guna); + } else if is_ik { + gp.check_guna_vrddhi_blocks(); + gp.try_run("7.3.84", |t| t.try_antya_guna()); } } @@ -327,24 +407,21 @@ fn try_r_guna_before_lit(p: &mut Prakriya, i: usize) -> Option<()> { let anga = p.get(i)?; if anga.has_antya('f') && anga.is_samyogadi() { - p.op_term("7.4.10", i, do_ar_guna); + p.run_at("7.4.10", i, do_ar_guna); } else if anga.has_antya('F') || (anga.has_u_in(&["fCa~", "f\\"]) && anga.has_adi('f')) { if anga.has_u("fCa~") { - p.op_term("7.4.11", i, op::adi("ar")); + p.run_at("7.4.11", i, op::adi("ar")); } else { let mut skipped = false; if anga.has_text_in(&["SF", "dF", "pF"]) && !anga.has_gana(Gana::Curadi) { - skipped = p.op_optional( - "7.4.12", - op::t(i, |t| { - t.set_antya("f"); - t.add_tag(T::FlagGunaApavada); - }), - ); + skipped = p.run_optional_at("7.4.12", i, |t| { + t.set_antya("f"); + t.add_tag(T::FlagGunaApavada); + }); } if !skipped { - p.op_term("7.4.11", i, do_ar_guna); + p.run_at("7.4.11", i, do_ar_guna); } } } @@ -360,7 +437,7 @@ fn run_for_index(p: &mut Prakriya, i: usize) -> Option<()> { if anga.has_u("jAgf") && !n.has_u_in(&["kvin", "ciR", "Ral"]) && !p.view(i_n)?.has_tag(T::Nit) { // jAgf-guna takes priority over vrddhi. Skip if already applied (e.g. for jAgf + Ric). if anga.has_antya('f') { - p.op_term("7.3.85", i, |t| { + p.run_at("7.3.85", i, |t| { t.set_antya("ar"); t.add_tag(T::FlagGuna); }); diff --git a/vidyut-prakriya/src/angasya/sup_adesha.rs b/vidyut-prakriya/src/angasya/sup_adesha.rs index 28ff421..4e83ec2 100644 --- a/vidyut-prakriya/src/angasya/sup_adesha.rs +++ b/vidyut-prakriya/src/angasya/sup_adesha.rs @@ -35,12 +35,12 @@ fn try_napumsaka_su_am_adesha(p: &mut Prakriya, i_anga: usize, i_sup: usize) -> if anga.has_text_in(gana::USES_DATARA_DATAMA) || anga.has_text_in(&["anya", "anyatara", "itara"]) { - p.op_term("7.1.25", i_sup, op::text("adq")); + p.run_at("7.1.25", i_sup, op::text("adq")); } else { op::adesha("7.1.24", p, i_sup, "am"); } } else { - p.op_term("7.1.23", i_sup, op::luk); + p.run_at("7.1.23", i_sup, op::luk); } Some(()) @@ -67,18 +67,18 @@ fn try_adanta_adesha(p: &mut Prakriya, i_anga: usize, i: usize) -> Option<()> { p.step("7.1.11"); } else { // narEH - p.op_term("7.1.9", i, op::text("Es")); + p.run_at("7.1.9", i, op::text("Es")); } } else if is_sarvanama && sup.has_u_in(nasi_ni) { let mut do_sub = true; if anga.has_text_in(gana::PURVA_ADI) { - do_sub = !p.op_optional("7.1.16", |_| {}); + do_sub = !p.run_optional("7.1.16", |_| {}); } if do_sub { if let Some(sub) = yatha(&sup_u, nasi_ni, smat_smin) { // tasmAt, tasmin - p.op_term("7.1.9", i, op::text(sub)); + p.run_at("7.1.9", i, op::text(sub)); } } } @@ -87,15 +87,15 @@ fn try_adanta_adesha(p: &mut Prakriya, i_anga: usize, i: usize) -> Option<()> { if sup.has_u_in(ta_nasi_nas) && sup.has_text_in(&["A", "as"]) { if let Some(sub) = yatha(&sup_u, ta_nasi_nas, ina_at_sya) { // devena, devAt, devasya - p.op_term("7.1.12", i, op::text(sub)); + p.run_at("7.1.12", i, op::text(sub)); } } else if sup.has_u("Ne") { if is_sarvanama { // tasmE - p.op_term("7.1.14", i, op::text("smE")); + p.run_at("7.1.14", i, op::text("smE")); } else { // devAya - p.op_term("7.1.13", i, op::text("ya")); + p.run_at("7.1.13", i, op::text("ya")); } } else if is_sarvanama && sup.has_u("jas") { // te, sarve @@ -171,17 +171,17 @@ fn try_sarvanamasthane_asambuddhau(p: &mut Prakriya, i_anga: usize, i: usize) -> if sarve_asambuddhau { if sau && anga.has_text("saKi") { - p.op_term("7.1.93", i_anga, op::antya("an")); + p.run_at("7.1.93", i_anga, op::antya("an")); } else if sau && (anga.has_antya('f') || anga.has_text_in(&["uSanas", "purudaMsas", "anehas"])) { - p.op_term("7.1.94", i_anga, op::antya("an")); + p.run_at("7.1.94", i_anga, op::antya("an")); } else if anga.has_text_in(&["catur", "anaquh"]) { // TODO: am/Am? if sambuddhau { - p.op_term("7.1.99", i_anga, op::mit("a")); + p.run_at("7.1.99", i_anga, op::mit("a")); } else { - p.op_term("7.1.98", i_anga, op::mit("A")); + p.run_at("7.1.98", i_anga, op::mit("A")); } } } @@ -196,7 +196,7 @@ fn try_pratipadika_guna(p: &mut Prakriya, i_anga: usize, i: usize) -> Option<()> if anga.has_antya('f') && (sup.has_u("Ni") || sup.has_tag(T::Sarvanamasthana)) { // kartari let sub = al::to_guna(anga.antya()?)?; - p.op_term("7.3.110", i_anga, op::antya(sub)); + p.run_at("7.3.110", i_anga, op::antya(sub)); } else { // `Ni` rules are an exception to 7.3.111. let anga = p.get(i_anga)?; @@ -207,7 +207,7 @@ fn try_pratipadika_guna(p: &mut Prakriya, i_anga: usize, i: usize) -> Option<()> { // agnaye, agneH let sub = al::to_guna(anga.antya()?)?; - p.op_term("7.3.111", i_anga, op::antya(sub)); + p.run_at("7.3.111", i_anga, op::antya(sub)); } } Some(()) @@ -223,20 +223,18 @@ fn try_add_nit_agamas(p: &mut Prakriya, i_anga: usize) -> Option<()> { let is_aap = (anga.has_antya('A') && is_aap(anga)) || p.has(i_anga + 1, is_nyap_pratyaya); if anga.has_tag(T::Nadi) && niti { - p.op("7.3.112", |p| op::insert_agama_before(p, i_sup, "Aw")); - it_samjna::run(p, i_sup).ok()?; + op::insert_agama_at("7.3.112", p, i_sup, "Aw"); } else if is_aap && niti { if anga.has_tag(T::Sarvanama) { // tasyE - p.op("7.3.114", |p| { + p.run("7.3.114", |p| { p.set(i_anga, op::antya("a")); op::insert_agama_before(p, i_sup, "syAw") }); it_samjna::run(p, i_sup).ok()?; } else { // senAyE - p.op("7.3.113", |p| op::insert_agama_before(p, i_sup, "yAw")); - it_samjna::run(p, i_sup).ok()?; + op::insert_agama_at("7.3.113", p, i_sup, "yAw"); } } @@ -248,7 +246,8 @@ fn try_ni_adesha(p: &mut Prakriya, i_anga: usize, i: usize) -> Option<()> { let anga = p.get(i_anga)?; let sup = p.get(i)?; if sup.has_u("Ni") { - let nadi_nyap = anga.has_tag_in(&[T::Nadi, T::StriNyap]); + let nadi_nyap = + anga.has_tag_in(&[T::Nadi, T::StriNyap]) || p.has(i_anga + 1, |t| t.has_u("wAp")); let it_ut = anga.has_antya('i') || anga.has_antya('u'); if it_ut { if anga.has_tag(T::Nadi) { @@ -286,28 +285,28 @@ fn try_misc_rules(p: &mut Prakriya, i_anga: usize, i_sup: usize) -> Option<()> { if sau && anga.has_text("div") { // dyOH - p.op_term("7.1.84", i_anga, op::antya("O")); + p.run_at("7.1.84", i_anga, op::antya("O")); } else if anga.has_text_in(&["paTin", "maTin", "fBukzin"]) { if sau { // panTAH, ... - p.op_term("7.1.85", i_anga, op::antya("A")); + p.run_at("7.1.85", i_anga, op::antya("A")); } if sarvanamasthane { // panTAnam, ... - p.op_term("7.1.86", i_anga, |t| t.find_and_replace_text("i", "a")); + p.run_at("7.1.86", i_anga, |t| t.find_and_replace_text("i", "a")); if p.has(i_anga, |t| t.text.contains('T')) { // panTAnam, ... - p.op_term("7.1.87", i_anga, |t| t.find_and_replace_text("T", "nT")); + p.run_at("7.1.87", i_anga, |t| t.find_and_replace_text("T", "nT")); } } if p.has(i_anga, |t| t.has_tag(T::Bha)) { // paTA, ... - p.op_term("7.1.88", i_anga, op::ti("")); + p.run_at("7.1.88", i_anga, op::ti("")); } } else if anga.has_text("pums") && sarvanamasthane { - p.op_term("7.1.89", i_anga, |t| t.set_text("pumas")); + p.run_at("7.1.89", i_anga, |t| t.set_text("pumas")); } Some(()) } @@ -323,7 +322,7 @@ pub fn run_before_bhasya(p: &mut Prakriya) -> Option<()> { let is_jas_shas = sup.has_u_in(&["jas", "Sas"]); if anga.has_tag(T::Sat) && is_jas_shas { - p.op_term("7.1.22", i_sup, op::luk); + p.run_at("7.1.22", i_sup, op::luk); } else if is_aap(anga) && sup.has_text("O") { op::adesha("7.1.18", p, i_sup, "SI"); } else if is_napumsaka && sup.has_text("O") { @@ -341,7 +340,7 @@ pub fn run_before_bhasya(p: &mut Prakriya) -> Option<()> { // Add samjnas. let sup = p.get(i_sup)?; if sup.has_u("Si") { - p.op_term("1.1.42", i_sup, op::add_tag(T::Sarvanamasthana)); + p.run_at("1.1.42", i_sup, op::add_tag(T::Sarvanamasthana)); } // This might cause "A --> nA" which blocks num-Agama. @@ -356,7 +355,7 @@ pub fn run_before_bhasya(p: &mut Prakriya) -> Option<()> { /// (7.1.19 - 7.1.32) pub fn run_after_bhasya(p: &mut Prakriya) -> Option<()> { let i_anga = p.find_last(T::Pratipadika)?; - let i_sup = i_anga + 1; + let i_sup = p.find_next_where(i_anga, |t| t.is_sup())?; try_yusmad_asmad_sup_adesha_after_bhasya(p, i_anga); try_sarvanamasthane_asambuddhau(p, i_anga, i_sup); diff --git a/vidyut-prakriya/src/ardhadhatuka.rs b/vidyut-prakriya/src/ardhadhatuka.rs index 52899df..9b8ff96 100644 --- a/vidyut-prakriya/src/ardhadhatuka.rs +++ b/vidyut-prakriya/src/ardhadhatuka.rs @@ -65,7 +65,7 @@ pub fn dhatu_adesha_before_pada(p: &mut Prakriya, la: Lakara) { } } if use_khya { - p.op("2.4.54", |p| { + p.run("2.4.54", |p| { op::upadesha(p, i, "KyAY"); // Remove tags set by `ca\kzi~\N` p.set(i, |t| { @@ -138,14 +138,14 @@ fn try_dhatu_adesha_before_vikarana(p: &mut Prakriya, la: Option) -> Opt let to_gaa = |p: &mut Prakriya| op::upadesha(p, i, "gAN"); if p.has(i + 1, |t| t.has_u("Ric")) && p.has(i + 2, |t| t.has_u_in(&["san", "caN"])) { - p.op_optional("2.4.51", to_gaa); + p.run_optional("2.4.51", to_gaa); } else if n.has_u("san") { // aDijigAMsate op::adesha("2.4.48", p, i, "gami~"); } else if n.has_lakshana("li~w") { - p.op("2.4.49", to_gaa); + p.run("2.4.49", to_gaa); } else if n.has_lakshana_in(&["lu~N", "lf~N"]) { - p.op_optional("2.4.50", to_gaa); + p.run_optional("2.4.50", to_gaa); } } else if dhatu.has_u("asa~") { op::adesha("2.4.52", p, i, "BU"); @@ -212,7 +212,7 @@ fn dhatu_adesha_after_vikarana(p: &mut Prakriya) -> Option<()> { if dhatu.has_u("i\\N") && p.terms().get(i + 2).is_some() { let n2 = p.terms().get(i + 2)?; if n.has_u("Ric") && n2.has_u_in(&["san", "caN"]) { - let done = p.op_optional("2.4.50", |p| op::upadesha(p, i, "gAN")); + let done = p.run_optional("2.4.50", |p| op::upadesha(p, i, "gAN")); if done { it_samjna::run(p, i).ok()?; } @@ -220,7 +220,7 @@ fn dhatu_adesha_after_vikarana(p: &mut Prakriya) -> Option<()> { } if p.has(i + 1, |t| t.has_u("yaN")) && p.has(i + 2, |t| t.has_u("ac")) { - p.op_term("2.4.74", i + 1, op::luk); + p.run_at("2.4.74", i + 1, op::luk); p.set(i + 1, |t| t.add_tag(T::FlagAtLopa)); } @@ -238,17 +238,17 @@ fn try_aa_adesha(p: &mut Prakriya) -> Option<()> { if dhatu.has_text("vye") && n.has_lakshana("li~w") { p.step("6.1.46"); } else { - p.op_term("6.1.45", i, op::antya("A")); + p.run_at("6.1.45", i, op::antya("A")); } } else if dhatu.has_text_in(&["sPur", "sPul"]) && n.has_u("GaY") { // visPAra, visPAla - p.op_term("6.1.47", i, op::upadha("A")); + p.run_at("6.1.47", i, op::upadha("A")); } else if dhatu.has_u_in(&["qukrI\\Y", "i\\N", "ji\\"]) && n.has_u("Ric") { // krApayati, aDyApayati, jApayati - p.op_term("6.1.48", i, op::antya("A")); + p.run_at("6.1.48", i, op::antya("A")); } else if dhatu.has_u("zi\\Du~") && n.has_u("Ric") { // sADayati, seDayati - p.op_optional("6.1.49", op::t(i, op::upadha("A"))); + p.run_optional_at("6.1.49", i, op::upadha("A")); } // 6.1.50 has a circular dependency: @@ -266,7 +266,7 @@ fn try_aa_adesha(p: &mut Prakriya) -> Option<()> { let nau = n.has_u("Ric"); if dhatu.has_u_in(&["mI\\Y", "qumi\\Y", "dI\\N"]) && ashiti_lyapi && will_cause_guna(&n) { - p.op_term("6.1.50", i, op::antya("A")); + p.run_at("6.1.50", i, op::antya("A")); } else if dhatu.has_text("lI") && ashiti_lyapi && will_cause_guna(&n) @@ -275,19 +275,19 @@ fn try_aa_adesha(p: &mut Prakriya) -> Option<()> { // Accept both lI and lIN: // līyateriti yakā nirdeśo na tu śyanā. līlīṅorātvaṃ vā syādejviṣaye // lyapi ca. (SK) - p.op_optional("6.1.51", op::t(i, op::antya("A"))); + p.run_optional_at("6.1.51", i, op::antya("A")); } else if dhatu.has_u("sPura~") && nau { - p.op_optional("6.1.54", op::t(i, op::upadha("A"))); + p.run_optional_at("6.1.54", i, op::upadha("A")); } else if dhatu.has_u_in(&["ciY", "ci\\Y"]) && nau { - p.op_optional("6.1.54", op::t(i, op::antya("A"))); + p.run_optional_at("6.1.54", i, op::antya("A")); } else if dhatu.has_u("vI\\") && dhatu.has_gana(Gana::Adadi) && nau { // Check gana to avoid aj -> vI - p.op_optional("6.1.55", op::t(i, op::antya("A"))); + p.run_optional_at("6.1.55", i, op::antya("A")); } else if nau && p.has_tag(T::FlagHetuBhaya) { if dhatu.has_u("YiBI\\") { - p.op_optional("6.1.56", op::t(i, op::antya("A"))); + p.run_optional_at("6.1.56", i, op::antya("A")); } else if dhatu.has_text("smi") { - p.op_optional("6.1.57", op::t(i, op::antya("A"))); + p.run_optional_at("6.1.57", i, op::antya("A")); } } @@ -304,10 +304,10 @@ pub fn try_add_am_agama(p: &mut Prakriya) -> Option<()> { if n.has_adi(&*JHAL) && !n.has_tag(T::kit) { if dhatu.has_text_in(&["sfj", "dfS"]) { // srazwA, drazwA - p.op_term("6.1.58", i, op::mit("a")); + p.run_at("6.1.58", i, op::mit("a")); } else if dhatu.has_tag(T::Anudatta) && dhatu.has_upadha('f') { // traptA, tarpitA, tarptA - p.op_optional("6.1.59", op::t(i, op::mit("a"))); + p.run_optional_at("6.1.59", i, op::mit("a")); } } @@ -322,7 +322,7 @@ pub fn run_before_vikarana( let i = p.find_first(T::Dhatu)?; // Check the following term in case we have `san`, etc. - if p.has(i + 1, |t| t.has_tag(T::Ardhadhatuka)) || la_is_ardhadhatuka { + if p.has(i + 1, |t| t.is_ardhadhatuka()) || la_is_ardhadhatuka { // Rules are under 2.4.35 "ArdhadhAtuke". try_dhatu_adesha_before_vikarana(p, la); } diff --git a/vidyut-prakriya/src/args/krt.rs b/vidyut-prakriya/src/args/krt.rs index 0a2a385..a378ee2 100644 --- a/vidyut-prakriya/src/args/krt.rs +++ b/vidyut-prakriya/src/args/krt.rs @@ -216,6 +216,8 @@ pub enum Krt { amac, /// -ala (maNgala) alac, + /// -as (cetaH) + asun, /// -Ayya Ayya, /// -itnu @@ -234,6 +236,8 @@ pub enum Krt { isi, /// -u (kAru) uR, + /// -us (Danus) + usi, /// -atu (kratu) katu, /// -ka @@ -384,6 +388,7 @@ enum_boilerplate!(Krt, { // =============== amac => "amac", alac => "alac", + asun => "asu~n", Ayya => "Ayya", itnuc => "itnuc", iTin => "iTin", @@ -392,6 +397,7 @@ enum_boilerplate!(Krt, { isan => "isan", isi => "isi~", uR => "uR", + usi => "usi~", // TODO: why do we keep the initial 'k' here? kan => "a~kan", katu => "katu", diff --git a/vidyut-prakriya/src/ashtadhyayi.rs b/vidyut-prakriya/src/ashtadhyayi.rs index 593fddc..45f0c1d 100644 --- a/vidyut-prakriya/src/ashtadhyayi.rs +++ b/vidyut-prakriya/src/ashtadhyayi.rs @@ -230,8 +230,14 @@ fn derive_subanta( ) -> Result { let p = &mut prakriya; + // First, create the pratipadika. pratipadika_karya::run(p, pratipadika, args.linga()); stritva::run(p); + if p.terms().len() > 1 { + run_rules(p, None, false)?; + } + + // Then, add the sup-pratyaya. sup_karya::run(p, args); samjna::run(p); run_rules(p, None, false)?; diff --git a/vidyut-prakriya/src/atidesha.rs b/vidyut-prakriya/src/atidesha.rs index 626d9fd..5fd7fec 100644 --- a/vidyut-prakriya/src/atidesha.rs +++ b/vidyut-prakriya/src/atidesha.rs @@ -31,38 +31,38 @@ impl<'a> AtideshaPrakriya<'a> { } fn optional(&mut self, rule: Code, func: impl Fn(&mut Prakriya)) { - self.added = self.p.op_optional(rule, func); + self.added = self.p.run_optional(rule, func); } fn optional_block(&mut self, rule: Code) { - self.added = self.p.op_optional(rule, |_| {}); + self.added = self.p.run_optional(rule, |_| {}); } fn add_nit(&mut self, rule: Code, i: usize) { - self.p.op_term(rule, i, op::add_tag(T::Nit)); + self.p.run_at(rule, i, op::add_tag(T::Nit)); self.added = true; } fn optional_add_nit(&mut self, rule: Code, i: usize) { - self.added = self.p.op_optional(rule, op::t(i, |t| t.add_tag(T::Nit))); + self.added = self.p.run_optional_at(rule, i, |t| t.add_tag(T::Nit)); } fn add_kit(&mut self, rule: Code, i: usize) { - self.p.op_term(rule, i, op::add_tag(T::kit)); + self.p.run_at(rule, i, op::add_tag(T::kit)); self.added = true; } fn optional_add_kit(&mut self, rule: Code, i: usize) { - self.added = self.p.op_optional(rule, op::t(i, |t| t.add_tag(T::kit))); + self.added = self.p.run_optional_at(rule, i, |t| t.add_tag(T::kit)); } fn remove_kit(&mut self, rule: Code, i: usize) { - self.p.op_term(rule, i, |t| t.remove_tag(T::kit)); + self.p.run_at(rule, i, |t| t.remove_tag(T::kit)); self.added = true; } fn optional_remove_kit(&mut self, rule: Code, i: usize) { - self.added = self.p.op_optional(rule, op::t(i, |t| t.remove_tag(T::kit))); + self.added = self.p.run_optional_at(rule, i, |t| t.remove_tag(T::kit)); } } @@ -158,7 +158,7 @@ fn try_add_kit_for_sic(p: &mut Prakriya, i: usize) -> Option { if (cur.has_text("sTA") || cur.has_tag(T::Ghu)) && sic && atmanepadesu { // upAsTita, aDita, ... - wrap.p.op("1.2.17", |p| { + wrap.p.run("1.2.17", |p| { p.set(i, |t| t.set_antya("i")); p.set(i_n, |t| t.add_tag(T::kit)); }); @@ -293,7 +293,7 @@ pub fn run_after_attva(p: &mut Prakriya) -> Option<()> { let stha_ghu = dhatu.has_text("sTA") || dhatu.has_tag(T::Ghu); if stha_ghu && tin.is_atmanepada() && n.has_u("si~c") { let i_n_end = n.end(); - p.op("1.2.17", |p| { + p.run("1.2.17", |p| { p.set(i, op::antya("i")); p.set(i_n_end, op::add_tag(T::kit)); }); diff --git a/vidyut-prakriya/src/atmanepada.rs b/vidyut-prakriya/src/atmanepada.rs index 63a6f54..3a96149 100644 --- a/vidyut-prakriya/src/atmanepada.rs +++ b/vidyut-prakriya/src/atmanepada.rs @@ -95,22 +95,22 @@ impl<'a> PadaPrakriya<'a> { /// Marks this prakriya as AtmanepadI. fn atma(&mut self, rule: Code) { - self.p.op(rule, op_atmanepada); + self.p.run(rule, op_atmanepada); } /// Optionally marks this prakriya as AtmanepadI. fn optional_atma(&mut self, rule: impl Into) { - self.p.op_optional(rule, op_atmanepada); + self.p.run_optional(rule, op_atmanepada); } /// Marks this prakriya as parasmaipadI. fn para(&mut self, rule: Code) { - self.p.op(rule, op_parasmaipada); + self.p.run(rule, op_parasmaipada); } /// Marks this prakriya as parasmaipadI. fn optional_para(&mut self, rule: Code) { - self.p.op_optional(rule, op_parasmaipada); + self.p.run_optional(rule, op_parasmaipada); } } @@ -126,7 +126,7 @@ pub fn run(p: &mut Prakriya) -> Option<()> { let has_upasargas = p.find_prev_where(i, |t| t.is_upasarga()).is_some(); if p.is_bhave_or_karmani() { - p.op("1.3.13", op_atmanepada); + p.run("1.3.13", op_atmanepada); return None; } @@ -255,7 +255,7 @@ pub fn run(p: &mut Prakriya) -> Option<()> { { // If this option is declined, we'll use the general rule below (1.3.74). Thus we get // BAyayati/BAyayate per the normal rules and BApayate/BIzayate if 1.3.68 is accepted. - pp.p.op_optional("1.3.68", |p| { + pp.p.run_optional("1.3.68", |p| { op_atmanepada(p); p.add_tag(T::FlagHetuBhaya); }); diff --git a/vidyut-prakriya/src/bin/explain_subanta.rs b/vidyut-prakriya/src/bin/explain_subanta.rs index 2a790f2..cc408a2 100644 --- a/vidyut-prakriya/src/bin/explain_subanta.rs +++ b/vidyut-prakriya/src/bin/explain_subanta.rs @@ -36,7 +36,7 @@ fn pretty_print_prakriya(p: &Prakriya, args: &SubantaArgs) { ); println!("------------------------------"); for step in p.history() { - println!("{:<10} | {}", step.rule(), step.result()); + println!("{:<10?} | {}", step.rule(), step.result()); } println!("------------------------------"); for choice in p.rule_choices() { diff --git a/vidyut-prakriya/src/char_view.rs b/vidyut-prakriya/src/char_view.rs index e1e89d5..8d3de94 100644 --- a/vidyut-prakriya/src/char_view.rs +++ b/vidyut-prakriya/src/char_view.rs @@ -2,91 +2,153 @@ use crate::prakriya::Prakriya; use crate::term::Term; use compact_str::CompactString; -/// A Prakriya that caches the `text` property of the prakriya. It also provides utilities for -/// working with chars in the prakriya text. +/// A wrapper for `Prakriya` that has stronger support for sound rules that apply within and across +/// term boundaries. +/// +/// Internally, `CharPrakriya` saves `prakriya.text()` to an ordinary string, which facilitates +/// applying character-based rules. `CharPrakriya` ensures that this string is up to date by +/// rebuilding the string whenever the system adds a new rule to the prakriya. pub(crate) struct CharPrakriya<'a> { - pub p: &'a mut Prakriya, - pub text: CompactString, + // The string representation of the prakriya. + text: CompactString, + // The prakriya that this struct wraps. `p` is private so that callers cannot mutate `p` + // without also updating `is_stale`. + p: &'a mut Prakriya, + // Whether `text` is in sync with the latest state in `p`. If `is_stale` is true, then + // `for_chars` will update `text` before beginning execution. + is_stale: bool, } + impl<'a> CharPrakriya<'a> { pub fn new(p: &'a mut Prakriya) -> Self { - let text = CompactString::from(p.text()); - CharPrakriya { p, text } + let text = p.compact_text(); + Self { + p, + text, + is_stale: false, + } } - #[allow(unused)] - pub fn char_rule( + /// Iterates over all characters in the prakriya. If `filter` applies at some index `i`, this + /// method applies `operator` to the same index `i`. + /// + /// For `filter`, we recommend using our `xy` and `xyz` functions, which are easier to manage. + /// + /// + /// ### API design + /// + /// A more natural way to implement this kind of logic is through a `for` loop over a sliding + /// window of characters, which we can call `char_window()` for the sake of this example. + /// Unfortunately, we have found this kind of approach difficult to implement in Rust. The + /// reason is that `.char_window()` and the body of the `for` loop would both require a mutable + /// reference to `CharPrakriya`, which violates Rust's restrictions on mutable memory access. + /// + /// Therefore, we have opted instead for this closure-based approach, which strictly controls + /// access to the mutable `CharPrakriya` struct. + pub fn for_chars( &mut self, filter: impl Fn(&mut Prakriya, &str, usize) -> bool, operator: impl Fn(&mut Prakriya, &str, usize) -> bool, ) { - let mut counter = 0; - loop { - let text = &self.text; - let mut changed_text = false; - - for i in 0..text.len() { - if filter(self.p, text, i) { - changed_text = operator(self.p, &self.text, i); - // Once the text has changed, our indices need to be reset. So, break the loop and - // try again. - if changed_text { - self.text = CompactString::from(self.p.text()); - break; - } - } + if self.is_stale { + self.text = self.p.compact_text(); + self.is_stale = false; + } + + let mut change_counter = 0; + let mut i = 0; + let mut len = self.text.len(); + while i < len { + let mut changed = false; + if filter(self.p, &self.text, i) { + // TODO: consider checking the state of `self.text` manually instead of requiring a + // boolean value from `operator`. In theory, `operator` can change any part of + // `text`, so we cannot measure a change unless we make a direct string comparison. + changed = operator(self.p, &self.text, i); } - if !changed_text { - break; + if changed { + change_counter += 1; + self.text = self.p.compact_text(); + len = self.text.len(); + } else { + i += 1; } - counter += 1; assert!( - counter <= 10, + change_counter <= 10, "Possible infinite loop: {:?}", self.p.history() ); } } - #[allow(unused)] - pub fn char_at(&self, i_char: usize) -> Option { - self.text.as_bytes().get(i_char).map(|x| *x as char) - } + /// Iterates over all characters in the prakriya in reverse order. If `filter` applies at some + /// index `i`, this method applies `operator` to the same index `i`. + /// + /// We have both `for_chars` and `for_chars_rev` because certain rules depend on applying these + /// changes in reverse order. For an example, see rule 8.3.61 (stautiṇyoreva ṣaṇyabhyāsāt), + /// which conditions ṣatva for the dhatu on ṣatva in san-pratyaya. + /// + /// TODO: consider standardizing on reverse-order iteration everywhere. + pub fn for_chars_rev( + &mut self, + filter: impl Fn(&mut Prakriya, &str, usize) -> bool, + operator: impl Fn(&mut Prakriya, &str, usize) -> bool, + ) { + if self.is_stale { + self.text = self.p.compact_text(); + self.is_stale = false; + } - /// Replaces character `i` of the current prakriya with the given substitute. - pub fn set_at(&mut self, index: usize, substitute: &str) { - let mut cur = 0; - for t in self.p.terms_mut() { - let delta = t.text.len(); - if (cur..cur + delta).contains(&index) { - let t_offset = index - cur; - t.text.replace_range(t_offset..=t_offset, substitute); - return; - } - cur += delta; + let mut change_counter = 0; + if self.text.is_empty() { + return; } - } + let mut i = self.text.len(); - #[allow(unused)] - pub fn term_at(&self, i_char: usize) -> Option<&Term> { - match self.term_index_at(i_char) { - Some(i) => self.p.get(i), - None => None, + while i > 0 { + let mut changed = false; + if filter(self.p, &self.text, i - 1) { + changed = operator(self.p, &self.text, i - 1); + } + + if changed { + change_counter += 1; + self.text = self.p.compact_text(); + } else { + i -= 1; + } + + assert!( + change_counter <= 10, + "Possible infinite loop: {:?}", + self.p.history() + ); } } - pub fn term_index_at(&self, i_char: usize) -> Option { - let mut cur = 0; - for (i, t) in self.p.terms().iter().enumerate() { - let delta = t.text.len(); - if (cur..cur + delta).contains(&i_char) { - return Some(i); + /// Processes a sliding window of terms, where each term is non-empty. + /// + /// - `filter` receives two consecutive terms and returns whether the rule should apply. + /// - `op` receives the prakriya and the indices of the two terms. + pub fn for_terms( + &mut self, + filter: impl Fn(&Term, &Term) -> bool, + op: impl Fn(&mut Prakriya, usize, usize), + ) -> Option<()> { + let n = self.p.terms().len(); + for i in 0..n - 1 { + let j = self.p.find_next_where(i, |t| !t.is_empty())?; + let x = self.p.get(i)?; + let y = self.p.get(j)?; + if filter(x, y) { + op(self.p, i, j); + self.is_stale = true; } - cur += delta; } - None + + Some(()) } } @@ -117,55 +179,7 @@ pub fn get_at(p: &Prakriya, index: usize) -> Option<&Term> { None } -pub(crate) fn get_index_at(p: &mut Prakriya, index: usize) -> Option { - get_term_and_offset_indices(p, index).map(|(i_term, _)| i_term) -} - -/// Replaces character `i` of the current prakriya with the given substitute. -pub fn set_at(p: &mut Prakriya, index: usize, substitute: &str) { - let mut cur = 0; - for t in p.terms_mut() { - let delta = t.text.len(); - if (cur..cur + delta).contains(&index) { - let t_offset = index - cur; - t.text.replace_range(t_offset..=t_offset, substitute); - return; - } - cur += delta; - } -} - -/// Applies a sound-based rule to the given prakriya. -pub fn char_rule( - p: &mut Prakriya, - filter: impl Fn(&mut Prakriya, &str, usize) -> bool, - operator: impl Fn(&mut Prakriya, &str, usize) -> bool, -) { - let mut counter = 0; - loop { - let text = p.compact_text(); - let mut changed_text = false; - - for i in 0..text.len() { - if filter(p, &text, i) { - changed_text = operator(p, &text, i); - // Once the text has changed, our indices need to be reset. So, break the loop and - // try again. - if changed_text { - break; - } - } - } - - if !changed_text { - break; - } - - counter += 1; - assert!(counter <= 10, "Possible infinite loop: {:?}", p.history()); - } -} - +/// Helper function for iterating over a sliding window that is two characters long. pub fn xy(inner: impl Fn(char, char) -> bool) -> impl Fn(&mut Prakriya, &str, usize) -> bool { move |_, text, i| { let x = text.as_bytes().get(i); @@ -178,6 +192,7 @@ pub fn xy(inner: impl Fn(char, char) -> bool) -> impl Fn(&mut Prakriya, &str, us } } +/// Helper function for iterating over a sliding window that is three characters long. pub fn xyz( inner: impl Fn(char, char, char) -> bool, ) -> impl Fn(&mut Prakriya, &str, usize) -> bool { diff --git a/vidyut-prakriya/src/dhatu_karya.rs b/vidyut-prakriya/src/dhatu_karya.rs index 23fa5a8..40af663 100644 --- a/vidyut-prakriya/src/dhatu_karya.rs +++ b/vidyut-prakriya/src/dhatu_karya.rs @@ -22,7 +22,7 @@ use crate::term::Term; /// Adds the mula-dhatu to the prakriya. fn add_mula_dhatu(p: &mut Prakriya, dhatu: &Dhatu) { - p.op("1.3.1", |p| { + p.run("1.3.1", |p| { let mut dhatu = Term::make_dhatu(dhatu.upadesha(), dhatu.gana(), dhatu.antargana()); dhatu.add_tag(T::Dhatu); p.push(dhatu); @@ -33,7 +33,7 @@ fn add_samjnas(p: &mut Prakriya, i: usize) { if p.has(i, |t| { t.has_text_in(&["dA", "de", "do", "DA", "De"]) && !t.has_u("dA\\p") }) { - p.op_term("1.1.20", i, op::add_tag(T::Ghu)); + p.run_at("1.1.20", i, op::add_tag(T::Ghu)); }; } @@ -54,9 +54,9 @@ fn try_run_bhvadi_gana_sutras(p: &mut Prakriya) -> Option<()> { p.step(DP("01.0937")); is_mit_blocked = true; } else if dhatu.has_u("Samo~") { - is_mit_blocked = p.op_optional(DP("01.0938"), |_| {}) + is_mit_blocked = p.run_optional(DP("01.0938"), |_| {}) } else if dhatu.has_text("yam") && is_bhvadi { - is_mit_blocked = p.op_optional(DP("01.0939"), |_| {}) + is_mit_blocked = p.run_optional(DP("01.0939"), |_| {}) } else if dhatu.has_u("sKadi~\\r") && i > 0 && p.has(i - 1, |t| t.has_u_in(&["ava", "pari"])) @@ -71,16 +71,16 @@ fn try_run_bhvadi_gana_sutras(p: &mut Prakriya) -> Option<()> { if is_mit_blocked { // Do nothing. } else if is_bhvadi && dhatu.has_text_in(&["jval", "hval", "hmal", "nam"]) && !has_upasarga { - p.op_optional(DP("01.0935"), op::t(i, op::add_tag(T::mit))); + p.run_optional_at(DP("01.0935"), i, op::add_tag(T::mit)); } else if dhatu.has_text_in(&["glE", "snA", "van", "vam"]) && !has_upasarga { - p.op_optional(DP("01.0936"), op::t(i, op::add_tag(T::mit))); + p.run_optional_at(DP("01.0936"), i, op::add_tag(T::mit)); } else if (dhatu.has_u_in(&["janI~\\", "jFz", "knasu~", "ra\\nja~^"]) && dhatu.has_gana(Gana::Divadi)) || (is_bhvadi && dhatu.ends_with("am")) { - p.op_term(DP("01.0934"), i, op::add_tag(T::mit)); + p.run_at(DP("01.0934"), i, op::add_tag(T::mit)); } else if is_bhvadi && dhatu.has_u_in(gana::GHAT_ADI) { - p.op_term(DP("01.0933"), i, op::add_tag(T::mit)); + p.run_at(DP("01.0933"), i, op::add_tag(T::mit)); } Some(()) @@ -96,7 +96,7 @@ fn try_run_divadi_gana_sutras(p: &mut Prakriya) -> Option<()> { "zUN", "dUN", "dI\\N", "qIN", "DI\\N", "mI\\N", "rI\\N", "lI\\N", "vrI\\N", ]) { // sUna, dUna, dIna, ... - p.op_term(DP("04.0162"), i, op::add_tag(T::odit)); + p.run_at(DP("04.0162"), i, op::add_tag(T::odit)); } Some(()) @@ -108,14 +108,14 @@ fn try_run_curadi_gana_sutras(p: &mut Prakriya, i: usize) -> Option<()> { let dhatu = p.get_if(i, |t| t.has_gana(Gana::Curadi))?; if dhatu.has_u_in(gana::JNAP_ADI) { - p.op_term(DP("10.0493"), i, op::add_tag(T::mit)); + p.run_at(DP("10.0493"), i, op::add_tag(T::mit)); } let dhatu = p.get(i)?; if dhatu.has_antargana(Antargana::Akusmiya) { - p.op(DP("10.0496"), |p| p.add_tag(T::Atmanepada)); + p.run(DP("10.0496"), |p| p.add_tag(T::Atmanepada)); } else if dhatu.has_u_in(gana::AAGARVIYA) { - p.op(DP("10.0497"), |p| p.add_tag(T::Atmanepada)); + p.run(DP("10.0497"), |p| p.add_tag(T::Atmanepada)); } Some(()) @@ -129,7 +129,7 @@ fn try_satva_and_natva(p: &mut Prakriya, i: usize) -> Option<()> { p.step("6.1.64.v1"); } else if dhatu.has_prefix_in(&["zw", "zW", "zR", "zaR"]) { // Varttika -- also change the next sound - p.op_term("6.1.64.v2", i, |t| { + p.run_at("6.1.64.v2", i, |t| { match &t.text[..2] { "zw" => t.text.replace_range(..2, "st"), "zW" => t.text.replace_range(..2, "sT"), @@ -145,19 +145,19 @@ fn try_satva_and_natva(p: &mut Prakriya, i: usize) -> Option<()> { }); } else { // zah -> sah - p.op_term("6.1.64", i, |t| { + p.run_at("6.1.64", i, |t| { t.add_tag(T::FlagAdeshadi); t.set_adi("s"); }); } } else if dhatu.has_adi('R') { // RI -> nI - p.op_term("6.1.65", i, |t| { + p.run_at("6.1.65", i, |t| { t.add_tag(T::FlagAdeshadi); t.set_adi("n"); }); } else if dhatu.has_u("DraRa~") { - p.op_term(Rule::Kaumudi("2318"), i, |t| { + p.run_at(Rule::Kaumudi("2318"), i, |t| { t.set_text("Dran"); }); } @@ -174,7 +174,7 @@ fn try_satva_and_natva(p: &mut Prakriya, i: usize) -> Option<()> { // TODO: why exception for cakz? fn try_add_num_agama(p: &mut Prakriya, i: usize) { if p.has(i, |t| t.has_tag(T::idit) && !t.has_u("ca\\kzi~\\N")) { - p.op_term("7.1.58", i, op::mit("n")); + p.run_at("7.1.58", i, op::mit("n")); } } diff --git a/vidyut-prakriya/src/dvitva.rs b/vidyut-prakriya/src/dvitva.rs index 2c859b2..1cb531c 100644 --- a/vidyut-prakriya/src/dvitva.rs +++ b/vidyut-prakriya/src/dvitva.rs @@ -54,7 +54,7 @@ fn try_dvitva_for_ajadi_dhatu(rule: Code, p: &mut Prakriya, i: usize) -> Option< p.insert_after(i, abhyasa); p.insert_after(i + 1, third); p.step(rule); - p.op_term("6.1.4", i + 1, op::add_tag(T::Abhyasa)); + p.run_at("6.1.4", i + 1, op::add_tag(T::Abhyasa)); p.set(i, |t| t.add_tag(T::Abhyasta)); p.set(i + 1, |t| t.add_tag(T::Abhyasta)); @@ -135,8 +135,8 @@ fn try_dvitva_for_sanadi_ajadi(rule: Code, p: &mut Prakriya, i_dhatu: usize) -> } p.step(rule); - p.op_term("6.1.4", i_ac + 1, |t| t.add_tag(T::Abhyasa)); - p.op("6.1.5", |p| { + p.run_at("6.1.4", i_ac + 1, |t| t.add_tag(T::Abhyasa)); + p.run("6.1.5", |p| { p.set(i_ac, op::add_tag(T::Abhyasta)); p.set(i_ac + 1, op::add_tag(T::Abhyasta)); p.set(i_dhatu, |t| t.add_tags(&[T::Abhyasta, T::Dvitva])); @@ -177,7 +177,7 @@ fn try_dvitva(rule: Code, p: &mut Prakriya, i: usize) -> Option<()> { let i_abhyasa = i; let i_dhatu = i + 1; - p.op_term("6.1.4", i_abhyasa, op::add_tag(T::Abhyasa)); + p.run_at("6.1.4", i_abhyasa, op::add_tag(T::Abhyasa)); p.set(i_abhyasa, |t| t.add_tag(T::Abhyasta)); p.set(i_dhatu, |t| t.add_tags(&[T::Abhyasta, T::Dvitva])); @@ -206,7 +206,7 @@ fn run_at_index(p: &mut Prakriya, i: usize) -> Option<()> { // These are termed abhyasta, but they can still undergo dvitva because // the rules below are conditioned specifically on "anabhyAsasya" ("not having an abhyasa") // from 6.1.8. - p.op_term("6.1.6", i, op::add_tag(T::Abhyasta)); + p.run_at("6.1.6", i, op::add_tag(T::Abhyasta)); } // Use a view to include `iw`-Agama. Skip vu~k and other dhatu-agamas. @@ -220,7 +220,7 @@ fn run_at_index(p: &mut Prakriya, i: usize) -> Option<()> { // dayateḥ iti dīṅo grahaṇaṃ na tu daya dāne ityasya. // digyādeśena dvirvacanasya bādhanam iṣyate. if dhatu.has_u("de\\N") { - p.op_term("7.4.9", i, op::text("digi")); + p.run_at("7.4.9", i, op::text("digi")); } else { try_dvitva("6.1.8", p, i); } diff --git a/vidyut-prakriya/src/it_agama.rs b/vidyut-prakriya/src/it_agama.rs index 00b509e..1450b27 100644 --- a/vidyut-prakriya/src/it_agama.rs +++ b/vidyut-prakriya/src/it_agama.rs @@ -183,8 +183,7 @@ fn try_lengthen_it_agama(p: &mut Prakriya, i: usize) -> Option<()> { if dhatu.has_text("grah") { if !n.has_tag(T::Cinvat) { - p.op_term("7.2.37", i, op::text("I")); - p.step("cinvat"); + p.run_at("7.2.37", i, op::text("I")); } } else if dhatu.has_antya('F') || dhatu.has_text("vf") { if last.has_lakshana("li~N") { @@ -192,7 +191,7 @@ fn try_lengthen_it_agama(p: &mut Prakriya, i: usize) -> Option<()> { } else if n.slice().iter().any(|t| t.has_u("si~c")) && last.is_parasmaipada() { p.step("7.2.40"); } else { - p.op_optional("7.2.38", op::t(i, op::text("I"))); + p.run_optional_at("7.2.38", i, op::text("I")); } } @@ -434,7 +433,7 @@ fn run_valadau_ardhadhatuke_before_attva_for_term(ip: &mut ItPrakriya) -> Option let mut can_run = true; // TODO: Adikarmani. if ip.p.any(&[T::Bhave]) { - can_run = ip.p.op_optional("7.2.17", |_| {}); + can_run = ip.p.run_optional("7.2.17", |_| {}); } if can_run { ip.try_block("7.2.16"); @@ -556,8 +555,7 @@ fn run_sarvadhatuke_for_term(ip: &mut ItPrakriya) -> Option<()> { let rudh_adi = &["rudi~r", "Yizva\\pa~", "Svasa~", "ana~", "jakza~"]; let is_aprkta = n.slice().iter().map(|t| t.text.len()).sum::() == 1; if anga.has_u("a\\da~") && is_aprkta { - ip.p.op("7.3.100", |p| op::insert_agama_before(p, i_n, "aw")); - it_samjna::run(ip.p, i_n).expect("ok"); + op::insert_agama_at("7.3.100", ip.p, i_n, "aw"); } else if anga.has_u_in(rudh_adi) { // First, check if we should use It-agama instead. // @@ -571,9 +569,9 @@ fn run_sarvadhatuke_for_term(ip: &mut ItPrakriya) -> Option<()> { let is_pit = n.has_tag(T::pit) && !n.has_tag(T::Nit); if n.has_adi(&*HAL) && n.has_tag(T::Sarvadhatuka) && is_pit && is_aprkta { let use_at = - ip.p.op_optional("7.3.99", |p| op::insert_agama_before(p, i_n, "aw")); + ip.p.run_optional("7.3.99", |p| op::insert_agama_before(p, i_n, "aw")); if !use_at { - ip.p.op("7.3.98", |p| op::insert_agama_before(p, i_n, "Iw")); + ip.p.run("7.3.98", |p| op::insert_agama_before(p, i_n, "Iw")); } it_samjna::run(ip.p, i_n).ok()?; } else { @@ -643,7 +641,7 @@ pub fn run_after_attva(p: &mut Prakriya) -> Option<()> { let dhatu = p.get(i)?; let is_para = p.terms().last()?.has_tag(T::Parasmaipada); if is_para && dhatu.has_antya('A') && n.has_adi(&*VAL) { - p.op("7.2.73", |p| { + p.run("7.2.73", |p| { p.set(i, |t| t.text.push('s')); op::insert_agama_after(p, i, "iw"); it_samjna::run(p, i + 1).ok(); diff --git a/vidyut-prakriya/src/it_samjna.rs b/vidyut-prakriya/src/it_samjna.rs index 4cfac9d..4239cef 100644 --- a/vidyut-prakriya/src/it_samjna.rs +++ b/vidyut-prakriya/src/it_samjna.rs @@ -144,7 +144,7 @@ pub fn run(p: &mut Prakriya, i: usize) -> Result<()> { if let Some(t) = p.get_mut(i) { if HAL.contains(antya) && !irit { - let vibhaktau_tusmah = t.has_tag(T::Vibhakti) && TUSMA.contains(antya); + let vibhaktau_tusmah = t.is_vibhakti() && TUSMA.contains(antya); if !vibhaktau_tusmah { t.add_tag(T::parse_it(antya)?); temp.truncate(temp.len() - 1); diff --git a/vidyut-prakriya/src/krt/basic.rs b/vidyut-prakriya/src/krt/basic.rs index cd2ca77..6b833f0 100644 --- a/vidyut-prakriya/src/krt/basic.rs +++ b/vidyut-prakriya/src/krt/basic.rs @@ -598,7 +598,7 @@ fn try_add_upapada_krt(p: &mut Prakriya, krt: Krt) -> Option { kp.try_add("3.2.19", wa); } } else if dhatu.has_u("qukf\\Y") { - if upapada.has_text_in(&DIVA_ADI) || upapada.has_tag(T::Sankhya) { + if upapada.has_text_in(DIVA_ADI) || upapada.has_tag(T::Sankhya) { kp.try_add("3.2.21", wa); } else if upapada.has_text("karman") { kp.optional_try_add("3.2.22", wa); @@ -763,13 +763,13 @@ fn try_add_upapada_krt(p: &mut Prakriya, krt: Krt) -> Option { } Kyun => { - if upapada.has_text_in(&ADHYA_ADI) && dhatu.has_u("qukf\\Y") { + if upapada.has_text_in(ADHYA_ADI) && dhatu.has_u("qukf\\Y") { kp.try_add("3.2.56", krt); } } KizRuc | KukaY => { - if upapada.has_text_in(&ADHYA_ADI) && dhatu.has_u("BU") { + if upapada.has_text_in(ADHYA_ADI) && dhatu.has_u("BU") { kp.try_add("3.2.57", krt); } } @@ -793,7 +793,7 @@ fn try_add_upapada_krt(p: &mut Prakriya, krt: Krt) -> Option { } else if kp.has_upapada("ud") && dhatu.has_u("zRi\\ha~") { kp.do_nipatana(code, "uzRih"); } else if dhatu.has_u("ancu~") { - kp.p.op_term(code, i_dhatu, |t| { + kp.p.run_at(code, i_dhatu, |t| { t.set_text("aYc"); t.add_tag(T::Krt); }); @@ -922,7 +922,7 @@ fn try_add_krt(p: &mut Prakriya, krt: Krt) -> Option { let added = kp.try_add("3.1.96", krt); if added && krt == K::tavyat && kp.dhatu().has_u("va\\sa~") { // vAstavya - kp.p.op_optional("3.1.96.v1", op::t(i + 1, |t| t.add_tag(T::Rit))); + kp.p.run_optional_at("3.1.96.v1", i + 1, |t| t.add_tag(T::Rit)); } } @@ -954,11 +954,11 @@ fn try_add_krt(p: &mut Prakriya, krt: Krt) -> Option { kp.optional_try_add("3.1.120", K::kyap); } else { // This rule makes rule 3.1.110 optional for vfz. - skip_3_1_110 = kp.p.op_optional("3.1.120", |_| {}); + skip_3_1_110 = kp.p.run_optional("3.1.120", |_| {}); } } else if dhatu.has_text("mfj") { // This rule makes rule 3.1.110 optional for mfj. - skip_3_1_110 = kp.p.op_optional("3.1.113", |_| {}); + skip_3_1_110 = kp.p.run_optional("3.1.113", |_| {}); } // Specific rules (required) @@ -1137,7 +1137,7 @@ fn try_add_krt(p: &mut Prakriya, krt: Krt) -> Option { if kp.has_krt { let i_last = kp.p.terms().len() - 1; - kp.p.op_term("1.1.26", i_last, op::add_tag(T::Nistha)); + kp.p.run_at("1.1.26", i_last, op::add_tag(T::Nistha)); } } @@ -1208,7 +1208,7 @@ fn try_add_krt(p: &mut Prakriya, krt: Krt) -> Option { if has_pada_match && !kp.has_krt { let i_la = kp.p.terms().len() - 1; kp.try_replace_lakara("3.2.128", i_la, krt); - kp.p.op_term("3.2.127", i_la, op::add_tag(T::Sat)); + kp.p.run_at("3.2.127", i_la, op::add_tag(T::Sat)); } } @@ -1273,7 +1273,7 @@ fn try_add_krt(p: &mut Prakriya, krt: Krt) -> Option { if dhatu.has_tag(T::qvit) { if kp.try_add("3.3.88", krt) { // TODO: put this somewhere else? - kp.p.op("4.4.20", |p| { + kp.p.run("4.4.20", |p| { p.push(Taddhita::map.to_term()); }); it_samjna::run(kp.p, i + 2).expect("should never fail"); diff --git a/vidyut-prakriya/src/krt/unadi_sutras.rs b/vidyut-prakriya/src/krt/unadi_sutras.rs index 9127401..6210868 100644 --- a/vidyut-prakriya/src/krt/unadi_sutras.rs +++ b/vidyut-prakriya/src/krt/unadi_sutras.rs @@ -99,9 +99,6 @@ pub fn try_add_unadi(p: &mut Prakriya, krt: Krt) -> Option { kp.try_add(Unadi("1.77"), krt); } } - K::manin => { - kp.try_add(Unadi("1.144"), krt); - } K::kTan => { if dhatu.has_u_in(&["ha\\na~", "kuza~", "RI\\Y", "ama~", "kASf~"]) { kp.try_add(Unadi("2.2"), krt); @@ -113,6 +110,19 @@ pub fn try_add_unadi(p: &mut Prakriya, krt: Krt) -> Option { // TODO: id-antaH api } } + K::usi => { + if dhatu.has_u("janI~\\") { + kp.try_add(Unadi("2.115"), krt); + } else if dhatu.has_text_in(&["f", "pF", "vap", "yaj", "tan", "Dan", "tap"]) { + kp.try_add_with(Unadi("2.117"), krt, |p| p.set(i + 1, |t| t.add_tag(T::nit))); + } else if dhatu.has_u("i\\R") { + kp.try_add_with(Unadi("2.118"), krt, |p| p.set(i + 1, |t| t.add_tag(T::Rit))); + } else if dhatu.has_u("ca\\kzi~\\N") { + kp.try_add_with(Unadi("2.119"), krt, |p| p.set(i + 1, |t| t.add_tag(T::Sit))); + } else if dhatu.has_text("muh") { + kp.try_add_with(Unadi("2.120"), krt, |p| p.set(i + 1, |t| t.add_tag(T::kit))); + } + } K::itnuc => { if dhatu.has_u_in(&["stana", "hfza~", "gada", "mada~", "spfha", "gfha"]) && nau { // stanayitnu, ... @@ -280,9 +290,22 @@ pub fn try_add_unadi(p: &mut Prakriya, krt: Krt) -> Option { kp.try_add(Unadi("4.54"), krt); } } + K::in_ => { + kp.try_add(Unadi("4.117"), krt); + } + K::manin => { + kp.try_add(Unadi("4.144"), krt); + } K::zwran => { kp.try_add(Unadi("4.158"), krt); } + K::asun => { + if dhatu.has_text("rap") { + kp.try_add_with(Unadi("4.189"), krt, |p| p.set(i, |t| t.set_upadha("e"))); + } else { + kp.try_add(Unadi("4.188"), krt); + } + } K::amac => { if dhatu.has_u("praTa~\\") { kp.try_add(Unadi("5.68"), krt); diff --git a/vidyut-prakriya/src/krt/utils.rs b/vidyut-prakriya/src/krt/utils.rs index 254a6a4..b9f8e8d 100644 --- a/vidyut-prakriya/src/krt/utils.rs +++ b/vidyut-prakriya/src/krt/utils.rs @@ -155,14 +155,14 @@ impl<'a> KrtPrakriya<'a> { } pub fn do_nipatana(&mut self, rule: impl Into, sub: &str) { - self.p.op(rule, op::nipatana(sub)); + self.p.run(rule, op::nipatana(sub)); self.had_match = true; self.has_krt = true } pub fn optional_do_nipatana(&mut self, rule: impl Into, sub: &str) -> bool { self.had_match = true; - if self.p.op_optional(rule, op::nipatana(sub)) { + if self.p.run_optional(rule, op::nipatana(sub)) { self.has_krt = true; true } else { @@ -184,7 +184,7 @@ impl<'a> KrtPrakriya<'a> { self.had_match = true; if self.krt == krt && !self.has_krt { // Insert term with it-samjna-prakarana. - self.p.op(rule, |p| { + self.p.run(rule, |p| { p.push(krt.to_term()); func(p); }); diff --git a/vidyut-prakriya/src/lib.rs b/vidyut-prakriya/src/lib.rs index 83af2bc..0775426 100644 --- a/vidyut-prakriya/src/lib.rs +++ b/vidyut-prakriya/src/lib.rs @@ -5,7 +5,7 @@ pub use crate::ashtadhyayi::{Ashtadhyayi, AshtadhyayiBuilder}; pub use crate::dhatupatha::Dhatupatha; pub use crate::errors::Error; -pub use crate::prakriya::{Code, Prakriya, RuleChoice, Step}; +pub use crate::prakriya::{Prakriya, Rule, RuleChoice, Step}; // Public modules. // - `args` defines the API contract. diff --git a/vidyut-prakriya/src/misc.rs b/vidyut-prakriya/src/misc.rs index 2cdfc6b..27ee06a 100644 --- a/vidyut-prakriya/src/misc.rs +++ b/vidyut-prakriya/src/misc.rs @@ -23,7 +23,7 @@ pub fn run_pad_adi(p: &mut Prakriya) -> Option<()> { if is_shas_prabhrti { if let Some(sub) = op::yatha(&prati.text, PADA_ADI, PAD_ADI) { - p.op_optional("6.1.63", op::t(i_prati, |t| t.set_text(sub))); + p.run_optional_at("6.1.63", i_prati, |t| t.set_text(sub)); } } diff --git a/vidyut-prakriya/src/operators.rs b/vidyut-prakriya/src/operators.rs index 7be9576..3e3f0e9 100644 --- a/vidyut-prakriya/src/operators.rs +++ b/vidyut-prakriya/src/operators.rs @@ -115,6 +115,13 @@ pub fn insert_agama_after(p: &mut Prakriya, i: usize, u: &str) { p.insert_after(i, agama); } +/// Inserts `agama` at index `i` of the prakriya then runs the it-samjna-prakarana. +pub fn insert_agama_at(rule: impl Into, p: &mut Prakriya, index: usize, agama: &str) { + insert_agama_before(p, index, agama); + p.step(rule.into()); + it_samjna::run(p, index).expect("ok"); +} + // legacy func that marks the rule after it-samjna-prakarana. pub fn upadesha(p: &mut Prakriya, i: usize, sub: &str) { if let Some(t) = p.get_mut(i) { diff --git a/vidyut-prakriya/src/prakriya.rs b/vidyut-prakriya/src/prakriya.rs index 997aa1e..3afa94a 100644 --- a/vidyut-prakriya/src/prakriya.rs +++ b/vidyut-prakriya/src/prakriya.rs @@ -27,6 +27,20 @@ pub enum Rule { Kaumudi(&'static str), } +impl Rule { + /// The string reprentation of this rule. + pub fn code(&self) -> &'static str { + match self { + Self::Ashtadhyayi(x) => x, + Self::Kashika(x) => x, + Self::Dhatupatha(x) => x, + Self::Unadi(x) => x, + Self::Linganushasana(x) => x, + Self::Kaumudi(x) => x, + } + } +} + // Since Ashtadhyayi rules are by far the most common, assume by default that static strings refer // to rules in the Ashtadhyayi. impl From<&'static str> for Rule { @@ -44,16 +58,8 @@ pub struct Step { impl Step { /// The rule that produced the current step. - // TODO: render different `Rule` types differently. - pub fn rule(&self) -> String { - match self.rule { - Rule::Ashtadhyayi(x) => x.to_string(), - Rule::Kashika(x) => format!("Kashika {x}"), - Rule::Dhatupatha(x) => format!("Dhatu {x}"), - Rule::Unadi(x) => format!("Unadi {x}"), - Rule::Linganushasana(x) => format!("Linga {x}"), - Rule::Kaumudi(x) => format!("Kaumudi {x}"), - } + pub fn rule(&self) -> Rule { + self.rule } /// The result of applying `rule`. @@ -125,7 +131,7 @@ impl Prakriya { &self.history } - /// [experimental] Returns the semantic condition (artha) under which this prakriya was + /// (experimental) Returns the semantic condition (artha) under which this prakriya was /// created. pub fn artha(&self) -> Option { self.artha @@ -305,6 +311,33 @@ impl Prakriya { None } + /// Finds the term that contains the char at index `i_char` in `self.text()`. + pub fn find_for_char_at(&self, i_char: usize) -> Option { + let mut cur = 0; + for (i, t) in self.terms().iter().enumerate() { + let delta = t.text.len(); + if (cur..cur + delta).contains(&i_char) { + return Some(i); + } + cur += delta; + } + None + } + + /// Replaces character `i` of the current prakriya with the given substitute. + pub fn set_char_at(&mut self, i_char: usize, substitute: &str) { + let mut cur = 0; + for t in self.terms_mut() { + let delta = t.text.len(); + if (cur..cur + delta).contains(&i_char) { + let i_offset = i_char - cur; + t.text.replace_range(i_offset..=i_offset, substitute); + return; + } + cur += delta; + } + } + // Filters /// Returns whether a term exists at `index` and matches the condition in `filter`. @@ -396,15 +429,15 @@ impl Prakriya { // Rule application - /// Applies the given operator. - pub(crate) fn op(&mut self, code: impl Into, operator: impl Fn(&mut Prakriya)) -> bool { + /// Runs the given operator. + pub(crate) fn run(&mut self, code: impl Into, operator: impl Fn(&mut Prakriya)) -> bool { operator(self); self.step(code); true } /// Applies the given operator to the given term. - pub(crate) fn op_term( + pub(crate) fn run_at( &mut self, rule: impl Into, index: usize, @@ -423,16 +456,30 @@ impl Prakriya { /// /// Returns: whether the operation was applied. This return value is required for certain /// complex conditions (e.g. 6.4.116 & 117; "if this rule was not applied, ..."). - pub(crate) fn op_optional( + pub(crate) fn run_optional( &mut self, rule: impl Into, operator: impl Fn(&mut Prakriya), ) -> bool { let rule = rule.into(); if self.is_allowed(rule) { - operator(self); - self.step(rule); - true + self.run(rule, operator) + } else { + self.decline(rule); + false + } + } + + /// Applies the given operator to the given term. + pub(crate) fn run_optional_at( + &mut self, + rule: impl Into, + index: usize, + operator: impl Fn(&mut Term), + ) -> bool { + let rule = rule.into(); + if self.is_allowed(rule) { + self.run_at(rule, index, operator) } else { self.decline(rule); false diff --git a/vidyut-prakriya/src/pratipadika_karya.rs b/vidyut-prakriya/src/pratipadika_karya.rs index 3dd82d1..7b546f3 100644 --- a/vidyut-prakriya/src/pratipadika_karya.rs +++ b/vidyut-prakriya/src/pratipadika_karya.rs @@ -25,7 +25,7 @@ pub fn run(p: &mut Prakriya, pratipadika: &Pratipadika, linga: Linga) -> Option< p.push(term); // Add samjnas - p.op_term("1.2.45", 0, |t| { + p.run_at("1.2.45", 0, |t| { t.add_tag(T::Pratipadika); }); p.add_tag(linga.as_tag()); @@ -34,7 +34,7 @@ pub fn run(p: &mut Prakriya, pratipadika: &Pratipadika, linga: Linga) -> Option< let prati = p.get(0)?; let sub = al::to_hrasva(prati.antya()?)?; if !prati.has_antya(sub) { - p.op_term("1.2.47", 0, op::antya(&sub.to_string())); + p.run_at("1.2.47", 0, op::antya(&sub.to_string())); } } diff --git a/vidyut-prakriya/src/samjna.rs b/vidyut-prakriya/src/samjna.rs index 9790d6a..3bce7fa 100644 --- a/vidyut-prakriya/src/samjna.rs +++ b/vidyut-prakriya/src/samjna.rs @@ -21,9 +21,9 @@ fn try_run_for_pratipadika(p: &mut Prakriya) -> Option<()> { let prati = p.get(i)?; let adi_ac = prati.text.find(al::is_ac)?; if al::is_vrddhi(prati.get_at(adi_ac)?) { - p.op_term("1.1.73", i, op::add_tag(T::Vrddha)); + p.run_at("1.1.73", i, op::add_tag(T::Vrddha)); } else if prati.has_u_in(TYAD_ADI) { - p.op_term("1.1.74", i, op::add_tag(T::Vrddha)); + p.run_at("1.1.74", i, op::add_tag(T::Vrddha)); } let prati = p.get(i)?; @@ -33,20 +33,20 @@ fn try_run_for_pratipadika(p: &mut Prakriya) -> Option<()> { let i_u = prati.has_antya('i') || prati.has_antya('u'); if prati.has_text_in(&["bahu", "gaRa"]) || prati.has_text_in(LAUKIKA_SANKHYA) { // TODO: vatu, qati - p.op_term("1.1.23", i, op::add_tag(T::Sankhya)); + p.run_at("1.1.23", i, op::add_tag(T::Sankhya)); let prati = p.get(i)?; if prati.has_antya('z') || prati.has_antya('n') { - p.op_term("1.1.24", i, op::add_tag(T::Sat)); + p.run_at("1.1.24", i, op::add_tag(T::Sat)); } } else if prati.has_text_in(PRATHAMA_ADI) && jasi { - p.op_optional("1.1.33", op::t(i, op::add_tag(T::Sarvanama))); + p.run_optional_at("1.1.33", i, op::add_tag(T::Sarvanama)); } else if prati.has_text_in(SARVA_ADI) || prati.has_text_in(USES_DATARA_DATAMA) { let mut sarvanama = true; if prati.has_text_in(PURVA_ADI) && jasi { - sarvanama = !p.op_optional("1.1.34", |_| {}); + sarvanama = !p.run_optional("1.1.34", |_| {}); } if sarvanama { - p.op_term("1.1.27", i, op::add_tag(T::Sarvanama)); + p.run_at("1.1.27", i, op::add_tag(T::Sarvanama)); } } else if i_u || ii_uu { let sup = p.get(i + 1)?; @@ -64,7 +64,7 @@ fn try_run_for_pratipadika(p: &mut Prakriya) -> Option<()> { let mut decided = false; if stri_linga && (iyan_uvan_astri || i_u) && sup.has_tag(T::Nit) { - decided = p.op_optional("1.4.6", op::t(i, op::add_tag(T::Nadi))); + decided = p.run_optional_at("1.4.6", i, op::add_tag(T::Nadi)); } let prati = p.get(i)?; @@ -72,19 +72,19 @@ fn try_run_for_pratipadika(p: &mut Prakriya) -> Option<()> { if i_u && !decided && !prati.has_text("saKi") { // TODO: patiH samAsa eva if !prati.has_text("pati") { - p.op_term("1.4.7", i, op::add_tag(T::Ghi)); + p.run_at("1.4.7", i, op::add_tag(T::Ghi)); } } else if ii_uu { if iyan_uvan_astri { if sup.has_u("Am") { - p.op_optional("1.4.5", op::t(i, op::add_tag(T::Nadi))); + p.run_optional_at("1.4.5", i, op::add_tag(T::Nadi)); } else { // "he SrIH", "he BrUH", but "he stri" p.step("1.4.4"); } } else { // Base case - p.op_term("1.4.3", i, op::add_tag(T::Nadi)); + p.run_at("1.4.3", i, op::add_tag(T::Nadi)); } } } @@ -117,16 +117,16 @@ pub fn try_run_for_pada_or_bha(p: &mut Prakriya) -> Option<()> { let is_svadi = next.has_tag_in(&[T::Sup, T::Taddhita]); if next.has_tag(T::sit) { - p.op_term("1.4.16", i, op::add_tag(T::Pada)); + p.run_at("1.4.16", i, op::add_tag(T::Pada)); } else if is_svadi && !next.has_tag(T::Sarvanamasthana) { if next.has_adi('y') || next.has_adi(&*AC) { - p.op_term("1.4.18", i, op::add_tag(T::Bha)); + p.run_at("1.4.18", i, op::add_tag(T::Bha)); } else if (term.has_antya('t') || term.has_antya('s')) && is_matvartha(next.first()?) { - p.op_term("1.4.19", i, op::add_tag(T::Bha)); + p.run_at("1.4.19", i, op::add_tag(T::Bha)); } else { - p.op_term("1.4.17", i, op::add_tag(T::Pada)); + p.run_at("1.4.17", i, op::add_tag(T::Pada)); } } } @@ -139,16 +139,16 @@ fn try_run_for_sup(p: &mut Prakriya) -> Option<()> { let i = p.find_last(T::Sup)?; if p.has_tag(T::Sambodhana) { - p.op_term("2.3.48", i, op::add_tag(T::Amantrita)); + p.run_at("2.3.48", i, op::add_tag(T::Amantrita)); if p.has_tag(T::Ekavacana) { - p.op_term("2.3.49", i, op::add_tag(T::Sambuddhi)); + p.run_at("2.3.49", i, op::add_tag(T::Sambuddhi)); } } let sup = p.get(i)?; // For 1.1.42, see the `sup_adesha` module. if sup.has_u_in(&["su~", "O", "jas", "am", "Ow"]) && !p.has_tag(T::Napumsaka) { - p.op_term("1.1.43", i, op::add_tag(T::Sarvanamasthana)); + p.run_at("1.1.43", i, op::add_tag(T::Sarvanamasthana)); } Some(()) @@ -158,7 +158,7 @@ fn try_run_for_taddhita(p: &mut Prakriya) -> Option<()> { let i = p.find_last(T::Taddhita)?; if p.has(i, |t| t.has_u_in(&["tarap", "tamap"])) { - p.op_term("1.1.22", i, |t| t.add_tag(T::Gha)); + p.run_at("1.1.22", i, |t| t.add_tag(T::Gha)); } Some(()) @@ -173,12 +173,12 @@ fn try_run_for_dhatu_pratyaya(p: &mut Prakriya, i: usize) -> Option<()> { if pratyaya.is_pratyaya() { if pratyaya.has_lakshana("li~w") { - p.op("3.4.115", add_ardha); + p.run("3.4.115", add_ardha); } else if pratyaya.has_lakshana("li~N") && p.has_tag(T::Ashih) { - p.op("3.4.116", add_ardha); + p.run("3.4.116", add_ardha); } else if pratyaya.has_tag_in(&[T::Tin, T::Sit]) { if !pratyaya.has_tag(T::Sarvadhatuka) { - p.op("3.4.113", add_sarva); + p.run("3.4.113", add_sarva); } } else { // Suffixes introduced before "dhAtoH" are not called ArdhadhAtuka. @@ -187,7 +187,7 @@ fn try_run_for_dhatu_pratyaya(p: &mut Prakriya, i: usize) -> Option<()> { // do nothing } else if !pratyaya.is_empty() && !pratyaya.has_tag(T::Ardhadhatuka) { // Check `is_empty` to avoid including luk, etc. - p.op("3.4.114", add_ardha); + p.run("3.4.114", add_ardha); } } } diff --git a/vidyut-prakriya/src/samprasarana.rs b/vidyut-prakriya/src/samprasarana.rs index 8405682..2f11803 100644 --- a/vidyut-prakriya/src/samprasarana.rs +++ b/vidyut-prakriya/src/samprasarana.rs @@ -1,10 +1,9 @@ -use crate::dhatu_gana as gana; -use crate::operators as op; /// Applies samprasarana changes as needed. /// /// Order of operations: /// - Must follow atidesha so that suffixes have the kit/Nit annotations necessary to cause /// samprasanara. +use crate::dhatu_gana as gana; use crate::prakriya::{Code, Prakriya}; use crate::tag::Tag as T; use crate::term::Term; @@ -86,7 +85,7 @@ fn find_samprasarana_match(p: &Prakriya, i: usize) -> Option<&'static str> { /// TODO: properly annotate 6.1.108 and related rules here. fn do_samprasarana(rule: Code, p: &mut Prakriya, i_dhatu: usize) -> Option<()> { let after = find_samprasarana_match(p, i_dhatu)?; - p.op_term(rule, i_dhatu, |t| { + p.run_at(rule, i_dhatu, |t| { t.set_text(after); t.add_tag(T::FlagSamprasarana); }); @@ -96,7 +95,7 @@ fn do_samprasarana(rule: Code, p: &mut Prakriya, i_dhatu: usize) -> Option<()> { fn do_samprasarana_for_abhyasa(rule: Code, p: &mut Prakriya, i_abhyasa: usize) -> Option<()> { let i_dhatu = i_abhyasa + 1; let after = find_samprasarana_match(p, i_dhatu)?; - p.op_term(rule, i_abhyasa, |t| { + p.run_at(rule, i_abhyasa, |t| { t.set_text(after); t.add_tag(T::FlagSamprasarana); }); @@ -120,20 +119,17 @@ pub fn run_for_dhatu(p: &mut Prakriya) -> Option<()> { let n_will_be_abhyasta = n_is_lit || n.has_u_in(&["san", "yaN", "Slu", "caN"]); let set_text = |rule, p: &mut Prakriya, text| { - p.op_term(rule, i, |t| { + p.run_at(rule, i, |t| { t.set_text(text); t.add_tag(T::FlagSamprasarana); }); }; let optional_set_text = |rule, p: &mut Prakriya, text| { - p.op_optional( - rule, - op::t(i, |t| { - t.set_text(text); - t.add_tag(T::FlagSamprasarana); - }), - ); + p.run_optional_at(rule, i, |t| { + t.set_text(text); + t.add_tag(T::FlagSamprasarana); + }); }; let is_ve = dhatu.has_u("ve\\Y"); diff --git a/vidyut-prakriya/src/sanadi.rs b/vidyut-prakriya/src/sanadi.rs index 86619c3..7e702bd 100644 --- a/vidyut-prakriya/src/sanadi.rs +++ b/vidyut-prakriya/src/sanadi.rs @@ -22,20 +22,20 @@ const AYADAYA: &[&str] = &[ /// Adds `upadesha` as a pratyaya after the dhatu at index `i_dhatu`. fn add_sanadi(rule: Code, p: &mut Prakriya, i_dhatu: usize, upadesha: &str) { - p.op(rule, |p| { + p.run(rule, |p| { let mut pratyaya = Term::make_upadesha(upadesha); pratyaya.add_tags(&[T::Pratyaya]); p.insert_after(i_dhatu, pratyaya); }); let i_pratyaya = i_dhatu + 1; - p.op_term("3.1.32", i_pratyaya, op::add_tag(T::Dhatu)); + p.run_at("3.1.32", i_pratyaya, op::add_tag(T::Dhatu)); it_samjna::run(p, i_pratyaya).expect("ok") } /// Optionally adds `upadesha` as a pratyaya after the dhatu at index `i_dhatu`. fn optional_add_sanadi(rule: Code, p: &mut Prakriya, i_dhatu: usize, upadesha: &str) { - let added = p.op_optional(rule, |p| { + let added = p.run_optional(rule, |p| { let mut pratyaya = Term::make_upadesha(upadesha); pratyaya.add_tags(&[T::Pratyaya]); p.insert_after(i_dhatu, pratyaya); @@ -43,7 +43,7 @@ fn optional_add_sanadi(rule: Code, p: &mut Prakriya, i_dhatu: usize, upadesha: & if added { let i_pratyaya = i_dhatu + 1; - p.op_term("3.1.32", i_pratyaya, op::add_tag(T::Dhatu)); + p.run_at("3.1.32", i_pratyaya, op::add_tag(T::Dhatu)); it_samjna::run(p, i_pratyaya).expect("ok") } } @@ -55,11 +55,11 @@ fn run_rules_for_yan_luk(p: &mut Prakriya) -> Option<()> { let i_yan = p.find_last_where(|t| t.is_pratyaya() && t.has_u("yaN"))?; // Apply luk. - p.op_term("2.4.74", i_yan, op::luk); + p.run_at("2.4.74", i_yan, op::luk); // "carkarItam ca" declares that yan-luk dhatus are part of ad-Adi gaNa. // As a result, we will see lopa of Sap-vikarana per 2.4.72. - p.op_term(DP("02.0076"), i_yan, |d| d.set_gana(Gana::Adadi)); + p.run_at(DP("02.0076"), i_yan, |d| d.set_gana(Gana::Adadi)); Some(()) } diff --git a/vidyut-prakriya/src/taddhita/matvartha_prakarana.rs b/vidyut-prakriya/src/taddhita/matvartha_prakarana.rs index c5bb10f..4cd35f5 100644 --- a/vidyut-prakriya/src/taddhita/matvartha_prakarana.rs +++ b/vidyut-prakriya/src/taddhita/matvartha_prakarana.rs @@ -26,11 +26,11 @@ pub fn run(tp: &mut TaddhitaPrakriya) { tp.with_context(TadAsyaAstiAsmin, |tp| { let prati = tp.prati(); - if prati.has_text_in(&RASA_ADI) { + if prati.has_text_in(RASA_ADI) { tp.try_add("5.2.95", matup); } else if prati.has_antya('A') { tp.optional_try_add("5.2.96", lac); - } else if prati.has_text_in(&SIDHMA_ADI) { + } else if prati.has_text_in(SIDHMA_ADI) { tp.optional_try_add("5.2.97", lac); } else if prati.has_text_in(&["vatsa", "aMsa"]) { tp.optional_try_add("5.2.98", lac); diff --git a/vidyut-prakriya/src/taddhita/pragdishiya.rs b/vidyut-prakriya/src/taddhita/pragdishiya.rs index 719b5b0..70c8971 100644 --- a/vidyut-prakriya/src/taddhita/pragdishiya.rs +++ b/vidyut-prakriya/src/taddhita/pragdishiya.rs @@ -4,7 +4,6 @@ Implements the taddhita rules in the "prAg diSo viBaktiH" section of pada 5.3. (5.3.1 - 5.3.26) */ use crate::args::Taddhita; -use crate::operators as op; use crate::taddhita::utils::TaddhitaPrakriya; use crate::tag::Tag as T; @@ -86,14 +85,14 @@ pub fn run(tp: &mut TaddhitaPrakriya) { if prati.has_u("idam") { if t.has_adi('r') || t.has_adi('T') { let sub = if t.has_adi('r') { "eta" } else { "it" }; - tp.p.op_term("5.3.4", i_prati, |t| t.set_text(sub)); + tp.p.run_at("5.3.4", i_prati, |t| t.set_text(sub)); } else { - tp.p.op_term("5.3.3", i_prati, |t| t.set_text("i")); + tp.p.run_at("5.3.3", i_prati, |t| t.set_text("i")); } } else if prati.has_u("etad") { - tp.p.op_term("5.3.5", i_prati, |t| t.set_text("a")); + tp.p.run_at("5.3.5", i_prati, |t| t.set_text("a")); } else if prati.has_u("sarva") && t.has_adi('d') { - tp.p.op_optional("5.3.6", op::t(i_prati, |t| t.set_text("sa"))); + tp.p.run_optional_at("5.3.6", i_prati, |t| t.set_text("sa")); } } } diff --git a/vidyut-prakriya/src/taddhita/pragdivyatiya.rs b/vidyut-prakriya/src/taddhita/pragdivyatiya.rs index 953eff2..7e7e80e 100644 --- a/vidyut-prakriya/src/taddhita/pragdivyatiya.rs +++ b/vidyut-prakriya/src/taddhita/pragdivyatiya.rs @@ -174,7 +174,7 @@ fn try_shaishika_rules(tp: &mut TaddhitaPrakriya, rule: &'static str) { if prati.has_text_in(&["yuzmad", "asmad"]) && tp.p.has(i_prati + 1, |t| t.has_u_in(&["KaY", "aR"])) { - tp.p.op_term("4.3.2", i_prati, |t| { + tp.p.run_at("4.3.2", i_prati, |t| { if t.has_text("yuzmad") { t.set_text("yuzmAka"); } else { @@ -310,7 +310,7 @@ pub fn run(tp: &mut TaddhitaPrakriya) { let putra_anta = prati.ends_with("putra"); let added = tp.optional_try_add("4.1.157", PiY); if added && putra_anta { - tp.p.op_optional("4.1.159", op::t(i_prati, |t| t.text += "k")); + tp.p.run_optional_at("4.1.159", i_prati, |t| t.text += "k"); } } } @@ -328,7 +328,7 @@ pub fn run(tp: &mut TaddhitaPrakriya) { }) { it_samjna::run(tp.p, i_prati + 1).expect("ok"); } - } else if prati.has_text_in(&gana::KALYANI_ADI) { + } else if prati.has_text_in(gana::KALYANI_ADI) { tp.try_add_with("4.1.126", Qak, |p| p.set(i_prati, |t| t.set_antya("in"))); } else if prati.has_text("kulawA") { tp.optional_try_add_with("4.1.127", Qak, |p| p.set(i_prati, |t| t.set_antya("in"))); @@ -434,7 +434,7 @@ pub fn run(tp: &mut TaddhitaPrakriya) { let prati = tp.prati(); if tp.has_taddhita && prati.has_text("kamboja") { - tp.p.op_term("4.1.175", i_prati + 1, op::luk); + tp.p.run_at("4.1.175", i_prati + 1, op::luk); } }); @@ -520,7 +520,7 @@ pub fn run(tp: &mut TaddhitaPrakriya) { let prati = tp.prati(); if prati.has_text("ka") { - tp.p.op_term("4.2.25", i_prati, |t| t.set_antya("i")); + tp.p.run_at("4.2.25", i_prati, |t| t.set_antya("i")); } }); @@ -560,7 +560,9 @@ pub fn run(tp: &mut TaddhitaPrakriya) { tp.try_add("4.2.43.v1", tal); } else if prati.has_text_in(gana::KHANDIKA_ADI) { tp.try_add("4.2.45", aY); - } else if true || prati.has_text_in(&["hastin", "Denu"]) { + } else if true + /* || prati.has_text_in(&["hastin", "Denu"]) */ + { // TODO: a-citta and remove `true` tp.optional_try_add("4.2.45", Wak); } @@ -659,7 +661,7 @@ pub fn run(tp: &mut TaddhitaPrakriya) { "azAQa", "bahulA", ]) { - tp.p.op_term("4.3.34", i_prati + 1, op::luk); + tp.p.run_at("4.3.34", i_prati + 1, op::luk); } }); diff --git a/vidyut-prakriya/src/taddhita/pragvahatiya.rs b/vidyut-prakriya/src/taddhita/pragvahatiya.rs index d1e8096..9458331 100644 --- a/vidyut-prakriya/src/taddhita/pragvahatiya.rs +++ b/vidyut-prakriya/src/taddhita/pragvahatiya.rs @@ -283,7 +283,7 @@ pub fn run(tp: &mut TaddhitaPrakriya) { let prati = tp.prati(); if prati.has_text("lavaRa") { tp.optional_try_add("4.4.52", P::WaY); - } else if prati.has_text_in(&KISHARA_ADI) { + } else if prati.has_text_in(KISHARA_ADI) { tp.try_add("4.4.53", P::zWan); } else if prati.has_text("SalAlu") { let added = tp.optional_try_add("4.4.54", P::zWan); diff --git a/vidyut-prakriya/src/taddhita/prakkritiya.rs b/vidyut-prakriya/src/taddhita/prakkritiya.rs index 1757cc5..56e2850 100644 --- a/vidyut-prakriya/src/taddhita/prakkritiya.rs +++ b/vidyut-prakriya/src/taddhita/prakkritiya.rs @@ -14,7 +14,7 @@ fn try_base_cases(tp: &mut TaddhitaPrakriya, _rule: &'static str) { // TODO: use `_rule` as well -- this should be simultaneous application. let prati = tp.prati(); - if prati.has_antya('u') || prati.has_antya('U') || prati.has_text_in(&GO_ADI) { + if prati.has_antya('u') || prati.has_antya('U') || prati.has_text_in(GO_ADI) { tp.try_add("5.1.2", yat); } else { tp.try_add("5.1.1", Ca); diff --git a/vidyut-prakriya/src/taddhita/svarthika_prakarana.rs b/vidyut-prakriya/src/taddhita/svarthika_prakarana.rs index cea8baf..df0f710 100644 --- a/vidyut-prakriya/src/taddhita/svarthika_prakarana.rs +++ b/vidyut-prakriya/src/taddhita/svarthika_prakarana.rs @@ -140,7 +140,7 @@ pub fn run(tp: &mut TaddhitaPrakriya) { tp.try_add("5.4.27", tal); } else if prati.has_text("avi") { tp.try_add("5.4.28", ka); - } else if prati.has_text_in(&YAVA_ADI) { + } else if prati.has_text_in(YAVA_ADI) { tp.try_add("5.4.29", kan); } else if prati.has_text("lohita") { tp.try_add("5.4.30", kan); @@ -148,7 +148,7 @@ pub fn run(tp: &mut TaddhitaPrakriya) { tp.try_add("5.4.32", kan); } else if prati.has_text("kAla") { tp.try_add("5.4.33", kan); - } else if prati.has_text_in(&VINAYA_ADI) { + } else if prati.has_text_in(VINAYA_ADI) { tp.try_add_with("5.4.34", Wak, |p| { p.set(i_prati, |t| { if t.has_text("upAya") { diff --git a/vidyut-prakriya/src/taddhita/utils.rs b/vidyut-prakriya/src/taddhita/utils.rs index 6a34b1e..7991eb0 100644 --- a/vidyut-prakriya/src/taddhita/utils.rs +++ b/vidyut-prakriya/src/taddhita/utils.rs @@ -110,7 +110,7 @@ impl<'a> TaddhitaPrakriya<'a> { self.had_match = true; if taddhita == self.taddhita && !self.has_taddhita { - self.p.op(rule, |p| { + self.p.run(rule, |p| { p.push(taddhita.to_term()); func(p); }); diff --git a/vidyut-prakriya/src/term.rs b/vidyut-prakriya/src/term.rs index 24a5efb..c7a23f5 100644 --- a/vidyut-prakriya/src/term.rs +++ b/vidyut-prakriya/src/term.rs @@ -320,6 +320,15 @@ impl Term { self.has_tag(Tag::Pratyaya) } + pub fn is_nyap_pratyaya(&self) -> bool { + self.has_tag(Tag::Pratyaya) && self.has_u_in(&["wAp", "cAp", "dAp", "NIp", "NIz"]) + } + + /// Returns whether the term has the `Sarvanama` samjna. + pub fn is_sarvadhatuka(&self) -> bool { + self.has_tag(Tag::Sarvadhatuka) + } + /// Returns whether the term has the `Sarvanama` samjna. pub fn is_sarvanama(&self) -> bool { self.has_tag(Tag::Sarvanama) diff --git a/vidyut-prakriya/src/tin_pratyaya.rs b/vidyut-prakriya/src/tin_pratyaya.rs index 75a40d8..744b165 100644 --- a/vidyut-prakriya/src/tin_pratyaya.rs +++ b/vidyut-prakriya/src/tin_pratyaya.rs @@ -144,29 +144,26 @@ fn maybe_do_lot_only_siddhi(p: &mut Prakriya, i: usize) -> Option<()> { let tin = p.get_if(i, |t| t.has_lakshana("lo~w"))?; if tin.has_text("si") { - p.op( - "3.4.87", - op::t(i, |t| { - t.set_u("hi"); - t.set_text("hi"); - t.remove_tag(T::pit); - }), - ); + p.run_at("3.4.87", i, |t| { + t.set_u("hi"); + t.set_text("hi"); + t.remove_tag(T::pit); + }); if p.has_tag(T::Chandasi) { - p.op_optional("3.4.88", op::t(i, op::add_tag(T::Pit))); + p.run_optional_at("3.4.88", i, op::add_tag(T::Pit)); } } else if tin.ends_with("mi") { // BavAni op::adesha("3.4.89", p, i, "ni"); } else if tin.has_antya('i') { // Bavatu - p.op_term("3.4.86", i, op::antya("u")); + p.run_at("3.4.86", i, op::antya("u")); } else if tin.has_antya('e') { if tin.has_tag(T::Uttama) && tin.has_antya('e') { - p.op_term("3.4.93", i, op::antya("E")); + p.run_at("3.4.93", i, op::antya("E")); } else if tin.ends_with("se") || tin.ends_with("ve") { - p.op_term("3.4.91", i, |t| { + p.run_at("3.4.91", i, |t| { let n = t.text.len(); if t.ends_with("se") { t.text.replace_range(n - 2.., "sva"); @@ -175,14 +172,14 @@ fn maybe_do_lot_only_siddhi(p: &mut Prakriya, i: usize) -> Option<()> { } }); } else { - p.op_term("3.4.90", i, op::antya("Am")); + p.run_at("3.4.90", i, op::antya("Am")); } } let tin = p.get(i)?; if tin.has_tag(T::Uttama) { // BavAni - p.op("3.4.92", |p| { + p.run("3.4.92", |p| { let agama = Term::make_agama("Aw"); // Add pit to the pratyaya, not the Agama. p.set(i, |t| t.add_tag(T::pit)); @@ -206,10 +203,10 @@ fn maybe_do_lin_siddhi(p: &mut Prakriya, i_tin: usize, la: Lakara) -> Result<()> if la == Lakara::AshirLin { // Add kit to the pratyaya, not the Agama. - p.op_term("3.4.104", i, op::add_tag(T::kit)); + p.run_at("3.4.104", i, op::add_tag(T::kit)); } else { // Add Nit to the pratyaya, not the Agama. - p.op_term("3.4.103", i, op::add_tag(T::Nit)); + p.run_at("3.4.103", i, op::add_tag(T::Nit)); } it_samjna::run(p, i - 1)?; } else { @@ -238,12 +235,12 @@ fn maybe_do_lin_siddhi(p: &mut Prakriya, i_tin: usize, la: Lakara) -> Result<()> } fn yatha(rule: Code, p: &mut Prakriya, i: usize, old: &[&str], new: &[&str]) { - p.op(rule, |p| op::upadesha_yatha(p, i, old, new)); + p.run(rule, |p| op::upadesha_yatha(p, i, old, new)); it_samjna::run(p, i).ok(); } fn yatha_optional(rule: Code, p: &mut Prakriya, i: usize, old: &[&str], new: &[&str]) { - if p.op_optional(rule, |p| op::upadesha_yatha(p, i, old, new)) { + if p.run_optional(rule, |p| op::upadesha_yatha(p, i, old, new)) { it_samjna::run(p, i).ok(); } } @@ -264,12 +261,12 @@ fn maybe_do_lot_and_nit_siddhi(p: &mut Prakriya, la: Lakara) { if p.has(i, |t| t.is_parasmaipada()) { if p.has(i, |t| t.has_tag(T::Uttama) && t.has_antya('s')) { - p.op_term("3.4.99", i, op::antya("")); + p.run_at("3.4.99", i, op::antya("")); } // lo~w excluded by existence of 3.4.86 if p.has(i, |t| t.has_antya('i')) && la != Lakara::Lot { - p.op_term("3.4.100", i, op::antya("")); + p.run_at("3.4.100", i, op::antya("")); } } } @@ -297,7 +294,7 @@ fn siddhi(p: &mut Prakriya, la: Lakara) -> Option<()> { } else if tin.has_text("TAs") { op::adesha("3.4.80", p, i, "se"); } else { - p.op_term("3.4.79", i, op::ti("e")); + p.run_at("3.4.79", i, op::ti("e")); } } else if tin.has_lakshana("li~w") && tin.is_parasmaipada() { yatha("3.4.82", p, i, TIN_PARA, NAL_PARA); @@ -305,7 +302,7 @@ fn siddhi(p: &mut Prakriya, la: Lakara) -> Option<()> { if dhatu.has_u("vida~") && tin.has_u_in(TIN_PARA) { yatha_optional("3.4.83", p, i, TIN_PARA, NAL_PARA); } else if dhatu.has_text("brU") && tin.has_u_in(&TIN_PARA[..5]) { - p.op_optional("3.4.84", |p| { + p.run_optional("3.4.84", |p| { p.set(i_dhatu, |t| t.set_text("Ah")); op::upadesha_yatha(p, i, TIN_PARA, NAL_PARA); it_samjna::run(p, i).ok(); diff --git a/vidyut-prakriya/src/tripadi/pada_8_2.rs b/vidyut-prakriya/src/tripadi/pada_8_2.rs index ba89018..9f9dd2d 100644 --- a/vidyut-prakriya/src/tripadi/pada_8_2.rs +++ b/vidyut-prakriya/src/tripadi/pada_8_2.rs @@ -1,5 +1,5 @@ use crate::args::Gana; -use crate::char_view::{char_rule, get_at, get_term_and_offset_indices, set_at, xyz}; +use crate::char_view::{get_at, get_term_and_offset_indices, xyz, CharPrakriya}; use crate::dhatu_gana; use crate::iterators::xy_rule; use crate::operators as op; @@ -46,9 +46,9 @@ fn try_na_lopa(p: &mut Prakriya) -> Option<()> { if prati.has_u("ahan") { // Special exception for ahan if p.has(i_prati + 1, |t| t.is_empty()) { - p.op_term("8.2.69", i_prati, |t| t.set_antya("r")); + p.run_at("8.2.69", i_prati, |t| t.set_antya("r")); } else { - p.op_term("8.2.68", i_prati, |t| t.set_antya("ru~")); + p.run_at("8.2.68", i_prati, |t| t.set_antya("ru~")); } return None; } @@ -58,7 +58,7 @@ fn try_na_lopa(p: &mut Prakriya) -> Option<()> { if p.has_tag(T::Napumsaka) { // "vA napuMsakAnAm" // (nAman, nAma) - blocked = p.op_optional("8.2.8.v1", |_| {}); + blocked = p.run_optional("8.2.8.v1", |_| {}); } else { // sambuddhi: yogin, Atman // ni: vyoman, Sarman, etc. (vedic) @@ -70,7 +70,7 @@ fn try_na_lopa(p: &mut Prakriya) -> Option<()> { if !blocked { // rAjA, rAjaByAm, ... // (these can be called `pada` by 1.4.17. - p.op_term("8.2.7", i_prati, op::antya("")); + p.run_at("8.2.7", i_prati, op::antya("")); } } @@ -95,9 +95,9 @@ fn try_matup_to_vatup(p: &mut Prakriya) -> Option<()> { let mat_upadha = x.has_antya(&*MA) || x.has_upadha(&*MA); let yavadi = x.has_u_in(YAVA_ADI); if mat_upadha && !yavadi { - p.op_term("8.2.9", i, |t| t.set_adi("v")); + p.run_at("8.2.9", i, |t| t.set_adi("v")); } else if x.has_antya(&*JHAY) { - p.op_term("8.2.10", i, |t| t.set_adi("v")); + p.run_at("8.2.10", i, |t| t.set_adi("v")); } } } @@ -121,7 +121,7 @@ fn try_change_r_to_l(p: &mut Prakriya) -> Option<()> { let y = p.get(j)?; if x.has_u_in(&["kfpU~\\", "kfpa~\\", "kfpa~"]) { - p.op("8.2.18", |p| { + p.run("8.2.18", |p| { if let Some(t) = p.get_mut(i) { do_ra_la(t); } @@ -132,14 +132,14 @@ fn try_change_r_to_l(p: &mut Prakriya) -> Option<()> { }); } else if y.has_u("aya~\\") { if x.has_upadha('r') || x.has_antya('r') { - p.op("8.2.19", op::t(i, do_ra_la)); + p.run_at("8.2.19", i, do_ra_la); } } else if x.has_u("gF") { if y.has_u("yaN") { - p.op("8.2.20", op::t(i, do_ra_la)); + p.run_at("8.2.20", i, do_ra_la); } else if x.has_gana(Gana::Tudadi) && y.has_adi(&*AC) { // TODO: why only gana 6? - p.op_optional("8.2.21", op::t(i, do_ra_la)); + p.run_optional_at("8.2.21", i, do_ra_la); } } } @@ -152,8 +152,8 @@ fn try_change_r_to_l(p: &mut Prakriya) -> Option<()> { /// (8.2.23 - 8.2.29) fn try_lopa_of_samyoganta_and_s(p: &mut Prakriya) -> Option<()> { // Exception to 8.2.23. - char_rule( - p, + let mut cp = CharPrakriya::new(p); + cp.for_chars( xyz(|x, y, z| JHAL.contains(x) && y == 's' && JHAL.contains(z)), |p, _, i| { let t = get_at(p, i + 1).expect("valid"); @@ -161,8 +161,7 @@ fn try_lopa_of_samyoganta_and_s(p: &mut Prakriya) -> Option<()> { // But, also part of bapsati? // TODO: clean up this rule if t.has_u("si~c") || t.has_u("Basa~") { - set_at(p, i + 1, ""); - p.step("8.2.26"); + p.run("8.2.26", |p| p.set_char_at(i + 1, "")); true } else { false @@ -180,22 +179,22 @@ fn try_lopa_of_samyoganta_and_s(p: &mut Prakriya) -> Option<()> { let y = p.get(j)?; if x.has_antya('r') && y.has_text("s") && j == p.terms().len() - 1 { // Urj -> Urk - p.op_term("8.2.24", j, op::adi("")); + p.run_at("8.2.24", j, op::adi("")); } else if x.has_antya('s') && y.has_adi('D') && !x.is_pada() { // Per kAzikA, applies only to s of si~c. But this seems to cause // problems e.g. for tAs + Dve. - p.op_term("8.2.25", i, op::antya("")); + p.run_at("8.2.25", i, op::antya("")); } } for i in 0..p.terms().len() { if let (Some(x), Some(y), Some(z)) = (p.get(i), p.get(i + 1), p.get(i + 2)) { if x.has_u("iw") && y.has_u("si~c") && z.has_u("Iw") { - p.op_term("8.2.28", i + 1, op::lopa); + p.run_at("8.2.28", i + 1, op::lopa); // sic-lopa is siddha with respect to prior rules (8.2.3 vArttika) // Therefore, apply ac-sandhi: - p.op("6.1.101", |p| { + p.run("6.1.101", |p| { p.set(i, op::antya("I")); p.set(i + 2, op::adi("")); }); @@ -203,8 +202,8 @@ fn try_lopa_of_samyoganta_and_s(p: &mut Prakriya) -> Option<()> { } } - char_rule( - p, + let mut cp = CharPrakriya::new(p); + cp.for_chars( |p, text, i| { let bytes = text.as_bytes(); if let Some(x) = bytes.get(i) { @@ -279,9 +278,9 @@ fn try_lopa_of_samyoganta_and_s(p: &mut Prakriya) -> Option<()> { if let (Some(b's'), Some(b's')) = (bytes.get(i), bytes.get(i + 1)) { // HACK for dhatus ending in 's' (acakAs + t -> acakAH) so that we preserve the // first 's' of the dhatu. - set_at(p, i + 1, ""); + p.set_char_at(i + 1, ""); } else { - set_at(p, i, ""); + p.set_char_at(i, ""); } p.step("8.2.29"); true @@ -293,7 +292,7 @@ fn try_lopa_of_samyoganta_and_s(p: &mut Prakriya) -> Option<()> { if let (Some(x), Some(y), Some(z)) = (p.get(i), p.get(i + 1), p.get(i + 2)) { // "ayamapi sica eva lopaḥ, tena iha na bhavati, dviṣṭarām, dviṣṭamām iti" (KV) if x.is_hrasva() && y.has_u("si~c") && z.has_adi(&*JHAL) && !x.is_agama() { - p.op_term("8.2.27", i + 1, op::lopa); + p.run_at("8.2.27", i + 1, op::lopa); } } } @@ -304,17 +303,16 @@ fn try_lopa_of_samyoganta_and_s(p: &mut Prakriya) -> Option<()> { while p.has(i, |t| { t.is_pada() && t.is_samyoganta() && t.has_antya(&*JHAL) }) { - p.op_term("8.2.23", i, |t| t.set_antya("")); + p.run_at("8.2.23", i, |t| t.set_antya("")); } } if !p.terms().last().expect("ok").is_dhatu() { - char_rule( - p, + let mut cp = CharPrakriya::new(p); + cp.for_chars_rev( |_, text, i| al::is_samyoganta(text) && i == text.len() - 1, |p, _, i| { - set_at(p, i, ""); - p.step("8.2.23"); + p.run("8.2.23", |p| p.set_char_at(i, "")); true }, ); @@ -350,18 +348,18 @@ fn try_ha_adesha(p: &mut Prakriya) -> Option<()> { if is_dhatu { let dhatu = p.get(i)?; if dhatu.has_u_in(DRUHA_ADI) { - p.op_optional("8.2.33", |p| p.set(i, op::antya("G"))); + p.run_optional("8.2.33", |p| p.set(i, op::antya("G"))); } else if dhatu.has_u("Ra\\ha~^") { - p.op_term("8.2.34", i, op::antya("D")); + p.run_at("8.2.34", i, op::antya("D")); } else if dhatu.has_text("Ah") { - p.op_term("8.2.35", i, op::antya("T")); + p.run_at("8.2.35", i, op::antya("T")); } else if dhatu.has_adi('d') && dhatu.has_antya('h') { - p.op_term("8.2.32", i, op::antya("G")); + p.run_at("8.2.32", i, op::antya("G")); } } // If no change was made, use the default. if p.has(i, |t| t.has_antya('h')) { - p.op_term("8.2.31", i, op::antya("Q")); + p.run_at("8.2.31", i, op::antya("Q")); } } } @@ -409,14 +407,14 @@ fn try_ch_to_s(p: &mut Prakriya) { if let Some(prefix) = x.text.strip_suffix("tC") { // TODO: seems implied, not sure. let n = prefix.len(); - p.op_term("8.2.36", i, |t| { + p.run_at("8.2.36", i, |t| { t.text.replace_range(n.., "z"); }); } else if !x.has_antya('k') { // HACK: check for explicit k to avoid errors with `yaj -> yiyakza -> yiyakzati`. The // more principled fix might be to disable the tripAdi for the dhAtu after the first // round, but that will require extensive updates elsewhere. - p.op_term("8.2.36", i, op::antya("z")); + p.run_at("8.2.36", i, op::antya("z")); } Some(()) @@ -438,7 +436,7 @@ fn per_term_1a(p: &mut Prakriya) -> Option<()> { if x.has_antya(&*CU) && (x.is_pada() || jhali_or_ante) { if let Some(c) = x.antya() { let sub = CU_TO_KU.get(c)?; - p.op_term("8.2.30", i, |t| { + p.run_at("8.2.30", i, |t| { // TODO: what is the rule that allows this change? if t.has_upadha('Y') { t.set_upadha("N"); @@ -465,7 +463,7 @@ fn per_term_1b(p: &mut Prakriya) -> Option<()> { if x.has_adi(&*BASH) && x.has_antya(&*JHAZ) && x.is_ekac() && x.is_dhatu() && if_y { let sub = BASH_TO_BHAZ.get(x.adi()?)?; - p.op_term("8.2.37", i, |t| { + p.run_at("8.2.37", i, |t| { t.set_adi(&sub.to_string()); }); } @@ -483,7 +481,7 @@ fn per_term_1b(p: &mut Prakriya) -> Option<()> { if c.has_antya(&*JHAL) && !has_exception && is_pada { let key = c.antya()?; let sub = JHAL_TO_JASH.get(key)?; - p.op_term("8.2.39", i, op::antya(&sub.to_string())); + p.run_at("8.2.39", i, op::antya(&sub.to_string())); } } @@ -500,7 +498,7 @@ fn run_misc_rules_1(p: &mut Prakriya) -> Option<()> { && (y.has_adi('t') || y.has_adi('T')) }, |p, _, j| { - p.op_term("8.2.40", j, op::adi("D")); + p.run_at("8.2.40", j, op::adi("D")); }, ); @@ -508,7 +506,7 @@ fn run_misc_rules_1(p: &mut Prakriya) -> Option<()> { p, |x, y| (x.has_antya('z') || x.has_antya('Q')) && y.has_adi('s'), |p, i, _| { - p.op_term("8.2.41", i, op::antya("k")); + p.run_at("8.2.41", i, op::antya("k")); }, ); @@ -537,16 +535,16 @@ fn run_rules_for_nistha_t(p: &mut Prakriya) -> Option<()> { if dhatu.has_u("YiPalA~") && !has_upasarga { // "ktavatvantasya apyetal latvam iṣyate, phullaḥ, phullavāniti" (KV) if k.has_u("kta") { - p.op(code, op::nipatana("Pulla")); + p.run(code, op::nipatana("Pulla")); } else { - p.op(code, op::nipatana("Pullavat")); + p.run(code, op::nipatana("Pullavat")); } } else if dhatu.has_text("kzIb") && !has_upasarga { - p.op(code, op::nipatana("kzIba")); + p.run(code, op::nipatana("kzIba")); } else if dhatu.has_text("kfS") && !has_upasarga { - p.op(code, op::nipatana("kfSa")); + p.run(code, op::nipatana("kfSa")); } else if dhatu.has_text("lAG") && i_d == 1 && p.has(0, |t| t.has_u("ud")) { - p.op(code, op::nipatana("ullAGa")); + p.run(code, op::nipatana("ullAGa")); } return Some(()); @@ -570,10 +568,10 @@ fn run_rules_for_nistha_t(p: &mut Prakriya) -> Option<()> { let code = "8.2.56"; if dhatu.has_u("hrI\\") { // By default, hrI takes -ta. So, this rule allows -na. - p.op_optional(code, op::t(i_k, op::adi("n"))); + p.run_optional_at(code, i_k, op::adi("n")); } else { // By default, these dhatus take -na. So, this rule allows -ta. - blocked = p.op_optional(code, |_| {}); + blocked = p.run_optional(code, |_| {}); } } else if dhatu.has_u("vi\\dx~^") { // TODO: think through the rules below. They all work correctly, but most users won't @@ -591,7 +589,7 @@ fn run_rules_for_nistha_t(p: &mut Prakriya) -> Option<()> { let dhatu = p.get(i_d)?; if dhatu.has_antya('r') || dhatu.has_antya('d') && ti { - p.op("8.2.42", |p| { + p.run("8.2.42", |p| { if p.has(i_d, |t| t.has_antya('d')) { p.set(i_d, op::antya("n")); } @@ -599,9 +597,9 @@ fn run_rules_for_nistha_t(p: &mut Prakriya) -> Option<()> { }); } - let set_adi = |rule, p: &mut Prakriya, s| p.op_term(rule, i_k, op::adi(s)); + let set_adi = |rule, p: &mut Prakriya, s| p.run_at(rule, i_k, op::adi(s)); let to_n = |rule, p: &mut Prakriya| set_adi(rule, p, "n"); - let optional_to_n = |rule, p: &mut Prakriya| p.op_optional(rule, op::t(i_k, op::adi("n"))); + let optional_to_n = |rule, p: &mut Prakriya| p.run_optional_at(rule, i_k, op::adi("n")); let dhatu = p.get(i_d)?; if dhatu.is_samyogadi() && dhatu.has_at(1, &*YAN) && dhatu.has_antya('A') { @@ -637,7 +635,7 @@ fn run_rules_for_nistha_t(p: &mut Prakriya) -> Option<()> { // kzAma set_adi("8.2.53", p, "m"); } else if dhatu.has_text("stI") && i_d > 0 && p.has(i_d - 1, |t| t.has_u("pra")) { - p.op_optional("8.2.54", op::t(i_k, |t| t.set_adi("m"))); + p.run_optional_at("8.2.54", i_k, |t| t.set_adi("m")); } Some(()) @@ -648,7 +646,7 @@ fn run_misc_rules_2(p: &mut Prakriya) -> Option<()> { p, |x, y| x.is_dhatu() && x.has_antya('m') && (y.has_adi('m') || y.has_adi('v')), |p, i, _| { - p.op_term("8.2.65", i, op::antya("n")); + p.run_at("8.2.65", i, op::antya("n")); }, ); @@ -661,7 +659,7 @@ fn try_add_final_r(p: &mut Prakriya) -> Option<()> { // TODO: sajuS for i in 0..p.terms().len() { if p.is_pada(i) && p.has(i, |t| t.has_antya('s')) { - p.op_term("8.2.66", i, op::antya("ru~")); + p.run_at("8.2.66", i, op::antya("ru~")); } } @@ -670,7 +668,7 @@ fn try_add_final_r(p: &mut Prakriya) -> Option<()> { p, |x, y| x.ends_with("aru~") && y.has_adi('a'), |p, i, j| { - p.op("6.1.113", |p| { + p.run("6.1.113", |p| { p.set(i, |t| t.find_and_replace_text("aru~", "o")); p.set(j, |t| t.set_adi("")); }); @@ -680,7 +678,7 @@ fn try_add_final_r(p: &mut Prakriya) -> Option<()> { p, |x, y| x.ends_with("aru~") && y.has_adi(&*HASH), |p, i, _| { - p.op_term("6.1.114", i, |t| { + p.run_at("6.1.114", i, |t| { t.find_and_replace_text("aru~", "o"); }); }, @@ -711,14 +709,14 @@ fn try_add_final_r_with_final_tin(p: &mut Prakriya) -> Option<()> { // FIXME: sloppy. Also, exclude "asti" for Vedic "AH". if dhatu.has_antya('s') && tin.has_u("tip") { - p.op_term("8.2.73", i_dhatu, op::antya("d")); + p.run_at("8.2.73", i_dhatu, op::antya("d")); } else if (dhatu.has_antya('s') || dhatu.has_antya('d')) && tin.has_u("sip") { if dhatu.has_antya('s') { // acakAs + s -> acakAH, acakAt, acakAd - p.op_optional("8.2.74", op::t(i_dhatu, op::antya("d"))); + p.run_optional_at("8.2.74", i_dhatu, op::antya("d")); } else { // aruRad + s -> aruRaH, aruRat, aruRad - p.op_optional("8.2.75", op::t(i_dhatu, op::antya("ru~"))); + p.run_optional_at("8.2.75", i_dhatu, op::antya("ru~")); } } @@ -752,7 +750,7 @@ fn try_lengthen_dhatu_vowel(p: &mut Prakriya) -> Option<()> { } else if is_ik(dhatu.upadha()) && is_rv(dhatu.antya()) { let sub = al::to_dirgha(dhatu.upadha()?)?; if p.has(i_n, |t| t.has_adi(&*HAL)) { - p.op_term("8.2.77", i, op::upadha(&sub.to_string())); + p.run_at("8.2.77", i, op::upadha(&sub.to_string())); } else { // TODO: only applies to padas. // p.op_term("8.2.76", i, op::upadha(&sub.to_string())); @@ -760,7 +758,7 @@ fn try_lengthen_dhatu_vowel(p: &mut Prakriya) -> Option<()> { } else if is_ik(before_upadha(dhatu)) && is_rv(dhatu.upadha()) && is_hal(dhatu.antya()) { let pre_upadha = before_upadha(dhatu)?; let sub = al::to_dirgha(pre_upadha)?.to_string(); - p.op("8.2.78", |p| { + p.run("8.2.78", |p| { let dhatu = &p.terms()[i]; let n = dhatu.text.len(); p.set(i, |t| { @@ -781,7 +779,7 @@ fn try_rules_for_adas(p: &mut Prakriya) -> Option<()> { // "s" might become "ru~" above, so check for "ru~" as well as final "s". if !adas.has_antya('~') && !adas.has_antya('s') { if (adas.has_antya('e') || sup.has_adi('e')) && sup.has_tag(T::Bahuvacana) { - p.op("8.2.81", |p| { + p.run("8.2.81", |p| { let t = p.get_mut(i).expect("ok"); t.find_and_replace_text("d", "m"); if t.has_antya('e') { @@ -791,7 +789,7 @@ fn try_rules_for_adas(p: &mut Prakriya) -> Option<()> { } }); } else if adas.text.contains('d') { - p.op("8.2.80", |p| { + p.run("8.2.80", |p| { let t = p.get_mut(i).expect("ok"); if t.has_antya('d') { t.set_antya("m"); diff --git a/vidyut-prakriya/src/tripadi/pada_8_3.rs b/vidyut-prakriya/src/tripadi/pada_8_3.rs index 48dbbe5..890e802 100644 --- a/vidyut-prakriya/src/tripadi/pada_8_3.rs +++ b/vidyut-prakriya/src/tripadi/pada_8_3.rs @@ -1,14 +1,14 @@ use crate::args::Gana; -use crate::char_view::{get_term_and_offset_indices, set_at, xy, CharPrakriya}; +use crate::char_view::{get_term_and_offset_indices, xy, CharPrakriya}; use crate::it_samjna; use crate::iterators::xy_rule; use crate::operators as op; +use crate::prakriya::Code; use crate::prakriya::Prakriya; use crate::sounds as al; use crate::sounds::{s, Set}; use crate::tag::Tag as T; use crate::term::Term; -use crate::Code; use lazy_static::lazy_static; lazy_static! { @@ -51,16 +51,16 @@ fn try_ra_lopa(p: &mut Prakriya) -> Option<()> { let has_ru = c.has_antya('r') && !c.has_upadha(&*HAL); if has_ru { if p.has(i + 1, |t| t.has_adi('r')) { - p.op_term("8.3.14", i, op::antya("")); + p.run_at("8.3.14", i, op::antya("")); let c = p.get(i)?; if c.is_hrasva() { let sub = al::to_dirgha(p.get(i)?.antya()?)?; // Placed here, otherwise this is vyartha. See `8.3.13` for the Qa case of // this rule. - p.op_term("6.3.111", i, op::antya(&sub.to_string())); + p.run_at("6.3.111", i, op::antya(&sub.to_string())); } } else if p.is_pada(i) && (is_avasane || is_khari) { - p.op_term("8.3.15", i, |t| { + p.run_at("8.3.15", i, |t| { t.set_antya(""); t.text += "H"; }); @@ -77,13 +77,13 @@ fn try_ra_lopa(p: &mut Prakriya) -> Option<()> { && y.has_adi(&*ASH) }, |p, i, j| { - p.op_term("8.3.17", i, |t| t.set_antya("y")); + p.run_at("8.3.17", i, |t| t.set_antya("y")); if p.has(j, |t| t.has_adi(&*AC)) { // Though technically optional, avoid including other rules to prevent creating // noisy output. - p.op_term("8.3.19", i, |t| t.set_antya("")); + p.run_at("8.3.19", i, |t| t.set_antya("")); } else { - p.op_term("8.3.22", i, |t| t.set_antya("")); + p.run_at("8.3.22", i, |t| t.set_antya("")); } }, ); @@ -106,7 +106,7 @@ fn try_mn_to_anusvara(p: &mut Prakriya) -> Option<()> { if p.has(i, |t| t.has_antya('m')) && p.is_pada(i) { if let Some(i_next) = p.find_next_where(i, |t| !t.is_empty()) { if p.has(i_next, |t| t.has_adi(&*HAL)) && !is_dhatu_prakriya { - p.op_term("8.3.23", i, |t| t.set_antya("M")); + p.run_at("8.3.23", i, |t| t.set_antya("M")); } } } @@ -114,7 +114,7 @@ fn try_mn_to_anusvara(p: &mut Prakriya) -> Option<()> { // TODO: a-padAnta let mut cp = CharPrakriya::new(p); - cp.char_rule( + cp.for_chars( xy(|x, y| (x == 'm' || x == 'n') && JHAL.contains(y)), |p, _, i| { if let Some((i_term, i_offset)) = get_term_and_offset_indices(p, i) { @@ -122,8 +122,7 @@ fn try_mn_to_anusvara(p: &mut Prakriya) -> Option<()> { if t.is_pada() && i_offset + 1 == t.text.len() { false } else { - set_at(p, i, "M"); - p.step("8.3.24"); + p.run("8.3.24", |p| p.set_char_at(i, "M")); true } } else { @@ -140,7 +139,7 @@ fn try_add_dhut_agama(p: &mut Prakriya) { p, |x, y| x.has_tag(T::Pada) && x.has_antya('q') && y.has_adi('s'), |p, _, j| { - if p.op_optional("8.3.29", |p| op::insert_agama_before(p, j, "Du~w")) { + if p.run_optional("8.3.29", |p| op::insert_agama_before(p, j, "Du~w")) { it_samjna::run(p, j).ok(); } }, @@ -159,31 +158,31 @@ fn try_visarjaniyasya(p: &mut Prakriya) -> Option<()> { let y = p.get(i_y)?; if y.has_adi(&*SHAR) { - p.op_optional("8.3.36", op::t(i_x, |t| t.set_antya("s"))); + p.run_optional_at("8.3.36", i_x, |t| t.set_antya("s")); } else if y.has_at(1, &*SHAR) { - p.op_term("8.3.35", i_x, |_| {}); + p.run_at("8.3.35", i_x, |_| {}); } else if y.has_adi(&*KU_PU) { if x.has_text_in(&["namas", "puras"]) && x.has_tag(T::Gati) { - p.op_term("8.3.40", i_x, |t| t.set_antya("s")); + p.run_at("8.3.40", i_x, |t| t.set_antya("s")); } else if is_it_ut_upadha(x) && !x.is_pratyaya() { - p.op_term("8.3.41", i_x, |t| t.set_antya("z")); + p.run_at("8.3.41", i_x, |t| t.set_antya("z")); } else if x.has_text("tiras") && x.has_tag(T::Gati) { - p.op_optional("8.3.42", op::t(i_x, |t| t.set_antya("s"))); + p.run_optional_at("8.3.42", i_x, |t| t.set_antya("s")); } else if x.text.ends_with("aH") && is_samasa(p, i_x) && !x.is_avyaya() && y.has_u("qukf\\Y") { - p.op_term("8.3.46", i_x, |t| t.set_antya("s")); + p.run_at("8.3.46", i_x, |t| t.set_antya("s")); } else if x.has_text("BAH") && y.has_text("kar") { // TODO: rest of kaskAdi - p.op_term("8.3.48", i_x, |t| t.set_antya("s")); + p.run_at("8.3.48", i_x, |t| t.set_antya("s")); } else { // TODO: jihvamuliya and upadhmaniya - p.op_term("8.3.37", i_x, |t| t.set_antya("H")); + p.run_at("8.3.37", i_x, |t| t.set_antya("H")); } } else { - p.op_term("8.3.34", i_x, |t| t.set_antya("s")); + p.run_at("8.3.34", i_x, |t| t.set_antya("s")); } } @@ -229,14 +228,14 @@ impl<'a> ShaPrakriya<'a> { fn try_shatva(&mut self, rule: Code) { if !self.done { - self.p.op_term(rule, self.i_term, |t| t.set_adi("z")); + self.p.run_at(rule, self.i_term, |t| t.set_adi("z")); } self.done = true; } fn try_run_with(&mut self, rule: Code, func: impl Fn(&mut Prakriya)) { if !self.done { - self.p.op(rule, func); + self.p.run(rule, func); } self.done = true; } @@ -245,7 +244,7 @@ impl<'a> ShaPrakriya<'a> { if !self.done { let done = self .p - .op_optional(rule, op::t(self.i_term, |t| t.set_adi("z"))); + .run_optional_at(rule, self.i_term, |t| t.set_adi("z")); self.done = done; done } else { @@ -445,7 +444,7 @@ fn run_shatva_rules_at_index(sp: &mut ShaPrakriya) -> Option<()> { let i_abhyasa = sp.i_term - 1; let is_stha_adi = !has_dhatu_in(dhatu, SU_TO_STUBH); if sp.p.has(i_abhyasa, |t| t.is_abhyasa() && t.has_adi('s')) && is_stha_adi { - sp.p.op_term("8.3.64", i_abhyasa, |t| t.set_adi("z")); + sp.p.run_at("8.3.64", i_abhyasa, |t| t.set_adi("z")); } } } @@ -542,7 +541,7 @@ fn run_shatva_rules(p: &mut Prakriya) -> Option<()> { // HACK for ezaH if p.get(0)?.has_text("esa") && p.get(0)?.has_tag(T::Sarvanama) { - p.op_term("8.3.59", 0, |t| t.set_text("eza")); + p.run_at("8.3.59", 0, |t| t.set_text("eza")); } // Other s -> z rules @@ -558,9 +557,9 @@ fn run_shatva_rules(p: &mut Prakriya) -> Option<()> { let x = p.get(i).expect("present"); let code = "8.3.60"; if x.has_text("s") { - p.op_term(code, i, op::text("z")); + p.run_at(code, i, op::text("z")); } else { - p.op_term(code, i, op::antya("z")); + p.run_at(code, i, op::antya("z")); } }, ); @@ -595,29 +594,26 @@ fn try_murdhanya_for_dha_in_tinanta(p: &mut Prakriya) -> Option<()> { if inah && shidhvam_lun_lit && dha { if p.has(i_anga + 1, |t| t.is_it_agama()) { - p.op_optional("8.3.79", op::t(i, op::adi("Q"))); + p.run_optional_at("8.3.79", i, op::adi("Q")); } else { - p.op_term("8.3.78", i, op::adi("Q")); + p.run_at("8.3.78", i, op::adi("Q")); } } Some(()) } -/// Runs rules that make a sound mUrdhanya when certain sounds precede. -/// -/// Example: `nesyati -> nezyati` -/// -/// (8.3.55 - 8.3.119) -fn try_murdhanya(p: &mut Prakriya) { - run_shatva_rules(p); - try_murdhanya_for_dha_in_tinanta(p); -} - pub fn run(p: &mut Prakriya) { try_ra_lopa(p); try_mn_to_anusvara(p); try_add_dhut_agama(p); try_visarjaniyasya(p); - try_murdhanya(p); + + // Runs rules that make a sound mUrdhanya when certain sounds precede. + // + // Example: `nesyati -> nezyati` + // + // (8.3.55 - 8.3.119) + run_shatva_rules(p); + try_murdhanya_for_dha_in_tinanta(p); } diff --git a/vidyut-prakriya/src/tripadi/pada_8_4.rs b/vidyut-prakriya/src/tripadi/pada_8_4.rs index 5cd70f9..d45ec38 100644 --- a/vidyut-prakriya/src/tripadi/pada_8_4.rs +++ b/vidyut-prakriya/src/tripadi/pada_8_4.rs @@ -1,8 +1,5 @@ use crate::args::Gana; -use crate::char_view::{ - char_rule, get_at, get_term_and_offset_indices, set_at, xy, xyz, CharPrakriya, -}; -use crate::iterators::xy_rule; +use crate::char_view::{get_at, get_term_and_offset_indices, xy, xyz, CharPrakriya}; use crate::operators as op; use crate::prakriya::Prakriya; use crate::sounds as al; @@ -63,35 +60,40 @@ fn find_natva_spans(text: &str) -> Vec<(usize, usize)> { /// /// `i_rs` is the index of the `r`/`z` sound that triggers the change, and `i_n` is the index of /// the `n` sound that we might change. -fn try_natva_for_span(cp: &mut CharPrakriya, i_rs: usize, i_n: usize) -> Option<()> { +fn try_natva_for_span(p: &mut Prakriya, text: &str, i_rs: usize, i_n: usize) -> Option<()> { + let i_x = p.find_for_char_at(i_rs)?; + let i_y = p.find_for_char_at(i_n)?; + + let len = text.len(); + debug_assert!(len > 0); + let i_last = len - 1; + // Exceptions to Ratva. - if let Some(i) = cp.p.find_first(T::Dhatu) { - let dhatu = cp.p.get(i)?; - let next = cp.p.get(i + 1)?; + if let Some(i) = p.find_first(T::Dhatu) { + let dhatu = p.get(i)?; + let next = p.get(i + 1)?; if (dhatu.has_u("kzuBa~") && next.has_u_in(&["SnA", "SAnac"])) || (dhatu.has_u("skanBu~") && next.has_u_in(&["SnA", "Snu"])) || (dhatu.has_u("tfpa~") && next.has_u("Snu")) || (dhatu.has_u("nftI~") && next.has_u("yaN")) { - cp.p.step("8.4.39"); + p.step("8.4.39"); return None; } } - let i_x = cp.term_index_at(i_rs)?; - let i_y = cp.term_index_at(i_n)?; - let x = cp.p.get(i_x)?; - let y = cp.p.get(i_y)?; + let x = p.get(i_x)?; + let y = p.get(i_y)?; if i_x != i_y && x.is_pada() && x.has_antya('z') { // nizpAna, ... - cp.p.step("8.4.35"); + p.step("8.4.35"); } else if y.has_u("Ra\\Sa~") && (y.has_antya('z') || y.has_antya('k')) { // pranazwa, ... - cp.p.step("8.4.36"); - } else if i_n == cp.text.len() - 1 { + p.step("8.4.36"); + } else if i_n == i_last { // akurvan, caran, ... - cp.p.step("8.4.37"); + p.step("8.4.37"); } else if x.is_upasarga() || x.has_u("antar") { // Allow "antar" per 1.4.65.v1. // Check !is_pratyaya to allow nirvAna -> nirvARa @@ -120,79 +122,72 @@ fn try_natva_for_span(cp: &mut CharPrakriya, i_rs: usize, i_n: usize) -> Option< items.iter().any(|(u, g)| d.has_gana(*g) && d.has_u(u)) }; - let i_dhatu = - cp.p.find_next_where(i_x, |t| t.is_dhatu() && !t.is_empty())?; - let dhatu = cp.p.get(i_dhatu)?; + let i_dhatu = p.find_next_where(i_x, |t| t.is_dhatu() && !t.is_empty())?; + let dhatu = p.get(i_dhatu)?; let is_hinu = || (dhatu.has_text("hi") && y.has_u("Snu")); let is_mina = || (dhatu.has_text("mI") && y.has_u("SnA")); if y.has_adi('n') && y.has_tag(T::FlagAdeshadi) { - cp.set_at(i_n, "R"); - cp.p.step("8.4.14"); + p.run("8.4.14", |p| p.set_char_at(i_n, "R")); } else if is_hinu() || is_mina() { // prahiRoti - cp.set_at(i_n, "R"); - cp.p.step("8.4.15"); + p.run("8.4.15", |p| p.set_char_at(i_n, "R")); } else if y.has_lakshana("lo~w") && y.has_u("ni") { if x.has_u("dur") { // TODO: extend - cp.p.step("1.4.60.v3"); + p.step("1.4.60.v3"); } else if x.has_u("antar") { // TODO: extend - cp.p.step("1.4.65.v1"); + p.step("1.4.65.v1"); } else { // pravapARi - cp.set_at(i_n, "R"); - cp.p.step("8.4.16"); + p.run("8.4.16", |p| p.set_char_at(i_n, "R")); } } else if y.is_upasarga() && y.has_u("ni") { if dhatu_in(dhatu, GAD_ADI) || dhatu.has_tag(T::Ghu) { - cp.set_at(i_n, "R"); - cp.p.step("8.4.17"); + p.run("8.4.17", |p| p.set_char_at(i_n, "R")); } else if !(dhatu.has_adi('k') || dhatu.has_adi('K') || dhatu.has_tag(T::FlagShanta)) { - cp.p.op_optional("8.4.18", |p| p.set(i_y, |t| t.set_adi("R"))); + p.run_optional("8.4.18", |p| p.set(i_y, |t| t.set_adi("R"))); } else { // pranikaroti, pranikhAdati } } else if dhatu.has_u("ana~") { - cp.set_at(i_n, "R"); - cp.p.step("8.4.19"); + p.run("8.4.19", |p| p.set_char_at(i_n, "R")); - let dhatu = cp.p.get(i_dhatu)?; + let dhatu = p.get(i_dhatu)?; if dhatu.has_tag(T::Abhyasta) { - cp.p.op_term("8.4.21", i_dhatu, |t| t.set_adi("R")); + p.run_at("8.4.21", i_dhatu, |t| t.set_adi("R")); } } else if dhatu.has_u("ha\\na~") && dhatu.has_upadha('a') { - let i_z = cp.p.find_next_where(i_y, |t| !t.is_empty())?; - if cp.p.has(i_z, |t| t.has_adi('v') || t.has_adi('m')) { - cp.p.op_optional("8.4.23", |p| p.set(i_y, |t| t.set_antya("R"))); + let i_z = p.find_next_where(i_y, |t| !t.is_empty())?; + if p.has(i_z, |t| t.has_adi('v') || t.has_adi('m')) { + p.run_optional("8.4.23", |p| p.set(i_y, |t| t.set_antya("R"))); } else { - cp.p.op_term("8.4.22", i_dhatu, |t| t.set_antya("R")); + p.run_at("8.4.22", i_dhatu, |t| t.set_antya("R")); } } else if y.is_krt() { - let (_, i_y_offset) = get_term_and_offset_indices(cp.p, i_n)?; + let (_, i_y_offset) = get_term_and_offset_indices(p, i_n)?; let acah = if i_y_offset == 0 { - i_y > 0 && cp.p.has(i_y - 1, |t| t.has_antya(&*AC)) + i_y > 0 && p.has(i_y - 1, |t| t.has_antya(&*AC)) } else { let prev = y.text.as_bytes()[i_y_offset - 1] as char; AC.contains(prev) }; if acah { - cp.p.op_term("8.4.22", i_y, |t| t.find_and_replace_text("n", "R")); + p.run_at("8.4.22", i_y, |t| t.find_and_replace_text("n", "R")); } } } else { // 8.4.1 states *samAna-pade*, which means that the span must not cross a pada. - let is_samana_pada = !cp.p.terms()[i_x..i_y].iter().any(|t| { + let is_samana_pada = !p.terms()[i_x..i_y].iter().any(|t| { t.has_tag_in(&[T::Sup, T::Tin]) || (t.has_tag(T::Pada) && !t.is_pratipadika()) }); // Allow "carman -> carmaRA" but disallow "sruGna -> *sruGRa" - let is_exempt_pratipadika = cp.p.has(i_x, |t| t.text.starts_with("srOGn")); + let is_exempt_pratipadika = p.has(i_x, |t| t.text.starts_with("srOGn")); if is_samana_pada && !is_exempt_pratipadika { // TODO: track loctaion of rzfF for better rule logging. - set_at(cp.p, i_n, "R"); - cp.p.step("8.4.2"); + p.run("8.4.2", |p| p.set_char_at(i_n, "R")); } } @@ -207,9 +202,9 @@ fn try_natva_for_span(cp: &mut CharPrakriya, i_rs: usize, i_n: usize) -> Option< /// (8.4.1 - 8.4.39) fn run_natva_rules(p: &mut Prakriya) { - let mut cp = CharPrakriya::new(p); - for (i_rs, i_n) in find_natva_spans(&cp.text) { - try_natva_for_span(&mut cp, i_rs, i_n); + let text = p.text(); + for (i_rs, i_n) in find_natva_spans(&text) { + try_natva_for_span(p, &text, i_rs, i_n); } } @@ -241,15 +236,15 @@ fn stu_to_swu(c: char) -> Option<&'static str> { Some(res) } -fn try_change_stu_to_parasavarna(p: &mut Prakriya) { +fn try_change_stu_to_parasavarna(cp: &mut CharPrakriya) { lazy_static! { static ref SCU: Set = s("S cu~"); static ref SWU: Set = s("z wu~"); static ref STU: Set = s("s tu~"); static ref TU: Set = s("tu~"); }; - char_rule( - p, + + cp.for_chars( xy(|x, y| (STU.contains(x) && SCU.contains(y)) || (SCU.contains(x) && STU.contains(y))), |p, text, i| { let x = text.as_bytes()[i] as char; @@ -260,18 +255,17 @@ fn try_change_stu_to_parasavarna(p: &mut Prakriya) { } else { if STU.contains(x) { let sub = stu_to_scu(x).expect(""); - set_at(p, i, sub); + p.set_char_at(i, sub); } else { let sub = stu_to_scu(y).expect(""); - set_at(p, i + 1, sub); + p.set_char_at(i + 1, sub); } p.step("8.4.40"); true } }, ); - char_rule( - p, + cp.for_chars( xy(|x, y| (STU.contains(x) && SWU.contains(y)) || (SWU.contains(x) && STU.contains(y))), |p, text, i| { let x = text.as_bytes()[i] as char; @@ -286,10 +280,10 @@ fn try_change_stu_to_parasavarna(p: &mut Prakriya) { } else { if STU.contains(x) { let sub = stu_to_swu(x).expect(""); - set_at(p, i, sub); + p.set_char_at(i, sub); } else { let sub = stu_to_swu(y).expect(""); - set_at(p, i + 1, sub); + p.set_char_at(i + 1, sub); } p.step("8.4.41"); true @@ -301,36 +295,33 @@ fn try_change_stu_to_parasavarna(p: &mut Prakriya) { /// Runs rules for retroflex Dha. /// /// This rule is in section 8.3, but it has scope to apply only if it follows 8.4.41. -fn try_dha_lopa(p: &mut Prakriya) -> Option<()> { - for i in 0..p.terms().len() { - let x = p.get(i)?; - let y = p.get(p.find_next_where(i, |t| !t.text.is_empty())?)?; - if x.has_antya('Q') && y.has_adi('Q') { - p.op_term("8.3.13", i, op::antya("")); +fn try_dha_lopa(cp: &mut CharPrakriya) { + cp.for_terms( + |x, y| x.has_antya('Q') && y.has_adi('Q'), + |p, i, _| { + p.run_at("8.3.13", i, op::antya("")); // Placed here, otherwise this is vyartha - let x = p.get(i)?; + let x = p.get(i).expect("ok"); // matches aN (no f, x) if x.has_antya(&*AN) { if x.has_u_in(&["zaha~\\", "va\\ha~^"]) && x.has_antya(&*AA) { // soQA, voQA, ... - p.op_term("6.3.112", i, op::antya("o")); + p.run_at("6.3.112", i, op::antya("o")); } else { - let sub = al::to_dirgha(x.antya()?)?; - p.op_term("6.3.111", i, op::antya(&sub.to_string())); + let sub = al::to_dirgha(x.antya().expect("ok")).expect("ok"); + p.run_at("6.3.111", i, op::antya(&sub.to_string())); } } - } - } - - Some(()) + }, + ); } -fn try_to_anunasika(p: &mut Prakriya) -> Option<()> { - for i in 0..p.terms().len() { - let x = p.get(i)?; - let y = p.get(i + 1)?; - if x.is_pada() && x.has_antya(&*YAR) && y.has_adi(&*ANUNASIKA) { +fn try_to_anunasika(cp: &mut CharPrakriya) { + cp.for_terms( + |x, y| x.is_pada() && x.has_antya(&*YAR) && y.has_adi(&*ANUNASIKA), + |p, i, _| { + let x = p.get(i).expect("defined"); // For now, apply the rule to just these sounds. let sub = match x.antya().expect("ok") { 'k' | 'g' => Some("N"), @@ -343,23 +334,20 @@ fn try_to_anunasika(p: &mut Prakriya) -> Option<()> { }; if let Some(sub) = sub { // By convention, this rule is always applied in classical Sanskrit. - p.op_term("8.4.45", i, |t| t.set_antya(sub)); + p.run_at("8.4.45", i, |t| t.set_antya(sub)); } - } - } - Some(()) + }, + ); } -fn try_jhal_adesha(p: &mut Prakriya) -> Option<()> { - char_rule( - p, +fn try_jhal_adesha(cp: &mut CharPrakriya) -> Option<()> { + cp.for_chars_rev( xy(|x, y| JHAL.contains(x) && JHASH.contains(y)), |p, text, i| { let x = text.as_bytes()[i] as char; let sub = JHAL_TO_JASH.get(x).expect("should be present"); if x != sub { - set_at(p, i, &sub.to_string()); - p.step("8.4.53"); + p.run("8.4.53", |p| p.set_char_at(i, &sub.to_string())); true } else { false @@ -367,18 +355,21 @@ fn try_jhal_adesha(p: &mut Prakriya) -> Option<()> { }, ); - if let Some(i) = p.find_first(T::Abhyasa) { - let abhyasa = p.get(i)?; + cp.for_terms( // Check for jaz-car to avoid applying a rule that causes no changee. - if abhyasa.has_adi(&*JHAL) && !abhyasa.has_adi(&*JASH_CAR) { - let sub = JHAL_TO_JASH_CAR.get(abhyasa.adi()?)?.to_string(); - p.op_term("8.4.54", i, op::adi(&sub)); - } - } + |x, _| x.is_abhyasa() && x.has_adi(&*JHAL) && !x.has_adi(&*JASH_CAR), + |p, i, _| { + let abhyasa = p.get(i).expect("ok"); + let sub = JHAL_TO_JASH_CAR + .get(abhyasa.adi().expect("ok")) + .expect("ok") + .to_string(); + p.run_at("8.4.54", i, op::adi(&sub)); + }, + ); // 8.2.38, but indicated here by use of "dadhas" in the rule. - xy_rule( - p, + cp.for_terms( |x, y| { x.has_u("quDA\\Y") && x.has_text_in(&["D", "d"]) @@ -393,15 +384,13 @@ fn try_jhal_adesha(p: &mut Prakriya) -> Option<()> { p.step("8.2.38") }, ); - - char_rule( - p, + cp.for_chars_rev( xy(|x, y| JHAL.contains(x) && KHAR.contains(y)), |p, text, i| { let x = text.as_bytes()[i] as char; let sub = JHAL_TO_CAR.get(x).expect("present"); if x != sub { - set_at(p, i, &sub.to_string()); + p.set_char_at(i, &sub.to_string()); p.step("8.4.55"); true } else { @@ -409,9 +398,7 @@ fn try_jhal_adesha(p: &mut Prakriya) -> Option<()> { } }, ); - - char_rule( - p, + cp.for_chars( |p, text, i| { let x = text.as_bytes()[i] as char; JHAL.contains(x) && i == text.len() - 1 && p.terms().last().expect("present").is_pada() @@ -422,7 +409,7 @@ fn try_jhal_adesha(p: &mut Prakriya) -> Option<()> { let sub = JHAL_TO_CAR.get(x).expect("present"); if x != sub { if p.is_allowed(code) { - set_at(p, i, &sub.to_string()); + p.set_char_at(i, &sub.to_string()); p.step(code); true } else { @@ -439,9 +426,8 @@ fn try_jhal_adesha(p: &mut Prakriya) -> Option<()> { } /// Runs rules that convert sounds to their savarna version. -fn try_to_savarna(p: &mut Prakriya) { - char_rule(p, xy(|x, y| x == 'M' && YAY.contains(y)), |p, text, i| { - let x = text.as_bytes()[i] as char; +fn try_to_savarna(cp: &mut CharPrakriya) { + cp.for_chars(xy(|x, y| x == 'M' && YAY.contains(y)), |p, text, i| { let y = text.as_bytes()[i + 1] as char; let sub = match y { 'k' | 'K' | 'g' | 'G' | 'N' => "N", @@ -451,39 +437,32 @@ fn try_to_savarna(p: &mut Prakriya) { 'p' | 'P' | 'b' | 'B' | 'm' => "m", _ => "M", }; - set_at(p, i, sub); - p.step("8.4.58"); + p.run("8.4.58", |p| p.set_char_at(i, sub)); // "M' is possible per 7.4.86 -- see the comments on that rule. - // To prevent an infinite loop, return true only if the original sound wasn't already an - // ansuvara. - x != 'M' + // To prevent an infinite loop, return true only if the new sound is not an anusvara. + sub != "M" }); - char_rule( - p, - xyz(|x, y, _| TU.contains(x) && y == 'l'), - |p, text, i| { - p.op("8.4.60", |p| { - let x = text.as_bytes()[i] as char; - if x == 'n' { - set_at(p, i, "~l") - } else { - set_at(p, i, "l") - } - }); - true + cp.for_chars(xyz(|x, y, _| TU.contains(x) && y == 'l'), |p, text, i| { + p.run("8.4.60", |p| { + let x = text.as_bytes()[i] as char; + if x == 'n' { + p.set_char_at(i, "~l") + } else { + p.set_char_at(i, "l") + } + }); + true + }); + + cp.for_terms( + |x, y| x.is_upasarga() && x.has_u("ud") && y.has_u_in(&["zWA\\", "zwaBi~\\"]), + |p, _, j| { + p.run_at("8.4.61", j, |t| t.set_adi("t")); }, ); - for i in 1..p.terms().len() { - if p.has(i - 1, |t| t.is_upasarga() && t.has_u("ud")) - && p.has(i, |t| t.has_u_in(&["zWA\\", "zwaBi~\\"])) - { - p.op_term("8.4.61", i, |t| t.set_adi("t")); - } - } - - char_rule(p, xy(|x, y| JHAY.contains(x) && y == 'h'), |p, text, i| { + cp.for_chars(xy(|x, y| JHAY.contains(x) && y == 'h'), |p, text, i| { let sub = match text.as_bytes().get(i).map(|x| *x as char) { Some('k') => Some("G"), Some('g') => Some("G"), @@ -498,40 +477,39 @@ fn try_to_savarna(p: &mut Prakriya) { _ => None, }; if let Some(sub) = sub { - p.op_optional("8.4.62", |p| set_at(p, i + 1, sub)) + p.run_optional("8.4.62", |p| p.set_char_at(i + 1, sub)) } else { false } }); - char_rule( - p, + cp.for_chars( xyz(|x, y, z| JHAY.contains(x) && y == 'S' && AT.contains(z)), - |p, _, i| p.op_optional("8.4.63", |p| set_at(p, i + 1, "C")), + |p, _, i| p.run_optional("8.4.63", |p| p.set_char_at(i + 1, "C")), ); - char_rule( - p, + cp.for_chars( xyz(|x, y, z| HAL.contains(x) && YAM.contains(y) && YAM.contains(z) && y == z), - |p, _, i| p.op_optional("8.4.64", |p| set_at(p, i + 1, "")), + |p, _, i| p.run_optional("8.4.64", |p| p.set_char_at(i + 1, "")), ); - char_rule( - p, + cp.for_chars( xyz(|x, y, z| { HAL.contains(x) && JHAR.contains(y) && JHAR.contains(z) && al::is_savarna(y, z) }), - |p, _, i| p.op_optional("8.4.65", |p| set_at(p, i + 1, "")), + |p, _, i| p.run_optional("8.4.65", |p| p.set_char_at(i + 1, "")), ); } pub fn run(p: &mut Prakriya) { run_natva_rules(p); - try_change_stu_to_parasavarna(p); - try_dha_lopa(p); - try_to_anunasika(p); - try_jhal_adesha(p); - try_to_savarna(p); + + let mut cp = CharPrakriya::new(p); + try_change_stu_to_parasavarna(&mut cp); + try_dha_lopa(&mut cp); + try_to_anunasika(&mut cp); + try_jhal_adesha(&mut cp); + try_to_savarna(&mut cp); } #[cfg(test)] diff --git a/vidyut-prakriya/src/uttarapade.rs b/vidyut-prakriya/src/uttarapade.rs index 42116c2..635ef16 100644 --- a/vidyut-prakriya/src/uttarapade.rs +++ b/vidyut-prakriya/src/uttarapade.rs @@ -27,7 +27,7 @@ pub fn run(p: &mut Prakriya) -> Option<()> { && (last.has_tag(T::Gha) || last.has_u_in(&["rUpap", "kalpap"])) { // TODO; check for bhASitapuMsvat - p.op_term("6.3.43", 0, |t| { + p.run_at("6.3.43", 0, |t| { // Rule only applies for NI, so just change `I`. t.set_antya("i"); }); @@ -43,13 +43,13 @@ pub fn run(p: &mut Prakriya) -> Option<()> { && uttara.has_u("yat") && !p.has_artha(Artha::Taddhita(TaddhitaArtha::Tadarthye)) { - p.op_term("6.3.53", i_purva, |t| t.set_text("pad")); + p.run_at("6.3.53", i_purva, |t| t.set_text("pad")); } let purva = p.get(i_purva)?; let uttara = p.get(i_uttara)?; if purva.is_sarvanama() && uttara.has_text_in(&["dfS"]) { - p.op_term("6.3.91", i_purva, |t| t.set_antya("A")); + p.run_at("6.3.91", i_purva, |t| t.set_antya("A")); } else if !purva.is_avyaya() && p.find_last(T::Kit).is_some() { let ajanta = al::is_ac(purva.antya()?); let i_khit = p.find_last_where(|t| t.has_tag(T::Kit))?; @@ -57,14 +57,14 @@ pub fn run(p: &mut Prakriya) -> Option<()> { if purva.has_text_in(&["vAc", "pur"]) { // vAcaMyama, purandara - p.op("6.3.69", |p| { + p.run("6.3.69", |p| { let mut am = Term::make_upadesha("am"); am.add_tags(&[T::Pratyaya, T::Vibhakti, T::Sup, T::V2, T::Pada]); p.insert_after(i_purva, am); p.set(i_purva, |t| t.remove_tag(T::Pada)); }); } else if purva.num_vowels() == 1 && purva.has_antya(&*AC) && !purva.has_antya(&*AA) { - p.op("6.3.68", |p| { + p.run("6.3.68", |p| { let mut am = Term::make_upadesha("am"); am.add_tags(&[T::Pratyaya, T::Vibhakti, T::Sup, T::V2, T::Pada]); p.insert_after(i_purva, am); @@ -72,13 +72,13 @@ pub fn run(p: &mut Prakriya) -> Option<()> { } else if purva.has_u_in(&["arus", "dvizat"]) || ajanta { if al::is_dirgha(purva.antya()?) && !purva.is_avyaya() { let sub = al::to_hrasva(purva.antya()?)?; - p.op_term("6.3.66", i_purva, |t| { + p.run_at("6.3.66", i_purva, |t| { t.set_antya(&sub.to_string()); }); } // aruntuda, dvizantapa - p.op_term("6.3.67", i_purva, |t| { + p.run_at("6.3.67", i_purva, |t| { op::mit("m")(t); // HACK: add `pada` for m -> M (8.3.23). t.add_tag(T::Pada); @@ -99,22 +99,22 @@ pub fn run_after_guna(p: &mut Prakriya) -> Option<()> { // rule is "bahulam" if purva.has_u("ni") && uttara.has_u_in(&["vfN", "vfY"]) { // nIvAra - p.op_term("6.3.122", i_purva, |t| t.set_antya("I")); + p.run_at("6.3.122", i_purva, |t| t.set_antya("I")); } } else if purva.has_antya(&*IK) { if uttara.has_text("kAS") && p.has(i_uttara + 1, |t| t.has_u("ac")) { // nIkASa, vIkASa, anUkASa let sub = al::to_dirgha(purva.antya()?)?; - p.op_term("6.3.123", i_purva, |t| t.set_antya(&sub.to_string())); + p.run_at("6.3.123", i_purva, |t| t.set_antya(&sub.to_string())); } else if uttara.has_tag(T::Ghu) && uttara.has_text("t") { // nItta, vItta, parItta let sub = al::to_dirgha(purva.antya()?)?; - p.op_term("6.3.124", i_purva, |t| t.set_antya(&sub.to_string())); + p.run_at("6.3.124", i_purva, |t| t.set_antya(&sub.to_string())); } } } else if uttara.has_text("citi") && p.has(i_uttara + 1, |t| t.has_u("kap")) { // citIka - p.op_term("6.3.125", i_uttara, |t| t.set_antya("I")); + p.run_at("6.3.125", i_uttara, |t| t.set_antya("I")); } Some(()) diff --git a/vidyut-prakriya/src/vikarana.rs b/vidyut-prakriya/src/vikarana.rs index 02e9ced..35c7c79 100644 --- a/vidyut-prakriya/src/vikarana.rs +++ b/vidyut-prakriya/src/vikarana.rs @@ -80,7 +80,7 @@ fn maybe_replace_cli_with_ksa(p: &mut Prakriya, i: usize) -> Option<()> { let sprs = &["spfS", "mfS", "kfz", "tfp", "dfp"]; if xyz(p, i, |x, _, _| x.has_text_in(sprs)) { - if p.op_optional("3.1.44.v1", |p| op::upadesha_no_it(p, i + 1, "si~c")) { + if p.run_optional("3.1.44.v1", |p| op::upadesha_no_it(p, i + 1, "si~c")) { return None; } } @@ -103,7 +103,7 @@ fn maybe_replace_cli_with_ksa(p: &mut Prakriya, i: usize) -> Option<()> { let to_ksa = replace_with(i + 1, "ksa"); if dhatu.has_text("Sliz") && dhatu.has_gana(Divadi) { // aSlizat, aSlikzat - added = p.op_optional("3.1.46", to_ksa); + added = p.run_optional("3.1.46", to_ksa); } let to_ksa = replace_with(i + 1, "ksa"); @@ -113,20 +113,20 @@ fn maybe_replace_cli_with_ksa(p: &mut Prakriya, i: usize) -> Option<()> { }) { // Takes priority over "Sala igupaDAt ..." (3.1.45) - p.op("3.1.55", |p| op::upadesha_no_it(p, i + 1, "aN")); + p.run("3.1.55", |p| op::upadesha_no_it(p, i + 1, "aN")); } else if !added && p.has(i, shal_igupadha_anit) { let dhatu = p.get(i)?; if dhatu.has_text("dfS") { p.step("3.1.47") } else if dhatu.has_tag(T::Udit) { - p.op_optional("3.1.45", |p| { + p.run_optional("3.1.45", |p| { to_ksa(p); // Needed if we use "ksa" with a veT root. p.add_tag(T::FlagHasAnitKsa); }); p.add_tag(T::FlagHagSetSic); } else { - p.op("3.1.45", to_ksa); + p.run("3.1.45", to_ksa); } } @@ -146,13 +146,13 @@ fn maybe_replace_cli_with_can(p: &mut Prakriya, i: usize) -> Option<()> { if p.has_tag(T::Kartari) && dhatu.is_ni_pratyaya() || is_shri_dru_sru(dhatu) { // acIkarat; aSiSriyat, adudruvat, asusruvat - p.op("3.1.48", to_can); + p.run("3.1.48", to_can); } else if dhatu.has_u("kamu~\\") { // acIkamat - p.op("3.1.48.v1", to_can); + p.run("3.1.48.v1", to_can); } else if dhatu.has_text_in(&["De", "Svi"]) { // adaDAt, aSiSviyat - p.op_optional("3.1.49", to_can); + p.run_optional("3.1.49", to_can); } // TODO: 3.1.50 - 3.1.51 @@ -168,7 +168,7 @@ fn maybe_replace_cli_with_an(p: &mut Prakriya, i: usize) -> Option<()> { let tin = p.get(i + 2)?; let to_an = replace_with(i + 1, "aN"); if dhatu.has_u("asu~") || dhatu.has_text_in(&["vac", "KyA"]) { - p.op("3.1.52", to_an); + p.run("3.1.52", to_an); } else if dhatu.has_text_in(&["lip", "sic", "hve"]) { let mut skip = false; if tin.is_atmanepada() { @@ -180,7 +180,7 @@ fn maybe_replace_cli_with_an(p: &mut Prakriya, i: usize) -> Option<()> { } } if !skip { - p.op("3.1.53", to_an); + p.run("3.1.53", to_an); } } @@ -202,16 +202,16 @@ fn maybe_replace_cli_with_an(p: &mut Prakriya, i: usize) -> Option<()> { // sf\\ (sarati) is not part of the rule. (SK) // f\\ (fcCati) is not part of the rule. (SK) // SAsu~\\ (ASAste) is not part of the rule. (KV) - p.op("3.1.56", to_an); + p.run("3.1.56", to_an); } else if is_parasmai && dhatu.has_tag(T::irit) { - p.op_optional("3.1.57", to_an); + p.run_optional("3.1.57", to_an); } else if is_parasmai && dhatu.has_text_in(&jr_stambhu) { - p.op_optional("3.1.58", to_an); + p.run_optional("3.1.58", to_an); } else if is_parasmai && dhatu.has_text_in(&["kf", "mf", "df", "ruh"]) && p.has_tag(T::Chandasi) { - p.op("3.1.59", to_an); + p.run("3.1.59", to_an); } } @@ -230,7 +230,7 @@ fn maybe_replace_cli_with_cin(p: &mut Prakriya, i: usize) -> Option<()> { if tin.has_u("ta") { if dhatu.has_text("pad") { // apAdi - p.op("3.1.60", to_cin); + p.run("3.1.60", to_cin); } else if dhatu.has_u_in(&[ "dIpI~\\", "janI~\\", @@ -241,9 +241,9 @@ fn maybe_replace_cli_with_cin(p: &mut Prakriya, i: usize) -> Option<()> { "o~pyAyI~\\", ]) { // adIpi, ajani, aboDi, ... - p.op_optional("3.1.61", to_cin); + p.run_optional("3.1.61", to_cin); } else if p.has_tag(T::Karmani) { - p.op("3.1.66", to_cin); + p.run("3.1.66", to_cin); } } @@ -254,13 +254,13 @@ fn maybe_replace_cli_with_cin(p: &mut Prakriya, i: usize) -> Option<()> { fn maybe_replace_cli_with_sic(p: &mut Prakriya, i: usize) { if has_cli(p, i) { - p.op("3.1.44", |p| op::upadesha_no_it(p, i + 1, "si~c")); + p.run("3.1.44", |p| op::upadesha_no_it(p, i + 1, "si~c")); } } /// Applies the vikarana rules for luN (3.1.43 - 3.1.66). fn add_lun_vikarana(p: &mut Prakriya) { - p.op("3.1.43", add_vikarana("cli~")); + p.run("3.1.43", add_vikarana("cli~")); let n = p.terms().len(); assert!(n >= 3); @@ -287,7 +287,7 @@ fn add_kr_bhu_or_as_after_am_pratyaya(p: &mut Prakriya) { let mut ran = false; if !ran { // corayAmbaBUva, ... - ran = p.op_optional("3.1.40:BU", |p| { + ran = p.run_optional("3.1.40:BU", |p| { let mut dhatu = Term::make_dhatu("BU", Bhvadi, None); dhatu.set_text("BU"); dhatu.add_tag(T::Dhatu); @@ -305,7 +305,7 @@ fn add_kr_bhu_or_as_after_am_pratyaya(p: &mut Prakriya) { } if !ran { // corayAmAsa, ... - ran = p.op_optional("3.1.40:as", |p| { + ran = p.run_optional("3.1.40:as", |p| { let mut dhatu = Term::make_dhatu("asa~", Adadi, None); dhatu.set_text("as"); dhatu.add_tag(T::Dhatu); @@ -323,7 +323,7 @@ fn add_kr_bhu_or_as_after_am_pratyaya(p: &mut Prakriya) { } if !ran { // corayAYcakAra, corayAYcakre, ... - p.op("3.1.40:kf", |p| { + p.run("3.1.40:kf", |p| { let mut dhatu = Term::make_dhatu("qukf\\Y", Tanadi, None); dhatu.set_text("kf"); dhatu.add_tag(T::Dhatu); @@ -345,19 +345,19 @@ pub fn try_add_am_pratyaya_for_lit(p: &mut Prakriya) -> Option<()> { if dhatu.has_text("kAs") || dhatu.is_pratyaya() { // kAsAYcakre; corayAYcakre - p.op("3.1.35", add_aam); + p.run("3.1.35", add_aam); } else if !dhatu.is_ekac() && !dhatu.has_text_in(&["jAgf", "UrRu"]) { // jAgf is handled separately below. - p.op("3.1.35.v1", add_aam); + p.run("3.1.35.v1", add_aam); } else if dhatu.has_adi(&*IC) && dhatu.is_guru() && !dhatu.has_u("fCa~") { // IkzAYcakre - p.op("3.1.36", add_aam); + p.run("3.1.36", add_aam); } else if dhatu.has_text_in(&["day", "ay", "As"]) { // dayAYcakre - p.op("3.1.37", add_aam); + p.run("3.1.37", add_aam); } else if dhatu.has_text_in(&["uz", "jAgf"]) || (dhatu.has_text("vid") && dhatu.has_gana(Adadi)) { - let used = p.op_optional("3.1.38", add_aam); + let used = p.run_optional("3.1.38", add_aam); if used { let dhatu = p.get(i)?; if dhatu.has_text("vid") { @@ -373,7 +373,7 @@ pub fn try_add_am_pratyaya_for_lit(p: &mut Prakriya) -> Option<()> { aam.add_tags(&[T::Pratyaya, T::Slu]); p.insert_after(i, aam); }; - if !p.op_optional("3.1.39", add_sluvat_am) { + if !p.run_optional("3.1.39", add_sluvat_am) { return None; } } else { @@ -397,7 +397,7 @@ fn maybe_add_am_pratyaya_for_lot(p: &mut Prakriya) { }; if p.has(i, |t| t.has_text("vid") && t.has_gana(Adadi) && is_lot) { - let added_am = p.op_optional("3.1.41", add_aam); + let added_am = p.run_optional("3.1.41", add_aam); if added_am { // Derive by nipAtana @@ -418,7 +418,7 @@ fn add_sarvadhatuka_vikarana(p: &mut Prakriya) -> Option<()> { let i = p.find_last(T::Dhatu)?; if p.has_tag_in(&[T::Bhave, T::Karmani]) { - p.op("3.1.67", add_vikarana("yak")); + p.run("3.1.67", add_vikarana("yak")); return Some(()); } @@ -431,7 +431,7 @@ fn add_sarvadhatuka_vikarana(p: &mut Prakriya) -> Option<()> { if dhatu.has_text_in(&[ "BrAS", "BlAS", "Bram", "kram", "klam", "tras", "truw", "laz", ]) { - let applied = p.op_optional("3.1.70", add_vikarana("Syan")); + let applied = p.run_optional("3.1.70", add_vikarana("Syan")); // Needed to make 3.1.69 available to roots like Bram if !applied && p.has(i, |t| t.has_gana(Divadi)) { @@ -440,19 +440,19 @@ fn add_sarvadhatuka_vikarana(p: &mut Prakriya) -> Option<()> { } else if dhatu.has_u("yasu~") { if !has_upasarga { // yasyati, yasati - divadi_declined = !p.op_optional("3.1.71", add_vikarana("Syan")); + divadi_declined = !p.run_optional("3.1.71", add_vikarana("Syan")); } else if i > 0 && p.has(i - 1, |t| t.has_u("sam")) { // saMyasyati, saMyasati - divadi_declined = !p.op_optional("3.1.72", add_vikarana("Syan")); + divadi_declined = !p.run_optional("3.1.72", add_vikarana("Syan")); } } else if dhatu.has_u("akzU~") { // akzRoti, akzati - p.op_optional("3.1.75", add_vikarana("Snu")); + p.run_optional("3.1.75", add_vikarana("Snu")); } else if dhatu.has_u("takzU~") { // takzRoti, takzati - p.op_optional("3.1.76", add_vikarana("Snu")); + p.run_optional("3.1.76", add_vikarana("Snu")); } else if dhatu.has_u_in(&stanbhu_stunbhu) { - p.op_optional("3.1.82", add_vikarana("Snu")); + p.run_optional("3.1.82", add_vikarana("Snu")); } if p.find_first(T::Vikarana).is_some() { @@ -462,37 +462,37 @@ fn add_sarvadhatuka_vikarana(p: &mut Prakriya) -> Option<()> { let dhatu = p.get(i)?; if dhatu.has_gana(Divadi) && !divadi_declined { // dIvyati - p.op("3.1.69", add_vikarana("Syan")); + p.run("3.1.69", add_vikarana("Syan")); } else if dhatu.has_gana(Svadi) { - p.op("3.1.73", add_vikarana("Snu")); + p.run("3.1.73", add_vikarana("Snu")); } else if dhatu.has_text("Sru") { - p.op("3.1.74", |p| { + p.run("3.1.74", |p| { p.set(i, |t| t.set_text("Sf")); add_vikarana("Snu")(p); }); } else if dhatu.has_gana(Tudadi) { // tudati - p.op("3.1.77", add_vikarana("Sa")); + p.run("3.1.77", add_vikarana("Sa")); } else if dhatu.has_gana(Rudhadi) { // ruRadDi - p.op("3.1.78", |p| { + p.run("3.1.78", |p| { p.set(i, |t| t.add_tag(T::Snam)); p.set(i, op::mit("na")); }); } else if dhatu.has_gana(Tanadi) || dhatu.has_u("qukf\\Y") { // tanoti; karoti - p.op("3.1.79", add_vikarana("u")); + p.run("3.1.79", add_vikarana("u")); } else if dhatu.has_u_in(&["Divi~", "kfvi~"]) { - p.op("3.1.80", |p| { + p.run("3.1.80", |p| { p.set(i, op::antya("a")); add_vikarana("u")(p); }); } else if dhatu.has_gana(Kryadi) { // krIRAti - p.op("3.1.81", add_vikarana("SnA")); + p.run("3.1.81", add_vikarana("SnA")); } else { // Bavati - p.op("3.1.68", add_vikarana("Sap")); + p.run("3.1.68", add_vikarana("Sap")); } Some(()) @@ -509,7 +509,6 @@ fn maybe_sic_lopa_before_parasmaipada( } let dhatu = p.get(i)?; - let do_luk = |p: &mut Prakriya, code| p.op(code, op::t(i_vikarana, op::luk)); if dhatu.has_text_in(&["GrA", "De", "So", "Co", "so"]) { let code = "2.4.78"; // De takes luk by 2.4.77, so 2.4.78 allows aluk. @@ -523,7 +522,7 @@ fn maybe_sic_lopa_before_parasmaipada( } else { // The other roots avoid luk by default, so 2.4.78 allows luk. if p.is_allowed(code) { - do_luk(p, code); + p.run_at(code, i_vikarana, op::luk); return None; } else { p.decline(code); @@ -541,7 +540,7 @@ fn maybe_sic_lopa_before_parasmaipada( // Run only if aluk was not used above. if p.has(i, gati_stha) { - do_luk(p, "2.4.77"); + p.run_at("2.4.77", i_vikarana, op::luk); } Some(()) @@ -557,7 +556,7 @@ fn maybe_sic_lopa_for_tanadi_atmanepada( let tin = p.get(i_tin)?; if dhatu.has_u_in(TAN_ADI) && tin.has_text_in(&["ta", "TAs"]) { // atata, ataTAH - p.op_optional("2.4.79", op::t(i_vikarana, op::luk)); + p.run_optional_at("2.4.79", i_vikarana, op::luk); } Some(()) @@ -576,10 +575,10 @@ fn try_pratyaya_lopa(p: &mut Prakriya) -> Option<()> { if vikarana.has_u("Sap") { if dhatu.has_gana(Adadi) { // atti, dvezwi - p.op_term("2.4.72", i_vikarana, op::luk); + p.run_at("2.4.72", i_vikarana, op::luk); } else if dhatu.has_gana(Juhotyadi) { // juhoti, biBarti - p.op_term("2.4.75", i_vikarana, op::slu); + p.run_at("2.4.75", i_vikarana, op::slu); } } else if vikarana.has_u("si~c") { maybe_sic_lopa_before_parasmaipada(p, i_dhatu, i_vikarana, i_tin); @@ -598,10 +597,10 @@ pub fn run(p: &mut Prakriya) -> Result<()> { if tin.has_lakshana_in(&["lf~w", "lf~N", "lu~w"]) { if tin.has_lakshana_in(&["lf~w", "lf~N"]) { // Bavizyati - p.op("3.1.33", add_vikarana("sya")); + p.run("3.1.33", add_vikarana("sya")); } else { // BavitA - p.op("3.1.33", add_vikarana("tAsi~")); + p.run("3.1.33", add_vikarana("tAsi~")); } } else if tin.has_lakshana("lu~N") { add_lun_vikarana(p); diff --git a/vidyut-prakriya/src/wasm.rs b/vidyut-prakriya/src/wasm.rs index b8698dc..ec679d3 100644 --- a/vidyut-prakriya/src/wasm.rs +++ b/vidyut-prakriya/src/wasm.rs @@ -12,6 +12,7 @@ JavaScript callers can use them more idiomatically. */ use crate::args::*; use crate::dhatupatha::Dhatupatha; +use crate::prakriya::Rule; use crate::prakriya::{Prakriya, Step}; use serde::Serialize; extern crate console_error_panic_hook; @@ -19,30 +20,59 @@ extern crate console_error_panic_hook; use crate::Ashtadhyayi; use wasm_bindgen::prelude::{wasm_bindgen, JsValue}; -/// A lightweight `Step` that exposes fewer private fields. +#[wasm_bindgen] +extern "C" { + /// Exposes `console.error` in case we need to log anything to the JS console. + #[wasm_bindgen(js_namespace = console, js_name = error)] + fn error(s: &str); +} + +/// A lightweight `Step` that exposes fewer private fields than the native `Step` struct. #[derive(Serialize)] pub struct WebStep { + /// The rule that was applied for this step of the derivation. rule: String, + /// The result of applying the given rule. result: String, } -/// A lightweight `Prakriya` that exposes fewer private fields. +/// A lightweight `Prakriya` that exposes fewer private fields than the native `Prakriya` struct. #[derive(Serialize)] pub struct WebPrakriya { + /// The final text produced by this prakriya. text: String, + /// The list of steps that was applied to produce `text`. history: Vec, } +impl Rule { + /// Converts a `Rule` to a string suitable for web display. + /// + /// We return SLP1 strings, which the frontend will transliterate to the user's chosen script. + fn as_web_string(&self) -> String { + match self { + Self::Ashtadhyayi(s) => s.to_string(), + Self::Dhatupatha(s) => format!("DAtupATa {s}"), + Self::Kashika(s) => format!("kAzikA {s}"), + Self::Linganushasana(s) => format!("liNgA {s}"), + Self::Kaumudi(s) => format!("kOmudI {s}"), + Self::Unadi(s) => format!("uRAdi {s}"), + } + } +} + +/// Converts the native `Step` array to a format that wasm_bindgen can serialize. fn to_web_history(history: &[Step]) -> Vec { history .iter() .map(|x| WebStep { - rule: x.rule(), + rule: x.rule().as_web_string(), result: x.result().clone(), }) .collect() } +/// Converts the native `Prakriya` struct to a format that wasm_bindgen can serialize. fn to_web_prakriyas(prakriyas: &[Prakriya]) -> Vec { prakriyas .iter() @@ -65,14 +95,10 @@ fn try_expand_dhatu(dhatu: &Dhatu, sanadi: Option, upasarga: Option, ) -> JsValue { if let Some(raw_dhatu) = self.dhatupatha.get(code) { + let dhatu = try_expand_dhatu(raw_dhatu, sanadi, upasarga); let mut args = TinantaArgs::builder() .lakara(lakara) .prayoga(prayoga) .purusha(purusha) .vacana(vacana); - if let Some(pada) = pada { args = args.pada(pada); } - let args = args.build().expect("should be well-formed"); let a = Ashtadhyayi::new(); - let dhatu = try_expand_dhatu(raw_dhatu, sanadi, upasarga); let prakriyas = a.derive_tinantas(&dhatu, &args); let web_prakriyas = to_web_prakriyas(&prakriyas); @@ -162,8 +185,6 @@ impl Vidyut { } /// Wrapper for `Ashtadhyayi::derive_krdantas`. - /// - /// TODO: how might we reduce the number of arguments here? #[allow(non_snake_case)] pub fn deriveKrdantas( &self, diff --git a/vidyut-prakriya/test_utils/src/lib.rs b/vidyut-prakriya/test_utils/src/lib.rs index 634589a..993e3a6 100644 --- a/vidyut-prakriya/test_utils/src/lib.rs +++ b/vidyut-prakriya/test_utils/src/lib.rs @@ -12,6 +12,7 @@ use vidyut_prakriya::args::Vibhakti::*; use vidyut_prakriya::args::*; use vidyut_prakriya::Ashtadhyayi; use vidyut_prakriya::Prakriya; +use vidyut_prakriya::Rule; // Derivation helpers // ------------------ @@ -109,11 +110,22 @@ fn derive_karmani(prefixes: &[&str], dhatu: &Dhatu, lakara: Lakara) -> Vec String { + match rule { + Rule::Ashtadhyayi(x) => x.to_string(), + Rule::Dhatupatha(x) => format!("DA {x}"), + Rule::Kashika(x) => format!("kA {x}"), + Rule::Kaumudi(x) => format!("kO {x}"), + Rule::Linganushasana(x) => format!("Li {x}"), + Rule::Unadi(x) => format!("uRA {x}"), + } +} + /// Nicely prints out the given prakriyas. fn print_all_prakriyas(prakriyas: &[Prakriya]) { for p in prakriyas { for step in p.history() { - println!("{} --> {}", step.rule(), step.result()); + println!("{} --> {}", debug_text(step.rule()), step.result()); } println!("{:?}", p.rule_choices()); println!(); @@ -319,12 +331,12 @@ pub fn yan_luk(dhatu: &Dhatu) -> Dhatu { // Pratipadika helpers // ------------------- -// Shorthand for building a pratipadika. +/// Shorthand for building a pratipadika. pub fn prati(text: &str) -> Pratipadika { Pratipadika::new(text) } -// Shorthand for building a pratipadika that ends with NI/Ap. +/// Shorthand for building a pratipadika that ends with NI/Ap. pub fn nyap(text: &str) -> Pratipadika { Pratipadika::builder() .text(text) @@ -333,6 +345,15 @@ pub fn nyap(text: &str) -> Pratipadika { .unwrap() } +/// Shorthand for building a pratipadika from a dhatu. +pub fn dhatu_prati(text: &str) -> Pratipadika { + Pratipadika::builder() + .text(text) + .is_dhatu(true) + .build() + .unwrap() +} + // Tinanta helpers (based on final suffix) // --------------------------------------- @@ -708,7 +729,7 @@ pub fn assert_has_artha_taddhita( // Subanta helpers // --------------- -pub fn assert_has_subantas_p( +fn assert_has_subantas_p( pratipadika: &Pratipadika, linga: Linga, vibhakti: Vibhakti, @@ -726,17 +747,6 @@ pub fn assert_has_subantas_p( assert_padas(actual, expected); } -pub fn assert_has_subantas( - pratipadika_text: &str, - linga: Linga, - vibhakti: Vibhakti, - vacana: Vacana, - expected: &[&str], -) { - let pratipadika = Pratipadika::new(pratipadika_text); - assert_has_subantas_p(&pratipadika, linga, vibhakti, vacana, expected); -} - /// Like `assert_has_subantas_p` but without any filtering on the last sound. /// (Needed for 8.4.56.) pub fn assert_has_subantas_raw( @@ -762,98 +772,114 @@ pub fn assert_has_subantas_raw( assert_padas(actual, expected); } -pub fn assert_has_sup_1s(prati: &str, linga: Linga, expected: &[&str]) { - assert_has_subantas(prati, linga, Prathama, Eka, &expected); +pub trait Prati { + fn to_p(self) -> Pratipadika; +} + +impl Prati for &Pratipadika { + fn to_p(self) -> Pratipadika { + self.clone() + } +} + +impl Prati for &str { + fn to_p(self) -> Pratipadika { + Pratipadika::new(self) + } +} + +pub fn assert_has_sup_1s(prati: impl Prati, linga: Linga, expected: &[&str]) { + assert_has_subantas_p(&prati.to_p(), linga, Prathama, Eka, &expected); } -pub fn assert_has_sup_1d(prati: &str, linga: Linga, expected: &[&str]) { - assert_has_subantas(prati, linga, Prathama, Dvi, &expected); +pub fn assert_has_sup_1d(prati: impl Prati, linga: Linga, expected: &[&str]) { + assert_has_subantas_p(&prati.to_p(), linga, Prathama, Dvi, &expected); } -pub fn assert_has_sup_1p(prati: &str, linga: Linga, expected: &[&str]) { - assert_has_subantas(prati, linga, Prathama, Bahu, &expected); +pub fn assert_has_sup_1p(prati: impl Prati, linga: Linga, expected: &[&str]) { + assert_has_subantas_p(&prati.to_p(), linga, Prathama, Bahu, &expected); } -pub fn assert_has_sup_2s(prati: &str, linga: Linga, expected: &[&str]) { - assert_has_subantas(prati, linga, Dvitiya, Eka, &expected); +pub fn assert_has_sup_2s(prati: impl Prati, linga: Linga, expected: &[&str]) { + assert_has_subantas_p(&prati.to_p(), linga, Dvitiya, Eka, &expected); } -pub fn assert_has_sup_2d(prati: &str, linga: Linga, expected: &[&str]) { - assert_has_subantas(prati, linga, Dvitiya, Dvi, &expected); +pub fn assert_has_sup_2d(prati: impl Prati, linga: Linga, expected: &[&str]) { + assert_has_subantas_p(&prati.to_p(), linga, Dvitiya, Dvi, &expected); } -pub fn assert_has_sup_2p(prati: &str, linga: Linga, expected: &[&str]) { - assert_has_subantas(prati, linga, Dvitiya, Bahu, &expected); +pub fn assert_has_sup_2p(prati: impl Prati, linga: Linga, expected: &[&str]) { + assert_has_subantas_p(&prati.to_p(), linga, Dvitiya, Bahu, &expected); } -pub fn assert_has_sup_3s(prati: &str, linga: Linga, expected: &[&str]) { - assert_has_subantas(prati, linga, Trtiya, Eka, &expected); +pub fn assert_has_sup_3s(prati: impl Prati, linga: Linga, expected: &[&str]) { + assert_has_subantas_p(&prati.to_p(), linga, Trtiya, Eka, &expected); } -pub fn assert_has_sup_3d(prati: &str, linga: Linga, expected: &[&str]) { - assert_has_subantas(prati, linga, Trtiya, Dvi, &expected); +pub fn assert_has_sup_3d(prati: impl Prati, linga: Linga, expected: &[&str]) { + assert_has_subantas_p(&prati.to_p(), linga, Trtiya, Dvi, &expected); } -pub fn assert_has_sup_3p(prati: &str, linga: Linga, expected: &[&str]) { - assert_has_subantas(prati, linga, Trtiya, Bahu, &expected); +pub fn assert_has_sup_3p(prati: impl Prati, linga: Linga, expected: &[&str]) { + assert_has_subantas_p(&prati.to_p(), linga, Trtiya, Bahu, &expected); } -pub fn assert_has_sup_4s(prati: &str, linga: Linga, expected: &[&str]) { - assert_has_subantas(prati, linga, Caturthi, Eka, &expected); +pub fn assert_has_sup_4s(prati: impl Prati, linga: Linga, expected: &[&str]) { + assert_has_subantas_p(&prati.to_p(), linga, Caturthi, Eka, &expected); } -pub fn assert_has_sup_4d(prati: &str, linga: Linga, expected: &[&str]) { - assert_has_subantas(prati, linga, Caturthi, Dvi, &expected); +pub fn assert_has_sup_4d(prati: impl Prati, linga: Linga, expected: &[&str]) { + assert_has_subantas_p(&prati.to_p(), linga, Caturthi, Dvi, &expected); } -pub fn assert_has_sup_4p(prati: &str, linga: Linga, expected: &[&str]) { - assert_has_subantas(prati, linga, Caturthi, Bahu, &expected); +pub fn assert_has_sup_4p(prati: impl Prati, linga: Linga, expected: &[&str]) { + assert_has_subantas_p(&prati.to_p(), linga, Caturthi, Bahu, &expected); } -pub fn assert_has_sup_5d(prati: &str, linga: Linga, expected: &[&str]) { - assert_has_subantas(prati, linga, Caturthi, Dvi, &expected); +pub fn assert_has_sup_5s(prati: impl Prati, linga: Linga, expected: &[&str]) { + assert_has_subantas_p(&prati.to_p(), linga, Panchami, Eka, &expected); } -pub fn assert_has_sup_5p(prati: &str, linga: Linga, expected: &[&str]) { - assert_has_subantas(prati, linga, Caturthi, Bahu, &expected); +pub fn assert_has_sup_5d(prati: impl Prati, linga: Linga, expected: &[&str]) { + assert_has_subantas_p(&prati.to_p(), linga, Panchami, Dvi, &expected); } -pub fn assert_has_sup_5s(prati: &str, linga: Linga, expected: &[&str]) { - assert_has_subantas(prati, linga, Panchami, Eka, &expected); +pub fn assert_has_sup_5p(prati: impl Prati, linga: Linga, expected: &[&str]) { + assert_has_subantas_p(&prati.to_p(), linga, Panchami, Bahu, &expected); } -pub fn assert_has_sup_6s(prati: &str, linga: Linga, expected: &[&str]) { - assert_has_subantas(prati, linga, Sasthi, Eka, &expected); +pub fn assert_has_sup_6s(prati: impl Prati, linga: Linga, expected: &[&str]) { + assert_has_subantas_p(&prati.to_p(), linga, Sasthi, Eka, &expected); } -pub fn assert_has_sup_6d(prati: &str, linga: Linga, expected: &[&str]) { - assert_has_subantas(prati, linga, Sasthi, Dvi, &expected); +pub fn assert_has_sup_6d(prati: impl Prati, linga: Linga, expected: &[&str]) { + assert_has_subantas_p(&prati.to_p(), linga, Sasthi, Dvi, &expected); } -pub fn assert_has_sup_6p(prati: &str, linga: Linga, expected: &[&str]) { - assert_has_subantas(prati, linga, Sasthi, Bahu, &expected); +pub fn assert_has_sup_6p(prati: impl Prati, linga: Linga, expected: &[&str]) { + assert_has_subantas_p(&prati.to_p(), linga, Sasthi, Bahu, &expected); } -pub fn assert_has_sup_7s(prati: &str, linga: Linga, expected: &[&str]) { - assert_has_subantas(prati, linga, Saptami, Eka, &expected); +pub fn assert_has_sup_7s(prati: impl Prati, linga: Linga, expected: &[&str]) { + assert_has_subantas_p(&prati.to_p(), linga, Saptami, Eka, &expected); } -pub fn assert_has_sup_7d(prati: &str, linga: Linga, expected: &[&str]) { - assert_has_subantas(prati, linga, Saptami, Dvi, &expected); +pub fn assert_has_sup_7d(prati: impl Prati, linga: Linga, expected: &[&str]) { + assert_has_subantas_p(&prati.to_p(), linga, Saptami, Dvi, &expected); } -pub fn assert_has_sup_7p(prati: &str, linga: Linga, expected: &[&str]) { - assert_has_subantas(prati, linga, Saptami, Bahu, &expected); +pub fn assert_has_sup_7p(prati: impl Prati, linga: Linga, expected: &[&str]) { + assert_has_subantas_p(&prati.to_p(), linga, Saptami, Bahu, &expected); } -pub fn assert_has_sup_ss(prati: &str, linga: Linga, expected: &[&str]) { - assert_has_subantas(prati, linga, Sambodhana, Eka, &expected); +pub fn assert_has_sup_ss(prati: impl Prati, linga: Linga, expected: &[&str]) { + assert_has_subantas_p(&prati.to_p(), linga, Sambodhana, Eka, &expected); } -pub fn assert_has_sup_sd(prati: &str, linga: Linga, expected: &[&str]) { - assert_has_subantas(prati, linga, Sambodhana, Dvi, &expected); +pub fn assert_has_sup_sd(prati: impl Prati, linga: Linga, expected: &[&str]) { + assert_has_subantas_p(&prati.to_p(), linga, Sambodhana, Dvi, &expected); } -pub fn assert_has_sup_sp(prati: &str, linga: Linga, expected: &[&str]) { - assert_has_subantas(prati, linga, Sambodhana, Bahu, &expected); +pub fn assert_has_sup_sp(prati: impl Prati, linga: Linga, expected: &[&str]) { + assert_has_subantas_p(&prati.to_p(), linga, Sambodhana, Bahu, &expected); } diff --git a/vidyut-prakriya/tests/kashika_1_1.rs b/vidyut-prakriya/tests/kashika_1_1.rs index e6ed79a..2486651 100644 --- a/vidyut-prakriya/tests/kashika_1_1.rs +++ b/vidyut-prakriya/tests/kashika_1_1.rs @@ -6,7 +6,6 @@ use vidyut_prakriya::args::Linga::*; use vidyut_prakriya::args::Purusha as P; use vidyut_prakriya::args::Taddhita as T; use vidyut_prakriya::args::Vacana::*; -use vidyut_prakriya::args::Vibhakti::*; use vidyut_prakriya::args::*; #[test] @@ -54,10 +53,10 @@ fn sutra_1_1_3() { assert_has_krdanta(&[], &d("unBa~", Tudadi), Krt::tfc, &["umBitf"]); // punargrahaNam of the terms "guna" and "vrddhi" - assert_has_subantas("div", Stri, Prathama, Eka, &["dyOH"]); - assert_has_subantas("paTin", Pum, Prathama, Eka, &["panTAH"]); - assert_has_subantas("tad", Pum, Prathama, Eka, &["saH"]); - assert_has_subantas("idam", Pum, Dvitiya, Eka, &["imam"]); + assert_has_sup_1s("div", Stri, &["dyOH"]); + assert_has_sup_1s("paTin", Pum, &["panTAH"]); + assert_has_sup_1s("tad", Pum, &["saH"]); + assert_has_sup_2s("idam", Pum, &["imam"]); } #[test] @@ -206,14 +205,14 @@ fn sutra_1_1_23() { #[test] fn sutra_1_1_24() { - assert_has_subantas("zaz", Napumsaka, Prathama, Bahu, &["zaw"]); - assert_has_subantas("paYcan", Napumsaka, Prathama, Bahu, &["paYca"]); - assert_has_subantas("saptan", Napumsaka, Prathama, Bahu, &["sapta"]); - assert_has_subantas("navan", Napumsaka, Prathama, Bahu, &["nava"]); - assert_has_subantas("daSan", Napumsaka, Prathama, Bahu, &["daSa"]); + assert_has_sup_1p("zaz", Napumsaka, &["zaw"]); + assert_has_sup_1p("paYcan", Napumsaka, &["paYca"]); + assert_has_sup_1p("saptan", Napumsaka, &["sapta"]); + assert_has_sup_1p("navan", Napumsaka, &["nava"]); + assert_has_sup_1p("daSan", Napumsaka, &["daSa"]); // others - assert_has_subantas("Sata", Napumsaka, Prathama, Bahu, &["SatAni"]); - assert_has_subantas("sahasra", Napumsaka, Prathama, Bahu, &["sahasrARi"]); + assert_has_sup_1p("Sata", Napumsaka, &["SatAni"]); + assert_has_sup_1p("sahasra", Napumsaka, &["sahasrARi"]); } #[test] @@ -230,61 +229,61 @@ fn sutra_1_1_26() { #[test] fn sutra_1_1_27() { // use Taddhita as T; - assert_has_subantas("sarva", Pum, Prathama, Eka, &["sarvaH"]); - assert_has_subantas("sarva", Pum, Prathama, Dvi, &["sarvO"]); - assert_has_subantas("sarva", Pum, Prathama, Bahu, &["sarve"]); - assert_has_subantas("sarva", Pum, Caturthi, Eka, &["sarvasmE"]); - assert_has_subantas("sarva", Pum, Panchami, Eka, &["sarvasmAt"]); - assert_has_subantas("sarva", Pum, Sasthi, Bahu, &["sarvezAm"]); - assert_has_subantas("sarva", Pum, Saptami, Eka, &["sarvasmin"]); + assert_has_sup_1s("sarva", Pum, &["sarvaH"]); + assert_has_sup_1d("sarva", Pum, &["sarvO"]); + assert_has_sup_1p("sarva", Pum, &["sarve"]); + assert_has_sup_4s("sarva", Pum, &["sarvasmE"]); + assert_has_sup_5s("sarva", Pum, &["sarvasmAt"]); + assert_has_sup_6p("sarva", Pum, &["sarvezAm"]); + assert_has_sup_7s("sarva", Pum, &["sarvasmin"]); // assert_has_taddhitanta(&prati("sarva"), T::akac, &["sarvaka"]); - assert_has_subantas("viSva", Pum, Prathama, Eka, &["viSvaH"]); - assert_has_subantas("viSva", Pum, Prathama, Dvi, &["viSvO"]); - assert_has_subantas("viSva", Pum, Prathama, Bahu, &["viSve"]); - assert_has_subantas("viSva", Pum, Caturthi, Eka, &["viSvasmE"]); - assert_has_subantas("viSva", Pum, Panchami, Eka, &["viSvasmAt"]); - assert_has_subantas("viSva", Pum, Sasthi, Bahu, &["viSvezAm"]); - assert_has_subantas("viSva", Pum, Saptami, Eka, &["viSvasmin"]); + assert_has_sup_1s("viSva", Pum, &["viSvaH"]); + assert_has_sup_1d("viSva", Pum, &["viSvO"]); + assert_has_sup_1p("viSva", Pum, &["viSve"]); + assert_has_sup_4s("viSva", Pum, &["viSvasmE"]); + assert_has_sup_5s("viSva", Pum, &["viSvasmAt"]); + assert_has_sup_6p("viSva", Pum, &["viSvezAm"]); + assert_has_sup_7s("viSva", Pum, &["viSvasmin"]); // assert_has_taddhitanta(&prati("viSva"), T::akac, &["viSvaka"]); - assert_has_subantas("uBaya", Pum, Prathama, Bahu, &["uBaye"]); - assert_has_subantas("uBaya", Pum, Caturthi, Eka, &["uBayasmE"]); - assert_has_subantas("uBaya", Pum, Panchami, Eka, &["uBayasmAt"]); - assert_has_subantas("uBaya", Pum, Sasthi, Bahu, &["uBayezAm"]); - assert_has_subantas("uBaya", Pum, Saptami, Eka, &["uBayasmin"]); + assert_has_sup_1p("uBaya", Pum, &["uBaye"]); + assert_has_sup_4s("uBaya", Pum, &["uBayasmE"]); + assert_has_sup_5s("uBaya", Pum, &["uBayasmAt"]); + assert_has_sup_6p("uBaya", Pum, &["uBayezAm"]); + assert_has_sup_7s("uBaya", Pum, &["uBayasmin"]); // qatara - assert_has_subantas("katara", Pum, Caturthi, Eka, &["katarasmE"]); - assert_has_subantas("katama", Pum, Caturthi, Eka, &["katamasmE"]); + assert_has_sup_4s("katara", Pum, &["katarasmE"]); + assert_has_sup_4s("katama", Pum, &["katamasmE"]); // itara, etc. - assert_has_subantas("itara", Pum, Caturthi, Eka, &["itarasmE"]); - assert_has_subantas("anya", Pum, Caturthi, Eka, &["anyasmE"]); - assert_has_subantas("anyatara", Pum, Caturthi, Eka, &["anyatarasmE"]); + assert_has_sup_4s("itara", Pum, &["itarasmE"]); + assert_has_sup_4s("anya", Pum, &["anyasmE"]); + assert_has_sup_4s("anyatara", Pum, &["anyatarasmE"]); // TODO: others } #[test] fn sutra_1_1_33() { - assert_has_subantas("praTama", Pum, Prathama, Bahu, &["praTame", "praTamAH"]); - assert_has_subantas("carama", Pum, Prathama, Bahu, &["carame", "caramAH"]); - assert_has_subantas("alpa", Pum, Prathama, Bahu, &["alpe", "alpAH"]); - assert_has_subantas("arDa", Pum, Prathama, Bahu, &["arDe", "arDAH"]); - assert_has_subantas("katipaya", Pum, Prathama, Bahu, &["katipaye", "katipayAH"]); - assert_has_subantas("nema", Pum, Prathama, Bahu, &["neme", "nemAH"]); + assert_has_sup_1p("praTama", Pum, &["praTame", "praTamAH"]); + assert_has_sup_1p("carama", Pum, &["carame", "caramAH"]); + assert_has_sup_1p("alpa", Pum, &["alpe", "alpAH"]); + assert_has_sup_1p("arDa", Pum, &["arDe", "arDAH"]); + assert_has_sup_1p("katipaya", Pum, &["katipaye", "katipayAH"]); + assert_has_sup_1p("nema", Pum, &["neme", "nemAH"]); // TODO: taya } #[test] fn sutra_1_1_34() { - assert_has_subantas("pUrva", Pum, Prathama, Bahu, &["pUrve", "pUrvAH"]); - assert_has_subantas("para", Pum, Prathama, Bahu, &["pare", "parAH"]); - assert_has_subantas("avara", Pum, Prathama, Bahu, &["avare", "avarAH"]); - assert_has_subantas("dakziRa", Pum, Prathama, Bahu, &["dakziRe", "dakziRAH"]); - assert_has_subantas("uttara", Pum, Prathama, Bahu, &["uttare", "uttarAH"]); - assert_has_subantas("apara", Pum, Prathama, Bahu, &["apare", "aparAH"]); - assert_has_subantas("aDara", Pum, Prathama, Bahu, &["aDare", "aDarAH"]); + assert_has_sup_1p("pUrva", Pum, &["pUrve", "pUrvAH"]); + assert_has_sup_1p("para", Pum, &["pare", "parAH"]); + assert_has_sup_1p("avara", Pum, &["avare", "avarAH"]); + assert_has_sup_1p("dakziRa", Pum, &["dakziRe", "dakziRAH"]); + assert_has_sup_1p("uttara", Pum, &["uttare", "uttarAH"]); + assert_has_sup_1p("apara", Pum, &["apare", "aparAH"]); + assert_has_sup_1p("aDara", Pum, &["aDare", "aDarAH"]); } #[test] @@ -299,26 +298,26 @@ fn sutra_1_1_40() { #[test] fn sutra_1_1_42() { - assert_has_subantas("kuRqa", Napumsaka, Prathama, Bahu, &["kuRqAni"]); - assert_has_subantas("kuRqa", Napumsaka, Dvitiya, Bahu, &["kuRqAni"]); - assert_has_subantas("daDi", Napumsaka, Prathama, Bahu, &["daDIni"]); - assert_has_subantas("maDu", Napumsaka, Prathama, Bahu, &["maDUni"]); - assert_has_subantas("trapu", Napumsaka, Prathama, Bahu, &["trapURi"]); - assert_has_subantas("jatu", Napumsaka, Prathama, Bahu, &["jatUni"]); + assert_has_sup_1p("kuRqa", Napumsaka, &["kuRqAni"]); + assert_has_sup_2p("kuRqa", Napumsaka, &["kuRqAni"]); + assert_has_sup_1p("daDi", Napumsaka, &["daDIni"]); + assert_has_sup_1p("maDu", Napumsaka, &["maDUni"]); + assert_has_sup_1p("trapu", Napumsaka, &["trapURi"]); + assert_has_sup_1p("jatu", Napumsaka, &["jatUni"]); } #[test] fn sutra_1_1_43() { - assert_has_subantas("rAjan", Pum, Prathama, Eka, &["rAjA"]); - assert_has_subantas("rAjan", Pum, Prathama, Dvi, &["rAjAnO"]); - assert_has_subantas("rAjan", Pum, Prathama, Bahu, &["rAjAnaH"]); - assert_has_subantas("rAjan", Pum, Dvitiya, Eka, &["rAjAnam"]); - assert_has_subantas("rAjan", Pum, Dvitiya, Dvi, &["rAjAnO"]); + assert_has_sup_1s("rAjan", Pum, &["rAjA"]); + assert_has_sup_1d("rAjan", Pum, &["rAjAnO"]); + assert_has_sup_1p("rAjan", Pum, &["rAjAnaH"]); + assert_has_sup_2s("rAjan", Pum, &["rAjAnam"]); + assert_has_sup_2d("rAjan", Pum, &["rAjAnO"]); // suw - assert_has_subantas("rAjan", Pum, Dvitiya, Bahu, &["rAjYaH"]); + assert_has_sup_2p("rAjan", Pum, &["rAjYaH"]); // anapuMsakasya - assert_has_subantas("sAman", Napumsaka, Prathama, Dvi, &["sAmanI", "sAmnI"]); - assert_has_subantas("veman", Napumsaka, Prathama, Dvi, &["vemanI", "vemnI"]); + assert_has_sup_1d("sAman", Napumsaka, &["sAmanI", "sAmnI"]); + assert_has_sup_1d("veman", Napumsaka, &["vemanI", "vemnI"]); } #[test] @@ -347,7 +346,7 @@ fn sutra_1_1_46() { fn sutra_1_1_47() { assert_has_lat_p(&["vi"], &d("ru\\Di~^r", Rudhadi), &["viruRadDi"]); assert_has_lat_p(&[], &d("mu\\cx~^", Tudadi), &["muYcati"]); - assert_has_subantas("payas", Napumsaka, Prathama, Bahu, &["payAMsi"]); + assert_has_sup_1p("payas", Napumsaka, &["payAMsi"]); } #[test] @@ -361,13 +360,12 @@ fn sutra_1_1_47_v1() { #[test] fn sutra_1_1_48() { - use Vibhakti::*; - assert_has_subantas("atirE", Napumsaka, Prathama, Eka, &["atiri"]); - assert_has_subantas("atinO", Napumsaka, Prathama, Eka, &["atinu"]); - assert_has_subantas("upago", Napumsaka, Prathama, Eka, &["upagu"]); + assert_has_sup_1s("atirE", Napumsaka, &["atiri"]); + assert_has_sup_1s("atinO", Napumsaka, &["atinu"]); + assert_has_sup_1s("upago", Napumsaka, &["upagu"]); // ecaH? - // TODO: assert_has_subantas("atiKawvA", Pum, Prathama, Eka, &["atiKawvaH"]); - // TODO: assert_has_subantas("atimAlA", Pum, Prathama, Eka, &["atimAlaH"]); + // TODO: assert_has_sup_1s("atiKawvA", Pum, &["atiKawvaH"]); + // TODO: assert_has_sup_1s("atimAlA", Pum, &["atimAlaH"]); } #[test] @@ -392,8 +390,8 @@ fn sutra_1_1_55() { assert_has_krdanta(&[], &asa, Krt::tumun, &["Bavitum"]); assert_has_krdanta(&[], &asa, Krt::tavya, &["Bavitavya"]); // Sit - assert_has_subantas("kuRqa", Napumsaka, Prathama, Bahu, &["kuRqAni"]); - assert_has_subantas("kuRqa", Napumsaka, Dvitiya, Bahu, &["kuRqAni"]); + assert_has_sup_1p("kuRqa", Napumsaka, &["kuRqAni"]); + assert_has_sup_2p("kuRqa", Napumsaka, &["kuRqAni"]); } #[test] @@ -406,9 +404,9 @@ fn sutra_1_1_56() { assert_has_krdanta(&[], &d("brUY", Adadi), Krt::tumun, &["vaktum"]); assert_has_krdanta(&[], &d("brUY", Adadi), Krt::tavya, &["vaktavya"]); - assert_has_subantas("kim", Pum, Trtiya, Eka, &["kena"]); - assert_has_subantas("kim", Pum, Trtiya, Dvi, &["kAByAm"]); - assert_has_subantas("kim", Pum, Trtiya, Bahu, &["kEH"]); + assert_has_sup_3s("kim", Pum, &["kena"]); + assert_has_sup_3d("kim", Pum, &["kAByAm"]); + assert_has_sup_3p("kim", Pum, &["kEH"]); let kf = d("qukf\\Y", Tanadi); let hf = d("hf\\Y", Bhvadi); @@ -424,8 +422,8 @@ fn sutra_1_1_56() { assert_has_krdanta(&["upa"], &hf, Krt::ktvA, &["upahftya"]); assert_has_krdanta(&["upa"], &stu, Krt::ktvA, &["upastutya"]); - assert_has_subantas("vfkza", Pum, Caturthi, Eka, &["vfkzAya"]); - assert_has_subantas("plakza", Pum, Caturthi, Eka, &["plakzAya"]); + assert_has_sup_4s("vfkza", Pum, &["vfkzAya"]); + assert_has_sup_4s("plakza", Pum, &["plakzAya"]); assert_has_tas(&[], &kf, Lan, &["akurutAm"]); assert_has_thas(&[], &kf, Lan, &["akurutam"]); diff --git a/vidyut-prakriya/tests/kashika_1_2.rs b/vidyut-prakriya/tests/kashika_1_2.rs index 27a137d..e4e0f51 100644 --- a/vidyut-prakriya/tests/kashika_1_2.rs +++ b/vidyut-prakriya/tests/kashika_1_2.rs @@ -3,8 +3,6 @@ use test_utils::*; use vidyut_prakriya::args::Gana::*; use vidyut_prakriya::args::Lakara::*; use vidyut_prakriya::args::Linga::*; -use vidyut_prakriya::args::Vacana::*; -use vidyut_prakriya::args::Vibhakti; use vidyut_prakriya::args::*; #[test] @@ -461,11 +459,10 @@ fn sutra_1_2_41() { #[test] fn sutra_1_2_45() { - use Vibhakti::*; - assert_has_subantas("qitTa", Pum, Prathama, Eka, &["qitTaH"]); - assert_has_subantas("kapitTa", Pum, Prathama, Eka, &["kapitTaH"]); - assert_has_subantas("kuRqa", Napumsaka, Prathama, Eka, &["kuRqam"]); - assert_has_subantas("pIWa", Napumsaka, Prathama, Eka, &["pIWam"]); + assert_has_sup_1s("qitTa", Pum, &["qitTaH"]); + assert_has_sup_1s("kapitTa", Pum, &["kapitTaH"]); + assert_has_sup_1s("kuRqa", Napumsaka, &["kuRqam"]); + assert_has_sup_1s("pIWa", Napumsaka, &["pIWam"]); // a-dhAtu? assert_has_lan(&[], &d("ha\\na~", Adadi), &["ahan"]); // TODO: others @@ -473,11 +470,10 @@ fn sutra_1_2_45() { #[test] fn sutra_1_2_47() { - use Vibhakti::*; - assert_has_subantas("atirE", Napumsaka, Prathama, Eka, &["atiri"]); - assert_has_subantas("atinO", Napumsaka, Prathama, Eka, &["atinu"]); + assert_has_sup_1s("atirE", Napumsaka, &["atiri"]); + assert_has_sup_1s("atinO", Napumsaka, &["atinu"]); // napuMsake - assert_has_subantas("grAmaRI", Pum, Prathama, Eka, &["grAmaRIH"]); + assert_has_sup_1s("grAmaRI", Pum, &["grAmaRIH"]); // prAtipadikasya - assert_has_subantas("kuRqa", Napumsaka, Prathama, Dvi, &["kuRqe"]); + assert_has_sup_1d("kuRqa", Napumsaka, &["kuRqe"]); } diff --git a/vidyut-prakriya/tests/kashika_1_3.rs b/vidyut-prakriya/tests/kashika_1_3.rs index 43962f1..7bf562e 100644 --- a/vidyut-prakriya/tests/kashika_1_3.rs +++ b/vidyut-prakriya/tests/kashika_1_3.rs @@ -4,8 +4,6 @@ use vidyut_prakriya::args::Gana::*; use vidyut_prakriya::args::Lakara::*; use vidyut_prakriya::args::Linga::*; use vidyut_prakriya::args::Taddhita as T; -use vidyut_prakriya::args::Vacana::*; -use vidyut_prakriya::args::Vibhakti as V; use vidyut_prakriya::args::*; #[test] @@ -24,11 +22,11 @@ fn sutra_1_3_3() { #[test] fn sutra_1_3_4() { // t - assert_has_subantas("vfkza", Pum, V::Panchami, Eka, &["vfkzAt"]); - assert_has_subantas("plakza", Pum, V::Panchami, Eka, &["plakzAt"]); + assert_has_sup_5s("vfkza", Pum, &["vfkzAt"]); + assert_has_sup_5s("plakza", Pum, &["plakzAt"]); // s let pac = &d("qupa\\ca~^z", Bhvadi); - assert_has_subantas("brAhmaRa", Pum, V::Prathama, Bahu, &["brAhmaRAH"]); + assert_has_sup_1p("brAhmaRa", Pum, &["brAhmaRAH"]); assert_has_tas(&[], &pac, Lat, &["pacataH"]); assert_has_thas(&[], &pac, Lat, &["pacaTaH"]); // m @@ -59,9 +57,9 @@ fn sutra_1_3_6() { assert_has_krdanta(&[], &d("nftI~", Divadi), Krt::zvun, &["nartaka"]); assert_has_krdanta(&[], &d("ra\\nja~^", Bhvadi), Krt::zvun, &["rajaka"]); // pratyayasya? - assert_has_subantas("zoqa", Pum, V::Prathama, Eka, &["zoqaH"]); - assert_has_subantas("zaRqa", Pum, V::Prathama, Eka, &["zaRqaH"]); - assert_has_subantas("zaqika", Pum, V::Prathama, Eka, &["zaqikaH"]); + assert_has_sup_1s("zoqa", Pum, &["zoqaH"]); + assert_has_sup_1s("zaRqa", Pum, &["zaRqaH"]); + assert_has_sup_1s("zaqika", Pum, &["zaqikaH"]); // AdiH assert_has_krdanta(&[], &d("ava~", Bhvadi), Krt::wizac, &["aviza"]); // TODO: right mah? @@ -73,7 +71,7 @@ fn sutra_1_3_7() { // ca assert_has_taddhitanta(&prati("kuYja"), T::cPaY, &["kOYjAyana"]); // ja - assert_has_subantas("brAhmaRa", Pum, V::Prathama, Bahu, &["brAhmaRAH"]); + assert_has_sup_1p("brAhmaRa", Pum, &["brAhmaRAH"]); // Ya assert_has_taddhitanta(&prati("SaRqika"), T::Yya, &["SARqikya"]); // wa @@ -111,8 +109,8 @@ fn sutra_1_3_8() { // Ga assert_has_krdanta(&[], &d("Ba\\njo~", Rudhadi), Krt::Gurac, &["BaNgura"]); // Na (Nasi --> At, Nas --> sya) - assert_has_subantas("vfkza", Pum, V::Panchami, Eka, &["vfkzAt"]); - assert_has_subantas("vfkza", Pum, V::Sasthi, Eka, &["vfkzasya"]); + assert_has_sup_5s("vfkza", Pum, &["vfkzAt"]); + assert_has_sup_6s("vfkza", Pum, &["vfkzasya"]); // ataddhite? assert_has_taddhitanta(&prati("cUqA"), T::lac, &["cUqAla"]); assert_has_taddhitanta(&prati("loman"), T::Sa, &["lomaSa"]); diff --git a/vidyut-prakriya/tests/kashika_1_4.rs b/vidyut-prakriya/tests/kashika_1_4.rs index a5d824c..27f9972 100644 --- a/vidyut-prakriya/tests/kashika_1_4.rs +++ b/vidyut-prakriya/tests/kashika_1_4.rs @@ -4,8 +4,6 @@ use vidyut_prakriya::args::Gana::*; use vidyut_prakriya::args::Lakara::*; use vidyut_prakriya::args::Linga::*; use vidyut_prakriya::args::Taddhita as T; -use vidyut_prakriya::args::Vacana::*; -use vidyut_prakriya::args::Vibhakti::*; use vidyut_prakriya::args::*; fn dhatu_prati(text: &str) -> Pratipadika { @@ -19,20 +17,20 @@ fn dhatu_prati(text: &str) -> Pratipadika { #[test] fn sutra_1_4_3() { // IkArAnta - assert_has_subantas_p(&nyap("kumArI"), Stri, Prathama, Eka, &["kumArI"]); - assert_has_subantas_p(&nyap("gOrI"), Stri, Prathama, Eka, &["gOrI"]); - assert_has_subantas("lakzmI", Stri, Prathama, Eka, &["lakzmIH"]); - assert_has_subantas_p(&nyap("SArNgaravI"), Stri, Prathama, Eka, &["SArNgaravI"]); + assert_has_sup_1s(&nyap("kumArI"), Stri, &["kumArI"]); + assert_has_sup_1s(&nyap("gOrI"), Stri, &["gOrI"]); + assert_has_sup_1s("lakzmI", Stri, &["lakzmIH"]); + assert_has_sup_1s(&nyap("SArNgaravI"), Stri, &["SArNgaravI"]); // UkArAnta - assert_has_subantas("brahmabanDU", Stri, Prathama, Eka, &["brahmabanDUH"]); - assert_has_subantas("yavagU", Stri, Prathama, Eka, &["yavagUH"]); + assert_has_sup_1s("brahmabanDU", Stri, &["brahmabanDUH"]); + assert_has_sup_1s("yavagU", Stri, &["yavagUH"]); // yU? - assert_has_subantas("mAtf", Stri, Caturthi, Eka, &["mAtre"]); - assert_has_subantas("duhitf", Stri, Caturthi, Eka, &["duhitre"]); + assert_has_sup_4s("mAtf", Stri, &["mAtre"]); + assert_has_sup_4s("duhitf", Stri, &["duhitre"]); // stryAKyO - assert_has_subantas("grAmaRI", Pum, Prathama, Eka, &["grAmaRIH"]); - assert_has_subantas("senAnI", Pum, Prathama, Eka, &["senAnIH"]); - assert_has_subantas("KalapU", Pum, Prathama, Eka, &["KalapUH"]); + assert_has_sup_1s("grAmaRI", Pum, &["grAmaRIH"]); + assert_has_sup_1s("senAnI", Pum, &["senAnIH"]); + assert_has_sup_1s("KalapU", Pum, &["KalapUH"]); } #[test] @@ -42,61 +40,55 @@ fn sutra_1_4_4() { .is_dhatu(true) .build() .unwrap(); - assert_has_subantas_p(&shri, Stri, Sambodhana, Eka, &["SrIH"]); - assert_has_subantas("BrU", Stri, Sambodhana, Eka, &["BrUH"]); + assert_has_sup_ss(&shri, Stri, &["SrIH"]); + assert_has_sup_ss("BrU", Stri, &["BrUH"]); // astrI - assert_has_subantas("strI", Stri, Sambodhana, Eka, &["stri"]); + assert_has_sup_ss("strI", Stri, &["stri"]); } #[test] fn sutra_1_4_5() { let shri = dhatu_prati("SrI"); - assert_has_subantas_p(&shri, Stri, Sasthi, Bahu, &["SriyAm", "SrIRAm"]); - assert_has_subantas("BrU", Stri, Sasthi, Bahu, &["BruvAm", "BrURAm"]); + assert_has_sup_6p(&shri, Stri, &["SriyAm", "SrIRAm"]); + assert_has_sup_6p("BrU", Stri, &["BruvAm", "BrURAm"]); // astrI - assert_has_subantas("strI", Stri, Sasthi, Bahu, &["strIRAm"]); + assert_has_sup_6p("strI", Stri, &["strIRAm"]); } #[test] fn sutra_1_4_6() { - assert_has_subantas("kfti", Stri, Caturthi, Eka, &["kftyE", "kftaye"]); - assert_has_subantas("Denu", Stri, Caturthi, Eka, &["DenvE", "Denave"]); - assert_has_subantas_p( - &dhatu_prati("SrI"), - Stri, - Caturthi, - Eka, - &["SriyE", "Sriye"], - ); - assert_has_subantas("BrU", Stri, Caturthi, Eka, &["BruvE", "Bruve"]); + assert_has_sup_4s("kfti", Stri, &["kftyE", "kftaye"]); + assert_has_sup_4s("Denu", Stri, &["DenvE", "Denave"]); + assert_has_sup_4s(&dhatu_prati("SrI"), Stri, &["SriyE", "Sriye"]); + assert_has_sup_4s("BrU", Stri, &["BruvE", "Bruve"]); // astrI - assert_has_subantas("strI", Stri, Caturthi, Eka, &["striyE"]); + assert_has_sup_4s("strI", Stri, &["striyE"]); // stryAKyO - assert_has_subantas("agni", Pum, Caturthi, Eka, &["agnaye"]); - assert_has_subantas("vAyu", Pum, Caturthi, Eka, &["vAyave"]); - assert_has_subantas("Banu", Pum, Caturthi, Eka, &["Banave"]); + assert_has_sup_4s("agni", Pum, &["agnaye"]); + assert_has_sup_4s("vAyu", Pum, &["vAyave"]); + assert_has_sup_4s("Banu", Pum, &["Banave"]); } #[test] fn sutra_1_4_7() { - assert_has_subantas("agni", Pum, Caturthi, Eka, &["agnaye"]); - assert_has_subantas("vAyu", Pum, Caturthi, Eka, &["vAyave"]); - assert_has_subantas("kfti", Stri, Caturthi, Eka, &["kftyE", "kftaye"]); - assert_has_subantas("Denu", Stri, Caturthi, Eka, &["DenvE", "Denave"]); + assert_has_sup_4s("agni", Pum, &["agnaye"]); + assert_has_sup_4s("vAyu", Pum, &["vAyave"]); + assert_has_sup_4s("kfti", Stri, &["kftyE", "kftaye"]); + assert_has_sup_4s("Denu", Stri, &["DenvE", "Denave"]); // asaKi - assert_has_subantas("saKi", Pum, Trtiya, Eka, &["saKyA"]); - assert_has_subantas("saKi", Pum, Caturthi, Eka, &["saKye"]); - assert_has_subantas("saKi", Pum, Panchami, Eka, &["saKyuH"]); - assert_has_subantas("saKi", Pum, Saptami, Eka, &["saKyO"]); + assert_has_sup_3s("saKi", Pum, &["saKyA"]); + assert_has_sup_4s("saKi", Pum, &["saKye"]); + assert_has_sup_5s("saKi", Pum, &["saKyuH"]); + assert_has_sup_7s("saKi", Pum, &["saKyO"]); } #[test] fn sutra_1_4_8() { - assert_has_subantas("pati", Pum, Trtiya, Eka, &["patyA"]); - assert_has_subantas("pati", Pum, Caturthi, Eka, &["patye"]); - assert_has_subantas("pati", Pum, Panchami, Eka, &["patyuH"]); - assert_has_subantas("pati", Pum, Sasthi, Eka, &["patyuH"]); - assert_has_subantas("pati", Pum, Saptami, Eka, &["patyO"]); + assert_has_sup_3s("pati", Pum, &["patyA"]); + assert_has_sup_4s("pati", Pum, &["patye"]); + assert_has_sup_5s("pati", Pum, &["patyuH"]); + assert_has_sup_6s("pati", Pum, &["patyuH"]); + assert_has_sup_7s("pati", Pum, &["patyO"]); // TODO: test when in samasa. } @@ -134,13 +126,13 @@ fn sutra_1_4_13() { assert_has_vas(&[], &kf, Lrt, &["karizyAvaH"]); assert_has_mas(&[], &kf, Lrt, &["karizyAmaH"]); - assert_has_subantas("kuRqa", Napumsaka, Prathama, Bahu, &["kuRqAni"]); + assert_has_sup_1p("kuRqa", Napumsaka, &["kuRqAni"]); // TODO: others; } #[test] fn sutra_1_4_14() { - assert_has_subantas("brAhmaRa", Pum, Prathama, Bahu, &["brAhmaRAH"]); + assert_has_sup_1p("brAhmaRa", Pum, &["brAhmaRAH"]); } #[test] @@ -162,17 +154,17 @@ fn sutra_1_4_19() { #[test] fn sutra_1_4_21() { - assert_has_subantas("brAhmaRa", Pum, Prathama, Bahu, &["brAhmaRAH"]); + assert_has_sup_1p("brAhmaRa", Pum, &["brAhmaRAH"]); assert_has_jhi(&[], &d("paWa~", Bhvadi), Lat, &["paWanti"]); } #[test] fn sutra_1_4_22() { let path = d("paWa~", Bhvadi); - assert_has_subantas("brAhmaRa", Pum, Prathama, Dvi, &["brAhmaRO"]); + assert_has_sup_1d("brAhmaRa", Pum, &["brAhmaRO"]); assert_has_tas(&[], &path, Lat, &["paWataH"]); - assert_has_subantas("brAhmaRa", Pum, Prathama, Eka, &["brAhmaRaH"]); + assert_has_sup_1s("brAhmaRa", Pum, &["brAhmaRaH"]); assert_has_tip(&[], &path, Lat, &["paWati"]); } diff --git a/vidyut-prakriya/tests/kashika_2_3.rs b/vidyut-prakriya/tests/kashika_2_3.rs index 067adaf..8bd9f2c 100644 --- a/vidyut-prakriya/tests/kashika_2_3.rs +++ b/vidyut-prakriya/tests/kashika_2_3.rs @@ -1,44 +1,42 @@ extern crate test_utils; use test_utils::*; use vidyut_prakriya::args::Linga::*; -use vidyut_prakriya::args::Vacana::*; -use vidyut_prakriya::args::Vibhakti::*; #[test] fn sutra_2_3_28() { - assert_has_subantas("vfka", Pum, Panchami, Bahu, &["vfkeByaH"]); - assert_has_subantas("aDyayana", Napumsaka, Panchami, Eka, &["aDyayanAt"]); + assert_has_sup_5p("vfka", Pum, &["vfkeByaH"]); + assert_has_sup_5s("aDyayana", Napumsaka, &["aDyayanAt"]); // lyap-lopa - assert_has_subantas("prAsAda", Napumsaka, Panchami, Eka, &["prAsAdAt"]); + assert_has_sup_5s("prAsAda", Napumsaka, &["prAsAdAt"]); // adhikarana - assert_has_subantas("Asana", Napumsaka, Panchami, Eka, &["AsanAt"]); - assert_has_subantas("Sayana", Napumsaka, Panchami, Eka, &["SayanAt"]); + assert_has_sup_5s("Asana", Napumsaka, &["AsanAt"]); + assert_has_sup_5s("Sayana", Napumsaka, &["SayanAt"]); // prashna - assert_has_subantas("pAwaliputra", Napumsaka, Panchami, Eka, &["pAwaliputrAt"]); + assert_has_sup_5s("pAwaliputra", Napumsaka, &["pAwaliputrAt"]); // TODO: tas-pratyaya } #[test] fn sutra_2_3_30() { - assert_has_subantas("grAma", Pum, Panchami, Eka, &["grAmAt"]); + assert_has_sup_5s("grAma", Pum, &["grAmAt"]); } #[test] fn sutra_2_3_47() { - assert_has_subantas("devadatta", Pum, Sambodhana, Eka, &["devadatta"]); - assert_has_subantas("devadatta", Pum, Sambodhana, Dvi, &["devadattO"]); - assert_has_subantas("devadatta", Pum, Sambodhana, Bahu, &["devadattAH"]); + assert_has_sup_ss("devadatta", Pum, &["devadatta"]); + assert_has_sup_sd("devadatta", Pum, &["devadattO"]); + assert_has_sup_sp("devadatta", Pum, &["devadattAH"]); } #[test] fn sutra_2_3_49() { - assert_has_subantas("pawu", Pum, Sambodhana, Eka, &["pawo"]); - assert_has_subantas("devadatta", Pum, Sambodhana, Eka, &["devadatta"]); + assert_has_sup_ss("pawu", Pum, &["pawo"]); + assert_has_sup_ss("devadatta", Pum, &["devadatta"]); } #[test] fn sutra_2_3_50() { - assert_has_subantas("rAjan", Pum, Sasthi, Eka, &["rAjYaH"]); - assert_has_subantas("paSu", Pum, Sasthi, Eka, &["paSoH"]); - assert_has_subantas("pitf", Pum, Sasthi, Eka, &["pituH"]); + assert_has_sup_6s("rAjan", Pum, &["rAjYaH"]); + assert_has_sup_6s("paSu", Pum, &["paSoH"]); + assert_has_sup_6s("pitf", Pum, &["pituH"]); } diff --git a/vidyut-prakriya/tests/kashika_3_2.rs b/vidyut-prakriya/tests/kashika_3_2.rs index 367f63d..afa0706 100644 --- a/vidyut-prakriya/tests/kashika_3_2.rs +++ b/vidyut-prakriya/tests/kashika_3_2.rs @@ -64,10 +64,9 @@ fn sutra_3_2_4() { #[test] fn sutra_3_2_5() { let mfj = d("mfjU~", Adadi); - let _nud = d("Ru\\da~^", Tudadi); + let nud = d("Ru\\da~^", Tudadi); assert_has_upapada_krdanta("tunda", &["pari"], &mfj, Krt::ka, &["tundaparimfja"]); - // TODO: fix sandhi - // assert_has_upapada_krdanta("Soka", &["apa"], &nud, Krt::ka, &["SokApanuda"]); + assert_has_upapada_krdanta("Soka", &["apa"], &nud, Krt::ka, &["SokApanuda"]); } #[test] diff --git a/vidyut-prakriya/tests/kashika_3_4.rs b/vidyut-prakriya/tests/kashika_3_4.rs index 264c53e..efd706d 100644 --- a/vidyut-prakriya/tests/kashika_3_4.rs +++ b/vidyut-prakriya/tests/kashika_3_4.rs @@ -5,8 +5,6 @@ use vidyut_prakriya::args::Lakara::*; use vidyut_prakriya::args::Linga::*; use vidyut_prakriya::args::Taddhita as T; use vidyut_prakriya::args::Upapada; -use vidyut_prakriya::args::Vacana::*; -use vidyut_prakriya::args::Vibhakti as V; use vidyut_prakriya::args::*; #[test] @@ -394,8 +392,8 @@ fn sutra_3_4_114() { // DAtoH assert_has_taddhitanta(&prati("vfkza"), T::tva, &["vfkzatva"]); assert_has_taddhitanta(&prati("vfkza"), T::tal, &["vfkzatA"]); - assert_has_subantas("lU", Pum, V::Trtiya, Dvi, &["lUByAm"]); - assert_has_subantas("lU", Pum, V::Trtiya, Bahu, &["lUBiH"]); + assert_has_sup_3d("lU", Pum, &["lUByAm"]); + assert_has_sup_3p("lU", Pum, &["lUBiH"]); assert_has_lat(&[], &d("gupa~\\", Bhvadi), &["jugupsate"]); } diff --git a/vidyut-prakriya/tests/kashika_4_1.rs b/vidyut-prakriya/tests/kashika_4_1.rs index 3ae77b8..075b0fc 100644 --- a/vidyut-prakriya/tests/kashika_4_1.rs +++ b/vidyut-prakriya/tests/kashika_4_1.rs @@ -3,16 +3,14 @@ use test_utils::*; use vidyut_prakriya::args::Linga::*; use vidyut_prakriya::args::Taddhita as T; use vidyut_prakriya::args::TaddhitaArtha::*; -use vidyut_prakriya::args::Vacana::*; -use vidyut_prakriya::args::Vibhakti::*; use vidyut_prakriya::args::*; fn assert_has_pum(prati: &str, expected: &[&str]) { - assert_has_subantas(prati, Pum, Prathama, Eka, expected); + assert_has_sup_1s(prati, Pum, expected); } fn assert_has_stri(prati: &str, expected: &[&str]) { - assert_has_subantas(prati, Stri, Prathama, Eka, expected); + assert_has_sup_1s(prati, Stri, expected); } fn assert_blocked(text: &str, artha: TaddhitaArtha, t: T) { @@ -23,170 +21,170 @@ fn assert_blocked(text: &str, artha: TaddhitaArtha, t: T) { fn sutra_4_1_2() { // NIp let kumari = nyap("kumArI"); - assert_has_subantas_p(&kumari, Stri, Prathama, Eka, &["kumArI"]); - assert_has_subantas_p(&kumari, Stri, Prathama, Dvi, &["kumAryO"]); - assert_has_subantas_p(&kumari, Stri, Prathama, Bahu, &["kumAryaH"]); - assert_has_subantas_p(&kumari, Stri, Dvitiya, Eka, &["kumArIm"]); - assert_has_subantas_p(&kumari, Stri, Dvitiya, Dvi, &["kumAryO"]); - assert_has_subantas_p(&kumari, Stri, Dvitiya, Bahu, &["kumArIH"]); - assert_has_subantas_p(&kumari, Stri, Trtiya, Eka, &["kumAryA"]); - assert_has_subantas_p(&kumari, Stri, Trtiya, Dvi, &["kumArIByAm"]); - assert_has_subantas_p(&kumari, Stri, Trtiya, Bahu, &["kumArIBiH"]); - assert_has_subantas_p(&kumari, Stri, Caturthi, Eka, &["kumAryE"]); - assert_has_subantas_p(&kumari, Stri, Caturthi, Dvi, &["kumArIByAm"]); - assert_has_subantas_p(&kumari, Stri, Caturthi, Bahu, &["kumArIByaH"]); - assert_has_subantas_p(&kumari, Stri, Panchami, Eka, &["kumAryAH"]); - assert_has_subantas_p(&kumari, Stri, Panchami, Dvi, &["kumArIByAm"]); - assert_has_subantas_p(&kumari, Stri, Panchami, Bahu, &["kumArIByaH"]); - assert_has_subantas_p(&kumari, Stri, Sasthi, Eka, &["kumAryAH"]); - assert_has_subantas_p(&kumari, Stri, Sasthi, Dvi, &["kumAryoH"]); - assert_has_subantas_p(&kumari, Stri, Sasthi, Bahu, &["kumArIRAm"]); - assert_has_subantas_p(&kumari, Stri, Saptami, Eka, &["kumAryAm"]); - assert_has_subantas_p(&kumari, Stri, Saptami, Dvi, &["kumAryoH"]); - assert_has_subantas_p(&kumari, Stri, Saptami, Bahu, &["kumArIzu"]); + assert_has_sup_1s(&kumari, Stri, &["kumArI"]); + assert_has_sup_1d(&kumari, Stri, &["kumAryO"]); + assert_has_sup_1p(&kumari, Stri, &["kumAryaH"]); + assert_has_sup_2s(&kumari, Stri, &["kumArIm"]); + assert_has_sup_2d(&kumari, Stri, &["kumAryO"]); + assert_has_sup_2p(&kumari, Stri, &["kumArIH"]); + assert_has_sup_3s(&kumari, Stri, &["kumAryA"]); + assert_has_sup_3d(&kumari, Stri, &["kumArIByAm"]); + assert_has_sup_3p(&kumari, Stri, &["kumArIBiH"]); + assert_has_sup_4s(&kumari, Stri, &["kumAryE"]); + assert_has_sup_4d(&kumari, Stri, &["kumArIByAm"]); + assert_has_sup_4p(&kumari, Stri, &["kumArIByaH"]); + assert_has_sup_5s(&kumari, Stri, &["kumAryAH"]); + assert_has_sup_5d(&kumari, Stri, &["kumArIByAm"]); + assert_has_sup_5p(&kumari, Stri, &["kumArIByaH"]); + assert_has_sup_6s(&kumari, Stri, &["kumAryAH"]); + assert_has_sup_6d(&kumari, Stri, &["kumAryoH"]); + assert_has_sup_6p(&kumari, Stri, &["kumArIRAm"]); + assert_has_sup_7s(&kumari, Stri, &["kumAryAm"]); + assert_has_sup_7d(&kumari, Stri, &["kumAryoH"]); + assert_has_sup_7p(&kumari, Stri, &["kumArIzu"]); // NIz let gauri = nyap("gOrI"); - assert_has_subantas_p(&gauri, Stri, Prathama, Eka, &["gOrI"]); - assert_has_subantas_p(&gauri, Stri, Prathama, Dvi, &["gOryO"]); - assert_has_subantas_p(&gauri, Stri, Prathama, Bahu, &["gOryaH"]); - assert_has_subantas_p(&gauri, Stri, Dvitiya, Eka, &["gOrIm"]); - assert_has_subantas_p(&gauri, Stri, Dvitiya, Dvi, &["gOryO"]); - assert_has_subantas_p(&gauri, Stri, Dvitiya, Bahu, &["gOrIH"]); - assert_has_subantas_p(&gauri, Stri, Trtiya, Eka, &["gOryA"]); - assert_has_subantas_p(&gauri, Stri, Trtiya, Dvi, &["gOrIByAm"]); - assert_has_subantas_p(&gauri, Stri, Trtiya, Bahu, &["gOrIBiH"]); - assert_has_subantas_p(&gauri, Stri, Caturthi, Eka, &["gOryE"]); - assert_has_subantas_p(&gauri, Stri, Caturthi, Dvi, &["gOrIByAm"]); - assert_has_subantas_p(&gauri, Stri, Caturthi, Bahu, &["gOrIByaH"]); - assert_has_subantas_p(&gauri, Stri, Panchami, Eka, &["gOryAH"]); - assert_has_subantas_p(&gauri, Stri, Panchami, Dvi, &["gOrIByAm"]); - assert_has_subantas_p(&gauri, Stri, Panchami, Bahu, &["gOrIByaH"]); - assert_has_subantas_p(&gauri, Stri, Sasthi, Eka, &["gOryAH"]); - assert_has_subantas_p(&gauri, Stri, Sasthi, Dvi, &["gOryoH"]); - assert_has_subantas_p(&gauri, Stri, Sasthi, Bahu, &["gOrIRAm"]); - assert_has_subantas_p(&gauri, Stri, Saptami, Eka, &["gOryAm"]); - assert_has_subantas_p(&gauri, Stri, Saptami, Dvi, &["gOryoH"]); - assert_has_subantas_p(&gauri, Stri, Saptami, Bahu, &["gOrIzu"]); + assert_has_sup_1s(&gauri, Stri, &["gOrI"]); + assert_has_sup_1d(&gauri, Stri, &["gOryO"]); + assert_has_sup_1p(&gauri, Stri, &["gOryaH"]); + assert_has_sup_2s(&gauri, Stri, &["gOrIm"]); + assert_has_sup_2d(&gauri, Stri, &["gOryO"]); + assert_has_sup_2p(&gauri, Stri, &["gOrIH"]); + assert_has_sup_3s(&gauri, Stri, &["gOryA"]); + assert_has_sup_3d(&gauri, Stri, &["gOrIByAm"]); + assert_has_sup_3p(&gauri, Stri, &["gOrIBiH"]); + assert_has_sup_4s(&gauri, Stri, &["gOryE"]); + assert_has_sup_4d(&gauri, Stri, &["gOrIByAm"]); + assert_has_sup_4p(&gauri, Stri, &["gOrIByaH"]); + assert_has_sup_5s(&gauri, Stri, &["gOryAH"]); + assert_has_sup_5d(&gauri, Stri, &["gOrIByAm"]); + assert_has_sup_5p(&gauri, Stri, &["gOrIByaH"]); + assert_has_sup_6s(&gauri, Stri, &["gOryAH"]); + assert_has_sup_6d(&gauri, Stri, &["gOryoH"]); + assert_has_sup_6p(&gauri, Stri, &["gOrIRAm"]); + assert_has_sup_7s(&gauri, Stri, &["gOryAm"]); + assert_has_sup_7d(&gauri, Stri, &["gOryoH"]); + assert_has_sup_7p(&gauri, Stri, &["gOrIzu"]); // NIn let sharngaravi = nyap("SArNgaravI"); - assert_has_subantas_p(&sharngaravi, Stri, Prathama, Eka, &["SArNgaravI"]); - assert_has_subantas_p(&sharngaravi, Stri, Prathama, Dvi, &["SArNgaravyO"]); - assert_has_subantas_p(&sharngaravi, Stri, Prathama, Bahu, &["SArNgaravyaH"]); - assert_has_subantas_p(&sharngaravi, Stri, Dvitiya, Eka, &["SArNgaravIm"]); - assert_has_subantas_p(&sharngaravi, Stri, Dvitiya, Dvi, &["SArNgaravyO"]); - assert_has_subantas_p(&sharngaravi, Stri, Dvitiya, Bahu, &["SArNgaravIH"]); - assert_has_subantas_p(&sharngaravi, Stri, Trtiya, Eka, &["SArNgaravyA"]); - assert_has_subantas_p(&sharngaravi, Stri, Trtiya, Dvi, &["SArNgaravIByAm"]); - assert_has_subantas_p(&sharngaravi, Stri, Trtiya, Bahu, &["SArNgaravIBiH"]); - assert_has_subantas_p(&sharngaravi, Stri, Caturthi, Eka, &["SArNgaravyE"]); - assert_has_subantas_p(&sharngaravi, Stri, Caturthi, Dvi, &["SArNgaravIByAm"]); - assert_has_subantas_p(&sharngaravi, Stri, Caturthi, Bahu, &["SArNgaravIByaH"]); - assert_has_subantas_p(&sharngaravi, Stri, Panchami, Eka, &["SArNgaravyAH"]); - assert_has_subantas_p(&sharngaravi, Stri, Panchami, Dvi, &["SArNgaravIByAm"]); - assert_has_subantas_p(&sharngaravi, Stri, Panchami, Bahu, &["SArNgaravIByaH"]); - assert_has_subantas_p(&sharngaravi, Stri, Sasthi, Eka, &["SArNgaravyAH"]); - assert_has_subantas_p(&sharngaravi, Stri, Sasthi, Dvi, &["SArNgaravyoH"]); - assert_has_subantas_p(&sharngaravi, Stri, Sasthi, Bahu, &["SArNgaravIRAm"]); - assert_has_subantas_p(&sharngaravi, Stri, Saptami, Eka, &["SArNgaravyAm"]); - assert_has_subantas_p(&sharngaravi, Stri, Saptami, Dvi, &["SArNgaravyoH"]); - assert_has_subantas_p(&sharngaravi, Stri, Saptami, Bahu, &["SArNgaravIzu"]); + assert_has_sup_1s(&sharngaravi, Stri, &["SArNgaravI"]); + assert_has_sup_1d(&sharngaravi, Stri, &["SArNgaravyO"]); + assert_has_sup_1p(&sharngaravi, Stri, &["SArNgaravyaH"]); + assert_has_sup_2s(&sharngaravi, Stri, &["SArNgaravIm"]); + assert_has_sup_2d(&sharngaravi, Stri, &["SArNgaravyO"]); + assert_has_sup_2p(&sharngaravi, Stri, &["SArNgaravIH"]); + assert_has_sup_3s(&sharngaravi, Stri, &["SArNgaravyA"]); + assert_has_sup_3d(&sharngaravi, Stri, &["SArNgaravIByAm"]); + assert_has_sup_3p(&sharngaravi, Stri, &["SArNgaravIBiH"]); + assert_has_sup_4s(&sharngaravi, Stri, &["SArNgaravyE"]); + assert_has_sup_4d(&sharngaravi, Stri, &["SArNgaravIByAm"]); + assert_has_sup_4p(&sharngaravi, Stri, &["SArNgaravIByaH"]); + assert_has_sup_5s(&sharngaravi, Stri, &["SArNgaravyAH"]); + assert_has_sup_5d(&sharngaravi, Stri, &["SArNgaravIByAm"]); + assert_has_sup_5p(&sharngaravi, Stri, &["SArNgaravIByaH"]); + assert_has_sup_6s(&sharngaravi, Stri, &["SArNgaravyAH"]); + assert_has_sup_6d(&sharngaravi, Stri, &["SArNgaravyoH"]); + assert_has_sup_6p(&sharngaravi, Stri, &["SArNgaravIRAm"]); + assert_has_sup_7s(&sharngaravi, Stri, &["SArNgaravyAm"]); + assert_has_sup_7d(&sharngaravi, Stri, &["SArNgaravyoH"]); + assert_has_sup_7p(&sharngaravi, Stri, &["SArNgaravIzu"]); // wAp let khatva = nyap("KawvA"); - assert_has_subantas_p(&khatva, Stri, Prathama, Eka, &["KawvA"]); - assert_has_subantas_p(&khatva, Stri, Prathama, Dvi, &["Kawve"]); - assert_has_subantas_p(&khatva, Stri, Prathama, Bahu, &["KawvAH"]); - assert_has_subantas_p(&khatva, Stri, Dvitiya, Eka, &["KawvAm"]); - assert_has_subantas_p(&khatva, Stri, Dvitiya, Dvi, &["Kawve"]); - assert_has_subantas_p(&khatva, Stri, Dvitiya, Bahu, &["KawvAH"]); - assert_has_subantas_p(&khatva, Stri, Trtiya, Eka, &["KawvayA"]); - assert_has_subantas_p(&khatva, Stri, Trtiya, Dvi, &["KawvAByAm"]); - assert_has_subantas_p(&khatva, Stri, Trtiya, Bahu, &["KawvABiH"]); - assert_has_subantas_p(&khatva, Stri, Caturthi, Eka, &["KawvAyE"]); - assert_has_subantas_p(&khatva, Stri, Caturthi, Dvi, &["KawvAByAm"]); - assert_has_subantas_p(&khatva, Stri, Caturthi, Bahu, &["KawvAByaH"]); - assert_has_subantas_p(&khatva, Stri, Panchami, Eka, &["KawvAyAH"]); - assert_has_subantas_p(&khatva, Stri, Panchami, Dvi, &["KawvAByAm"]); - assert_has_subantas_p(&khatva, Stri, Panchami, Bahu, &["KawvAByaH"]); - assert_has_subantas_p(&khatva, Stri, Sasthi, Eka, &["KawvAyAH"]); - assert_has_subantas_p(&khatva, Stri, Sasthi, Dvi, &["KawvayoH"]); - assert_has_subantas_p(&khatva, Stri, Sasthi, Bahu, &["KawvAnAm"]); - assert_has_subantas_p(&khatva, Stri, Saptami, Eka, &["KawvAyAm"]); - assert_has_subantas_p(&khatva, Stri, Saptami, Dvi, &["KawvayoH"]); - assert_has_subantas_p(&khatva, Stri, Saptami, Bahu, &["KawvAsu"]); + assert_has_sup_1s(&khatva, Stri, &["KawvA"]); + assert_has_sup_1d(&khatva, Stri, &["Kawve"]); + assert_has_sup_1p(&khatva, Stri, &["KawvAH"]); + assert_has_sup_2s(&khatva, Stri, &["KawvAm"]); + assert_has_sup_2d(&khatva, Stri, &["Kawve"]); + assert_has_sup_2p(&khatva, Stri, &["KawvAH"]); + assert_has_sup_3s(&khatva, Stri, &["KawvayA"]); + assert_has_sup_3d(&khatva, Stri, &["KawvAByAm"]); + assert_has_sup_3p(&khatva, Stri, &["KawvABiH"]); + assert_has_sup_4s(&khatva, Stri, &["KawvAyE"]); + assert_has_sup_4d(&khatva, Stri, &["KawvAByAm"]); + assert_has_sup_4p(&khatva, Stri, &["KawvAByaH"]); + assert_has_sup_5s(&khatva, Stri, &["KawvAyAH"]); + assert_has_sup_5d(&khatva, Stri, &["KawvAByAm"]); + assert_has_sup_5p(&khatva, Stri, &["KawvAByaH"]); + assert_has_sup_6s(&khatva, Stri, &["KawvAyAH"]); + assert_has_sup_6d(&khatva, Stri, &["KawvayoH"]); + assert_has_sup_6p(&khatva, Stri, &["KawvAnAm"]); + assert_has_sup_7s(&khatva, Stri, &["KawvAyAm"]); + assert_has_sup_7d(&khatva, Stri, &["KawvayoH"]); + assert_has_sup_7p(&khatva, Stri, &["KawvAsu"]); // qAp let bahuraja = nyap("bahurAjA"); - assert_has_subantas_p(&bahuraja, Stri, Prathama, Eka, &["bahurAjA"]); - assert_has_subantas_p(&bahuraja, Stri, Prathama, Dvi, &["bahurAje"]); - assert_has_subantas_p(&bahuraja, Stri, Prathama, Bahu, &["bahurAjAH"]); - assert_has_subantas_p(&bahuraja, Stri, Dvitiya, Eka, &["bahurAjAm"]); - assert_has_subantas_p(&bahuraja, Stri, Dvitiya, Dvi, &["bahurAje"]); - assert_has_subantas_p(&bahuraja, Stri, Dvitiya, Bahu, &["bahurAjAH"]); - assert_has_subantas_p(&bahuraja, Stri, Trtiya, Eka, &["bahurAjayA"]); - assert_has_subantas_p(&bahuraja, Stri, Trtiya, Dvi, &["bahurAjAByAm"]); - assert_has_subantas_p(&bahuraja, Stri, Trtiya, Bahu, &["bahurAjABiH"]); - assert_has_subantas_p(&bahuraja, Stri, Caturthi, Eka, &["bahurAjAyE"]); - assert_has_subantas_p(&bahuraja, Stri, Caturthi, Dvi, &["bahurAjAByAm"]); - assert_has_subantas_p(&bahuraja, Stri, Caturthi, Bahu, &["bahurAjAByaH"]); - assert_has_subantas_p(&bahuraja, Stri, Panchami, Eka, &["bahurAjAyAH"]); - assert_has_subantas_p(&bahuraja, Stri, Panchami, Dvi, &["bahurAjAByAm"]); - assert_has_subantas_p(&bahuraja, Stri, Panchami, Bahu, &["bahurAjAByaH"]); - assert_has_subantas_p(&bahuraja, Stri, Sasthi, Eka, &["bahurAjAyAH"]); - assert_has_subantas_p(&bahuraja, Stri, Sasthi, Dvi, &["bahurAjayoH"]); - assert_has_subantas_p(&bahuraja, Stri, Sasthi, Bahu, &["bahurAjAnAm"]); - assert_has_subantas_p(&bahuraja, Stri, Saptami, Eka, &["bahurAjAyAm"]); - assert_has_subantas_p(&bahuraja, Stri, Saptami, Dvi, &["bahurAjayoH"]); - assert_has_subantas_p(&bahuraja, Stri, Saptami, Bahu, &["bahurAjAsu"]); + assert_has_sup_1s(&bahuraja, Stri, &["bahurAjA"]); + assert_has_sup_1d(&bahuraja, Stri, &["bahurAje"]); + assert_has_sup_1p(&bahuraja, Stri, &["bahurAjAH"]); + assert_has_sup_2s(&bahuraja, Stri, &["bahurAjAm"]); + assert_has_sup_2d(&bahuraja, Stri, &["bahurAje"]); + assert_has_sup_2p(&bahuraja, Stri, &["bahurAjAH"]); + assert_has_sup_3s(&bahuraja, Stri, &["bahurAjayA"]); + assert_has_sup_3d(&bahuraja, Stri, &["bahurAjAByAm"]); + assert_has_sup_3p(&bahuraja, Stri, &["bahurAjABiH"]); + assert_has_sup_4s(&bahuraja, Stri, &["bahurAjAyE"]); + assert_has_sup_4d(&bahuraja, Stri, &["bahurAjAByAm"]); + assert_has_sup_4p(&bahuraja, Stri, &["bahurAjAByaH"]); + assert_has_sup_5s(&bahuraja, Stri, &["bahurAjAyAH"]); + assert_has_sup_5d(&bahuraja, Stri, &["bahurAjAByAm"]); + assert_has_sup_5p(&bahuraja, Stri, &["bahurAjAByaH"]); + assert_has_sup_6s(&bahuraja, Stri, &["bahurAjAyAH"]); + assert_has_sup_6d(&bahuraja, Stri, &["bahurAjayoH"]); + assert_has_sup_6p(&bahuraja, Stri, &["bahurAjAnAm"]); + assert_has_sup_7s(&bahuraja, Stri, &["bahurAjAyAm"]); + assert_has_sup_7d(&bahuraja, Stri, &["bahurAjayoH"]); + assert_has_sup_7p(&bahuraja, Stri, &["bahurAjAsu"]); // cAp let karishagandhya = nyap("kArIzaganDyA"); - assert_has_subantas_p(&karishagandhya, Stri, Prathama, Eka, &["kArIzaganDyA"]); - assert_has_subantas_p(&karishagandhya, Stri, Prathama, Dvi, &["kArIzaganDye"]); - assert_has_subantas_p(&karishagandhya, Stri, Prathama, Bahu, &["kArIzaganDyAH"]); - assert_has_subantas_p(&karishagandhya, Stri, Dvitiya, Eka, &["kArIzaganDyAm"]); - assert_has_subantas_p(&karishagandhya, Stri, Dvitiya, Dvi, &["kArIzaganDye"]); - assert_has_subantas_p(&karishagandhya, Stri, Dvitiya, Bahu, &["kArIzaganDyAH"]); - assert_has_subantas_p(&karishagandhya, Stri, Trtiya, Eka, &["kArIzaganDyayA"]); - assert_has_subantas_p(&karishagandhya, Stri, Trtiya, Dvi, &["kArIzaganDyAByAm"]); - assert_has_subantas_p(&karishagandhya, Stri, Trtiya, Bahu, &["kArIzaganDyABiH"]); - assert_has_subantas_p(&karishagandhya, Stri, Caturthi, Eka, &["kArIzaganDyAyE"]); - assert_has_subantas_p(&karishagandhya, Stri, Caturthi, Dvi, &["kArIzaganDyAByAm"]); - assert_has_subantas_p(&karishagandhya, Stri, Caturthi, Bahu, &["kArIzaganDyAByaH"]); - assert_has_subantas_p(&karishagandhya, Stri, Panchami, Eka, &["kArIzaganDyAyAH"]); - assert_has_subantas_p(&karishagandhya, Stri, Panchami, Dvi, &["kArIzaganDyAByAm"]); - assert_has_subantas_p(&karishagandhya, Stri, Panchami, Bahu, &["kArIzaganDyAByaH"]); - assert_has_subantas_p(&karishagandhya, Stri, Sasthi, Eka, &["kArIzaganDyAyAH"]); - assert_has_subantas_p(&karishagandhya, Stri, Sasthi, Dvi, &["kArIzaganDyayoH"]); - assert_has_subantas_p(&karishagandhya, Stri, Sasthi, Bahu, &["kArIzaganDyAnAm"]); - assert_has_subantas_p(&karishagandhya, Stri, Saptami, Eka, &["kArIzaganDyAyAm"]); - assert_has_subantas_p(&karishagandhya, Stri, Saptami, Dvi, &["kArIzaganDyayoH"]); - assert_has_subantas_p(&karishagandhya, Stri, Saptami, Bahu, &["kArIzaganDyAsu"]); + assert_has_sup_1s(&karishagandhya, Stri, &["kArIzaganDyA"]); + assert_has_sup_1d(&karishagandhya, Stri, &["kArIzaganDye"]); + assert_has_sup_1p(&karishagandhya, Stri, &["kArIzaganDyAH"]); + assert_has_sup_2s(&karishagandhya, Stri, &["kArIzaganDyAm"]); + assert_has_sup_2d(&karishagandhya, Stri, &["kArIzaganDye"]); + assert_has_sup_2p(&karishagandhya, Stri, &["kArIzaganDyAH"]); + assert_has_sup_3s(&karishagandhya, Stri, &["kArIzaganDyayA"]); + assert_has_sup_3d(&karishagandhya, Stri, &["kArIzaganDyAByAm"]); + assert_has_sup_3p(&karishagandhya, Stri, &["kArIzaganDyABiH"]); + assert_has_sup_4s(&karishagandhya, Stri, &["kArIzaganDyAyE"]); + assert_has_sup_4d(&karishagandhya, Stri, &["kArIzaganDyAByAm"]); + assert_has_sup_4p(&karishagandhya, Stri, &["kArIzaganDyAByaH"]); + assert_has_sup_5s(&karishagandhya, Stri, &["kArIzaganDyAyAH"]); + assert_has_sup_5d(&karishagandhya, Stri, &["kArIzaganDyAByAm"]); + assert_has_sup_5p(&karishagandhya, Stri, &["kArIzaganDyAByaH"]); + assert_has_sup_6s(&karishagandhya, Stri, &["kArIzaganDyAyAH"]); + assert_has_sup_6d(&karishagandhya, Stri, &["kArIzaganDyayoH"]); + assert_has_sup_6p(&karishagandhya, Stri, &["kArIzaganDyAnAm"]); + assert_has_sup_7s(&karishagandhya, Stri, &["kArIzaganDyAyAm"]); + assert_has_sup_7d(&karishagandhya, Stri, &["kArIzaganDyayoH"]); + assert_has_sup_7p(&karishagandhya, Stri, &["kArIzaganDyAsu"]); let drshad = Pratipadika::new("dfzad"); - assert_has_subantas_p(&drshad, Pum, Prathama, Eka, &["dfzat"]); - assert_has_subantas_p(&drshad, Pum, Prathama, Dvi, &["dfzadO"]); - assert_has_subantas_p(&drshad, Pum, Prathama, Bahu, &["dfzadaH"]); - assert_has_subantas_p(&drshad, Pum, Dvitiya, Eka, &["dfzadam"]); - assert_has_subantas_p(&drshad, Pum, Dvitiya, Dvi, &["dfzadO"]); - assert_has_subantas_p(&drshad, Pum, Dvitiya, Bahu, &["dfzadaH"]); - assert_has_subantas_p(&drshad, Pum, Trtiya, Eka, &["dfzadA"]); - assert_has_subantas_p(&drshad, Pum, Trtiya, Dvi, &["dfzadByAm"]); - assert_has_subantas_p(&drshad, Pum, Trtiya, Bahu, &["dfzadBiH"]); - assert_has_subantas_p(&drshad, Pum, Caturthi, Eka, &["dfzade"]); - assert_has_subantas_p(&drshad, Pum, Caturthi, Dvi, &["dfzadByAm"]); - assert_has_subantas_p(&drshad, Pum, Caturthi, Bahu, &["dfzadByaH"]); - assert_has_subantas_p(&drshad, Pum, Panchami, Eka, &["dfzadaH"]); - assert_has_subantas_p(&drshad, Pum, Panchami, Dvi, &["dfzadByAm"]); - assert_has_subantas_p(&drshad, Pum, Panchami, Bahu, &["dfzadByaH"]); - assert_has_subantas_p(&drshad, Pum, Sasthi, Eka, &["dfzadaH"]); - assert_has_subantas_p(&drshad, Pum, Sasthi, Dvi, &["dfzadoH"]); - assert_has_subantas_p(&drshad, Pum, Sasthi, Bahu, &["dfzadAm"]); - assert_has_subantas_p(&drshad, Pum, Saptami, Eka, &["dfzadi"]); - assert_has_subantas_p(&drshad, Pum, Saptami, Dvi, &["dfzadoH"]); - assert_has_subantas_p(&drshad, Pum, Saptami, Bahu, &["dfzatsu"]); + assert_has_sup_1s(&drshad, Pum, &["dfzat"]); + assert_has_sup_1d(&drshad, Pum, &["dfzadO"]); + assert_has_sup_1p(&drshad, Pum, &["dfzadaH"]); + assert_has_sup_2s(&drshad, Pum, &["dfzadam"]); + assert_has_sup_2d(&drshad, Pum, &["dfzadO"]); + assert_has_sup_2p(&drshad, Pum, &["dfzadaH"]); + assert_has_sup_3s(&drshad, Pum, &["dfzadA"]); + assert_has_sup_3d(&drshad, Pum, &["dfzadByAm"]); + assert_has_sup_3p(&drshad, Pum, &["dfzadBiH"]); + assert_has_sup_4s(&drshad, Pum, &["dfzade"]); + assert_has_sup_4d(&drshad, Pum, &["dfzadByAm"]); + assert_has_sup_4p(&drshad, Pum, &["dfzadByaH"]); + assert_has_sup_5s(&drshad, Pum, &["dfzadaH"]); + assert_has_sup_5d(&drshad, Pum, &["dfzadByAm"]); + assert_has_sup_5p(&drshad, Pum, &["dfzadByaH"]); + assert_has_sup_6s(&drshad, Pum, &["dfzadaH"]); + assert_has_sup_6d(&drshad, Pum, &["dfzadoH"]); + assert_has_sup_6p(&drshad, Pum, &["dfzadAm"]); + assert_has_sup_7s(&drshad, Pum, &["dfzadi"]); + assert_has_sup_7d(&drshad, Pum, &["dfzadoH"]); + assert_has_sup_7p(&drshad, Pum, &["dfzatsu"]); } #[test] diff --git a/vidyut-prakriya/tests/kashika_6_1.rs b/vidyut-prakriya/tests/kashika_6_1.rs index b7f30bd..fc92e9e 100644 --- a/vidyut-prakriya/tests/kashika_6_1.rs +++ b/vidyut-prakriya/tests/kashika_6_1.rs @@ -6,7 +6,6 @@ use vidyut_prakriya::args::Linga::*; use vidyut_prakriya::args::Purusha::*; use vidyut_prakriya::args::Taddhita as T; use vidyut_prakriya::args::Vacana::*; -use vidyut_prakriya::args::Vibhakti as V; use vidyut_prakriya::args::*; #[test] @@ -612,13 +611,12 @@ fn sutra_6_1_59() { #[test] fn sutra_6_1_64() { - use Vibhakti::*; assert_has_lat(&[], &d("zaha~\\", Bhvadi), &["sahate"]); assert_has_lat_p(&[], &d("zi\\ca~^", Tudadi), &["siYcati"]); // DAtu? - // assert_has_subantas("zoqaSan", Pum, Prathama, Bahu, &["zoqaSa"]); - assert_has_subantas("zaRqa", Pum, Prathama, Eka, &["zaRqaH"]); - assert_has_subantas("zaqika", Pum, Prathama, Eka, &["zaqikaH"]); + // assert_has_sup_1p("zoqaSan", Pum, &["zoqaSa"]); + assert_has_sup_1s("zaRqa", Pum, &["zaRqaH"]); + assert_has_sup_1s("zaqika", Pum, &["zaqikaH"]); // AdeH? assert_has_lat(&[], &d("kaza~", Bhvadi), &["kazati"]); assert_has_lat_p(&[], &d("laza~^", Bhvadi), &["lazati", "lazyati"]); @@ -663,14 +661,14 @@ fn sutra_6_1_66() { #[test] fn sutra_6_1_69() { // eN - assert_has_subantas("agni", Pum, V::Sambodhana, Eka, &["agne"]); - assert_has_subantas("vAyu", Pum, V::Sambodhana, Eka, &["vAyo"]); + assert_has_sup_ss("agni", Pum, &["agne"]); + assert_has_sup_ss("vAyu", Pum, &["vAyo"]); // hrasva - assert_has_subantas("devadatta", Pum, V::Sambodhana, Eka, &["devadatta"]); - assert_has_subantas("nadI", Stri, V::Sambodhana, Eka, &["nadi"]); - assert_has_subantas("vaDU", Stri, V::Sambodhana, Eka, &["vaDu"]); - assert_has_subantas("kuRqa", Napumsaka, V::Sambodhana, Eka, &["kuRqa"]); - assert_has_subantas("katarat", Napumsaka, V::Sambodhana, Eka, &["katarat"]); + assert_has_sup_ss("devadatta", Pum, &["devadatta"]); + assert_has_sup_ss("nadI", Stri, &["nadi"]); + assert_has_sup_ss("vaDU", Stri, &["vaDu"]); + assert_has_sup_ss("kuRqa", Napumsaka, &["kuRqa"]); + assert_has_sup_ss("katarat", Napumsaka, &["katarat"]); } // saMhitAyAm ... @@ -714,8 +712,8 @@ fn sutra_6_1_79() { // TODO: vAntaH? // yi? - assert_has_subantas("go", Stri, V::Trtiya, Dvi, &["goByAm"]); - assert_has_subantas("nO", Stri, V::Trtiya, Dvi, &["nOByAm"]); + assert_has_sup_3d("go", Stri, &["goByAm"]); + assert_has_sup_3d("nO", Stri, &["nOByAm"]); // pratyaye? assert_has_sandhi("go", "yAnam", &["goyAnam"]); @@ -817,10 +815,10 @@ fn sutra_6_1_91() { #[test] fn sutra_6_1_93() { - assert_has_subantas("go", Stri, V::Dvitiya, Eka, &["gAm"]); - assert_has_subantas("go", Stri, V::Dvitiya, Bahu, &["gAH"]); - assert_has_subantas("dyo", Stri, V::Dvitiya, Eka, &["dyAm"]); - assert_has_subantas("dyo", Stri, V::Dvitiya, Bahu, &["dyAH"]); + assert_has_sup_2s("go", Stri, &["gAm"]); + assert_has_sup_2p("go", Stri, &["gAH"]); + assert_has_sup_2s("dyo", Stri, &["dyAm"]); + assert_has_sup_2p("dyo", Stri, &["dyAH"]); } #[test] @@ -874,7 +872,7 @@ fn sutra_6_1_101() { assert_has_sandhi("hotf", "fSayaH", &["hotFSayaH"]); // akaH? - assert_has_subantas("agni", Pum, V::Caturthi, Eka, &["agnaye"]); + assert_has_sup_4s("agni", Pum, &["agnaye"]); // savarne? assert_has_sandhi("daDi", "atra", &["daDyatra"]); @@ -885,64 +883,64 @@ fn sutra_6_1_101() { #[test] fn sutra_6_1_102() { - assert_has_subantas("agni", Pum, V::Prathama, Dvi, &["agnI"]); - assert_has_subantas("vAyu", Pum, V::Prathama, Dvi, &["vAyU"]); - assert_has_subantas("vfkza", Pum, V::Prathama, Bahu, &["vfkzAH"]); - assert_has_subantas("plakza", Pum, V::Prathama, Bahu, &["plakzAH"]); - assert_has_subantas("vfkza", Pum, V::Dvitiya, Bahu, &["vfkzAn"]); - assert_has_subantas("plakza", Pum, V::Dvitiya, Bahu, &["plakzAn"]); + assert_has_sup_1d("agni", Pum, &["agnI"]); + assert_has_sup_1d("vAyu", Pum, &["vAyU"]); + assert_has_sup_1p("vfkza", Pum, &["vfkzAH"]); + assert_has_sup_1p("plakza", Pum, &["plakzAH"]); + assert_has_sup_2p("vfkza", Pum, &["vfkzAn"]); + assert_has_sup_2p("plakza", Pum, &["plakzAn"]); } #[test] fn sutra_6_1_103() { - assert_has_subantas("vfkza", Pum, V::Dvitiya, Bahu, &["vfkzAn"]); - assert_has_subantas("agni", Pum, V::Dvitiya, Bahu, &["agnIn"]); - assert_has_subantas("vAyu", Pum, V::Dvitiya, Bahu, &["vAyUn"]); - assert_has_subantas("kartf", Pum, V::Dvitiya, Bahu, &["kartFn"]); - assert_has_subantas("hartf", Pum, V::Dvitiya, Bahu, &["hartFn"]); - assert_has_subantas("zaRqaka", Pum, V::Dvitiya, Bahu, &["zaRqakAn"]); - assert_has_subantas("zaRQaka", Pum, V::Dvitiya, Bahu, &["zaRQakAn"]); - assert_has_subantas("sTUra", Pum, V::Dvitiya, Bahu, &["sTUrAn"]); - assert_has_subantas("araka", Pum, V::Dvitiya, Bahu, &["arakAn"]); + assert_has_sup_2p("vfkza", Pum, &["vfkzAn"]); + assert_has_sup_2p("agni", Pum, &["agnIn"]); + assert_has_sup_2p("vAyu", Pum, &["vAyUn"]); + assert_has_sup_2p("kartf", Pum, &["kartFn"]); + assert_has_sup_2p("hartf", Pum, &["hartFn"]); + assert_has_sup_2p("zaRqaka", Pum, &["zaRqakAn"]); + assert_has_sup_2p("zaRQaka", Pum, &["zaRQakAn"]); + assert_has_sup_2p("sTUra", Pum, &["sTUrAn"]); + assert_has_sup_2p("araka", Pum, &["arakAn"]); // tasmAt - assert_has_subantas("go", Pum, V::Dvitiya, Bahu, &["gAH"]); + assert_has_sup_2p("go", Pum, &["gAH"]); // SazaH - assert_has_subantas("vfkza", Pum, V::Prathama, Bahu, &["vfkzAH"]); - assert_has_subantas("plakza", Pum, V::Prathama, Bahu, &["plakzAH"]); + assert_has_sup_1p("vfkza", Pum, &["vfkzAH"]); + assert_has_sup_1p("plakza", Pum, &["plakzAH"]); // puMsi - assert_has_subantas("Denu", Stri, V::Dvitiya, Bahu, &["DenUH"]); - assert_has_subantas("bahvI", Stri, V::Dvitiya, Bahu, &["bahvIH"]); - assert_has_subantas("kumArI", Stri, V::Dvitiya, Bahu, &["kumArIH"]); + assert_has_sup_2p("Denu", Stri, &["DenUH"]); + assert_has_sup_2p("bahvI", Stri, &["bahvIH"]); + assert_has_sup_2p("kumArI", Stri, &["kumArIH"]); // TODO: caYca } #[test] fn sutra_6_1_104() { - assert_has_subantas("vfkza", Pum, V::Prathama, Dvi, &["vfkzO"]); - assert_has_subantas("plakza", Pum, V::Prathama, Dvi, &["plakzO"]); - assert_has_subantas_p(&nyap("KawvA"), Stri, V::Prathama, Dvi, &["Kawve"]); - assert_has_subantas_p(&nyap("kuRqA"), Stri, V::Prathama, Dvi, &["kuRqe"]); + assert_has_sup_1d("vfkza", Pum, &["vfkzO"]); + assert_has_sup_1d("plakza", Pum, &["plakzO"]); + assert_has_sup_1d(&nyap("KawvA"), Stri, &["Kawve"]); + assert_has_sup_1d(&nyap("kuRqA"), Stri, &["kuRqe"]); // At - assert_has_subantas("agni", Pum, V::Prathama, Dvi, &["agnI"]); + assert_has_sup_1d("agni", Pum, &["agnI"]); // ici - assert_has_subantas("vfkza", Pum, V::Prathama, Bahu, &["vfkzAH"]); + assert_has_sup_1p("vfkza", Pum, &["vfkzAH"]); } #[test] fn sutra_6_1_105() { - assert_has_subantas("kumArI", Stri, V::Prathama, Dvi, &["kumAryO"]); - assert_has_subantas("kumArI", Stri, V::Prathama, Bahu, &["kumAryaH"]); - assert_has_subantas("brahmabanDU", Stri, V::Prathama, Dvi, &["brahmabanDvO"]); - assert_has_subantas("brahmabanDU", Stri, V::Prathama, Bahu, &["brahmabanDvaH"]); + assert_has_sup_1d("kumArI", Stri, &["kumAryO"]); + assert_has_sup_1p("kumArI", Stri, &["kumAryaH"]); + assert_has_sup_1d("brahmabanDU", Stri, &["brahmabanDvO"]); + assert_has_sup_1p("brahmabanDU", Stri, &["brahmabanDvaH"]); } #[test] fn sutra_6_1_107() { - assert_has_subantas("vfkza", Pum, V::Dvitiya, Eka, &["vfkzam"]); - assert_has_subantas("plakza", Pum, V::Dvitiya, Eka, &["plakzam"]); - assert_has_subantas("agni", Pum, V::Dvitiya, Eka, &["agnim"]); - assert_has_subantas("vAyu", Pum, V::Dvitiya, Eka, &["vAyum"]); - assert_has_subantas("kumArI", Stri, V::Dvitiya, Eka, &["kumArIm"]); + assert_has_sup_2s("vfkza", Pum, &["vfkzam"]); + assert_has_sup_2s("plakza", Pum, &["plakzam"]); + assert_has_sup_2s("agni", Pum, &["agnim"]); + assert_has_sup_2s("vAyu", Pum, &["vAyum"]); + assert_has_sup_2s("kumArI", Stri, &["kumArIm"]); } #[test] @@ -975,24 +973,24 @@ fn sutra_6_1_109() { #[test] fn sutra_6_1_110() { - assert_has_subantas("agni", Pum, V::Panchami, Eka, &["agneH"]); - assert_has_subantas("vAyu", Pum, V::Panchami, Eka, &["vAyoH"]); - assert_has_subantas("agni", Pum, V::Sasthi, Eka, &["agneH"]); - assert_has_subantas("vAyu", Pum, V::Sasthi, Eka, &["vAyoH"]); + assert_has_sup_5s("agni", Pum, &["agneH"]); + assert_has_sup_5s("vAyu", Pum, &["vAyoH"]); + assert_has_sup_6s("agni", Pum, &["agneH"]); + assert_has_sup_6s("vAyu", Pum, &["vAyoH"]); } #[test] fn sutra_6_1_111() { - assert_has_subantas("hotf", Pum, V::Panchami, Eka, &["hotuH"]); - assert_has_subantas("hotf", Pum, V::Sasthi, Eka, &["hotuH"]); + assert_has_sup_5s("hotf", Pum, &["hotuH"]); + assert_has_sup_6s("hotf", Pum, &["hotuH"]); } #[test] fn sutra_6_1_112() { - assert_has_subantas("saKi", Pum, V::Panchami, Eka, &["saKyuH"]); - assert_has_subantas("saKi", Pum, V::Sasthi, Eka, &["saKyuH"]); - assert_has_subantas("pati", Pum, V::Panchami, Eka, &["patyuH"]); - assert_has_subantas("pati", Pum, V::Sasthi, Eka, &["patyuH"]); + assert_has_sup_5s("saKi", Pum, &["saKyuH"]); + assert_has_sup_6s("saKi", Pum, &["saKyuH"]); + assert_has_sup_5s("pati", Pum, &["patyuH"]); + assert_has_sup_6s("pati", Pum, &["patyuH"]); // TODO: others } diff --git a/vidyut-prakriya/tests/kashika_6_4.rs b/vidyut-prakriya/tests/kashika_6_4.rs index c50486c..abb64a4 100644 --- a/vidyut-prakriya/tests/kashika_6_4.rs +++ b/vidyut-prakriya/tests/kashika_6_4.rs @@ -6,17 +6,8 @@ use vidyut_prakriya::args::Linga::*; use vidyut_prakriya::args::Purusha::*; use vidyut_prakriya::args::Taddhita as T; use vidyut_prakriya::args::Vacana::*; -use vidyut_prakriya::args::Vibhakti as V; use vidyut_prakriya::args::*; -fn prati_dhatu(text: &str) -> Pratipadika { - Pratipadika::builder() - .text(text) - .is_dhatu(true) - .build() - .unwrap() -} - fn prati_udit(text: &str) -> Pratipadika { Pratipadika::builder() .text(text) @@ -31,8 +22,6 @@ fn assert_has_hi(prefixes: &[&str], d: &Dhatu, expected: &[&str]) { #[test] fn sutra_6_4_1() { - use Vibhakti::*; - // halaH assert_has_krdanta(&[], &d("hve\\Y", Bhvadi), Krt::kta, &["hUta"]); assert_has_krdanta(&[], &d("jyA\\", Kryadi), Krt::kta, &["jIna"]); @@ -43,30 +32,18 @@ fn sutra_6_4_1() { assert_has_krdanta(&["dur"], &ve, Krt::kta, &["duruta"]); // nAmi dIrgha - assert_has_subantas("agni", Pum, Sasthi, Bahu, &["agnInAm"]); - assert_has_subantas("vAyu", Pum, Sasthi, Bahu, &["vAyUnAm"]); + assert_has_sup_6p("agni", Pum, &["agnInAm"]); + assert_has_sup_6p("vAyu", Pum, &["vAyUnAm"]); // angasya? - assert_has_subantas("krimiRA", Stri, Dvitiya, Eka, &["krimiRAm"]); - assert_has_subantas("pAmanA", Stri, Dvitiya, Eka, &["pAmanAm"]); + assert_has_sup_2s("krimiRA", Stri, &["krimiRAm"]); + assert_has_sup_2s("pAmanA", Stri, &["pAmanAm"]); // ato bhisa ais - assert_has_subantas("vfkza", Pum, Trtiya, Bahu, &["vfkzEH"]); - assert_has_subantas("plakza", Pum, Trtiya, Bahu, &["plakzEH"]); + assert_has_sup_3p("vfkza", Pum, &["vfkzEH"]); + assert_has_sup_3p("plakza", Pum, &["plakzEH"]); // angasya - assert_has_subantas_p( - &nyap("brAhmaRaBissA"), - Stri, - Prathama, - Eka, - &["brAhmaRaBissA"], - ); - assert_has_subantas_p( - &nyap("odanaBissadA"), - Stri, - Prathama, - Eka, - &["odanaBissadA"], - ); + assert_has_sup_1s(&nyap("brAhmaRaBissA"), Stri, &["brAhmaRaBissA"]); + assert_has_sup_1s(&nyap("odanaBissadA"), Stri, &["odanaBissadA"]); } #[test] @@ -87,86 +64,79 @@ fn sutra_6_4_2() { #[test] fn sutra_6_4_3() { - use Vibhakti::*; - assert_has_subantas("agni", Pum, Sasthi, Bahu, &["agnInAm"]); - assert_has_subantas("vAyu", Pum, Sasthi, Bahu, &["vAyUnAm"]); - assert_has_subantas("kartf", Pum, Sasthi, Bahu, &["kartFRAm"]); - assert_has_subantas("hartf", Pum, Sasthi, Bahu, &["hartFRAm"]); + assert_has_sup_6p("agni", Pum, &["agnInAm"]); + assert_has_sup_6p("vAyu", Pum, &["vAyUnAm"]); + assert_has_sup_6p("kartf", Pum, &["kartFRAm"]); + assert_has_sup_6p("hartf", Pum, &["hartFRAm"]); } #[test] fn sutra_6_4_4() { - use Vibhakti::*; - assert_has_subantas("tisf", Stri, Sasthi, Bahu, &["tisfRAm"]); - assert_has_subantas("catasf", Stri, Sasthi, Bahu, &["catasfRAm"]); + assert_has_sup_6p("tisf", Stri, &["tisfRAm"]); + assert_has_sup_6p("catasf", Stri, &["catasfRAm"]); } #[test] fn sutra_6_4_6() { - use Vibhakti::*; - assert_has_subantas("nf", Pum, Sasthi, Bahu, &["nFRAm", "nfRAm"]); + assert_has_sup_6p("nf", Pum, &["nFRAm", "nfRAm"]); } #[test] fn sutra_6_4_7() { - use Vibhakti::*; - assert_has_subantas("paYcan", Pum, Sasthi, Bahu, &["paYcAnAm"]); - assert_has_subantas("saptan", Pum, Sasthi, Bahu, &["saptAnAm"]); - assert_has_subantas("navan", Pum, Sasthi, Bahu, &["navAnAm"]); - assert_has_subantas("daSan", Pum, Sasthi, Bahu, &["daSAnAm"]); + assert_has_sup_6p("paYcan", Pum, &["paYcAnAm"]); + assert_has_sup_6p("saptan", Pum, &["saptAnAm"]); + assert_has_sup_6p("navan", Pum, &["navAnAm"]); + assert_has_sup_6p("daSan", Pum, &["daSAnAm"]); // naH - assert_has_subantas("catur", Pum, Sasthi, Bahu, &["caturRAm"]); + assert_has_sup_6p("catur", Pum, &["caturRAm"]); // nAmi - assert_has_subantas("carman", Pum, Sasthi, Bahu, &["carmaRAm"]); + assert_has_sup_6p("carman", Pum, &["carmaRAm"]); } #[test] fn sutra_6_4_8() { - use Vibhakti::*; - assert_has_subantas("rAjan", Pum, Prathama, Eka, &["rAjA"]); - assert_has_subantas("rAjan", Pum, Prathama, Dvi, &["rAjAnO"]); - assert_has_subantas("rAjan", Pum, Prathama, Bahu, &["rAjAnaH"]); - assert_has_subantas("rAjan", Pum, Dvitiya, Eka, &["rAjAnam"]); - assert_has_subantas("rAjan", Pum, Dvitiya, Dvi, &["rAjAnO"]); - assert_has_subantas("sAman", Napumsaka, Prathama, Bahu, &["sAmAni"]); - assert_has_subantas("sAman", Napumsaka, Dvitiya, Bahu, &["sAmAni"]); + assert_has_sup_1s("rAjan", Pum, &["rAjA"]); + assert_has_sup_1d("rAjan", Pum, &["rAjAnO"]); + assert_has_sup_1p("rAjan", Pum, &["rAjAnaH"]); + assert_has_sup_2s("rAjan", Pum, &["rAjAnam"]); + assert_has_sup_2d("rAjan", Pum, &["rAjAnO"]); + assert_has_sup_1p("sAman", Napumsaka, &["sAmAni"]); + assert_has_sup_2p("sAman", Napumsaka, &["sAmAni"]); // sarvanAmasTAne - assert_has_subantas("rAjan", Pum, Saptami, Eka, &["rAjani", "rAjYi"]); - assert_has_subantas("sAman", Pum, Saptami, Eka, &["sAmani", "sAmni"]); + assert_has_sup_7s("rAjan", Pum, &["rAjani", "rAjYi"]); + assert_has_sup_7s("sAman", Pum, &["sAmani", "sAmni"]); // asambudDO - assert_has_subantas("rAjan", Pum, Sambodhana, Eka, &["rAjan"]); - assert_has_subantas("takzan", Pum, Sambodhana, Eka, &["takzan"]); + assert_has_sup_ss("rAjan", Pum, &["rAjan"]); + assert_has_sup_ss("takzan", Pum, &["takzan"]); } #[test] fn sutra_6_4_10() { - use Vibhakti::*; let shreyas = prati_udit("Sreyas"); - assert_has_subantas_p(&shreyas, Pum, Prathama, Eka, &["SreyAn"]); - assert_has_subantas_p(&shreyas, Pum, Prathama, Dvi, &["SreyAMsO"]); - assert_has_subantas_p(&shreyas, Pum, Prathama, Bahu, &["SreyAMsaH"]); - assert_has_subantas_p(&shreyas, Napumsaka, Prathama, Bahu, &["SreyAMsi"]); - assert_has_subantas("payas", Napumsaka, Prathama, Bahu, &["payAMsi"]); - assert_has_subantas("yaSas", Napumsaka, Prathama, Bahu, &["yaSAMsi"]); + assert_has_sup_1s(&shreyas, Pum, &["SreyAn"]); + assert_has_sup_1d(&shreyas, Pum, &["SreyAMsO"]); + assert_has_sup_1p(&shreyas, Pum, &["SreyAMsaH"]); + assert_has_sup_1p(&shreyas, Napumsaka, &["SreyAMsi"]); + assert_has_sup_1p("payas", Napumsaka, &["payAMsi"]); + assert_has_sup_1p("yaSas", Napumsaka, &["yaSAMsi"]); // mahat let mahat = prati_udit("mahat"); - assert_has_subantas_p(&mahat, Pum, Prathama, Eka, &["mahAn"]); - assert_has_subantas_p(&mahat, Pum, Prathama, Dvi, &["mahAntO"]); - assert_has_subantas_p(&mahat, Pum, Prathama, Bahu, &["mahAntaH"]); + assert_has_sup_1s(&mahat, Pum, &["mahAn"]); + assert_has_sup_1d(&mahat, Pum, &["mahAntO"]); + assert_has_sup_1p(&mahat, Pum, &["mahAntaH"]); // asambudDo - assert_has_subantas_p(&shreyas, Pum, Sambodhana, Eka, &["Sreyan"]); - assert_has_subantas_p(&mahat, Pum, Sambodhana, Eka, &["mahan"]); + assert_has_sup_ss(&shreyas, Pum, &["Sreyan"]); + assert_has_sup_ss(&mahat, Pum, &["mahan"]); } #[test] fn sutra_6_4_14() { - use Vibhakti::*; - assert_has_subantas_p(&prati_udit("Bavat"), Pum, Prathama, Eka, &["BavAn"]); - assert_has_subantas_p(&prati_udit("kftavat"), Pum, Prathama, Eka, &["kftavAn"]); - assert_has_subantas_p(&prati_udit("gomat"), Pum, Prathama, Eka, &["gomAn"]); - assert_has_subantas_p(&prati_udit("yavamat"), Pum, Prathama, Eka, &["yavamAn"]); - assert_has_subantas("suyaSas", Pum, Prathama, Eka, &["suyaSAH"]); - assert_has_subantas("suSrotas", Pum, Prathama, Eka, &["suSrotAH"]); + assert_has_sup_1s(&prati_udit("Bavat"), Pum, &["BavAn"]); + assert_has_sup_1s(&prati_udit("kftavat"), Pum, &["kftavAn"]); + assert_has_sup_1s(&prati_udit("gomat"), Pum, &["gomAn"]); + assert_has_sup_1s(&prati_udit("yavamat"), Pum, &["yavamAn"]); + assert_has_sup_1s("suyaSas", Pum, &["suyaSAH"]); + assert_has_sup_1s("suSrotas", Pum, &["suSrotAH"]); // TODO: others } @@ -280,16 +250,15 @@ fn sutra_6_4_21() { #[test] fn sutra_6_4_23() { - use Vibhakti::*; assert_has_lat(&[], &d("anjU~", Rudhadi), &["anakti"]); assert_has_lat(&[], &d("Ba\\njo~", Rudhadi), &["Banakti"]); assert_has_lat(&[], &d("hisi~", Rudhadi), &["hinasti"]); // TODO: make these proper tests and model the dhatu. - assert_has_subantas("yajYa", Pum, Sasthi, Bahu, &["yajYAnAm"]); - assert_has_subantas("yatna", Pum, Sasthi, Bahu, &["yatnAnAm"]); - assert_has_subantas("viSna", Pum, Sasthi, Bahu, &["viSnAnAm"]); - assert_has_subantas("praSna", Pum, Sasthi, Bahu, &["praSnAnAm"]); + assert_has_sup_6p("yajYa", Pum, &["yajYAnAm"]); + assert_has_sup_6p("yatna", Pum, &["yatnAnAm"]); + assert_has_sup_6p("viSna", Pum, &["viSnAnAm"]); + assert_has_sup_6p("praSna", Pum, &["praSnAnAm"]); } #[test] @@ -1016,16 +985,16 @@ fn sutra_6_4_78() { #[test] fn sutra_6_4_79() { let stri = nyap("strI"); - assert_has_subantas_p(&stri, Stri, V::Prathama, Eka, &["strI"]); - assert_has_subantas_p(&stri, Stri, V::Prathama, Dvi, &["striyO"]); - assert_has_subantas_p(&stri, Stri, V::Prathama, Bahu, &["striyaH"]); + assert_has_sup_1s(&stri, Stri, &["strI"]); + assert_has_sup_1d(&stri, Stri, &["striyO"]); + assert_has_sup_1p(&stri, Stri, &["striyaH"]); } #[test] fn sutra_6_4_80() { let stri = nyap("strI"); - assert_has_subantas_p(&stri, Stri, V::Dvitiya, Eka, &["strIm", "striyam"]); - assert_has_subantas_p(&stri, Stri, V::Dvitiya, Bahu, &["strIH", "striyaH"]); + assert_has_sup_2s(&stri, Stri, &["strIm", "striyam"]); + assert_has_sup_2p(&stri, Stri, &["strIH", "striyaH"]); } #[test] @@ -1041,19 +1010,19 @@ fn sutra_6_4_81() { #[ignore] #[test] fn sutra_6_4_83() { - assert_has_subantas("KalapU", Pum, V::Prathama, Dvi, &["KalapvO"]); - assert_has_subantas("KalapU", Pum, V::Prathama, Bahu, &["KalapvaH"]); - assert_has_subantas("SatasU", Pum, V::Prathama, Dvi, &["SatasvO"]); - assert_has_subantas("SatasU", Pum, V::Prathama, Bahu, &["SatasvaH"]); - assert_has_subantas("sakfllU", Pum, V::Prathama, Dvi, &["sakfllvO"]); - assert_has_subantas("sakfllU", Pum, V::Prathama, Bahu, &["sakfllvaH"]); + assert_has_sup_1d("KalapU", Pum, &["KalapvO"]); + assert_has_sup_1p("KalapU", Pum, &["KalapvaH"]); + assert_has_sup_1d("SatasU", Pum, &["SatasvO"]); + assert_has_sup_1p("SatasU", Pum, &["SatasvaH"]); + assert_has_sup_1d("sakfllU", Pum, &["sakfllvO"]); + assert_has_sup_1p("sakfllU", Pum, &["sakfllvaH"]); // supi let lu = d("lUY", Kryadi); assert_has_tas(&[], &lu, Lit, &["luluvatuH"]); assert_has_jhi(&[], &lu, Lit, &["luluvuH"]); // asaMyogapUrva - assert_has_subantas("kawaprU", Pum, V::Prathama, Dvi, &["kawapruvO"]); - assert_has_subantas("kawaprU", Pum, V::Prathama, Bahu, &["kawapruvaH"]); + assert_has_sup_1d("kawaprU", Pum, &["kawapruvO"]); + assert_has_sup_1p("kawaprU", Pum, &["kawapruvaH"]); // TODO: luvO, luvaH, etc. } @@ -1651,28 +1620,26 @@ fn sutra_6_4_126() { #[ignore] #[test] fn sutra_6_4_131() { - use V::*; - assert_has_subantas("vidvas", Pum, Sasthi, Eka, &["viduzaH"]); - assert_has_subantas("vidvas", Pum, Trtiya, Eka, &["viduzA"]); - assert_has_subantas("vidvas", Pum, Caturthi, Eka, &["viduze"]); - assert_has_subantas("pecivas", Pum, Sasthi, Eka, &["pecuzaH"]); - assert_has_subantas("pecivas", Pum, Trtiya, Eka, &["pecuzA"]); - assert_has_subantas("pecivas", Pum, Caturthi, Eka, &["pecuze"]); - assert_has_subantas("papivas", Pum, Sasthi, Eka, &["papuzaH"]); + assert_has_sup_6s("vidvas", Pum, &["viduzaH"]); + assert_has_sup_3s("vidvas", Pum, &["viduzA"]); + assert_has_sup_4s("vidvas", Pum, &["viduze"]); + assert_has_sup_6s("pecivas", Pum, &["pecuzaH"]); + assert_has_sup_3s("pecivas", Pum, &["pecuzA"]); + assert_has_sup_4s("pecivas", Pum, &["pecuze"]); + assert_has_sup_6s("papivas", Pum, &["papuzaH"]); } #[test] fn sutra_6_4_133() { - use V::*; - assert_has_subantas("Svan", Pum, Sasthi, Eka, &["SunaH"]); - assert_has_subantas("Svan", Pum, Trtiya, Eka, &["SunA"]); - assert_has_subantas("Svan", Pum, Caturthi, Eka, &["Sune"]); - assert_has_subantas("yuvan", Pum, Sasthi, Eka, &["yUnaH"]); - assert_has_subantas("yuvan", Pum, Trtiya, Eka, &["yUnA"]); - assert_has_subantas("yuvan", Pum, Caturthi, Eka, &["yUne"]); - assert_has_subantas("maGavan", Pum, Sasthi, Eka, &["maGonaH"]); - assert_has_subantas("maGavan", Pum, Trtiya, Eka, &["maGonA"]); - assert_has_subantas("maGavan", Pum, Caturthi, Eka, &["maGone"]); + assert_has_sup_6s("Svan", Pum, &["SunaH"]); + assert_has_sup_3s("Svan", Pum, &["SunA"]); + assert_has_sup_4s("Svan", Pum, &["Sune"]); + assert_has_sup_6s("yuvan", Pum, &["yUnaH"]); + assert_has_sup_3s("yuvan", Pum, &["yUnA"]); + assert_has_sup_4s("yuvan", Pum, &["yUne"]); + assert_has_sup_6s("maGavan", Pum, &["maGonaH"]); + assert_has_sup_3s("maGavan", Pum, &["maGonA"]); + assert_has_sup_4s("maGavan", Pum, &["maGone"]); // atadDite? assert_has_taddhitanta(&prati("Svan"), T::aY, &["SOva"]); @@ -1684,12 +1651,11 @@ fn sutra_6_4_133() { #[test] fn sutra_6_4_134() { - use V::*; - assert_has_subantas("rAjan", Pum, Sasthi, Eka, &["rAjYaH"]); - assert_has_subantas("rAjan", Pum, Trtiya, Eka, &["rAjYA"]); - assert_has_subantas("rAjan", Pum, Caturthi, Eka, &["rAjYe"]); - assert_has_subantas("takzan", Pum, Trtiya, Eka, &["takzRA"]); - assert_has_subantas("takzan", Pum, Caturthi, Eka, &["takzRe"]); + assert_has_sup_6s("rAjan", Pum, &["rAjYaH"]); + assert_has_sup_3s("rAjan", Pum, &["rAjYA"]); + assert_has_sup_4s("rAjan", Pum, &["rAjYe"]); + assert_has_sup_3s("takzan", Pum, &["takzRA"]); + assert_has_sup_4s("takzan", Pum, &["takzRe"]); } #[ignore] @@ -1705,52 +1671,49 @@ fn sutra_6_4_135() { #[test] fn sutra_6_4_136() { - use V::*; - assert_has_subantas("rAjan", Pum, Saptami, Eka, &["rAjYi", "rAjani"]); - assert_has_subantas("sAman", Napumsaka, Saptami, Eka, &["sAmni", "sAmani"]); - assert_has_subantas("sAman", Napumsaka, Prathama, Dvi, &["sAmnI", "sAmanI"]); + assert_has_sup_7s("rAjan", Pum, &["rAjYi", "rAjani"]); + assert_has_sup_7s("sAman", Napumsaka, &["sAmni", "sAmani"]); + assert_has_sup_1d("sAman", Napumsaka, &["sAmnI", "sAmanI"]); } #[test] fn sutra_6_4_137() { - use V::*; - assert_has_subantas("parvan", Pum, Trtiya, Eka, &["parvaRA"]); - assert_has_subantas("parvan", Pum, Caturthi, Eka, &["parvaRe"]); - assert_has_subantas("aTarvan", Pum, Trtiya, Eka, &["aTarvaRA"]); - assert_has_subantas("aTarvan", Pum, Caturthi, Eka, &["aTarvaRe"]); + assert_has_sup_3s("parvan", Pum, &["parvaRA"]); + assert_has_sup_4s("parvan", Pum, &["parvaRe"]); + assert_has_sup_3s("aTarvan", Pum, &["aTarvaRA"]); + assert_has_sup_4s("aTarvan", Pum, &["aTarvaRe"]); // saMyogAt? // TODO - // assert_has_subantas("pratidIvan", Napumsaka, Trtiya, Eka, &["pratidIvnA"]); - // assert_has_subantas("pratidIvan", Napumsaka, Caturthi, Eka, &["pratidIvne"]); - assert_has_subantas("sAman", Napumsaka, Trtiya, Eka, &["sAmnA"]); - assert_has_subantas("sAman", Napumsaka, Caturthi, Eka, &["sAmne"]); + // assert_has_sup_3s("pratidIvan", Napumsaka, &["pratidIvnA"]); + // assert_has_sup_4s("pratidIvan", Napumsaka, &["pratidIvne"]); + assert_has_sup_3s("sAman", Napumsaka, &["sAmnA"]); + assert_has_sup_4s("sAman", Napumsaka, &["sAmne"]); // vamAntAt? - assert_has_subantas("takzan", Pum, Trtiya, Eka, &["takzRA"]); - assert_has_subantas("takzan", Pum, Caturthi, Eka, &["takzRe"]); + assert_has_sup_3s("takzan", Pum, &["takzRA"]); + assert_has_sup_4s("takzan", Pum, &["takzRe"]); } #[test] fn sutra_6_4_140() { - use V::*; - let kilalapa = &prati_dhatu("kilAlapA"); - assert_has_subantas_p(&kilalapa, Pum, Dvitiya, Bahu, &["kilAlapaH"]); - assert_has_subantas_p(&kilalapa, Pum, Trtiya, Eka, &["kilAlapA"]); - assert_has_subantas_p(&kilalapa, Pum, Caturthi, Eka, &["kilAlape"]); - let shubhamya = &prati_dhatu("SuBaMyA"); - assert_has_subantas_p(&shubhamya, Pum, Dvitiya, Bahu, &["SuBaMyaH"]); - assert_has_subantas_p(&shubhamya, Pum, Trtiya, Eka, &["SuBaMyA"]); - assert_has_subantas_p(&shubhamya, Pum, Caturthi, Eka, &["SuBaMye"]); + let kilalapa = dhatu_prati("kilAlapA"); + assert_has_sup_2p(&kilalapa, Pum, &["kilAlapaH"]); + assert_has_sup_3s(&kilalapa, Pum, &["kilAlapA"]); + assert_has_sup_4s(&kilalapa, Pum, &["kilAlape"]); + let shubhamya = dhatu_prati("SuBaMyA"); + assert_has_sup_2p(&shubhamya, Pum, &["SuBaMyaH"]); + assert_has_sup_3s(&shubhamya, Pum, &["SuBaMyA"]); + assert_has_sup_4s(&shubhamya, Pum, &["SuBaMye"]); // AtaH? - let ni = &prati_dhatu("nI"); - assert_has_subantas_p(&ni, Pum, Trtiya, Eka, &["niyA"]); - assert_has_subantas_p(&ni, Pum, Caturthi, Eka, &["niye"]); + let ni = dhatu_prati("nI"); + assert_has_sup_3s(&ni, Pum, &["niyA"]); + assert_has_sup_4s(&ni, Pum, &["niye"]); // dhAtoH? - assert_has_subantas("KawvA", Stri, Dvitiya, Bahu, &["KawvAH"]); - assert_has_subantas("mAlA", Stri, Dvitiya, Bahu, &["mAlAH"]); + assert_has_sup_2p("KawvA", Stri, &["KawvAH"]); + assert_has_sup_2p("mAlA", Stri, &["mAlAH"]); } #[ignore] @@ -1760,7 +1723,7 @@ fn sutra_6_4_142() { // TODO: assert_has_taddhitanta(&prati("viMSati"), T::waq, &["viMSa"]); // qiti? - assert_has_subantas("viMSati", Pum, V::Trtiya, Eka, &["viMSatyA"]); + assert_has_sup_3s("viMSati", Pum, &["viMSatyA"]); } #[ignore] @@ -1775,14 +1738,13 @@ fn sutra_6_4_143() { #[test] fn sutra_6_4_144() { - use V::*; assert_has_taddhitanta(&prati("agniSarman"), T::iY, &["AgniSarmi"]); assert_has_taddhitanta(&prati("uquloman"), T::iY, &["Oqulomi"]); // naH? // taddhite? - assert_has_subantas("Sarman", Napumsaka, Trtiya, Eka, &["SarmaRA"]); - assert_has_subantas("Sarman", Napumsaka, Caturthi, Eka, &["SarmaRe"]); + assert_has_sup_3s("Sarman", Napumsaka, &["SarmaRA"]); + assert_has_sup_4s("Sarman", Napumsaka, &["SarmaRe"]); } #[test] diff --git a/vidyut-prakriya/tests/kashika_7_1.rs b/vidyut-prakriya/tests/kashika_7_1.rs index d3935af..e190e33 100644 --- a/vidyut-prakriya/tests/kashika_7_1.rs +++ b/vidyut-prakriya/tests/kashika_7_1.rs @@ -3,8 +3,6 @@ use test_utils::*; use vidyut_prakriya::args::Gana::*; use vidyut_prakriya::args::Lakara::*; use vidyut_prakriya::args::Linga::*; -use vidyut_prakriya::args::Vacana::*; -use vidyut_prakriya::args::Vibhakti::*; use vidyut_prakriya::args::*; #[test] @@ -124,226 +122,226 @@ fn sutra_7_1_7() { #[test] fn sutra_7_1_9() { - assert_has_subantas("vfkza", Pum, Trtiya, Bahu, &["vfkzEH"]); - assert_has_subantas("plakza", Pum, Trtiya, Bahu, &["plakzEH"]); - assert_has_subantas("atijarasa", Pum, Trtiya, Bahu, &["atijarasEH"]); + assert_has_sup_3p("vfkza", Pum, &["vfkzEH"]); + assert_has_sup_3p("plakza", Pum, &["plakzEH"]); + assert_has_sup_3p("atijarasa", Pum, &["atijarasEH"]); } // 7.1.10 is chAndasa #[test] fn sutra_7_1_11() { - assert_has_subantas("idam", Pum, Trtiya, Bahu, &["eBiH"]); - assert_has_subantas("adas", Pum, Trtiya, Bahu, &["amIBiH"]); + assert_has_sup_3p("idam", Pum, &["eBiH"]); + assert_has_sup_3p("adas", Pum, &["amIBiH"]); // TODO: imaka, amuka } #[test] fn sutra_7_1_12() { - assert_has_subantas("vfkza", Pum, Trtiya, Eka, &["vfkzeRa"]); - assert_has_subantas("plakza", Pum, Trtiya, Eka, &["plakzeRa"]); - assert_has_subantas("vfkza", Pum, Panchami, Eka, &["vfkzAt"]); - assert_has_subantas("plakza", Pum, Panchami, Eka, &["plakzAt"]); - assert_has_subantas("vfkza", Pum, Sasthi, Eka, &["vfkzasya"]); - assert_has_subantas("plakza", Pum, Sasthi, Eka, &["plakzasya"]); + assert_has_sup_3s("vfkza", Pum, &["vfkzeRa"]); + assert_has_sup_3s("plakza", Pum, &["plakzeRa"]); + assert_has_sup_5s("vfkza", Pum, &["vfkzAt"]); + assert_has_sup_5s("plakza", Pum, &["plakzAt"]); + assert_has_sup_6s("vfkza", Pum, &["vfkzasya"]); + assert_has_sup_6s("plakza", Pum, &["plakzasya"]); - assert_has_subantas("saKi", Pum, Trtiya, Eka, &["saKyA"]); - assert_has_subantas("pati", Pum, Trtiya, Eka, &["patyA"]); + assert_has_sup_3s("saKi", Pum, &["saKyA"]); + assert_has_sup_3s("pati", Pum, &["patyA"]); } #[test] fn sutra_7_1_13() { - assert_has_subantas("vfkza", Pum, Caturthi, Eka, &["vfkzAya"]); - assert_has_subantas("plakza", Pum, Caturthi, Eka, &["plakzAya"]); + assert_has_sup_4s("vfkza", Pum, &["vfkzAya"]); + assert_has_sup_4s("plakza", Pum, &["plakzAya"]); - assert_has_subantas("saKi", Pum, Caturthi, Eka, &["saKye"]); - assert_has_subantas("pati", Pum, Caturthi, Eka, &["patye"]); + assert_has_sup_4s("saKi", Pum, &["saKye"]); + assert_has_sup_4s("pati", Pum, &["patye"]); } #[test] fn sutra_7_1_14() { - assert_has_subantas("sarva", Pum, Caturthi, Eka, &["sarvasmE"]); - assert_has_subantas("viSva", Pum, Caturthi, Eka, &["viSvasmE"]); - assert_has_subantas("yad", Pum, Caturthi, Eka, &["yasmE"]); - assert_has_subantas("tad", Pum, Caturthi, Eka, &["tasmE"]); - assert_has_subantas("kim", Pum, Caturthi, Eka, &["kasmE"]); + assert_has_sup_4s("sarva", Pum, &["sarvasmE"]); + assert_has_sup_4s("viSva", Pum, &["viSvasmE"]); + assert_has_sup_4s("yad", Pum, &["yasmE"]); + assert_has_sup_4s("tad", Pum, &["tasmE"]); + assert_has_sup_4s("kim", Pum, &["kasmE"]); } #[test] fn sutra_7_1_15() { - assert_has_subantas("sarva", Pum, Panchami, Eka, &["sarvasmAt"]); - assert_has_subantas("viSva", Pum, Panchami, Eka, &["viSvasmAt"]); - assert_has_subantas("yad", Pum, Panchami, Eka, &["yasmAt"]); - assert_has_subantas("tad", Pum, Panchami, Eka, &["tasmAt"]); - assert_has_subantas("kim", Pum, Panchami, Eka, &["kasmAt"]); + assert_has_sup_5s("sarva", Pum, &["sarvasmAt"]); + assert_has_sup_5s("viSva", Pum, &["viSvasmAt"]); + assert_has_sup_5s("yad", Pum, &["yasmAt"]); + assert_has_sup_5s("tad", Pum, &["tasmAt"]); + assert_has_sup_5s("kim", Pum, &["kasmAt"]); - assert_has_subantas("sarva", Pum, Saptami, Eka, &["sarvasmin"]); - assert_has_subantas("viSva", Pum, Saptami, Eka, &["viSvasmin"]); - assert_has_subantas("yad", Pum, Saptami, Eka, &["yasmin"]); - assert_has_subantas("tad", Pum, Saptami, Eka, &["tasmin"]); - assert_has_subantas("anya", Pum, Saptami, Eka, &["anyasmin"]); + assert_has_sup_7s("sarva", Pum, &["sarvasmin"]); + assert_has_sup_7s("viSva", Pum, &["viSvasmin"]); + assert_has_sup_7s("yad", Pum, &["yasmin"]); + assert_has_sup_7s("tad", Pum, &["tasmin"]); + assert_has_sup_7s("anya", Pum, &["anyasmin"]); } #[test] fn sutra_7_1_16() { - assert_has_subantas("pUrva", Pum, Panchami, Eka, &["pUrvasmAt", "pUrvAt"]); - assert_has_subantas("pUrva", Pum, Saptami, Eka, &["pUrvasmin", "pUrve"]); - assert_has_subantas("para", Pum, Panchami, Eka, &["parasmAt", "parAt"]); - assert_has_subantas("para", Pum, Saptami, Eka, &["parasmin", "pare"]); - assert_has_subantas("avara", Pum, Panchami, Eka, &["avarasmAt", "avarAt"]); - assert_has_subantas("avara", Pum, Saptami, Eka, &["avarasmin", "avare"]); - assert_has_subantas("dakziRa", Pum, Panchami, Eka, &["dakziRasmAt", "dakziRAt"]); - assert_has_subantas("dakziRa", Pum, Saptami, Eka, &["dakziRasmin", "dakziRe"]); - assert_has_subantas("uttara", Pum, Panchami, Eka, &["uttarasmAt", "uttarAt"]); - assert_has_subantas("uttara", Pum, Saptami, Eka, &["uttarasmin", "uttare"]); - assert_has_subantas("apara", Pum, Panchami, Eka, &["aparasmAt", "aparAt"]); - assert_has_subantas("apara", Pum, Saptami, Eka, &["aparasmin", "apare"]); - assert_has_subantas("aDara", Pum, Panchami, Eka, &["aDarasmAt", "aDarAt"]); - assert_has_subantas("aDara", Pum, Saptami, Eka, &["aDarasmin", "aDare"]); - assert_has_subantas("sva", Pum, Panchami, Eka, &["svasmAt", "svAt"]); - assert_has_subantas("sva", Pum, Saptami, Eka, &["svasmin", "sve"]); - assert_has_subantas("antara", Pum, Panchami, Eka, &["antarasmAt", "antarAt"]); - assert_has_subantas("antara", Pum, Saptami, Eka, &["antarasmin", "antare"]); + assert_has_sup_5s("pUrva", Pum, &["pUrvasmAt", "pUrvAt"]); + assert_has_sup_7s("pUrva", Pum, &["pUrvasmin", "pUrve"]); + assert_has_sup_5s("para", Pum, &["parasmAt", "parAt"]); + assert_has_sup_7s("para", Pum, &["parasmin", "pare"]); + assert_has_sup_5s("avara", Pum, &["avarasmAt", "avarAt"]); + assert_has_sup_7s("avara", Pum, &["avarasmin", "avare"]); + assert_has_sup_5s("dakziRa", Pum, &["dakziRasmAt", "dakziRAt"]); + assert_has_sup_7s("dakziRa", Pum, &["dakziRasmin", "dakziRe"]); + assert_has_sup_5s("uttara", Pum, &["uttarasmAt", "uttarAt"]); + assert_has_sup_7s("uttara", Pum, &["uttarasmin", "uttare"]); + assert_has_sup_5s("apara", Pum, &["aparasmAt", "aparAt"]); + assert_has_sup_7s("apara", Pum, &["aparasmin", "apare"]); + assert_has_sup_5s("aDara", Pum, &["aDarasmAt", "aDarAt"]); + assert_has_sup_7s("aDara", Pum, &["aDarasmin", "aDare"]); + assert_has_sup_5s("sva", Pum, &["svasmAt", "svAt"]); + assert_has_sup_7s("sva", Pum, &["svasmin", "sve"]); + assert_has_sup_5s("antara", Pum, &["antarasmAt", "antarAt"]); + assert_has_sup_7s("antara", Pum, &["antarasmin", "antare"]); } #[test] fn sutra_7_1_17() { - assert_has_subantas("sarva", Pum, Prathama, Bahu, &["sarve"]); - assert_has_subantas("viSva", Pum, Prathama, Bahu, &["viSve"]); - assert_has_subantas("yad", Pum, Prathama, Bahu, &["ye"]); - assert_has_subantas("tad", Pum, Prathama, Bahu, &["te"]); - assert_has_subantas("kim", Pum, Prathama, Bahu, &["ke"]); + assert_has_sup_1p("sarva", Pum, &["sarve"]); + assert_has_sup_1p("viSva", Pum, &["viSve"]); + assert_has_sup_1p("yad", Pum, &["ye"]); + assert_has_sup_1p("tad", Pum, &["te"]); + assert_has_sup_1p("kim", Pum, &["ke"]); } #[test] fn sutra_7_1_18() { - assert_has_subantas_p(&nyap("KawvA"), Stri, Prathama, Dvi, &["Kawve"]); - assert_has_subantas_p(&nyap("KawvA"), Stri, Dvitiya, Dvi, &["Kawve"]); + assert_has_sup_1d(&nyap("KawvA"), Stri, &["Kawve"]); + assert_has_sup_2d(&nyap("KawvA"), Stri, &["Kawve"]); // TODO: more } #[test] fn sutra_7_1_19() { - assert_has_subantas("kuRqa", Napumsaka, Prathama, Dvi, &["kuRqe"]); - assert_has_subantas("kuRqa", Napumsaka, Dvitiya, Dvi, &["kuRqe"]); - assert_has_subantas("daDi", Napumsaka, Prathama, Dvi, &["daDinI"]); - assert_has_subantas("maDu", Napumsaka, Prathama, Dvi, &["maDunI"]); - assert_has_subantas("trapu", Napumsaka, Prathama, Dvi, &["trapuRI"]); - assert_has_subantas("jatu", Napumsaka, Prathama, Dvi, &["jatunI"]); + assert_has_sup_1d("kuRqa", Napumsaka, &["kuRqe"]); + assert_has_sup_2d("kuRqa", Napumsaka, &["kuRqe"]); + assert_has_sup_1d("daDi", Napumsaka, &["daDinI"]); + assert_has_sup_1d("maDu", Napumsaka, &["maDunI"]); + assert_has_sup_1d("trapu", Napumsaka, &["trapuRI"]); + assert_has_sup_1d("jatu", Napumsaka, &["jatunI"]); } #[test] fn sutra_7_1_20() { - assert_has_subantas("kuRqa", Napumsaka, Prathama, Bahu, &["kuRqAni"]); - assert_has_subantas("kuRqa", Napumsaka, Dvitiya, Bahu, &["kuRqAni"]); - assert_has_subantas("daDi", Napumsaka, Prathama, Bahu, &["daDIni"]); - assert_has_subantas("maDu", Napumsaka, Prathama, Bahu, &["maDUni"]); - assert_has_subantas("trapu", Napumsaka, Prathama, Bahu, &["trapURi"]); - assert_has_subantas("jatu", Napumsaka, Prathama, Bahu, &["jatUni"]); + assert_has_sup_1p("kuRqa", Napumsaka, &["kuRqAni"]); + assert_has_sup_2p("kuRqa", Napumsaka, &["kuRqAni"]); + assert_has_sup_1p("daDi", Napumsaka, &["daDIni"]); + assert_has_sup_1p("maDu", Napumsaka, &["maDUni"]); + assert_has_sup_1p("trapu", Napumsaka, &["trapURi"]); + assert_has_sup_1p("jatu", Napumsaka, &["jatUni"]); } #[ignore] #[test] fn sutra_7_1_21() { - assert_has_subantas("azwan", Pum, Prathama, Bahu, &["azwO"]); - assert_has_subantas("azwan", Pum, Dvitiya, Bahu, &["azwO"]); + assert_has_sup_1p("azwan", Pum, &["azwO"]); + assert_has_sup_2p("azwan", Pum, &["azwO"]); } #[ignore] #[test] fn sutra_7_1_22() { - assert_has_subantas("zaz", Pum, Prathama, Bahu, &["zaw"]); - assert_has_subantas("zaz", Pum, Dvitiya, Bahu, &["zaw"]); - assert_has_subantas("paYcan", Pum, Prathama, Bahu, &["paYca"]); - assert_has_subantas("saptan", Pum, Prathama, Bahu, &["sapta"]); - assert_has_subantas("navan", Pum, Prathama, Bahu, &["nava"]); - assert_has_subantas("daSan", Pum, Prathama, Bahu, &["daSa"]); + assert_has_sup_1p("zaz", Pum, &["zaw"]); + assert_has_sup_2p("zaz", Pum, &["zaw"]); + assert_has_sup_1p("paYcan", Pum, &["paYca"]); + assert_has_sup_1p("saptan", Pum, &["sapta"]); + assert_has_sup_1p("navan", Pum, &["nava"]); + assert_has_sup_1p("daSan", Pum, &["daSa"]); } #[test] fn sutra_7_1_23() { - assert_has_subantas("daDi", Napumsaka, Prathama, Eka, &["daDi"]); - assert_has_subantas("daDi", Napumsaka, Dvitiya, Eka, &["daDi"]); - assert_has_subantas("maDu", Napumsaka, Prathama, Eka, &["maDu"]); - assert_has_subantas("maDu", Napumsaka, Dvitiya, Eka, &["maDu"]); - assert_has_subantas("trapu", Napumsaka, Prathama, Eka, &["trapu"]); - assert_has_subantas("jatu", Napumsaka, Prathama, Eka, &["jatu"]); + assert_has_sup_1s("daDi", Napumsaka, &["daDi"]); + assert_has_sup_2s("daDi", Napumsaka, &["daDi"]); + assert_has_sup_1s("maDu", Napumsaka, &["maDu"]); + assert_has_sup_2s("maDu", Napumsaka, &["maDu"]); + assert_has_sup_1s("trapu", Napumsaka, &["trapu"]); + assert_has_sup_1s("jatu", Napumsaka, &["jatu"]); } #[test] fn sutra_7_1_24() { - assert_has_subantas("kuRqa", Napumsaka, Prathama, Eka, &["kuRqam"]); - assert_has_subantas("kuRqa", Napumsaka, Dvitiya, Eka, &["kuRqam"]); + assert_has_sup_1s("kuRqa", Napumsaka, &["kuRqam"]); + assert_has_sup_2s("kuRqa", Napumsaka, &["kuRqam"]); } #[ignore] #[test] fn sutra_7_1_25() { - assert_has_subantas("katara", Napumsaka, Prathama, Eka, &["katarat"]); - assert_has_subantas("katara", Napumsaka, Dvitiya, Eka, &["katarat"]); - assert_has_subantas("katama", Napumsaka, Prathama, Eka, &["katamat"]); - assert_has_subantas("katama", Napumsaka, Dvitiya, Eka, &["katamat"]); - assert_has_subantas("itara", Napumsaka, Prathama, Eka, &["itarat"]); - assert_has_subantas("anyatara", Napumsaka, Prathama, Eka, &["anyatarat"]); - assert_has_subantas("anya", Napumsaka, Prathama, Eka, &["anyat"]); + assert_has_sup_1s("katara", Napumsaka, &["katarat"]); + assert_has_sup_2s("katara", Napumsaka, &["katarat"]); + assert_has_sup_1s("katama", Napumsaka, &["katamat"]); + assert_has_sup_2s("katama", Napumsaka, &["katamat"]); + assert_has_sup_1s("itara", Napumsaka, &["itarat"]); + assert_has_sup_1s("anyatara", Napumsaka, &["anyatarat"]); + assert_has_sup_1s("anya", Napumsaka, &["anyat"]); - assert_has_subantas("nema", Napumsaka, Prathama, Eka, &["nemam"]); - assert_has_subantas("nema", Napumsaka, Dvitiya, Eka, &["nemam"]); + assert_has_sup_1s("nema", Napumsaka, &["nemam"]); + assert_has_sup_2s("nema", Napumsaka, &["nemam"]); } // 7.1.26 is chAndasa. #[test] fn sutra_7_1_27() { - assert_has_subantas("asmad", Pum, Sasthi, Eka, &["mama"]); - assert_has_subantas("yuzmad", Pum, Sasthi, Eka, &["tava"]); + assert_has_sup_6s("asmad", Pum, &["mama"]); + assert_has_sup_6s("yuzmad", Pum, &["tava"]); } #[test] fn sutra_7_1_28() { - assert_has_subantas("asmad", Pum, Caturthi, Eka, &["mahyam"]); - assert_has_subantas("yuzmad", Pum, Caturthi, Eka, &["tuByam"]); + assert_has_sup_4s("asmad", Pum, &["mahyam"]); + assert_has_sup_4s("yuzmad", Pum, &["tuByam"]); - assert_has_subantas("yuzmad", Pum, Prathama, Eka, &["tvam"]); - assert_has_subantas("asmad", Pum, Prathama, Eka, &["aham"]); - assert_has_subantas("yuzmad", Pum, Prathama, Dvi, &["yuvAm"]); - assert_has_subantas("asmad", Pum, Prathama, Dvi, &["AvAm"]); - assert_has_subantas("yuzmad", Pum, Prathama, Bahu, &["yUyam"]); - assert_has_subantas("asmad", Pum, Prathama, Bahu, &["vayam"]); - assert_has_subantas("yuzmad", Pum, Dvitiya, Eka, &["tvAm"]); - assert_has_subantas("asmad", Pum, Dvitiya, Eka, &["mAm"]); - assert_has_subantas("yuzmad", Pum, Dvitiya, Dvi, &["yuvAm"]); - assert_has_subantas("asmad", Pum, Dvitiya, Dvi, &["AvAm"]); + assert_has_sup_1s("yuzmad", Pum, &["tvam"]); + assert_has_sup_1s("asmad", Pum, &["aham"]); + assert_has_sup_1d("yuzmad", Pum, &["yuvAm"]); + assert_has_sup_1d("asmad", Pum, &["AvAm"]); + assert_has_sup_1p("yuzmad", Pum, &["yUyam"]); + assert_has_sup_1p("asmad", Pum, &["vayam"]); + assert_has_sup_2s("yuzmad", Pum, &["tvAm"]); + assert_has_sup_2s("asmad", Pum, &["mAm"]); + assert_has_sup_2d("yuzmad", Pum, &["yuvAm"]); + assert_has_sup_2d("asmad", Pum, &["AvAm"]); } #[test] fn sutra_7_1_29() { - assert_has_subantas("asmad", Pum, Dvitiya, Bahu, &["asmAn"]); - assert_has_subantas("yuzmad", Pum, Dvitiya, Bahu, &["yuzmAn"]); + assert_has_sup_2p("asmad", Pum, &["asmAn"]); + assert_has_sup_2p("yuzmad", Pum, &["yuzmAn"]); } #[test] fn sutra_7_1_30() { - assert_has_subantas("asmad", Pum, Caturthi, Bahu, &["asmaByam"]); - assert_has_subantas("yuzmad", Pum, Caturthi, Bahu, &["yuzmaByam"]); + assert_has_sup_4p("asmad", Pum, &["asmaByam"]); + assert_has_sup_4p("yuzmad", Pum, &["yuzmaByam"]); } #[test] fn sutra_7_1_31() { - assert_has_subantas("asmad", Pum, Panchami, Bahu, &["asmat"]); - assert_has_subantas("yuzmad", Pum, Panchami, Bahu, &["yuzmat"]); + assert_has_sup_5p("asmad", Pum, &["asmat"]); + assert_has_sup_5p("yuzmad", Pum, &["yuzmat"]); } #[test] fn sutra_7_1_32() { - assert_has_subantas("asmad", Pum, Panchami, Eka, &["mat"]); - assert_has_subantas("yuzmad", Pum, Panchami, Eka, &["tvat"]); + assert_has_sup_5s("asmad", Pum, &["mat"]); + assert_has_sup_5s("yuzmad", Pum, &["tvat"]); } #[test] fn sutra_7_1_33() { - assert_has_subantas("asmad", Pum, Sasthi, Bahu, &["asmAkam"]); - assert_has_subantas("yuzmad", Pum, Sasthi, Bahu, &["yuzmAkam"]); + assert_has_sup_6p("asmad", Pum, &["asmAkam"]); + assert_has_sup_6p("yuzmad", Pum, &["yuzmAkam"]); } #[test] @@ -395,65 +393,53 @@ fn sutra_7_1_37() { #[ignore] #[test] fn sutra_7_1_52() { - assert_has_subantas("sarva", Pum, Sasthi, Bahu, &["sarvezAm"]); - assert_has_subantas("viSva", Pum, Sasthi, Bahu, &["viSvezAm"]); - assert_has_subantas("yad", Pum, Sasthi, Bahu, &["yezAm"]); - assert_has_subantas("tad", Pum, Sasthi, Bahu, &["tezAm"]); + assert_has_sup_6p("sarva", Pum, &["sarvezAm"]); + assert_has_sup_6p("viSva", Pum, &["viSvezAm"]); + assert_has_sup_6p("yad", Pum, &["yezAm"]); + assert_has_sup_6p("tad", Pum, &["tezAm"]); - assert_has_subantas("sarva", Stri, Sasthi, Bahu, &["sarvAsAm"]); - assert_has_subantas("yad", Stri, Sasthi, Bahu, &["yAsAm"]); - assert_has_subantas("tad", Stri, Sasthi, Bahu, &["tAsAm"]); + assert_has_sup_6p("sarva", Stri, &["sarvAsAm"]); + assert_has_sup_6p("yad", Stri, &["yAsAm"]); + assert_has_sup_6p("tad", Stri, &["tAsAm"]); - assert_has_subantas("Bavat", Pum, Sasthi, Bahu, &["BavatAm"]); + assert_has_sup_6p("Bavat", Pum, &["BavatAm"]); } #[ignore] #[test] fn sutra_7_1_53() { - assert_has_subantas("tri", Pum, Sasthi, Bahu, &["trayARAm"]); + assert_has_sup_6p("tri", Pum, &["trayARAm"]); } #[test] fn sutra_7_1_54() { - assert_has_subantas("plakza", Pum, Sasthi, Bahu, &["plakzARAm"]); - assert_has_subantas("agni", Pum, Sasthi, Bahu, &["agnInAm"]); - assert_has_subantas("vAyu", Pum, Sasthi, Bahu, &["vAyUnAm"]); - assert_has_subantas("kartf", Pum, Sasthi, Bahu, &["kartFRAm"]); - - assert_has_subantas_p(&nyap("kumArI"), Stri, Sasthi, Bahu, &["kumArIRAm"]); - assert_has_subantas_p(&nyap("kiSorI"), Stri, Sasthi, Bahu, &["kiSorIRAm"]); - assert_has_subantas_p(&nyap("gOrI"), Stri, Sasthi, Bahu, &["gOrIRAm"]); - assert_has_subantas_p(&nyap("SArNgaravI"), Stri, Sasthi, Bahu, &["SArNgaravIRAm"]); - assert_has_subantas_p(&nyap("lakzmI"), Stri, Sasthi, Bahu, &["lakzmIRAm"]); - assert_has_subantas_p( - &nyap("brahmabanDU"), - Stri, - Sasthi, - Bahu, - &["brahmabanDUnAm"], - ); - assert_has_subantas_p(&nyap("vIrabanDU"), Stri, Sasthi, Bahu, &["vIrabanDUnAm"]); - assert_has_subantas_p(&nyap("KawvA"), Stri, Sasthi, Bahu, &["KawvAnAm"]); - assert_has_subantas_p(&nyap("mAlA"), Stri, Sasthi, Bahu, &["mAlAnAm"]); - assert_has_subantas_p(&nyap("bahurAjA"), Stri, Sasthi, Bahu, &["bahurAjAnAm"]); - assert_has_subantas_p( - &nyap("kArIzaganDyA"), - Stri, - Sasthi, - Bahu, - &["kArIzaganDyAnAm"], - ); + assert_has_sup_6p("plakza", Pum, &["plakzARAm"]); + assert_has_sup_6p("agni", Pum, &["agnInAm"]); + assert_has_sup_6p("vAyu", Pum, &["vAyUnAm"]); + assert_has_sup_6p("kartf", Pum, &["kartFRAm"]); + + assert_has_sup_6p(&nyap("kumArI"), Stri, &["kumArIRAm"]); + assert_has_sup_6p(&nyap("kiSorI"), Stri, &["kiSorIRAm"]); + assert_has_sup_6p(&nyap("gOrI"), Stri, &["gOrIRAm"]); + assert_has_sup_6p(&nyap("SArNgaravI"), Stri, &["SArNgaravIRAm"]); + assert_has_sup_6p(&nyap("lakzmI"), Stri, &["lakzmIRAm"]); + assert_has_sup_6p(&nyap("brahmabanDU"), Stri, &["brahmabanDUnAm"]); + assert_has_sup_6p(&nyap("vIrabanDU"), Stri, &["vIrabanDUnAm"]); + assert_has_sup_6p(&nyap("KawvA"), Stri, &["KawvAnAm"]); + assert_has_sup_6p(&nyap("mAlA"), Stri, &["mAlAnAm"]); + assert_has_sup_6p(&nyap("bahurAjA"), Stri, &["bahurAjAnAm"]); + assert_has_sup_6p(&nyap("kArIzaganDyA"), Stri, &["kArIzaganDyAnAm"]); } #[ignore] #[test] fn sutra_7_1_55() { - assert_has_subantas("zaz", Pum, Sasthi, Bahu, &["zaRRAm"]); - assert_has_subantas("paYcan", Pum, Sasthi, Bahu, &["paYcAnAm"]); - assert_has_subantas("saptan", Pum, Sasthi, Bahu, &["saptAnAm"]); - assert_has_subantas("navan", Pum, Sasthi, Bahu, &["navAnAm"]); - assert_has_subantas("daSan", Pum, Sasthi, Bahu, &["daSAnAm"]); - assert_has_subantas("catur", Pum, Sasthi, Bahu, &["caturRAm"]); + assert_has_sup_6p("zaz", Pum, &["zaRRAm"]); + assert_has_sup_6p("paYcan", Pum, &["paYcAnAm"]); + assert_has_sup_6p("saptan", Pum, &["saptAnAm"]); + assert_has_sup_6p("navan", Pum, &["navAnAm"]); + assert_has_sup_6p("daSan", Pum, &["daSAnAm"]); + assert_has_sup_6p("catur", Pum, &["caturRAm"]); } #[test] @@ -664,118 +650,118 @@ fn sutra_7_1_69() { #[test] fn sutra_7_1_72() { - assert_has_subantas("udaSvit", Napumsaka, Prathama, Bahu, &["udaSvinti"]); - assert_has_subantas("Sakft", Napumsaka, Prathama, Bahu, &["Sakfnti"]); - assert_has_subantas("yaSas", Napumsaka, Prathama, Bahu, &["yaSAMsi"]); - assert_has_subantas("payas", Napumsaka, Prathama, Bahu, &["payAMsi"]); + assert_has_sup_1p("udaSvit", Napumsaka, &["udaSvinti"]); + assert_has_sup_1p("Sakft", Napumsaka, &["Sakfnti"]); + assert_has_sup_1p("yaSas", Napumsaka, &["yaSAMsi"]); + assert_has_sup_1p("payas", Napumsaka, &["payAMsi"]); // ajantasya - assert_has_subantas("kuRqa", Napumsaka, Prathama, Bahu, &["kuRqAni"]); - assert_has_subantas("vana", Napumsaka, Prathama, Bahu, &["vanAni"]); - assert_has_subantas("trapu", Napumsaka, Prathama, Bahu, &["trapURi"]); - assert_has_subantas("jatu", Napumsaka, Prathama, Bahu, &["jatUni"]); + assert_has_sup_1p("kuRqa", Napumsaka, &["kuRqAni"]); + assert_has_sup_1p("vana", Napumsaka, &["vanAni"]); + assert_has_sup_1p("trapu", Napumsaka, &["trapURi"]); + assert_has_sup_1p("jatu", Napumsaka, &["jatUni"]); // napuMsakasya - assert_has_subantas("agnicit", Pum, Prathama, Eka, &["agnicit"]); + assert_has_sup_1s("agnicit", Pum, &["agnicit"]); // jhal-acaH - assert_has_subantas("bahupur", Napumsaka, Prathama, Bahu, &["bahupuri"]); - assert_has_subantas("vimaladiv", Napumsaka, Prathama, Bahu, &["vimaladivi"]); - assert_has_subantas("catur", Napumsaka, Prathama, Bahu, &["catvAri"]); - assert_has_subantas("ahan", Napumsaka, Prathama, Bahu, &["ahAni"]); + assert_has_sup_1p("bahupur", Napumsaka, &["bahupuri"]); + assert_has_sup_1p("vimaladiv", Napumsaka, &["vimaladivi"]); + assert_has_sup_1p("catur", Napumsaka, &["catvAri"]); + assert_has_sup_1p("ahan", Napumsaka, &["ahAni"]); - assert_has_subantas("Sreyas", Napumsaka, Prathama, Bahu, &["SreyAMsi"]); - assert_has_subantas("BUyas", Napumsaka, Prathama, Bahu, &["BUyAMsi"]); - assert_has_subantas("kurvat", Napumsaka, Prathama, Bahu, &["kurvanti"]); - assert_has_subantas("kfzat", Napumsaka, Prathama, Bahu, &["kfzanti"]); + assert_has_sup_1p("Sreyas", Napumsaka, &["SreyAMsi"]); + assert_has_sup_1p("BUyas", Napumsaka, &["BUyAMsi"]); + assert_has_sup_1p("kurvat", Napumsaka, &["kurvanti"]); + assert_has_sup_1p("kfzat", Napumsaka, &["kfzanti"]); // TODO: bahUrji } #[test] fn sutra_7_1_73() { - assert_has_subantas("trapu", Napumsaka, Prathama, Dvi, &["trapuRI"]); - assert_has_subantas("jatu", Napumsaka, Prathama, Dvi, &["jatunI"]); - assert_has_subantas("tumburu", Napumsaka, Prathama, Dvi, &["tumburuRI"]); - assert_has_subantas("trapu", Napumsaka, Caturthi, Eka, &["trapuRe"]); - assert_has_subantas("jatu", Napumsaka, Caturthi, Eka, &["jatune"]); - assert_has_subantas("tumburu", Napumsaka, Caturthi, Eka, &["tumburuRe"]); + assert_has_sup_1d("trapu", Napumsaka, &["trapuRI"]); + assert_has_sup_1d("jatu", Napumsaka, &["jatunI"]); + assert_has_sup_1d("tumburu", Napumsaka, &["tumburuRI"]); + assert_has_sup_4s("trapu", Napumsaka, &["trapuRe"]); + assert_has_sup_4s("jatu", Napumsaka, &["jatune"]); + assert_has_sup_4s("tumburu", Napumsaka, &["tumburuRe"]); // ikaH - assert_has_subantas("kuRqa", Napumsaka, Prathama, Dvi, &["kuRqe"]); - assert_has_subantas("pIWa", Napumsaka, Prathama, Dvi, &["pIWe"]); + assert_has_sup_1d("kuRqa", Napumsaka, &["kuRqe"]); + assert_has_sup_1d("pIWa", Napumsaka, &["pIWe"]); } #[test] fn sutra_7_1_84() { - assert_has_subantas("div", Stri, Prathama, Eka, &["dyOH"]); + assert_has_sup_1s("div", Stri, &["dyOH"]); } #[test] fn sutra_7_1_85() { - assert_has_subantas("paTin", Pum, Prathama, Eka, &["panTAH"]); - assert_has_subantas("maTin", Pum, Prathama, Eka, &["manTAH"]); - assert_has_subantas("fBukzin", Pum, Prathama, Eka, &["fBukzAH"]); + assert_has_sup_1s("paTin", Pum, &["panTAH"]); + assert_has_sup_1s("maTin", Pum, &["manTAH"]); + assert_has_sup_1s("fBukzin", Pum, &["fBukzAH"]); } #[test] fn sutra_7_1_86() { - assert_has_subantas("paTin", Pum, Prathama, Eka, &["panTAH"]); - assert_has_subantas("paTin", Pum, Prathama, Dvi, &["panTAnO"]); - assert_has_subantas("paTin", Pum, Prathama, Bahu, &["panTAnaH"]); - assert_has_subantas("paTin", Pum, Dvitiya, Eka, &["panTAnam"]); - assert_has_subantas("paTin", Pum, Dvitiya, Dvi, &["panTAnO"]); + assert_has_sup_1s("paTin", Pum, &["panTAH"]); + assert_has_sup_1d("paTin", Pum, &["panTAnO"]); + assert_has_sup_1p("paTin", Pum, &["panTAnaH"]); + assert_has_sup_2s("paTin", Pum, &["panTAnam"]); + assert_has_sup_2d("paTin", Pum, &["panTAnO"]); - assert_has_subantas("maTin", Pum, Prathama, Eka, &["manTAH"]); - assert_has_subantas("maTin", Pum, Prathama, Dvi, &["manTAnO"]); - assert_has_subantas("maTin", Pum, Prathama, Bahu, &["manTAnaH"]); - assert_has_subantas("maTin", Pum, Dvitiya, Eka, &["manTAnam"]); - assert_has_subantas("maTin", Pum, Dvitiya, Dvi, &["manTAnO"]); + assert_has_sup_1s("maTin", Pum, &["manTAH"]); + assert_has_sup_1d("maTin", Pum, &["manTAnO"]); + assert_has_sup_1p("maTin", Pum, &["manTAnaH"]); + assert_has_sup_2s("maTin", Pum, &["manTAnam"]); + assert_has_sup_2d("maTin", Pum, &["manTAnO"]); - assert_has_subantas("fBukzin", Pum, Prathama, Eka, &["fBukzAH"]); - assert_has_subantas("fBukzin", Pum, Prathama, Dvi, &["fBukzARO"]); - assert_has_subantas("fBukzin", Pum, Prathama, Bahu, &["fBukzARaH"]); - assert_has_subantas("fBukzin", Pum, Dvitiya, Eka, &["fBukzARam"]); - assert_has_subantas("fBukzin", Pum, Dvitiya, Dvi, &["fBukzARO"]); + assert_has_sup_1s("fBukzin", Pum, &["fBukzAH"]); + assert_has_sup_1d("fBukzin", Pum, &["fBukzARO"]); + assert_has_sup_1p("fBukzin", Pum, &["fBukzARaH"]); + assert_has_sup_2s("fBukzin", Pum, &["fBukzARam"]); + assert_has_sup_2d("fBukzin", Pum, &["fBukzARO"]); } #[test] fn sutra_7_1_87() { - assert_has_subantas("paTin", Pum, Prathama, Eka, &["panTAH"]); - assert_has_subantas("paTin", Pum, Prathama, Dvi, &["panTAnO"]); - assert_has_subantas("paTin", Pum, Prathama, Bahu, &["panTAnaH"]); + assert_has_sup_1s("paTin", Pum, &["panTAH"]); + assert_has_sup_1d("paTin", Pum, &["panTAnO"]); + assert_has_sup_1p("paTin", Pum, &["panTAnaH"]); - assert_has_subantas("maTin", Pum, Prathama, Eka, &["manTAH"]); - assert_has_subantas("maTin", Pum, Prathama, Dvi, &["manTAnO"]); - assert_has_subantas("maTin", Pum, Prathama, Bahu, &["manTAnaH"]); + assert_has_sup_1s("maTin", Pum, &["manTAH"]); + assert_has_sup_1d("maTin", Pum, &["manTAnO"]); + assert_has_sup_1p("maTin", Pum, &["manTAnaH"]); } #[test] fn sutra_7_1_88() { - assert_has_subantas("paTin", Pum, Dvitiya, Bahu, &["paTaH"]); - assert_has_subantas("paTin", Pum, Trtiya, Eka, &["paTA"]); - assert_has_subantas("paTin", Pum, Caturthi, Eka, &["paTe"]); + assert_has_sup_2p("paTin", Pum, &["paTaH"]); + assert_has_sup_3s("paTin", Pum, &["paTA"]); + assert_has_sup_4s("paTin", Pum, &["paTe"]); - assert_has_subantas("maTin", Pum, Dvitiya, Bahu, &["maTaH"]); - assert_has_subantas("maTin", Pum, Trtiya, Eka, &["maTA"]); - assert_has_subantas("maTin", Pum, Caturthi, Eka, &["maTe"]); + assert_has_sup_2p("maTin", Pum, &["maTaH"]); + assert_has_sup_3s("maTin", Pum, &["maTA"]); + assert_has_sup_4s("maTin", Pum, &["maTe"]); - assert_has_subantas("fBukzin", Pum, Dvitiya, Bahu, &["fBukzaH"]); - assert_has_subantas("fBukzin", Pum, Trtiya, Eka, &["fBukzA"]); - assert_has_subantas("fBukzin", Pum, Caturthi, Eka, &["fBukze"]); + assert_has_sup_2p("fBukzin", Pum, &["fBukzaH"]); + assert_has_sup_3s("fBukzin", Pum, &["fBukzA"]); + assert_has_sup_4s("fBukzin", Pum, &["fBukze"]); } #[ignore] #[test] fn sutra_7_1_89() { - assert_has_subantas("pums", Pum, Prathama, Eka, &["pumAn"]); - assert_has_subantas("pums", Pum, Prathama, Dvi, &["pumAMsO"]); - assert_has_subantas("pums", Pum, Prathama, Bahu, &["pumAMsaH"]); + assert_has_sup_1s("pums", Pum, &["pumAn"]); + assert_has_sup_1d("pums", Pum, &["pumAMsO"]); + assert_has_sup_1p("pums", Pum, &["pumAMsaH"]); } #[test] fn sutra_7_1_90() { - assert_has_subantas("go", Pum, Prathama, Eka, &["gOH"]); - assert_has_subantas("go", Pum, Prathama, Dvi, &["gAvO"]); - assert_has_subantas("go", Pum, Prathama, Bahu, &["gAvaH"]); + assert_has_sup_1s("go", Pum, &["gOH"]); + assert_has_sup_1d("go", Pum, &["gAvO"]); + assert_has_sup_1p("go", Pum, &["gAvaH"]); // TODO: others } @@ -787,39 +773,39 @@ fn sutra_7_1_91() { #[test] fn sutra_7_1_92() { - assert_has_subantas("saKi", Pum, Prathama, Dvi, &["saKAyO"]); - assert_has_subantas("saKi", Pum, Prathama, Bahu, &["saKAyaH"]); + assert_has_sup_1d("saKi", Pum, &["saKAyO"]); + assert_has_sup_1p("saKi", Pum, &["saKAyaH"]); // asambuddhau? - assert_has_subantas("saKi", Pum, Sambodhana, Eka, &["saKe"]); + assert_has_sup_ss("saKi", Pum, &["saKe"]); } #[ignore] #[test] fn sutra_7_1_93() { - assert_has_subantas("saKi", Pum, Prathama, Eka, &["saKA"]); + assert_has_sup_1s("saKi", Pum, &["saKA"]); // asambuddhau? - assert_has_subantas("saKi", Pum, Sambodhana, Eka, &["saKe"]); + assert_has_sup_ss("saKi", Pum, &["saKe"]); } #[ignore] #[test] fn sutra_7_1_94() { - assert_has_subantas("kartf", Pum, Prathama, Eka, &["kartA"]); - assert_has_subantas("hartf", Pum, Prathama, Eka, &["hartA"]); - assert_has_subantas("mAtf", Pum, Prathama, Eka, &["mAtA"]); - assert_has_subantas("pitf", Pum, Prathama, Eka, &["pitA"]); - assert_has_subantas("BrAtf", Pum, Prathama, Eka, &["BrAtA"]); - assert_has_subantas("uSanas", Pum, Prathama, Eka, &["uSanA"]); - assert_has_subantas("purudaMsas", Pum, Prathama, Eka, &["purudaMsA"]); - assert_has_subantas("anehas", Pum, Prathama, Eka, &["anehA"]); + assert_has_sup_1s("kartf", Pum, &["kartA"]); + assert_has_sup_1s("hartf", Pum, &["hartA"]); + assert_has_sup_1s("mAtf", Pum, &["mAtA"]); + assert_has_sup_1s("pitf", Pum, &["pitA"]); + assert_has_sup_1s("BrAtf", Pum, &["BrAtA"]); + assert_has_sup_1s("uSanas", Pum, &["uSanA"]); + assert_has_sup_1s("purudaMsas", Pum, &["purudaMsA"]); + assert_has_sup_1s("anehas", Pum, &["anehA"]); // asambuddhau? - assert_has_subantas("kartf", Pum, Sambodhana, Eka, &["kartaH"]); - assert_has_subantas("mAtf", Pum, Sambodhana, Eka, &["mAtaH"]); - assert_has_subantas("pitf", Pum, Sambodhana, Eka, &["pitaH"]); - assert_has_subantas("purudaMsas", Pum, Sambodhana, Eka, &["purudaMsaH"]); - assert_has_subantas("anehas", Pum, Sambodhana, Eka, &["anehaH"]); - assert_has_subantas("uSanas", Pum, Sambodhana, Eka, &["uSanaH"]); + assert_has_sup_ss("kartf", Pum, &["kartaH"]); + assert_has_sup_ss("mAtf", Pum, &["mAtaH"]); + assert_has_sup_ss("pitf", Pum, &["pitaH"]); + assert_has_sup_ss("purudaMsas", Pum, &["purudaMsaH"]); + assert_has_sup_ss("anehas", Pum, &["anehaH"]); + assert_has_sup_ss("uSanas", Pum, &["uSanaH"]); } #[test] diff --git a/vidyut-prakriya/tests/kashika_7_2.rs b/vidyut-prakriya/tests/kashika_7_2.rs index 38150c5..04fb377 100644 --- a/vidyut-prakriya/tests/kashika_7_2.rs +++ b/vidyut-prakriya/tests/kashika_7_2.rs @@ -6,7 +6,6 @@ use vidyut_prakriya::args::Linga::*; use vidyut_prakriya::args::Purusha::*; use vidyut_prakriya::args::Taddhita as T; use vidyut_prakriya::args::Vacana::*; -use vidyut_prakriya::args::Vibhakti as V; use vidyut_prakriya::args::*; #[test] @@ -1207,11 +1206,10 @@ fn sutra_7_2_83() { #[test] fn sutra_7_2_84() { - use Vibhakti::*; - assert_has_subantas("azwan", Pum, Trtiya, Bahu, &["azwABiH", "azwaBiH"]); - assert_has_subantas("azwan", Pum, Caturthi, Bahu, &["azwAByaH", "azwaByaH"]); - assert_has_subantas("azwan", Pum, Sasthi, Bahu, &["azwAnAm"]); - assert_has_subantas("azwan", Pum, Saptami, Bahu, &["azwAsu", "azwasu"]); + assert_has_sup_3p("azwan", Pum, &["azwABiH", "azwaBiH"]); + assert_has_sup_4p("azwan", Pum, &["azwAByaH", "azwaByaH"]); + assert_has_sup_6p("azwan", Pum, &["azwAnAm"]); + assert_has_sup_7p("azwan", Pum, &["azwAsu", "azwasu"]); // viBaktO assert_has_taddhitanta(&prati("azwan"), T::tva, &["azwatva"]); assert_has_taddhitanta(&prati("azwan"), T::tal, &["azwatA"]); @@ -1219,11 +1217,10 @@ fn sutra_7_2_84() { #[test] fn sutra_7_2_85() { - use Vibhakti::*; - assert_has_subantas("rE", Pum, Trtiya, Dvi, &["rAByAm"]); - assert_has_subantas("rE", Pum, Trtiya, Bahu, &["rABiH"]); + assert_has_sup_3d("rE", Pum, &["rAByAm"]); + assert_has_sup_3p("rE", Pum, &["rABiH"]); // hali - assert_has_subantas("rE", Pum, Prathama, Dvi, &["rAyO"]); + assert_has_sup_1d("rE", Pum, &["rAyO"]); // viBaktO assert_has_taddhitanta(&prati("rE"), T::tva, &["rEtva"]); assert_has_taddhitanta(&prati("rE"), T::tal, &["rEtA"]); @@ -1231,200 +1228,187 @@ fn sutra_7_2_85() { #[test] fn sutra_7_2_86() { - use Vibhakti::*; - assert_has_subantas("yuzmad", Pum, Trtiya, Bahu, &["yuzmABiH"]); - assert_has_subantas("asmad", Pum, Trtiya, Bahu, &["asmABiH"]); - assert_has_subantas("yuzmad", Pum, Saptami, Bahu, &["yuzmAsu"]); - assert_has_subantas("asmad", Pum, Saptami, Bahu, &["asmAsu"]); + assert_has_sup_3p("yuzmad", Pum, &["yuzmABiH"]); + assert_has_sup_3p("asmad", Pum, &["asmABiH"]); + assert_has_sup_7p("yuzmad", Pum, &["yuzmAsu"]); + assert_has_sup_7p("asmad", Pum, &["asmAsu"]); // anAdeSe - assert_has_subantas("yuzmad", Pum, Panchami, Bahu, &["yuzmat"]); - assert_has_subantas("asmad", Pum, Panchami, Bahu, &["asmat"]); + assert_has_sup_5p("yuzmad", Pum, &["yuzmat"]); + assert_has_sup_5p("asmad", Pum, &["asmat"]); } #[test] fn sutra_7_2_87() { - use Vibhakti::*; - assert_has_subantas("yuzmad", Pum, Dvitiya, Eka, &["tvAm"]); - assert_has_subantas("asmad", Pum, Dvitiya, Eka, &["mAm"]); - assert_has_subantas("yuzmad", Pum, Dvitiya, Dvi, &["yuvAm"]); - assert_has_subantas("asmad", Pum, Dvitiya, Dvi, &["AvAm"]); + assert_has_sup_2s("yuzmad", Pum, &["tvAm"]); + assert_has_sup_2s("asmad", Pum, &["mAm"]); + assert_has_sup_2d("yuzmad", Pum, &["yuvAm"]); + assert_has_sup_2d("asmad", Pum, &["AvAm"]); } #[test] fn sutra_7_2_88() { - use Vibhakti::*; - assert_has_subantas("yuzmad", Pum, Prathama, Dvi, &["yuvAm"]); - assert_has_subantas("asmad", Pum, Prathama, Dvi, &["AvAm"]); + assert_has_sup_1d("yuzmad", Pum, &["yuvAm"]); + assert_has_sup_1d("asmad", Pum, &["AvAm"]); - assert_has_subantas("yuzmad", Pum, Sasthi, Dvi, &["yuvayoH"]); - assert_has_subantas("asmad", Pum, Sasthi, Dvi, &["AvayoH"]); - assert_has_subantas("yuzmad", Pum, Prathama, Eka, &["tvam"]); - assert_has_subantas("asmad", Pum, Prathama, Eka, &["aham"]); - assert_has_subantas("yuzmad", Pum, Prathama, Bahu, &["yUyam"]); - assert_has_subantas("asmad", Pum, Prathama, Bahu, &["vayam"]); + assert_has_sup_6d("yuzmad", Pum, &["yuvayoH"]); + assert_has_sup_6d("asmad", Pum, &["AvayoH"]); + assert_has_sup_1s("yuzmad", Pum, &["tvam"]); + assert_has_sup_1s("asmad", Pum, &["aham"]); + assert_has_sup_1p("yuzmad", Pum, &["yUyam"]); + assert_has_sup_1p("asmad", Pum, &["vayam"]); } #[test] fn sutra_7_2_89() { - use Vibhakti::*; - assert_has_subantas("yuzmad", Pum, Trtiya, Eka, &["tvayA"]); - assert_has_subantas("asmad", Pum, Trtiya, Eka, &["mayA"]); - assert_has_subantas("yuzmad", Pum, Saptami, Eka, &["tvayi"]); - assert_has_subantas("asmad", Pum, Saptami, Eka, &["mayi"]); - assert_has_subantas("yuzmad", Pum, Saptami, Dvi, &["yuvayoH"]); - assert_has_subantas("asmad", Pum, Saptami, Dvi, &["AvayoH"]); + assert_has_sup_3s("yuzmad", Pum, &["tvayA"]); + assert_has_sup_3s("asmad", Pum, &["mayA"]); + assert_has_sup_7s("yuzmad", Pum, &["tvayi"]); + assert_has_sup_7s("asmad", Pum, &["mayi"]); + assert_has_sup_7d("yuzmad", Pum, &["yuvayoH"]); + assert_has_sup_7d("asmad", Pum, &["AvayoH"]); - assert_has_subantas("yuzmad", Pum, Trtiya, Dvi, &["yuvAByAm"]); - assert_has_subantas("asmad", Pum, Trtiya, Dvi, &["AvAByAm"]); + assert_has_sup_3d("yuzmad", Pum, &["yuvAByAm"]); + assert_has_sup_3d("asmad", Pum, &["AvAByAm"]); - assert_has_subantas("yuzmad", Pum, Panchami, Eka, &["tvat"]); - assert_has_subantas("asmad", Pum, Panchami, Eka, &["mat"]); + assert_has_sup_5s("yuzmad", Pum, &["tvat"]); + assert_has_sup_5s("asmad", Pum, &["mat"]); } #[test] fn sutra_7_2_90() { - use Vibhakti::*; - assert_has_subantas("yuzmad", Pum, Prathama, Eka, &["tvam"]); - assert_has_subantas("asmad", Pum, Prathama, Eka, &["aham"]); - assert_has_subantas("yuzmad", Pum, Prathama, Bahu, &["yUyam"]); - assert_has_subantas("asmad", Pum, Prathama, Bahu, &["vayam"]); - assert_has_subantas("yuzmad", Pum, Caturthi, Eka, &["tuByam"]); - assert_has_subantas("asmad", Pum, Caturthi, Eka, &["mahyam"]); - assert_has_subantas("yuzmad", Pum, Caturthi, Bahu, &["yuzmaByam"]); - assert_has_subantas("asmad", Pum, Caturthi, Bahu, &["asmaByam"]); - assert_has_subantas("yuzmad", Pum, Panchami, Eka, &["tvat"]); - assert_has_subantas("asmad", Pum, Panchami, Eka, &["mat"]); - assert_has_subantas("yuzmad", Pum, Panchami, Bahu, &["yuzmat"]); - assert_has_subantas("asmad", Pum, Panchami, Bahu, &["asmat"]); - assert_has_subantas("yuzmad", Pum, Sasthi, Eka, &["tava"]); - assert_has_subantas("asmad", Pum, Sasthi, Eka, &["mama"]); - assert_has_subantas("yuzmad", Pum, Sasthi, Bahu, &["yuzmAkam"]); - assert_has_subantas("asmad", Pum, Sasthi, Bahu, &["asmAkam"]); + assert_has_sup_1s("yuzmad", Pum, &["tvam"]); + assert_has_sup_1s("asmad", Pum, &["aham"]); + assert_has_sup_1p("yuzmad", Pum, &["yUyam"]); + assert_has_sup_1p("asmad", Pum, &["vayam"]); + assert_has_sup_4s("yuzmad", Pum, &["tuByam"]); + assert_has_sup_4s("asmad", Pum, &["mahyam"]); + assert_has_sup_4p("yuzmad", Pum, &["yuzmaByam"]); + assert_has_sup_4p("asmad", Pum, &["asmaByam"]); + assert_has_sup_5s("yuzmad", Pum, &["tvat"]); + assert_has_sup_5s("asmad", Pum, &["mat"]); + assert_has_sup_5p("yuzmad", Pum, &["yuzmat"]); + assert_has_sup_5p("asmad", Pum, &["asmat"]); + assert_has_sup_6s("yuzmad", Pum, &["tava"]); + assert_has_sup_6s("asmad", Pum, &["mama"]); + assert_has_sup_6p("yuzmad", Pum, &["yuzmAkam"]); + assert_has_sup_6p("asmad", Pum, &["asmAkam"]); } #[test] fn sutra_7_2_92() { - use Vibhakti::*; - assert_has_subantas("yuzmad", Pum, Prathama, Dvi, &["yuvAm"]); - assert_has_subantas("asmad", Pum, Prathama, Dvi, &["AvAm"]); - assert_has_subantas("yuzmad", Pum, Trtiya, Dvi, &["yuvAByAm"]); - assert_has_subantas("asmad", Pum, Trtiya, Dvi, &["AvAByAm"]); - assert_has_subantas("yuzmad", Pum, Sasthi, Dvi, &["yuvayoH"]); - assert_has_subantas("asmad", Pum, Sasthi, Dvi, &["AvayoH"]); + assert_has_sup_1d("yuzmad", Pum, &["yuvAm"]); + assert_has_sup_1d("asmad", Pum, &["AvAm"]); + assert_has_sup_3d("yuzmad", Pum, &["yuvAByAm"]); + assert_has_sup_3d("asmad", Pum, &["AvAByAm"]); + assert_has_sup_6d("yuzmad", Pum, &["yuvayoH"]); + assert_has_sup_6d("asmad", Pum, &["AvayoH"]); // TODO: others } #[test] fn sutra_7_2_93() { - use Vibhakti::*; - assert_has_subantas("yuzmad", Pum, Prathama, Bahu, &["yUyam"]); - assert_has_subantas("asmad", Pum, Prathama, Bahu, &["vayam"]); + assert_has_sup_1p("yuzmad", Pum, &["yUyam"]); + assert_has_sup_1p("asmad", Pum, &["vayam"]); // TODO: others } #[test] fn sutra_7_2_94() { - assert_has_subantas("yuzmad", Pum, V::Prathama, Eka, &["tvam"]); - assert_has_subantas("asmad", Pum, V::Prathama, Eka, &["aham"]); + assert_has_sup_1s("yuzmad", Pum, &["tvam"]); + assert_has_sup_1s("asmad", Pum, &["aham"]); // TODO: others } #[test] fn sutra_7_2_95() { - assert_has_subantas("yuzmad", Pum, V::Caturthi, Eka, &["tuByam"]); - assert_has_subantas("asmad", Pum, V::Caturthi, Eka, &["mahyam"]); + assert_has_sup_4s("yuzmad", Pum, &["tuByam"]); + assert_has_sup_4s("asmad", Pum, &["mahyam"]); // TODO: others } #[test] fn sutra_7_2_96() { - assert_has_subantas("yuzmad", Pum, V::Sasthi, Eka, &["tava"]); - assert_has_subantas("asmad", Pum, V::Sasthi, Eka, &["mama"]); + assert_has_sup_6s("yuzmad", Pum, &["tava"]); + assert_has_sup_6s("asmad", Pum, &["mama"]); // TODO: others } #[test] fn sutra_7_2_97() { - use Vibhakti::*; - assert_has_subantas("yuzmad", Pum, Dvitiya, Eka, &["tvAm"]); - assert_has_subantas("asmad", Pum, Dvitiya, Eka, &["mAm"]); - assert_has_subantas("yuzmad", Pum, Trtiya, Eka, &["tvayA"]); - assert_has_subantas("asmad", Pum, Trtiya, Eka, &["mayA"]); - assert_has_subantas("yuzmad", Pum, Panchami, Eka, &["tvat"]); - assert_has_subantas("asmad", Pum, Panchami, Eka, &["mat"]); - assert_has_subantas("yuzmad", Pum, Saptami, Eka, &["tvayi"]); - assert_has_subantas("asmad", Pum, Saptami, Eka, &["mayi"]); + assert_has_sup_2s("yuzmad", Pum, &["tvAm"]); + assert_has_sup_2s("asmad", Pum, &["mAm"]); + assert_has_sup_3s("yuzmad", Pum, &["tvayA"]); + assert_has_sup_3s("asmad", Pum, &["mayA"]); + assert_has_sup_5s("yuzmad", Pum, &["tvat"]); + assert_has_sup_5s("asmad", Pum, &["mat"]); + assert_has_sup_7s("yuzmad", Pum, &["tvayi"]); + assert_has_sup_7s("asmad", Pum, &["mayi"]); // TODO: others } #[test] fn sutra_7_2_99() { - use Vibhakti::*; - assert_has_subantas("tri", Stri, Prathama, Bahu, &["tisraH"]); - assert_has_subantas("catur", Stri, Prathama, Bahu, &["catasraH"]); - assert_has_subantas("tri", Stri, Trtiya, Bahu, &["tisfBiH"]); - assert_has_subantas("catur", Stri, Trtiya, Bahu, &["catasfBiH"]); + assert_has_sup_1p("tri", Stri, &["tisraH"]); + assert_has_sup_1p("catur", Stri, &["catasraH"]); + assert_has_sup_3p("tri", Stri, &["tisfBiH"]); + assert_has_sup_3p("catur", Stri, &["catasfBiH"]); // striyAm - assert_has_subantas("tri", Pum, Prathama, Bahu, &["trayaH"]); - assert_has_subantas("catur", Pum, Prathama, Bahu, &["catvAraH"]); - assert_has_subantas("tri", Napumsaka, Prathama, Bahu, &["trIRi"]); - assert_has_subantas("catur", Napumsaka, Prathama, Bahu, &["catvAri"]); + assert_has_sup_1p("tri", Pum, &["trayaH"]); + assert_has_sup_1p("catur", Pum, &["catvAraH"]); + assert_has_sup_1p("tri", Napumsaka, &["trIRi"]); + assert_has_sup_1p("catur", Napumsaka, &["catvAri"]); } #[test] fn sutra_7_2_100() { - use Vibhakti::*; - assert_has_subantas("tri", Stri, Prathama, Bahu, &["tisraH"]); - assert_has_subantas("catur", Stri, Prathama, Bahu, &["catasraH"]); - assert_has_subantas("tri", Stri, Dvitiya, Bahu, &["tisraH"]); - assert_has_subantas("catur", Stri, Dvitiya, Bahu, &["catasraH"]); + assert_has_sup_1p("tri", Stri, &["tisraH"]); + assert_has_sup_1p("catur", Stri, &["catasraH"]); + assert_has_sup_2p("tri", Stri, &["tisraH"]); + assert_has_sup_2p("catur", Stri, &["catasraH"]); // TODO: others } #[test] fn sutra_7_2_101() { - use Vibhakti::*; let jara = nyap("jarA"); - assert_has_subantas_p(&jara, Stri, Trtiya, Eka, &["jarasA", "jarayA"]); - assert_has_subantas_p(&jara, Stri, Caturthi, Eka, &["jarase", "jarAyE"]); + assert_has_sup_3s(&jara, Stri, &["jarasA", "jarayA"]); + assert_has_sup_4s(&jara, Stri, &["jarase", "jarAyE"]); // aci - assert_has_subantas_p(&jara, Stri, Trtiya, Dvi, &["jarAByAm"]); - assert_has_subantas_p(&jara, Stri, Trtiya, Bahu, &["jarABiH"]); + assert_has_sup_3d(&jara, Stri, &["jarAByAm"]); + assert_has_sup_3p(&jara, Stri, &["jarABiH"]); // TODO: others } #[test] fn sutra_7_2_102() { - use Vibhakti::*; - assert_has_subantas("tyad", Pum, Prathama, Eka, &["syaH"]); - assert_has_subantas("tyad", Pum, Prathama, Dvi, &["tyO"]); - assert_has_subantas("tyad", Pum, Prathama, Bahu, &["tye"]); - assert_has_subantas("tad", Pum, Prathama, Eka, &["saH"]); - assert_has_subantas("tad", Pum, Prathama, Dvi, &["tO"]); - assert_has_subantas("tad", Pum, Prathama, Bahu, &["te"]); - assert_has_subantas("yad", Pum, Prathama, Eka, &["yaH"]); - assert_has_subantas("yad", Pum, Prathama, Dvi, &["yO"]); - assert_has_subantas("yad", Pum, Prathama, Bahu, &["ye"]); - assert_has_subantas("etad", Pum, Prathama, Eka, &["ezaH"]); - assert_has_subantas("etad", Pum, Prathama, Dvi, &["etO"]); - assert_has_subantas("etad", Pum, Prathama, Bahu, &["ete"]); - assert_has_subantas("idam", Pum, Prathama, Eka, &["ayam"]); - assert_has_subantas("idam", Pum, Prathama, Dvi, &["imO"]); - assert_has_subantas("idam", Pum, Prathama, Bahu, &["ime"]); - assert_has_subantas("adas", Pum, Prathama, Eka, &["asO"]); - assert_has_subantas("adas", Pum, Prathama, Dvi, &["amU"]); - assert_has_subantas("adas", Pum, Prathama, Bahu, &["amI"]); + assert_has_sup_1s("tyad", Pum, &["syaH"]); + assert_has_sup_1d("tyad", Pum, &["tyO"]); + assert_has_sup_1p("tyad", Pum, &["tye"]); + assert_has_sup_1s("tad", Pum, &["saH"]); + assert_has_sup_1d("tad", Pum, &["tO"]); + assert_has_sup_1p("tad", Pum, &["te"]); + assert_has_sup_1s("yad", Pum, &["yaH"]); + assert_has_sup_1d("yad", Pum, &["yO"]); + assert_has_sup_1p("yad", Pum, &["ye"]); + assert_has_sup_1s("etad", Pum, &["ezaH"]); + assert_has_sup_1d("etad", Pum, &["etO"]); + assert_has_sup_1p("etad", Pum, &["ete"]); + assert_has_sup_1s("idam", Pum, &["ayam"]); + assert_has_sup_1d("idam", Pum, &["imO"]); + assert_has_sup_1p("idam", Pum, &["ime"]); + assert_has_sup_1s("adas", Pum, &["asO"]); + assert_has_sup_1d("adas", Pum, &["amU"]); + assert_has_sup_1p("adas", Pum, &["amI"]); // exception - assert_has_subantas("dvi", Pum, Prathama, Dvi, &["dvO"]); - assert_has_subantas("dvi", Pum, Trtiya, Dvi, &["dvAByAm"]); + assert_has_sup_1d("dvi", Pum, &["dvO"]); + assert_has_sup_3d("dvi", Pum, &["dvAByAm"]); } #[test] fn sutra_7_2_103() { - use Vibhakti::*; - assert_has_subantas("kim", Pum, Prathama, Eka, &["kaH"]); - assert_has_subantas("kim", Pum, Prathama, Dvi, &["kO"]); - assert_has_subantas("kim", Pum, Prathama, Bahu, &["ke"]); + assert_has_sup_1s("kim", Pum, &["kaH"]); + assert_has_sup_1d("kim", Pum, &["kO"]); + assert_has_sup_1p("kim", Pum, &["ke"]); } #[test] @@ -1441,67 +1425,59 @@ fn sutra_7_2_105() { #[test] fn sutra_7_2_106() { - use Vibhakti::*; - assert_has_subantas("tyad", Pum, Prathama, Eka, &["syaH"]); - assert_has_subantas("tad", Pum, Prathama, Eka, &["saH"]); - assert_has_subantas("etad", Pum, Prathama, Eka, &["ezaH"]); - assert_has_subantas("adas", Pum, Prathama, Eka, &["asO"]); + assert_has_sup_1s("tyad", Pum, &["syaH"]); + assert_has_sup_1s("tad", Pum, &["saH"]); + assert_has_sup_1s("etad", Pum, &["ezaH"]); + assert_has_sup_1s("adas", Pum, &["asO"]); } #[test] fn sutra_7_2_107() { - use Vibhakti::*; - assert_has_subantas("adas", Pum, Prathama, Eka, &["asO"]); + assert_has_sup_1s("adas", Pum, &["asO"]); // TODO: others } #[test] fn sutra_7_2_108() { - use Vibhakti::*; - assert_has_subantas("idam", Stri, Prathama, Eka, &["iyam"]); - assert_has_subantas("idam", Pum, Prathama, Eka, &["ayam"]); + assert_has_sup_1s("idam", Stri, &["iyam"]); + assert_has_sup_1s("idam", Pum, &["ayam"]); } #[test] fn sutra_7_2_109() { - use Vibhakti::*; - assert_has_subantas("idam", Pum, Prathama, Dvi, &["imO"]); - assert_has_subantas("idam", Pum, Prathama, Bahu, &["ime"]); - assert_has_subantas("idam", Pum, Dvitiya, Eka, &["imam"]); - assert_has_subantas("idam", Pum, Dvitiya, Dvi, &["imO"]); - assert_has_subantas("idam", Pum, Dvitiya, Bahu, &["imAn"]); + assert_has_sup_1d("idam", Pum, &["imO"]); + assert_has_sup_1p("idam", Pum, &["ime"]); + assert_has_sup_2s("idam", Pum, &["imam"]); + assert_has_sup_2d("idam", Pum, &["imO"]); + assert_has_sup_2p("idam", Pum, &["imAn"]); } #[test] fn sutra_7_2_110() { - use Vibhakti::*; - assert_has_subantas("idam", Stri, Prathama, Eka, &["iyam"]); + assert_has_sup_1s("idam", Stri, &["iyam"]); } #[test] fn sutra_7_2_111() { - use Vibhakti::*; - assert_has_subantas("idam", Pum, Prathama, Eka, &["ayam"]); + assert_has_sup_1s("idam", Pum, &["ayam"]); // puMsi - assert_has_subantas("idam", Stri, Prathama, Eka, &["iyam"]); + assert_has_sup_1s("idam", Stri, &["iyam"]); } #[test] fn sutra_7_2_112() { - use Vibhakti::*; - assert_has_subantas("idam", Pum, Trtiya, Eka, &["anena"]); - assert_has_subantas("idam", Pum, Sasthi, Dvi, &["anayoH"]); + assert_has_sup_3s("idam", Pum, &["anena"]); + assert_has_sup_6d("idam", Pum, &["anayoH"]); // TODO: others } #[test] fn sutra_7_2_113() { - use Vibhakti::*; - assert_has_subantas("idam", Pum, Trtiya, Dvi, &["AByAm"]); - assert_has_subantas("idam", Pum, Trtiya, Bahu, &["eBiH"]); - assert_has_subantas("idam", Pum, Panchami, Bahu, &["eByaH"]); - assert_has_subantas("idam", Pum, Sasthi, Bahu, &["ezAm"]); - assert_has_subantas("idam", Pum, Saptami, Bahu, &["ezu"]); + assert_has_sup_3d("idam", Pum, &["AByAm"]); + assert_has_sup_3p("idam", Pum, &["eBiH"]); + assert_has_sup_5p("idam", Pum, &["eByaH"]); + assert_has_sup_6p("idam", Pum, &["ezAm"]); + assert_has_sup_7p("idam", Pum, &["ezu"]); // TODO: others } @@ -1516,14 +1492,13 @@ fn sutra_7_2_114() { #[test] fn sutra_7_2_115() { - use Vibhakti::*; - assert_has_subantas("saKi", Pum, Prathama, Dvi, &["saKAyO"]); - assert_has_subantas("saKi", Pum, Prathama, Bahu, &["saKAyaH"]); - assert_has_subantas("saKi", Pum, Dvitiya, Eka, &["saKAyam"]); - assert_has_subantas("saKi", Pum, Dvitiya, Dvi, &["saKAyO"]); - - assert_has_subantas("saKi", Pum, Trtiya, Eka, &["saKyA"]); - assert_has_subantas("saKi", Pum, Caturthi, Eka, &["saKye"]); + assert_has_sup_1d("saKi", Pum, &["saKAyO"]); + assert_has_sup_1p("saKi", Pum, &["saKAyaH"]); + assert_has_sup_2s("saKi", Pum, &["saKAyam"]); + assert_has_sup_2d("saKi", Pum, &["saKAyO"]); + + assert_has_sup_3s("saKi", Pum, &["saKyA"]); + assert_has_sup_4s("saKi", Pum, &["saKye"]); } #[test] diff --git a/vidyut-prakriya/tests/kashika_7_3.rs b/vidyut-prakriya/tests/kashika_7_3.rs index 9628416..f89d946 100644 --- a/vidyut-prakriya/tests/kashika_7_3.rs +++ b/vidyut-prakriya/tests/kashika_7_3.rs @@ -4,8 +4,6 @@ use vidyut_prakriya::args::Gana::*; use vidyut_prakriya::args::Lakara::*; use vidyut_prakriya::args::Linga::*; use vidyut_prakriya::args::Taddhita as T; -use vidyut_prakriya::args::Vacana::*; -use vidyut_prakriya::args::Vibhakti as V; use vidyut_prakriya::args::*; /// Shorthand for creating a nijanta dhAtu. @@ -785,235 +783,193 @@ fn sutra_7_3_101() { #[test] fn sutra_7_3_102() { - assert_has_subantas("vfkza", Pum, V::Caturthi, Eka, &["vfkzAya"]); - assert_has_subantas("plakza", Pum, V::Caturthi, Eka, &["plakzAya"]); - assert_has_subantas("vfkza", Pum, V::Caturthi, Dvi, &["vfkzAByAm"]); - assert_has_subantas("plakza", Pum, V::Caturthi, Dvi, &["plakzAByAm"]); + assert_has_sup_4s("vfkza", Pum, &["vfkzAya"]); + assert_has_sup_4s("plakza", Pum, &["plakzAya"]); + assert_has_sup_4d("vfkza", Pum, &["vfkzAByAm"]); + assert_has_sup_4d("plakza", Pum, &["plakzAByAm"]); // ataH - assert_has_subantas("agni", Pum, V::Caturthi, Dvi, &["agniByAm"]); + assert_has_sup_4d("agni", Pum, &["agniByAm"]); // yaYi - assert_has_subantas("vfkza", Pum, V::Sasthi, Eka, &["vfkzasya"]); - assert_has_subantas("plakza", Pum, V::Sasthi, Eka, &["plakzasya"]); + assert_has_sup_6s("vfkza", Pum, &["vfkzasya"]); + assert_has_sup_6s("plakza", Pum, &["plakzasya"]); } #[test] fn sutra_7_3_103() { - assert_has_subantas("vfkza", Pum, V::Caturthi, Bahu, &["vfkzeByaH"]); - assert_has_subantas("plakza", Pum, V::Caturthi, Bahu, &["plakzeByaH"]); - assert_has_subantas("vfkza", Pum, V::Saptami, Bahu, &["vfkzezu"]); - assert_has_subantas("plakza", Pum, V::Saptami, Bahu, &["plakzezu"]); + assert_has_sup_4p("vfkza", Pum, &["vfkzeByaH"]); + assert_has_sup_4p("plakza", Pum, &["plakzeByaH"]); + assert_has_sup_7p("vfkza", Pum, &["vfkzezu"]); + assert_has_sup_7p("plakza", Pum, &["plakzezu"]); // bahuvacane - assert_has_subantas("vfkza", Pum, V::Caturthi, Dvi, &["vfkzAByAm"]); - assert_has_subantas("plakza", Pum, V::Caturthi, Dvi, &["plakzAByAm"]); + assert_has_sup_4d("vfkza", Pum, &["vfkzAByAm"]); + assert_has_sup_4d("plakza", Pum, &["plakzAByAm"]); // Jali - assert_has_subantas("vfkza", Pum, V::Sasthi, Bahu, &["vfkzARAm"]); + assert_has_sup_6p("vfkza", Pum, &["vfkzARAm"]); // TODO: supi } #[test] fn sutra_7_3_104() { - assert_has_subantas("vfkza", Pum, V::Sasthi, Dvi, &["vfkzayoH"]); - assert_has_subantas("plakza", Pum, V::Sasthi, Dvi, &["plakzayoH"]); - assert_has_subantas("vfkza", Pum, V::Saptami, Dvi, &["vfkzayoH"]); - assert_has_subantas("plakza", Pum, V::Saptami, Dvi, &["plakzayoH"]); + assert_has_sup_6d("vfkza", Pum, &["vfkzayoH"]); + assert_has_sup_6d("plakza", Pum, &["plakzayoH"]); + assert_has_sup_7d("vfkza", Pum, &["vfkzayoH"]); + assert_has_sup_7d("plakza", Pum, &["plakzayoH"]); } #[test] fn sutra_7_3_105() { - use Vibhakti::*; - assert_has_subantas_p(&nyap("KawvA"), Stri, Trtiya, Eka, &["KawvayA"]); - assert_has_subantas_p(&nyap("mAlA"), Stri, Trtiya, Eka, &["mAlayA"]); - assert_has_subantas_p(&nyap("KawvA"), Stri, Sasthi, Dvi, &["KawvayoH"]); - assert_has_subantas_p(&nyap("mAlA"), Stri, Sasthi, Dvi, &["mAlayoH"]); - assert_has_subantas_p(&nyap("bahurAjA"), Stri, Trtiya, Eka, &["bahurAjayA"]); - assert_has_subantas_p( - &nyap("kArIzaganDyA"), - Stri, - Trtiya, - Eka, - &["kArIzaganDyayA"], - ); - assert_has_subantas_p(&nyap("bahurAjA"), Stri, Sasthi, Dvi, &["bahurAjayoH"]); - assert_has_subantas_p( - &nyap("kArIzaganDyA"), - Stri, - Sasthi, - Dvi, - &["kArIzaganDyayoH"], - ); + assert_has_sup_3s(&nyap("KawvA"), Stri, &["KawvayA"]); + assert_has_sup_3s(&nyap("mAlA"), Stri, &["mAlayA"]); + assert_has_sup_6d(&nyap("KawvA"), Stri, &["KawvayoH"]); + assert_has_sup_6d(&nyap("mAlA"), Stri, &["mAlayoH"]); + assert_has_sup_3s(&nyap("bahurAjA"), Stri, &["bahurAjayA"]); + assert_has_sup_3s(&nyap("kArIzaganDyA"), Stri, &["kArIzaganDyayA"]); + assert_has_sup_6d(&nyap("bahurAjA"), Stri, &["bahurAjayoH"]); + assert_has_sup_6d(&nyap("kArIzaganDyA"), Stri, &["kArIzaganDyayoH"]); // TODO: add others } #[test] fn sutra_7_3_106() { - assert_has_subantas_p(&nyap("KawvA"), Stri, V::Sambodhana, Eka, &["Kawve"]); - assert_has_subantas_p(&nyap("bahurAjA"), Stri, V::Sambodhana, Eka, &["bahurAje"]); - assert_has_subantas_p( - &nyap("kArIzaganDyA"), - Stri, - V::Sambodhana, - Eka, - &["kArIzaganDye"], - ); + assert_has_sup_ss(&nyap("KawvA"), Stri, &["Kawve"]); + assert_has_sup_ss(&nyap("bahurAjA"), Stri, &["bahurAje"]); + assert_has_sup_ss(&nyap("kArIzaganDyA"), Stri, &["kArIzaganDye"]); } #[test] fn sutra_7_3_107() { - assert_has_subantas_p(&nyap("ambA"), Stri, V::Sambodhana, Eka, &["amba"]); - assert_has_subantas_p(&nyap("akkA"), Stri, V::Sambodhana, Eka, &["akka"]); - assert_has_subantas_p(&nyap("allA"), Stri, V::Sambodhana, Eka, &["alla"]); + assert_has_sup_ss(&nyap("ambA"), Stri, &["amba"]); + assert_has_sup_ss(&nyap("akkA"), Stri, &["akka"]); + assert_has_sup_ss(&nyap("allA"), Stri, &["alla"]); // nadyoH - assert_has_subantas_p(&nyap("kumArI"), Stri, V::Sambodhana, Eka, &["kumAri"]); - assert_has_subantas_p( - &nyap("SArNgaravI"), - Stri, - V::Sambodhana, - Eka, - &["SArNgaravi"], - ); - assert_has_subantas("brahmabanDU", Stri, V::Sambodhana, Eka, &["brahmabanDu"]); - assert_has_subantas("vIrabanDU", Stri, V::Sambodhana, Eka, &["vIrabanDu"]); + assert_has_sup_ss(&nyap("kumArI"), Stri, &["kumAri"]); + assert_has_sup_ss(&nyap("SArNgaravI"), Stri, &["SArNgaravi"]); + assert_has_sup_ss("brahmabanDU", Stri, &["brahmabanDu"]); + assert_has_sup_ss("vIrabanDU", Stri, &["vIrabanDu"]); } #[test] fn sutra_7_3_108() { - assert_has_subantas("agni", Pum, V::Sambodhana, Eka, &["agne"]); - assert_has_subantas("vAyu", Pum, V::Sambodhana, Eka, &["vAyo"]); - assert_has_subantas("pawu", Pum, V::Sambodhana, Eka, &["pawo"]); + assert_has_sup_ss("agni", Pum, &["agne"]); + assert_has_sup_ss("vAyu", Pum, &["vAyo"]); + assert_has_sup_ss("pawu", Pum, &["pawo"]); // But, not for these because the prAtipadika was not originally hrasva - assert_has_subantas_p(&nyap("kumArI"), Stri, V::Sambodhana, Eka, &["kumAri"]); - assert_has_subantas("brahmabanDU", Stri, V::Sambodhana, Eka, &["brahmabanDu"]); + assert_has_sup_ss(&nyap("kumArI"), Stri, &["kumAri"]); + assert_has_sup_ss("brahmabanDU", Stri, &["brahmabanDu"]); } #[test] fn sutra_7_3_109() { - assert_has_subantas("agni", Pum, V::Prathama, Bahu, &["agnayaH"]); - assert_has_subantas("vAyu", Pum, V::Prathama, Bahu, &["vAyavaH"]); - assert_has_subantas("pawu", Pum, V::Prathama, Bahu, &["pawavaH"]); - assert_has_subantas("Denu", Stri, V::Prathama, Bahu, &["DenavaH"]); - assert_has_subantas("budDi", Stri, V::Prathama, Bahu, &["budDayaH"]); + assert_has_sup_1p("agni", Pum, &["agnayaH"]); + assert_has_sup_1p("vAyu", Pum, &["vAyavaH"]); + assert_has_sup_1p("pawu", Pum, &["pawavaH"]); + assert_has_sup_1p("Denu", Stri, &["DenavaH"]); + assert_has_sup_1p("budDi", Stri, &["budDayaH"]); } #[ignore] #[test] fn sutra_7_3_110() { - assert_has_subantas("mAtf", Stri, V::Saptami, Eka, &["mAtari"]); - assert_has_subantas("pitf", Pum, V::Saptami, Eka, &["pitari"]); - assert_has_subantas("BrAtf", Pum, V::Saptami, Eka, &["BrAtari"]); - assert_has_subantas("kartf", Pum, V::Saptami, Eka, &["kartari"]); + assert_has_sup_7s("mAtf", Stri, &["mAtari"]); + assert_has_sup_7s("pitf", Pum, &["pitari"]); + assert_has_sup_7s("BrAtf", Pum, &["BrAtari"]); + assert_has_sup_7s("kartf", Pum, &["kartari"]); // sarvanAmasTAne - assert_has_subantas("kartf", Pum, V::Prathama, Dvi, &["kartArO"]); - assert_has_subantas("kartf", Pum, V::Prathama, Bahu, &["kartAraH"]); - assert_has_subantas("mAtf", Stri, V::Prathama, Dvi, &["mAtarO"]); - assert_has_subantas("pitf", Pum, V::Prathama, Dvi, &["pitarO"]); - assert_has_subantas("BrAtf", Pum, V::Prathama, Dvi, &["BrAtarO"]); + assert_has_sup_1d("kartf", Pum, &["kartArO"]); + assert_has_sup_1p("kartf", Pum, &["kartAraH"]); + assert_has_sup_1d("mAtf", Stri, &["mAtarO"]); + assert_has_sup_1d("pitf", Pum, &["pitarO"]); + assert_has_sup_1d("BrAtf", Pum, &["BrAtarO"]); } #[test] fn sutra_7_3_111() { - assert_has_subantas("agni", Pum, V::Caturthi, Eka, &["agnaye"]); - assert_has_subantas("vAyu", Pum, V::Caturthi, Eka, &["vAyave"]); - assert_has_subantas("agni", Pum, V::Panchami, Eka, &["agneH"]); - assert_has_subantas("vAyu", Pum, V::Panchami, Eka, &["vAyoH"]); - assert_has_subantas("agni", Pum, V::Sasthi, Eka, &["agneH"]); - assert_has_subantas("vAyu", Pum, V::Sasthi, Eka, &["vAyoH"]); + assert_has_sup_4s("agni", Pum, &["agnaye"]); + assert_has_sup_4s("vAyu", Pum, &["vAyave"]); + assert_has_sup_5s("agni", Pum, &["agneH"]); + assert_has_sup_5s("vAyu", Pum, &["vAyoH"]); + assert_has_sup_6s("agni", Pum, &["agneH"]); + assert_has_sup_6s("vAyu", Pum, &["vAyoH"]); // GeH - assert_has_subantas("saKi", Pum, V::Caturthi, Eka, &["saKye"]); - assert_has_subantas("pati", Pum, V::Caturthi, Eka, &["patye"]); + assert_has_sup_4s("saKi", Pum, &["saKye"]); + assert_has_sup_4s("pati", Pum, &["patye"]); // Niti - assert_has_subantas("agni", Pum, V::Caturthi, Dvi, &["agniByAm"]); + assert_has_sup_4d("agni", Pum, &["agniByAm"]); // TODO: supi } #[test] fn sutra_7_3_112() { - assert_has_subantas("kumArI", Stri, V::Caturthi, Eka, &["kumAryE"]); - assert_has_subantas("brahmabanDU", Stri, V::Caturthi, Eka, &["brahmabanDvE"]); - assert_has_subantas("kumArI", Stri, V::Panchami, Eka, &["kumAryAH"]); - assert_has_subantas("brahmabanDU", Stri, V::Panchami, Eka, &["brahmabanDvAH"]); + assert_has_sup_4s("kumArI", Stri, &["kumAryE"]); + assert_has_sup_4s("brahmabanDU", Stri, &["brahmabanDvE"]); + assert_has_sup_5s("kumArI", Stri, &["kumAryAH"]); + assert_has_sup_5s("brahmabanDU", Stri, &["brahmabanDvAH"]); } #[test] fn sutra_7_3_113() { - use Vibhakti::*; - assert_has_subantas_p(&nyap("KawvA"), Stri, Caturthi, Eka, &["KawvAyE"]); - assert_has_subantas_p(&nyap("bahurAjA"), Stri, Caturthi, Eka, &["bahurAjAyE"]); - assert_has_subantas_p( - &nyap("kArIzaganDyA"), - Stri, - Caturthi, - Eka, - &["kArIzaganDyAyE"], - ); - assert_has_subantas_p(&nyap("KawvA"), Stri, Panchami, Eka, &["KawvAyAH"]); - assert_has_subantas_p(&nyap("bahurAjA"), Stri, Panchami, Eka, &["bahurAjAyAH"]); - assert_has_subantas_p( - &nyap("kArIzaganDyA"), - Stri, - Panchami, - Eka, - &["kArIzaganDyAyAH"], - ); + assert_has_sup_4s(&nyap("KawvA"), Stri, &["KawvAyE"]); + assert_has_sup_4s(&nyap("bahurAjA"), Stri, &["bahurAjAyE"]); + assert_has_sup_4s(&nyap("kArIzaganDyA"), Stri, &["kArIzaganDyAyE"]); + assert_has_sup_5s(&nyap("KawvA"), Stri, &["KawvAyAH"]); + assert_has_sup_5s(&nyap("bahurAjA"), Stri, &["bahurAjAyAH"]); + assert_has_sup_5s(&nyap("kArIzaganDyA"), Stri, &["kArIzaganDyAyAH"]); } #[ignore] #[test] fn sutra_7_3_114() { - use Vibhakti::*; - assert_has_subantas("sarva", Stri, Caturthi, Eka, &["sarvasyE"]); - assert_has_subantas("viSva", Stri, Caturthi, Eka, &["viSvasyE"]); - assert_has_subantas("yad", Stri, Caturthi, Eka, &["yasyE"]); - assert_has_subantas("tad", Stri, Caturthi, Eka, &["tasyE"]); - assert_has_subantas("kim", Stri, Caturthi, Eka, &["kasyE"]); - assert_has_subantas("anya", Stri, Caturthi, Eka, &["anyasyE"]); - assert_has_subantas("sarva", Stri, Panchami, Eka, &["sarvasyAH"]); - assert_has_subantas("viSva", Stri, Panchami, Eka, &["viSvasyAH"]); - assert_has_subantas("yad", Stri, Panchami, Eka, &["yasyAH"]); - assert_has_subantas("tad", Stri, Panchami, Eka, &["tasyAH"]); - assert_has_subantas("kim", Stri, Panchami, Eka, &["kasyAH"]); - assert_has_subantas("anya", Stri, Panchami, Eka, &["anyasyAH"]); + assert_has_sup_4s("sarva", Stri, &["sarvasyE"]); + assert_has_sup_4s("viSva", Stri, &["viSvasyE"]); + assert_has_sup_4s("yad", Stri, &["yasyE"]); + assert_has_sup_4s("tad", Stri, &["tasyE"]); + assert_has_sup_4s("kim", Stri, &["kasyE"]); + assert_has_sup_4s("anya", Stri, &["anyasyE"]); + assert_has_sup_5s("sarva", Stri, &["sarvasyAH"]); + assert_has_sup_5s("viSva", Stri, &["viSvasyAH"]); + assert_has_sup_5s("yad", Stri, &["yasyAH"]); + assert_has_sup_5s("tad", Stri, &["tasyAH"]); + assert_has_sup_5s("kim", Stri, &["kasyAH"]); + assert_has_sup_5s("anya", Stri, &["anyasyAH"]); // TODO: ApaH } #[test] fn sutra_7_3_116() { - assert_has_subantas_p(&nyap("kumArI"), Stri, V::Saptami, Eka, &["kumAryAm"]); - assert_has_subantas_p(&nyap("gOrI"), Stri, V::Saptami, Eka, &["gOryAm"]); - assert_has_subantas("brahmabanDU", Stri, V::Saptami, Eka, &["brahmabanDvAm"]); - assert_has_subantas("DIBanDU", Stri, V::Saptami, Eka, &["DIBanDvAm"]); + assert_has_sup_7s(&nyap("kumArI"), Stri, &["kumAryAm"]); + assert_has_sup_7s(&nyap("gOrI"), Stri, &["gOryAm"]); + assert_has_sup_7s("brahmabanDU", Stri, &["brahmabanDvAm"]); + assert_has_sup_7s("DIBanDU", Stri, &["DIBanDvAm"]); } #[test] fn sutra_7_3_117() { - use Vibhakti::*; - assert_has_subantas("kfti", Stri, Saptami, Eka, &["kftO", "kftyAm"]); - assert_has_subantas("Denu", Stri, Saptami, Eka, &["DenO", "DenvAm"]); + assert_has_sup_7s("kfti", Stri, &["kftO", "kftyAm"]); + assert_has_sup_7s("Denu", Stri, &["DenO", "DenvAm"]); } #[test] fn sutra_7_3_118() { - assert_has_subantas("saKi", Pum, V::Saptami, Eka, &["saKyO"]); - assert_has_subantas("pati", Pum, V::Saptami, Eka, &["patyO"]); + assert_has_sup_7s("saKi", Pum, &["saKyO"]); + assert_has_sup_7s("pati", Pum, &["patyO"]); } #[test] fn sutra_7_3_119() { - use Vibhakti::*; - assert_has_subantas("agni", Pum, Saptami, Eka, &["agnO"]); - assert_has_subantas("vAyu", Pum, Saptami, Eka, &["vAyO"]); - assert_has_subantas("kfti", Stri, Saptami, Eka, &["kftO", "kftyAm"]); - assert_has_subantas("Denu", Stri, Saptami, Eka, &["DenO", "DenvAm"]); - assert_has_subantas("pawu", Pum, Saptami, Eka, &["pawO"]); + assert_has_sup_7s("agni", Pum, &["agnO"]); + assert_has_sup_7s("vAyu", Pum, &["vAyO"]); + assert_has_sup_7s("kfti", Stri, &["kftO", "kftyAm"]); + assert_has_sup_7s("Denu", Stri, &["DenO", "DenvAm"]); + assert_has_sup_7s("pawu", Pum, &["pawO"]); } #[test] fn sutra_7_3_120() { - use Vibhakti::*; - assert_has_subantas("agni", Pum, Trtiya, Eka, &["agninA"]); - assert_has_subantas("vAyu", Pum, Trtiya, Eka, &["vAyunA"]); - assert_has_subantas("pawu", Pum, Trtiya, Eka, &["pawunA"]); + assert_has_sup_3s("agni", Pum, &["agninA"]); + assert_has_sup_3s("vAyu", Pum, &["vAyunA"]); + assert_has_sup_3s("pawu", Pum, &["pawunA"]); // astriyAm - assert_has_subantas("kfti", Stri, Trtiya, Eka, &["kftyA"]); - assert_has_subantas("Denu", Stri, Trtiya, Eka, &["DenvA"]); + assert_has_sup_3s("kfti", Stri, &["kftyA"]); + assert_has_sup_3s("Denu", Stri, &["DenvA"]); // TODO: others } diff --git a/vidyut-prakriya/tests/kashika_7_4.rs b/vidyut-prakriya/tests/kashika_7_4.rs index 9f42c3c..aee9d05 100644 --- a/vidyut-prakriya/tests/kashika_7_4.rs +++ b/vidyut-prakriya/tests/kashika_7_4.rs @@ -6,7 +6,6 @@ use vidyut_prakriya::args::Linga::*; use vidyut_prakriya::args::Purusha::*; use vidyut_prakriya::args::Taddhita as T; use vidyut_prakriya::args::Vacana::*; -use vidyut_prakriya::args::Vibhakti as V; use vidyut_prakriya::args::*; fn yan_san(dhatu: &Dhatu) -> Dhatu { @@ -436,10 +435,10 @@ fn sutra_7_4_47() { #[test] fn sutra_7_4_48() { - assert_has_subantas("ap", Pum, V::Trtiya, Bahu, &["adBiH"]); - assert_has_subantas("ap", Pum, V::Caturthi, Bahu, &["adByaH"]); + assert_has_sup_3p("ap", Pum, &["adBiH"]); + assert_has_sup_4p("ap", Pum, &["adByaH"]); // BiH? - assert_has_subantas("ap", Pum, V::Saptami, Bahu, &["apsu"]); + assert_has_sup_7p("ap", Pum, &["apsu"]); } #[test] diff --git a/vidyut-prakriya/tests/kashika_8_2.rs b/vidyut-prakriya/tests/kashika_8_2.rs index 90088df..5c74281 100644 --- a/vidyut-prakriya/tests/kashika_8_2.rs +++ b/vidyut-prakriya/tests/kashika_8_2.rs @@ -5,8 +5,6 @@ use vidyut_prakriya::args::Lakara::*; use vidyut_prakriya::args::Linga::*; use vidyut_prakriya::args::Taddhita as T; use vidyut_prakriya::args::TaddhitaArtha; -use vidyut_prakriya::args::Vacana::*; -use vidyut_prakriya::args::Vibhakti::*; use vidyut_prakriya::args::*; fn prati_udit(text: &str) -> Pratipadika { @@ -17,19 +15,11 @@ fn prati_udit(text: &str) -> Pratipadika { .unwrap() } -fn prati_dhatu(text: &str) -> Pratipadika { - Pratipadika::builder() - .text(text) - .is_dhatu(true) - .build() - .unwrap() -} - #[test] fn sutra_8_2_7() { - assert_has_subantas("rAjan", Pum, Prathama, Eka, &["rAjA"]); - assert_has_subantas("rAjan", Pum, Trtiya, Dvi, &["rAjaByAm"]); - assert_has_subantas("rAjan", Pum, Trtiya, Bahu, &["rAjaBiH"]); + assert_has_sup_1s("rAjan", Pum, &["rAjA"]); + assert_has_sup_3d("rAjan", Pum, &["rAjaByAm"]); + assert_has_sup_3p("rAjan", Pum, &["rAjaBiH"]); assert_has_taddhitanta(&prati("rAjan"), T::tal, &["rAjatA"]); assert_has_taddhitanta(&prati("rAjan"), T::tarap, &["rAjatara"]); assert_has_taddhitanta(&prati("rAjan"), T::tamap, &["rAjatama"]); @@ -37,8 +27,8 @@ fn sutra_8_2_7() { #[test] fn sutra_8_2_8() { - assert_has_subantas("rAjan", Pum, Sambodhana, Eka, &["rAjan"]); - assert_has_subantas("takzan", Pum, Sambodhana, Eka, &["takzan"]); + assert_has_sup_ss("rAjan", Pum, &["rAjan"]); + assert_has_sup_ss("takzan", Pum, &["takzan"]); } #[test] @@ -125,21 +115,21 @@ fn sutra_8_2_21() { #[test] fn sutra_8_2_23() { - assert_has_subantas_p(&prati_udit("gomat"), Pum, Prathama, Eka, &["gomAn"]); - assert_has_subantas_p(&prati_udit("yavamat"), Pum, Prathama, Eka, &["yavamAn"]); - assert_has_subantas_p(&prati_udit("kftavat"), Pum, Prathama, Eka, &["kftavAn"]); - assert_has_subantas_p(&prati_udit("hatavat"), Pum, Prathama, Eka, &["hatavAn"]); - assert_has_subantas_p(&prati_udit("Sreyas"), Pum, Prathama, Eka, &["SreyAn"]); - assert_has_subantas_p(&prati_udit("BUyas"), Pum, Prathama, Eka, &["BUyAn"]); + assert_has_sup_1s(&prati_udit("gomat"), Pum, &["gomAn"]); + assert_has_sup_1s(&prati_udit("yavamat"), Pum, &["yavamAn"]); + assert_has_sup_1s(&prati_udit("kftavat"), Pum, &["kftavAn"]); + assert_has_sup_1s(&prati_udit("hatavat"), Pum, &["hatavAn"]); + assert_has_sup_1s(&prati_udit("Sreyas"), Pum, &["SreyAn"]); + assert_has_sup_1s(&prati_udit("BUyas"), Pum, &["BUyAn"]); // TODO: others } #[ignore] #[test] fn sutra_8_2_24() { - assert_has_subantas("mAtf", Stri, Sasthi, Eka, &["mAtuH"]); - assert_has_subantas("pitf", Pum, Sasthi, Eka, &["pituH"]); - assert_has_subantas("Urj", Pum, Prathama, Eka, &["Urk"]); + assert_has_sup_6s("mAtf", Stri, &["mAtuH"]); + assert_has_sup_6s("pitf", Pum, &["pituH"]); + assert_has_sup_1s("Urj", Pum, &["Urk"]); assert_has_lan(&[], &d("mfjU~", Adadi), &["amArw"]); } @@ -262,14 +252,14 @@ fn sutra_8_2_31() { assert_has_krdanta(&[], &sah, Krt::tfc, &["soQf", "sahitf"]); assert_has_krdanta(&[], &sah, Krt::tumun, &["soQum", "sahitum"]); assert_has_krdanta(&[], &sah, Krt::tavya, &["soQavya", "sahitavya"]); - assert_has_subantas("jalAzAh", Pum, Prathama, Eka, &["jalAzAw"]); + assert_has_sup_1s("jalAzAh", Pum, &["jalAzAw"]); let vah = d("va\\ha~^", Bhvadi); assert_has_krdanta(&[], &vah, Krt::tfc, &["voQf"]); assert_has_krdanta(&[], &vah, Krt::tumun, &["voQum"]); assert_has_krdanta(&[], &vah, Krt::tavya, &["voQavya"]); - assert_has_subantas("prazWavAh", Pum, Prathama, Eka, &["prazWavAw"]); - assert_has_subantas("dityavAh", Pum, Prathama, Eka, &["dityavAw"]); + assert_has_sup_1s("prazWavAh", Pum, &["prazWavAw"]); + assert_has_sup_1s("dityavAh", Pum, &["dityavAw"]); } #[test] @@ -747,8 +737,8 @@ fn sutra_8_2_60() { #[test] fn sutra_8_2_68() { - assert_has_subantas("ahan", Pum, Trtiya, Dvi, &["ahoByAm"]); - assert_has_subantas("ahan", Pum, Trtiya, Bahu, &["ahoBiH"]); + assert_has_sup_3d("ahan", Pum, &["ahoByAm"]); + assert_has_sup_3p("ahan", Pum, &["ahoBiH"]); // TODO: others } @@ -759,8 +749,8 @@ fn sutra_8_2_69() { assert_has_sandhi("ahan", "BuNkte", &["ahar BuNkte"]); // a-supi? - assert_has_subantas("ahan", Pum, Trtiya, Dvi, &["ahoByAm"]); - assert_has_subantas("ahan", Pum, Trtiya, Bahu, &["ahoBiH"]); + assert_has_sup_3d("ahan", Pum, &["ahoByAm"]); + assert_has_sup_3p("ahan", Pum, &["ahoBiH"]); } #[test] @@ -787,10 +777,10 @@ fn sutra_8_2_75() { #[ignore] #[test] fn sutra_8_2_76() { - assert_has_subantas_p(&prati_dhatu("gir"), Pum, Prathama, Eka, &["gIH"]); - assert_has_subantas_p(&prati_dhatu("Dur"), Pum, Prathama, Eka, &["DUH"]); - assert_has_subantas_p(&prati_dhatu("pur"), Pum, Prathama, Eka, &["pUH"]); - assert_has_subantas_p(&prati_dhatu("ASis"), Pum, Prathama, Eka, &["pUH"]); + assert_has_sup_1s(&dhatu_prati("gir"), Pum, &["gIH"]); + assert_has_sup_1s(&dhatu_prati("Dur"), Pum, &["DUH"]); + assert_has_sup_1s(&dhatu_prati("pur"), Pum, &["pUH"]); + assert_has_sup_1s(&dhatu_prati("ASis"), Pum, &["pUH"]); } #[test] @@ -834,21 +824,21 @@ fn sutra_8_2_79() { #[ignore] #[test] fn sutra_8_2_80() { - assert_has_subantas("adas", Pum, Dvitiya, Eka, &["amum"]); - assert_has_subantas("adas", Pum, Dvitiya, Dvi, &["amU"]); - assert_has_subantas("adas", Pum, Dvitiya, Bahu, &["amUn"]); + assert_has_sup_2s("adas", Pum, &["amum"]); + assert_has_sup_2d("adas", Pum, &["amU"]); + assert_has_sup_2p("adas", Pum, &["amUn"]); // TODO: - // assert_has_subantas("adas", Pum, Trtiya, Eka, &["amunA"]); - assert_has_subantas("adas", Pum, Trtiya, Dvi, &["amUByAm"]); + // assert_has_sup_3s("adas", Pum, &["amunA"]); + assert_has_sup_3d("adas", Pum, &["amUByAm"]); // aseH - assert_has_subantas("adas", Napumsaka, Prathama, Eka, &["adaH"]); + assert_has_sup_1s("adas", Napumsaka, &["adaH"]); } #[test] fn sutra_8_2_81() { - assert_has_subantas("adas", Pum, Prathama, Bahu, &["amI"]); - assert_has_subantas("adas", Pum, Trtiya, Bahu, &["amIBiH"]); - assert_has_subantas("adas", Pum, Caturthi, Bahu, &["amIByaH"]); - assert_has_subantas("adas", Pum, Sasthi, Bahu, &["amIzAm"]); - assert_has_subantas("adas", Pum, Saptami, Bahu, &["amIzu"]); + assert_has_sup_1p("adas", Pum, &["amI"]); + assert_has_sup_3p("adas", Pum, &["amIBiH"]); + assert_has_sup_4p("adas", Pum, &["amIByaH"]); + assert_has_sup_6p("adas", Pum, &["amIzAm"]); + assert_has_sup_7p("adas", Pum, &["amIzu"]); } diff --git a/vidyut-prakriya/tests/kashika_8_3.rs b/vidyut-prakriya/tests/kashika_8_3.rs index e591e23..83d3a05 100644 --- a/vidyut-prakriya/tests/kashika_8_3.rs +++ b/vidyut-prakriya/tests/kashika_8_3.rs @@ -3,8 +3,6 @@ use test_utils::*; use vidyut_prakriya::args::Gana::*; use vidyut_prakriya::args::Lakara::*; use vidyut_prakriya::args::Linga::*; -use vidyut_prakriya::args::Vacana::*; -use vidyut_prakriya::args::Vibhakti as V; use vidyut_prakriya::args::*; #[test] @@ -30,8 +28,8 @@ fn sutra_8_3_15() { assert_has_sandhi("vfkzas", "tarati", &["vfkzas tarati"]); assert_has_sandhi("plakzas", "tarati", &["plakzas tarati"]); // avasAne - assert_has_subantas("vfkza", Pum, V::Prathama, Eka, &["vfkzaH"]); - assert_has_subantas("plakza", Pum, V::Prathama, Eka, &["plakzaH"]); + assert_has_sup_1s("vfkza", Pum, &["vfkzaH"]); + assert_has_sup_1s("plakza", Pum, &["plakzaH"]); // khar-avasAnayoH? assert_has_sandhi("agnis", "nayati", &["agnir nayati"]); @@ -41,25 +39,13 @@ fn sutra_8_3_15() { #[ignore] #[test] fn sutra_8_3_16() { - assert_has_subantas( - "payas", - Napumsaka, - V::Saptami, - Bahu, - &["payaHsu", "payassu"], - ); + assert_has_sup_7p("payas", Napumsaka, &["payaHsu", "payassu"]); // TODO: sarpizzu? - // assert_has_subantas("sarpis", Napumsaka, V::Saptami, Bahu, &["sarpiHzu"]); - assert_has_subantas( - "yaSas", - Napumsaka, - V::Saptami, - Bahu, - &["yaSaHsu", "yaSassu"], - ); + // assert_has_sup_7p("sarpis", Napumsaka, &["sarpiHzu"]); + assert_has_sup_7p("yaSas", Napumsaka, &["yaSaHsu", "yaSassu"]); // ruH - assert_has_subantas("gir", Napumsaka, V::Saptami, Bahu, &["gIrzu"]); - assert_has_subantas("Dur", Napumsaka, V::Saptami, Bahu, &["DUrzu"]); + assert_has_sup_7p("gir", Napumsaka, &["gIrzu"]); + assert_has_sup_7p("Dur", Napumsaka, &["DUrzu"]); } #[test] @@ -92,10 +78,10 @@ fn sutra_8_3_23() { #[ignore] #[test] fn sutra_8_3_24() { - assert_has_subantas("payas", Napumsaka, V::Prathama, Bahu, &["payAMsi"]); - assert_has_subantas("yaSas", Napumsaka, V::Prathama, Bahu, &["yaSAMsi"]); + assert_has_sup_1p("payas", Napumsaka, &["payAMsi"]); + assert_has_sup_1p("yaSas", Napumsaka, &["yaSAMsi"]); - assert_has_subantas("sarpis", Napumsaka, V::Prathama, Bahu, &["sarpIMzi"]); + assert_has_sup_1p("sarpis", Napumsaka, &["sarpIMzi"]); // makArasya let kram = d("kramu~", Bhvadi); @@ -146,8 +132,8 @@ fn sutra_8_3_36() { fn sutra_8_3_55() { assert_has_lit_p(&[], &d("zi\\ca~^", Tudadi), &["sizeca"]); assert_has_lit_p(&[], &d("Yizva\\pa~", Adadi), &["suzvApa"]); - assert_has_subantas("agni", Pum, V::Saptami, Bahu, &["agnizu"]); - assert_has_subantas("vAyu", Pum, V::Saptami, Bahu, &["vAyuzu"]); + assert_has_sup_7p("agni", Pum, &["agnizu"]); + assert_has_sup_7p("vAyu", Pum, &["vAyuzu"]); let kf = d("qukf\\Y", Tanadi); assert_has_dhvam(&[], &kf, Lun, &["akfQvam"]); diff --git a/vidyut-prakriya/tests/kashika_8_4.rs b/vidyut-prakriya/tests/kashika_8_4.rs index f577861..2f1ce0d 100644 --- a/vidyut-prakriya/tests/kashika_8_4.rs +++ b/vidyut-prakriya/tests/kashika_8_4.rs @@ -4,8 +4,6 @@ use vidyut_prakriya::args::Gana::*; use vidyut_prakriya::args::Lakara::*; use vidyut_prakriya::args::Linga::*; use vidyut_prakriya::args::Taddhita as T; -use vidyut_prakriya::args::Vacana::*; -use vidyut_prakriya::args::Vibhakti as V; use vidyut_prakriya::args::*; #[test] @@ -27,31 +25,31 @@ fn sutra_8_4_1() { #[ignore] #[test] fn sutra_8_4_1_v1() { - assert_has_subantas_p(&nyap("tri"), Stri, V::Sasthi, Bahu, &["tisfRAm"]); - assert_has_subantas_p(&nyap("catur"), Stri, V::Sasthi, Bahu, &["catasfRAm"]); - assert_has_subantas_p(&nyap("mAtf"), Stri, V::Sasthi, Bahu, &["mAtFRAm"]); - assert_has_subantas("pitf", Pum, V::Sasthi, Bahu, &["pitFRAm"]); + assert_has_sup_6p(&nyap("tri"), Stri, &["tisfRAm"]); + assert_has_sup_6p(&nyap("catur"), Stri, &["catasfRAm"]); + assert_has_sup_6p(&nyap("mAtf"), Stri, &["mAtFRAm"]); + assert_has_sup_6p("pitf", Pum, &["pitFRAm"]); } #[test] fn sutra_8_4_2() { assert_has_krdanta(&[], &d("qukf\\Y", Tanadi), Krt::lyuw, &["karaRa"]); assert_has_krdanta(&[], &d("hf\\Y", Bhvadi), Krt::lyuw, &["haraRa"]); - assert_has_subantas("kiri", Pum, V::Trtiya, Eka, &["kiriRA"]); - assert_has_subantas("giri", Pum, V::Trtiya, Eka, &["giriRA"]); - assert_has_subantas("kuru", Pum, V::Trtiya, Eka, &["kuruRA"]); - assert_has_subantas("guru", Pum, V::Trtiya, Eka, &["guruRA"]); + assert_has_sup_3s("kiri", Pum, &["kiriRA"]); + assert_has_sup_3s("giri", Pum, &["giriRA"]); + assert_has_sup_3s("kuru", Pum, &["kuruRA"]); + assert_has_sup_3s("guru", Pum, &["guruRA"]); // kavarga - assert_has_subantas("arka", Pum, V::Trtiya, Eka, &["arkeRa"]); - assert_has_subantas("mUrKa", Pum, V::Trtiya, Eka, &["mUrKeRa"]); - assert_has_subantas("garga", Pum, V::Trtiya, Eka, &["gargeRa"]); - assert_has_subantas("arGa", Pum, V::Trtiya, Eka, &["arGeRa"]); + assert_has_sup_3s("arka", Pum, &["arkeRa"]); + assert_has_sup_3s("mUrKa", Pum, &["mUrKeRa"]); + assert_has_sup_3s("garga", Pum, &["gargeRa"]); + assert_has_sup_3s("arGa", Pum, &["arGeRa"]); // pavarga - assert_has_subantas("darpa", Pum, V::Trtiya, Eka, &["darpeRa"]); - assert_has_subantas("rePa", Pum, V::Trtiya, Eka, &["rePeRa"]); - assert_has_subantas("garBa", Pum, V::Trtiya, Eka, &["garBeRa"]); - assert_has_subantas("carman", Pum, V::Trtiya, Eka, &["carmaRA"]); - assert_has_subantas("varman", Pum, V::Trtiya, Eka, &["varmaRA"]); + assert_has_sup_3s("darpa", Pum, &["darpeRa"]); + assert_has_sup_3s("rePa", Pum, &["rePeRa"]); + assert_has_sup_3s("garBa", Pum, &["garBeRa"]); + assert_has_sup_3s("carman", Pum, &["carmaRA"]); + assert_has_sup_3s("varman", Pum, &["varmaRA"]); // AN let nah = d("Ra\\ha~^", Divadi); @@ -282,10 +280,10 @@ fn sutra_8_4_36() { #[test] fn sutra_8_4_37() { - assert_has_subantas("vfkza", Pum, V::Dvitiya, Bahu, &["vfkzAn"]); - assert_has_subantas("plakza", Pum, V::Dvitiya, Bahu, &["plakzAn"]); - assert_has_subantas("ari", Pum, V::Dvitiya, Bahu, &["arIn"]); - assert_has_subantas("giri", Pum, V::Dvitiya, Bahu, &["girIn"]); + assert_has_sup_2p("vfkza", Pum, &["vfkzAn"]); + assert_has_sup_2p("plakza", Pum, &["plakzAn"]); + assert_has_sup_2p("ari", Pum, &["arIn"]); + assert_has_sup_2p("giri", Pum, &["girIn"]); } #[test] @@ -367,7 +365,7 @@ fn sutra_8_4_42() { // woH? assert_has_taddhitanta(&prati("sarpis"), T::tamap, &["sarpizwama"]); // // an-Am? - assert_has_subantas("zaz", Pum, V::Sasthi, Bahu, &["zaRRAm"]); + assert_has_sup_6p("zaz", Pum, &["zaRRAm"]); } #[test] @@ -441,10 +439,12 @@ fn sutra_8_4_55() { #[test] fn sutra_8_4_56() { - assert_has_subantas_raw("vAc", Stri, V::Prathama, Eka, &["vAk", "vAg"]); - assert_has_subantas_raw("tvac", Stri, V::Prathama, Eka, &["tvak", "tvag"]); - assert_has_subantas_raw("Svalih", Stri, V::Prathama, Eka, &["Svaliw", "Svaliq"]); - assert_has_subantas_raw("trizwuB", Stri, V::Prathama, Eka, &["trizwup", "trizwub"]); + use Vacana::*; + use Vibhakti::*; + assert_has_subantas_raw("vAc", Stri, Prathama, Eka, &["vAk", "vAg"]); + assert_has_subantas_raw("tvac", Stri, Prathama, Eka, &["tvak", "tvag"]); + assert_has_subantas_raw("Svalih", Stri, Prathama, Eka, &["Svaliw", "Svaliq"]); + assert_has_subantas_raw("trizwuB", Stri, Prathama, Eka, &["trizwup", "trizwub"]); } #[test] diff --git a/vidyut-prakriya/tests/kaumudi_10.rs b/vidyut-prakriya/tests/kaumudi_10.rs new file mode 100644 index 0000000..2dbded4 --- /dev/null +++ b/vidyut-prakriya/tests/kaumudi_10.rs @@ -0,0 +1,48 @@ +extern crate test_utils; +use test_utils::*; +use vidyut_prakriya::args::Linga::*; + +#[test] +fn sk_309() { + assert_has_sup_1s("jYAna", Napumsaka, &["jYAnam"]); + assert_has_sup_ss("jYAna", Napumsaka, &["jYAna"]); +} + +#[test] +fn skip_sk_310() {} + +#[test] +fn sk_311() { + assert_has_sup_1d("jYAna", Napumsaka, &["jYAne"]); +} + +#[test] +fn skip_sk_312_to_sk_313() {} + +#[test] +fn sk_315() { + assert_has_sup_1p("jYAna", Napumsaka, &["jYAnAni"]); +} + +#[test] +fn skip_sk_316() {} + +#[test] +fn sk_319() { + assert_has_sup_1s("vAri", Napumsaka, &["vAri"]); +} + +#[ignore] +#[test] +fn sk_320() { + assert_has_sup_1d("vAri", Napumsaka, &["vAriRI"]); + assert_has_sup_1p("vAri", Napumsaka, &["vArIRi"]); + assert_has_sup_ss("vAri", Napumsaka, &["vAri", "vAre"]); + assert_has_sup_3s("vAri", Napumsaka, &["vAriRA"]); + assert_has_sup_4s("vAri", Napumsaka, &["vAriRe"]); + assert_has_sup_5s("vAri", Napumsaka, &["vAriRaH"]); + assert_has_sup_6d("vAri", Napumsaka, &["vAriRoH"]); + assert_has_sup_6p("vAri", Napumsaka, &["vArIRAm"]); + assert_has_sup_7s("vAri", Napumsaka, &["vArIRi"]); + assert_has_sup_7d("vAri", Napumsaka, &["vArIRoH"]); +} diff --git a/vidyut-prakriya/tests/kaumudi_60.rs b/vidyut-prakriya/tests/kaumudi_60.rs index 85ce4d6..44c4e50 100644 --- a/vidyut-prakriya/tests/kaumudi_60.rs +++ b/vidyut-prakriya/tests/kaumudi_60.rs @@ -38,8 +38,22 @@ fn sk_2685() { assert_has_lat(&["parA"], &ji, &["parAjayate"]); } +#[test] +fn sk_2696_to_sk_2697() { + let han = d("ha\\na~", Adadi); + assert_has_ta(&["AN"], &han, Lun, &["Ahata", "AvaDizwa"]); + assert_has_aataam(&["AN"], &han, Lun, &["AhasAtAm", "AvaDizAtAm"]); + assert_has_jha(&["AN"], &han, Lun, &["Ahasata", "AvaDizata"]); +} + #[test] fn sk_2699() { let gam = d("ga\\mx~", Bhvadi); assert_has_ta(&["sam"], &gam, Lat, &["saNgacCate"]); } + +#[test] +fn sk_2703() { + let hve = d("hve\\Y", Bhvadi); + assert_has_ta(&["ni"], &hve, Lat, &["nihvayate"]); +} diff --git a/vidyut-prakriya/tests/kaumudi_65.rs b/vidyut-prakriya/tests/kaumudi_65.rs new file mode 100644 index 0000000..16fcfdd --- /dev/null +++ b/vidyut-prakriya/tests/kaumudi_65.rs @@ -0,0 +1,45 @@ +extern crate test_utils; +use test_utils::*; +use vidyut_prakriya::args::Dhatu; +use vidyut_prakriya::args::Gana::*; +use vidyut_prakriya::args::Krt; +use vidyut_prakriya::args::Krt::*; + +fn assert_has_krt(prefixes: &[&str], dhatu: &Dhatu, krt: Krt, expected: &[&str]) { + assert_has_krdanta(prefixes, dhatu, krt, expected) +} + +#[test] +fn skip_sk_2829_to_sk_2833() {} + +#[test] +fn sk_2834() { + let edh = d("eDa~\\", Bhvadi); + assert_has_krt(&[], &edh, tavya, &["eDitavya"]); + assert_has_krt(&[], &edh, anIyar, &["eDanIya"]); + + let vas = d("va\\sa~", Bhvadi); + assert_has_krt(&[], &vas, tavyat, &["vastavya", "vAstavya"]); + + let pac = d("qupa\\ca~^z", Bhvadi); + assert_has_krt(&[], &pac, kelimar, &["pacelima"]); + assert_has_krt(&[], &pac, tavya, &["paktavya"]); + + let bhid = d("Bi\\di~^r", Rudhadi); + assert_has_krt(&[], &bhid, tavya, &["Bettavya"]); +} + +#[test] +fn sk_2847() { + let shak = d("Sa\\kx~", Svadi); + assert_has_krt(&[], &shak, yat, &["Sakya"]); + + let sah = d("zaha~\\", Bhvadi); + assert_has_krt(&[], &sah, yat, &["sahya"]); +} + +#[test] +fn sk_2860() { + let x = d("Kanu~^", Bhvadi); + assert_has_krt(&[], &x, kyap, &["Keya"]); +} diff --git a/vidyut-prakriya/tests/kaumudi_67.rs b/vidyut-prakriya/tests/kaumudi_67.rs index 953b5a2..ae1403c 100644 --- a/vidyut-prakriya/tests/kaumudi_67.rs +++ b/vidyut-prakriya/tests/kaumudi_67.rs @@ -50,18 +50,6 @@ fn unadi_1_77() { assert_has_krdanta(&[], &d("qukf\\Y", Tanadi), Krt::katu, &["kratu"]); } -#[test] -fn unadi_1_144() { - use Krt::manin; - assert_has_krdanta(&[], &d("qukf\\Y", Tanadi), manin, &["karman"]); - assert_has_krdanta(&[], &d("cara~", Bhvadi), manin, &["carman"]); - assert_has_krdanta(&[], &d("Basa~", Juhotyadi), manin, &["Basman"]); - assert_has_krdanta(&[], &d("janI~\\", Divadi), manin, &["janman"]); - assert_has_krdanta(&[], &d("SF", Kryadi), manin, &["Sarman"]); - assert_has_krdanta(&[], &d("Cada~", Curadi), manin, &["Cadman"]); - // TODO: sutrAman -} - #[test] fn unadi_2_2() { assert_has_krdanta(&[], &d("ha\\na~", Adadi), Krt::kTan, &["haTa"]); @@ -81,6 +69,40 @@ fn unadi_2_108() { // TODO: id-anta? } +#[test] +fn unadi_2_115() { + assert_has_krdanta(&[], &d("janI~\\", Divadi), Krt::usi, &["janus"]); +} + +#[test] +fn unadi_2_117() { + use Krt::usi; + assert_has_krdanta(&[], &d("f\\", Bhvadi), usi, &["arus"]); + assert_has_krdanta(&[], &d("pF", Kryadi), usi, &["parus"]); + assert_has_krdanta(&[], &d("quva\\pa~^", Bhvadi), usi, &["vapus"]); + assert_has_krdanta(&[], &d("ya\\ja~^", Bhvadi), usi, &["yajus"]); + assert_has_krdanta(&[], &d("tanu~^", Tanadi), usi, &["tanus"]); + assert_has_krdanta(&[], &d("Dana~", Juhotyadi), usi, &["Danus"]); + assert_has_krdanta(&[], &d("ta\\pa~", Bhvadi), usi, &["tapus"]); + // TODO: tanuzI, tanUMzi +} + +#[test] +fn unadi_2_118() { + assert_has_krdanta(&[], &d("i\\R", Adadi), Krt::usi, &["Ayus"]); + // TODO: AyuzI +} + +#[test] +fn unadi_2_119() { + assert_has_krdanta(&[], &d("ca\\kzi~\\N", Adadi), Krt::usi, &["cakzus"]); +} + +#[test] +fn unadi_2_120() { + assert_has_krdanta(&[], &d("mu\\ha~", Divadi), Krt::usi, &["muhus"]); +} + #[ignore] #[test] fn unadi_3_29() { @@ -248,6 +270,41 @@ fn unadi_4_54() { assert_has_krdanta(&[], &d("jAgf", Adadi), Krt::kvinUnadi, &["jAgfvi"]); } +#[ignore] +#[test] +fn unadi_4_117() { + use Krt::in_; + assert_has_krdanta(&[], &d("qupa\\ca~^z", Bhvadi), in_, &["paci"]); + assert_has_krdanta(&[], &d("tuqa~", Tudadi), in_, &["tuqi"]); + assert_has_krdanta(&[], &d("tuqi~\\", Bhvadi), in_, &["tuRqi"]); + assert_has_krdanta(&[], &d("vala~\\", Bhvadi), in_, &["vali"]); + assert_has_krdanta(&[], &d("vawa~", Bhvadi), in_, &["vawi"]); + assert_has_krdanta(&[], &d("ya\\ja~^", Bhvadi), in_, &["yaji"]); + assert_has_upapada_krdanta("deva", &[], &d("ya\\ja~^", Bhvadi), in_, &["devayaji"]); + assert_has_krdanta(&[], &d("kASf~\\", Bhvadi), in_, &["kASi"]); + assert_has_krdanta(&[], &d("yatI~\\", Bhvadi), in_, &["yati"]); + assert_has_krdanta(&[], &d("malla~\\", Bhvadi), in_, &["malli"]); + assert_has_krdanta(&[], &d("kila~", Tudadi), in_, &["keli"]); + assert_has_krdanta(&[], &d("masI~", Divadi), in_, &["masi"]); + assert_has_krdanta(&[], &d("kuwa~", Tudadi), in_, &["kowi"]); + assert_has_krdanta(&[], &d("hila~", Tudadi), in_, &["heli"]); + assert_has_krdanta(&[], &d("buDa~", Bhvadi), in_, &["boDi"]); + assert_has_krdanta(&[], &d("wunadi~", Bhvadi), in_, &["nandi"]); + assert_has_krdanta(&[], &d("kala~\\", Bhvadi), in_, &["kali"]); +} + +#[test] +fn unadi_4_144() { + use Krt::manin; + assert_has_krdanta(&[], &d("qukf\\Y", Tanadi), manin, &["karman"]); + assert_has_krdanta(&[], &d("cara~", Bhvadi), manin, &["carman"]); + assert_has_krdanta(&[], &d("Basa~", Juhotyadi), manin, &["Basman"]); + assert_has_krdanta(&[], &d("janI~\\", Divadi), manin, &["janman"]); + assert_has_krdanta(&[], &d("SF", Kryadi), manin, &["Sarman"]); + assert_has_krdanta(&[], &d("Cada~", Curadi), manin, &["Cadman"]); + // TODO: sutrAman +} + #[test] fn unadi_4_158() { assert_has_krdanta(&[], &d("vasa~\\", Adadi), Krt::zwran, &["vastra"]); @@ -255,6 +312,20 @@ fn unadi_4_158() { assert_has_krdanta(&[], &d("Sasu~", Bhvadi), Krt::zwran, &["Sastra"]); } +#[test] +fn unadi_4_188() { + use Krt::asun; + assert_has_krdanta(&[], &d("citI~", Bhvadi), asun, &["cetas"]); + assert_has_krdanta(&[], &d("sf\\", Bhvadi), asun, &["saras"]); + assert_has_krdanta(&[], &d("pI\\N", Divadi), asun, &["payas"]); + assert_has_krdanta(&[], &d("za\\dx~", Bhvadi), asun, &["sadas"]); +} + +#[test] +fn unadi_4_189() { + assert_has_krdanta(&[], &d("rapa~", Bhvadi), Krt::asun, &["repas"]); +} + #[test] fn unadi_5_68() { assert_has_krdanta(&[], &d("praTa~\\", Bhvadi), Krt::amac, &["praTama"]); diff --git a/vidyut-prakriya/tests/kaumudi_9.rs b/vidyut-prakriya/tests/kaumudi_9.rs index 2dbded4..bafd27a 100644 --- a/vidyut-prakriya/tests/kaumudi_9.rs +++ b/vidyut-prakriya/tests/kaumudi_9.rs @@ -3,46 +3,101 @@ use test_utils::*; use vidyut_prakriya::args::Linga::*; #[test] -fn sk_309() { - assert_has_sup_1s("jYAna", Napumsaka, &["jYAnam"]); - assert_has_sup_ss("jYAna", Napumsaka, &["jYAna"]); +fn sk_287() { + let rama = nyap("ramA"); + assert_has_sup_1d(&rama, Stri, &["rame"]); + assert_has_sup_1p(&rama, Stri, &["ramAH"]); } #[test] -fn skip_sk_310() {} +fn sk_288() { + let rama = nyap("ramA"); + assert_has_sup_ss(&rama, Stri, &["rame"]); + assert_has_sup_sd(&rama, Stri, &["rame"]); + assert_has_sup_sp(&rama, Stri, &["ramAH"]); + assert_has_sup_2s(&rama, Stri, &["ramAm"]); + assert_has_sup_2d(&rama, Stri, &["rame"]); + assert_has_sup_2p(&rama, Stri, &["ramAH"]); +} + +#[test] +fn sk_289() { + let rama = nyap("ramA"); + assert_has_sup_3s(&rama, Stri, &["ramayA"]); + assert_has_sup_3d(&rama, Stri, &["ramAByAm"]); + assert_has_sup_3p(&rama, Stri, &["ramABiH"]); +} + +#[test] +fn sk_290() { + let rama = nyap("ramA"); + assert_has_sup_4s(&rama, Stri, &["ramAyE"]); + assert_has_sup_6s(&rama, Stri, &["ramAyAH"]); + assert_has_sup_6d(&rama, Stri, &["ramayoH"]); + assert_has_sup_6p(&rama, Stri, &["ramARAm"]); + assert_has_sup_7s(&rama, Stri, &["ramAyAm"]); + assert_has_sup_7d(&rama, Stri, &["ramayoH"]); + assert_has_sup_7p(&rama, Stri, &["ramAsu"]); +} + +#[test] +fn sk_291() { + assert_has_sup_4s("sarva", Stri, &["sarvasyE"]); + assert_has_sup_5s("sarva", Stri, &["sarvasyAH"]); + assert_has_sup_7s("sarva", Stri, &["sarvasyAm"]); + assert_has_sup_7d("sarva", Stri, &["sarvayoH"]); + assert_has_sup_7p("sarva", Stri, &["sarvAsu"]); +} #[test] -fn sk_311() { - assert_has_sup_1d("jYAna", Napumsaka, &["jYAne"]); +fn sk_296() { + assert_has_sup_4s("mati", Stri, &["matyE", "mataye"]); + assert_has_sup_5s("mati", Stri, &["matyAH", "mateH"]); + assert_has_sup_6s("mati", Stri, &["matyAH", "mateH"]); } #[test] -fn skip_sk_312_to_sk_313() {} +fn skip_sk_298() {} #[test] -fn sk_315() { - assert_has_sup_1p("jYAna", Napumsaka, &["jYAnAni"]); +fn sk_299() { + assert_has_sup_1p("tri", Stri, &["tisraH"]); + assert_has_sup_2p("tri", Stri, &["tisraH"]); } +#[ignore] #[test] -fn skip_sk_316() {} +fn sk_300() { + assert_has_sup_6p("tri", Stri, &["tisfRAm"]); + assert_has_sup_7p("tri", Stri, &["tisfzu"]); + // TODO: others +} #[test] -fn sk_319() { - assert_has_sup_1s("vAri", Napumsaka, &["vAri"]); +fn sk_301() { + assert_has_sup_1d("strI", Stri, &["striyO"]); + assert_has_sup_1p("strI", Stri, &["striyaH"]); } +#[test] +fn sk_303() { + let shri = dhatu_prati("SrI"); + assert_has_sup_ss(&shri, Stri, &["SrIH"]); + assert_has_sup_4s(&shri, Stri, &["Sriye", "SriyE"]); + assert_has_sup_5s(&shri, Stri, &["SriyAH", "SriyaH"]); +} + +#[test] +fn skip_sk_305() {} + #[ignore] #[test] -fn sk_320() { - assert_has_sup_1d("vAri", Napumsaka, &["vAriRI"]); - assert_has_sup_1p("vAri", Napumsaka, &["vArIRi"]); - assert_has_sup_ss("vAri", Napumsaka, &["vAri", "vAre"]); - assert_has_sup_3s("vAri", Napumsaka, &["vAriRA"]); - assert_has_sup_4s("vAri", Napumsaka, &["vAriRe"]); - assert_has_sup_5s("vAri", Napumsaka, &["vAriRaH"]); - assert_has_sup_6d("vAri", Napumsaka, &["vAriRoH"]); - assert_has_sup_6p("vAri", Napumsaka, &["vArIRAm"]); - assert_has_sup_7s("vAri", Napumsaka, &["vArIRi"]); - assert_has_sup_7d("vAri", Napumsaka, &["vArIRoH"]); +fn sk_306() { + assert_has_sup_1s("krozwf", Stri, &["krozwrI"]); + assert_has_sup_1d("krozwf", Stri, &["krozwryO"]); + assert_has_sup_1p("krozwf", Stri, &["krozwryaH"]); + + assert_has_sup_1s("vaDU", Stri, &["vaDUH"]); + assert_has_sup_1s("BU", Stri, &["BUH"]); + assert_has_sup_ss("suBrU", Stri, &["suBrUH"]); } diff --git a/vidyut-prakriya/www/static/app.js b/vidyut-prakriya/www/static/app.js index 1ab117a..30dae31 100644 --- a/vidyut-prakriya/www/static/app.js +++ b/vidyut-prakriya/www/static/app.js @@ -1,3 +1,23 @@ +/** + * A simple demo interface for vidyut-prakriya. + * + * + * Outline + * ======= + * + * Focus on `App`, which contains the main code. We use the Alpine framework, + * which you can think of as a lightweight version of Vue. + * + * + * Constraints + * =========== + * - This demo is served on GitHub pages. So, no databases -- everything should + * be done client side! + * - This demo should use our wasm build's public API. + * - Although this is a production site, the stakes are low -- do things the + * hacky way if that fixes the problem. + */ + import init, { Krt, Vidyut, Gana, Lakara, Prayoga, Purusha, Vacana, Pada, Sanadi, Linga, Vibhakti } from "/static/wasm/vidyut_prakriya.js"; // Krts that create ordinary nouns. @@ -5,8 +25,8 @@ const NOMINAL_KRTS = [ Krt.GaY, Krt.lyuw, Krt.Rvul, + Krt.tfc, Krt.kvip, - Krt.kvin, ]; // Krts that are generally called *participles*. @@ -30,8 +50,18 @@ const PARTICIPLE_KRTS = [ const AVYAYA_KRTS = [ Krt.tumun, Krt.ktvA, + Krt.Ramul, ]; +const Params = { + Dhatu: "dhatu", + Tab: "tab", + Pada: "pada", + Prayoga: "prayoga", + Sanadi: "sanadi", + ActivePada: "activePada", +} + // Turn the TSV file sutrapatha.tsv into a map. function parseSutras(tsv) { let sutras = {}; @@ -84,6 +114,7 @@ function removeSlpSvaras(s) { return s.replaceAll(/[\^\\]/g, ''); } +// Parse a dhatupatha string into separate objects. function parseDhatus(text) { let dhatus = []; text.split(/\r?\n/).forEach((line) => { @@ -100,6 +131,7 @@ function parseDhatus(text) { return dhatus; } +// Load and initialize the Vidyut API. async function loadVidyut() { await init(); @@ -107,18 +139,14 @@ async function loadVidyut() { const text = await resp.text(); return { + // Vidyut needs its own copy of the dhatupatha. vidyut: Vidyut.init(text), + // For JS use dhatus: parseDhatus(text), } } const App = () => ({ - ganas: Gana, - lakaras: Lakara, - prayogas: Prayoga, - purushas: Purusha, - vacanas: Vacana, - activeTab: 'dhatu', // All dhatus. @@ -142,7 +170,6 @@ const App = () => ({ dhatuFilter: null, // Transliteration script (devanagari, iast, telugu, etc.) - // devanagari is default script: 'devanagari', async init() { @@ -155,6 +182,7 @@ const App = () => ({ // wait for the dhatus to load so that we can set activeDhatu. this.readUrlState(); + // Save important properties to the URL when they change. this.$watch('activeDhatu', (value) => { this.updateUrlState(); }); @@ -170,17 +198,22 @@ const App = () => ({ this.$watch('upasarga', (value) => { this.updateUrlState(); }); + this.$watch('activePada', (value) => { + this.updateUrlState(); + }); }, // Mutators + // Load the application state from the URL, if applicable. readUrlState() { const params = new URLSearchParams(window.location.search); - const dhatuCode = params.get('dhatu'); - const tab = params.get('tab'); - const prayoga = params.get('prayoga'); - const upasarga = params.get('upasarga'); - const sanadi = params.get('sanadi'); + const dhatuCode = params.get(Params.Dhatu); + const tab = params.get(Params.Tab); + const prayoga = params.get(Params.Prayoga); + const upasarga = params.get(Params.Upasarga); + const sanadi = params.get(Params.Sanadi); + const activePada = params.get(Params.ActivePada); console.log(`realUrlState, prayoga=${prayoga}, upasarga=${upasarga}, sanadi=${sanadi}`); if (tab) { @@ -198,42 +231,56 @@ const App = () => ({ if (dhatuCode) { this.setActiveDhatu(dhatuCode); } + if (activePada) { + this.setActivePada(JSON.parse(activePada)); + } }, + // Encode the current application state in the URL so that it can be + // referenced later. updateUrlState() { const url = new URL(window.location.href); let dhatuCode = null; if (this.activeDhatu) { dhatuCode = this.activeDhatu.code; } - setParam(url, "dhatu", dhatuCode); - setParam(url, "tab", this.activeTab); - setParam(url, "prayoga", this.prayoga); - setParam(url, "sanadi", this.sanadi); - setParam(url, "upasarga", this.upasarga); + setParam(url, Params.Dhatu, dhatuCode); + setParam(url, Params.Tab, this.activeTab); + setParam(url, Params.Prayoga, this.prayoga); + setParam(url, Params.Sanadi, this.sanadi); + setParam(url, Params.Upasarga, this.upasarga); + if (this.activePada) { + setParam(url, Params.ActivePada, JSON.stringify(this.activePada)); + } else { + setParam(url, Params.ActivePada, null); + } console.log("updateUrlState to: ", url); history.replaceState(null, document.title, url.toString()); }, + // Set the active dhatu (and show its forms) setActiveDhatu(s) { this.activeDhatu = this.dhatus.find(d => d.code === s); // Scroll position might be off if the user has scrolled far down the dhatu list. window.scrollTo({ top: 0 }); }, + // Set the active pada (and show its prakriya) setActivePada(p) { this.activePada = p; this.prakriya = this.createPrakriya(); window.scrollTo({ top: 0 }); }, + // Create the active pada (and show all forms for the dhatu) clearActivePada() { this.activePada = null; this.prakriya = null; }, + // Clear the active dhatu (and show the full dhatu list). clearActiveDhatu() { // Breaks if we clear `activeDhatu` last -- not sure why. So, clear it first. this.activeDhatu = null; @@ -243,6 +290,7 @@ const App = () => ({ this.clearActivePada(); }, + // Set the app's active tab. setTab(s) { // Reset the prakriya so that we don't display a krt pratyaya for tin, etc. // The proper fix is to have separate prakriyas for each tab. @@ -307,10 +355,12 @@ const App = () => ({ return allPrakriyas.find((p) => p.text == pada.text); }, + // Render the given SLP1 text in Devanagari. deva(s) { return Sanscript.t(s, 'slp1', this.script); }, + // Render the given SLP1 text in Devanagari without svara marks. devaNoSvara(s) { return Sanscript.t(removeSlpSvaras(s), 'slp1', this.script); }, @@ -325,6 +375,7 @@ const App = () => ({ return this.deva(str); }, + /// Create all tinantas allowed by the given `args`. createParadigm(args) { const { dhatu, lakara, prayoga, pada, sanadi, upasarga } = args; @@ -378,6 +429,25 @@ const App = () => ({ return paradigm; }, + // Get a nice human-readable name for the given lakara. + getLakaraTitle(value) { + const mapping = { + "Lat": "law", + "Lit": "liw", + "Lut": "luw", + "Lrt": "lfw", + "Let": "lew", + "Lot": "low", + "Lan": "laN", + "VidhiLin": "viDi-liN", + "AshirLin": "ASIr-liN", + "Lun": "luN", + "Lrn": "lfN", + }; + const text = mapping[Lakara[value]]; + return this.deva(text); + }, + createKrdantas() { if (this.activeDhatu === null) { return []; @@ -409,7 +479,7 @@ const App = () => ({ let results = []; for (const lakara in lakaras) { let laResults = { - title: Lakara[lakara], + title: this.getLakaraTitle(lakara), }; for (const tinPada in tinPadas) { @@ -438,6 +508,7 @@ window.Lakara = Lakara; window.Prayoga = Prayoga; window.Sanadi = Sanadi; +// Initialize the app. window.addEventListener('alpine:init', () => { Alpine.data("app", App) }); diff --git a/vidyut-prakriya/www/templates/index.html b/vidyut-prakriya/www/templates/index.html index bcfb001..d381773 100644 --- a/vidyut-prakriya/www/templates/index.html +++ b/vidyut-prakriya/www/templates/index.html @@ -120,7 +120,7 @@

- + @@ -150,7 +150,7 @@