@@ -208,14 +208,14 @@ final class Pattern {
208208 }
209209 self . addBackrefToRegEx ( varParenNum)
210210 } else {
211- variableUses. append ( ( name, regExPattern. characters. count) )
211+ variableUses. append ( ( name, self . regExPattern. characters. count) )
212212 }
213213 continue
214214 }
215215
216216 // Handle [[foo:.*]].
217217 self . variableDefs [ name] = curParen
218- regExPattern += " ( "
218+ self . regExPattern += " ( "
219219 curParen += 1
220220
221221 let ( res, paren) = self . addRegExToRegEx ( matchStr. substring ( from: matchStr. index ( after: ne. lowerBound) ) , curParen)
@@ -224,7 +224,7 @@ final class Pattern {
224224 return nil
225225 }
226226
227- regExPattern += " ) "
227+ self . regExPattern += " ) "
228228 }
229229
230230 // Handle fixed string matches.
@@ -240,8 +240,8 @@ final class Pattern {
240240
241241 if options. contains ( . matchFullLines) {
242242 if !options. contains ( . strictWhitespace) {
243- regExPattern += " * "
244- regExPattern += " $ "
243+ self . regExPattern += " * "
244+ self . regExPattern += " $ "
245245 }
246246 }
247247 }
@@ -276,29 +276,7 @@ final class Pattern {
276276 return " \( self . lineNumber + offset) "
277277 }
278278
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 ? {
302280 // If there are variable uses, we need to create a temporary string with the
303281 // actual value.
304282 var regExToMatch = self . regExPattern
@@ -326,6 +304,35 @@ final class Pattern {
326304 insertOffset += value. utf8. count
327305 }
328306 }
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+ }
329336
330337 // Match the newly constructed regex.
331338 guard let r = try ? NSRegularExpression ( pattern: regExToMatch, options: [ ] ) else {
0 commit comments