dsl: extract dsl_error; ParseError -> DslError

This commit is contained in:
🪞👃🪞 2025-05-10 15:49:33 +03:00
parent f18e01c220
commit ed772b9872
4 changed files with 34 additions and 21 deletions

View file

@ -1,10 +1,21 @@
use crate::*;
/// Map EDN tokens to parameters of a given type for a given context
/// TODO: Replace both [Context] and [TryFromDsl] with this trait
/// which returns a [Result].
pub trait Dsl<U>: Sized {
fn take <'state, 'source> (_: &'state Self, _: &mut TokenIter<'source>) -> Perhaps<U> {
Ok(None)
}
fn take_or_fail <'state, 'source> (
state: &'state Self, iter: &mut TokenIter<'source>
) -> Usually<U> {
if let Some(value) = Self::take(state, iter)? {
Ok(value)
} else {
Result::Err("not found".into()) // TODO add info and error type
}
}
}
/// Map EDN tokens to parameters of a given type for a given context