mirror of
https://codeberg.org/unspeaker/tengri.git
synced 2025-12-06 03:36:42 +01:00
This commit is contained in:
parent
cbd28a5934
commit
5a2177cc77
4 changed files with 131 additions and 94 deletions
|
|
@ -121,11 +121,7 @@ impl ToTokens for ExposeArm {
|
|||
}
|
||||
}
|
||||
|
||||
impl From<LitStr> for ExposeSym {
|
||||
fn from (this: LitStr) -> Self {
|
||||
Self(this)
|
||||
}
|
||||
}
|
||||
impl From<LitStr> for ExposeSym { fn from (this: LitStr) -> Self { Self(this) } }
|
||||
|
||||
impl PartialOrd for ExposeSym {
|
||||
fn partial_cmp (&self, other: &Self) -> Option<Ordering> {
|
||||
|
|
@ -153,11 +149,7 @@ impl PartialEq for ExposeSym {
|
|||
|
||||
impl Eq for ExposeSym {}
|
||||
|
||||
impl From<Type> for ExposeType {
|
||||
fn from (this: Type) -> Self {
|
||||
Self(Box::new(this))
|
||||
}
|
||||
}
|
||||
impl From<Type> for ExposeType { fn from (this: Type) -> Self { Self(Box::new(this)) } }
|
||||
|
||||
impl PartialOrd for ExposeType {
|
||||
fn partial_cmp (&self, other: &Self) -> Option<Ordering> {
|
||||
|
|
|
|||
|
|
@ -4,9 +4,7 @@ use crate::*;
|
|||
pub(crate) struct ViewDef(pub(crate) ViewMeta, pub(crate) ViewImpl);
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub(crate) struct ViewMeta {
|
||||
pub(crate) output: Ident,
|
||||
}
|
||||
pub(crate) struct ViewMeta { pub(crate) output: Ident }
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub(crate) struct ViewImpl {
|
||||
|
|
@ -43,53 +41,54 @@ impl ToTokens for ViewDef {
|
|||
fn to_tokens (&self, out: &mut TokenStream2) {
|
||||
let Self(ViewMeta { output }, ViewImpl { block, exposed }) = self;
|
||||
let self_ty = &block.self_ty;
|
||||
let builtins: Vec<_> = builtins_with_types()
|
||||
.iter()
|
||||
.map(|ty|write_quote(quote! {
|
||||
let value: Option<#ty> = Give::<#ty>::give(self, &mut exp.clone())?;
|
||||
if let Some(value) = value {
|
||||
return Ok(Some(value.boxed()))
|
||||
}
|
||||
}))
|
||||
.collect();
|
||||
let exposed: Vec<_> = exposed
|
||||
.iter()
|
||||
.map(|(key, value)|write_quote(quote! {
|
||||
#key => {
|
||||
Some(Box::new(Thunk::new(move||#self_ty::#value(self))))//Box::new("todo"))
|
||||
},
|
||||
})).collect();
|
||||
// Expressions are handled by built-in functions
|
||||
// that operate over constants and symbols.
|
||||
let builtins: Vec<_> = builtins_with_types().iter().map(|ty|write_quote(quote! {
|
||||
::tengri::dsl::Value::Exp(_, expr) => {
|
||||
Give::<#ty>::give(&mut expr.clone()).map(|value|value.boxed())
|
||||
},
|
||||
})).collect();
|
||||
// Symbols are handled by user-taked functions
|
||||
// that take no parameters but `&self`.
|
||||
let exposed: Vec<_> = exposed.iter().map(|(key, value)|write_quote(quote! {
|
||||
::tengri::dsl::Value::Sym(#key) => {
|
||||
Some(Box::new(Thunk::new(move||#self_ty::#value(self))))
|
||||
},
|
||||
})).collect();
|
||||
write_quote_to(out, quote! {
|
||||
/// 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::Give<Box<dyn Render<#output>>> for #self_ty {
|
||||
fn give <'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
|
||||
// that operate over constants and symbols.
|
||||
::tengri::dsl::Value::Exp(_, exp) => {
|
||||
#(#builtins)*
|
||||
None
|
||||
},
|
||||
// Symbols are handled by user-taked functions
|
||||
// that take no parameters but `&self`.
|
||||
::tengri::dsl::Value::Sym(sym) => match sym {
|
||||
#(#exposed)*
|
||||
_ => None
|
||||
},
|
||||
_ => None
|
||||
}
|
||||
} else {
|
||||
None
|
||||
})
|
||||
}
|
||||
}
|
||||
give!(Box<dyn Render<#output>>|state:#self_ty, words|Ok(None));
|
||||
//impl <'n, State: ::tengri::dsl::Give<Box<dyn Render<#output>>>>
|
||||
//Take<'n, Box<dyn Render<#output>> for #self_ty
|
||||
//{
|
||||
//fn give <'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
|
||||
//// that operate over constants and symbols.
|
||||
//::tengri::dsl::Value::Exp(_, exp) => {
|
||||
//#(#builtins)*
|
||||
//None
|
||||
//},
|
||||
//// Symbols are handled by user-taked functions
|
||||
//// that take no parameters but `&self`.
|
||||
//::tengri::dsl::Value::Sym(sym) => match sym {
|
||||
//#(#exposed)*
|
||||
//_ => None
|
||||
//},
|
||||
//_ => None
|
||||
//}
|
||||
//} else {
|
||||
//None
|
||||
//})
|
||||
//}
|
||||
//}
|
||||
/// Generated by [tengri_proc].
|
||||
///
|
||||
/// Delegates the rendering of [#self_ty] to the [#self_ty::view} method,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue