js_regex 3.6.0 → 3.7.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 8365bf02c61518e8db07367f1501e31ac8599f709b0cfb80847803d7aa4f17b1
4
- data.tar.gz: f6840ad243194ad82ff589a9cd3f11c3db11b6f2a0f471b50dbb0b3510ebcc08
3
+ metadata.gz: c133491821c27a1ce87f58e59c828e92cef7e1f7f9be99b015e79e55ded6874e
4
+ data.tar.gz: 7ea0268f1e0d8cf48c6a56b635d8189dfb1c2f0ad969902eb0d2a9380d01f03a
5
5
  SHA512:
6
- metadata.gz: 163fdc6a6011088e22804a0bb2174d30c5c053afec187964aac9f6cfaf1dfecd93719a824971f6820b25c54e6ac521e2cd2ca7b5be13463ab7461fb1f1ac794d
7
- data.tar.gz: f0f6efbf118747f79211caec3335b8b34f5f69b69c7d0c78db5b0edb77812a2663dba6bd78e0b074efe2b27d58542c504e18239f78d5b25d40942f21b1486e15
6
+ metadata.gz: 2f31af53ed6fd3213839df7ece799dc951a0f979cf9858cce47ae8151c167de5a5c5464de3d7355782a8bd56f6d142c5d152d4e381ffed9e26f7f51b13c445b1
7
+ data.tar.gz: 46525b2bb74b11189495f831fa860980291c9be05c5d546e7fc1ed1bee335d4cb29059b6ba1ffb008528c78309c4e75e2f9088570d7691565180821b912ffc96
data/lib/js_regex.rb CHANGED
@@ -1,5 +1,3 @@
1
- # frozen_string_literal: true
2
-
3
1
  # JsRegex converts ::Regexp instances to JavaScript.
4
2
  #
5
3
  # Usage:
@@ -10,6 +8,7 @@
10
8
  #
11
9
  class JsRegex
12
10
  require_relative File.join('js_regex', 'conversion')
11
+ require_relative File.join('js_regex', 'error')
13
12
  require_relative File.join('js_regex', 'version')
14
13
  require 'json'
15
14
 
@@ -30,4 +29,15 @@ class JsRegex
30
29
  def to_s
31
30
  "/#{source.empty? ? '(?:)' : source}/#{options}"
32
31
  end
32
+
33
+ def self.new!(ruby_regex, options: nil)
34
+ js_regex = new(ruby_regex, options: options)
35
+ if js_regex.warnings.any?
36
+ raise StandardError.new(
37
+ "Could not fully convert the given regex #{ruby_regex.inspect}:\n" +
38
+ js_regex.warnings.join("\n")
39
+ ).extend(JsRegex::Error)
40
+ end
41
+ js_regex
42
+ end
33
43
  end
@@ -1,5 +1,3 @@
1
- # frozen_string_literal: true
2
-
3
1
  class JsRegex
4
2
  #
5
3
  # This class acts as a facade, passing a regex to the converters.
@@ -9,6 +7,7 @@ class JsRegex
9
7
  class Conversion
10
8
  require 'regexp_parser'
11
9
  require_relative 'converter'
10
+ require_relative 'error'
12
11
  require_relative 'node'
13
12
  require_relative 'second_pass'
14
13
 
@@ -27,6 +26,8 @@ class JsRegex
27
26
  converted_tree = Converter.convert(tree, context)
28
27
  final_tree = SecondPass.call(converted_tree)
29
28
  [final_tree.to_s, context.warnings]
29
+ rescue Regexp::Parser::Error => e
30
+ raise e.extend(JsRegex::Error)
30
31
  end
31
32
 
32
33
  def convert_options(input, custom_options)
@@ -1,8 +1,6 @@
1
- # frozen_string_literal: true
2
-
3
1
  class JsRegex
4
2
  module Converter
5
- Dir[File.join(File.dirname(__FILE__), 'converter', '*.rb')].each do |file|
3
+ Dir[File.join(__dir__, 'converter', '*.rb')].sort.each do |file|
6
4
  require file
7
5
  end
8
6
 
@@ -1,5 +1,3 @@
1
- # frozen_string_literal: true
2
-
3
1
  require_relative 'base'
4
2
 
5
3
  class JsRegex
@@ -1,5 +1,3 @@
1
- # frozen_string_literal: true
2
-
3
1
  require_relative 'base'
4
2
  require_relative 'group_converter'
5
3
 
@@ -1,5 +1,3 @@
1
- # frozen_string_literal: true
2
-
3
1
  require_relative 'base'
4
2
 
5
3
  class JsRegex
@@ -1,5 +1,3 @@
1
- # frozen_string_literal: true
2
-
3
1
  class JsRegex
4
2
  module Converter
5
3
  #
@@ -1,5 +1,3 @@
1
- # frozen_string_literal: true
2
-
3
1
  require_relative 'base'
4
2
 
5
3
  class JsRegex
@@ -1,5 +1,3 @@
1
- # frozen_string_literal: true
2
-
3
1
  class JsRegex
4
2
  module Converter
5
3
  #
@@ -1,5 +1,3 @@
1
- # frozen_string_literal: true
2
-
3
1
  require_relative 'base'
4
2
  require_relative 'literal_converter'
5
3
 
@@ -1,5 +1,3 @@
1
- # frozen_string_literal: true
2
-
3
1
  require_relative 'base'
4
2
 
5
3
  class JsRegex
@@ -1,5 +1,3 @@
1
- # frozen_string_literal: true
2
-
3
1
  require_relative 'base'
4
2
 
5
3
  class JsRegex
@@ -1,5 +1,3 @@
1
- # frozen_string_literal: true
2
-
3
1
  require_relative 'base'
4
2
 
5
3
  class JsRegex
@@ -1,5 +1,3 @@
1
- # frozen_string_literal: true
2
-
3
1
  require_relative 'base'
4
2
 
5
3
  class JsRegex
@@ -1,5 +1,3 @@
1
- # frozen_string_literal: true
2
-
3
1
  require_relative 'base'
4
2
  require 'character_set'
5
3
 
@@ -1,5 +1,3 @@
1
- # frozen_string_literal: true
2
-
3
1
  require_relative 'base'
4
2
  require_relative 'escape_converter'
5
3
  require_relative 'type_converter'
@@ -37,9 +35,7 @@ class JsRegex
37
35
 
38
36
  def all_children_directly_compatible?
39
37
  # note that #each_expression is recursive
40
- expression.each_expression do |exp|
41
- return unless child_directly_compatible?(exp)
42
- end
38
+ expression.each_expression.all? { |ch| child_directly_compatible?(ch) }
43
39
  end
44
40
 
45
41
  def child_directly_compatible?(exp)
@@ -1,5 +1,3 @@
1
- # frozen_string_literal: true
2
-
3
1
  require_relative 'base'
4
2
 
5
3
  class JsRegex
@@ -1,5 +1,3 @@
1
- # frozen_string_literal: true
2
-
3
1
  require_relative 'base'
4
2
 
5
3
  class JsRegex
@@ -1,5 +1,3 @@
1
- # frozen_string_literal: true
2
-
3
1
  require_relative 'base'
4
2
 
5
3
  class JsRegex
@@ -0,0 +1,5 @@
1
+ class JsRegex
2
+ # This is mixed into errors, e.g. those thrown by the parser,
3
+ # allowing to `rescue JsRegex::Error`.
4
+ module Error; end
5
+ end
data/lib/js_regex/node.rb CHANGED
@@ -1,11 +1,11 @@
1
- # frozen_string_literal: true
2
-
3
1
  class JsRegex
4
2
  #
5
3
  # Converter#convert result. Represents a branch or leaf node with an optional
6
4
  # quantifier as well as type and reference annotations for SecondPass.
7
5
  #
8
6
  class Node
7
+ require_relative 'error'
8
+
9
9
  attr_reader :children, :quantifier, :reference, :type
10
10
 
11
11
  TYPES = %i[
@@ -49,7 +49,9 @@ class JsRegex
49
49
  when :backref_num, :captured_group, :plain
50
50
  children.join << quantifier.to_s
51
51
  else
52
- raise TypeError, "#{type} must be substituted before stringification"
52
+ raise TypeError.new(
53
+ "#{type} must be substituted before stringification"
54
+ ).extend(JsRegex::Error)
53
55
  end
54
56
  end
55
57
 
@@ -1,5 +1,3 @@
1
- # frozen_string_literal: true
2
-
3
1
  class JsRegex
4
2
  #
5
3
  # After conversion of a full Regexp::Expression tree, this
@@ -61,7 +59,7 @@ class JsRegex
61
59
 
62
60
  def condition_permutations(conditions)
63
61
  (0..(conditions.length)).inject([]) do |arr, n|
64
- arr += conditions.combination(n).to_a
62
+ arr + conditions.combination(n).to_a
65
63
  end
66
64
  end
67
65
 
@@ -1,5 +1,3 @@
1
- # frozen_string_literal: true
2
-
3
1
  class JsRegex
4
- VERSION = '3.6.0'
2
+ VERSION = '3.7.0'
5
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: js_regex
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.6.0
4
+ version: 3.7.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Janosch Müller
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-12-02 00:00:00.000000000 Z
11
+ date: 2021-03-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: character_set
@@ -30,14 +30,14 @@ dependencies:
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: '2.0'
33
+ version: '2.1'
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: '2.0'
40
+ version: '2.1'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: regexp_property_values
43
43
  requirement: !ruby/object:Gem::Requirement
@@ -108,6 +108,34 @@ dependencies:
108
108
  - - "~>"
109
109
  - !ruby/object:Gem::Version
110
110
  version: 0.2.12
111
+ - !ruby/object:Gem::Dependency
112
+ name: gouteur
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - "~>"
116
+ - !ruby/object:Gem::Version
117
+ version: '1.0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - "~>"
123
+ - !ruby/object:Gem::Version
124
+ version: '1.0'
125
+ - !ruby/object:Gem::Dependency
126
+ name: rubocop
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - "~>"
130
+ - !ruby/object:Gem::Version
131
+ version: '1.8'
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - "~>"
137
+ - !ruby/object:Gem::Version
138
+ version: '1.8'
111
139
  description: JsRegex converts Ruby's native regular expressions for JavaScript, taking
112
140
  care of various incompatibilities and returning warnings for unsolvable differences.
113
141
  email:
@@ -135,6 +163,7 @@ files:
135
163
  - lib/js_regex/converter/subexpression_converter.rb
136
164
  - lib/js_regex/converter/type_converter.rb
137
165
  - lib/js_regex/converter/unsupported_token_converter.rb
166
+ - lib/js_regex/error.rb
138
167
  - lib/js_regex/node.rb
139
168
  - lib/js_regex/second_pass.rb
140
169
  - lib/js_regex/version.rb
@@ -157,7 +186,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
157
186
  - !ruby/object:Gem::Version
158
187
  version: '0'
159
188
  requirements: []
160
- rubygems_version: 3.1.2
189
+ rubygems_version: 3.2.3
161
190
  signing_key:
162
191
  specification_version: 4
163
192
  summary: Converts Ruby regexes to JavaScript regexes.