Skip to content

[Syntax] Fix TriviaPiece.isNewline #2943

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 3 commits into from
Jan 21, 2025
Merged

Conversation

rintaro
Copy link
Member

@rintaro rintaro commented Jan 18, 2025

In Swift, only CR, LF, and CR+LF are considered newline characters. TriviaPiece.isNewline should not return true for VT and FF.

Instead of using Swift.Character.isNewline, introduce TriviaTraits in CodeGeneration, and manually set them for each trivia piece kind.

Also some drive-by cleanups:

  • Eliminate Trivia.swiftCharacters because it was unused.
  • Use String? for Token.characters because string is naturally a collection of characters.
  • Eliminate Trivia.CharactersLen because Trivia.characters.utf8.count is straightforward enough, and it was technically wrong because it returned character count, but not UTF8 byte count.

In Swift, only 'CR', 'LF', and 'CR+LF' are considered newline
characters. `TriviaPiece.isNewline` should not return true for 'VT' and
'FF'.

Instead of using 'Swift.Character.isNewline', introduce 'TriviaTraits' in
CodeGeneration, and manually set them for each trivia piece kind.
Not sure how it was used, but it's not used anymore.
'String' is natually a collection of characters. Eliminate
'Trivia.CharactersLen' because 'Trivia.characters.utf8.count' is
straightforward enough, and it was technically wrong because it returned
character count, but not utf8 byte count.
@rintaro
Copy link
Member Author

rintaro commented Jan 18, 2025

@swift-ci Please test

@rintaro
Copy link
Member Author

rintaro commented Jan 19, 2025

@swift-ci Please test

@rintaro
Copy link
Member Author

rintaro commented Jan 19, 2025

@swift-ci Please test Windows

1 similar comment
@rintaro
Copy link
Member Author

rintaro commented Jan 20, 2025

@swift-ci Please test Windows

@rintaro rintaro enabled auto-merge January 20, 2025 21:42
@rintaro rintaro merged commit da224d8 into swiftlang:main Jan 21, 2025
3 checks passed
@rintaro rintaro deleted the triviapiece-trait branch January 21, 2025 02:34
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.

2 participants