Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mengasingkan kod teras dalam subcrate 'onc' #4

Merged
merged 12 commits into from
Apr 24, 2024
Merged

Conversation

Thaza-Kun
Copy link
Owner

@Thaza-Kun Thaza-Kun commented Apr 6, 2024

Addresses #3

@Thaza-Kun
Copy link
Owner Author

Thaza-Kun commented Apr 24, 2024

Summary of Changes

Breaking Changes

As a rule of thumb, any items not tagged #[wasm_bindgen] are moved to onc and some that are tagged, are partially separated. Here are some of the items that is affected:

  1. wasm_rs::phonotactic::Phonotactic is now split into two: the original and onc::phonotactic::PhonotactilRule. Logic functions are deferred to PhonotacticRule and can be easily accessed by Phonotactic.as_rule().

  2. Phrase is moved to onc crate as is. No APIs are found broken.

  3. SyllableUnit is moved to onc crate as is. No APIs are found broken.

  4. SyllableTag is moved to onc crate as is. No APIs are found broken.

  5. AltTagVec is moved to onc crate as is. No APIs are found broken.

  6. wasm_rs::phonotactic::InnerParseResult<'a> becomes onc::ParseResult<'a>.
    a. Consequently, InnerParseResult.render(string) has now become wasm_rs::phonotactic::ParseResult.from_inner() because of visibility hierarchy (onc::ParseResult now cannot see wasm_rs::phonotactic::ParseResult). This changes the API from before:

    // Before
    InnerParseResult::from(s).render(options)
    
    // After
    use onc::ParseResult as InnerParseResult;
    ParseResult::from_inner(&InnerParseResult::from(s), &options)
  7. wasm_rs::imbuhan::Imbuhan { ... } struct becomes a newtype wasm_rs::imbuhan::Imbuhan(onc::affixes::AffixesRule<JenisKata>) with the original fields deferred to AffixesRule<POS> and the method names are put as is but the logic is pushed to the inner struct like so:

    // Before
    struct Imbuhan {
        untuk: HashSet<JenisKata>,
        awal: Option<String>,
        akhir: Option<String>,
        ganti: Option<Ganti>
    }
    impl Imbuhan {
        pub fn transform_string_with(&self, input: &str, phonotactic: &PhonotacticRule) -> String;
    }
    // After
    // File: onc::affixes.rs
    struct AffixesRule<POS: Hash + Eq> {
        untuk: HashSet<POS>,
        awal: Option<String>,
        akhir: Option<String>,
        ganti: Option<Ganti>
    }
    impl<POS: Hash + Eq> AffixesRule<POS> {
        pub fn transform_string_with(&self, input: &str, phonotactic: &PhonotacticRule) -> String;
    }
    // File: src::imbuhan.rs
    use onc::affixes::AffixesRule
    struct Imbuhan(AffixesRule<JenisKata>)
    impl Imbuhan {
        pub fn transform_string_with(&self, input: &str, phonotactic: &PhonotacticRule) -> String {
        self.0.transform_string_with(input, phonotactic)
        }
    }

Quality of Life

  1. Add two examples to wasm_rs: phonotactic.rs and imbuhan.rs showing how the frontend is expected to use the interface.
  2. Tests are moved to onc

@Thaza-Kun Thaza-Kun marked this pull request as ready for review April 24, 2024 11:15
@Thaza-Kun Thaza-Kun merged commit d9e39dd into master Apr 24, 2024
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant