Skip to content

Commit

Permalink
Also reserving Option<...> for query arguments.
Browse files Browse the repository at this point in the history
  • Loading branch information
recatek committed Jan 19, 2025
1 parent 993fc64 commit f8b64c7
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 9 deletions.
22 changes: 19 additions & 3 deletions macros/src/generate/query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,9 @@ fn find_bind_mut(param: &ParseQueryParam) -> TokenStream {
ParseQueryParamType::OneOf(_) => {
panic!("must unpack OneOf first")
}
ParseQueryParamType::Option(_) => {
todo!() // Not yet implemented
}
ParseQueryParamType::With(_) => {
todo!() // Not yet implemented
}
Expand Down Expand Up @@ -232,7 +235,10 @@ fn find_bind_borrow(param: &ParseQueryParam) -> TokenStream {
ParseQueryParamType::OneOf(_) => {
panic!("must unpack OneOf first")
}
ParseQueryParamType::With(_) => {
ParseQueryParamType::Option(_) => {
todo!() // Not yet implemented
}
ParseQueryParamType::With(_) => {
todo!() // Not yet implemented
}
ParseQueryParamType::Without(_) => {
Expand Down Expand Up @@ -507,7 +513,10 @@ fn iter_bind_mut(param: &ParseQueryParam) -> TokenStream {
ParseQueryParamType::OneOf(_) => {
panic!("must unpack OneOf first")
}
ParseQueryParamType::With(_) => {
ParseQueryParamType::Option(_) => {
todo!() // Not yet implemented
}
ParseQueryParamType::With(_) => {
todo!() // Not yet implemented
}
ParseQueryParamType::Without(_) => {
Expand Down Expand Up @@ -546,7 +555,10 @@ fn iter_bind_borrow(param: &ParseQueryParam) -> TokenStream {
ParseQueryParamType::OneOf(_) => {
panic!("must unpack OneOf first")
}
ParseQueryParamType::With(_) => {
ParseQueryParamType::Option(_) => {
todo!() // Not yet implemented
}
ParseQueryParamType::With(_) => {
todo!() // Not yet implemented
}
ParseQueryParamType::Without(_) => {
Expand All @@ -572,6 +584,7 @@ fn to_type(param: &ParseQueryParam, archetype: &DataArchetype) -> TokenStream {
ParseQueryParamType::EntityDirectAny => quote!(EntityDirectAny),
ParseQueryParamType::EntityDirectWild => quote!(EntityDirect<#archetype_name>),
ParseQueryParamType::OneOf(_) => panic!("must unpack OneOf first"),
ParseQueryParamType::Option(_) => todo!(),
ParseQueryParamType::With(_) => todo!(),
ParseQueryParamType::Without(_) => todo!(),
}
Expand Down Expand Up @@ -676,6 +689,9 @@ fn bind_query_params(
continue; // No need to check more
}
}
ParseQueryParamType::Option(_) => {
todo!() // Not yet implemented
}
ParseQueryParamType::With(_) => {
todo!() // Not yet implemented
}
Expand Down
27 changes: 21 additions & 6 deletions macros/src/parse/query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ mod kw {
syn::custom_keyword!(EntityDirectAny);

syn::custom_keyword!(OneOf);
syn::custom_keyword!(Option);
syn::custom_keyword!(With);
syn::custom_keyword!(Without);
}
Expand Down Expand Up @@ -59,19 +60,22 @@ pub struct ParseQueryParam {
}

#[derive(Clone, Debug)]
#[allow(dead_code)]
pub enum ParseQueryParamType {
Component(Ident), // CompFoo
Component(Ident), // CompFoo

// Entity Types
Entity(Ident), // Entity<A>
EntityWild, // Entity<_>
EntityAny, // EntityAny
EntityDirect(Ident), // EntityDirect<A>
EntityDirectWild, // EntityDirect<_>
EntityDirectAny, // EntityDirectAny
OneOf(Box<[Ident]>), // OneOf<CompFoo, CompBar>

#[allow(dead_code)]
// Special Types
OneOf(Box<[Ident]>), // OneOf<CompFoo, CompBar>
Option(Ident), // Option<CompFoo> -- TODO: RESERVED
With(Ident), // With<CompFoo> -- TODO: RESERVED
#[allow(dead_code)]
Without(Ident), // Without<CompFoo> -- TODO: RESERVED
}

Expand Down Expand Up @@ -281,10 +285,21 @@ impl Parse for ParseQueryParamType {
break Err(lookahead.error());
}
}
} else if lookahead.peek(kw::Option) {
Err(syn::Error::new(
input.span(),
"reserved special 'Option' not yet implemented",
))
} else if lookahead.peek(kw::With) {
Err(syn::Error::new(input.span(), "reserved keyword 'With' not yet implemented"))
Err(syn::Error::new(
input.span(),
"reserved special 'With' not yet implemented",
))
} else if lookahead.peek(kw::Without) {
Err(syn::Error::new(input.span(), "reserved keyword 'Without' not yet implemented"))
Err(syn::Error::new(
input.span(),
"reserved special 'Without' not yet implemented",
))
} else if lookahead.peek(Ident) {
// Component
Ok(ParseQueryParamType::Component(input.parse()?))
Expand Down

0 comments on commit f8b64c7

Please sign in to comment.