From a6ce33267e8920de6c21a3ff2379129fbdb5e402 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Fri, 8 Jul 2022 17:33:16 +0200 Subject: [PATCH 1/3] Rename custom `#[value]` attribute to `#[param]` It is a model parameter, so the new name is more descriptive, while just as short. --- crates/fj-proc/src/lib.rs | 14 +++++++------- models/cuboid/src/lib.rs | 6 +++--- models/spacer/src/lib.rs | 6 +++--- models/star/src/lib.rs | 8 ++++---- 4 files changed, 17 insertions(+), 17 deletions(-) diff --git a/crates/fj-proc/src/lib.rs b/crates/fj-proc/src/lib.rs index 6432a25b0..6e7abdd53 100644 --- a/crates/fj-proc/src/lib.rs +++ b/crates/fj-proc/src/lib.rs @@ -86,7 +86,7 @@ pub fn model(_: TokenStream, input: TokenStream) -> TokenStream { } /// Represents one parameter given to the `model` -/// `#[value(default=3, min=4)] num_points: u64` +/// `#[param(default=3, min=4)] num_points: u64` /// `^^^^^^^^^^^^^^^^^^^^^^^^^^ ~~~~~~~~~~ ^^^-- ty` /// ` | |` /// ` attr ident` @@ -112,8 +112,8 @@ impl Parse for Argument { } } -/// Represents all arguments given to the `#[value]` attribute eg: -/// `#[value(default=3, min=4)]` +/// Represents all arguments given to the `#[param]` attribute eg: +/// `#[param(default=3, min=4)]` /// ` ^^^^^^^^^^^^^^^^` #[derive(Debug, Clone)] struct HelperAttribute { @@ -128,11 +128,11 @@ impl Parse for HelperAttribute { let _: syn::token::Pound = input.parse()?; bracketed!(attr_content in input); let ident: proc_macro2::Ident = attr_content.parse()?; - if ident != *"value" { + if ident != *"param" { return Err(syn::Error::new_spanned( ident.clone(), format!( - "Unknown attribute \"{}\" found, expected \"value\"", + "Unknown attribute \"{}\" found, expected \"param\"", ident ), )); @@ -180,8 +180,8 @@ impl HelperAttribute { } } -/// Represents one argument given to the `#[value]` attribute eg: -/// `#[value(default=3)]` +/// Represents one argument given to the `#[param]` attribute eg: +/// `#[param(default=3)]` /// ` ^^^^^^^^^----- is parsed as DefaultParam{ ident: Some(default), val: 3 }` #[derive(Debug, Clone)] struct DefaultParam { diff --git a/models/cuboid/src/lib.rs b/models/cuboid/src/lib.rs index 6ce903ae5..6505e3612 100644 --- a/models/cuboid/src/lib.rs +++ b/models/cuboid/src/lib.rs @@ -1,8 +1,8 @@ #[fj::model] pub fn model( - #[value(default = 3.0)] x: f64, - #[value(default = 2.0)] y: f64, - #[value(default = 1.0)] z: f64, + #[param(default = 3.0)] x: f64, + #[param(default = 2.0)] y: f64, + #[param(default = 1.0)] z: f64, ) -> fj::Shape { #[rustfmt::skip] let rectangle = fj::Sketch::from_points(vec![ diff --git a/models/spacer/src/lib.rs b/models/spacer/src/lib.rs index 2849164ad..98724904d 100644 --- a/models/spacer/src/lib.rs +++ b/models/spacer/src/lib.rs @@ -2,9 +2,9 @@ use fj::syntax::*; #[fj::model] pub fn model( - #[value(default = 1.0, min = inner * 1.01)] outer: f64, - #[value(default = 0.5, max = outer * 0.99)] inner: f64, - #[value(default = 1.0)] height: f64, + #[param(default = 1.0, min = inner * 1.01)] outer: f64, + #[param(default = 0.5, max = outer * 0.99)] inner: f64, + #[param(default = 1.0)] height: f64, ) -> fj::Shape { let outer_edge = fj::Sketch::from_circle(fj::Circle::from_radius(outer)); let inner_edge = fj::Sketch::from_circle(fj::Circle::from_radius(inner)); diff --git a/models/star/src/lib.rs b/models/star/src/lib.rs index 477c4d715..3d1775680 100644 --- a/models/star/src/lib.rs +++ b/models/star/src/lib.rs @@ -2,10 +2,10 @@ use std::f64::consts::PI; #[fj::model] pub fn model( - #[value(default = 5, min = 3)] num_points: u64, - #[value(default = 1.0, min = 1.0)] r1: f64, - #[value(default = 2.0, min = 2.0)] r2: f64, - #[value(default = 1.0)] h: f64, + #[param(default = 5, min = 3)] num_points: u64, + #[param(default = 1.0, min = 1.0)] r1: f64, + #[param(default = 2.0, min = 2.0)] r2: f64, + #[param(default = 1.0)] h: f64, ) -> fj::Shape { let num_vertices = num_points * 2; let vertex_iter = (0..num_vertices).map(|i| { From b4f9893dc25bec727e52698ae65fc869649fef1f Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Fri, 8 Jul 2022 17:34:32 +0200 Subject: [PATCH 2/3] Update variable name --- crates/fj-proc/src/lib.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/crates/fj-proc/src/lib.rs b/crates/fj-proc/src/lib.rs index 6e7abdd53..c5c7b43a0 100644 --- a/crates/fj-proc/src/lib.rs +++ b/crates/fj-proc/src/lib.rs @@ -124,7 +124,7 @@ struct HelperAttribute { impl Parse for HelperAttribute { fn parse(input: syn::parse::ParseStream) -> syn::Result { let attr_content; - let value_content; + let param_content; let _: syn::token::Pound = input.parse()?; bracketed!(attr_content in input); let ident: proc_macro2::Ident = attr_content.parse()?; @@ -139,14 +139,14 @@ impl Parse for HelperAttribute { } if attr_content.peek(syn::token::Paren) { - parenthesized!(value_content in attr_content); - if value_content.is_empty() { + parenthesized!(param_content in attr_content); + if param_content.is_empty() { Ok(Self { values: None }) } else { Ok(Self { values: Some( syn::punctuated::Punctuated::parse_separated_nonempty_with( - &value_content, + ¶m_content, DefaultParam::parse, )?, ), From d6c471a76658f94aeaa25cb18d51b544da42101b Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Fri, 8 Jul 2022 17:35:22 +0200 Subject: [PATCH 3/3] Update struct field name --- crates/fj-proc/src/lib.rs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/crates/fj-proc/src/lib.rs b/crates/fj-proc/src/lib.rs index c5c7b43a0..e398d8563 100644 --- a/crates/fj-proc/src/lib.rs +++ b/crates/fj-proc/src/lib.rs @@ -117,7 +117,7 @@ impl Parse for Argument { /// ` ^^^^^^^^^^^^^^^^` #[derive(Debug, Clone)] struct HelperAttribute { - pub values: + pub param: Option>, } @@ -141,10 +141,10 @@ impl Parse for HelperAttribute { if attr_content.peek(syn::token::Paren) { parenthesized!(param_content in attr_content); if param_content.is_empty() { - Ok(Self { values: None }) + Ok(Self { param: None }) } else { Ok(Self { - values: Some( + param: Some( syn::punctuated::Punctuated::parse_separated_nonempty_with( ¶m_content, DefaultParam::parse, @@ -153,14 +153,14 @@ impl Parse for HelperAttribute { }) } } else { - Ok(Self { values: None }) + Ok(Self { param: None }) } } } impl HelperAttribute { fn get_parameter(&self, parameter_name: &str) -> Option { - if let Some(values) = self.values.clone() { + if let Some(values) = self.param.clone() { values.into_iter().find(|val| val.ident == *parameter_name) } else { None