module Regexp::Syntax

Define the base module and the simplest of tokens.

After loading all the tokens the map is full. Extract all tokens and types into the All and Types constants.

Constants

CURRENT
VERSION_CONST_REGEXP
VERSION_FORMAT
VERSION_REGEXP

Public Instance Methods

comparable(name) click to toggle source
# File lib/regexp_parser/syntax/version_lookup.rb, line 61
def comparable(name)
  # add .99 to treat versions without a patch value as latest patch version
  Gem::Version.new((name.to_s.scan(/\d+/) << 99).join('.'))
end
const_missing(const_name) click to toggle source
Calls superclass method
# File lib/regexp_parser/syntax/version_lookup.rb, line 44
def const_missing(const_name)
  if const_name =~ VERSION_CONST_REGEXP
    return fallback_version_class(const_name)
  end
  super
end
fallback_version_class(version) click to toggle source
# File lib/regexp_parser/syntax/version_lookup.rb, line 51
def fallback_version_class(version)
  sorted = (specified_versions + [version]).sort_by { |ver| comparable(ver) }
  index = sorted.index(version)
  index > 0 && const_get(sorted[index - 1])
end
for(name) click to toggle source

Returns the syntax specification class for the given syntax version name. The special names β€˜any’ and β€˜*’ return Syntax::Any.

# File lib/regexp_parser/syntax/version_lookup.rb, line 22
def for(name)
  (@alias_map ||= {})[name] ||= version_class(name)
end
new(name) click to toggle source
# File lib/regexp_parser/syntax/version_lookup.rb, line 26
def new(name)
  warn 'Regexp::Syntax.new is deprecated in favor of Regexp::Syntax.for. '\
       'It does not return distinct instances and will be removed in v3.0.0.'
  self.for(name)
end
specified_versions() click to toggle source
# File lib/regexp_parser/syntax/version_lookup.rb, line 57
def specified_versions
  constants.select { |const_name| const_name =~ VERSION_CONST_REGEXP }
end
supported?(name) click to toggle source
# File lib/regexp_parser/syntax/version_lookup.rb, line 32
def supported?(name)
  name =~ VERSION_REGEXP && comparable(name) >= comparable('1.8.6')
end
version_class(version) click to toggle source
# File lib/regexp_parser/syntax/version_lookup.rb, line 36
def version_class(version)
  return Regexp::Syntax::Any if ['*', 'any'].include?(version.to_s)

  version =~ VERSION_REGEXP || raise(InvalidVersionNameError, version)
  version_const_name = "V#{version.to_s.scan(/\d+/).join('_')}"
  const_get(version_const_name) || raise(UnknownSyntaxNameError, version)
end