diff --git a/dsl/src/dsl_iter.rs b/dsl/src/dsl_iter.rs index 0a94b3c..de9fe7a 100644 --- a/dsl/src/dsl_iter.rs +++ b/dsl/src/dsl_iter.rs @@ -14,10 +14,7 @@ use crate::*; /// Provides a native [Iterator] API over the [ConstIntoIter] [SourceIter] /// [TokenIter::next] returns just the [Token] and mutates `self`, /// instead of returning an updated version of the struct as [SourceIter::next] does. -#[derive(Copy, Clone, Debug, Default, PartialEq)] pub struct TokenIter<'a>( - pub SourceIter<'a> -); - +#[derive(Copy, Clone, Debug, Default, PartialEq)] pub struct TokenIter<'a>(pub SourceIter<'a>); impl<'a> TokenIter<'a> { pub const fn new (source: &'a str) -> Self { Self(SourceIter::new(source)) @@ -34,12 +31,6 @@ impl<'a> Iterator for TokenIter<'a> { } } -impl<'a> From> for TokenIter<'a> { - fn from (source: SourceIter<'a>) -> Self{ - Self(source) - } -} - /// Owns a reference to the source text. /// [SourceIter::next] emits subsequent pairs of: /// * a [Token] and diff --git a/input/src/input_dsl.rs b/input/src/input_dsl.rs index 1fe3acf..3a79fd4 100644 --- a/input/src/input_dsl.rs +++ b/input/src/input_dsl.rs @@ -74,7 +74,7 @@ impl<'a, S, C: DslCommand<'a, S>, I: DslInput> KeyMap<'a, S, C, I> for TokenIter /// which may be made available subject to given conditions. pub struct InputMap<'a, S, C: DslCommand<'a, S>, I: DslInput, M: KeyMap<'a, S, C, I> + Send + Sync> { __: &'a PhantomData<(S, C, I)>, - pub layers: Vec<( + layers: Vec<( fn(&S)->bool, M )>, @@ -152,3 +152,37 @@ where None } } + + //fn handle (&self, state: &mut T, input: &U) -> Perhaps { + //for layer in self.layers.iter() { + //if !(layer.0)(state) { + //continue + //} + //let command: Option = SourceIter(layer.1).command::<_, _, _>(state, input); + //if let Some(command) = command { + //if let Some(undo) = command.execute(state)? { + ////app.history.push(undo); + //} + //return Ok(Some(true)) + //} + //} + //Ok(None) + //} +//} + //fn layer (mut self, keymap: &'static str) -> Self { + //self.add_layer(keymap); + //self + //} + //fn layer_if (mut self, condition: impl Fn(&T)->bool + 'static, keymap: &'static str) -> Self { + //self.add_layer_if(condition, keymap); + //self + //} + //fn add_layer (&mut self, keymap: &'static str) -> &mut Self { + //self.layers.push((Box::new(|_|true), keymap)); + //self + //} + //fn add_layer_if (&mut self, condition: impl Fn(&T)->bool + 'static, keymap: &'static str) -> &mut Self { + //self.layers.push((Box::new(condition), keymap)); + //self + //} +//}