Skip to content

Commit

Permalink
Implement library support for partial A-tehta elision
Browse files Browse the repository at this point in the history
Not yet exposed in the executable.
  • Loading branch information
Yaulendil committed Dec 6, 2022
1 parent 5d4aaeb commit 4ec5724
Show file tree
Hide file tree
Showing 5 changed files with 206 additions and 15 deletions.
12 changes: 5 additions & 7 deletions src/characters/glyph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -299,13 +299,6 @@ impl<P: Policy> Glyph<P> {
self.tehta_alt = other.tehta_alt;
}

/// Elide the [A-tehta](TEHTA_A).
pub fn elide_a(&mut self) {
if self.tehta == Some(TEHTA_A) {
self.tehta_hidden = true;
}
}

/// If the base [`char`] matches a specific value, change it to another.
pub fn replace_base(&mut self, old: char, new: char) -> bool {
if self.base == Some(old) {
Expand Down Expand Up @@ -530,6 +523,11 @@ impl<P: Policy> Glyph<P> {
}
}
}

/// Return `true` if the glyph carries the [A-tehta](TEHTA_A).
pub fn tehta_is_a(&self) -> bool {
self.tehta == Some(TEHTA_A)
}
}

/// Private: Helper methods.
Expand Down
29 changes: 27 additions & 2 deletions src/iter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,25 @@ impl<I, P, Q> Iterator for TokenIter<I, P, Q> where
glyph.dot_under = true;
}

if self.settings.elide_a {
glyph.elide_a();
if self.settings.elide_a && glyph.tehta_is_a() {
if self.settings.keep_a_long && glyph.tehta_alt {
// We want to shorten long vowels, and this one is long.
glyph.tehta_alt = false;

/*if glyph.base.is_some() { // TODO
glyph.tehta_alt = false;
} else {
glyph.tehta_hidden = true;
}*/
} else if self.settings.keep_a_init {
// We want to keep an initial occurrence.
if matches!(&self.last, Some(Token::Glyph(_))) {
// This is not an initial occurrence. Elide it.
glyph.tehta_hidden = true;
}
} else {
glyph.tehta_hidden = true;
}
}

if self.settings.alt_a {
Expand Down Expand Up @@ -139,6 +156,12 @@ pub struct TranscriberSettings {
/// If this is `true`, the [A-tehta](TEHTA_A) will not be used.
pub elide_a: bool,

/// If this is `true`, the [A-tehta](TEHTA_A) will not be elided initially.
pub keep_a_init: bool,

/// If this is `true`, the [A-tehta](TEHTA_A) will not be elided when long.
pub keep_a_long: bool,

/// If this is `true`, the [short carrier](CARRIER_SHORT) will be replaced
/// by its [ligating variant](CARRIER_SHORT_LIG) where appropriate.
pub ligate_short: bool,
Expand All @@ -164,6 +187,8 @@ impl TranscriberSettings {
alt_rince: false,
dot_plain: false,
elide_a: false,
keep_a_init: false,
keep_a_long: false,
ligate_short: false,
ligate_zwj: 0,
nuquerna: false,
Expand Down
2 changes: 2 additions & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,8 @@ impl Command {
alt_rince: self.style_flags.alt_rince,
dot_plain: self.style_flags.dot_plain,
elide_a: self.style_flags.elide_a,
keep_a_init: false,
keep_a_long: false,
ligate_short: self.ligate_all || self.ligate_short,
ligate_zwj: if self.ligate_all { u8::MAX } else { self.ligate_zwj },
nuquerna: self.style_flags.nuquerna,
Expand Down
12 changes: 6 additions & 6 deletions src/mode/tests/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@ macro_rules! params {
/// will transcribe it, returning a tuple with the input and output. If the
/// input is an already-transcribed tuple, this will resolve to a reference.
macro_rules! tengwar {
($mode:ty $([$($k:ident=$v:expr),*])?, $input:literal) => {{
use $crate::ToTengwar;

#[allow(unused_mut)]
let mut iter = $input.transcriber::<$mode>();
$($(iter.settings.$k = $v;)*)?
($mode:ty $([])?, $input:literal) => {
($input, <$mode as $crate::TengwarMode>::transcribe::<String>($input))
};
($mode:ty [$($k:ident=$v:expr),+ $(,)?], $input:literal) => {{
let mut iter = <$mode as $crate::TengwarMode>::default_transcriber($input);
$(iter.settings.$k = $v;)+
($input, iter.collect::<String>())
}};
($mode:ty $([$($t:tt)*])?, $input:expr) => { &$input };
Expand Down
166 changes: 166 additions & 0 deletions src/mode/tests/quenya.rs
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,172 @@ fn elision() {
TENGWA_URE, // au
TENGWA_LAMBE, TEHTA_E.base, // lë
]);

// NAMÁRIË
{
test_tengwar!(Quenya, "namárië" => [
TENGWA_NUMEN, TEHTA_A.base, // na
TENGWA_MALTA, // m
CARRIER_LONG, TEHTA_A.base, // á
TENGWA_ROMEN, TEHTA_I.base, // ri
CARRIER_SHORT, TEHTA_E.base, // ë
]);
test_tengwar!(Quenya[elide_a=true], "namárië" => [
TENGWA_NUMEN, // n(a)
TENGWA_MALTA, // m
CARRIER_LONG, // á
TENGWA_ROMEN, TEHTA_I.base, // ri
CARRIER_SHORT, TEHTA_E.base, // ë
]);
test_tengwar!(Quenya[elide_a=true, keep_a_init=true], "namárië" => [
TENGWA_NUMEN, TEHTA_A.base, // na
TENGWA_MALTA, // m
CARRIER_LONG, // á
TENGWA_ROMEN, TEHTA_I.base, // ri
CARRIER_SHORT, TEHTA_E.base, // ë
]);
test_tengwar!(Quenya[elide_a=true, keep_a_long=true], "namárië" => [
TENGWA_NUMEN, // n(a)
TENGWA_MALTA, TEHTA_A.base, // má
TENGWA_ROMEN, TEHTA_I.base, // ri
CARRIER_SHORT, TEHTA_E.base, // ë
]);
test_tengwar!(Quenya[
elide_a=true,
keep_a_init=true,
keep_a_long=true,
], "namárië" => [
TENGWA_NUMEN, TEHTA_A.base, // na
TENGWA_MALTA, TEHTA_A.base, // má
TENGWA_ROMEN, TEHTA_I.base, // ri
CARRIER_SHORT, TEHTA_E.base, // e
]);
}

// MÁRA
{
test_tengwar!(Quenya, "mára" => [
TENGWA_MALTA, CARRIER_LONG, TEHTA_A.base, // má
TENGWA_ROMEN, TEHTA_A.base, // ra
]);
test_tengwar!(Quenya[elide_a=true], "mára" => [
TENGWA_MALTA, CARRIER_LONG, // má
TENGWA_ROMEN, // r(a)
]);
test_tengwar!(Quenya[elide_a=true, keep_a_init=true], "mára" => [
TENGWA_MALTA, CARRIER_LONG, TEHTA_A.base, // má
TENGWA_ROMEN, // r(a)
]);
test_tengwar!(Quenya[elide_a=true, keep_a_long=true], "mára" => [
TENGWA_MALTA, TEHTA_A.base, // má
TENGWA_ROMEN, // r(a)
]);
test_tengwar!(Quenya[
elide_a=true,
keep_a_init=true,
keep_a_long=true,
], "mára" => [
TENGWA_MALTA, TEHTA_A.base, // má
TENGWA_ROMEN, // r(a)
]);
}

// MARÁ
{
test_tengwar!(Quenya, "mará" => [
TENGWA_MALTA, TEHTA_A.base, // ma
TENGWA_ROMEN, // r
CARRIER_LONG, TEHTA_A.base, // á
]);
test_tengwar!(Quenya[elide_a=true], "mará" => [
TENGWA_MALTA, // m(a)
TENGWA_ROMEN, // r
CARRIER_LONG, // á
]);
test_tengwar!(Quenya[elide_a=true, keep_a_init=true], "mará" => [
TENGWA_MALTA, TEHTA_A.base, // ma
TENGWA_ROMEN, // r
CARRIER_LONG, // á
]);
test_tengwar!(Quenya[elide_a=true, keep_a_long=true], "mará" => [
TENGWA_MALTA, // m(a)
TENGWA_ROMEN, TEHTA_A.base, // rá
]);
test_tengwar!(Quenya[
elide_a=true,
keep_a_init=true,
keep_a_long=true,
], "mará" => [
TENGWA_MALTA, TEHTA_A.base, // ma
TENGWA_ROMEN, TEHTA_A.base, // rá
]);
}

// MARIA
{
test_tengwar!(Quenya, "maria" => [
TENGWA_MALTA, TEHTA_A.base, // ma
TENGWA_ROMEN, TEHTA_I.base, // ri
CARRIER_SHORT, TEHTA_A.base, // a
]);
test_tengwar!(Quenya[elide_a=true], "maria" => [
TENGWA_MALTA, // m(a)
TENGWA_ROMEN, TEHTA_I.base, // ri
CARRIER_SHORT, // a
]);
test_tengwar!(Quenya[elide_a=true, keep_a_init=true], "maria" => [
TENGWA_MALTA, TEHTA_A.base, // ma
TENGWA_ROMEN, TEHTA_I.base, // ri
CARRIER_SHORT, // a
]);
test_tengwar!(Quenya[elide_a=true, keep_a_long=true], "maria" => [
TENGWA_MALTA, // m(a)
TENGWA_ROMEN, TEHTA_I.base, // ri
CARRIER_SHORT, // a
]);
test_tengwar!(Quenya[
elide_a=true,
keep_a_init=true,
keep_a_long=true,
], "maria" => [
TENGWA_MALTA, TEHTA_A.base, // ma
TENGWA_ROMEN, TEHTA_I.base, // ri
CARRIER_SHORT, // a
]);
}

// MARIÁ
{
test_tengwar!(Quenya, "mariá" => [
TENGWA_MALTA, TEHTA_A.base, // ma
TENGWA_ROMEN, TEHTA_I.base, // ri
CARRIER_LONG, TEHTA_A.base, // á
]);
test_tengwar!(Quenya[elide_a=true], "mariá" => [
TENGWA_MALTA, // m(a)
TENGWA_ROMEN, TEHTA_I.base, // ri
CARRIER_LONG, // á
]);
test_tengwar!(Quenya[elide_a=true, keep_a_init=true], "mariá" => [
TENGWA_MALTA, TEHTA_A.base, // ma
TENGWA_ROMEN, TEHTA_I.base, // ri
CARRIER_LONG, // á
]);
test_tengwar!(Quenya[elide_a=true, keep_a_long=true], "mariá" => [
TENGWA_MALTA, // m(a)
TENGWA_ROMEN, TEHTA_I.base, // ri
CARRIER_SHORT, TEHTA_A.base, // á
]);
test_tengwar!(Quenya[
elide_a=true,
keep_a_init=true,
keep_a_long=true,
], "mariá" => [
TENGWA_MALTA, TEHTA_A.base, // ma
TENGWA_ROMEN, TEHTA_I.base, // ri
CARRIER_SHORT, TEHTA_A.base, // á
]);
}
}


Expand Down

0 comments on commit 4ec5724

Please sign in to comment.