From c744e4bd663a6d315f9ebdca94ae43dbf1782658 Mon Sep 17 00:00:00 2001 From: Arthur Paulino Date: Sun, 27 Aug 2023 16:40:18 -0300 Subject: [PATCH] fix printing for keywords --- src/symbol.rs | 5 +++++ src/writer.rs | 11 ++++++++++- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/src/symbol.rs b/src/symbol.rs index 47bfec4373..e9fbed3061 100644 --- a/src/symbol.rs +++ b/src/symbol.rs @@ -103,6 +103,11 @@ impl Symbol { Self::new_from_vec(path, true) } + #[inline] + pub fn set_as_keyword(&mut self) { + self.keyword = true; + } + /// Creates a new Symbol with the path extended by the given vector of path segments. pub fn extend>(&self, child: &[A]) -> Self { let mut path = Vec::with_capacity(self.path.len() + child.len()); diff --git a/src/writer.rs b/src/writer.rs index 24fb617472..3f22a6c37c 100644 --- a/src/writer.rs +++ b/src/writer.rs @@ -75,7 +75,8 @@ impl Write for Expression { } Key(car, cdr) => { let head = store.fetch_string(car).expect("missing keyword head"); - let tail = store.fetch_key(cdr).expect("missing keyword tail"); + let mut tail = store.fetch_sym(cdr).expect("missing keyword tail"); + tail.set_as_keyword(); write_symbol(w, tail.extend(&[head]), state) } EmptyStr => write!(w, "\"\""), @@ -378,4 +379,12 @@ pub mod test { let res = num.fmt_to_string(&store, initial_lurk_state()); assert_eq!(&res, &"5"); } + + #[test] + fn test_print_keyword() { + let mut store = Store::::default(); + let foo_key_ptr = store.intern_symbol(&Symbol::key_from_vec(vec!["foo".into()])); + let foo_key_str = foo_key_ptr.fmt_to_string(&store, initial_lurk_state()); + assert_eq!(":foo", foo_key_str); + } }