sim_codec_bridge/
render.rs1use sim_kernel::{Error, Expr, Result, Symbol};
2
3use crate::{BridgeBook, BridgePart, render_frame, render_frame_with_prose};
4
5pub fn render_frame_part(book: &BridgeBook, part: &BridgePart) -> Result<String> {
7 render_frame_part_with_prose(book, part, |name, _| {
8 Err(Error::Eval(format!(
9 "BRIDGE prose hole {} requires fenced rendering",
10 name.as_qualified_str()
11 )))
12 })
13}
14
15pub fn render_frame_part_with_prose<F>(
18 book: &BridgeBook,
19 part: &BridgePart,
20 render_prose: F,
21) -> Result<String>
22where
23 F: FnMut(&Symbol, &Expr) -> Result<String>,
24{
25 if part.kind != Symbol::qualified("bridge", "Frame") {
26 return Err(Error::Eval(format!(
27 "BRIDGE fluent rendering requires bridge/Frame, found {}",
28 part.kind
29 )));
30 }
31 let payload = book.frames.validate_payload(&part.payload)?;
32 let spec = book.frames.require_spec(&payload.frame)?;
33 let sentence = if spec
34 .holes
35 .iter()
36 .any(|hole| matches!(hole.kind, crate::FrameHoleKind::Prose))
37 {
38 render_frame_with_prose(spec, &part.payload, render_prose)?
39 } else {
40 render_frame(spec, &part.payload)?
41 };
42 Ok(format!("[{}] {sentence}", part.id.as_qualified_str()))
43}