mirror of
https://codeberg.org/unspeaker/tek.git
synced 2025-12-06 11:46:41 +01:00
ughhh needs special case
This commit is contained in:
parent
cf1fd5b45a
commit
a362028ae7
4 changed files with 124 additions and 97 deletions
|
|
@ -92,28 +92,36 @@ impl<T: Context<U>, U> Context<U> for Option<T> {
|
|||
}
|
||||
};
|
||||
}
|
||||
/// Implement `Context` for a context and content type.
|
||||
/// Implement `Context` for a context and the boolean type.
|
||||
///
|
||||
/// This enables support for layout expressions.
|
||||
#[macro_export] macro_rules! provide_content {
|
||||
(|$self:ident:$State:ty|{ $($pat:pat => $expr:expr),* $(,)? }) => {
|
||||
impl<'a, E: Output> Context<'a, Box<dyn Render<E> + 'a>> for $State {
|
||||
fn get (&'a $self, atom: &'a Value) -> Option<Box<dyn Render<E> + 'a>> {
|
||||
Some(match (atom.kind(), atom.text()) {
|
||||
/// This enables support for boolean literals.
|
||||
#[macro_export] macro_rules! provide_bool {
|
||||
// Provide a value that may also be a numeric literal in the EDN, to a generic implementation.
|
||||
($type:ty:|$self:ident:<$T:ident:$Trait:path>|{ $($pat:pat => $expr:expr),* $(,)? }) => {
|
||||
impl<$T: $Trait> Context<$type> for $T {
|
||||
fn get (&$self, atom: &Value) -> Option<$type> {
|
||||
Some(match atom {
|
||||
Value::Num(n) => match *n { 0 => false, _ => true },
|
||||
Value::Sym(":false") | Value::Sym(":f") => false,
|
||||
Value::Sym(":true") | Value::Sym(":t") => true,
|
||||
$(Value::Sym($pat) => $expr,)*
|
||||
_ => return Context::get(self, atom)
|
||||
})
|
||||
}
|
||||
}
|
||||
};
|
||||
// Provide a value that may also be a numeric literal in the EDN, to a concrete implementation.
|
||||
($type:ty:|$self:ident:$State:ty|{ $($pat:pat => $expr:expr),* $(,)? }) => {
|
||||
impl Context<$type> for $State {
|
||||
fn get (&$self, atom: &Value) -> Option<$type> {
|
||||
Some(match atom {
|
||||
Value::Num(n) => match *n { 0 => false, _ => true },
|
||||
Value::Sym(":false") | Value::Sym(":f") => false,
|
||||
Value::Sym(":true") | Value::Sym(":t") => true,
|
||||
$(Value::Sym($pat) => $expr,)*
|
||||
_ => return None
|
||||
})
|
||||
}
|
||||
}
|
||||
};
|
||||
($Output:ty: |$self:ident:$State:ty|{ $($pat:pat => $expr:expr),* $(,)? }) => {
|
||||
impl<'a> Context<'a, Box<dyn Render<$Output> + 'a>> for $State {
|
||||
fn get (&'a $self, atom: &'a Value) -> Option<Box<dyn Render<$Output> + 'a>> {
|
||||
Some(match (atom.kind(), atom.text()) {
|
||||
$(Value::Sym($pat) => $expr,)*
|
||||
_ => return None
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
use crate::*;
|
||||
#[derive(Copy, Clone, Debug, PartialEq)] pub struct TokenIter<'a>(pub &'a str);
|
||||
#[derive(Copy, Clone, Debug, Default, PartialEq)] pub struct TokenIter<'a>(pub &'a str);
|
||||
const_iter!(<'a>|self: TokenIter<'a>| => Token<'a> => self.next_mut().map(|(result, _)|result));
|
||||
impl<'a> From<&'a str> for TokenIter<'a> {fn from (source: &'a str) -> Self{Self::new(source)}}
|
||||
impl<'a> TokenIter<'a> {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue