Compare commits

...

2 commits

Author SHA1 Message Date
cbd28a5934 dsl: auto-impl the obvious one (hopefully)
Some checks are pending
/ build (push) Waiting to run
re foreign trait constraints
2025-05-23 21:52:08 +03:00
ddf0c05d5f dsl: Provide -> Take, Receive -> Give (swap + shorten) 2025-05-23 21:39:29 +03:00
10 changed files with 88 additions and 73 deletions

View file

@ -1,52 +1,64 @@
use crate::*; use crate::*;
pub trait Receive<Type> { // maybe their names should be switched around?
fn receive <'source> (&self, words: &mut TokenIter<'source>) -> Perhaps<Type>;
fn receive_or_fail <'source, E: Into<Box<dyn std::error::Error>>, F: Fn()->E> ( /// [Take]s instances of [Type] given [TokenIter].
pub trait Give<Type> {
/// Implement this to be able to [Give] [Type] from the [TokenIter].
fn give <'source> (&self, words: &mut TokenIter<'source>) -> Perhaps<Type>;
/// Return custom error on [None].
fn give_or_fail <'source, E: Into<Box<dyn std::error::Error>>, F: Fn()->E> (
&self, words: &mut TokenIter<'source>, error: F &self, words: &mut TokenIter<'source>, error: F
) -> Usually<Type> { ) -> Usually<Type> {
if let Some(value) = Receive::<Type>::receive(self, words)? { if let Some(value) = Give::<Type>::give(self, words)? {
Ok(value) Ok(value)
} else { } else {
Result::Err(format!("receive: {}: {:?}", error().into(), words.peek().map(|x|x.value)).into()) Result::Err(format!("give: {}: {:?}", error().into(), words.peek().map(|x|x.value)).into())
} }
} }
} }
pub trait Provide<'n, State>: Sized + 'n { impl<'n, T: Take<'n, U>, U> Give<T> for U {
fn provide <'source> (state: &State, words: &mut TokenIter<'source>) fn give <'source> (&self, words: &mut TokenIter<'source>) -> Perhaps<T> {
-> Perhaps<Self>; T::take(self, words)
fn provide_or_fail <'source, E: Into<Box<dyn std::error::Error>>, F: Fn()->E> ( }
}
/// [Give]s instances of [Self] given [TokenIter].
pub trait Take<'n, State>: Sized + 'n {
fn take <'source> (state: &State, words: &mut TokenIter<'source>) -> Perhaps<Self>;
/// Return custom error on [None].
fn take_or_fail <'source, E: Into<Box<dyn std::error::Error>>, F: Fn()->E> (
state: &State, words: &mut TokenIter<'source>, error: F state: &State, words: &mut TokenIter<'source>, error: F
) -> Usually<Self> { ) -> Usually<Self> {
if let Some(value) = Provide::<State>::provide(state, words)? { if let Some(value) = Take::<State>::take(state, words)? {
Ok(value) Ok(value)
} else { } else {
Result::Err(format!("provide: {}: {:?}", error().into(), words.peek().map(|x|x.value)).into()) Result::Err(format!("take: {}: {:?}", error().into(), words.peek().map(|x|x.value)).into())
} }
} }
} }
/// Implement the [Receive] trait, which boils down to /// Implement the [Give] trait, which boils down to
/// specifying two types and providing an expression. /// specifying two types and providing an expression.
#[macro_export] macro_rules! from_dsl { #[macro_export] macro_rules! from_dsl {
(@a: $T:ty: |$state:ident, $words:ident|$expr:expr) => { (@a: $T:ty: |$state:ident, $words:ident|$expr:expr) => {
impl<'n, State, A: Provide<'n, State>> Provide<'n, State> for $T { impl<'n, State, A: Take<'n, State>> Take<'n, State> for $T {
fn provide <'source> ($state: &State, $words: &mut TokenIter<'source>) -> Perhaps<$T> { fn take <'source> ($state: &State, $words: &mut TokenIter<'source>) -> Perhaps<$T> {
$expr $expr
} }
} }
}; };
(@ab: $T:ty: |$state:ident, $words:ident|$expr:expr) => { (@ab: $T:ty: |$state:ident, $words:ident|$expr:expr) => {
impl<'n, State, A: Provide<'n, State>, B: Provide<'n, State>> Provide<'n, State> for $T { impl<'n, State, A: Take<'n, State>, B: Take<'n, State>> Take<'n, State> for $T {
fn provide <'source> ($state: &State, $words: &mut TokenIter<'source>) -> Perhaps<$T> { fn take <'source> ($state: &State, $words: &mut TokenIter<'source>) -> Perhaps<$T> {
$expr $expr
} }
} }
}; };
($T:ty: |$state:ident:$S:ty, $words:ident|$expr:expr) => { ($T:ty: |$state:ident:$S:ty, $words:ident|$expr:expr) => {
impl<'n> Provide<'n, $S> for $T { impl<'n> Take<'n, $S> for $T {
fn provide <'source> ($state: &$S, $words: &mut TokenIter<'source>) -> Perhaps<$T> { fn take <'source> ($state: &$S, $words: &mut TokenIter<'source>) -> Perhaps<$T> {
$expr $expr
} }
} }
@ -55,16 +67,16 @@ pub trait Provide<'n, State>: Sized + 'n {
// auto impl graveyard: // auto impl graveyard:
//impl<'n, State: Receive<Type>, Type: 'n> Provide<'n, State> for Type { //impl<'n, State: Give<Type>, Type: 'n> Take<'n, State> for Type {
//fn provide <'source> (state: &State, words: &mut TokenIter<'source>) //fn take <'source> (state: &State, words: &mut TokenIter<'source>)
//-> Perhaps<Self> //-> Perhaps<Self>
//{ //{
//state.take(words) //state.take(words)
//} //}
//} //}
//impl<'n, Type: Provide<'n, State>, State> Receive<Type> for State { //impl<'n, Type: Take<'n, State>, State> Give<Type> for State {
//fn take <'source> (&self, words: &mut TokenIter<'source>) -> Perhaps<Type> { //fn take <'source> (&self, words: &mut TokenIter<'source>) -> Perhaps<Type> {
//Type::provide(self, words) //Type::take(self, words)
//} //}
//} //}

View file

@ -5,13 +5,13 @@ use std::marker::PhantomData;
pub trait DslInput: Input { fn matches_dsl (&self, token: &str) -> bool; } pub trait DslInput: Input { fn matches_dsl (&self, token: &str) -> bool; }
/// A pre-configured mapping of input events to commands. /// A pre-configured mapping of input events to commands.
pub trait KeyMap<'k, S, C: Provide<'k, S> + Command<S>, I: DslInput> { pub trait KeyMap<'k, S, C: Take<'k, S> + Command<S>, I: DslInput> {
/// Try to find a command that matches the current input event. /// Try to find a command that matches the current input event.
fn keybind_resolve (&self, state: &S, input: &I) -> Perhaps<C>; fn keybind_resolve (&self, state: &S, input: &I) -> Perhaps<C>;
} }
/// A [SourceIter] can be a [KeyMap]. /// A [SourceIter] can be a [KeyMap].
impl<'k, S, C: Provide<'k, S> + Command<S>, I: DslInput> KeyMap<'k, S, C, I> for SourceIter<'k> { impl<'k, S, C: Take<'k, S> + Command<S>, I: DslInput> KeyMap<'k, S, C, I> for SourceIter<'k> {
fn keybind_resolve (&self, state: &S, input: &I) -> Perhaps<C> { fn keybind_resolve (&self, state: &S, input: &I) -> Perhaps<C> {
let mut iter = self.clone(); let mut iter = self.clone();
while let Some((token, rest)) = iter.next() { while let Some((token, rest)) = iter.next() {
@ -22,7 +22,7 @@ impl<'k, S, C: Provide<'k, S> + Command<S>, I: DslInput> KeyMap<'k, S, C, I> for
match exp_iter.next() { match exp_iter.next() {
Some(Token { value: Value::Sym(binding), .. }) => { Some(Token { value: Value::Sym(binding), .. }) => {
if input.matches_dsl(binding) { if input.matches_dsl(binding) {
if let Some(command) = Provide::provide(state, &mut exp_iter)? { if let Some(command) = Take::take(state, &mut exp_iter)? {
return Ok(Some(command)) return Ok(Some(command))
} }
} }
@ -38,7 +38,7 @@ impl<'k, S, C: Provide<'k, S> + Command<S>, I: DslInput> KeyMap<'k, S, C, I> for
} }
/// A [TokenIter] can be a [KeyMap]. /// A [TokenIter] can be a [KeyMap].
impl<'k, S, C: Provide<'k, S> + Command<S>, I: DslInput> KeyMap<'k, S, C, I> for TokenIter<'k> { impl<'k, S, C: Take<'k, S> + Command<S>, I: DslInput> KeyMap<'k, S, C, I> for TokenIter<'k> {
fn keybind_resolve (&self, state: &S, input: &I) -> Perhaps<C> { fn keybind_resolve (&self, state: &S, input: &I) -> Perhaps<C> {
let mut iter = self.clone(); let mut iter = self.clone();
while let Some(next) = iter.next() { while let Some(next) = iter.next() {
@ -48,7 +48,7 @@ impl<'k, S, C: Provide<'k, S> + Command<S>, I: DslInput> KeyMap<'k, S, C, I> for
match e.next() { match e.next() {
Some(Token { value: Value::Sym(binding), .. }) => { Some(Token { value: Value::Sym(binding), .. }) => {
if input.matches_dsl(binding) { if input.matches_dsl(binding) {
if let Some(command) = Provide::provide(state, &mut e)? { if let Some(command) = Take::take(state, &mut e)? {
return Ok(Some(command)) return Ok(Some(command))
} }
} }
@ -69,7 +69,7 @@ pub type InputCondition<'k, S> = Box<dyn Fn(&S)->Usually<bool> + Send + Sync + '
/// which may be made available subject to given conditions. /// which may be made available subject to given conditions.
pub struct InputMap<'k, pub struct InputMap<'k,
S, S,
C: Command<S> + Provide<'k, S>, C: Command<S> + Take<'k, S>,
I: DslInput, I: DslInput,
M: KeyMap<'k, S, C, I> M: KeyMap<'k, S, C, I>
> { > {
@ -79,7 +79,7 @@ pub struct InputMap<'k,
impl<'k, impl<'k,
S, S,
C: Command<S> + Provide<'k, S>, C: Command<S> + Take<'k, S>,
I: DslInput, I: DslInput,
M: KeyMap<'k, S, C, I> M: KeyMap<'k, S, C, I>
> Default for InputMap<'k, S, C, I, M>{ > Default for InputMap<'k, S, C, I, M>{
@ -88,7 +88,7 @@ impl<'k,
} }
} }
impl<'k, S, C: Command<S> + Provide<'k, S>, I: DslInput, M: KeyMap<'k, S, C, I>> impl<'k, S, C: Command<S> + Take<'k, S>, I: DslInput, M: KeyMap<'k, S, C, I>>
InputMap<'k, S, C, I, M> { InputMap<'k, S, C, I, M> {
pub fn new (keymap: M) -> Self { pub fn new (keymap: M) -> Self {
Self::default().layer(keymap) Self::default().layer(keymap)
@ -111,7 +111,7 @@ InputMap<'k, S, C, I, M> {
} }
} }
impl<'k, S, C: Command<S> + Provide<'k, S>, I: DslInput, M: KeyMap<'k, S, C, I>> impl<'k, S, C: Command<S> + Take<'k, S>, I: DslInput, M: KeyMap<'k, S, C, I>>
std::fmt::Debug for InputMap<'k, S, C, I, M> { std::fmt::Debug for InputMap<'k, S, C, I, M> {
fn fmt (&self, f: &mut std::fmt::Formatter) -> Result<(), std::fmt::Error> { fn fmt (&self, f: &mut std::fmt::Formatter) -> Result<(), std::fmt::Error> {
write!(f, "[InputMap: {} layer(s)]", self.layers.len()) write!(f, "[InputMap: {} layer(s)]", self.layers.len())
@ -121,7 +121,7 @@ std::fmt::Debug for InputMap<'k, S, C, I, M> {
/// An [InputMap] can be a [KeyMap]. /// An [InputMap] can be a [KeyMap].
impl<'k, impl<'k,
S, S,
C: Command<S> + Provide<'k, S>, C: Command<S> + Take<'k, S>,
I: DslInput, I: DslInput,
M: KeyMap<'k, S, C, I> M: KeyMap<'k, S, C, I>
> KeyMap<'k, S, C, I> for InputMap<'k, S, C, I, M> { > KeyMap<'k, S, C, I> for InputMap<'k, S, C, I, M> {

View file

@ -36,15 +36,15 @@ pub enum Alignment { #[default] Center, X, Y, NW, N, NE, E, SE, S, SW, W }
pub struct Align<A>(Alignment, A); pub struct Align<A>(Alignment, A);
#[cfg(feature = "dsl")] #[cfg(feature = "dsl")]
impl<'n, State: Receive<A>, A: 'n> Provide<'n, State> for Align<A> { impl<'n, State: Give<A>, A: 'n> Take<'n, State> for Align<A> {
fn provide <'source> (state: &State, words: &mut TokenIter<'source>) -> Perhaps<Self> { fn take <'source> (state: &State, words: &mut TokenIter<'source>) -> Perhaps<Self> {
if let Some(Token { value: Value::Key(key), .. }) = words.peek() { if let Some(Token { value: Value::Key(key), .. }) = words.peek() {
match key { match key {
"align/c"|"align/x"|"align/y"| "align/c"|"align/x"|"align/y"|
"align/n"|"align/s"|"align/e"|"align/w"| "align/n"|"align/s"|"align/e"|"align/w"|
"align/nw"|"align/sw"|"align/ne"|"align/se" => { "align/nw"|"align/sw"|"align/ne"|"align/se" => {
let _ = words.next().unwrap(); let _ = words.next().unwrap();
let content = state.receive_or_fail(&mut words.clone(), ||"expected content")?; let content = state.give_or_fail(&mut words.clone(), ||"expected content")?;
return Ok(Some(match key { return Ok(Some(match key {
"align/c" => Self::c(content), "align/c" => Self::c(content),
"align/x" => Self::x(content), "align/x" => Self::x(content),

View file

@ -21,16 +21,16 @@ impl<E: Output, A: Content<E>, B: Content<E>> Content<E> for Bsp<A, B> {
} }
} }
#[cfg(feature = "dsl")] #[cfg(feature = "dsl")]
impl<'n, State: Receive<A> + Receive<B>, A: 'n, B: 'n> Provide<'n, State> for Bsp<A, B> { impl<'n, State: Give<A> + Give<B>, A: 'n, B: 'n> Take<'n, State> for Bsp<A, B> {
fn provide <'source> (state: &State, words: &mut TokenIter<'source>) -> Perhaps<Self> { fn take <'source> (state: &State, words: &mut TokenIter<'source>) -> Perhaps<Self> {
Ok(if let Some(Token { Ok(if let Some(Token {
value: Value::Key("bsp/n"|"bsp/s"|"bsp/e"|"bsp/w"|"bsp/a"|"bsp/b"), value: Value::Key("bsp/n"|"bsp/s"|"bsp/e"|"bsp/w"|"bsp/a"|"bsp/b"),
.. ..
}) = words.peek() { }) = words.peek() {
if let Value::Key(key) = words.next().unwrap().value() { if let Value::Key(key) = words.next().unwrap().value() {
let base = words.clone(); let base = words.clone();
let a: A = state.receive_or_fail(words, ||"bsp: expected content 1")?; let a: A = state.give_or_fail(words, ||"bsp: expected content 1")?;
let b: B = state.receive_or_fail(words, ||"bsp: expected content 2")?; let b: B = state.give_or_fail(words, ||"bsp: expected content 2")?;
return Ok(Some(match key { return Ok(Some(match key {
"bsp/n" => Self::n(a, b), "bsp/n" => Self::n(a, b),
"bsp/s" => Self::s(a, b), "bsp/s" => Self::s(a, b),

View file

@ -9,15 +9,15 @@ impl<A, B> Either<A, B> {
} }
} }
#[cfg(feature = "dsl")] #[cfg(feature = "dsl")]
impl<'n, State: Receive<bool> + Receive<A> + Receive<B>, A: 'n, B: 'n> Provide<'n, State> for Either<A, B> { impl<'n, State: Give<bool> + Give<A> + Give<B>, A: 'n, B: 'n> Take<'n, State> for Either<A, B> {
fn provide <'source> (state: &State, token: &mut TokenIter<'source>) -> Perhaps<Self> { fn take <'source> (state: &State, token: &mut TokenIter<'source>) -> Perhaps<Self> {
if let Some(Token { value: Value::Key("either"), .. }) = token.peek() { if let Some(Token { value: Value::Key("either"), .. }) = token.peek() {
let base = token.clone(); let base = token.clone();
let _ = token.next().unwrap(); let _ = token.next().unwrap();
return Ok(Some(Self( return Ok(Some(Self(
state.receive_or_fail(token, ||"either: no condition")?, state.give_or_fail(token, ||"either: no condition")?,
state.receive_or_fail(token, ||"either: no content 1")?, state.give_or_fail(token, ||"either: no content 1")?,
state.receive_or_fail(token, ||"either: no content 2")?, state.give_or_fail(token, ||"either: no content 2")?,
))) )))
} }
Ok(None) Ok(None)

View file

@ -1,7 +1,7 @@
//! [Content] items that modify the inherent //! [Content] items that modify the inherent
//! dimensions of their inner [Render]ables. //! dimensions of their inner [Render]ables.
//! //!
//! Transform may also react to the [Area] provided. //! Transform may also react to the [Area] taked.
//! ``` //! ```
//! use ::tengri::{output::*, tui::*}; //! use ::tengri::{output::*, tui::*};
//! let area: [u16;4] = [10, 10, 20, 20]; //! let area: [u16;4] = [10, 10, 20, 20];
@ -33,19 +33,19 @@ macro_rules! transform_xy {
#[inline] pub const fn xy (item: A) -> Self { Self::XY(item) } #[inline] pub const fn xy (item: A) -> Self { Self::XY(item) }
} }
#[cfg(feature = "dsl")] #[cfg(feature = "dsl")]
impl<'n, A: 'n, T: Receive<A>> Provide<'n, T> for $Enum<A> { impl<'n, A: 'n, T: Give<A>> Take<'n, T> for $Enum<A> {
fn provide <'source> (state: &T, token: &mut TokenIter<'source>) fn take <'source> (state: &T, token: &mut TokenIter<'source>)
-> Perhaps<Self> -> Perhaps<Self>
{ {
if let Some(Token { value: Value::Key(k), .. }) = token.peek() { if let Some(Token { value: Value::Key(k), .. }) = token.peek() {
let mut base = token.clone(); let mut base = token.clone();
return Ok(Some(match token.next() { return Ok(Some(match token.next() {
Some(Token{value:Value::Key($x),..}) => Some(Token{value:Value::Key($x),..}) =>
Self::x(state.receive_or_fail(token, ||"x: no content")?), Self::x(state.give_or_fail(token, ||"x: no content")?),
Some(Token{value:Value::Key($y),..}) => Some(Token{value:Value::Key($y),..}) =>
Self::y(state.receive_or_fail(token, ||"y: no content")?), Self::y(state.give_or_fail(token, ||"y: no content")?),
Some(Token{value:Value::Key($xy),..}) => Some(Token{value:Value::Key($xy),..}) =>
Self::xy(state.receive_or_fail(token, ||"xy: no content")?), Self::xy(state.give_or_fail(token, ||"xy: no content")?),
_ => unreachable!() _ => unreachable!()
})) }))
} }
@ -79,25 +79,25 @@ macro_rules! transform_xy_unit {
#[inline] pub const fn xy (x: U, y: U, item: A) -> Self { Self::XY(x, y, item) } #[inline] pub const fn xy (x: U, y: U, item: A) -> Self { Self::XY(x, y, item) }
} }
#[cfg(feature = "dsl")] #[cfg(feature = "dsl")]
impl<'n, A: 'n, U: Coordinate + 'n, T: Receive<A> + Receive<U>> Provide<'n, T> for $Enum<U, A> { impl<'n, A: 'n, U: Coordinate + 'n, T: Give<A> + Give<U>> Take<'n, T> for $Enum<U, A> {
fn provide <'source> ( fn take <'source> (
state: &T, token: &mut TokenIter<'source> state: &T, token: &mut TokenIter<'source>
) -> Perhaps<Self> { ) -> Perhaps<Self> {
Ok(if let Some(Token { value: Value::Key($x|$y|$xy), .. }) = token.peek() { Ok(if let Some(Token { value: Value::Key($x|$y|$xy), .. }) = token.peek() {
let mut base = token.clone(); let mut base = token.clone();
Some(match token.next() { Some(match token.next() {
Some(Token { value: Value::Key($x), .. }) => Self::x( Some(Token { value: Value::Key($x), .. }) => Self::x(
state.receive_or_fail(token, ||"x: no unit")?, state.give_or_fail(token, ||"x: no unit")?,
state.receive_or_fail(token, ||"x: no content")?, state.give_or_fail(token, ||"x: no content")?,
), ),
Some(Token { value: Value::Key($y), .. }) => Self::y( Some(Token { value: Value::Key($y), .. }) => Self::y(
state.receive_or_fail(token, ||"y: no unit")?, state.give_or_fail(token, ||"y: no unit")?,
state.receive_or_fail(token, ||"y: no content")?, state.give_or_fail(token, ||"y: no content")?,
), ),
Some(Token { value: Value::Key($x), .. }) => Self::xy( Some(Token { value: Value::Key($x), .. }) => Self::xy(
state.receive_or_fail(token, ||"xy: no unit x")?, state.give_or_fail(token, ||"xy: no unit x")?,
state.receive_or_fail(token, ||"xy: no unit y")?, state.give_or_fail(token, ||"xy: no unit y")?,
state.receive_or_fail(token, ||"xy: no content")? state.give_or_fail(token, ||"xy: no content")?
), ),
_ => unreachable!(), _ => unreachable!(),
}) })

View file

@ -2,15 +2,17 @@ use crate::*;
/// Show an item only when a condition is true. /// Show an item only when a condition is true.
pub struct When<A>(pub bool, pub A); pub struct When<A>(pub bool, pub A);
impl<A> When<A> { impl<A> When<A> {
/// Create a binary condition. /// Create a binary condition.
pub const fn new (c: bool, a: A) -> Self { pub const fn new (c: bool, a: A) -> Self {
Self(c, a) Self(c, a)
} }
} }
#[cfg(feature = "dsl")] #[cfg(feature = "dsl")]
impl<'n, State: Receive<bool> + Receive<A>, A: 'n> Provide<'n, State> for When<A> { impl<'n, State: Give<bool>, A: Take<'n, State>> Take<'n, State> for When<A> {
fn provide <'source> (state: &State, words: &mut TokenIter<'source>) -> Perhaps<Self> { fn take <'source> (state: &State, words: &mut TokenIter<'source>) -> Perhaps<Self> {
Ok(if let Some(Token { Ok(if let Some(Token {
value: Value::Key("when"), value: Value::Key("when"),
.. ..
@ -18,14 +20,15 @@ impl<'n, State: Receive<bool> + Receive<A>, A: 'n> Provide<'n, State> for When<A
let _ = words.next(); let _ = words.next();
let base = words.clone(); let base = words.clone();
return Ok(Some(Self( return Ok(Some(Self(
state.receive_or_fail(words, ||"cond: no condition")?, state.give_or_fail(words, ||"cond: no condition")?,
state.receive_or_fail(words, ||"cond: no content")?, A::take_or_fail(state, words, ||"cond: no content")?,
))) )))
} else { } else {
None None
}) })
} }
} }
impl<E: Output, A: Render<E>> Content<E> for When<A> { impl<E: Output, A: Render<E>> Content<E> for When<A> {
fn layout (&self, to: E::Area) -> E::Area { fn layout (&self, to: E::Area) -> E::Area {
let Self(cond, item) = self; let Self(cond, item) = self;

View file

@ -84,7 +84,7 @@ impl ToTokens for CommandDef {
let mut out = TokenStream2::new(); let mut out = TokenStream2::new();
for (arg, ty) in arm.args() { for (arg, ty) in arm.args() {
write_quote_to(&mut out, quote! { write_quote_to(&mut out, quote! {
#arg: Provide::provide_or_fail(self, words)?, #arg: Take::take_or_fail(self, words)?,
}); });
} }
out out
@ -149,8 +149,8 @@ impl ToTokens for CommandDef {
} }
} }
/// Generated by [tengri_proc::command]. /// Generated by [tengri_proc::command].
impl<'n> ::tengri::dsl::Provide<'n, #state> for #command_enum { impl<'n> ::tengri::dsl::Take<'n, #state> for #command_enum {
fn provide <'source> ( fn take <'source> (
state: &#state, state: &#state,
words: &mut ::tengri::dsl::TokenIter<'source> words: &mut ::tengri::dsl::TokenIter<'source>
) -> Perhaps<Self> { ) -> Perhaps<Self> {

View file

@ -85,8 +85,8 @@ impl ToTokens for ExposeImpl {
let values = variants.iter().map(ExposeArm::from); let values = variants.iter().map(ExposeArm::from);
write_quote_to(out, quote! { write_quote_to(out, quote! {
/// Generated by [tengri_proc::expose]. /// Generated by [tengri_proc::expose].
impl<'n> ::tengri::dsl::Provide<'n, #state> for #t { impl<'n> ::tengri::dsl::Take<'n, #state> for #t {
fn provide <'source> ( fn take <'source> (
state: &#state, state: &#state,
words: &mut ::tengri::dsl::TokenIter<'source> words: &mut ::tengri::dsl::TokenIter<'source>
) -> Perhaps<Self> { ) -> Perhaps<Self> {

View file

@ -46,7 +46,7 @@ impl ToTokens for ViewDef {
let builtins: Vec<_> = builtins_with_types() let builtins: Vec<_> = builtins_with_types()
.iter() .iter()
.map(|ty|write_quote(quote! { .map(|ty|write_quote(quote! {
let value: Option<#ty> = Receive::<#ty>::receive(self, &mut exp.clone())?; let value: Option<#ty> = Give::<#ty>::give(self, &mut exp.clone())?;
if let Some(value) = value { if let Some(value) = value {
return Ok(Some(value.boxed())) return Ok(Some(value.boxed()))
} }
@ -65,8 +65,8 @@ impl ToTokens for ViewDef {
/// Gives [#self_ty] the ability to construct the [Render]able /// Gives [#self_ty] the ability to construct the [Render]able
/// which might corresponds to a given [TokenStream], /// which might corresponds to a given [TokenStream],
/// while taking [#self_ty]'s state into consideration. /// while taking [#self_ty]'s state into consideration.
impl ::tengri::dsl::Receive<Box<dyn Render<#output>>> for #self_ty { impl ::tengri::dsl::Give<Box<dyn Render<#output>>> for #self_ty {
fn receive <'source> (&self, words: &mut ::tengri::dsl::TokenIter<'source>) fn give <'source> (&self, words: &mut ::tengri::dsl::TokenIter<'source>)
-> Perhaps<Box<dyn Render<#output>>> -> Perhaps<Box<dyn Render<#output>>>
{ {
Ok(if let Some(::tengri::dsl::Token { value, .. }) = words.peek() { Ok(if let Some(::tengri::dsl::Token { value, .. }) = words.peek() {
@ -77,7 +77,7 @@ impl ToTokens for ViewDef {
#(#builtins)* #(#builtins)*
None None
}, },
// Symbols are handled by user-provided functions // Symbols are handled by user-taked functions
// that take no parameters but `&self`. // that take no parameters but `&self`.
::tengri::dsl::Value::Sym(sym) => match sym { ::tengri::dsl::Value::Sym(sym) => match sym {
#(#exposed)* #(#exposed)*
@ -100,7 +100,7 @@ impl ToTokens for ViewDef {
#self_ty::view(self) #self_ty::view(self)
} }
} }
// Original user-provided implementation: // Original user-taked implementation:
#block #block
}) })
} }