feat: symbol display
This commit is contained in:
@@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user