feat: symbol display

This commit is contained in:
2025-05-05 12:01:49 +08:00
parent b9dcc83c39
commit 6f7ef266a6
3 changed files with 55 additions and 4 deletions

View File

@@ -3,6 +3,7 @@ use std::ops::Deref;
use derive_more::Constructor;
use ecow::EcoString;
use regex::Regex;
#[derive(Clone, Debug, PartialEq, Constructor)]
pub struct Catchable {
@@ -30,7 +31,17 @@ impl<T: Into<EcoString>> From<T> for Symbol {
impl Display for Symbol {
fn fmt(&self, f: &mut Formatter<'_>) -> FmtResult {
write!(f, r#"Sym({})"#, self.0)
if self.normal() {
write!(f, r#""{}""#, self.0)
} else {
write!(f, "{}", self.0)
}
}
}
impl Symbol {
fn normal(&self) -> bool {
!Regex::new(r#"^[a-zA-Z\_][a-zA-Z0-9\_\'\-]*$"#).unwrap().is_match(self)
}
}