Module: Regexp::Syntax

Included in:
Parser
Defined in:
lib/regexp_parser/syntax/tokens.rb,
lib/regexp_parser/syntax.rb,
lib/regexp_parser/syntax/any.rb,
lib/regexp_parser/syntax/base.rb,
lib/regexp_parser/syntax/tokens.rb,
lib/regexp_parser/syntax/ruby/1.8.rb,
lib/regexp_parser/syntax/ruby/1.9.rb,
lib/regexp_parser/syntax/ruby/2.0.rb,
lib/regexp_parser/syntax/ruby/2.1.rb,
lib/regexp_parser/syntax/ruby/2.2.rb,
lib/regexp_parser/syntax/ruby/2.3.rb,
lib/regexp_parser/syntax/versions.rb,
lib/regexp_parser/syntax/ruby/1.8.6.rb,
lib/regexp_parser/syntax/ruby/1.8.7.rb,
lib/regexp_parser/syntax/ruby/1.9.1.rb,
lib/regexp_parser/syntax/ruby/1.9.2.rb,
lib/regexp_parser/syntax/ruby/1.9.3.rb,
lib/regexp_parser/syntax/ruby/2.0.0.rb,
lib/regexp_parser/syntax/ruby/2.1.0.rb,
lib/regexp_parser/syntax/ruby/2.1.2.rb,
lib/regexp_parser/syntax/ruby/2.1.3.rb,
lib/regexp_parser/syntax/ruby/2.1.4.rb,
lib/regexp_parser/syntax/ruby/2.1.5.rb,
lib/regexp_parser/syntax/ruby/2.1.6.rb,
lib/regexp_parser/syntax/ruby/2.1.7.rb,
lib/regexp_parser/syntax/ruby/2.1.8.rb,
lib/regexp_parser/syntax/ruby/2.1.9.rb,
lib/regexp_parser/syntax/ruby/2.2.0.rb,
lib/regexp_parser/syntax/ruby/2.2.1.rb,
lib/regexp_parser/syntax/ruby/2.2.2.rb,
lib/regexp_parser/syntax/ruby/2.2.3.rb,
lib/regexp_parser/syntax/ruby/2.2.4.rb,
lib/regexp_parser/syntax/ruby/2.2.5.rb,
lib/regexp_parser/syntax/ruby/2.2.6.rb,
lib/regexp_parser/syntax/ruby/2.3.0.rb,
lib/regexp_parser/syntax/ruby/2.3.1.rb,
lib/regexp_parser/syntax/ruby/2.3.2.rb,
lib/regexp_parser/syntax/ruby/2.3.3.rb,
lib/regexp_parser/syntax/ruby/2.1.10.rb,
lib/regexp_parser/syntax/tokens/keep.rb,
lib/regexp_parser/syntax/tokens/meta.rb,
lib/regexp_parser/syntax/tokens/group.rb,
lib/regexp_parser/syntax/tokens/anchor.rb,
lib/regexp_parser/syntax/tokens/escape.rb,
lib/regexp_parser/syntax/tokens/backref.rb,
lib/regexp_parser/syntax/tokens/assertion.rb,
lib/regexp_parser/syntax/tokens/quantifier.rb,
lib/regexp_parser/syntax/tokens/conditional.rb,
lib/regexp_parser/syntax/tokens/character_set.rb,
lib/regexp_parser/syntax/tokens/character_type.rb,
lib/regexp_parser/syntax/tokens/unicode_property.rb

Overview

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

Defined Under Namespace

Modules: Ruby, Token Classes: Any, Base, InvalidVersionNameError, NotImplementedError, SyntaxError, UnknownSyntaxNameError

Constant Summary collapse

VERSION_FORMAT =
'\Aruby/\d+\.\d+(\.\d+)?\z'
VERSION_REGEXP =
/#{VERSION_FORMAT}/
VERSIONS =
[
  # Ruby 1.8.x (NOTE: 1.8.6 is no longer a supported runtime,
  # but its regex features are still recognized.)
  'ruby/1.8.6',
  'ruby/1.8.7',

  # alias for the latest 1.8 implementation
  'ruby/1.8',

  # Ruby 1.9.x
  'ruby/1.9.1',
  'ruby/1.9.2',
  'ruby/1.9.3',

  # alias for the latest 1.9 implementation
  'ruby/1.9',

  # Ruby 2.0.x
  'ruby/2.0.0',

  # alias for the latest 2.0 implementations
  'ruby/2.0',

  # Ruby 2.1.x
  'ruby/2.1.0',
  'ruby/2.1.2',
  'ruby/2.1.3',
  'ruby/2.1.4',
  'ruby/2.1.5',
  'ruby/2.1.6',
  'ruby/2.1.7',
  'ruby/2.1.8',
  'ruby/2.1.9',
  'ruby/2.1.10',

  # alias for the latest 2.1 implementations
  'ruby/2.1',

  # Ruby 2.2.x
  'ruby/2.2.0',
  'ruby/2.2.1',
  'ruby/2.2.2',
  'ruby/2.2.3',
  'ruby/2.2.4',
  'ruby/2.2.5',
  'ruby/2.2.6',

  # alias for the latest 2.2 implementations
  'ruby/2.2',

  # Ruby 2.3.x
  'ruby/2.3.0',
  'ruby/2.3.1',
  'ruby/2.3.2',
  'ruby/2.3.3',

  # alias for the latest 2.3 implementation
  'ruby/2.3',
]

Class Method Summary collapse

Class Method Details

.new(name) ⇒ Object

Loads and instantiates an instance of the syntax specification class for the given syntax version name. The special names β€˜any’ and β€˜*’ return an instance of Syntax::Any.



32
33
34
35
36
37
38
39
# File 'lib/regexp_parser/syntax.rb', line 32

def self.new(name)
  return Regexp::Syntax::Any.new if
    ['*', 'any'].include?( name.to_s )

  raise UnknownSyntaxNameError.new(name) unless supported?(name)

  version_class(name).new
end

.supported?(name) ⇒ Boolean

Returns:

  • (Boolean)


41
42
43
# File 'lib/regexp_parser/syntax.rb', line 41

def self.supported?(name)
  VERSIONS.include?(name)
end

.version_class(version) ⇒ Object



45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/regexp_parser/syntax.rb', line 45

def self.version_class(version)
  raise InvalidVersionNameError.new(version) unless
    version =~ VERSION_REGEXP

  version_const_name = version.scan(/\d+/).join

  const_name = "Regexp::Syntax::Ruby::V#{version_const_name}"

  if RUBY_VERSION >= '2.0.0'
    Kernel.const_get(const_name)
  else
    Object.module_eval(const_name, __FILE__, __LINE__)
  end
end