aboutsummaryrefslogtreecommitdiff
path: root/rprt-engine/src/selection_functions/function_empty.rs
diff options
context:
space:
mode:
Diffstat (limited to 'rprt-engine/src/selection_functions/function_empty.rs')
-rw-r--r--rprt-engine/src/selection_functions/function_empty.rs175
1 files changed, 169 insertions, 6 deletions
diff --git a/rprt-engine/src/selection_functions/function_empty.rs b/rprt-engine/src/selection_functions/function_empty.rs
index bf0a45c..4b69dcf 100644
--- a/rprt-engine/src/selection_functions/function_empty.rs
+++ b/rprt-engine/src/selection_functions/function_empty.rs
@@ -1,12 +1,175 @@
use crate::{
- selection::Selection,
- selection_functions::types::{SFArguments, SFResult},
+ buffer::BufferID,
+ expression::SearchModifier,
+ selection::{Interval, Selection},
+ selection_functions::types::{
+ SelectionFunction, SelectionFunctionError, UnparameterisedSelectionFunction,
+ },
+ state::EditorState,
};
-pub fn empty_sequential(_: SFArguments) -> SFResult {
- Ok(Selection::empty())
+pub struct Empty;
+
+impl UnparameterisedSelectionFunction for Empty {
+ const NAME: &'static str = "empty";
+
+ fn niladic(&self, _es: &EditorState) -> Result<Selection, SelectionFunctionError> {
+ Ok(Selection::empty())
+ }
+
+ fn monadic_rank0(
+ &self,
+ _es: &EditorState,
+ _buffer_id: BufferID,
+ _pos: usize,
+ ) -> Result<Selection, SelectionFunctionError> {
+ Ok(Selection::empty())
+ }
+
+ fn monadic_rank1(
+ &self,
+ _es: &EditorState,
+ _buffer_id: BufferID,
+ _interval: &Interval,
+ ) -> Result<Selection, SelectionFunctionError> {
+ Ok(Selection::empty())
+ }
+}
+
+pub struct ReverseEmpty;
+
+impl UnparameterisedSelectionFunction for ReverseEmpty {
+ const NAME: &'static str = "reverse_empty";
+
+ fn niladic(&self, es: &EditorState) -> Result<Selection, SelectionFunctionError> {
+ Ok(empty_in_buffer(es.current_buffer_id))
+ }
+
+ fn monadic_rank0(
+ &self,
+ _es: &EditorState,
+ buffer_id: BufferID,
+ _pos: usize,
+ ) -> Result<Selection, SelectionFunctionError> {
+ Ok(empty_in_buffer(buffer_id))
+ }
+
+ fn monadic_rank1(
+ &self,
+ _es: &EditorState,
+ buffer_id: BufferID,
+ _interval: &Interval,
+ ) -> Result<Selection, SelectionFunctionError> {
+ Ok(empty_in_buffer(buffer_id))
+ }
+}
+
+pub struct SequentialEmpty;
+
+impl UnparameterisedSelectionFunction for SequentialEmpty {
+ const NAME: &'static str = "sequential_empty";
+
+ fn niladic(&self, _es: &EditorState) -> Result<Selection, SelectionFunctionError> {
+ Err(SelectionFunctionError::NoNiladicForm(";e"))
+ }
+
+ fn monadic_rank0(
+ &self,
+ _es: &EditorState,
+ buffer_id: BufferID,
+ _pos: usize,
+ ) -> Result<Selection, SelectionFunctionError> {
+ Ok(empty_in_buffer(buffer_id))
+ }
+
+ fn monadic_rank1(
+ &self,
+ _es: &EditorState,
+ buffer_id: BufferID,
+ _interval: &Interval,
+ ) -> Result<Selection, SelectionFunctionError> {
+ Ok(empty_in_buffer(buffer_id))
+ }
+}
+
+pub struct SequentialReverseEmpty;
+
+impl UnparameterisedSelectionFunction for SequentialReverseEmpty {
+ const NAME: &'static str = "sequential_reverse_empty";
+
+ fn niladic(&self, _es: &EditorState) -> Result<Selection, SelectionFunctionError> {
+ Err(SelectionFunctionError::NoNiladicForm(";'e"))
+ }
+
+ fn monadic_rank0(
+ &self,
+ _es: &EditorState,
+ buffer_id: BufferID,
+ _pos: usize,
+ ) -> Result<Selection, SelectionFunctionError> {
+ Ok(empty_in_buffer(buffer_id))
+ }
+
+ fn monadic_rank1(
+ &self,
+ _es: &EditorState,
+ buffer_id: BufferID,
+ _interval: &Interval,
+ ) -> Result<Selection, SelectionFunctionError> {
+ Ok(empty_in_buffer(buffer_id))
+ }
+}
+
+pub struct ReverseSequentialEmpty;
+
+impl UnparameterisedSelectionFunction for ReverseSequentialEmpty {
+ const NAME: &'static str = "reverse_sequential_empty";
+
+ fn niladic(&self, _es: &EditorState) -> Result<Selection, SelectionFunctionError> {
+ Err(SelectionFunctionError::NoNiladicForm("';e"))
+ }
+
+ fn monadic_rank0(
+ &self,
+ _es: &EditorState,
+ buffer_id: BufferID,
+ _pos: usize,
+ ) -> Result<Selection, SelectionFunctionError> {
+ Ok(empty_in_buffer(buffer_id))
+ }
+
+ fn monadic_rank1(
+ &self,
+ _es: &EditorState,
+ buffer_id: BufferID,
+ _interval: &Interval,
+ ) -> Result<Selection, SelectionFunctionError> {
+ Ok(empty_in_buffer(buffer_id))
+ }
+}
+
+fn empty_in_buffer(buffer_id: BufferID) -> Selection {
+ Selection::Vectors {
+ buffer_id,
+ ranges: Vec::new(),
+ }
}
-pub fn empty_structural(_: SFArguments) -> SFResult {
- Ok(Selection::empty())
+pub fn selection_function_empty(
+ es: &EditorState,
+ left: Option<&Selection>,
+ right: Option<&Selection>,
+ search_mod: Option<SearchModifier>,
+) -> Result<Selection, SelectionFunctionError> {
+ match search_mod {
+ None => Empty.apply(&(), es, left, right),
+ Some(SearchModifier::Sequential) => SequentialEmpty.apply(&(), es, left, right),
+ Some(SearchModifier::Reverse) => ReverseEmpty.apply(&(), es, left, right),
+ Some(SearchModifier::SequentialReverse) => {
+ SequentialReverseEmpty.apply(&(), es, left, right)
+ }
+ Some(SearchModifier::ReverseSequential) => {
+ ReverseSequentialEmpty.apply(&(), es, left, right)
+ }
+ }
}