js_regex 1.0.18 → 1.0.19

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
  SHA1:
3
- metadata.gz: 891029686f8e97bfbd2dcfbc0e7d215fe800514e
4
- data.tar.gz: 18575912265708487a3dc8a83853c88686258430
3
+ metadata.gz: 2429773ea6bbeb5d7eed4ffa01742f0cecc4df77
4
+ data.tar.gz: b5b3d8380986a844cf8577cf76a55ec846fc8eb6
5
5
  SHA512:
6
- metadata.gz: ceb4dbf1e706c5e80bce3f3e63565b00eaff0d11b0f64fca69a37290dd557fa0bc151b9edff06f8af1d81acabcd1a9130c7436d333116cd71be43fc564ff0b80
7
- data.tar.gz: 0f2578b28458d272aefe9f8cbe0a3cd3e27851b1b12e17fae69f1f805ac2f72b2e5ae882296f2593bc10cd930a3431628c2c4f0b712351620d9087251a092950
6
+ metadata.gz: 2728a8ceb9ee272aabd1d30b6bd2c16154abc104f1c7cd3f2da7bc357582773c6d68afea5cc3a5844cae49bf7090ec3da6eacca86252b0543406533120b264fe
7
+ data.tar.gz: 25d2e9dd9fbeda9cf624200565bca5e6603fd082549ecc0dab790fa3fb979eb03cab4105c15156123569dad079ac3ca31afe76e532a29d0f0161b60e8d95bc2f
@@ -9,13 +9,17 @@ class JsRegex
9
9
  require 'regexp_parser'
10
10
  Dir[File.join(File.dirname(__FILE__), '**', '*.rb')].each { |f| require f }
11
11
 
12
- attr_reader :ruby_regex, :source, :options, :warnings
12
+ attr_reader :ruby_regex, :context, :converters, :source, :options, :warnings
13
13
 
14
14
  def initialize(ruby_regex)
15
15
  @ruby_regex = ruby_regex
16
- @source = ''
17
- @options = ''
18
- @warnings = []
16
+
17
+ @context = Converter::Context.new
18
+ @converters = {}
19
+
20
+ @source = ''
21
+ @options = ''
22
+ @warnings = []
19
23
 
20
24
  convert_source(ruby_regex)
21
25
  convert_options(ruby_regex)
@@ -29,6 +33,24 @@ class JsRegex
29
33
 
30
34
  private
31
35
 
36
+ CONVERTER_MAP = Hash.new(Converter::UnsupportedTokenConverter).merge(
37
+ anchor: Converter::AnchorConverter,
38
+ assertion: Converter::AssertionConverter,
39
+ backref: Converter::BackreferenceConverter,
40
+ conditional: Converter::ConditionalConverter,
41
+ escape: Converter::EscapeConverter,
42
+ free_space: Converter::FreespaceConverter,
43
+ group: Converter::GroupConverter,
44
+ literal: Converter::LiteralConverter,
45
+ meta: Converter::MetaConverter,
46
+ nonproperty: Converter::NonpropertyConverter,
47
+ property: Converter::PropertyConverter,
48
+ quantifier: Converter::QuantifierConverter,
49
+ set: Converter::SetConverter,
50
+ subset: Converter::SetConverter,
51
+ type: Converter::TypeConverter
52
+ ).freeze
53
+
32
54
  def convert_source(ruby_regex)
33
55
  Regexp::Scanner.scan(ruby_regex) do |token_class, subtype, data, s, e|
34
56
  # There might be a lot of tokens, so don't wrap their data in objects.
@@ -45,24 +67,7 @@ class JsRegex
45
67
  end
46
68
 
47
69
  def converter_for_token_class(token_class)
48
- converters[token_class] ||= begin
49
- converter_name = converter_name_for_token_class(token_class)
50
- converter_class = JsRegex::Converter.const_get(converter_name)
51
- converter_class.new(self, context)
52
- end
53
- end
54
-
55
- def converter_name_for_token_class(token_class)
56
- name = "#{token_class.to_s.delete('_').capitalize}Converter"
57
- Converter.const_defined?(name) ? name : 'UnsupportedTokenConverter'
58
- end
59
-
60
- def converters
61
- @converters ||= {}
62
- end
63
-
64
- def context
65
- @context ||= JsRegex::Converter::Context.new
70
+ converters[token_class] ||= CONVERTER_MAP[token_class].new(self, context)
66
71
  end
67
72
 
68
73
  def convert_options(ruby_regex)
@@ -1,7 +1,7 @@
1
+ require_relative 'base'
2
+
1
3
  class JsRegex
2
- #
3
4
  module Converter
4
- require_relative 'base'
5
5
  #
6
6
  # Template class implementation.
7
7
  #
@@ -1,7 +1,8 @@
1
+ require_relative 'base'
2
+ require_relative 'group_converter'
3
+
1
4
  class JsRegex
2
- #
3
5
  module Converter
4
- require_relative 'group_converter'
5
6
  #
6
7
  # Template class implementation.
7
8
  #
@@ -1,11 +1,11 @@
1
+ require_relative 'base'
2
+
1
3
  class JsRegex
2
- #
3
4
  module Converter
4
- require_relative 'base'
5
5
  #
6
6
  # Template class implementation.
7
7
  #
8
- class BackrefConverter < JsRegex::Converter::Base
8
+ class BackreferenceConverter < JsRegex::Converter::Base
9
9
  private
10
10
 
11
11
  def convert_data
@@ -1,7 +1,7 @@
1
+ require_relative 'base'
2
+
1
3
  class JsRegex
2
- #
3
4
  module Converter
4
- require_relative 'base'
5
5
  #
6
6
  # Template class implementation.
7
7
  #
@@ -1,8 +1,8 @@
1
+ require_relative 'base'
2
+ require_relative 'literal_converter'
3
+
1
4
  class JsRegex
2
- #
3
5
  module Converter
4
- require_relative 'base'
5
- require_relative 'literal_converter'
6
6
  #
7
7
  # Template class implementation.
8
8
  #
@@ -11,10 +11,27 @@ class JsRegex
11
11
 
12
12
  def convert_data
13
13
  case subtype
14
- when :backslash, :codepoint, :form_feed, :return, :hex, :interval_close,
15
- :interval_open, :newline, :one_or_more, :octal, :space, :set_close,
16
- :set_open, :dot, :tab, :vertical_tab, :zero_or_more, :zero_or_one,
17
- :carriage
14
+ when :backslash,
15
+ :bol,
16
+ :carriage,
17
+ :codepoint,
18
+ :dot,
19
+ :eol,
20
+ :form_feed,
21
+ :hex,
22
+ :interval_close,
23
+ :interval_open,
24
+ :newline,
25
+ :octal,
26
+ :one_or_more,
27
+ :return,
28
+ :set_close,
29
+ :set_open,
30
+ :space,
31
+ :tab,
32
+ :vertical_tab,
33
+ :zero_or_more,
34
+ :zero_or_one
18
35
  pass_through
19
36
  when :literal
20
37
  LiteralConverter.convert(data, self)
@@ -1,7 +1,7 @@
1
+ require_relative 'base'
2
+
1
3
  class JsRegex
2
- #
3
4
  module Converter
4
- require_relative 'base'
5
5
  #
6
6
  # Template class implementation.
7
7
  #
@@ -1,7 +1,7 @@
1
+ require_relative 'base'
2
+
1
3
  class JsRegex
2
- #
3
4
  module Converter
4
- require_relative 'base'
5
5
  #
6
6
  # Template class implementation.
7
7
  #
@@ -1,7 +1,7 @@
1
+ require_relative 'base'
2
+
1
3
  class JsRegex
2
- #
3
4
  module Converter
4
- require_relative 'base'
5
5
  #
6
6
  # Template class implementation.
7
7
  #
@@ -1,7 +1,7 @@
1
+ require_relative 'base'
2
+
1
3
  class JsRegex
2
- #
3
4
  module Converter
4
- require_relative 'base'
5
5
  #
6
6
  # Template class implementation.
7
7
  #
@@ -1,7 +1,8 @@
1
+ require_relative 'base'
2
+ require_relative 'property_converter'
3
+
1
4
  class JsRegex
2
- #
3
5
  module Converter
4
- require_relative 'property_converter'
5
6
  #
6
7
  # Template class implementation.
7
8
  #
@@ -1,8 +1,8 @@
1
+ require_relative 'base'
2
+ require_relative File.join('..', 'property_map')
3
+
1
4
  class JsRegex
2
- #
3
5
  module Converter
4
- require_relative 'base'
5
- require_relative File.join('..', 'property_map')
6
6
  #
7
7
  # Template class implementation.
8
8
  #
@@ -1,7 +1,7 @@
1
+ require_relative 'base'
2
+
1
3
  class JsRegex
2
- #
3
4
  module Converter
4
- require_relative 'base'
5
5
  #
6
6
  # Template class implementation.
7
7
  #
@@ -1,10 +1,10 @@
1
+ require_relative 'base'
2
+ require_relative 'literal_converter'
3
+ require_relative 'property_converter'
4
+ require_relative 'type_converter'
5
+
1
6
  class JsRegex
2
- #
3
7
  module Converter
4
- require_relative 'base'
5
- require_relative 'literal_converter'
6
- require_relative 'property_converter'
7
- require_relative 'type_converter'
8
8
  #
9
9
  # Template class implementation.
10
10
  #
@@ -1,7 +1,7 @@
1
+ require_relative 'base'
2
+
1
3
  class JsRegex
2
- #
3
4
  module Converter
4
- require_relative 'base'
5
5
  #
6
6
  # Template class implementation.
7
7
  #
@@ -1,7 +1,7 @@
1
+ require_relative 'base'
2
+
1
3
  class JsRegex
2
- #
3
4
  module Converter
4
- require_relative 'base'
5
5
  #
6
6
  # Template class implementation.
7
7
  #
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: 1.0.18
4
+ version: 1.0.19
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: 2016-09-04 00:00:00.000000000 Z
11
+ date: 2016-11-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: regexp_parser
@@ -24,48 +24,62 @@ dependencies:
24
24
  - - '='
25
25
  - !ruby/object:Gem::Version
26
26
  version: 0.3.6
27
+ - !ruby/object:Gem::Dependency
28
+ name: mutant-rspec
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '0.8'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '0.8'
27
41
  - !ruby/object:Gem::Dependency
28
42
  name: rake
29
43
  requirement: !ruby/object:Gem::Requirement
30
44
  requirements:
31
45
  - - "~>"
32
46
  - !ruby/object:Gem::Version
33
- version: '11.1'
47
+ version: '11.3'
34
48
  type: :development
35
49
  prerelease: false
36
50
  version_requirements: !ruby/object:Gem::Requirement
37
51
  requirements:
38
52
  - - "~>"
39
53
  - !ruby/object:Gem::Version
40
- version: '11.1'
54
+ version: '11.3'
41
55
  - !ruby/object:Gem::Dependency
42
56
  name: rspec-core
43
57
  requirement: !ruby/object:Gem::Requirement
44
58
  requirements:
45
59
  - - "~>"
46
60
  - !ruby/object:Gem::Version
47
- version: '3.4'
61
+ version: '3.5'
48
62
  type: :development
49
63
  prerelease: false
50
64
  version_requirements: !ruby/object:Gem::Requirement
51
65
  requirements:
52
66
  - - "~>"
53
67
  - !ruby/object:Gem::Version
54
- version: '3.4'
68
+ version: '3.5'
55
69
  - !ruby/object:Gem::Dependency
56
70
  name: rspec-expectations
57
71
  requirement: !ruby/object:Gem::Requirement
58
72
  requirements:
59
73
  - - "~>"
60
74
  - !ruby/object:Gem::Version
61
- version: '3.4'
75
+ version: '3.5'
62
76
  type: :development
63
77
  prerelease: false
64
78
  version_requirements: !ruby/object:Gem::Requirement
65
79
  requirements:
66
80
  - - "~>"
67
81
  - !ruby/object:Gem::Version
68
- version: '3.4'
82
+ version: '3.5'
69
83
  - !ruby/object:Gem::Dependency
70
84
  name: therubyracer
71
85
  requirement: !ruby/object:Gem::Requirement
@@ -86,14 +100,14 @@ dependencies:
86
100
  requirements:
87
101
  - - "~>"
88
102
  - !ruby/object:Gem::Version
89
- version: '0.5'
103
+ version: '0.6'
90
104
  type: :development
91
105
  prerelease: false
92
106
  version_requirements: !ruby/object:Gem::Requirement
93
107
  requirements:
94
108
  - - "~>"
95
109
  - !ruby/object:Gem::Version
96
- version: '0.5'
110
+ version: '0.6'
97
111
  description: JsRegex converts Ruby's native regular expressions for JavaScript, taking
98
112
  care of various incompatibilities and returning warnings for unsolvable differences.
99
113
  email:
@@ -106,7 +120,7 @@ files:
106
120
  - lib/js_regex/conversion.rb
107
121
  - lib/js_regex/converter/anchor_converter.rb
108
122
  - lib/js_regex/converter/assertion_converter.rb
109
- - lib/js_regex/converter/backref_converter.rb
123
+ - lib/js_regex/converter/backreference_converter.rb
110
124
  - lib/js_regex/converter/base.rb
111
125
  - lib/js_regex/converter/conditional_converter.rb
112
126
  - lib/js_regex/converter/context.rb
@@ -119,7 +133,6 @@ files:
119
133
  - lib/js_regex/converter/property_converter.rb
120
134
  - lib/js_regex/converter/quantifier_converter.rb
121
135
  - lib/js_regex/converter/set_converter.rb
122
- - lib/js_regex/converter/subset_converter.rb
123
136
  - lib/js_regex/converter/type_converter.rb
124
137
  - lib/js_regex/converter/unsupported_token_converter.rb
125
138
  - lib/js_regex/property_map.rb
@@ -148,4 +161,3 @@ signing_key:
148
161
  specification_version: 4
149
162
  summary: Converts Ruby regexes to JavaScript regexes.
150
163
  test_files: []
151
- has_rdoc:
@@ -1,10 +0,0 @@
1
- class JsRegex
2
- #
3
- module Converter
4
- require_relative 'set_converter'
5
- #
6
- # Simple reroute to SetConverter.
7
- #
8
- class SubsetConverter < JsRegex::Converter::SetConverter; end
9
- end
10
- end