-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f44babd
commit d504aaf
Showing
6 changed files
with
106 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
extern crate proc_macro; | ||
|
||
use proc_macro::TokenStream; | ||
use quote::{ToTokens, quote}; | ||
use syn::{parse::{Parse, ParseStream}, Result, parse_macro_input, Attribute, FnArg, Ident, ItemFn, Token}; | ||
|
||
// Parses a unit struct with attributes. | ||
// | ||
// #[path = "s.tmpl"] | ||
// struct S; | ||
struct UnitStruct { | ||
attrs: Vec<Attribute>, | ||
struct_token: Token![struct], | ||
name: Ident, | ||
semi_token: Token![;], | ||
} | ||
|
||
impl Parse for UnitStruct { | ||
fn parse(input: ParseStream) -> Result<Self> { | ||
Ok(UnitStruct { | ||
attrs: input.call(Attribute::parse_outer)?, | ||
struct_token: input.parse()?, | ||
name: input.parse()?, | ||
semi_token: input.parse()?, | ||
}) | ||
} | ||
} | ||
|
||
#[proc_macro_attribute] | ||
pub fn define(args: TokenStream, input: TokenStream) -> TokenStream { | ||
//let args = syn::parse(args).unwrap(); | ||
|
||
let input = parse_macro_input!(input as ItemFn); | ||
|
||
let ItemFn { | ||
// The function signature | ||
sig, | ||
// The visibility specifier of this function | ||
vis, | ||
// The function block or body | ||
block, | ||
// Other attributes applied to this function | ||
attrs, | ||
} = input; | ||
|
||
sig.inputs.iter().for_each(|s| { | ||
match s { | ||
FnArg::Typed(s) => { | ||
println!("{:?}", s.ty.to_token_stream()); | ||
} | ||
_ => {} | ||
} | ||
}); | ||
|
||
let new = Ident::new(&format!("_call_{}", sig.ident), sig.ident.span()); | ||
|
||
let params = sig.inputs.to_token_stream(); | ||
println!("New {}", new.to_string()); | ||
|
||
let ident = sig.ident; | ||
|
||
quote! { | ||
fn #ident(args: &Vec<String>) { | ||
|
||
} | ||
|
||
#vis fn #new(#params) #block | ||
}.into() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
[package] | ||
name = "tests" | ||
version = "0.1.0" | ||
edition = "2021" | ||
|
||
[dependencies] | ||
lead_lang_macros = { path = ".." } | ||
lead_lang_interpreter = { path = "../../interpreter" } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
use lead_lang_macros::define; | ||
|
||
fn main() { | ||
println!("Hello, world!"); | ||
_call_call("".into(), "".into()) | ||
} | ||
|
||
#[define] | ||
fn call(a: String, b: String) { | ||
println!("{a} {b}"); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters