File tree Expand file tree Collapse file tree 3 files changed +15
-6
lines changed Expand file tree Collapse file tree 3 files changed +15
-6
lines changed Original file line number Diff line number Diff line change 88 tests :
99 name : Test
1010 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
1411 soundness :
1512 name : Soundness
1613 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 {
15941594// MARK: Lexing a character in a string literal
15951595
15961596extension Lexer . Cursor {
1597- enum CharacterLex {
1597+ enum CharacterLex : Equatable {
15981598 /// A normal character as it occurs in the source file
15991599 case success( Unicode . Scalar )
16001600
Original file line number Diff line number Diff line change @@ -83,8 +83,8 @@ extension StringSegmentSyntax {
8383 precondition ( !hasError, " appendUnescapedLiteralValue relies on properly parsed literals " )
8484
8585 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 .
8888 output. append ( String ( syntaxText: rawText) )
8989 return
9090 }
@@ -105,6 +105,18 @@ extension StringSegmentSyntax {
105105 )
106106
107107 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+ }
108120 case . success( let scalar) ,
109121 . validatedEscapeSequence( let scalar) :
110122 output. append ( Character ( scalar) )
You can’t perform that action at this time.
0 commit comments