wip: dsl, output, input, proc, tui: sorting out give and take
Some checks are pending
/ build (push) Waiting to run

This commit is contained in:
🪞👃🪞 2025-05-24 23:57:12 +03:00
parent 5a2177cc77
commit 3e1084555b
10 changed files with 273 additions and 301 deletions

View file

@ -32,26 +32,19 @@ macro_rules! transform_xy {
#[inline] pub const fn y (item: A) -> Self { Self::Y(item) }
#[inline] pub const fn xy (item: A) -> Self { Self::XY(item) }
}
#[cfg(feature = "dsl")]
impl<'n, A: 'n, T: Give<A>> Take<'n, T> for $Enum<A> {
fn take <'source> (state: &T, token: &mut TokenIter<'source>)
-> Perhaps<Self>
{
if let Some(Token { value: Value::Key(k), .. }) = token.peek() {
let mut base = token.clone();
return Ok(Some(match token.next() {
Some(Token{value:Value::Key($x),..}) =>
Self::x(state.give_or_fail(token, ||"x: no content")?),
Some(Token{value:Value::Key($y),..}) =>
Self::y(state.give_or_fail(token, ||"y: no content")?),
Some(Token{value:Value::Key($xy),..}) =>
Self::xy(state.give_or_fail(token, ||"xy: no content")?),
_ => unreachable!()
}))
}
Ok(None)
}
}
#[cfg(feature = "dsl")] take!($Enum<A>, A|state, words|Ok(
if let Some(Token { value: Value::Key(k), .. }) = words.peek() {
let mut base = words.clone();
let content = state.give_or_fail(words, ||format!("{k}: no content"))?;
return Ok(Some(match words.next() {
Some(Token{value: Value::Key($x),..}) => Self::x(content),
Some(Token{value: Value::Key($y),..}) => Self::y(content),
Some(Token{value: Value::Key($xy),..}) => Self::xy(content),
_ => unreachable!()
}))
} else {
None
}));
impl<E: Output, T: Content<E>> Content<E> for $Enum<T> {
fn content (&self) -> impl Render<E> + '_ {
match self {
@ -78,56 +71,45 @@ macro_rules! transform_xy_unit {
#[inline] pub const fn y (y: U, item: A) -> Self { Self::Y(y, item) }
#[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: Give<A> + Give<U>> Take<'n, T> for $Enum<U, A> {
fn take <'source> (
state: &T, token: &mut TokenIter<'source>
) -> Perhaps<Self> {
Ok(if let Some(Token { value: Value::Key($x|$y|$xy), .. }) = token.peek() {
let mut base = token.clone();
Some(match token.next() {
Some(Token { value: Value::Key($x), .. }) => Self::x(
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.give_or_fail(token, ||"y: no unit")?,
state.give_or_fail(token, ||"y: no content")?,
),
Some(Token { value: Value::Key($x), .. }) => Self::xy(
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!(),
})
} else {
None
#[cfg(feature = "dsl")] take!($Enum<U, A>, U, A|state, words|Ok(
if let Some(Token { value: Value::Key($x|$y|$xy), .. }) = words.peek() {
let mut base = words.clone();
Some(match words.next() {
Some(Token { value: Value::Key($x), .. }) => Self::x(
state.give_or_fail(words, ||"x: no unit")?,
state.give_or_fail(words, ||"x: no content")?,
),
Some(Token { value: Value::Key($y), .. }) => Self::y(
state.give_or_fail(words, ||"y: no unit")?,
state.give_or_fail(words, ||"y: no content")?,
),
Some(Token { value: Value::Key($x), .. }) => Self::xy(
state.give_or_fail(words, ||"xy: no unit x")?,
state.give_or_fail(words, ||"xy: no unit y")?,
state.give_or_fail(words, ||"xy: no content")?
),
_ => unreachable!(),
})
}
}
} else {
None
}));
impl<E: Output, T: Content<E>> Content<E> for $Enum<E::Unit, T> {
fn content (&self) -> impl Render<E> + '_ {
Some(match self {
Self::X(_, content) => content,
Self::Y(_, content) => content,
Self::XY(_, _, content) => content,
})
}
fn layout (&$self, $to: E::Area) -> E::Area {
$layout.into()
}
fn content (&self) -> impl Render<E> + '_ {
use $Enum::*;
Some(match self { X(_, c) => c, Y(_, c) => c, XY(_, _, c) => c, })
}
}
impl<U: Copy + Coordinate, T> $Enum<U, T> {
impl<U: Coordinate, T> $Enum<U, T> {
#[inline] pub fn dx (&self) -> U {
match self {
Self::X(x, _) => *x, Self::Y(_, _) => 0.into(), Self::XY(x, _, _) => *x,
}
use $Enum::*;
match self { X(x, _) => *x, Y(_, _) => 0.into(), XY(x, _, _) => *x, }
}
#[inline] pub fn dy (&self) -> U {
match self {
Self::X(_, _) => 0.into(), Self::Y(y, _) => *y, Self::XY(_, y, _) => *y,
}
use $Enum::*;
match self { X(_, _) => 0.into(), Y(y, _) => *y, XY(_, y, _) => *y, }
}
}
}