@@ -208,14 +208,14 @@ final class Pattern {
208
208
}
209
209
self . addBackrefToRegEx ( varParenNum)
210
210
} else {
211
- variableUses. append ( ( name, regExPattern. characters. count) )
211
+ variableUses. append ( ( name, self . regExPattern. characters. count) )
212
212
}
213
213
continue
214
214
}
215
215
216
216
// Handle [[foo:.*]].
217
217
self . variableDefs [ name] = curParen
218
- regExPattern += " ( "
218
+ self . regExPattern += " ( "
219
219
curParen += 1
220
220
221
221
let ( res, paren) = self . addRegExToRegEx ( matchStr. substring ( from: matchStr. index ( after: ne. lowerBound) ) , curParen)
@@ -224,7 +224,7 @@ final class Pattern {
224
224
return nil
225
225
}
226
226
227
- regExPattern += " ) "
227
+ self . regExPattern += " ) "
228
228
}
229
229
230
230
// Handle fixed string matches.
@@ -240,8 +240,8 @@ final class Pattern {
240
240
241
241
if options. contains ( . matchFullLines) {
242
242
if !options. contains ( . strictWhitespace) {
243
- regExPattern += " * "
244
- regExPattern += " $ "
243
+ self . regExPattern += " * "
244
+ self . regExPattern += " $ "
245
245
}
246
246
}
247
247
}
@@ -276,29 +276,7 @@ final class Pattern {
276
276
return " \( self . lineNumber + offset) "
277
277
}
278
278
279
- /// Matches the pattern string against the input buffer.
280
- ///
281
- /// This returns the position that is matched or npos if there is no match. If
282
- /// there is a match, the range of the match is returned.
283
- ///
284
- /// The variable table provides the current values of filecheck variables and
285
- /// is updated if this match defines new values.
286
- func match( _ buffer : String , _ variableTable : BoxedTable ) -> NSRange ? {
287
- // If this is the EOF pattern, match it immediately.
288
- if self . type == . EOF {
289
- return NSRange ( location: buffer. utf8. count, length: 0 )
290
- }
291
-
292
- // If this is a fixed string pattern, just match it now.
293
- if !self . fixedString. isEmpty {
294
- if let b = buffer. range ( of: self . fixedString) ? . lowerBound {
295
- return NSRange ( location: buffer. distance ( from: buffer. startIndex, to: b) , length: self . fixedString. utf8. count)
296
- }
297
- return nil
298
- }
299
-
300
- // Regex match.
301
-
279
+ func computeRegexToMatch( _ variableTable : BoxedTable ) -> String ? {
302
280
// If there are variable uses, we need to create a temporary string with the
303
281
// actual value.
304
282
var regExToMatch = self . regExPattern
@@ -326,6 +304,35 @@ final class Pattern {
326
304
insertOffset += value. utf8. count
327
305
}
328
306
}
307
+ return regExToMatch
308
+ }
309
+
310
+ /// Matches the pattern string against the input buffer.
311
+ ///
312
+ /// This returns the position that is matched or npos if there is no match. If
313
+ /// there is a match, the range of the match is returned.
314
+ ///
315
+ /// The variable table provides the current values of filecheck variables and
316
+ /// is updated if this match defines new values.
317
+ func match( _ buffer : String , _ variableTable : BoxedTable ) -> NSRange ? {
318
+ // If this is the EOF pattern, match it immediately.
319
+ if self . type == . EOF {
320
+ return NSRange ( location: buffer. utf8. count, length: 0 )
321
+ }
322
+
323
+ // If this is a fixed string pattern, just match it now.
324
+ if !self . fixedString. isEmpty {
325
+ if let b = buffer. range ( of: self . fixedString) ? . lowerBound {
326
+ return NSRange ( location: buffer. distance ( from: buffer. startIndex, to: b) , length: self . fixedString. utf8. count)
327
+ }
328
+ return nil
329
+ }
330
+
331
+ // Regex match.
332
+
333
+ guard let regExToMatch = computeRegexToMatch ( variableTable) else {
334
+ return nil
335
+ }
329
336
330
337
// Match the newly constructed regex.
331
338
guard let r = try ? NSRegularExpression ( pattern: regExToMatch, options: [ ] ) else {
0 commit comments