use super::{Lowerer, list_of, str_of};
use crate::Spanned;
impl Lowerer<'_> {
pub fn explained(&mut self, node: &Spanned, shapes: &[&str], format_speaks: bool) {
if node.get("example").is_some()
|| (format_speaks && node.get("format").is_some())
|| node.get("text").is_some()
{
return;
}
let Some(key) = shapes.iter().find(|k| node.get(k).is_some()) else {
return;
};
self.fail(
node.line,
"TL_66",
format!(
"a rule that declares `{key}` carries an `example` of it: a failure shows the example, and the scaffold writes it"
),
);
}
pub fn one_voice(&mut self, node: &Spanned) {
if let Some(guidance) = str_of(node, "guidance") {
self.one_voice_in(node.line, &guidance, list_of(node, "example"));
}
}
pub fn one_voice_in(
&mut self,
line: usize,
guidance: &str,
examples: impl IntoIterator<Item = String>,
) {
if examples.into_iter().any(|e| guidance.trim() == e.trim()) {
self.fail(
line,
"TL_68",
"`guidance` and `example` hold the same words: guidance says what the example cannot",
);
}
}
pub fn check_bounds(&mut self, line: usize, min: usize, max: Option<usize>) {
if let Some(max) = max
&& min > max
{
self.fail(line, "TL_98", format!("`min` {min} is above `max` {max}"));
}
}
}