Tested and improved validation of #[property] attribute arguments.
This commit is contained in:
parent
2263a63657
commit
5a9dde728c
|
@ -0,0 +1,23 @@
|
|||
use zero_ui::core::{property, UiNode};
|
||||
|
||||
#[property(context, unknown: true)]
|
||||
fn unknown_arg(child: impl UiNode, input: bool) -> impl UiNode {
|
||||
child
|
||||
}
|
||||
|
||||
#[property(context, allowed_in_when: "false")]
|
||||
fn invalid_allowed_in_when_value(child: impl UiNode, input: bool) -> impl UiNode {
|
||||
child
|
||||
}
|
||||
|
||||
#[property(context, allowed_in_when)]
|
||||
fn missing_allowed_in_when_value_1(child: impl UiNode, input: bool) -> impl UiNode {
|
||||
child
|
||||
}
|
||||
|
||||
#[property(context, allowed_in_when: )]
|
||||
fn missing_allowed_in_when_value_2(child: impl UiNode, input: bool) -> impl UiNode {
|
||||
child
|
||||
}
|
||||
|
||||
fn main() {}
|
|
@ -0,0 +1,27 @@
|
|||
use zero_ui::core::{property, UiNode};
|
||||
|
||||
#[property(context)]
|
||||
fn trailing_comma_1(child: impl UiNode, input: bool) -> impl UiNode {
|
||||
let _ = input;
|
||||
child
|
||||
}
|
||||
|
||||
#[property(context, allowed_in_when: true)]
|
||||
fn allowed_in_when(child: impl UiNode, input: bool) -> impl UiNode {
|
||||
let _ = input;
|
||||
child
|
||||
}
|
||||
|
||||
#[property(context, allowed_in_when: false)]
|
||||
fn not_allowed_in_when(child: impl UiNode, input: bool) -> impl UiNode {
|
||||
let _ = input;
|
||||
child
|
||||
}
|
||||
|
||||
#[property(context, allowed_in_when: false,)]
|
||||
fn trailing_comma_2(child: impl UiNode, input: bool) -> impl UiNode {
|
||||
let _ = input;
|
||||
child
|
||||
}
|
||||
|
||||
fn main() {}
|
|
@ -27,7 +27,7 @@ pub use input::keyword;
|
|||
pub use input::Priority;
|
||||
|
||||
mod input {
|
||||
use syn::{parse::*, *};
|
||||
use syn::{parse::*, spanned::Spanned, *};
|
||||
|
||||
pub mod keyword {
|
||||
syn::custom_keyword!(context);
|
||||
|
@ -51,8 +51,21 @@ mod input {
|
|||
Ok(MacroArgs {
|
||||
priority: input.parse()?,
|
||||
allowed_in_when: {
|
||||
if input.peek(Token![,]) {
|
||||
Some((input.parse()?, input.parse()?, input.parse()?, input.parse()?))
|
||||
if input.peek(Token![,]) && input.peek2(keyword::allowed_in_when) {
|
||||
let comma = input.parse().unwrap();
|
||||
let allowed_in_when = input.parse::<keyword::allowed_in_when>().unwrap();
|
||||
|
||||
if input.is_empty() {
|
||||
return Err(syn::Error::new(allowed_in_when.span(), "expected `allowed_in_when : <bool>`"));
|
||||
}
|
||||
let colon = input.parse::<Token![:]>()?;
|
||||
|
||||
if input.is_empty() {
|
||||
return Err(syn::Error::new(colon.span(), "expected `: <bool>`"));
|
||||
}
|
||||
let bool_ = input.parse()?;
|
||||
|
||||
Some((comma, allowed_in_when, colon, bool_))
|
||||
} else {
|
||||
None
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue