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

@ -5,29 +5,29 @@ impl<A> When<A> { pub fn new (c: bool, a: A) -> Self { Self(c, a) } }
/// Show one item if a condition is true and another if the condition is false
pub struct Either<A, B>(pub bool, pub A, pub B);
impl<A, B> Either<A, B> { pub fn new (c: bool, a: A, b: B) -> Self { Self(c, a, b) } }
try_from_atoms!(<'a, E>: When<RenderBox<'a, E>>: |state, atoms| {
let head = atoms.next()?;
if (head.kind(), head.text()) == (TokenKind::Key, "when") {
let condition = atoms.next();
if let Some(ref condition) = condition {
let condition = state.get_bool(condition).expect("no condition");
if let Some(ref content) = atoms.next() {
let content = state.get_content(content).expect("no atom");
try_from_expr!(<'a, E>: When<RenderBox<'a, E>>: |state, iter| {
if let Some((Token { value: Value::Key("when"), .. }, _)) = iter.next() {
let iter = iter.clone();
let condition = iter.next();
if let Some((ref condition, _)) = condition {
let condition = state.get_bool(&condition.value).expect("no condition");
if let Some((ref content, _)) = iter.next() {
let content = state.get_content(&content.value).expect("no atom");
return Some(Self(condition, content))
}
}
}
});
try_from_atoms!(<'a, E>: Either<RenderBox<'a, E>, RenderBox<'a, E>>: |state, atoms| {
let head = atoms.next()?;
if (head.kind(), head.text()) == (TokenKind::Key, "either") {
let condition = atoms.next();
if let Some(ref condition) = condition {
let condition = state.get_bool(condition).expect("no condition");
if let Some(ref content1) = atoms.next() {
let content1 = state.get_content(content1).expect("no content1");
if let Some(ref content2) = atoms.next() {
let content2 = state.get_content(content2).expect("no content2");
try_from_expr!(<'a, E>: Either<RenderBox<'a, E>, RenderBox<'a, E>>: |state, iter| {
if let Some((Token { value: Value::Key("either"), .. }, _)) = iter.next() {
let iter = iter.clone();
let condition = iter.next();
if let Some((ref condition, _)) = condition {
let condition = state.get_bool(&condition.value).expect("no condition");
if let Some((ref content1, _)) = iter.next() {
let content1 = state.get_content(&content1.value).expect("no content1");
if let Some((ref content2, _)) = iter.next() {
let content2 = state.get_content(&content2.value).expect("no content2");
return Some(Self(condition, content1, content2))
}
}