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

feat: provide span for more nodes #17

Merged
merged 2 commits into from
Nov 30, 2021

Conversation

dsherret
Copy link
Contributor

@dsherret dsherret commented Sep 19, 2021

Several nodes in the tree were missing a span and there were a lot of String properties that would be better represented by SpannedString.

I'm making a code formatter using this crate (seems like a very good parser 🙂) and so knowing all the spans is very important.

Closes #16

@dsherret
Copy link
Contributor Author

dsherret commented Sep 19, 2021

Actually, going to convert to draft. I think all the Strings should be SpannedString.

Edit: Ok, should be good now.

@dsherret dsherret marked this pull request as ready for review September 20, 2021 03:01
@@ -27,6 +27,7 @@ lazy_static = "1.4"

[dev-dependencies]
indoc = "0.3"
pretty_assertions = "0.7.2"
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 will admit that it's a little bit overboard how many spans get tested with this PR, but this makes it a lot more manageable. Perhaps in the future we could make it so that spans can be skipped in some of the assertions.

Copy link
Contributor

Choose a reason for hiding this comment

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

This is fine by me, I'd also like to reduce the test code verbosity eventually but I don't think we need to deal with that now.

@dsherret
Copy link
Contributor Author

dsherret commented Sep 20, 2021

I can't view the circleci output, so not sure why it's failing. Works fine for me locally (my guess would be maybe I used a new rust language feature? Seems like it's on rust 1.42) Edit: Yup, that was it.

@timothyb89
Copy link
Contributor

Hi! At first glance this looks great, though I'll need to circle back for a thorough review.

One quick note, per the organization's code of conduct we do need a DCO sign-off. We'll squash and merge the commit, so assuming you agree to sign off on the DCO, if you add the string to the PR description I think GitHub will copy it into the squash commit's message (or we can copy it over manually on merge, whichever is needed).

@dsherret
Copy link
Contributor Author

dsherret commented Oct 9, 2021

@timothyb89 done! I squashed everything in this PR to a single commit and added that to the message.

Copy link
Contributor

@timothyb89 timothyb89 left a comment

Choose a reason for hiding this comment

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

On the whole, this looks great! I left a couple of small comments but otherwise I like this a lot.

Standardizing on SpannedString hurts ergonomics a bit but ultimately I think it's necessary.

I'd eventually like to figure out something to make the unit tests less verbose, but we don't need that in this PR. Maybe a SpannedString::quoted(offset: usize, content: &str) helper, or maybe something to mock spans where we don't care to rigorously re-validate them in every single comparison? In any case, a problem for another day.

@@ -36,6 +53,67 @@ pub(crate) fn clean_escaped_breaks(s: &str) -> String {
s.replace("\\\n", "")
}

#[derive(Debug, PartialEq, Eq, Clone)]
Copy link
Contributor

Choose a reason for hiding this comment

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

Small nit, this could use a docstring.

src/util.rs Outdated
Comment on lines 131 to 136
impl SpannedString {
pub fn as_str(&self) -> &str {
self.content.as_str()
}
}

Copy link
Contributor

Choose a reason for hiding this comment

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

Now that we'll be using SpannedString everywhere, a couple quick impls would go a long way toward improving our API ergonomics:

impl AsRef<str> for SpannedString {
  fn as_ref(&self) -> &str {
    &self.content
  }
}

impl fmt::Display for SpannedString {
  fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
    self.content.fmt(f)
  }
}

(there's a bunch of other trait impls that might make SpannedString pretend to be a regular str a bit better, but IMO these are the low-hanging fruit)

@dsherret dsherret requested a review from timothyb89 November 16, 2021 22:51
@dsherret
Copy link
Contributor Author

Sorry, I completely forgot about this PR and didn't realize you left some comments. I have resolved them now I think.

Copy link
Contributor

@timothyb89 timothyb89 left a comment

Choose a reason for hiding this comment

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

Thanks! This looks good to me, though ideally I'd like to fish a 2nd approval out of the team (cc @HewlettPackard/parser-rs-committers)

@timothyb89 timothyb89 requested a review from a team November 22, 2021 05:59
Copy link
Member

@spricet spricet left a comment

Choose a reason for hiding this comment

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

lgtm. Looks like we'll need a major version rev?

Nevermind. I see we're still 0.x i'm okay with an unstable minor rev as long as we document the release well

@jonmcquillan jonmcquillan mentioned this pull request Nov 29, 2021
@spricet spricet merged commit 44bf74a into HewlettPackard:master Nov 30, 2021
@dsherret dsherret deleted the span-for-nodes branch December 1, 2021 19:10
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.

[Request] Provide span in all instructions
3 participants