mirror of
https://codeberg.org/unspeaker/tengri.git
synced 2025-12-06 19:56:44 +01:00
This commit is contained in:
parent
a4a1066f18
commit
abc87d3234
7 changed files with 25 additions and 197 deletions
|
|
@ -2,13 +2,13 @@ use crate::*;
|
|||
|
||||
pub trait Dsl<Type> {
|
||||
fn take <'source> (&self, words: &mut TokenIter<'source>) -> Perhaps<Type>;
|
||||
fn take_or_fail <'source> (
|
||||
&self, words: &mut TokenIter<'source>, error: impl Into<Box<dyn std::error::Error>>
|
||||
fn take_or_fail <'source, E: Into<Box<dyn std::error::Error>>, F: Fn()->E> (
|
||||
&self, words: &mut TokenIter<'source>, error: F
|
||||
) -> Usually<Type> {
|
||||
if let Some(value) = Dsl::<Type>::take(self, words)? {
|
||||
Ok(value)
|
||||
} else {
|
||||
Result::Err(format!("{}: {:?}", error.into(), words.peek().map(|x|x.value)).into())
|
||||
Result::Err(format!("{}: {:?}", error().into(), words.peek().map(|x|x.value)).into())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -22,13 +22,13 @@ impl<Type: Namespace<State>, State> Dsl<Type> for State {
|
|||
pub trait Namespace<State>: Sized {
|
||||
fn take_from <'source> (state: &State, words: &mut TokenIter<'source>)
|
||||
-> Perhaps<Self>;
|
||||
fn take_from_or_fail <'source> (
|
||||
state: &State, words: &mut TokenIter<'source>, error: impl Into<Box<dyn std::error::Error>>
|
||||
fn take_from_or_fail <'source, E: Into<Box<dyn std::error::Error>>, F: Fn()->E> (
|
||||
state: &State, words: &mut TokenIter<'source>, error: F
|
||||
) -> Usually<Self> {
|
||||
if let Some(value) = Namespace::<State>::take_from(state, words)? {
|
||||
Ok(value)
|
||||
} else {
|
||||
Result::Err(format!("{}: {:?}", error.into(), words.peek().map(|x|x.value)).into())
|
||||
Result::Err(format!("{}: {:?}", error().into(), words.peek().map(|x|x.value)).into())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue