regexp_parser 2.13.1 → 2.13.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -12,22 +12,15 @@ module Regexp::Syntax
12
12
  include Regexp::Syntax::Token
13
13
 
14
14
  class << self
15
- attr_accessor :features
15
+ attr_accessor :features, :added_features, :removed_features
16
16
 
17
17
  # automatically inherit features through the syntax class hierarchy
18
18
  def inherited(subclass)
19
19
  super
20
+ # a min target of Ruby 2.6 would allow `to_h { |k, v| [k, v.dup] }`
20
21
  subclass.features = features.to_h.map { |k, v| [k, v.dup] }.to_h
21
- end
22
-
23
- def implements(type, tokens)
24
- (features[type] ||= []).concat(tokens)
25
- added_features[type] = tokens
26
- end
27
-
28
- def excludes(type, tokens)
29
- tokens.each { |tok| features[type].delete(tok) }
30
- removed_features[type] = tokens
22
+ subclass.added_features = {}
23
+ subclass.removed_features = {}
31
24
  end
32
25
 
33
26
  def implements?(type, token)
@@ -45,14 +38,6 @@ module Regexp::Syntax
45
38
  end
46
39
  alias :check! :implements!
47
40
 
48
- def added_features
49
- @added_features ||= {}
50
- end
51
-
52
- def removed_features
53
- @removed_features ||= {}
54
- end
55
-
56
41
  def normalize(type, token)
57
42
  case type
58
43
  when :group
@@ -64,6 +49,24 @@ module Regexp::Syntax
64
49
  end
65
50
  end
66
51
 
52
+ def freeze_features
53
+ freeze_feature_map(features)
54
+ freeze_feature_map(added_features)
55
+ freeze_feature_map(removed_features)
56
+ end
57
+
58
+ def implements(type, tokens)
59
+ (features[type] ||= []).concat(tokens)
60
+ added_features[type] = tokens
61
+ end
62
+
63
+ def excludes(type, tokens)
64
+ tokens.each { |tok| features[type].delete(tok) }
65
+ removed_features[type] = tokens
66
+ end
67
+
68
+ private
69
+
67
70
  def normalize_group(type, token)
68
71
  case token
69
72
  when :named_ab, :named_sq
@@ -95,6 +98,17 @@ module Regexp::Syntax
95
98
  [type, token]
96
99
  end
97
100
  end
101
+
102
+ if defined?(Ractor)
103
+ def freeze_feature_map(map)
104
+ Ractor.make_shareable(map)
105
+ end
106
+ else
107
+ def freeze_feature_map(map)
108
+ map.each_value(&:freeze)
109
+ map.freeze
110
+ end
111
+ end
98
112
  end
99
113
 
100
114
  # TODO: drop this backwards compatibility code in v3.0.0, do `private :new`
@@ -24,7 +24,7 @@ module Regexp::Syntax
24
24
  def for(name)
25
25
  return Regexp::Syntax::Any if ['*', 'any'].include?(name.to_s)
26
26
 
27
- name =~ VERSION_REGEXP || raise(InvalidVersionNameError, name)
27
+ name.to_s =~ VERSION_REGEXP || raise(InvalidVersionNameError, name)
28
28
  version_const_name = "V#{name.to_s.scan(/\d+/).join('_')}"
29
29
  const_get(version_const_name)
30
30
  end
@@ -75,6 +75,8 @@ module Regexp::Syntax
75
75
  constants.select { |const_name| const_name =~ VERSION_CONST_REGEXP }
76
76
  end
77
77
 
78
+ # This method only runs at load-time, otherwise it could interfere with Ractors.
79
+ # https://github.com/ruby/rubygems/issues/9964
78
80
  def comparable(name)
79
81
  # add .99 to treat versions without a patch value as latest patch version
80
82
  Gem::Version.new((name.to_s.scan(/\d+/) << 99).join('.'))
@@ -7,6 +7,8 @@ class Regexp::Syntax::V2_0_0 < Regexp::Syntax::V1_9_3
7
7
  implements :nonproperty, UnicodeProperty::V2_0_0
8
8
  implements :type, CharacterType::Clustered
9
9
 
10
- excludes :property, %i[newline]
11
- excludes :nonproperty, %i[newline]
10
+ unless RUBY_ENGINE == 'jruby'
11
+ excludes :property, %i[newline]
12
+ excludes :nonproperty, %i[newline]
13
+ end
12
14
  end
@@ -11,3 +11,9 @@ require_relative 'syntax/base'
11
11
  require_relative 'syntax/any'
12
12
  require_relative 'syntax/version_lookup'
13
13
  require_relative 'syntax/versions'
14
+
15
+ # Make all versions Ractor-safe
16
+ Regexp::Syntax.constants.each do |const|
17
+ obj = Regexp::Syntax.const_get(const)
18
+ obj.freeze_features if obj.instance_of?(Class) && obj < Regexp::Syntax::Base
19
+ end
@@ -2,6 +2,6 @@
2
2
 
3
3
  class Regexp
4
4
  class Parser
5
- VERSION = '2.13.1'
5
+ VERSION = '2.13.3'
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: regexp_parser
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.13.1
4
+ version: 2.13.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ammar Ali
@@ -49,9 +49,11 @@ files:
49
49
  - lib/regexp_parser/expression/methods/options.rb
50
50
  - lib/regexp_parser/expression/methods/parts.rb
51
51
  - lib/regexp_parser/expression/methods/printing.rb
52
+ - lib/regexp_parser/expression/methods/quantification.rb
52
53
  - lib/regexp_parser/expression/methods/referenced_expressions.rb
53
54
  - lib/regexp_parser/expression/methods/strfregexp.rb
54
55
  - lib/regexp_parser/expression/methods/tests.rb
56
+ - lib/regexp_parser/expression/methods/to_s.rb
55
57
  - lib/regexp_parser/expression/methods/traverse.rb
56
58
  - lib/regexp_parser/expression/quantifier.rb
57
59
  - lib/regexp_parser/expression/sequence.rb
@@ -127,7 +129,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
127
129
  - !ruby/object:Gem::Version
128
130
  version: '0'
129
131
  requirements: []
130
- rubygems_version: 4.0.20
132
+ rubygems_version: 4.0.23
131
133
  specification_version: 4
132
134
  summary: Scanner, lexer, parser for ruby's regular expressions
133
135
  test_files: []