dsl: implement Display for Value

This commit is contained in:
🪞👃🪞 2025-05-13 20:25:44 +03:00
parent faecc2c304
commit 632977a0dc

View file

@ -189,6 +189,21 @@ pub const fn to_digit (c: char) -> DslResult<usize> {
Exp(usize, TokenIter<'source>),
}
impl<'source> std::fmt::Display for Value<'source> {
fn fmt (&self, out: &mut std::fmt::Formatter) -> Result<(), std::fmt::Error> {
write!(out, "{}", match self {
Nil => String::new(),
Err(e) => format!("[error: {e}]"),
Num(n) => format!("{n}"),
Sym(s) => format!("{s}"),
Key(s) => format!("{s}"),
Str(s) => format!("{s}"),
Exp(_, e) => format!("{e:?}"),
});
Ok(())
}
}
impl<'source> Token<'source> {
pub const fn new (
source: &'source str, start: usize, length: usize, value: Value<'source>