diff --git a/dsl/src/dsl_provide.rs b/dsl/src/dsl_provide.rs index bda4381..a0130f7 100644 --- a/dsl/src/dsl_provide.rs +++ b/dsl/src/dsl_provide.rs @@ -18,17 +18,23 @@ pub trait Give { } } +impl<'n, T: Take<'n, U>, U> Give for U { + fn give <'source> (&self, words: &mut TokenIter<'source>) -> Perhaps { + T::take(self, words) + } +} + /// [Give]s instances of [Self] given [TokenIter]. pub trait Take<'n, State>: Sized + 'n { - fn provide <'source> (state: &State, words: &mut TokenIter<'source>) -> Perhaps; + fn take <'source> (state: &State, words: &mut TokenIter<'source>) -> Perhaps; /// Return custom error on [None]. - fn provide_or_fail <'source, E: Into>, F: Fn()->E> ( + fn take_or_fail <'source, E: Into>, F: Fn()->E> ( state: &State, words: &mut TokenIter<'source>, error: F ) -> Usually { - if let Some(value) = Take::::provide(state, words)? { + if let Some(value) = Take::::take(state, words)? { Ok(value) } 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()) } } } @@ -38,21 +44,21 @@ pub trait Take<'n, State>: Sized + 'n { #[macro_export] macro_rules! from_dsl { (@a: $T:ty: |$state:ident, $words:ident|$expr:expr) => { 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 } } }; (@ab: $T:ty: |$state:ident, $words:ident|$expr:expr) => { 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 } } }; ($T:ty: |$state:ident:$S:ty, $words:ident|$expr:expr) => { 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 } } @@ -62,7 +68,7 @@ pub trait Take<'n, State>: Sized + 'n { // auto impl graveyard: //impl<'n, State: Give, 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 //{ //state.take(words) @@ -71,6 +77,6 @@ pub trait Take<'n, State>: Sized + 'n { //impl<'n, Type: Take<'n, State>, State> Give for State { //fn take <'source> (&self, words: &mut TokenIter<'source>) -> Perhaps { - //Type::provide(self, words) + //Type::take(self, words) //} //} diff --git a/input/src/input_dsl.rs b/input/src/input_dsl.rs index a01e6d6..79334f4 100644 --- a/input/src/input_dsl.rs +++ b/input/src/input_dsl.rs @@ -22,7 +22,7 @@ impl<'k, S, C: Take<'k, S> + Command, I: DslInput> KeyMap<'k, S, C, I> for So match exp_iter.next() { Some(Token { value: Value::Sym(binding), .. }) => { if input.matches_dsl(binding) { - if let Some(command) = Take::provide(state, &mut exp_iter)? { + if let Some(command) = Take::take(state, &mut exp_iter)? { return Ok(Some(command)) } } @@ -48,7 +48,7 @@ impl<'k, S, C: Take<'k, S> + Command, I: DslInput> KeyMap<'k, S, C, I> for To match e.next() { Some(Token { value: Value::Sym(binding), .. }) => { if input.matches_dsl(binding) { - if let Some(command) = Take::provide(state, &mut e)? { + if let Some(command) = Take::take(state, &mut e)? { return Ok(Some(command)) } } diff --git a/output/src/ops/align.rs b/output/src/ops/align.rs index 4c81616..8031e0e 100644 --- a/output/src/ops/align.rs +++ b/output/src/ops/align.rs @@ -37,7 +37,7 @@ pub struct Align(Alignment, A); #[cfg(feature = "dsl")] impl<'n, State: Give, A: 'n> Take<'n, State> for Align { - fn provide <'source> (state: &State, words: &mut TokenIter<'source>) -> Perhaps { + fn take <'source> (state: &State, words: &mut TokenIter<'source>) -> Perhaps { if let Some(Token { value: Value::Key(key), .. }) = words.peek() { match key { "align/c"|"align/x"|"align/y"| diff --git a/output/src/ops/bsp.rs b/output/src/ops/bsp.rs index d423176..9ecd6d7 100644 --- a/output/src/ops/bsp.rs +++ b/output/src/ops/bsp.rs @@ -22,7 +22,7 @@ impl, B: Content> Content for Bsp { } #[cfg(feature = "dsl")] impl<'n, State: Give + Give, A: 'n, B: 'n> Take<'n, State> for Bsp { - fn provide <'source> (state: &State, words: &mut TokenIter<'source>) -> Perhaps { + fn take <'source> (state: &State, words: &mut TokenIter<'source>) -> Perhaps { Ok(if let Some(Token { value: Value::Key("bsp/n"|"bsp/s"|"bsp/e"|"bsp/w"|"bsp/a"|"bsp/b"), .. diff --git a/output/src/ops/either.rs b/output/src/ops/either.rs index e234d99..a35d555 100644 --- a/output/src/ops/either.rs +++ b/output/src/ops/either.rs @@ -10,7 +10,7 @@ impl Either { } #[cfg(feature = "dsl")] impl<'n, State: Give + Give + Give, A: 'n, B: 'n> Take<'n, State> for Either { - fn provide <'source> (state: &State, token: &mut TokenIter<'source>) -> Perhaps { + fn take <'source> (state: &State, token: &mut TokenIter<'source>) -> Perhaps { if let Some(Token { value: Value::Key("either"), .. }) = token.peek() { let base = token.clone(); let _ = token.next().unwrap(); diff --git a/output/src/ops/transform.rs b/output/src/ops/transform.rs index 71b0f0a..5e0ec04 100644 --- a/output/src/ops/transform.rs +++ b/output/src/ops/transform.rs @@ -1,7 +1,7 @@ //! [Content] items that modify the inherent //! 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::*}; //! let area: [u16;4] = [10, 10, 20, 20]; @@ -34,7 +34,7 @@ macro_rules! transform_xy { } #[cfg(feature = "dsl")] impl<'n, A: 'n, T: Give> Take<'n, T> for $Enum { - fn provide <'source> (state: &T, token: &mut TokenIter<'source>) + fn take <'source> (state: &T, token: &mut TokenIter<'source>) -> Perhaps { if let Some(Token { value: Value::Key(k), .. }) = token.peek() { @@ -80,7 +80,7 @@ macro_rules! transform_xy_unit { } #[cfg(feature = "dsl")] impl<'n, A: 'n, U: Coordinate + 'n, T: Give + Give> Take<'n, T> for $Enum { - fn provide <'source> ( + fn take <'source> ( state: &T, token: &mut TokenIter<'source> ) -> Perhaps { Ok(if let Some(Token { value: Value::Key($x|$y|$xy), .. }) = token.peek() { diff --git a/output/src/ops/when.rs b/output/src/ops/when.rs index 2ffde7b..db295ab 100644 --- a/output/src/ops/when.rs +++ b/output/src/ops/when.rs @@ -12,7 +12,7 @@ impl When { #[cfg(feature = "dsl")] impl<'n, State: Give, A: Take<'n, State>> Take<'n, State> for When { - fn provide <'source> (state: &State, words: &mut TokenIter<'source>) -> Perhaps { + fn take <'source> (state: &State, words: &mut TokenIter<'source>) -> Perhaps { Ok(if let Some(Token { value: Value::Key("when"), .. @@ -21,7 +21,7 @@ impl<'n, State: Give, A: Take<'n, State>> Take<'n, State> for When { let base = words.clone(); return Ok(Some(Self( state.give_or_fail(words, ||"cond: no condition")?, - A::provide_or_fail(state, words, ||"cond: no content")?, + A::take_or_fail(state, words, ||"cond: no content")?, ))) } else { None diff --git a/proc/src/proc_command.rs b/proc/src/proc_command.rs index 5b8b597..b8cf812 100644 --- a/proc/src/proc_command.rs +++ b/proc/src/proc_command.rs @@ -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: Take::provide_or_fail(self, words)?, + #arg: Take::take_or_fail(self, words)?, }); } out @@ -150,7 +150,7 @@ impl ToTokens for CommandDef { } /// Generated by [tengri_proc::command]. impl<'n> ::tengri::dsl::Take<'n, #state> for #command_enum { - fn provide <'source> ( + fn take <'source> ( state: &#state, words: &mut ::tengri::dsl::TokenIter<'source> ) -> Perhaps { diff --git a/proc/src/proc_expose.rs b/proc/src/proc_expose.rs index 1aff847..b0fae39 100644 --- a/proc/src/proc_expose.rs +++ b/proc/src/proc_expose.rs @@ -86,7 +86,7 @@ impl ToTokens for ExposeImpl { write_quote_to(out, quote! { /// Generated by [tengri_proc::expose]. impl<'n> ::tengri::dsl::Take<'n, #state> for #t { - fn provide <'source> ( + fn take <'source> ( state: &#state, words: &mut ::tengri::dsl::TokenIter<'source> ) -> Perhaps { diff --git a/proc/src/proc_view.rs b/proc/src/proc_view.rs index 39702fe..f68adc0 100644 --- a/proc/src/proc_view.rs +++ b/proc/src/proc_view.rs @@ -77,7 +77,7 @@ impl ToTokens for ViewDef { #(#builtins)* None }, - // Symbols are handled by user-provided functions + // Symbols are handled by user-taked functions // that take no parameters but `&self`. ::tengri::dsl::Value::Sym(sym) => match sym { #(#exposed)* @@ -100,7 +100,7 @@ impl ToTokens for ViewDef { #self_ty::view(self) } } - // Original user-provided implementation: + // Original user-taked implementation: #block }) }