@@ -150,29 +150,50 @@ private func copyCString(_ str: String) -> UnsafePointer<CChar> {
150
150
151
151
/// Interface for libswift.
152
152
///
153
- /// Lex a regular expression literal starting at `inputPtr`, making sure not to
154
- /// lex past `bufferEndPtr`. The pointer at which to resume lexing is returned,
155
- /// or nil if this is not a regex literal. The `errOut` parameter will be set
156
- /// if an error is encountered.
153
+ /// Attempt to lex a regex literal string.
154
+ ///
155
+ /// - Parameters:
156
+ /// - CurPtrPtr: A pointer to the current pointer of lexer, which should be
157
+ /// the start of the literal. This will be advanced to the point
158
+ /// at which the lexer should resume, or will remain the same if
159
+ /// this is not a regex literal.
160
+ /// - BufferEnd: A pointer to the end of the buffer, which should not be lexed
161
+ /// past.
162
+ /// - ErrorOut: If an error is encountered, this will be set to the error
163
+ /// string.
164
+ ///
165
+ /// - Returns: A bool indicating whether lexing was completely erroneous, and
166
+ /// cannot be recovered from, or false if there either was no error,
167
+ /// or there was a recoverable error.
157
168
func libswiftLexRegexLiteral(
158
- _ inputPtr : UnsafePointer < CChar > ? ,
169
+ _ curPtrPtr : UnsafeMutablePointer < UnsafePointer < CChar > ? > ? ,
159
170
_ bufferEndPtr: UnsafePointer < CChar > ? ,
160
171
_ errOut: UnsafeMutablePointer < UnsafePointer < CChar > ? > ?
161
- ) -> UnsafePointer < CChar > ? {
162
- guard let inputPtr = inputPtr, let endPtr = bufferEndPtr else { return nil }
172
+ ) -> /*CompletelyErroneous*/ CBool {
173
+ guard let curPtrPtr = curPtrPtr, let inputPtr = curPtrPtr. pointee,
174
+ let bufferEndPtr = bufferEndPtr
175
+ else {
176
+ fatalError ( " Expected lexing pointers " )
177
+ }
163
178
guard let errOut = errOut else { fatalError ( " Expected error out param " ) }
164
179
165
180
do {
166
- let ( _, _, endPtr) = try lexRegex ( start: inputPtr, end: endPtr)
167
- return endPtr. assumingMemoryBound ( to: CChar . self)
181
+ let ( _, _, endPtr) = try lexRegex ( start: inputPtr, end: bufferEndPtr)
182
+ curPtrPtr. pointee = endPtr. assumingMemoryBound ( to: CChar . self)
183
+ return false
168
184
} catch let error as LexError {
169
185
if error. kind == . unknownDelimiter {
170
186
// An unknown delimiter should be recovered from, as we may want to try
171
187
// lex something else.
172
- return nil
188
+ return false
173
189
}
174
190
errOut. pointee = copyCString ( " \( error) " )
175
- return error. resumePtr. assumingMemoryBound ( to: CChar . self)
191
+ curPtrPtr. pointee = error. resumePtr. assumingMemoryBound ( to: CChar . self)
192
+
193
+ // For now, treat every error as unrecoverable.
194
+ // TODO: We should ideally be able to recover from a regex with missing
195
+ // closing delimiters, which would help with code completion.
196
+ return true
176
197
} catch {
177
198
fatalError ( " Should be a LexError " )
178
199
}
0 commit comments