output: more big refactors

This commit is contained in:
🪞👃🪞 2025-09-07 12:34:30 +03:00
parent 194f2f9874
commit 5e6338fad8
68 changed files with 1604 additions and 1016 deletions

View file

@ -63,7 +63,7 @@ dsl_type!(DslExpr {
).into())
};
)*
Ok(Some($body as $Type))
Ok(Some($body/* as $Type*/))
};
($name, get)
}),* )? ];
@ -74,12 +74,14 @@ pub trait DslNsExprs<'a, T: 'a>: 'a {
const EXPRS: DslExprs<'a, Self, T> = &[];
/// Resolve an expression if known.
fn from_expr (&'a self, dsl: impl DslExpr + 'a) -> Perhaps<T> {
let head = dsl.head()?;
for (key, get) in Self::EXPRS.iter() {
if Some(*key) == head {
return get(self, dsl.tail()?.unwrap_or(""))
if let Some(dsl) = dsl.expr()? {
let head = dsl.head()?;
for (key, get) in Self::EXPRS.iter() {
if Some(*key) == head {
return get(self, dsl.tail()?.unwrap_or(""))
}
}
}
return Ok(None)
Ok(None)
}
}

View file

@ -16,3 +16,31 @@ pub trait DslNs<'a, T: 'a>: DslNsWords<'a, T> + DslNsExprs<'a, T> {
Ok(None)
}
}
#[macro_export] macro_rules! dsl_ns {
($State:ty: $Type:ty {
$(literal = |$dsl:ident| $literal:expr;)?
$(word = |$state_w:ident| {
$($word:literal => $body_w:expr),* $(,)?
};)?
$(expr = |$state_e:ident| {
$($head:literal $args:tt => $body_e:expr),* $(,)?
};)?
}) => {
impl<'a> DslNs<'a, $Type> for $State {
$(fn from_literal (&self, $dsl: impl Dsl) -> Perhaps<$Type> {
$literal
})?
}
impl<'a> DslNsWords<'a, $Type> for $State {
$(dsl_words! { 'a |$state_w| -> $Type {
$($word => $body_w),*
} })?
}
impl<'a> DslNsExprs<'a, $Type> for $State {
$(dsl_exprs! { 'a |$state_e| -> $Type {
$($head $args => $body_e),*
} })?
}
}
}