diff options
| author | tslil <tslil@posteo.de> | 2026-03-21 15:10:05 +0000 |
|---|---|---|
| committer | tslil <tslil@posteo.de> | 2026-03-21 17:28:51 +0000 |
| commit | fb0d0b91bfd45d1911e993ca753d81da5e60f60c (patch) | |
| tree | 258da432a1b00a399d8f3b9afd1f4504f4d20eee /rprt-engine/src | |
| parent | c22cc3b348bdcb446fb0e44070da36fdf6b05800 (diff) | |
fixing evaluation semantics
Diffstat (limited to 'rprt-engine/src')
| -rw-r--r-- | rprt-engine/src/evaluate.rs | 33 |
1 files changed, 30 insertions, 3 deletions
diff --git a/rprt-engine/src/evaluate.rs b/rprt-engine/src/evaluate.rs index f6fee8a..b23c1be 100644 --- a/rprt-engine/src/evaluate.rs +++ b/rprt-engine/src/evaluate.rs @@ -11,6 +11,8 @@ use thiserror::Error; pub enum EvaluationError { #[error("{0}")] SelectionFunctionError(VectoriseError<SFError>), + #[error("Invalid right-only application")] + IROApplication, #[error("Not yet implemented {0}")] UnimplementedError(&'static str), } @@ -21,6 +23,10 @@ pub fn evaluate( left: Option<Selection>, right: Option<Selection>, ) -> Result<StateResult, EvaluationError> { + if left.is_none() && right.is_some() { + return Err(EvaluationError::IROApplication); + }; + match comp { Composite::SelectionFunction { func, @@ -36,8 +42,29 @@ pub fn evaluate( Err(EvaluationError::UnimplementedError("text function")) } Composite::Hook { kind, left, right } => Err(EvaluationError::UnimplementedError("hook")), - Composite::Train2 { f, g } => Err(EvaluationError::UnimplementedError("train2")), - Composite::Train3 { f, g, h } => Err(EvaluationError::UnimplementedError("train3")), - Composite::Group { operations } => Err(EvaluationError::UnimplementedError("group")), + Composite::Train2 { f, g } => { + let (left, mut state) = evaluate(es, *f, left, right)?; + let (sel, more_state) = evaluate(es, *g, Some(left), None)?; + state.extend(more_state); + Ok((sel, state)) + } + Composite::Train3 { f, g, h } => { + let (f_left, mut f_state) = evaluate(es, *f, left.clone(), right.clone())?; + let (g_right, h_state) = evaluate(es, *h, left, right)?; + let (sel, g_state) = evaluate(es, *g, Some(f_left), Some(g_right))?; + f_state.extend(h_state); + f_state.extend(g_state); + Ok((sel, f_state)) + } + Composite::Group { operations } => { + // TODO: does rust have some monadic failure map thing on first failure? + let mut selections = Vec::new(); + let mut states = Vec::new(); + for f in operations { + let (sel, state) = evaluate(es, f, left.clone(), right.clone())?; + selections.extend(sel); + states.extend(state); + } + } } } |
