mirror of
https://codeberg.org/unspeaker/tek.git
synced 2025-12-13 23:26:41 +01:00
TokenIter -> SourceIter, reuse logic in operators, and now it renders correctly!
This commit is contained in:
parent
266f59085e
commit
b8726de78f
13 changed files with 203 additions and 154 deletions
|
|
@ -32,33 +32,27 @@ 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| {
|
||||
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
|
||||
})
|
||||
if let Some(Token { value: Value::Key(key), .. }) = iter.peek() {
|
||||
match key {
|
||||
"bsp/n"|"bsp/s"|"bsp/e"|"bsp/w"|"bsp/a"|"bsp/b" => {
|
||||
let _ = iter.next().unwrap();
|
||||
let c1 = iter.next().expect("no content1 specified");
|
||||
let c2 = iter.next().expect("no content2 specified");
|
||||
let c1 = state.get_content(&c1.value).expect("no content1 provided");
|
||||
let c2 = state.get_content(&c2.value).expect("no content2 provided");
|
||||
return Some(match key {
|
||||
"bsp/n" => Self::n(c1, c2),
|
||||
"bsp/s" => Self::s(c1, c2),
|
||||
"bsp/e" => Self::e(c1, c2),
|
||||
"bsp/w" => Self::w(c1, c2),
|
||||
"bsp/a" => Self::a(c1, c2),
|
||||
"bsp/b" => Self::b(c1, c2),
|
||||
_ => unreachable!(),
|
||||
})
|
||||
},
|
||||
_ => return None
|
||||
}
|
||||
}
|
||||
});
|
||||
impl<A, B> Bsp<A, B> {
|
||||
pub fn n (a: A, b: B) -> Self { Self(North, a, b) }
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue