File tree Expand file tree Collapse file tree 3 files changed +18
-2
lines changed Expand file tree Collapse file tree 3 files changed +18
-2
lines changed Original file line number Diff line number Diff line change @@ -48,7 +48,7 @@ fileprivate class StringLiteralExpressionIndentationChecker {
48
48
// Only checking tokens on a newline
49
49
return nil
50
50
}
51
- let hasSufficientIndentation = token. tokenView. leadingTrivia { leadingTrivia in
51
+ let hasSufficientIndentation = token. tokenView. leadingTrivia { leadingTrivia -> Bool in
52
52
let indentationStartIndex = leadingTrivia. lastIndex ( where: { $0 == UInt8 ( ascii: " \n " ) || $0 == UInt8 ( ascii: " \r " ) } ) ? . advanced ( by: 1 ) ?? leadingTrivia. startIndex
53
53
return SyntaxText ( rebasing: leadingTrivia [ indentationStartIndex... ] ) . hasPrefix ( expectedIndentation)
54
54
}
Original file line number Diff line number Diff line change @@ -64,6 +64,22 @@ extension RawSyntax: RawSyntaxNodeProtocol {
64
64
}
65
65
}
66
66
67
+ #if swift(<5.8)
68
+ // Cherry-pick this function from SE-0370
69
+ extension Slice {
70
+ @inlinable
71
+ public func initialize< S> (
72
+ from source: S
73
+ ) -> ( unwritten: S . Iterator , index: Index )
74
+ where S: Sequence , Base == UnsafeMutableBufferPointer < S . Element > {
75
+ let buffer = Base ( rebasing: self )
76
+ let ( iterator, index) = buffer. initialize ( from: source)
77
+ let distance = buffer. distance ( from: buffer. startIndex, to: index)
78
+ return ( iterator, startIndex. advanced ( by: distance) )
79
+ }
80
+ }
81
+ #endif
82
+
67
83
@_spi ( RawSyntax)
68
84
public struct RawTokenSyntax : RawSyntaxNodeProtocol {
69
85
public typealias SyntaxType = TokenSyntax
Original file line number Diff line number Diff line change @@ -15,7 +15,7 @@ import XCTest
15
15
@_spi ( RawSyntax) import SwiftParser
16
16
17
17
fileprivate func lex( _ sourceBytes: [ UInt8 ] ) -> [ Lexer . Lexeme ] {
18
- return sourceBytes. withUnsafeBufferPointer { buf in
18
+ return sourceBytes. withUnsafeBufferPointer { ( buf) -> [ Lexer . Lexeme ] in
19
19
var lexemes = [ Lexer . Lexeme] ( )
20
20
for token in Lexer . tokenize ( buf, from: 0 ) {
21
21
lexemes. append ( token)
You can’t perform that action at this time.
0 commit comments