mirror of
https://codeberg.org/unspeaker/tengri.git
synced 2025-12-06 19:56:44 +01:00
This commit is contained in:
parent
2048dd2263
commit
776cea6f1b
9 changed files with 126 additions and 108 deletions
|
|
@ -149,9 +149,9 @@ impl ToTokens for CommandDef {
|
|||
}
|
||||
}
|
||||
/// Generated by [tengri_proc::command].
|
||||
impl<'source> ::tengri::dsl::Namespace<'source, #state> for #command_enum {
|
||||
fn take_from <'state> (
|
||||
state: &'state #state,
|
||||
impl ::tengri::dsl::Namespace<#state> for #command_enum {
|
||||
fn take_from <'source> (
|
||||
state: &#state,
|
||||
words: &mut ::tengri::dsl::TokenIter<'source>
|
||||
) -> Perhaps<Self> {
|
||||
let mut words = words.clone();
|
||||
|
|
|
|||
|
|
@ -85,9 +85,9 @@ impl ToTokens for ExposeImpl {
|
|||
let values = variants.iter().map(ExposeArm::from);
|
||||
write_quote_to(out, quote! {
|
||||
/// Generated by [tengri_proc::expose].
|
||||
impl<'source> ::tengri::dsl::Namespace<'source, #state> for #t {
|
||||
fn take_from <'state> (
|
||||
state: &'state #state,
|
||||
impl ::tengri::dsl::Namespace<#state> for #t {
|
||||
fn take_from <'source> (
|
||||
state: &#state,
|
||||
words: &mut ::tengri::dsl::TokenIter<'source>
|
||||
) -> Perhaps<Self> {
|
||||
Ok(Some(match words.next().map(|x|x.value) {
|
||||
|
|
|
|||
|
|
@ -43,10 +43,15 @@ impl ToTokens for ViewDef {
|
|||
fn to_tokens (&self, out: &mut TokenStream2) {
|
||||
let Self(ViewMeta { output }, ViewImpl { block, exposed }) = self;
|
||||
let view = &block.self_ty;
|
||||
let builtins = builtins().iter().map(|ty|write_quote(quote! {
|
||||
if let Some(value) = Namespace::<#ty>::take_from(state, &mut exp.clone())? {
|
||||
return Ok(Some(value.boxed()))
|
||||
}
|
||||
})).collect::<Vec<_>>();
|
||||
let mut available = vec![];
|
||||
let exposed: Vec<_> = exposed.iter().map(|(key, value)|{
|
||||
available.push(key.clone());
|
||||
write_quote(quote! { #key => Some(state.#value().boxed()), })
|
||||
write_quote(quote! { #key => Some(#view::#value(state).boxed()), })
|
||||
}).collect();
|
||||
let available: String = available.join(", ");
|
||||
let error_msg = LitStr::new(
|
||||
|
|
@ -70,23 +75,26 @@ impl ToTokens for ViewDef {
|
|||
/// Gives [#view] the ability to construct the [Render]able
|
||||
/// which might corresponds to a given [TokenStream],
|
||||
/// while taking [#view]'s state into consideration.
|
||||
impl<'source> ::tengri::dsl::Namespace<'source, #view> for Box<dyn Render<#output> + 'source> {
|
||||
fn take_from <'state> (
|
||||
state: &'state #view,
|
||||
words: &mut ::tengri::dsl::TokenIter<'source>,
|
||||
impl ::tengri::dsl::Namespace<#view> for Box<dyn Render<#output>> {
|
||||
fn take_from <'source> (
|
||||
state: &#view,
|
||||
words: &mut ::tengri::dsl::TokenIter<'source>
|
||||
) -> Perhaps<Self> {
|
||||
Ok(words.peek().and_then(|::tengri::dsl::Token{ value, .. }|match value {
|
||||
::tengri::dsl::Value::Exp(_, exp) => {
|
||||
todo!("builtin layout ops");
|
||||
//#builtins
|
||||
None
|
||||
},
|
||||
::tengri::dsl::Value::Sym(sym) => match sym {
|
||||
#(#exposed)*
|
||||
Ok(if let Some(::tengri::dsl::Token { value, .. }) = words.peek() {
|
||||
match value {
|
||||
::tengri::dsl::Value::Exp(_, exp) => {
|
||||
//#(#builtins)*
|
||||
None
|
||||
},
|
||||
::tengri::dsl::Value::Sym(sym) => match sym {
|
||||
#(#exposed)*
|
||||
_ => None
|
||||
},
|
||||
_ => None
|
||||
},
|
||||
_ => None
|
||||
}))
|
||||
}
|
||||
} else {
|
||||
None
|
||||
})
|
||||
}
|
||||
}
|
||||
})
|
||||
|
|
@ -95,19 +103,19 @@ impl ToTokens for ViewDef {
|
|||
|
||||
fn builtins () -> [TokenStream2;14] {
|
||||
[
|
||||
quote! { When::<A> },
|
||||
quote! { Either::<A, B> },
|
||||
quote! { Align::<A> },
|
||||
quote! { Bsp::<A, B> },
|
||||
quote! { Fill::<A> },
|
||||
quote! { Fixed::<_, A> },
|
||||
quote! { Min::<_, A> },
|
||||
quote! { Max::<_, A> },
|
||||
quote! { Shrink::<_, A> },
|
||||
quote! { Expand::<_, A> },
|
||||
quote! { Push::<_, A> },
|
||||
quote! { Pull::<_, A> },
|
||||
quote! { Margin::<_, A> },
|
||||
quote! { Padding::<_, A> },
|
||||
quote! { When::<_> },
|
||||
quote! { Either::<_, _> },
|
||||
quote! { Align::<_> },
|
||||
quote! { Bsp::<_, _> },
|
||||
quote! { Fill::<_> },
|
||||
quote! { Fixed::<_, _> },
|
||||
quote! { Min::<_, _> },
|
||||
quote! { Max::<_, _> },
|
||||
quote! { Shrink::<_, _> },
|
||||
quote! { Expand::<_, _> },
|
||||
quote! { Push::<_, _> },
|
||||
quote! { Pull::<_, _> },
|
||||
quote! { Margin::<_, _> },
|
||||
quote! { Padding::<_, _> },
|
||||
]
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue