mirror of
https://github.com/topjohnwu/cxx.git
synced 2025-02-20 08:03:28 +00:00
Accept unquoted path in type_id macro
This commit is contained in:
parent
3b4efdc62a
commit
a8d94a110f
@ -15,8 +15,10 @@ mod type_id;
|
||||
|
||||
use crate::syntax::file::Module;
|
||||
use crate::syntax::namespace::Namespace;
|
||||
use crate::syntax::qualified::QualifiedName;
|
||||
use proc_macro::TokenStream;
|
||||
use syn::{parse_macro_input, LitStr};
|
||||
use syn::parse::{Parse, ParseStream, Result};
|
||||
use syn::parse_macro_input;
|
||||
|
||||
/// `#[cxx::bridge] mod ffi { ... }`
|
||||
///
|
||||
@ -50,6 +52,14 @@ pub fn bridge(args: TokenStream, input: TokenStream) -> TokenStream {
|
||||
|
||||
#[proc_macro]
|
||||
pub fn type_id(input: TokenStream) -> TokenStream {
|
||||
let arg = parse_macro_input!(input as LitStr);
|
||||
type_id::expand(arg).into()
|
||||
struct TypeId(QualifiedName);
|
||||
|
||||
impl Parse for TypeId {
|
||||
fn parse(input: ParseStream) -> Result<Self> {
|
||||
QualifiedName::parse_quoted_or_unquoted(input).map(TypeId)
|
||||
}
|
||||
}
|
||||
|
||||
let arg = parse_macro_input!(input as TypeId);
|
||||
type_id::expand(arg.0).into()
|
||||
}
|
||||
|
@ -1,16 +1,16 @@
|
||||
use crate::syntax::qualified::QualifiedName;
|
||||
use proc_macro2::TokenStream;
|
||||
use quote::{format_ident, quote};
|
||||
use syn::LitStr;
|
||||
|
||||
// "folly::File" => `(f, o, l, l, y, (), F, i, l, e)`
|
||||
pub fn expand(arg: LitStr) -> TokenStream {
|
||||
pub fn expand(arg: QualifiedName) -> TokenStream {
|
||||
let mut ids = Vec::new();
|
||||
|
||||
for word in arg.value().split("::") {
|
||||
for word in arg.segments {
|
||||
if !ids.is_empty() {
|
||||
ids.push(quote!(()));
|
||||
}
|
||||
for ch in word.chars() {
|
||||
for ch in word.to_string().chars() {
|
||||
ids.push(match ch {
|
||||
'A'..='Z' | 'a'..='z' => {
|
||||
let t = format_ident!("{}", ch);
|
||||
|
@ -13,7 +13,7 @@ mod impls;
|
||||
pub mod mangle;
|
||||
pub mod namespace;
|
||||
mod parse;
|
||||
mod qualified;
|
||||
pub mod qualified;
|
||||
pub mod report;
|
||||
pub mod set;
|
||||
pub mod symbol;
|
||||
|
Loading…
x
Reference in New Issue
Block a user