   /// Matches the pattern string against the input buffer.
   ///
   /// This returns the position that is matched or npos if there is no match. If
-  /// there is a match, the size of the matched string is returned in \p
-  /// MatchLen.
+  /// there is a match, the range of the match is returned.
   ///
-  /// The \p VariableTable StringMap provides the current values of filecheck
-  /// variables and is updated if this match defines new values.
-  func match(_ buffer : String, _ variableTable : BoxedTable) -> (Int, Int)? {
+  /// The variable table provides the current values of filecheck variables and 
+  /// is updated if this match defines new values.
+  func match(_ buffer : String, _ variableTable : BoxedTable) -> NSRange? {
     var matchLen : Int = 0
     // If this is the EOF pattern, match it immediately.
     if self.type == .EOF {
       matchLen = 0
-      return (buffer.utf8.count, matchLen)
+      return NSRange(location: buffer.utf8.count, length: matchLen)
     }
 
     // If this is a fixed string pattern, just match it now.
     if !self.fixedString.isEmpty {
       matchLen = self.fixedString.utf8.count
       if let b = buffer.range(of: self.fixedString)?.lowerBound {
-        return (buffer.distance(from: buffer.startIndex, to: b), matchLen)
+        return NSRange(location: buffer.distance(from: buffer.startIndex, to: b), length: matchLen)
       }
       return nil
     }

      }

      // Scan to next CHECK-LABEL match, ignoring CHECK-NOT and CHECK-DAG
      guard let (matchLabelPos, matchLabelLen) = checkStr.check(buffer, true, variableTable) else {
        // Immediately bail of CHECK-LABEL fails, nothing else we can do.
        return false
      }

      checkRegion = buffer.substring(to: buffer.index(buffer.startIndex, offsetBy: matchLabelPos + matchLabelLen))
      buffer = buffer.substring(from: buffer.index(buffer.startIndex, offsetBy: matchLabelPos + matchLabelLen))
      j += 1
    }



      // Check each string within the scanned region, including a second check
      // of any final CHECK-LABEL (to verify CHECK-NOT and CHECK-DAG)
      guard let range = checkStrings[i].check(checkRegion, false, variableTable) else {
        failedChecks = true
        i = j
        break
      }

      checkRegion = checkRegion.substring(from: checkRegion.index(checkRegion.startIndex, offsetBy: NSMaxRange(range)))
    }

    if j == e {
