Skip to content

Commit

Permalink
fix printing for keywords
Browse files Browse the repository at this point in the history
  • Loading branch information
arthurpaulino committed Aug 27, 2023
1 parent b53e26c commit c744e4b
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
5 changes: 5 additions & 0 deletions src/symbol.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<A: AsRef<str>>(&self, child: &[A]) -> Self {
let mut path = Vec::with_capacity(self.path.len() + child.len());
Expand Down
11 changes: 10 additions & 1 deletion src/writer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,8 @@ impl<F: LurkField> Write<F> for Expression<F> {
}
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, "\"\""),
Expand Down Expand Up @@ -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::<Fr>::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);
}
}

0 comments on commit c744e4b

Please sign in to comment.