pub mod coverage;
pub mod cross_check;
pub mod extract;
pub mod locate;
pub mod question_frame;
pub mod respects;
pub mod route;
pub mod segment;
pub mod verify;
use turnframe_tasks::StructuralError;
use crate::words::{Span, Words};
pub(crate) fn out_of_range(what: &str, span: Span, words: &Words) -> StructuralError {
let (from, to) = span.shown();
StructuralError::new(
"span_out_of_range",
format!(
"{what}: words {from} to {to} are not in the message, whose words are numbered 1 to {}",
words.len()
),
)
}
pub(crate) fn check_span(what: &str, span: Span, words: &Words) -> Result<(), StructuralError> {
words
.check(span)
.map_err(|_| out_of_range(what, span, words))
}
pub(crate) fn not_one_of(field: &str, value: &str, allowed: &[String]) -> StructuralError {
StructuralError::new(
"not_in_set",
format!(
"`{field}` must be one of: {}; `{value}` is not",
allowed.join(", ")
),
)
}
pub(crate) fn check_one_of(
field: &str,
value: &str,
allowed: &[String],
) -> Result<(), StructuralError> {
if allowed.iter().any(|candidate| candidate == value) {
Ok(())
} else {
Err(not_one_of(field, value, allowed))
}
}