Method: ABNF::Seq#split_recursion

Defined in:
lib/abnf/regexp.rb

#split_recursion(n) ⇒ Object



288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
# File 'lib/abnf/regexp.rb', line 288

def split_recursion(n)
  case @elts.length
  when 0
    [EmptySet, self, EmptySet]
  when 1
    @elts.first.split_recursion(n)
  else
    leftmost_nonrec, leftmost_rest_right = @elts.first.split_left_recursion(n)
    rightmost_nonrec, rightmost_rest_left = @elts.last.split_right_recursion(n)
  rest_middle = Seq.new(*@elts[1...-1])

  if leftmost_rest_right.empty_set?
    [leftmost_nonrec + rest_middle + rightmost_rest_left,
leftmost_nonrec + rest_middle + rightmost_nonrec,
EmptySet]
  elsif rightmost_rest_left.empty_set?
    [EmptySet,
leftmost_nonrec + rest_middle + rightmost_nonrec,
leftmost_rest_right + rest_middle + rightmost_nonrec]
  else
    raise Exception.new("non left/right recursion") # bug
  end
  end
end