Unify `fluent_embed` macro API as `localize()`

finchie
Feb 18, 2024, 12:28 AM
5FIVUZYFLOZ2CCH4GCOQQZFL3GDEB23VJ7J6YUXQDZQEAQDB76DQC

Dependencies

  • [2] OCR4YRQ2 Parse group from fluent file specified by macro attribute
  • [3] QSK7JRBA Add simple `attribute_path` function
  • [4] XGNME3WR Move `Group::derive_enum` to new `crate::parse_macro` module
  • [5] UOMQT7LT Add support for cardinal CLDR plural selectors
  • [6] D652S2N3 Rename `parse` module to `parse_fluent`
  • [7] 5TEX4MNU Split `fluent_embed` into `group` and `parse` modules
  • [8] HJMYJDC7 Simplify `fluent_embed::group` module
  • [*] O77KA6C4 Create `fluent_embed` crate

Change contents

  • edit in fluent_embed/src/parse_macro.rs at line 5
    [3.103]
    [3.103]
    use proc_macro2::TokenStream;
  • edit in fluent_embed/src/parse_macro.rs at line 7
    [3.137]
    [3.137]
    use syn::punctuated::Punctuated;
  • replacement in fluent_embed/src/parse_macro.rs at line 12
    [3.199][3.199:397]()
    enum_data: syn::DataEnum,
    ) -> proc_macro2::TokenStream {
    let mut idents = Vec::with_capacity(enum_data.variants.len());
    let mut messages = Vec::with_capacity(enum_data.variants.len());
    [3.199]
    [3.397]
    variants: Punctuated<syn::Variant, syn::token::Comma>,
    ) -> TokenStream {
    let mut idents = Vec::with_capacity(variants.len());
    let mut messages = Vec::with_capacity(variants.len());
  • replacement in fluent_embed/src/parse_macro.rs at line 17
    [3.398][3.398:438]()
    for variant in enum_data.variants {
    [3.398]
    [3.438]
    for variant in variants {
  • replacement in fluent_embed/src/parse_macro.rs at line 55
    [3.45][2.0:62](),[2.62][3.107:258](),[3.107][3.107:258]()
    pub fn attribute_groups(attribute: syn::Attribute) -> Group {
    match attribute.meta {
    syn::Meta::List(list_data) => {
    let path_literal: syn::LitStr = syn::parse2(list_data.tokens).unwrap();
    [3.45]
    [2.63]
    pub fn attribute_groups(path_literal: syn::LitStr) -> Group {
    // Read the fluent file at the given path
    let manifest_root = std::env::var("CARGO_MANIFEST_DIR").unwrap();
    let resource_path = PathBuf::from(manifest_root).join(path_literal.value());
    let fluent_contents = std::fs::read_to_string(resource_path).unwrap();
  • replacement in fluent_embed/src/parse_macro.rs at line 61
    [2.64][2.64:368]()
    // Read the fluent file at the given path
    let manifest_root = std::env::var("CARGO_MANIFEST_DIR").unwrap();
    let resource_path = PathBuf::from(manifest_root).join(path_literal.value());
    let fluent_contents = std::fs::read_to_string(resource_path).unwrap();
    [2.64]
    [2.368]
    // Parse the file into a `Group`
    let resource = fluent_syntax::parser::parse(fluent_contents).unwrap();
    let group = Group::from_resource(resource);
  • replacement in fluent_embed/src/parse_macro.rs at line 65
    [2.369][2.369:553]()
    // Parse the file into a `Group`
    let resource = fluent_syntax::parser::parse(fluent_contents).unwrap();
    let group = Group::from_resource(resource);
    [2.369]
    [3.327]
    group
    }
  • replacement in fluent_embed/src/parse_macro.rs at line 68
    [3.328][2.554:572](),[3.461][3.1589:1599](),[2.572][3.1589:1599](),[3.1589][3.1589:1599](),[3.1599][3.462:545](),[3.545][3.1599:1605](),[3.1599][3.1599:1605]()
    group
    }
    syn::Meta::Path(_) => todo!(),
    syn::Meta::NameValue(_) => todo!(),
    }
    [3.328]
    [3.1605]
    pub fn localize(
    path: syn::LitStr,
    ident: syn::Ident,
    variants: Punctuated<syn::Variant, syn::token::Comma>,
    ) -> TokenStream {
    let group = attribute_groups(path);
    derive_enum(group, ident, variants)
  • replacement in fluent_embed/src/lib.rs at line 5
    [3.1387][3.3487:3509](),[3.3509][2.573:627]()
    pub use group::Group;
    pub use parse_macro::{attribute_groups, derive_enum};
    [3.1387]
    pub use parse_macro::localize;