Skip to content
This repository has been archived by the owner on Sep 12, 2018. It is now read-only.

Ensure printing/parsing edn strings is isomorphic #241

Merged
merged 3 commits into from
Feb 4, 2017

Conversation

victorporof
Copy link
Contributor

@victorporof victorporof commented Feb 3, 2017

Fixes #240

Copy link
Member

@ncalexan ncalexan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great tests! I have one substantive comment about commas that I think we should all agree on.

@@ -98,17 +98,17 @@ pub keyword -> Value =
}

pub list -> Value =
"(" v:(value)* ")" {
"(" __ v:(value)* __ ")" {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, interesting, I thought I'd covered this with

__ v:(nil / boolean / float / bigint / integer / text / keyword / symbol / list / vector / map / set) __ {
but if there are no values, then you need the whitespace. Good catch!

edn/src/types.rs Outdated
@@ -83,8 +83,8 @@ impl Display for Value {
}
Map(ref v) => {
write!(f, "{{")?;
for (key, val) in v {
write!(f, " :{} {}", key, val)?;
for (index, (key, val)) in v.iter().enumerate() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The leading colon is definitely wrong, so good fix there, but generally EDN does not include commas -- they're whitespace. Why would we include commas in Map but not the other container types? Because of the pairing? I'd prefer not to include them, which agrees with Clojure{Script?, although I could be argued down. @rnewman, do you have a strong opinion?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, consider using join here, which is probably more efficient.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll remove the commas

@victorporof
Copy link
Contributor Author

Addressed comments.

@victorporof victorporof merged commit 4d83aaf into rust Feb 4, 2017
@victorporof victorporof deleted the edn-parse-parsed branch February 4, 2017 07:49
@@ -53,6 +53,7 @@ fn test_nil() {

#[test]
fn test_nan() {
assert_eq!(nan("#fNaN").unwrap(), Float(OrderedFloat(f64::NAN)));
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't believe this is correct.

#fNaN is itself a tag, so #fNaN should not match the nan production. Whitespace is required: #f NaN. This test should instead assert that #fNaN does not match nan, right?

@victorporof, am I misreading this change?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good point. In that case, we should explicitly force the /required/ white space.

Copy link
Contributor Author

@victorporof victorporof Feb 5, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@rnewman, makes sense. If that's the case, whitespace should be enforced.

Is that the case for #f +Infinity and #f -Infinity as well though? The reason I made the change in the first place was because #f +Infinity and #f -Infinity wasn't parseable. Wouldn't #f-Infinity have to also be parsed as a tag? Or are tags more picky with what characters are allowed?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've filed #244, let's move the conversation there?

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants