wip: fix(dsl): maybe getting somewhere?
Some checks are pending
/ build (push) Waiting to run

This commit is contained in:
🪞👃🪞 2025-06-21 13:48:45 +03:00
parent 91dc77cfea
commit 11f686650f
19 changed files with 964 additions and 918 deletions

View file

@ -44,15 +44,16 @@ impl ToTokens for ViewDef {
// Expressions are handled by built-in functions
// that operate over constants and symbols.
let builtin = builtins_with_boxes_output(quote! { #output }).map(|builtin|quote! {
::tengri::dsl::Value::Exp(_, expr) => return Ok(Some(
#builtin::try_provide(state, expr, ||"failed to load builtin")?.boxed()
::tengri::dsl::DslVal::Exp(_, expr) => return Ok(Some(
#builtin::dsl_from(self, expr, ||Box::new("failed to load builtin".into()))?
.boxed()
)),
});
// Symbols are handled by user-taked functions
// that take no parameters but `&self`.
let exposed = exposed.iter().map(|(key, value)|write_quote(quote! {
::tengri::dsl::Value::Sym(#key) => return Ok(Some(
state.#value().boxed()
::tengri::dsl::DslVal::Sym(#key) => return Ok(Some(
self.#value().boxed()
)),
}));
write_quote_to(out, quote! {
@ -63,15 +64,14 @@ impl ToTokens for ViewDef {
/// Makes [#self_ty] able to construct the [Render]able
/// which might correspond to a given [TokenStream],
/// while taking [#self_ty]'s state into consideration.
impl<'state> ::tengri::dsl::Dsl<Box<dyn Render<#output> + 'state>> for #self_ty {
fn try_provide (state: &'state #self_ty, mut words: ::tengri::dsl::Ast) ->
Perhaps<Box<dyn Render<#output> + 'state>>
impl<'state> ::tengri::dsl::DslInto<
Box<dyn ::tengri::output::Render<#output> + 'state>
> for #self_ty {
fn try_dsl_into (&self, dsl: &impl ::tengri::dsl::Dsl)
-> Perhaps<Box<dyn ::tengri::output::Render<#output> + 'state>>
{
Ok(if let Some(::tengri::dsl::Token { value, .. }) = words.peek() {
match value { #(#builtin)* #(#exposed)* _ => None }
} else {
None
})
use ::tengri::dsl::DslVal::*;
Ok(match dsl.val() { #(#builtin)* #(#exposed)* _ => return Ok(None) })
}
}
})