mirror of
https://codeberg.org/unspeaker/tek.git
synced 2025-12-06 19:56:42 +01:00
slightly closer to scripted
This commit is contained in:
parent
50728729b7
commit
fcfb7a0915
5 changed files with 66 additions and 46 deletions
|
|
@ -5,10 +5,10 @@ pub struct DslNs<'t, T: 't>(pub &'t [(&'t str, T)]);
|
|||
|
||||
/// Namespace where keys are symbols.
|
||||
pub trait DslSymNs<'t, T: 't>: 't {
|
||||
const NS: DslNs<'t, fn (&'t Self)->T>;
|
||||
const SYMS: DslNs<'t, fn (&'t Self)->T>;
|
||||
fn from_sym <D: Dsl> (&'t self, dsl: D) -> Usually<T> {
|
||||
if let Some(dsl) = dsl.sym()? {
|
||||
for (sym, get) in Self::NS.0 {
|
||||
for (sym, get) in Self::SYMS.0 {
|
||||
if dsl == *sym {
|
||||
return Ok(get(self))
|
||||
}
|
||||
|
|
@ -21,19 +21,22 @@ pub trait DslSymNs<'t, T: 't>: 't {
|
|||
#[macro_export] macro_rules! dsl_sym (
|
||||
(|$state:ident:$State:ty| -> $type:ty {$($lit:literal => $exp:expr),* $(,)?})=>{
|
||||
impl<'t> DslSymNs<'t, $type> for $State {
|
||||
const NS: DslNs<'t, fn (&'t $State)->$type> =
|
||||
const SYMS: DslNs<'t, fn (&'t $State)->$type> =
|
||||
DslNs(&[$(($lit, |$state: &$State|$exp)),*]); } });
|
||||
|
||||
pub trait DslExpNs<'t, T: 't>: 't { const NS: DslNs<'t, fn (&'t Self, &str)->T>; }
|
||||
pub trait DslExpNs<'t, T: 't>: 't {
|
||||
const EXPS: DslNs<'t, fn (&'t Self, &str)->T>;
|
||||
}
|
||||
#[macro_export] macro_rules! dsl_exp (
|
||||
(|$state:ident:$State:ty|->$type:ty { $(
|
||||
[$key:literal $(/ $sub:ident: $Sub:ty)? $(, $arg:ident $(?)? :$argtype:ty)*] => $body:expr
|
||||
),* $(,)? }) => {
|
||||
impl<'t> DslExpNs<'t, $type> for $State {
|
||||
const NS: DslNs<'t, fn (&'t $State, &str)->$type> =
|
||||
const EXPS: DslNs<'t, fn (&'t $State, &str)->$type> =
|
||||
DslNs(&[]); } });
|
||||
|
||||
pub type DslCb = fn (&App) -> Box<dyn Render<TuiOut>>;
|
||||
|
||||
impl<'t, D: Dsl> std::ops::Index<D> for DslNs<'t, DslCb> {
|
||||
type Output = DslCb;
|
||||
fn index (&self, index: D) -> &Self::Output {
|
||||
|
|
@ -47,6 +50,7 @@ impl<'t, D: Dsl> std::ops::Index<D> for DslNs<'t, DslCb> {
|
|||
&(view_nil as DslCb)
|
||||
}
|
||||
}
|
||||
fn view_nil (_: &App) -> Box<dyn Render<TuiOut>> {
|
||||
|
||||
pub fn view_nil (_: &App) -> Box<dyn Render<TuiOut>> {
|
||||
Box::new(Fill::xy("·"))
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue