diff --git a/widestring-suffix/Cargo.toml b/widestring-suffix/Cargo.toml deleted file mode 100644 index 1e7275968..000000000 --- a/widestring-suffix/Cargo.toml +++ /dev/null @@ -1,13 +0,0 @@ -[package] -name = "widestring-suffix" -version = "0.1.0" -edition.workspace = true -rust-version.workspace = true - -[lib] -proc-macro = true - -[dependencies] -syn = { version = "1.0", features = ["full", "visit-mut"] } -proc-macro2 = "1.0" -quote = "1.0" diff --git a/widestring-suffix/src/lib.rs b/widestring-suffix/src/lib.rs deleted file mode 100644 index af14d928a..000000000 --- a/widestring-suffix/src/lib.rs +++ /dev/null @@ -1,51 +0,0 @@ -extern crate proc_macro as pm; - -use proc_macro2::{Group, Literal, TokenStream, TokenTree}; -use quote::quote_spanned; -use syn::{Lit, LitStr}; - -/// A proc macro which allows easy creation of nul-terminated wide strings. -/// It replaces strings with an L suffix like so: -/// "foo"L -/// with a call like so: -/// crate::wchar::L!("foo") -#[proc_macro_attribute] -pub fn widestrs(_attr: pm::TokenStream, input: pm::TokenStream) -> pm::TokenStream { - let s = widen_stream(input.into()); - s.into() -} - -fn widen_token_tree(tt: TokenTree) -> TokenStream { - match tt { - TokenTree::Group(group) => { - let wide_stream = widen_stream(group.stream()); - TokenTree::Group(Group::new(group.delimiter(), wide_stream)).into() - } - TokenTree::Literal(lit) => widen_literal(lit), - tt => tt.into(), - } -} - -fn widen_stream(input: TokenStream) -> TokenStream { - input.into_iter().map(widen_token_tree).collect() -} - -fn try_parse_literal(tt: TokenTree) -> Option { - let ts: TokenStream = tt.into(); - match syn::parse2::(ts) { - Ok(Lit::Str(lit)) => Some(lit), - _ => None, - } -} - -fn widen_literal(lit: Literal) -> TokenStream { - let tt = TokenTree::Literal(lit); - match try_parse_literal(tt.clone()) { - Some(lit) if lit.suffix() == "L" => { - let value = lit.value(); - let span = lit.span(); - quote_spanned!(span=> crate::wchar::L!(#value)) - } - _ => tt.into(), - } -} diff --git a/widestring-suffix/tests/test.rs b/widestring-suffix/tests/test.rs deleted file mode 100644 index eb11e1b72..000000000 --- a/widestring-suffix/tests/test.rs +++ /dev/null @@ -1,24 +0,0 @@ -use widestring_suffix::widestrs; - -mod wchar { - macro_rules! L { - ($string:expr) => { - 42 - }; - } - - pub(crate) use L; -} - -#[widestrs] -mod stuff { - pub fn test1() { - let s = "abc"L; - assert_eq!(s, 42); - } -} - -#[test] -fn test_widestring() { - stuff::test1(); -}