From 24ef322b57d29d26224e7f9e772b3691143b2da2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gustav=20S=C3=B6rn=C3=A4s?= Date: Fri, 19 Feb 2021 19:19:44 +0100 Subject: begin work on automatic link --- sylt_macro/src/lib.rs | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'sylt_macro/src/lib.rs') diff --git a/sylt_macro/src/lib.rs b/sylt_macro/src/lib.rs index 1cafde8..9bfef65 100644 --- a/sylt_macro/src/lib.rs +++ b/sylt_macro/src/lib.rs @@ -1,5 +1,7 @@ +use lazy_static::lazy_static; use proc_macro::TokenStream; use quote::quote; +use std::borrow::Cow; use syn::{Expr, Pat, Token, parse::{Parse, ParseStream, Result}, parse_macro_input}; struct ExternBlock { @@ -91,3 +93,22 @@ pub fn extern_function(tokens: TokenStream) -> TokenStream { }; TokenStream::from(tokens) } + +#[proc_macro_attribute] +pub fn extern_link(attr: TokenStream, tokens: TokenStream) -> TokenStream { + let parsed: syn::ItemFn = parse_macro_input!(tokens); + + let name = if attr.is_empty() { + Cow::Borrowed(&parsed.sig.ident) + } else { + let attr: syn::Ident = parse_macro_input!(attr); + Cow::Owned(attr) + }; + + let tokens = quote! { + #parsed + + + }; + TokenStream::from(tokens) +} -- cgit v1.2.1