mirror of
https://codeberg.org/unspeaker/tek.git
synced 2025-12-08 12:46:42 +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
|
|
@ -7,31 +7,24 @@ 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_expr!(<'a, E>: When<RenderBox<'a, E>>: |state, iter| {
|
||||
if let Some(Token { value: Value::Key("when"), .. }) = iter.peek() {
|
||||
let iter = iter.clone().next().unwrap().1;
|
||||
let condition = iter.next();
|
||||
if let Some((ref condition, _)) = condition {
|
||||
let condition = state.get(&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))
|
||||
}
|
||||
}
|
||||
let _ = iter.next().unwrap();
|
||||
let condition = iter.next().expect("no condition specified");
|
||||
let content = iter.next().expect("no content specified");
|
||||
let condition = state.get(&condition.value).expect("no condition provided");
|
||||
let content = state.get_content(&content.value).expect("no content provided");
|
||||
return Some(Self(condition, content))
|
||||
}
|
||||
});
|
||||
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().next().unwrap().1;
|
||||
let condition = iter.next();
|
||||
if let Some((ref condition, _)) = condition {
|
||||
let condition = state.get(&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))
|
||||
}
|
||||
}
|
||||
}
|
||||
if let Some(Token { value: Value::Key("either"), .. }) = iter.peek() {
|
||||
let _ = iter.next().unwrap();
|
||||
let condition = iter.next().expect("no condition specified");
|
||||
let content = iter.next().expect("no content specified");
|
||||
let alternate = iter.next().expect("no alternate specified");
|
||||
let condition = state.get(&condition.value).expect("no condition provided");
|
||||
let content = state.get_content(&content.value).expect("no content provided");
|
||||
let alternate = state.get_content(&alternate.value).expect("no alternate provided");
|
||||
return Some(Self(condition, content, alternate))
|
||||
}
|
||||
});
|
||||
impl<E: Output, A: Render<E>> Content<E> for When<A> {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue