TokenIter -> SourceIter, reuse logic in operators, and now it renders correctly!

This commit is contained in:
🪞👃🪞 2025-01-19 01:46:06 +01:00
parent 266f59085e
commit b8726de78f
13 changed files with 203 additions and 154 deletions

View file

@ -7,7 +7,7 @@ use crate::*;
fn content (&$self) -> impl Render<$Output> { $expr }
}
impl<'a> ViewContext<'a, $Output> for $State {
fn get_content_custom (&'a $self, value: &Value<'a>) -> Option<RenderBox<'a, $Output>> {
fn get_content_sym (&'a $self, value: &Value<'a>) -> Option<RenderBox<'a, $Output>> {
if let Value::Sym(s) = value {
match *s {
$($sym => Some($body),)*
@ -23,7 +23,7 @@ use crate::*;
// An ephemeral wrapper around view state and view description,
// that is meant to be constructed and returned from [Content::content].
pub struct View<'a, T>(pub &'a T, pub TokenIter<'a>);
pub struct View<'a, T>(pub &'a T, pub SourceIter<'a>);
impl<'a, O: Output + 'a, T: ViewContext<'a, O>> Content<O> for View<'a, T> {
fn content (&self) -> impl Render<O> {
let iter = self.1.clone();
@ -42,14 +42,14 @@ pub trait ViewContext<'a, E: Output + 'a>: Send + Sync
+ Context<E::Unit>
{
fn get_content (&'a self, value: &Value<'a>) -> Option<RenderBox<'a, E>> {
if let Some(builtin) = self.get_content_builtin(value) {
Some(builtin)
} else {
self.get_content_custom(value)
match value {
Value::Sym(_) => self.get_content_sym(value),
Value::Exp(_, _) => self.get_content_exp(value),
_ => panic!("only :symbols and (expressions) accepted here")
}
}
fn get_content_custom (&'a self, value: &Value<'a>) -> Option<RenderBox<'a, E>>;
fn get_content_builtin (&'a self, value: &Value<'a>) -> Option<RenderBox<'a, E>> {
fn get_content_sym (&'a self, value: &Value<'a>) -> Option<RenderBox<'a, E>>;
fn get_content_exp (&'a self, value: &Value<'a>) -> Option<RenderBox<'a, E>> {
try_delegate!(self, *value, When::<RenderBox<'a, E>>);
try_delegate!(self, *value, Either::<RenderBox<'a, E>, RenderBox<'a, E>>);
try_delegate!(self, *value, Align::<RenderBox<'a, E>>);
@ -78,6 +78,7 @@ pub trait ViewContext<'a, E: Output + 'a>: Send + Sync
(<$l:lifetime, $E:ident>: $Struct:ty: |$state:ident, $iter:ident|$body:expr) => {
impl<$l, $E: Output + $l, T: ViewContext<$l, $E>> TryFromAtom<$l, T> for $Struct {
fn try_from_expr ($state: &$l T, $iter: TokenIter<'a>) -> Option<Self> {
let mut $iter = $iter.clone();
$body;
None
}