dsl: Provide -> Take, Receive -> Give (swap + shorten)

This commit is contained in:
🪞👃🪞 2025-05-23 21:39:29 +03:00
parent 583660c330
commit ddf0c05d5f
10 changed files with 64 additions and 55 deletions

View file

@ -9,15 +9,15 @@ impl<A, B> Either<A, B> {
}
}
#[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> {
if let Some(Token { value: Value::Key("either"), .. }) = token.peek() {
let base = token.clone();
let _ = token.next().unwrap();
return Ok(Some(Self(
state.receive_or_fail(token, ||"either: no condition")?,
state.receive_or_fail(token, ||"either: no content 1")?,
state.receive_or_fail(token, ||"either: no content 2")?,
state.give_or_fail(token, ||"either: no condition")?,
state.give_or_fail(token, ||"either: no content 1")?,
state.give_or_fail(token, ||"either: no content 2")?,
)))
}
Ok(None)