Sha256: bcdc8ea9244bc346138a6d44da67d675391d9d78f34af91218e3f43ee2f6a353

Contents?: true

Size: 1.85 KB

Versions: 113

Compression:

Stored size: 1.85 KB

Contents

class Regexp::Scanner
  # Base for all scanner validation errors
  class ValidationError < ScannerError
    # Centralizes and unifies the handling of validation related errors.
    def self.for(type, problem, reason = nil)
      types.fetch(type).new(problem, reason)
    end

    def self.types
      @types ||= {
        backref:      InvalidBackrefError,
        group:        InvalidGroupError,
        group_option: InvalidGroupOption,
        posix_class:  UnknownPosixClassError,
        property:     UnknownUnicodePropertyError,
        sequence:     InvalidSequenceError,
      }
    end
  end

  # Invalid sequence format. Used for escape sequences, mainly.
  class InvalidSequenceError < ValidationError
    def initialize(what = 'sequence', where = '')
      super "Invalid #{what} at #{where}"
    end
  end

  # Invalid group. Used for named groups.
  class InvalidGroupError < ValidationError
    def initialize(what, reason)
      super "Invalid #{what}, #{reason}."
    end
  end

  # Invalid groupOption. Used for inline options.
  # TODO: should become InvalidGroupOptionError in v3.0.0 for consistency
  class InvalidGroupOption < ValidationError
    def initialize(option, text)
      super "Invalid group option #{option} in #{text}"
    end
  end

  # Invalid back reference. Used for name a number refs/calls.
  class InvalidBackrefError < ValidationError
    def initialize(what, reason)
      super "Invalid back reference #{what}, #{reason}"
    end
  end

  # The property name was not recognized by the scanner.
  class UnknownUnicodePropertyError < ValidationError
    def initialize(name, _)
      super "Unknown unicode character property name #{name}"
    end
  end

  # The POSIX class name was not recognized by the scanner.
  class UnknownPosixClassError < ValidationError
    def initialize(text, _)
      super "Unknown POSIX class #{text}"
    end
  end
end

Version data entries

113 entries across 112 versions & 16 rubygems

Version Path
synctera_ruby_sdk-1.1.3 vendor/bundle/ruby/3.2.0/gems/regexp_parser-2.8.1/lib/regexp_parser/scanner/errors/validation_error.rb
synctera_ruby_sdk-1.1.2 vendor/bundle/ruby/3.2.0/gems/regexp_parser-2.8.1/lib/regexp_parser/scanner/errors/validation_error.rb
synctera_ruby_sdk-1.1.1 vendor/bundle/ruby/3.2.0/gems/regexp_parser-2.8.1/lib/regexp_parser/scanner/errors/validation_error.rb
sampero-0.1.0 vendor/bundle/ruby/3.2.0/gems/regexp_parser-2.8.1/lib/regexp_parser/scanner/errors/validation_error.rb
tursodb-0.1.0 vendor/bundle/ruby/3.2.0/gems/regexp_parser-2.8.1/lib/regexp_parser/scanner/errors/validation_error.rb
synctera_ruby_sdk-1.0.0 vendor/bundle/ruby/3.2.0/gems/regexp_parser-2.8.1/lib/regexp_parser/scanner/errors/validation_error.rb
mlh-rubocop-config-1.0.2 vendor/bundle/ruby/3.2.0/gems/regexp_parser-2.8.1/lib/regexp_parser/scanner/errors/validation_error.rb
fablicop-1.10.3 vendor/bundle/ruby/3.2.0/gems/regexp_parser-2.8.1/lib/regexp_parser/scanner/errors/validation_error.rb
scrapbook-0.3.1 vendor/ruby/2.7.0/gems/regexp_parser-2.8.1/lib/regexp_parser/scanner/errors/validation_error.rb
fablicop-1.10.2 vendor/bundle/ruby/3.2.0/gems/regexp_parser-2.8.1/lib/regexp_parser/scanner/errors/validation_error.rb
regexp_parser-2.8.1 lib/regexp_parser/scanner/errors/validation_error.rb
fluent-plugin-google-cloud-logging-on-prem-0.1.0 vendor/ruby/3.1.0/gems/regexp_parser-2.8.0/lib/regexp_parser/scanner/errors/validation_error.rb
regexp_parser-2.8.0 lib/regexp_parser/scanner/errors/validation_error.rb