Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rename define_components! to cgp_preset! with slight improvement #41

Merged
merged 18 commits into from
Dec 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,14 @@

## Pre-Release

- Rename `define_components!` to `cgp_preset!` with slight improvement - [#41](https://github.com/contextgeneric/cgp/pull/41)
- Introduce `replace_with!` macro that allows replacement of an identifier with a list of component types in the body.
- Introduce `for_each_replace!` macro that allows repeated replacement of an identifier with each element of components in the list in the body.
- Rename `define_components!` to `cgp_preset!`.
- Use `replace_with!` inside the generated `with_preset!` macro.
- Re-introduce the `IsPreset` trait to allow bulk delegation of components.


- Redesign `derive_component` to `cgp_component` with improved syntax - [#38](https://github.com/contextgeneric/cgp/pull/38)
- Rename the attribute `#[derive_component]` to `#[cgp_component]`
- The macro syntax has been changed as follows:
Expand Down
2 changes: 1 addition & 1 deletion crates/cgp-component-macro-lib/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ description = """
"""

[dependencies]
syn = { version = "2.0.37", features = [ "full" ] }
syn = { version = "2.0.37", features = [ "full", "extra-traits" ] }
quote = "1.0.33"
proc-macro2 = "1.0.67"
itertools = "0.11.0"
Expand Down
28 changes: 1 addition & 27 deletions crates/cgp-component-macro-lib/src/delegate_components/ast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,14 @@ use quote::ToTokens;
use syn::parse::{Parse, ParseStream};
use syn::punctuated::Punctuated;
use syn::token::{Bracket, Colon, Comma, Lt};
use syn::{braced, bracketed, Generics, Ident, Token, Type};
use syn::{braced, bracketed, Generics, Token, Type};

pub struct DelegateComponentsAst {
pub target_type: Type,
pub target_generics: Generics,
pub delegate_entries: DelegateEntriesAst,
}

pub struct DefineComponentsAst {
pub components_ident: Ident,
pub components_generics: Generics,
pub delegate_entries: DelegateEntriesAst,
}

pub struct DelegateEntriesAst {
pub entries: Punctuated<DelegateEntryAst, Comma>,
}
Expand Down Expand Up @@ -63,26 +57,6 @@ impl Parse for DelegateComponentsAst {
}
}

impl Parse for DefineComponentsAst {
fn parse(input: ParseStream) -> syn::Result<Self> {
let components_ident: Ident = input.parse()?;

let components_generics = if input.peek(Lt) {
input.parse()?
} else {
Default::default()
};

let delegate_entries: DelegateEntriesAst = input.parse()?;

Ok(Self {
components_ident,
components_generics,
delegate_entries,
})
}
}

impl Parse for DelegateEntriesAst {
fn parse(input: ParseStream) -> syn::Result<Self> {
let entries = {
Expand Down
67 changes: 0 additions & 67 deletions crates/cgp-component-macro-lib/src/delegate_components/define.rs

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ use quote::ToTokens;
use crate::delegate_components::ast::DelegateComponentsAst;
use crate::delegate_components::impl_delegate::impl_delegate_components;

pub fn delegate_components(body: TokenStream) -> TokenStream {
let ast: DelegateComponentsAst = syn::parse2(body).unwrap();
pub fn delegate_components(body: TokenStream) -> syn::Result<TokenStream> {
let ast: DelegateComponentsAst = syn::parse2(body)?;

let impl_items = impl_delegate_components(
&ast.target_type,
Expand All @@ -19,5 +19,5 @@ pub fn delegate_components(body: TokenStream) -> TokenStream {
output.extend(impl_item.to_token_stream());
}

output
Ok(output)
}
3 changes: 0 additions & 3 deletions crates/cgp-component-macro-lib/src/delegate_components/mod.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
pub mod ast;
pub mod define;
pub mod define_struct;
pub mod delegate;
pub mod delegates_to;
pub mod impl_delegate;
pub mod merge_generics;
pub mod substitution_macro;

pub use define::define_components;
pub use delegate::delegate_components;

This file was deleted.

Loading
Loading