Skip to content

Introduce RawTokenSyntax(kind:, tokenText:, ...) for a convenient way to create a token without any trivia #839

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

Merged
merged 1 commit into from
Oct 4, 2022

Conversation

akyrtzi
Copy link
Contributor

@akyrtzi akyrtzi commented Sep 25, 2022

This allows the parser to consistently use the RawSyntaxData.ParsedToken form for parsed tokens, instead of RawSyntaxData.MaterializedToken.

@akyrtzi akyrtzi requested a review from ahoppen as a code owner September 25, 2022 21:35
@akyrtzi
Copy link
Contributor Author

akyrtzi commented Sep 25, 2022

@swift-ci Please test

@CodaFi
Copy link
Contributor

CodaFi commented Sep 26, 2022

This looks fine. Curious why we don't just default the two parameters of the existing initializer to []?

@akyrtzi
Copy link
Contributor Author

akyrtzi commented Sep 26, 2022

This looks fine. Curious why we don't just default the two parameters of the existing initializer to []?

My motivation was to use RawSyntax.parsedToken() for these parsed expressions as well and keep RawSyntax.makeMaterializedToken() for programmatic creations.

Alternatively, in RawSyntax(kind:, text:...) I could check whether leadingTriviaPieces and trailingTriviaPieces are empty and conditionally use RawSyntax.parsedToken() in such a case (otherwise use RawSyntax.makeMaterializedToken()), WDTY?

@CodaFi
Copy link
Contributor

CodaFi commented Sep 27, 2022

Makes sense. Thanks!

…:, text:, ...)`

Also if the trivias are empty use `RawSyntax.parsedToken()`.
This allows the parser to consistently use the `RawSyntaxData.ParsedToken` form for parsed tokens,
instead of `RawSyntaxData.MaterializedToken`.
@akyrtzi akyrtzi force-pushed the pr/created-parsed-tokentext branch from 5130bf7 to 60bd837 Compare September 27, 2022 19:28
@akyrtzi
Copy link
Contributor Author

akyrtzi commented Sep 27, 2022

@swift-ci Please test

@akyrtzi
Copy link
Contributor Author

akyrtzi commented Sep 27, 2022

See updated commit.

@akyrtzi
Copy link
Contributor Author

akyrtzi commented Sep 30, 2022

Is this good to go? 🙏

@akyrtzi akyrtzi requested a review from rintaro October 3, 2022 18:03
@rintaro
Copy link
Member

rintaro commented Oct 4, 2022

Curious why we want to use only ParsedToken from parser? I failed to see a disadvantage using MaterializedToken.

@akyrtzi
Copy link
Contributor Author

akyrtzi commented Oct 4, 2022

ParsedToken is a much simpler structure than MaterializedToken (essentially just a text buffer + kind) so way easier to experiment with encoding it in alternative storage, like a content addressable storage system.

@rintaro
Copy link
Member

rintaro commented Oct 4, 2022

Interesting.

I wondered because we consider the internal structure of RawSyntax an implementation detail, and as long as it's wrapped with RawSyntaxData, the smaller footprint (MemoryLayout.size) wouldn't be a benefit of using ParsedToken.
I'm OK with this change, but please just be aware that the structure might change, in fact we have a plan to add some flags (hasError etc.) to ParsedToken in the (near) future.

@akyrtzi akyrtzi merged commit 70eaab1 into swiftlang:main Oct 4, 2022
@akyrtzi akyrtzi deleted the pr/created-parsed-tokentext branch October 4, 2022 16:57
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