use std::sync::Arc;
use techy::core::node::NodeRef;
use crate::core::lowering::{
DefaultMark, Lower, LowerCx, LowerError, Lowerer, Lowering, LoweringDecl, LoweringRule,
};
use crate::core::registry::{BuildError, FeatureBuilder};
use crate::lang::Flm;
use crate::stdlib::backends::latex_recomposed::BACKEND;
use super::{ENTRY, LIST, PIECE};
pub fn rule_name(element: &str) -> String {
format!("{element}.lower.latex-recomposed")
}
#[derive(Debug, Default, Clone, Copy)]
pub struct NothingRule;
impl Lower for NothingRule {
fn lower(
&self,
_node: NodeRef<'_, Flm>,
_cx: &mut LowerCx<'_>,
_lw: &mut dyn Lowerer,
) -> Result<Lowering, LowerError> {
Ok(Lowering::Emit(Vec::new()))
}
}
pub(super) fn register(b: &mut FeatureBuilder<'_>) -> Result<(), BuildError> {
b.peer_backend(BACKEND, "the recomposed-LaTeX backend, on which the table of contents writes nothing")?;
for element in [PIECE, LIST, ENTRY] {
b.lowering_rule(
LoweringRule::new(
rule_name(element),
element,
LoweringDecl::new(),
Arc::new(NothingRule),
DefaultMark::OnBackends(vec![BACKEND.into()]),
)
.docs("the table of contents writes nothing in the recomposed LaTeX: LaTeX builds its own"),
)?;
}
Ok(())
}