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

@ -33,7 +33,7 @@ macro_rules! transform_xy {
#[inline] pub const fn xy (item: A) -> Self { Self::XY(item) }
}
#[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>)
-> Perhaps<Self>
{
@ -41,11 +41,11 @@ macro_rules! transform_xy {
let mut base = token.clone();
return Ok(Some(match token.next() {
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),..}) =>
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),..}) =>
Self::xy(state.receive_or_fail(token, ||"xy: no content")?),
Self::xy(state.give_or_fail(token, ||"xy: no content")?),
_ => unreachable!()
}))
}
@ -79,7 +79,7 @@ macro_rules! transform_xy_unit {
#[inline] pub const fn xy (x: U, y: U, item: A) -> Self { Self::XY(x, y, item) }
}
#[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> (
state: &T, token: &mut TokenIter<'source>
) -> Perhaps<Self> {
@ -87,17 +87,17 @@ macro_rules! transform_xy_unit {
let mut base = token.clone();
Some(match token.next() {
Some(Token { value: Value::Key($x), .. }) => Self::x(
state.receive_or_fail(token, ||"x: no unit")?,
state.receive_or_fail(token, ||"x: no content")?,
state.give_or_fail(token, ||"x: no unit")?,
state.give_or_fail(token, ||"x: no content")?,
),
Some(Token { value: Value::Key($y), .. }) => Self::y(
state.receive_or_fail(token, ||"y: no unit")?,
state.receive_or_fail(token, ||"y: no content")?,
state.give_or_fail(token, ||"y: no unit")?,
state.give_or_fail(token, ||"y: no content")?,
),
Some(Token { value: Value::Key($x), .. }) => Self::xy(
state.receive_or_fail(token, ||"xy: no unit x")?,
state.receive_or_fail(token, ||"xy: no unit y")?,
state.receive_or_fail(token, ||"xy: no content")?
state.give_or_fail(token, ||"xy: no unit x")?,
state.give_or_fail(token, ||"xy: no unit y")?,
state.give_or_fail(token, ||"xy: no content")?
),
_ => unreachable!(),
})