mirror of
https://github.com/fish-shell/fish-shell.git
synced 2025-02-21 10:25:42 +08:00
Delete widestring-suffix
This commit is contained in:
parent
507d634cfa
commit
1da9af781c
@ -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"
|
@ -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<LitStr> {
|
||||
let ts: TokenStream = tt.into();
|
||||
match syn::parse2::<Lit>(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(),
|
||||
}
|
||||
}
|
@ -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();
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user