diff options
Diffstat (limited to '')
8 files changed, 221 insertions, 0 deletions
diff --git a/third_party/rust/unic-langid-macros-impl/.cargo-checksum.json b/third_party/rust/unic-langid-macros-impl/.cargo-checksum.json new file mode 100644 index 0000000000..e4773cea52 --- /dev/null +++ b/third_party/rust/unic-langid-macros-impl/.cargo-checksum.json @@ -0,0 +1 @@ +{"files":{"Cargo.toml":"64b7309cfef73fbefdec8588f92c91adeebee5b8ee5d824e8e3792763c84f8a6","README.md":"5040022258561c990431417a73521d15ace408b70329a97bc61da94914ed1a75","src/lib.rs":"83231cab2e2ceb3aebd4ec6f103a8ff98d1b52b407e7c9d6c66fba911637379d"},"package":"1f5cdec05b907f4e2f6843f4354f4ce6a5bebe1a56df320a49134944477ce4d8"}
\ No newline at end of file diff --git a/third_party/rust/unic-langid-macros-impl/Cargo.toml b/third_party/rust/unic-langid-macros-impl/Cargo.toml new file mode 100644 index 0000000000..a353df5889 --- /dev/null +++ b/third_party/rust/unic-langid-macros-impl/Cargo.toml @@ -0,0 +1,50 @@ +# THIS FILE IS AUTOMATICALLY GENERATED BY CARGO +# +# When uploading crates to the registry Cargo will automatically +# "normalize" Cargo.toml files for maximal compatibility +# with all versions of Cargo and also rewrite `path` dependencies +# to registry (e.g., crates.io) dependencies. +# +# If you are reading this file be aware that the original Cargo.toml +# will likely look very different (and much more reasonable). +# See Cargo.toml.orig for the original contents. + +[package] +edition = "2018" +name = "unic-langid-macros-impl" +version = "0.9.1" +authors = [ + "Manish Goregaokar <manishsmail@gmail.com>", + "Zibi Braniecki <gandalf@mozilla.com>", +] +include = [ + "src/**/*", + "benches/*.rs", + "Cargo.toml", + "README.md", +] +description = "API for managing Unicode Language Identifiers" +readme = "README.md" +categories = ["internationalization"] +license = "MIT/Apache-2.0" +repository = "https://github.com/zbraniecki/unic-locale" + +[lib] +proc_macro = true + +[dependencies.proc-macro-hack] +version = "0.5" + +[dependencies.quote] +version = "1.0" + +[dependencies.syn] +version = "1.0" +features = [ + "parsing", + "proc-macro", +] +default-features = false + +[dependencies.unic-langid-impl] +version = "0.9" diff --git a/third_party/rust/unic-langid-macros-impl/README.md b/third_party/rust/unic-langid-macros-impl/README.md new file mode 100644 index 0000000000..203468ce2e --- /dev/null +++ b/third_party/rust/unic-langid-macros-impl/README.md @@ -0,0 +1 @@ +This is an internal macro implementation crate for `unic-langid`. Please use `unic-langid`. diff --git a/third_party/rust/unic-langid-macros-impl/src/lib.rs b/third_party/rust/unic-langid-macros-impl/src/lib.rs new file mode 100644 index 0000000000..ee27a51e81 --- /dev/null +++ b/third_party/rust/unic-langid-macros-impl/src/lib.rs @@ -0,0 +1,108 @@ +extern crate proc_macro; + +use proc_macro::TokenStream; + +use proc_macro_hack::proc_macro_hack; +use quote::quote; +use syn::{parse_macro_input, LitStr}; + +use unic_langid_impl::{subtags, LanguageIdentifier}; + +#[proc_macro_hack] +pub fn lang(input: TokenStream) -> TokenStream { + let id = parse_macro_input!(input as LitStr); + let parsed: subtags::Language = id.value().parse().expect("Malformed Language Subtag"); + + let lang: Option<u64> = parsed.into(); + let lang = if let Some(lang) = lang { + quote!(unsafe { $crate::subtags::Language::from_raw_unchecked(#lang) }) + } else { + quote!(None) + }; + + TokenStream::from(quote! { + #lang + }) +} + +#[proc_macro_hack] +pub fn script(input: TokenStream) -> TokenStream { + let id = parse_macro_input!(input as LitStr); + let parsed: subtags::Script = id.value().parse().expect("Malformed Script Subtag"); + + let script: u32 = parsed.into(); + + TokenStream::from(quote! { + unsafe { $crate::subtags::Script::from_raw_unchecked(#script) } + }) +} + +#[proc_macro_hack] +pub fn region(input: TokenStream) -> TokenStream { + let id = parse_macro_input!(input as LitStr); + let parsed: subtags::Region = id.value().parse().expect("Malformed Region Subtag"); + + let region: u32 = parsed.into(); + + TokenStream::from(quote! { + unsafe { $crate::subtags::Region::from_raw_unchecked(#region) } + }) +} + +#[proc_macro_hack] +pub fn variant_fn(input: TokenStream) -> TokenStream { + let id = parse_macro_input!(input as LitStr); + let parsed: subtags::Variant = id.value().parse().expect("Malformed Variant Subtag"); + + let variant: u64 = parsed.into(); + + TokenStream::from(quote! { + unsafe { $crate::subtags::Variant::from_raw_unchecked(#variant) } + }) +} + +#[proc_macro_hack] +pub fn langid(input: TokenStream) -> TokenStream { + let id = parse_macro_input!(input as LitStr); + let parsed: LanguageIdentifier = id.value().parse().expect("Malformed Language Identifier"); + + let (lang, script, region, variants) = parsed.into_parts(); + + let lang: Option<u64> = lang.into(); + let lang = if let Some(lang) = lang { + quote!(unsafe { $crate::subtags::Language::from_raw_unchecked(#lang) }) + } else { + quote!($crate::subtags::Language::default()) + }; + + let script = if let Some(script) = script { + let script: u32 = script.into(); + quote!(Some(unsafe { $crate::subtags::Script::from_raw_unchecked(#script) })) + } else { + quote!(None) + }; + + let region = if let Some(region) = region { + let region: u32 = region.into(); + quote!(Some(unsafe { $crate::subtags::Region::from_raw_unchecked(#region) })) + } else { + quote!(None) + }; + + let variants = if !variants.is_empty() { + let v: Vec<_> = variants + .iter() + .map(|v| { + let variant: u64 = v.into(); + quote!(unsafe { $crate::subtags::Variant::from_raw_unchecked(#variant) }) + }) + .collect(); + quote!(Some(Box::new([#(#v,)*]))) + } else { + quote!(None) + }; + + TokenStream::from(quote! { + unsafe { $crate::LanguageIdentifier::from_raw_parts_unchecked(#lang, #script, #region, #variants) } + }) +} diff --git a/third_party/rust/unic-langid-macros/.cargo-checksum.json b/third_party/rust/unic-langid-macros/.cargo-checksum.json new file mode 100644 index 0000000000..643d0d6039 --- /dev/null +++ b/third_party/rust/unic-langid-macros/.cargo-checksum.json @@ -0,0 +1 @@ +{"files":{"Cargo.toml":"debce559451d7edd257495d2f7a8c3bd081e1ec15625d42668165cec8f2a4cf7","README.md":"6bab9883bd094c16d22f7aeddb59b391c1567c167ffed2f28aee9e2a82de1a1d","src/lib.rs":"f850878a5d545496073593ef1ca340ef385f78bc6585c5d3b46fe8ffc2087bd5"},"package":"055e618bf694161ffff0466d95cef3e1a5edc59f6ba1888e97801f2b4ebdc4fe"}
\ No newline at end of file diff --git a/third_party/rust/unic-langid-macros/Cargo.toml b/third_party/rust/unic-langid-macros/Cargo.toml new file mode 100644 index 0000000000..55fad3cfc7 --- /dev/null +++ b/third_party/rust/unic-langid-macros/Cargo.toml @@ -0,0 +1,42 @@ +# THIS FILE IS AUTOMATICALLY GENERATED BY CARGO +# +# When uploading crates to the registry Cargo will automatically +# "normalize" Cargo.toml files for maximal compatibility +# with all versions of Cargo and also rewrite `path` dependencies +# to registry (e.g., crates.io) dependencies. +# +# If you are reading this file be aware that the original Cargo.toml +# will likely look very different (and much more reasonable). +# See Cargo.toml.orig for the original contents. + +[package] +edition = "2018" +name = "unic-langid-macros" +version = "0.9.1" +authors = [ + "Manish Goregaokar <manishsmail@gmail.com>", + "Zibi Braniecki <gandalf@mozilla.com>", +] +include = [ + "src/**/*", + "benches/*.rs", + "Cargo.toml", + "README.md", +] +description = "API for managing Unicode Language Identifiers" +readme = "README.md" +categories = ["internationalization"] +license = "MIT/Apache-2.0" +repository = "https://github.com/zbraniecki/unic-locale" + +[dependencies.proc-macro-hack] +version = "0.5" + +[dependencies.tinystr] +version = "0.7.0" + +[dependencies.unic-langid-impl] +version = "0.9" + +[dependencies.unic-langid-macros-impl] +version = "0.9" diff --git a/third_party/rust/unic-langid-macros/README.md b/third_party/rust/unic-langid-macros/README.md new file mode 100644 index 0000000000..4497b805d6 --- /dev/null +++ b/third_party/rust/unic-langid-macros/README.md @@ -0,0 +1 @@ +This is an internal macro declaration crate for `unic-langid`. Please use `unic-langid` instead. diff --git a/third_party/rust/unic-langid-macros/src/lib.rs b/third_party/rust/unic-langid-macros/src/lib.rs new file mode 100644 index 0000000000..9e075e15c0 --- /dev/null +++ b/third_party/rust/unic-langid-macros/src/lib.rs @@ -0,0 +1,17 @@ +use proc_macro_hack::proc_macro_hack; +pub use unic_langid_impl::{subtags, LanguageIdentifier}; + +#[proc_macro_hack] +pub use unic_langid_macros_impl::langid; + +#[proc_macro_hack] +pub use unic_langid_macros_impl::lang; + +#[proc_macro_hack] +pub use unic_langid_macros_impl::script; + +#[proc_macro_hack] +pub use unic_langid_macros_impl::region; + +#[proc_macro_hack] +pub use unic_langid_macros_impl::variant_fn as variant; |