mirror of
https://codeberg.org/unspeaker/tengri.git
synced 2025-12-06 03:36:42 +01:00
wip: finally, informative type errors from the macro
Some checks failed
/ build (push) Has been cancelled
Some checks failed
/ build (push) Has been cancelled
fixin mixin
This commit is contained in:
parent
abc87d3234
commit
583660c330
10 changed files with 152 additions and 205 deletions
|
|
@ -84,7 +84,7 @@ impl ToTokens for CommandDef {
|
|||
let mut out = TokenStream2::new();
|
||||
for (arg, ty) in arm.args() {
|
||||
write_quote_to(&mut out, quote! {
|
||||
#arg: Namespace::take_from_or_fail(self, words)?,
|
||||
#arg: Provide::provide_or_fail(self, words)?,
|
||||
});
|
||||
}
|
||||
out
|
||||
|
|
@ -149,8 +149,8 @@ impl ToTokens for CommandDef {
|
|||
}
|
||||
}
|
||||
/// Generated by [tengri_proc::command].
|
||||
impl ::tengri::dsl::Namespace<#state> for #command_enum {
|
||||
fn take_from <'source> (
|
||||
impl<'n> ::tengri::dsl::Provide<'n, #state> for #command_enum {
|
||||
fn provide <'source> (
|
||||
state: &#state,
|
||||
words: &mut ::tengri::dsl::TokenIter<'source>
|
||||
) -> Perhaps<Self> {
|
||||
|
|
|
|||
|
|
@ -85,8 +85,8 @@ impl ToTokens for ExposeImpl {
|
|||
let values = variants.iter().map(ExposeArm::from);
|
||||
write_quote_to(out, quote! {
|
||||
/// Generated by [tengri_proc::expose].
|
||||
impl ::tengri::dsl::Namespace<#state> for #t {
|
||||
fn take_from <'source> (
|
||||
impl<'n> ::tengri::dsl::Provide<'n, #state> for #t {
|
||||
fn provide <'source> (
|
||||
state: &#state,
|
||||
words: &mut ::tengri::dsl::TokenIter<'source>
|
||||
) -> Perhaps<Self> {
|
||||
|
|
|
|||
|
|
@ -46,7 +46,7 @@ impl ToTokens for ViewDef {
|
|||
let builtins: Vec<_> = builtins_with_types()
|
||||
.iter()
|
||||
.map(|ty|write_quote(quote! {
|
||||
let value: Option<#ty> = Dsl::take(state, &mut exp.clone())?;
|
||||
let value: Option<#ty> = Receive::<#ty>::receive(self, &mut exp.clone())?;
|
||||
if let Some(value) = value {
|
||||
return Ok(Some(value.boxed()))
|
||||
}
|
||||
|
|
@ -55,30 +55,20 @@ impl ToTokens for ViewDef {
|
|||
let exposed: Vec<_> = exposed
|
||||
.iter()
|
||||
.map(|(key, value)|write_quote(quote! {
|
||||
#key => Some(#self_ty::#value(state).boxed()),
|
||||
#key => {
|
||||
Some(Box::new(Thunk::new(move||#self_ty::#value(self))))//Box::new("todo"))
|
||||
},
|
||||
})).collect();
|
||||
write_quote_to(out, quote! {
|
||||
#block
|
||||
/// Generated by [tengri_proc].
|
||||
///
|
||||
/// Delegates the rendering of [#self_ty] to the [#self_ty::view} method,
|
||||
/// which you will need to implement, e.g. passing a [TokenIter]
|
||||
/// containing a layout and keybindings config from user dirs.
|
||||
impl ::tengri::output::Content<#output> for #self_ty {
|
||||
fn content (&self) -> impl Render<#output> {
|
||||
#self_ty::view(self)
|
||||
}
|
||||
}
|
||||
/// Generated by [tengri_proc].
|
||||
///
|
||||
/// Gives [#self_ty] the ability to construct the [Render]able
|
||||
/// which might corresponds to a given [TokenStream],
|
||||
/// while taking [#self_ty]'s state into consideration.
|
||||
impl ::tengri::dsl::Namespace<#self_ty> for Box<dyn Render<#output> + '_> {
|
||||
fn take_from <'source> (
|
||||
state: &#self_ty,
|
||||
words: &mut ::tengri::dsl::TokenIter<'source>
|
||||
) -> Perhaps<Self> {
|
||||
impl ::tengri::dsl::Receive<Box<dyn Render<#output>>> for #self_ty {
|
||||
fn receive <'source> (&self, words: &mut ::tengri::dsl::TokenIter<'source>)
|
||||
-> Perhaps<Box<dyn Render<#output>>>
|
||||
{
|
||||
Ok(if let Some(::tengri::dsl::Token { value, .. }) = words.peek() {
|
||||
match value {
|
||||
// Expressions are handled by built-in functions
|
||||
|
|
@ -100,6 +90,18 @@ impl ToTokens for ViewDef {
|
|||
})
|
||||
}
|
||||
}
|
||||
/// Generated by [tengri_proc].
|
||||
///
|
||||
/// Delegates the rendering of [#self_ty] to the [#self_ty::view} method,
|
||||
/// which you will need to implement, e.g. passing a [TokenIter]
|
||||
/// containing a layout and keybindings config from user dirs.
|
||||
impl ::tengri::output::Content<#output> for #self_ty {
|
||||
fn content (&self) -> impl Render<#output> + '_ {
|
||||
#self_ty::view(self)
|
||||
}
|
||||
}
|
||||
// Original user-provided implementation:
|
||||
#block
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue