aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--rprt-engine/src/selection.rs9
-rw-r--r--rprt-engine/src/selection_function.rs36
2 files changed, 35 insertions, 10 deletions
diff --git a/rprt-engine/src/selection.rs b/rprt-engine/src/selection.rs
index ee83294..1d1c557 100644
--- a/rprt-engine/src/selection.rs
+++ b/rprt-engine/src/selection.rs
@@ -75,15 +75,6 @@ where
SelectionError(SelectionError),
}
-impl<E> From<E> for VectoriseError<E>
-where
- E: std::error::Error + 'static,
-{
- fn from(e: E) -> Self {
- VectoriseError::ProcessingError(e)
- }
-}
-
impl Selection {
pub fn empty() -> Self {
Self::MultiRanges {
diff --git a/rprt-engine/src/selection_function.rs b/rprt-engine/src/selection_function.rs
index 3da61c9..0b6e98e 100644
--- a/rprt-engine/src/selection_function.rs
+++ b/rprt-engine/src/selection_function.rs
@@ -47,7 +47,37 @@ impl From<SFComponents> for SelectionFunction<VectoriseError<SFError>> {
}
impl SelectionFunction<VectoriseError<SFError>> {
- pub fn empty() -> Self {
+ pub fn transform_conditional(sf: Self) -> Self {
+ fn condition(
+ pred: Result<Selection, VectoriseError<SFError>>,
+ res: Selection,
+ ) -> Result<Selection, VectoriseError<SFError>> {
+ match pred {
+ Ok(mut sel) => Ok(if sel.is_empty() { sel } else { res }),
+ Err(e) => Err(e),
+ }
+ }
+
+ let dyadic: Option<Box<dyn Fn(&EditorState, &Selection, &Selection) -> Result<_, _>>> =
+ if let Some(dyadic) = sf.dyadic {
+ Some(Box::new(move |es, left, right| {
+ condition((dyadic)(es, left, right), left.clone())
+ }))
+ } else {
+ None
+ };
+
+ let monadic: Box<dyn Fn(&EditorState, &Selection) -> Result<_, _>> =
+ Box::new(move |es, left| condition((sf.monadic)(es, left), left.clone()));
+
+ SelectionFunction {
+ niladic: sf.niladic,
+ monadic,
+ dyadic,
+ }
+ }
+ // ----------------------------------------------------------------
+ pub fn empty_sequential() -> Self {
SFComponents {
niladic: Box::new(|_| Ok(Selection::empty())),
monadic_rank0: Box::new(|_, _, _| Ok(Selection::empty())),
@@ -57,6 +87,10 @@ impl SelectionFunction<VectoriseError<SFError>> {
.into()
}
+ pub fn empy_structural() -> Self {
+ Self::empty_sequential()
+ }
+
pub fn end_sequential() -> Self {
fn get_end_position(es: &EditorState, buffer_id: BufferID) -> Result<Selection, SFError> {
if let Some(buf) = es.get_buffer(buffer_id) {