use crate::{Format, FormatConfig, Node, node};
use microcad_lang_parse::ast;
impl Format for ast::Literal {
fn format(&self, f: &FormatConfig) -> Node {
node!(f, self.extras => self.literal)
}
}
impl Format for ast::LiteralKind {
fn format(&self, f: &FormatConfig) -> Node {
match self {
ast::LiteralKind::String(lit) => lit.format(f),
ast::LiteralKind::Bool(lit) => lit.format(f),
ast::LiteralKind::Integer(lit) => lit.format(f),
ast::LiteralKind::Float(lit) => lit.format(f),
ast::LiteralKind::Quantity(lit) => lit.format(f),
ast::LiteralKind::Error(_) => Node::Nil,
}
}
}
impl Format for ast::StringLiteral {
fn format(&self, _: &FormatConfig) -> Node {
format!("\"{}\"", self.content).into()
}
}
impl Format for ast::BoolLiteral {
fn format(&self, _: &FormatConfig) -> Node {
if self.value { "true" } else { "false" }.into()
}
}
impl Format for ast::IntegerLiteral {
fn format(&self, _: &FormatConfig) -> Node {
self.raw.clone().into()
}
}
impl Format for ast::FloatLiteral {
fn format(&self, _: &FormatConfig) -> Node {
self.raw.clone().into()
}
}
impl Format for ast::QuantityLiteral {
fn format(&self, _: &FormatConfig) -> Node {
format!("{}{}", self.raw, self.unit.name).into()
}
}