mirror of
https://codeberg.org/unspeaker/tek.git
synced 2025-12-06 19:56:42 +01:00
getting there with the iters but still wrong
This commit is contained in:
parent
323afe4c89
commit
266f59085e
3 changed files with 32 additions and 35 deletions
|
|
@ -2,7 +2,7 @@ use crate::*;
|
|||
#[derive(Debug, Copy, Clone, Default)] pub enum Alignment { #[default] Center, X, Y, NW, N, NE, E, SE, S, SW, W }
|
||||
pub struct Align<A>(Alignment, A);
|
||||
try_from_expr!(<'a, E>: Align<RenderBox<'a, E>>: |state, iter| {
|
||||
if let Some((Token { value: Value::Key(key), .. }, _)) = iter.next() {
|
||||
if let Some((Token { value: Value::Key(key), .. }, iter)) = iter.next() {
|
||||
match key {
|
||||
"align/c" => return Some(Self::c(state.get_content(&iter.next()?.0.value).expect("no content"))),
|
||||
"align/x" => return Some(Self::x(state.get_content(&iter.next()?.0.value).expect("no content"))),
|
||||
|
|
@ -15,7 +15,7 @@ try_from_expr!(<'a, E>: Align<RenderBox<'a, E>>: |state, iter| {
|
|||
"align/ne" => return Some(Self::ne(state.get_content(&iter.next()?.0.value).expect("no content"))),
|
||||
"align/sw" => return Some(Self::sw(state.get_content(&iter.next()?.0.value).expect("no content"))),
|
||||
"align/se" => return Some(Self::se(state.get_content(&iter.next()?.0.value).expect("no content"))),
|
||||
_ => {}
|
||||
_ => return None
|
||||
}
|
||||
}
|
||||
});
|
||||
|
|
|
|||
|
|
@ -32,36 +32,33 @@ impl<E: Output, A: Content<E>, B: Content<E>> Content<E> for Bsp<A, B> {
|
|||
}
|
||||
}
|
||||
try_from_expr!(<'a, E>: Bsp<RenderBox<'a, E>, RenderBox<'a, E>>: |state, iter| {
|
||||
if let Some(Token { value: Value::Key(key), .. }) = iter.peek() {
|
||||
let iter = iter.clone().next().unwrap().1;
|
||||
match key {
|
||||
"bsp/n" => return Some(Self::n(
|
||||
state.get_content(&iter.next()?.0.value).expect("no south"),
|
||||
state.get_content(&iter.next()?.0.value).expect("no north")
|
||||
)),
|
||||
"bsp/s" => return Some(Self::s(
|
||||
state.get_content(&iter.next()?.0.value).expect("no north"),
|
||||
state.get_content(&iter.next()?.0.value).expect("no south")
|
||||
)),
|
||||
"bsp/e" => return Some(Self::e(
|
||||
state.get_content(&iter.next()?.0.value).expect("no west"),
|
||||
state.get_content(&iter.next()?.0.value).expect("no east")
|
||||
)),
|
||||
"bsp/w" => return Some(Self::w(
|
||||
state.get_content(&iter.next()?.0.value).expect("no east"),
|
||||
state.get_content(&iter.next()?.0.value).expect("no west")
|
||||
)),
|
||||
"bsp/a" => return Some(Self::a(
|
||||
state.get_content(&iter.next()?.0.value).expect("no above"),
|
||||
state.get_content(&iter.next()?.0.value).expect("no below")
|
||||
)),
|
||||
"bsp/b" => return Some(Self::b(
|
||||
state.get_content(&iter.next()?.0.value).expect("no above"),
|
||||
state.get_content(&iter.next()?.0.value).expect("no below")
|
||||
)),
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
Some(if let Some((Token { value: Value::Key("bsp/n"), .. }, iter)) = iter.next() {
|
||||
let (s, iter) = iter.next().map(|(c, iter)|(state.get_content(&c.value).expect("no south provided"), iter)).expect("no south specified");
|
||||
let (n, _) = iter.next().map(|(c, iter)|(state.get_content(&c.value).expect("no north provided"), iter)).expect("no north specified");
|
||||
Self::n(s, n)
|
||||
} else if let Some((Token { value: Value::Key("bsp/s"), .. }, iter)) = iter.next() {
|
||||
let (n, iter) = iter.next().map(|(c, iter)|(state.get_content(&c.value).expect("no north provided"), iter)).expect("no north specified");
|
||||
let (s, _) = iter.next().map(|(c, iter)|(state.get_content(&c.value).expect("no south provided"), iter)).expect("no south specified");
|
||||
Self::s(n, s)
|
||||
} else if let Some((Token { value: Value::Key("bsp/e"), .. }, iter)) = iter.next() {
|
||||
let (w, iter) = iter.next().map(|(c, iter)|(state.get_content(&c.value).expect("no west provided"), iter)).expect("no west specified");
|
||||
let (e, _) = iter.next().map(|(c, iter)|(state.get_content(&c.value).expect("no east provided"), iter)).expect("no east specified");
|
||||
Self::e(w, e)
|
||||
} else if let Some((Token { value: Value::Key("bsp/w"), .. }, iter)) = iter.next() {
|
||||
let (e, iter) = iter.next().map(|(c, iter)|(state.get_content(&c.value).expect("no west provided"), iter)).expect("no west specified");
|
||||
let (w, _) = iter.next().map(|(c, iter)|(state.get_content(&c.value).expect("no east provided"), iter)).expect("no east specified");
|
||||
Self::w(e, w)
|
||||
} else if let Some((Token { value: Value::Key("bsp/a"), .. }, iter)) = iter.next() {
|
||||
let (a, iter) = iter.next().map(|(c, iter)|(state.get_content(&c.value).expect("no above provided"), iter)).expect("no above specified");
|
||||
let (b, _) = iter.next().map(|(c, iter)|(state.get_content(&c.value).expect("no below provided"), iter)).expect("no below specified");
|
||||
Self::a(a, b)
|
||||
} else if let Some((Token { value: Value::Key("bsp/b"), .. }, iter)) = iter.next() {
|
||||
let (a, iter) = iter.next().map(|(c, iter)|(state.get_content(&c.value).expect("no above provided"), iter)).expect("no above specified");
|
||||
let (b, _) = iter.next().map(|(c, iter)|(state.get_content(&c.value).expect("no below provided"), iter)).expect("no below specified");
|
||||
Self::b(a, b)
|
||||
} else {
|
||||
return None
|
||||
})
|
||||
});
|
||||
impl<A, B> Bsp<A, B> {
|
||||
pub fn n (a: A, b: B) -> Self { Self(North, a, b) }
|
||||
|
|
|
|||
|
|
@ -55,16 +55,16 @@ macro_rules! transform_xy_unit {
|
|||
fn try_from_expr (state: &'a T, iter: TokenIter<'a>) -> Option<Self> {
|
||||
Some(if let Some((Token { value: Value::Key($x), .. }, iter)) = iter.next() {
|
||||
let (x, iter) = iter.next().map(|(x, iter)|(state.get(&x.value).expect("no x provided"), iter)).expect("no x specified");
|
||||
let (c, _) = iter.next().map(|(x, iter)|(state.get_content(&x.value).expect("no content provided"), iter)).expect("no content specified");
|
||||
let (c, _) = iter.next().map(|(c, iter)|(state.get_content(&c.value).expect("no content provided"), iter)).expect("no content specified");
|
||||
Self::x(x, c)
|
||||
} else if let Some((Token { value: Value::Key($y), .. }, iter)) = iter.next() {
|
||||
let (y, iter) = iter.next().map(|(y, iter)|(state.get(&y.value).expect("no y provided"), iter)).expect("no y specified");
|
||||
let (c, _) = iter.next().map(|(x, iter)|(state.get_content(&x.value).expect("no content provided"), iter)).expect("no content specified");
|
||||
let (c, _) = iter.next().map(|(c, iter)|(state.get_content(&c.value).expect("no content provided"), iter)).expect("no content specified");
|
||||
Self::y(y, c)
|
||||
} else if let Some((Token { value: Value::Key($xy), .. }, iter)) = iter.next() {
|
||||
let (x, iter) = iter.next().map(|(x, iter)|(state.get(&x.value).expect("no x provided"), iter)).expect("no x specified");
|
||||
let (y, iter) = iter.next().map(|(y, iter)|(state.get(&y.value).expect("no y provided"), iter)).expect("no y specified");
|
||||
let (c, _) = iter.next().map(|(x, iter)|(state.get_content(&x.value).expect("no content provided"), iter)).expect("no content specified");
|
||||
let (c, _) = iter.next().map(|(c, iter)|(state.get_content(&c.value).expect("no content provided"), iter)).expect("no content specified");
|
||||
Self::xy(x, y, c)
|
||||
} else {
|
||||
return None
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue