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

Remove EndOfFileTrivia and always collect trivia after top-level parsing #733

Merged
merged 8 commits into from
Jan 12, 2024

Conversation

Xanewok
Copy link
Contributor

@Xanewok Xanewok commented Jan 9, 2024

Checks boxes in #640 #638

This adapts ParserFunction to always attempt parsing the leading trivia after we had a succesful match. This has a nice side benefit of not overwriting tokens that would allow for more progress when collecting the final trivia (unlike previous [AttemptedParseRule, EndOfFileTrivia] sequence).

I'm not so happy with the resulting tree shape, however; IMO we should either:

  1. return a "tree" that has both parents - the first one being the expected parsed rule node but also the second parent being the "leading trivia"
  2. or at least introduce a notion of a virtual EndOfFile token that this final end-of-file trivia can belong to.

Otherwise, a lone, final LeadingTrivia child belonging to the rule node seems misplaced and it's not intuitive for me to find the remaining trivia in that place. I'm open for other suggestions!

@Xanewok Xanewok requested a review from a team as a code owner January 9, 2024 14:03
Copy link

changeset-bot bot commented Jan 9, 2024

⚠️ No Changeset found

Latest commit: 206dc3f

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

Copy link
Contributor

@OmarTawfik OmarTawfik left a comment

Choose a reason for hiding this comment

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

Left a few questions/concerns

@@ -0,0 +1,2 @@
// first
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: are the whitespaces intended here? I wonder if we should update the name of the test if so.

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 wanted to say that only a single comment is collected from the two; I've changed this to only_until_newline to better convey the meaning that we should only collect... well, until the newline, as part of the trailing trivia.

@OmarTawfik OmarTawfik self-requested a review January 11, 2024 18:25
@Xanewok Xanewok added this pull request to the merge queue Jan 12, 2024
Merged via the queue into NomicFoundation:main with commit 954a236 Jan 12, 2024
1 check passed
@Xanewok Xanewok deleted the collect-remaining-trivia branch January 12, 2024 02:23
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.

3 participants