diff options
| author | tslil <tslil@posteo.de> | 2026-03-24 18:27:04 +0000 |
|---|---|---|
| committer | tslil <tslil@posteo.de> | 2026-03-24 18:31:24 +0000 |
| commit | 12455c6369547e970c4556bb20d8261eadc3b5ab (patch) | |
| tree | 94d7bb592e50b1eaa4954b50322af4534ae5036d /rprt-engine/src | |
| parent | 5ee9f5e935e147e5f16801a9cbe461f0585c6ba8 (diff) | |
big ole rename for consistent terminology: scalar, vector, matrix, tensor
Diffstat (limited to 'rprt-engine/src')
| -rw-r--r-- | rprt-engine/src/lib.rs | 1 | ||||
| -rw-r--r-- | rprt-engine/src/selection.rs | 90 | ||||
| -rw-r--r-- | rprt-engine/src/selection_functions/function_character.rs | 24 | ||||
| -rw-r--r-- | rprt-engine/src/selection_functions/function_end.rs | 24 | ||||
| -rw-r--r-- | rprt-engine/src/selection_functions/result_transformation.rs | 4 | ||||
| -rw-r--r-- | rprt-engine/src/text.rs | 18 |
6 files changed, 90 insertions, 71 deletions
diff --git a/rprt-engine/src/lib.rs b/rprt-engine/src/lib.rs index e002005..8d53464 100644 --- a/rprt-engine/src/lib.rs +++ b/rprt-engine/src/lib.rs @@ -5,4 +5,5 @@ pub mod parser; pub mod selection; pub mod selection_functions; pub mod state; +pub mod text; pub mod token; diff --git a/rprt-engine/src/selection.rs b/rprt-engine/src/selection.rs index 341c6ad..a3259b8 100644 --- a/rprt-engine/src/selection.rs +++ b/rprt-engine/src/selection.rs @@ -52,19 +52,19 @@ impl Interval { #[derive(Debug, Clone)] pub enum Selection { - Position { + Scalar { buffer_id: BufferID, pos: usize, }, - Range { + Vector { buffer_id: BufferID, interval: Interval, }, - Ranges { + Vectors { buffer_id: BufferID, ranges: Vec<Interval>, }, - MultiRanges { + MultiVectors { multi_ranges: HashMap<BufferID, Vec<Interval>>, }, } @@ -94,13 +94,13 @@ where impl Selection { pub fn empty() -> Self { - Self::MultiRanges { + Self::MultiVectors { multi_ranges: HashMap::new(), } } fn normalise(&mut self) { - if let Self::MultiRanges { multi_ranges } = self { + if let Self::MultiVectors { multi_ranges } = self { multi_ranges.retain(|_, v| !v.is_empty()) } } @@ -108,19 +108,19 @@ impl Selection { pub fn is_empty(&mut self) -> bool { self.normalise(); match self { - Self::Position { .. } => return false, - Self::Range { .. } => return false, - Self::Ranges { ranges, .. } => ranges.is_empty(), - Self::MultiRanges { multi_ranges } => multi_ranges.is_empty(), + Self::Scalar { .. } => return false, + Self::Vector { .. } => return false, + Self::Vectors { ranges, .. } => ranges.is_empty(), + Self::MultiVectors { multi_ranges } => multi_ranges.is_empty(), } } fn rank(&self) -> Rank { match self { - Self::Position { .. } => Rank::Zero, - Self::Range { .. } => Rank::One, - Self::Ranges { .. } => Rank::Two, - Self::MultiRanges { .. } => Rank::Three, + Self::Scalar { .. } => Rank::Zero, + Self::Vector { .. } => Rank::One, + Self::Vectors { .. } => Rank::Two, + Self::MultiVectors { .. } => Rank::Three, } } @@ -128,13 +128,13 @@ impl Selection { use Rank::*; match (self, to_rank) { - (Self::Position { .. }, Zero) => Ok(self.clone()), - (Self::Range { .. }, One) => Ok(self.clone()), - (Self::Ranges { .. }, Two) => Ok(self.clone()), - (Self::MultiRanges { .. }, Three) => Ok(self.clone()), + (Self::Scalar { .. }, Zero) => Ok(self.clone()), + (Self::Vector { .. }, One) => Ok(self.clone()), + (Self::Vectors { .. }, Two) => Ok(self.clone()), + (Self::MultiVectors { .. }, Three) => Ok(self.clone()), - // Position - (Self::Position { pos, buffer_id }, One) => Ok(Self::Range { + // Scalar + (Self::Scalar { pos, buffer_id }, One) => Ok(Self::Vector { interval: Interval { start: pos + 0, end: pos + 1, @@ -142,7 +142,7 @@ impl Selection { }, buffer_id: *buffer_id, }), - (Self::Position { pos, buffer_id }, Two) => Ok(Self::Ranges { + (Self::Scalar { pos, buffer_id }, Two) => Ok(Self::Vectors { ranges: vec![Interval { start: pos + 0, end: pos + 1, @@ -150,7 +150,7 @@ impl Selection { }], buffer_id: *buffer_id, }), - (Self::Position { pos, buffer_id }, Three) => { + (Self::Scalar { pos, buffer_id }, Three) => { let mut map = HashMap::new(); map.insert( *buffer_id, @@ -160,22 +160,22 @@ impl Selection { capture_groups: Vec::new(), }], ); - Ok(Self::MultiRanges { multi_ranges: map }) + Ok(Self::MultiVectors { multi_ranges: map }) } - // Range promotions + // Vector promotions ( - Self::Range { + Self::Vector { interval, buffer_id, }, Two, - ) => Ok(Self::Ranges { + ) => Ok(Self::Vectors { ranges: vec![interval.clone()], buffer_id: *buffer_id, }), ( - Self::Range { + Self::Vector { interval, buffer_id, }, @@ -183,14 +183,14 @@ impl Selection { ) => { let mut map = HashMap::new(); map.insert(*buffer_id, vec![interval.clone()]); - Ok(Self::MultiRanges { multi_ranges: map }) + Ok(Self::MultiVectors { multi_ranges: map }) } - // Ranges promotion - (Self::Ranges { ranges, buffer_id }, Three) => { + // Vectors promotion + (Self::Vectors { ranges, buffer_id }, Three) => { let mut map = HashMap::new(); map.insert(*buffer_id, ranges.clone()); - Ok(Self::MultiRanges { multi_ranges: map }) + Ok(Self::MultiVectors { multi_ranges: map }) } // all other cases @@ -203,10 +203,10 @@ impl Selection { fn buffers(&self) -> Vec<BufferID> { match self { - Self::Position { buffer_id, .. } => vec![*buffer_id], - Self::Range { buffer_id, .. } => vec![*buffer_id], - Self::Ranges { buffer_id, .. } => vec![*buffer_id], - Self::MultiRanges { multi_ranges } => multi_ranges.keys().copied().collect(), + Self::Scalar { buffer_id, .. } => vec![*buffer_id], + Self::Vector { buffer_id, .. } => vec![*buffer_id], + Self::Vectors { buffer_id, .. } => vec![*buffer_id], + Self::MultiVectors { multi_ranges } => multi_ranges.keys().copied().collect(), } } @@ -243,12 +243,12 @@ impl Selection { for sel in &promoted { match sel { - Self::Ranges { ranges, .. } => all_intervals.extend(ranges.clone()), - _ => unreachable!("promote() to Rank::Two should always produce Ranges"), + Self::Vectors { ranges, .. } => all_intervals.extend(ranges.clone()), + _ => unreachable!("promote() to Rank::Two should always produce Vectors"), } } - Ok(Self::Ranges { + Ok(Self::Vectors { ranges: all_intervals, buffer_id, }) @@ -259,7 +259,7 @@ impl Selection { for sel in &promoted { match sel { - Self::MultiRanges { multi_ranges } => { + Self::MultiVectors { multi_ranges } => { for (&buffer, intervals) in multi_ranges { buffer_intervals .entry(buffer) @@ -268,12 +268,12 @@ impl Selection { } } _ => unreachable!( - "promote() to Rank::Three should always produce MultiRanges" + "promote() to Rank::Three should always produce MultiVectors" ), } } - Ok(Self::MultiRanges { + Ok(Self::MultiVectors { multi_ranges: buffer_intervals, }) } @@ -299,18 +299,18 @@ impl Selection { }; match self { - &Self::Position { buffer_id, pos } => { + &Self::Scalar { buffer_id, pos } => { fn_rank_zero(state, buffer_id, pos).map_err(ProcessingError) } - Self::Range { + Self::Vector { interval, buffer_id, } => fn_rank_one(state, *buffer_id, interval).map_err(VectoriseError::ProcessingError), - Self::Ranges { buffer_id, ranges } => { + Self::Vectors { buffer_id, ranges } => { let results = do_rank_one(*buffer_id, ranges)?; Self::union(results).map_err(SelectionError) } - Self::MultiRanges { multi_ranges } => { + Self::MultiVectors { multi_ranges } => { let all_ok: Vec<Vec<Self>> = multi_ranges .iter() .map(|(buffer_id, ranges)| do_rank_one(*buffer_id, ranges)) diff --git a/rprt-engine/src/selection_functions/function_character.rs b/rprt-engine/src/selection_functions/function_character.rs index 87bda3d..b4bbf0f 100644 --- a/rprt-engine/src/selection_functions/function_character.rs +++ b/rprt-engine/src/selection_functions/function_character.rs @@ -11,14 +11,14 @@ selection_function! { param_type: usize, niladic: |(param, es): (usize, &EditorState)| { let buf = get_buffer(es, es.current_buffer_id)?; - Ok(Selection::Position { + Ok(Selection::Scalar { buffer_id: es.current_buffer_id, pos: usize::min(param, buf.max_pos()) }) }, - monadic_rank0: |_, buffer_id, pos| Ok(Selection::Position {buffer_id, pos}), + monadic_rank0: |_, buffer_id, pos| Ok(Selection::Scalar {buffer_id, pos}), monadic_rank1: |(param, _), buffer_id, int| Ok( - Selection::Position {buffer_id, pos: usize::min(int.end, *param)} + Selection::Scalar {buffer_id, pos: usize::min(int.end, *param)} ) } @@ -28,11 +28,11 @@ selection_function!( niladic: |_| Err(SFError::NoNiladicForm(";n").into()), monadic_rank0: |(param, es), buffer_id, pos| { let buf = get_buffer(es, buffer_id)?; - Ok(Selection::Position {buffer_id, pos: usize::min(pos+*param, buf.max_pos())}) + Ok(Selection::Scalar {buffer_id, pos: usize::min(pos+*param, buf.max_pos())}) }, monadic_rank1: |(param, es), buffer_id, int| { let buf = get_buffer(es, buffer_id)?; - Ok(Selection::Position {buffer_id, pos: usize::min(int.end+*param, buf.max_pos())}) + Ok(Selection::Scalar {buffer_id, pos: usize::min(int.end+*param, buf.max_pos())}) } ); @@ -41,7 +41,7 @@ selection_function!( param_type: usize, niladic: |(param, es): (usize, &EditorState)| { let buf = get_buffer(es, es.current_buffer_id)?; - Ok(Selection::Position { + Ok(Selection::Scalar { buffer_id: es.current_buffer_id, pos: if buf.max_pos() < param { 0 @@ -50,9 +50,9 @@ selection_function!( }, }) }, - monadic_rank0: |_, buffer_id, pos| Ok(Selection::Position {buffer_id, pos}), + monadic_rank0: |_, buffer_id, pos| Ok(Selection::Scalar {buffer_id, pos}), monadic_rank1: |(param, _), buffer_id, int| Ok( - Selection::Position {buffer_id, pos: usize::min(int.end, *param)} + Selection::Scalar {buffer_id, pos: usize::min(int.end, *param)} ) ); @@ -61,10 +61,10 @@ selection_function!( param_type: usize, niladic: |_| Err(SFError::NoNiladicForm(";'n").into()), monadic_rank0: |(param, _), buffer_id, pos| { - Ok(Selection::Position {buffer_id, pos: if *param<pos {pos - *param} else {0}}) + Ok(Selection::Scalar {buffer_id, pos: if *param<pos {pos - *param} else {0}}) }, monadic_rank1: |(param, _), buffer_id, int| { - Ok(Selection::Position {buffer_id, pos: if *param<int.end {int.end - *param} else {0}}) + Ok(Selection::Scalar {buffer_id, pos: if *param<int.end {int.end - *param} else {0}}) } ); @@ -73,10 +73,10 @@ selection_function!( param_type: usize, niladic: |_| Err(SFError::NoNiladicForm("';n").into()), monadic_rank0: |(param, _), buffer_id, pos| { - Ok(Selection::Position {buffer_id, pos: if *param<pos {pos - *param} else {0}}) + Ok(Selection::Scalar {buffer_id, pos: if *param<pos {pos - *param} else {0}}) }, monadic_rank1: |(param, _), buffer_id, int| { - Ok(Selection::Position {buffer_id, pos: if *param<int.start {int.start - *param} else {0}}) + Ok(Selection::Scalar {buffer_id, pos: if *param<int.start {int.start - *param} else {0}}) } ); diff --git a/rprt-engine/src/selection_functions/function_end.rs b/rprt-engine/src/selection_functions/function_end.rs index 44aab90..75b4c96 100644 --- a/rprt-engine/src/selection_functions/function_end.rs +++ b/rprt-engine/src/selection_functions/function_end.rs @@ -11,36 +11,36 @@ selection_function! { param_type: (), niladic: |(_, es): ((), &EditorState)| { let buf = get_buffer(es, es.current_buffer_id)?; - Ok(Selection::Position { + Ok(Selection::Scalar { buffer_id: es.current_buffer_id, pos: buf.max_pos(), }) }, - monadic_rank0: |_, buffer_id, pos | Ok(Selection::Position { buffer_id, pos }), - monadic_rank1: |_, buffer_id, int | Ok(Selection::Position { buffer_id, pos: int.end }) + monadic_rank0: |_, buffer_id, pos | Ok(Selection::Scalar { buffer_id, pos }), + monadic_rank1: |_, buffer_id, int | Ok(Selection::Scalar { buffer_id, pos: int.end }) } selection_function! { name: reverse_end, param_type: (), niladic: |(_, es): ((), &EditorState)| { - Ok(Selection::Position { + Ok(Selection::Scalar { buffer_id: es.current_buffer_id, pos: 0, }) }, - monadic_rank0: |_, buffer_id, pos | Ok(Selection::Position { buffer_id, pos }), - monadic_rank1: |_, buffer_id, int | Ok(Selection::Position { buffer_id, pos: int.start }) + monadic_rank0: |_, buffer_id, pos | Ok(Selection::Scalar { buffer_id, pos }), + monadic_rank1: |_, buffer_id, int | Ok(Selection::Scalar { buffer_id, pos: int.start }) } selection_function! { name: sequential_end, param_type: (), niladic: |_| Err(SFError::NoNiladicForm(";$").into()), - monadic_rank0: |_, buffer_id, pos| Ok(Selection::Position { buffer_id, pos }), + monadic_rank0: |_, buffer_id, pos| Ok(Selection::Scalar { buffer_id, pos }), monadic_rank1: |(_, es), buffer_id, _| { let buf = get_buffer(es, buffer_id)?; - Ok(Selection::Position { buffer_id, pos: buf.max_pos() }) + Ok(Selection::Scalar { buffer_id, pos: buf.max_pos() }) } } @@ -49,10 +49,10 @@ selection_function! { param_type: (), niladic: |_| Err(SFError::NoNiladicForm(";'$").into()), monadic_rank0: |_, buffer_id, pos| { - Ok(Selection::Position { buffer_id, pos }) + Ok(Selection::Scalar { buffer_id, pos }) }, monadic_rank1: |_, buffer_id, interval| { - Ok(Selection::Position { + Ok(Selection::Scalar { buffer_id, pos: interval.end, }) @@ -64,10 +64,10 @@ selection_function! { param_type: (), niladic: |_| Err(SFError::NoNiladicForm("';$").into()), monadic_rank0: |_, buffer_id, pos| { - Ok(Selection::Position { buffer_id, pos }) + Ok(Selection::Scalar { buffer_id, pos }) }, monadic_rank1: |_, buffer_id, interval| { - Ok(Selection::Position { + Ok(Selection::Scalar { buffer_id, pos: interval.end, }) diff --git a/rprt-engine/src/selection_functions/result_transformation.rs b/rprt-engine/src/selection_functions/result_transformation.rs index 865038c..c150916 100644 --- a/rprt-engine/src/selection_functions/result_transformation.rs +++ b/rprt-engine/src/selection_functions/result_transformation.rs @@ -20,7 +20,7 @@ pub fn complement_transform(es: &EditorState, result: Selection) -> SFResult { if pos + 1 < max_pos { ranges.push(Interval::new(pos + 1, max_pos)); } - Ok(Selection::Ranges { buffer_id, ranges }) + Ok(Selection::Vectors { buffer_id, ranges }) } else { Err(SFError::BufferNotFound(buffer_id)) } @@ -48,7 +48,7 @@ pub fn complement_transform(es: &EditorState, result: Selection) -> SFResult { ranges.push(Interval::new(0, interval.start)); ranges.push(Interval::new(interval.end, max_pos)); } - Ok(Selection::Ranges { buffer_id, ranges }) + Ok(Selection::Vectors { buffer_id, ranges }) } else { Err(SFError::BufferNotFound(buffer_id)) } diff --git a/rprt-engine/src/text.rs b/rprt-engine/src/text.rs new file mode 100644 index 0000000..4db6509 --- /dev/null +++ b/rprt-engine/src/text.rs @@ -0,0 +1,18 @@ +use std::collections::HashMap; + +use crate::buffer::BufferID; + +#[derive(Debug, Clone)] +pub enum Text { + Vector { + buffer_id: BufferID, + content: String, + }, + Tensor { + buffer_id: BufferID, + content: Vec<String>, + }, + Matrix { + multi_ranges: HashMap<BufferID, Vec<String>>, + }, +} |
