pub mod context;
pub mod vide;
pub mod writer;
use crate::markup::Node;
use std::fmt;
pub use context::{EmitContext, Helpers};
pub use vide::Vide;
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct EmitError {
pub message: String,
pub offset: usize,
pub length: usize,
pub help: Option<String>,
}
impl EmitError {
pub fn new(message: impl Into<String>, offset: usize, length: usize) -> Self {
Self {
message: message.into(),
offset,
length,
help: None,
}
}
pub fn with_help(mut self, help: impl Into<String>) -> Self {
self.help = Some(help.into());
self
}
pub fn maybe_help(mut self, help: Option<String>) -> Self {
self.help = help;
self
}
}
impl fmt::Display for EmitError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "{} (at byte {})", self.message, self.offset)
}
}
impl std::error::Error for EmitError {}
pub trait Backend {
fn name(&self) -> &'static str;
fn emit(&self, node: &Node, context: &EmitContext<'_>) -> Result<String, EmitError>;
}