use crate::lower::ir;
use microcad_lang_base::SrcRef;
use microcad_lang_proc_macros::SrcReferrer;
#[derive(Clone, Debug, PartialEq, SrcReferrer)]
pub struct FormatExpression {
pub spec: Option<ir::FormatSpec>,
pub expression: ir::Expression,
src_ref: SrcRef,
}
impl FormatExpression {
pub fn new(spec: Option<ir::FormatSpec>, expression: ir::Expression, src_ref: SrcRef) -> Self {
Self {
src_ref,
spec,
expression,
}
}
}
impl std::fmt::Display for FormatExpression {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
if let Some(spec) = &self.spec {
write!(f, "{{{}:{}}}", spec, self.expression)
} else {
write!(f, "{{{}}}", self.expression)
}
}
}