Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Attempt to implement comments parsing for deserialize #93

Merged
merged 7 commits into from May 17, 2022

Conversation

jollm
Copy link
Contributor

@jollm jollm commented May 15, 2022

This change attempts to handle the following case:

"If a ; character is encountered outside of a string, that character
and all subsequent characters to the next newline should be ignored."

as described in https://github.com/edn-format/edn#comments

This change attempts to handle the following case:

"If a ; character is encountered outside of a string, that character
and all subsequent characters to the next newline should be ignored."

as described in https://github.com/edn-format/edn#comments
Copy link
Collaborator

@naomijub naomijub left a comment

Choose a reason for hiding this comment

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

Nice works
Thank you for the PR.

@@ -397,6 +426,10 @@ fn read_map(chars: &mut std::iter::Enumerate<std::str::Chars>) -> Result<Edn, Er
loop {
match chars.next() {
Some((_, '}')) => return Ok(Edn::Map(Map::new(res))),
Some((_, ';')) => {
read_comment(chars)?;
()
Copy link
Collaborator

Choose a reason for hiding this comment

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

You don't need () here (Rust will interpret a line ending in ; as ().

Copy link
Collaborator

Choose a reason for hiding this comment

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

I do think this expression is not necessary, as it is already being considered in parse

Copy link
Contributor Author

Choose a reason for hiding this comment

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

thanks for the tip on that!, I'll fix all of those similar cases

the top level parse doesn't catch inside a map, vec, set, etc., so if i comment this line the following test fails (from line 852):
test deserialize::parse::test::parse_comment_inside_map ... FAILED

@@ -13,6 +13,14 @@ pub(crate) fn parse(
Some((_, '(')) => read_list(chars)?,
Some((_, '#')) => tagged_or_set(chars)?,
Some((_, '{')) => read_map(chars)?,
Some((_, ';')) => {
let cmt = read_comment(chars)?;
match chars.next() {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Considering read_comment returns Edn::Empty and the functions receives a mutable chars, I don't think this match is necessary

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is for the case where the only thing existing is a comment (tests starting on line 815) (fails without match). Normally the return from read_comment is ignored in favor of whatever the next call to parse returns. Your comment made me realize that an attempt to deserialize an empty or whitespace only string will fail instead of return Edn::Empty, so it would be surprising for comment to behave differently. For now I will make both return Edn::Empty, but the other option is to have both fail..

src/deserialize/parse.rs Outdated Show resolved Hide resolved
src/deserialize/parse.rs Outdated Show resolved Hide resolved
src/deserialize/parse.rs Outdated Show resolved Hide resolved
src/deserialize/parse.rs Outdated Show resolved Hide resolved
src/deserialize/parse.rs Outdated Show resolved Hide resolved
src/deserialize/parse.rs Show resolved Hide resolved
@naomijub
Copy link
Collaborator

@evaporei Do you think we need a type Edn::Comment for serialization purposes?

@naomijub
Copy link
Collaborator

@jollm I noticed the circleCI hasn't executed. You need to go to your fork circle CI and enable it for this project

@codecov-commenter
Copy link

codecov-commenter commented May 15, 2022

Codecov Report

Merging #93 (e21a68e) into master (ac3f2c5) will increase coverage by 0.86%.
The diff coverage is 98.35%.

@@            Coverage Diff             @@
##           master      #93      +/-   ##
==========================================
+ Coverage   84.47%   85.33%   +0.86%     
==========================================
  Files          11       11              
  Lines        1977     2135     +158     
==========================================
+ Hits         1670     1822     +152     
- Misses        307      313       +6     
Impacted Files Coverage Δ
src/deserialize/parse.rs 96.03% <98.35%> (+0.70%) ⬆️
src/serialize/mod.rs 85.03% <0.00%> (-1.03%) ⬇️
src/edn/mod.rs 74.60% <0.00%> (-0.14%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update ac3f2c5...e21a68e. Read the comment docs.

jollm added 2 commits May 15, 2022 00:37
- Return Edn::Empty for empty, whitespace only, and comment only
  strings.
- Fix ; is implied ()
- Use compact lazy iterator expression to read comments
- Add tests for empty and whitespace only cases
- Add a test for literal whitespace ending comment instead of \n
- Add test for string ending in multiple new lines
@jollm jollm requested a review from naomijub May 15, 2022 08:10
@jollm
Copy link
Contributor Author

jollm commented May 15, 2022

The latest diff is smaller and I hope cleaner. It avoids checking for comments and whitespace at inner levels.

@naomijub
Copy link
Collaborator

I promise to review again tomorrow

@naomijub
Copy link
Collaborator

Dont forget to enable your circle CI for this project https://app.circleci.com/pipelines/github/jollm/edn-rs

@jollm
Copy link
Contributor Author

jollm commented May 15, 2022

"Commas , are also considered whitespace, other than within strings."
from https://github.com/edn-format/edn#general-considerations

This simplifies inner parsing levels, no longer having to check for
commas.
@naomijub naomijub merged commit 4455d77 into edn-rs:master May 17, 2022
@naomijub naomijub mentioned this pull request May 17, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants