Module: Regexp::Syntax
- Defined in:
- lib/regexp_parser/syntax/token.rb,
lib/regexp_parser/syntax.rb,
lib/regexp_parser/syntax/any.rb,
lib/regexp_parser/syntax/base.rb,
lib/regexp_parser/syntax/token.rb,
lib/regexp_parser/syntax/token/keep.rb,
lib/regexp_parser/syntax/token/meta.rb,
lib/regexp_parser/syntax/token/group.rb,
lib/regexp_parser/syntax/token/anchor.rb,
lib/regexp_parser/syntax/token/escape.rb,
lib/regexp_parser/syntax/token/virtual.rb,
lib/regexp_parser/syntax/version_lookup.rb,
lib/regexp_parser/syntax/token/assertion.rb,
lib/regexp_parser/syntax/token/quantifier.rb,
lib/regexp_parser/syntax/token/conditional.rb,
lib/regexp_parser/syntax/token/posix_class.rb,
lib/regexp_parser/syntax/token/backreference.rb,
lib/regexp_parser/syntax/token/character_set.rb,
lib/regexp_parser/syntax/token/character_type.rb,
lib/regexp_parser/syntax/token/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: Token
Classes: Any, Base, InvalidVersionNameError, NotImplementedError, SyntaxError, UnknownSyntaxNameError, V1_8_6, V1_9_1, V1_9_3, V2_0_0, V2_2_0, V2_3_0, V2_4_0, V2_4_1, V2_5_0, V2_6_0, V2_6_2, V2_6_3, V3_1_0, V3_2_0
Constant Summary
collapse
- CURRENT =
Regexp::Syntax.for("ruby/#{RUBY_VERSION}")
- VERSION_FORMAT =
'\Aruby/\d+\.\d+(\.\d+)?\z'
- VERSION_REGEXP =
/#{VERSION_FORMAT}/
- VERSION_CONST_REGEXP =
/\AV\d+_\d+(?:_\d+)?\z/
Class Method Summary
collapse
Class Method Details
.comparable(name) ⇒ Object
61
62
63
64
|
# File 'lib/regexp_parser/syntax/version_lookup.rb', line 61
def comparable(name)
Gem::Version.new((name.to_s.scan(/\d+/) << 99).join('.'))
end
|
.const_missing(const_name) ⇒ Object
44
45
46
47
48
49
|
# 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) ⇒ Object
51
52
53
54
55
|
# 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) ⇒ Object
Returns the syntax specification class for the given syntax version name. The special names βanyβ and β*β return Syntax::Any.
22
23
24
|
# File 'lib/regexp_parser/syntax/version_lookup.rb', line 22
def for(name)
(@alias_map ||= {})[name] ||= version_class(name)
end
|
.new(name) ⇒ Object
26
27
28
29
30
|
# 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 ⇒ Object
57
58
59
|
# 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) ⇒ Boolean
32
33
34
|
# 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) ⇒ Object
36
37
38
39
40
41
42
|
# 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
|