fix: command: refs
Some checks are pending
/ build (push) Waiting to run

This commit is contained in:
🪞👃🪞 2025-05-08 17:39:02 +03:00
parent e3bfae8897
commit 2a6087e1c7
2 changed files with 30 additions and 19 deletions

View file

@ -1,5 +1,5 @@
#![feature(str_as_str)]
#![feature(box_patterns)]
extern crate proc_macro;
pub(crate) use std::collections::{BTreeMap, BTreeSet};
@ -14,7 +14,8 @@ pub(crate) use syn::{
parse, parse_macro_input, parse_quote as pq,
braced, bracketed, parenthesized, Token,
Arm, Expr, Attribute, Meta, MetaList, Path, PathSegment, PathArguments,
ImplItem, ImplItemFn, LitStr, Type, ItemImpl, ReturnType, Signature, FnArg, PatType,
ImplItem, ImplItemFn, LitStr, Type, ItemImpl, ReturnType, Signature, FnArg,
Pat, PatType, PatIdent,
parse::{Parse, ParseStream, Result},
token::{PathSep, Brace},
punctuated::Punctuated,

View file

@ -88,11 +88,11 @@ impl ToTokens for CommandDef {
});
//if exposed.len() > 0 {
//panic!("{:#?}", block.self_ty);
if let Type::Path(ref path) = *block.self_ty {
if path.path.segments.get(0).unwrap().ident == "TekCommand" {
//if let Type::Path(ref path) = *block.self_ty {
//if path.path.segments.get(0).unwrap().ident == "TekCommand" {
//panic!("\n{}", quote! {#out});
}
}
//}
//}
}
}
@ -117,8 +117,10 @@ impl CommandArm {
out.append(Group::new(Delimiter::Brace, {
let mut out = TokenStream2::new();
for arg in self.1.iter().skip(2) {
if let FnArg::Typed(PatType { attrs, pat, colon_token, ty }) = arg {
write_quote_to(&mut out, quote! { #pat : #ty , });
if let FnArg::Typed(PatType {
ty, pat: box Pat::Ident(PatIdent { ident, .. }), ..
}) = arg {
write_quote_to(&mut out, quote! { #ident : #ty , });
} else {
unreachable!("only typed args should be present at this position")
}
@ -137,13 +139,15 @@ impl CommandArm {
out.append(Group::new(Delimiter::Brace, {
let mut out = TokenStream2::new();
for arg in self.1.iter().skip(2) {
if let FnArg::Typed(PatType { attrs, pat, colon_token, ty }) = arg {
if let FnArg::Typed(PatType {
ty, pat: box Pat::Ident(PatIdent { ident: arg, .. }), ..
}) = arg {
let take_err = LitStr::new(&format!("{}: missing argument \"{}\" ({})",
quote!{#ident}, quote!{#pat}, quote!{#ty}), Span::call_site());
quote!{#ident}, quote!{#arg}, quote!{#ty}), Span::call_site());
let give_err = LitStr::new(&format!("{}: missing value \"{}\" ({})",
quote!{#ident}, quote!{#pat}, quote!{#ty}), Span::call_site());
quote!{#ident}, quote!{#arg}, quote!{#ty}), Span::call_site());
write_quote_to(&mut out, quote! {
#pat : Context::get(state, &iter.next().expect(#take_err).value)
#arg : Context::get(state, &iter.next().expect(#take_err).value)
.expect(#give_err) ,
});
} else {
@ -163,8 +167,10 @@ impl CommandArm {
out.append(Group::new(Delimiter::Brace, {
let mut out = TokenStream2::new();
for arg in self.1.iter().skip(2) {
if let FnArg::Typed(PatType { attrs, pat, colon_token, ty }) = arg {
write_quote_to(&mut out, quote! { #pat , });
if let FnArg::Typed(PatType {
ty, pat: box Pat::Ident(PatIdent { ident: arg, .. }), ..
}) = arg {
write_quote_to(&mut out, quote! { #arg , });
} else {
unreachable!("only typed args should be present at this position")
}
@ -179,11 +185,13 @@ impl CommandArm {
let key = LitStr::new(&self.to_key(), Span::call_site());
let ident = &self.0;
let take_args = self.1.iter().skip(2).map(|arg|{
if let FnArg::Typed(PatType { attrs, pat, colon_token, ty }) = arg {
if let FnArg::Typed(PatType {
ty, pat: box Pat::Ident(PatIdent { ident: arg, .. }), ..
}) = arg {
let take_err = LitStr::new(&format!("{}: missing argument \"{}\" ({})",
quote!{#ident}, quote!{#pat}, quote!{#ty}), Span::call_site());
quote!{#ident}, quote!{#arg}, quote!{#ty}), Span::call_site());
write_quote(quote! {
let #pat: #ty = Context::<#ty>::get(
let #ident: #ty = Context::<#ty>::get(
state,
&iter.next().expect(#take_err).value
);
@ -208,10 +216,12 @@ impl CommandArm {
let variant = self.to_enum_variant_unbind();
let mut give_rest = write_quote(quote! { /*TODO*/ });
let give_args = self.1.iter().skip(2).map(|arg|{
if let FnArg::Typed(PatType { attrs, pat, colon_token, ty }) = arg {
if let FnArg::Typed(PatType {
ty, pat: box Pat::Ident(PatIdent { ident: arg, .. }), ..
}) = arg {
//let give_err = LitStr::new(&format!("{}: missing value \"{}\" ({})",
//quote!{#ident}, quote!{#pat}, quote!{#ty}), Span::call_site());
write_quote(quote! { #pat, })
write_quote(quote! { #arg, })
} else {
unreachable!("only typed args should be present at this position")
}