Skip to content

Commit 2244c53

Browse files
authored
Merge pull request #87 from hamishknight/tweak-interface
2 parents 3568449 + 7353d36 commit 2244c53

File tree

2 files changed

+36
-15
lines changed

2 files changed

+36
-15
lines changed

Sources/_MatchingEngine/Regex/Parse/Mocking.swift

Lines changed: 32 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -150,29 +150,50 @@ private func copyCString(_ str: String) -> UnsafePointer<CChar> {
150150

151151
/// Interface for libswift.
152152
///
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.
157168
func libswiftLexRegexLiteral(
158-
_ inputPtr: UnsafePointer<CChar>?,
169+
_ curPtrPtr: UnsafeMutablePointer<UnsafePointer<CChar>?>?,
159170
_ bufferEndPtr: UnsafePointer<CChar>?,
160171
_ 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+
}
163178
guard let errOut = errOut else { fatalError("Expected error out param") }
164179

165180
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
168184
} catch let error as LexError {
169185
if error.kind == .unknownDelimiter {
170186
// An unknown delimiter should be recovered from, as we may want to try
171187
// lex something else.
172-
return nil
188+
return false
173189
}
174190
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
176197
} catch {
177198
fatalError("Should be a LexError")
178199
}

Sources/_StringProcessing/ConsumerInterface.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -354,27 +354,27 @@ extension Unicode.BinaryProperty {
354354
case .diacratic: // spelling?
355355
return consumeScalarProp(\.isDiacritic)
356356
case .emojiModifierBase:
357-
if #available(macOS 10.12.2, *) {
357+
if #available(macOS 10.12.2, iOS 10.2, tvOS 10.1, watchOS 3.1.1, *) {
358358
return consumeScalarProp(\.isEmojiModifierBase)
359359
} else {
360360
throw unsupported("isEmojiModifierBase on old OSes")
361361
}
362362
case .emojiComponent:
363363
break
364364
case .emojiModifier:
365-
if #available(macOS 10.12.2, *) {
365+
if #available(macOS 10.12.2, iOS 10.2, tvOS 10.1, watchOS 3.1.1, *) {
366366
return consumeScalarProp(\.isEmojiModifier)
367367
} else {
368368
throw unsupported("isEmojiModifier on old OSes")
369369
}
370370
case .emoji:
371-
if #available(macOS 10.12.2, *) {
371+
if #available(macOS 10.12.2, iOS 10.2, tvOS 10.1, watchOS 3.1.1, *) {
372372
return consumeScalarProp(\.isEmoji)
373373
} else {
374374
throw unsupported("isEmoji on old OSes")
375375
}
376376
case .emojiPresentation:
377-
if #available(macOS 10.12.2, *) {
377+
if #available(macOS 10.12.2, iOS 10.2, tvOS 10.1, watchOS 3.1.1, *) {
378378
return consumeScalarProp(\.isEmojiPresentation)
379379
} else {
380380
throw unsupported("isEmojiPresentation on old OSes")

0 commit comments

Comments
 (0)