module Regexp::Scanner

def self.scan_options(p, data, ts, te)

like an options run and handle the rest in here.
ambiguity, so we just ask it to find the beginning of what looks
Ragel's regex-based scan of the group options introduced a lot of
def self.scan_options(p, data, ts, te)
  text = text(data, ts, te).first
  options_char, options_length = true, 0
  # Copy while we have option characters. There is no maximum length,
  # as ruby allows things like '(?xxxxxxxxx-xxxxxxxxxxxxx:abc)'.
  negative_options = false
  while options_char
    if data[te + options_length]
      c = data[te + options_length].chr
      if c =~ /[-mixdau]/
        negative_options = true if c == '-'
        raise InvalidGroupOption.new(c, text) if negative_options and
          c =~ /[dau]/
        text << c ; p += 1 ; options_length += 1
      else
        options_char = false
      end
    else
      raise PrematureEndError.new("expression options `#{text}'")
    end
  end
  if data[te + options_length]
    c = data[te + options_length].chr
    if c == ':'
      # Include the ':' in the options text
      text << c ; p += 1 ; options_length += 1
      emit_options(text, ts, te + options_length)
    elsif c == ')'
      # Don't include the closing ')', let group_close handle it.
      emit_options(text, ts, te + options_length)
    else
      # Plain Regexp reports this as 'undefined group option'
      raise ScannerError.new(
        "Unexpected `#{c}' in options sequence, ':' or ')' expected")
    end
  else
    raise PrematureEndError.new("expression options `#{text}'")
  end
  p # return the new value of the data pointer
end