soundchange 0.0.3

Tool for implementing sound change algorithms in Rust
docs.rs failed to build soundchange-0.0.3
Please check the build logs for more information.
See Builds for ideas on how to fix a failed build, or Metadata for how to configure docs.rs builds.
If you believe this is docs.rs' fault, open an issue.

Rust-soundchange

A tool for implementing sound change algorithms.

This is strictly modeled after Mark Rosenfelder's Sound Change Applier, with a necessary tweak for Rust's macro system.

Typical usage and the comparison with the original SCA rules:

#![feature(phase)]
#[phase(plugin, link)] extern crate soundchange;
#[phase(plugin, link)] extern crate log;

fn main() {
    fn boundary(c: Option<char>) -> bool { c.is_none() }
    fn vowel(c: Option<char>) -> bool { c.map_or(false, |c| "aeiou".contains_char(c)) }
    fn reverse(s: &str, out: &mut String) { out.extend(s.chars().rev()); }

    let s = "fihs".into_string();
    let s = subst_rules! { s.as_slice() with    // V=aeiou
        "f" [boundary] => "gh";                 // f/gh/_#
        "f" => "ph";                            // f/ph/_
        ["w"] vowel ["m" vowel "n"] => "o";     // V/o/w_mVn
        "sh" ["o"] => "ti";                     // sh/ti/_o
        [vowel] "hs" => reverse;                // sh/\\/V_
        "" [boundary] => "ing";                 // /ing/_#
    };
    assert_eq!(s.as_slice(), "phishing");
}

Note: You can use RUST_LOG=4 for tracking any change on the string and rules that trigger that change.

Any expression in the left side is considered a "condition" for searching, and can be either char, &str or a function from Option<char> to bool. The function argument is an Option since it can look at the string boundary. [] indicates a context, and is not considered when the string gets transformed. (The behavior of conditions can be also customized by implementing IntoCond trait and/or Search trait. &str and the function implements both.)

Any expression in the right side is considered a "transformer", and can be either char, &str or a function from char to char. When multiple characters have been matched, a function will be invoked for each character. (The behavior of transformers can be also customized by implementing Transform trait.)

The actual processing is driven through the subst function, which is for convenience wrapped into the subst_rules! macro. The syntax should be self-explanatory, except that it returns a CowString.

Case Study: English Pronunciation

src/english provides a reimplementation of Mark Rosenfelder's pronunciation algorithm for English.