naomijub / edn-rs

[DEPRECATED]: Crate to parse and emit EDN
https://crates.io/crates/edn-rs
MIT License
81 stars 14 forks source link

String with hash sign parsed incorrectly #91

Closed eerohele closed 2 years ago

eerohele commented 2 years ago
println!("{}", Edn::from_str("\"#{}\"").unwrap());

Prints:

"@}"

Expected output:

"#{}"

I'm only getting started with Rust, so my apologies in advance if this is a rookie mistake.

naomijub commented 2 years ago

I'll take a look, due to the way we process the characters we need to replace #{ by @. So the issue makes a lot of sense

naomijub commented 2 years ago

So you want to read a string that contains an empty set or just read a set?

because if it is read a set, you should be using:

#[test]
    fn empty_set() {
        assert_eq!("#{}", format!("{}",Edn::from_str("#{}").unwrap()));
    }

Having said that, this is a bug and I will need time to fix it, because I will probably need to change how we detect sets

eerohele commented 2 years ago

So you want to read a string that contains an empty set or just read a set?

I want to read a string that contains, among other things, a string of Clojure code.

Here's an example input string:

{:token "clj" :code "(reduce conj #{} [1 2 2 3 4])"}

Calling Edn::from_str on that currently yields {:code "(reduce conj @} [1 2 2 3 4])", :token "clj", }.

naomijub commented 2 years ago

PR is on the way https://github.com/naomijub/edn-rs/pull/92 But I have already published the version 0.17.1 so it unblocks you

eerohele commented 2 years ago

Wow, thank you very much for the quick fix, as well as for the great library!