bok-macro as dep of bok
Signed-off-by: Luca Fulchir <luca.fulchir@runesauth.com>
This commit is contained in:
parent
11ecc75393
commit
cc77805029
1
Cargo.lock
generated
1
Cargo.lock
generated
@ -23,7 +23,6 @@ dependencies = [
|
||||
name = "bok-macro"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"bok",
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn",
|
||||
|
@ -15,5 +15,4 @@ proc-macro = true
|
||||
[dependencies]
|
||||
syn = { version = "2.0", features = [ "full" ] }
|
||||
quote = { version = "1.0" }
|
||||
bok = { path = "../bok" }
|
||||
proc-macro2 = "1.0"
|
||||
|
@ -17,15 +17,12 @@
|
||||
|
||||
use ::proc_macro::TokenStream;
|
||||
use ::quote::quote;
|
||||
use ::syn::{
|
||||
parse::{ParseBuffer, ParseStream, Parser},
|
||||
parse_macro_input, DeriveInput,
|
||||
};
|
||||
use ::syn::{parse::Parser, parse_macro_input, DeriveInput};
|
||||
|
||||
/// Use as #[repository(MyBaseRepo)]
|
||||
/// Use as #[::bok::repository(MyBaseRepo)]
|
||||
/// Will setup a `base` field that is the given base repo
|
||||
///
|
||||
/// e.g.: `#[repository(::bok::RepositoryEmpty)]`
|
||||
/// e.g.: `#[::bok::repository(::bok::RepositoryEmpty)]`
|
||||
#[proc_macro_attribute]
|
||||
pub fn repository(attrs: TokenStream, input: TokenStream) -> TokenStream {
|
||||
let mut ast = parse_macro_input!(input as DeriveInput);
|
||||
@ -44,6 +41,7 @@ pub fn repository(attrs: TokenStream, input: TokenStream) -> TokenStream {
|
||||
}
|
||||
|
||||
quote! {
|
||||
#[derive(::bok::Repository)]
|
||||
#ast
|
||||
}
|
||||
.into()
|
||||
@ -52,7 +50,9 @@ pub fn repository(attrs: TokenStream, input: TokenStream) -> TokenStream {
|
||||
}
|
||||
}
|
||||
|
||||
/// Use as #[derive(Repository)]
|
||||
/// Unless you know what you are doing, use `#[::bok::repository(MyBaseRepo)]` instead
|
||||
///
|
||||
/// Use as #[derive(::bok::Repository)]
|
||||
/// adds extension capabilities to a repo
|
||||
#[proc_macro_derive(Repository)]
|
||||
pub fn derive_repository(input: TokenStream) -> TokenStream {
|
||||
@ -94,14 +94,14 @@ pub fn derive_repository(input: TokenStream) -> TokenStream {
|
||||
|
||||
TokenStream::from(expanded)
|
||||
}
|
||||
/// Use on a function as #[to_code]
|
||||
/// Use on a function as `#[::bok::to_code]`
|
||||
/// will create a new function, same name with `_code` that
|
||||
/// returns the ::proc_macro2::TokenStream of the function
|
||||
///
|
||||
/// e.g.:
|
||||
/// ```
|
||||
/// impl MyPackage {
|
||||
/// #[::bok_macro::to_code]
|
||||
/// #[::bok::to_code]
|
||||
/// fn build() {
|
||||
/// ...
|
||||
/// }
|
||||
@ -177,10 +177,10 @@ pub fn to_code(_attrs: TokenStream, input: TokenStream) -> TokenStream {
|
||||
*/
|
||||
}
|
||||
|
||||
/// Use as #[package(MyBasePackage)]
|
||||
/// Use as #[::bok::package(MyBasePackage)]
|
||||
/// Will setup a `base` field that is the given base package
|
||||
///
|
||||
/// e.g.: `#[package(::bok::PkgEmpty)]`
|
||||
/// e.g.: `#[::bok::package(::bok::PkgEmpty)]`
|
||||
#[proc_macro_attribute]
|
||||
pub fn package(attrs: TokenStream, input: TokenStream) -> TokenStream {
|
||||
let mut ast = parse_macro_input!(input as DeriveInput);
|
||||
@ -199,6 +199,7 @@ pub fn package(attrs: TokenStream, input: TokenStream) -> TokenStream {
|
||||
}
|
||||
|
||||
quote! {
|
||||
#[derive(::bok::Package)]
|
||||
#ast
|
||||
}
|
||||
.into()
|
||||
@ -207,7 +208,9 @@ pub fn package(attrs: TokenStream, input: TokenStream) -> TokenStream {
|
||||
}
|
||||
}
|
||||
|
||||
/// #[derive(Package)]
|
||||
/// Unless you know what you are doing, use `#[::bok::package(MyBasePackage)]` instead
|
||||
///
|
||||
/// #[derive(::bok::Package)]
|
||||
/// adds:
|
||||
/// * Builder pattern to a package
|
||||
/// * deref for builder towards `.base`
|
||||
@ -382,7 +385,7 @@ pub fn derive_package(input: TokenStream) -> TokenStream {
|
||||
->::core::fmt::Result
|
||||
{
|
||||
// FIXME: this sounds convoluted.
|
||||
// first we make everything into a string, then we
|
||||
// first we turn everything into a string, then we
|
||||
// parse the string into tokenstream again to format it
|
||||
// reason: the `prettyplease` works on `::syn::File`
|
||||
// and I can't find an easy translation
|
||||
@ -398,7 +401,7 @@ pub fn derive_package(input: TokenStream) -> TokenStream {
|
||||
use ::core::fmt::Write;
|
||||
|
||||
write!(out,
|
||||
"#[::bok_macro::to_code]\n\
|
||||
"#[::bok::to_code]\n\
|
||||
fn {}(&self) -> Result<(), ()> {{\n{}\n}}\n",
|
||||
name, fn_str)
|
||||
|
||||
@ -407,7 +410,6 @@ pub fn derive_package(input: TokenStream) -> TokenStream {
|
||||
}
|
||||
};
|
||||
|
||||
// from the Pkg trait
|
||||
use ::core::fmt::Write;
|
||||
|
||||
let pkg_empty = ::bok::PkgEmpty{};
|
||||
|
@ -31,7 +31,7 @@ bok::moduse! {
|
||||
/// Base repository with some packages
|
||||
///
|
||||
#[::bok_macro::repository(::bok::RepositoryEmpty)]
|
||||
#[derive(::bok_macro::Repository, ::std::default::Default)]
|
||||
#[derive(::std::default::Default)]
|
||||
pub struct Pkgs1 {}
|
||||
|
||||
// Add some packages to the repository
|
||||
@ -47,7 +47,7 @@ bok::repo_packages! {
|
||||
/// This repository extends and changes Pkgs1
|
||||
///
|
||||
#[::bok_macro::repository(Pkgs1)]
|
||||
#[derive(::bok_macro::Repository, ::std::default::Default)]
|
||||
#[derive(::std::default::Default)]
|
||||
pub struct Pkgs2 {}
|
||||
|
||||
// add a third package with `::default()` values
|
||||
|
@ -18,7 +18,6 @@
|
||||
/// Example package
|
||||
/// Automatically implements `.builder().my_attr(42).build()` pattern
|
||||
#[::bok_macro::package(::bok::PkgEmpty)]
|
||||
#[derive(::bok_macro::Package)]
|
||||
pub struct One {
|
||||
pub my_attr: u32,
|
||||
}
|
||||
|
@ -18,7 +18,6 @@
|
||||
/// Example package
|
||||
/// Automatically implements `.builder().my_attr(42).build()` pattern
|
||||
#[::bok_macro::package(::bok::PkgEmpty)]
|
||||
#[derive(::bok_macro::Package)]
|
||||
pub struct Three {
|
||||
pub my_attr: u32,
|
||||
}
|
||||
|
@ -18,7 +18,6 @@
|
||||
/// Example package
|
||||
/// Automatically implements `.builder().my_attr(42).build()` pattern
|
||||
#[::bok_macro::package(::bok::PkgEmpty)]
|
||||
#[derive(::bok_macro::Package)]
|
||||
pub struct Two {
|
||||
pub my_attr: u32,
|
||||
}
|
||||
|
@ -18,6 +18,4 @@ paste = "1.0"
|
||||
bitflags = "2.4"
|
||||
proc-macro2 = "1.0"
|
||||
quote = "1.0"
|
||||
|
||||
[dev-dependencies]
|
||||
bok-macro = { path="../bok-macro" }
|
||||
|
@ -15,6 +15,8 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
pub use ::bok_macro::{package, repository, to_code, Package, Repository};
|
||||
|
||||
//use ::std::any::Any;
|
||||
|
||||
// Package stuff
|
||||
|
Loading…
Reference in New Issue
Block a user