mirror of
https://codeberg.org/unspeaker/tek.git
synced 2025-12-06 11:46:41 +01:00
test top level expr parsing
This commit is contained in:
parent
d14d67172c
commit
9756862091
7 changed files with 129 additions and 82 deletions
|
|
@ -32,7 +32,9 @@ 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.next() {
|
||||
panic!("bsp:\n{iter:#?}\n{:#?}", iter.peek());
|
||||
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"),
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@ impl<A> When<A> { pub fn new (c: bool, a: A) -> Self { Self(c, a) } }
|
|||
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.next() {
|
||||
if let Some(Token { value: Value::Key("when"), .. }) = iter.peek() {
|
||||
let iter = iter.clone();
|
||||
let condition = iter.next();
|
||||
if let Some((ref condition, _)) = condition {
|
||||
|
|
|
|||
|
|
@ -9,9 +9,12 @@ use crate::*;
|
|||
impl<'a> ViewContext<'a, $Output> for $State {
|
||||
fn get_content_custom (&'a $self, value: &Value<'a>) -> Option<RenderBox<'a, $Output>> {
|
||||
if let Value::Sym(s) = value {
|
||||
match *s { $($sym => Some($body),)* _ => None }
|
||||
match *s {
|
||||
$($sym => Some($body),)*
|
||||
_ => None
|
||||
}
|
||||
} else {
|
||||
panic!("expected symbol")
|
||||
panic!("expected content, got: {value:?}")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -72,12 +75,10 @@ pub trait ViewContext<'a, E: Output + 'a>: Send + Sync
|
|||
}
|
||||
}
|
||||
#[macro_export] macro_rules! try_from_expr {
|
||||
(<$l:lifetime, $E:ident>: $Struct:ty: |$state:ident, $atoms:ident|$body:expr) => {
|
||||
(<$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_atom ($state: &$l T, atom: Value<$l>) -> Option<Self> {
|
||||
if let Value::Exp(0, $atoms) = atom {
|
||||
$body;
|
||||
}
|
||||
fn try_from_expr ($state: &$l T, $iter: TokenIter<'a>) -> Option<Self> {
|
||||
$body;
|
||||
None
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue