remove Atom. almost there

This commit is contained in:
🪞👃🪞 2025-01-18 15:37:53 +01:00
parent dc7b713108
commit cf1fd5b45a
20 changed files with 539 additions and 739 deletions

View file

@ -1,5 +1,4 @@
use crate::*;
use RefAtom::*;
/// Defines an enum that transforms its content
/// along either the X axis, the Y axis, or both.
///
@ -13,21 +12,17 @@ macro_rules! transform_xy {
pub fn y (item: T) -> Self { Self::Y(item) }
pub fn xy (item: T) -> Self { Self::XY(item) }
}
impl<'a, E: Output + 'a, T: ViewContext<'a, E>> TryFromAtom<'a, T> for $Enum<RenderBox<'a, E>> {
fn try_from_atoms (state: &'a T, mut atoms: impl Iterator<Item = RefAtom<'a>> + 'a) -> Option<Self> {
let head = atoms.next()?;
if head.kind() != TokenKind::Key { return None }
Some(match head.text() {
$x => Self::x(
state.get_content(&atoms.next().expect("no content")).expect("no content")
),
$y => Self::y(
state.get_content(&atoms.next().expect("no content")).expect("no content")
),
$xy => Self::xy(
state.get_content(&atoms.next().expect("no content")).expect("no content")
),
_ => return None
impl<'a, E: Output + 'a, T: ViewContext<'a, E>> TryFromAtom<T>
for $Enum<RenderBox<'a, E>> {
fn try_from_expr (state: &T, iter: TokenIter) -> Option<Self> {
Some(if let Some((Token { value: Value::Key($x), .. }, _)) = iter.next() {
Self::x(state.get_content(&iter.next().expect("no content").0.value).expect("no content"))
} else if let Some((Token { value: Value::Key($y), .. }, _)) = iter.next() {
Self::y(state.get_content(&iter.next().expect("no content").0.value).expect("no content"))
} else if let Some((Token { value: Value::Key($xy), .. }, _)) = iter.next() {
Self::xy(state.get_content(&iter.next().expect("no content").0.value).expect("no content"))
} else {
return None
})
}
}
@ -56,25 +51,24 @@ macro_rules! transform_xy_unit {
pub fn y (y: U, item: T) -> Self { Self::Y(y, item) }
pub fn xy (x: U, y: U, item: T) -> Self { Self::XY(x, y, item) }
}
impl<'a, E: Output + 'a, T: ViewContext<'a, E>> TryFromAtom<'a, T> for $Enum<E::Unit, RenderBox<'a, E>> {
fn try_from_atoms (state: &'a T, mut atoms: impl Iterator<Item = RefAtom<'a>> + 'a) -> Option<Self> {
let head = atoms.next()?;
if head.kind() != TokenKind::Key { return None }
Some(match head.text() {
$x => Self::x(
state.get_unit(&atoms.next().expect("no x")).expect("no x"),
state.get_content(&atoms.next().expect("no content")).expect("no content")
),
$y => Self::y(
state.get_unit(&atoms.next().expect("no y")).expect("no y"),
state.get_content(&atoms.next().expect("no content")).expect("no content")
),
$xy => Self::xy(
state.get_unit(&atoms.next().expect("no x")).expect("no x"),
state.get_unit(&atoms.next().expect("no y")).expect("no y"),
state.get_content(&atoms.next().expect("no content")).expect("no content"),
),
_ => return None
impl<'a, E: Output + 'a, T: ViewContext<'a, E>> TryFromAtom<T>
for $Enum<E::Unit, RenderBox<'a, E>> {
fn try_from_expr (state: &T, iter: TokenIter) -> Option<Self> {
Some(if let Some((Token { value: Value::Key($x), .. }, _)) = iter.next() {
let x = state.get_unit(&iter.next().expect("no x").0.value).expect("no x");
let c = state.get_content(&iter.next().expect("no content").0.value).expect("no content");
Self::x(x, c)
} else if let Some((Token { value: Value::Key($y), .. }, _)) = iter.next() {
let y = state.get_unit(&iter.next().expect("no y").0.value).expect("no y");
let c = state.get_content(&iter.next().expect("no content").0.value).expect("no content");
Self::y(y, c)
} else if let Some((Token { value: Value::Key($xy), .. }, _)) = iter.next() {
let x = state.get_unit(&iter.next().expect("no x").0.value).expect("no x");
let y = state.get_unit(&iter.next().expect("no y").0.value).expect("no y");
let c = state.get_content(&iter.next().expect("no content").0.value).expect("no content");
Self::xy(x, y, c)
} else {
return None
})
}
}