Class: Ruby::Rego::Builtins::Regex::GlobIntersection::Intersector

Inherits:
Object
  • Object
show all
Defined in:
lib/ruby/rego/builtins/regex/glob_intersection/intersector.rb

Overview

Recursive intersection engine (gintersect.intersect*). Instance state holds the work budget so the recursion can bail out on pathological input.

Instance Method Summary collapse

Constructor Details

#initializeIntersector

Returns a new instance of Intersector.



17
18
19
# File 'lib/ruby/rego/builtins/regex/glob_intersection/intersector.rb', line 17

def initialize
  @work = 0
end

Instance Method Details

#intersect_normal(lhs, rhs) ⇒ Object

Walks both globs while unflagged tokens match; defers to the special handlers once a flagged token appears.



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/ruby/rego/builtins/regex/glob_intersection/intersector.rb', line 23

def intersect_normal(lhs, rhs)
  index1 = 0
  index2 = 0
  while index1 < lhs.length && index2 < rhs.length
    charge_work
    token_lhs = lhs[index1]
    token_rhs = rhs[index2]
    if token_lhs.flagged? || token_rhs.flagged?
      return intersect_special(lhs[index1..] || [],
                               rhs[index2..] || [])
    end
    return false unless GlobIntersection.match?(token_lhs, token_rhs)

    index1 += 1
    index2 += 1
  end
  index1 == lhs.length && index2 == rhs.length
end