diff options
| author | Gustav Sörnäs <gustav@sornas.net> | 2021-02-19 19:19:44 +0100 |
|---|---|---|
| committer | Gustav Sörnäs <gustav@sornas.net> | 2021-02-19 19:19:44 +0100 |
| commit | 24ef322b57d29d26224e7f9e772b3691143b2da2 (patch) | |
| tree | c6f9dd5779b202116405c57ff69f5d858ba480b5 | |
| parent | 2a38312c067414ee82da971b880d650ccd6b084c (diff) | |
| download | sylt-24ef322b57d29d26224e7f9e772b3691143b2da2.tar.gz | |
begin work on automatic link
| -rw-r--r-- | Cargo.lock | 1 | ||||
| -rw-r--r-- | sylt_macro/Cargo.toml | 1 | ||||
| -rw-r--r-- | sylt_macro/src/lib.rs | 21 |
3 files changed, 23 insertions, 0 deletions
@@ -531,6 +531,7 @@ dependencies = [ name = "sylt_macro" version = "0.1.0" dependencies = [ + "lazy_static", "quote", "syn", ] diff --git a/sylt_macro/Cargo.toml b/sylt_macro/Cargo.toml index 9ac045e..04ae39d 100644 --- a/sylt_macro/Cargo.toml +++ b/sylt_macro/Cargo.toml @@ -12,3 +12,4 @@ proc-macro = true [dependencies] syn = { version = "1.0", features=["full"] } quote = "1.0" +lazy_static = "1.4" 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) +} |
