File tree 3 files changed +15
-6
lines changed
3 files changed +15
-6
lines changed Original file line number Diff line number Diff line change 8
8
tests :
9
9
name : Test
10
10
uses : swiftlang/github-workflows/.github/workflows/swift_package_test.yml@main
11
- with :
12
- # https://github.com/swiftlang/swift-syntax/issues/2992
13
- enable_windows_checks : false
14
11
soundness :
15
12
name : Soundness
16
13
uses : swiftlang/github-workflows/.github/workflows/soundness.yml@main
Original file line number Diff line number Diff line change @@ -1594,7 +1594,7 @@ extension Lexer.Cursor {
1594
1594
// MARK: Lexing a character in a string literal
1595
1595
1596
1596
extension Lexer . Cursor {
1597
- enum CharacterLex {
1597
+ enum CharacterLex : Equatable {
1598
1598
/// A normal character as it occurs in the source file
1599
1599
case success( Unicode . Scalar )
1600
1600
Original file line number Diff line number Diff line change @@ -83,8 +83,8 @@ extension StringSegmentSyntax {
83
83
precondition ( !hasError, " appendUnescapedLiteralValue relies on properly parsed literals " )
84
84
85
85
let rawText = content. rawText
86
- if !rawText. contains ( " \\ " ) {
87
- // Fast path. No escape sequence.
86
+ if !rawText. contains ( where : { $0 == " \\ " || $0 == " \r " } ) {
87
+ // Fast path. No escape sequence that need to be interpreted or line endings that need to be normalized to \n .
88
88
output. append ( String ( syntaxText: rawText) )
89
89
return
90
90
}
@@ -105,6 +105,18 @@ extension StringSegmentSyntax {
105
105
)
106
106
107
107
switch lex {
108
+ case . success( Unicode . Scalar ( " \r " ) ) :
109
+ // Line endings in multi-line string literals are normalized to line feeds even if the source file has a
110
+ // different encoding for new lines.
111
+ output. append ( " \n " )
112
+ if cursor. peek ( ) == " \n " {
113
+ // If we have \r\n, eat the \n as well and leave
114
+ let consumed = cursor. lexCharacterInStringLiteral (
115
+ stringLiteralKind: stringLiteralKind,
116
+ delimiterLength: delimiterLength
117
+ )
118
+ assert ( consumed == . success( Unicode . Scalar ( " \n " ) ) )
119
+ }
108
120
case . success( let scalar) ,
109
121
. validatedEscapeSequence( let scalar) :
110
122
output. append ( Character ( scalar) )
You can’t perform that action at this time.
0 commit comments