regexp_parser 2.12.0 → 2.13.0

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.
@@ -22,7 +22,11 @@ module Regexp::Syntax
22
22
  # Returns the syntax specification class for the given syntax
23
23
  # version name. The special names 'any' and '*' return Syntax::Any.
24
24
  def for(name)
25
- (@alias_map ||= {})[name] ||= version_class(name)
25
+ return Regexp::Syntax::Any if ['*', 'any'].include?(name.to_s)
26
+
27
+ name =~ VERSION_REGEXP || raise(InvalidVersionNameError, name)
28
+ version_const_name = "V#{name.to_s.scan(/\d+/).join('_')}"
29
+ const_get(version_const_name)
26
30
  end
27
31
 
28
32
  def new(name)
@@ -31,25 +35,36 @@ module Regexp::Syntax
31
35
  self.for(name)
32
36
  end
33
37
 
34
- def supported?(name)
35
- name =~ VERSION_REGEXP && comparable(name) >= comparable('1.8.6')
38
+ def version_class(name)
39
+ warn 'Regexp::Syntax.version_class is deprecated in favor of Regexp::Syntax.for. '\
40
+ 'It will be removed in regexp_parser v3.0.0.'
41
+ self.for(name)
36
42
  end
37
43
 
38
- def version_class(version)
39
- return Regexp::Syntax::Any if ['*', 'any'].include?(version.to_s)
40
-
41
- version =~ VERSION_REGEXP || raise(InvalidVersionNameError, version)
42
- version_const_name = "V#{version.to_s.scan(/\d+/).join('_')}"
43
- const_get(version_const_name) || raise(UnknownSyntaxNameError, version)
44
+ def supported?(name)
45
+ name =~ VERSION_REGEXP && comparable(name) >= comparable('1.8.6')
44
46
  end
45
47
 
46
48
  def const_missing(const_name)
47
49
  if const_name =~ VERSION_CONST_REGEXP
48
- return fallback_version_class(const_name)
50
+ return set_fallback_version_class(const_name) ||
51
+ raise(UnknownSyntaxNameError, const_name)
49
52
  end
50
53
  super
51
54
  end
52
55
 
56
+ def set_fallback_version_class(const_name)
57
+ return unless (klass = fallback_version_class(const_name))
58
+
59
+ if constants.count { |c| c =~ VERSION_REGEXP } > 1000
60
+ raise Regexp::Syntax::SyntaxError,
61
+ "Unexpected high number of syntax versions defined. "\
62
+ "Do not accept unfiltered user input as Regexp::Syntax version."
63
+ end
64
+ const_set(const_name, klass)
65
+ klass
66
+ end
67
+
53
68
  def fallback_version_class(version)
54
69
  sorted = (specified_versions + [version]).sort_by { |ver| comparable(ver) }
55
70
  index = sorted.index(version)
@@ -2,6 +2,6 @@
2
2
 
3
3
  class Regexp
4
4
  class Parser
5
- VERSION = '2.12.0'
5
+ VERSION = '2.13.0'
6
6
  end
7
7
  end
@@ -1,8 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- $:.unshift File.join(File.dirname(__FILE__), 'lib')
4
-
5
- require 'regexp_parser/version'
3
+ require_relative 'lib/regexp_parser/version'
6
4
 
7
5
  Gem::Specification.new do |spec|
8
6
  spec.name = 'regexp_parser'
@@ -14,8 +12,6 @@ Gem::Specification.new do |spec|
14
12
 
15
13
  spec.metadata['bug_tracker_uri'] = "#{spec.homepage}/issues"
16
14
  spec.metadata['changelog_uri'] = "#{spec.homepage}/blob/master/CHANGELOG.md"
17
- spec.metadata['homepage_uri'] = spec.homepage
18
- spec.metadata['source_code_uri'] = spec.homepage
19
15
  spec.metadata['wiki_uri'] = "#{spec.homepage}/wiki"
20
16
 
21
17
  spec.metadata['rubygems_mfa_required'] = 'true'
@@ -27,10 +23,8 @@ Gem::Specification.new do |spec|
27
23
 
28
24
  spec.require_paths = ['lib']
29
25
 
30
- spec.files = Dir.glob('lib/**/*.{csv,rb,rl}') +
31
- %w[Gemfile Rakefile LICENSE regexp_parser.gemspec]
32
-
33
- spec.platform = Gem::Platform::RUBY
26
+ spec.files = Dir.glob('lib/**/*.{csv,rb}') +
27
+ %w[LICENSE regexp_parser.gemspec]
34
28
 
35
29
  spec.required_ruby_version = '>= 2.0.0'
36
30
  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.12.0
4
+ version: 2.13.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ammar Ali
@@ -18,9 +18,7 @@ executables: []
18
18
  extensions: []
19
19
  extra_rdoc_files: []
20
20
  files:
21
- - Gemfile
22
21
  - LICENSE
23
- - Rakefile
24
22
  - lib/regexp_parser.rb
25
23
  - lib/regexp_parser/error.rb
26
24
  - lib/regexp_parser/expression.rb
@@ -63,14 +61,11 @@ files:
63
61
  - lib/regexp_parser/lexer.rb
64
62
  - lib/regexp_parser/parser.rb
65
63
  - lib/regexp_parser/scanner.rb
66
- - lib/regexp_parser/scanner/char_type.rl
67
64
  - lib/regexp_parser/scanner/errors/premature_end_error.rb
68
65
  - lib/regexp_parser/scanner/errors/scanner_error.rb
69
66
  - lib/regexp_parser/scanner/errors/validation_error.rb
70
67
  - lib/regexp_parser/scanner/properties/long.csv
71
68
  - lib/regexp_parser/scanner/properties/short.csv
72
- - lib/regexp_parser/scanner/property.rl
73
- - lib/regexp_parser/scanner/scanner.rl
74
69
  - lib/regexp_parser/syntax.rb
75
70
  - lib/regexp_parser/syntax/any.rb
76
71
  - lib/regexp_parser/syntax/base.rb
@@ -116,8 +111,6 @@ licenses:
116
111
  metadata:
117
112
  bug_tracker_uri: https://github.com/ammar/regexp_parser/issues
118
113
  changelog_uri: https://github.com/ammar/regexp_parser/blob/master/CHANGELOG.md
119
- homepage_uri: https://github.com/ammar/regexp_parser
120
- source_code_uri: https://github.com/ammar/regexp_parser
121
114
  wiki_uri: https://github.com/ammar/regexp_parser/wiki
122
115
  rubygems_mfa_required: 'true'
123
116
  rdoc_options: []
@@ -134,7 +127,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
134
127
  - !ruby/object:Gem::Version
135
128
  version: '0'
136
129
  requirements: []
137
- rubygems_version: 4.0.3
130
+ rubygems_version: 4.0.20
138
131
  specification_version: 4
139
132
  summary: Scanner, lexer, parser for ruby's regular expressions
140
133
  test_files: []
data/Gemfile DELETED
@@ -1,17 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- source 'https://rubygems.org'
4
-
5
- gemspec
6
-
7
- group :development, :test do
8
- gem 'leto', '~> 2.1'
9
- gem 'rake', '~> 13.1'
10
- gem 'regexp_property_values', '~> 1.5'
11
- gem 'rspec', '~> 3.10'
12
- if RUBY_VERSION.to_f >= 2.7
13
- gem 'benchmark-ips', '~> 2.1'
14
- gem 'gouteur', '~> 1.1'
15
- gem 'rubocop', '>= 1.80.2'
16
- end
17
- end
data/Rakefile DELETED
@@ -1,25 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'bundler'
4
- require 'rubygems'
5
- require 'rubygems/package_task'
6
- require 'rake'
7
- require 'rake/testtask'
8
- require 'rspec/core/rake_task'
9
-
10
- Dir['tasks/**/*.rake'].each { |file| load(file) }
11
-
12
- Bundler::GemHelper.install_tasks
13
-
14
- RSpec::Core::RakeTask.new(:spec)
15
-
16
- task :default => [:'test:full']
17
-
18
- namespace :test do
19
- task full: [:ragel, :spec]
20
- end
21
-
22
- # Add ragel task as a prerequisite for building the gem to ensure that the
23
- # latest scanner code is generated and included in the build.
24
- desc "Runs ragel before building the gem"
25
- task build: :ragel
@@ -1,28 +0,0 @@
1
- %%{
2
- machine re_char_type;
3
-
4
- single_codepoint_char_type = [dDhHsSwW];
5
- multi_codepoint_char_type = [RX];
6
-
7
- char_type_char = single_codepoint_char_type | multi_codepoint_char_type;
8
-
9
- # Char types scanner
10
- # --------------------------------------------------------------------------
11
- char_type := |*
12
- char_type_char {
13
- case text = copy(data, ts-1, te)
14
- when '\d'; emit(:type, :digit, text)
15
- when '\D'; emit(:type, :nondigit, text)
16
- when '\h'; emit(:type, :hex, text)
17
- when '\H'; emit(:type, :nonhex, text)
18
- when '\s'; emit(:type, :space, text)
19
- when '\S'; emit(:type, :nonspace, text)
20
- when '\w'; emit(:type, :word, text)
21
- when '\W'; emit(:type, :nonword, text)
22
- when '\R'; emit(:type, :linebreak, text)
23
- when '\X'; emit(:type, :xgrapheme, text)
24
- end
25
- fret;
26
- };
27
- *|;
28
- }%%
@@ -1,30 +0,0 @@
1
- %%{
2
- machine re_property;
3
-
4
- property_char = [pP];
5
-
6
- property_sequence = property_char . '{' . '^'? (alnum|space|[_\-\.=])+ '}';
7
-
8
- action premature_property_end {
9
- raise PrematureEndError.new('unicode property')
10
- }
11
-
12
- # Unicode properties scanner
13
- # --------------------------------------------------------------------------
14
- unicode_property := |*
15
-
16
- property_sequence < eof(premature_property_end) {
17
- text = copy(data, ts-1, te)
18
- type = (text[1] == 'P') ^ (text[3] == '^') ? :nonproperty : :property
19
-
20
- name = text[3..-2].gsub(/[\^\s_\-]/, '').downcase
21
-
22
- token = self.class.short_prop_map[name] || self.class.long_prop_map[name]
23
- raise ValidationError.for(:property, name) unless token
24
-
25
- self.emit(type, token.to_sym, text)
26
-
27
- fret;
28
- };
29
- *|;
30
- }%%