regexp_parser 0.3.6 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/ChangeLog +6 -0
- data/lib/regexp_parser/syntax.rb +24 -182
- data/lib/regexp_parser/syntax/any.rb +15 -0
- data/lib/regexp_parser/syntax/base.rb +102 -0
- data/lib/regexp_parser/syntax/ruby/2.1.10.rb +13 -0
- data/lib/regexp_parser/syntax/ruby/2.1.rb +2 -2
- data/lib/regexp_parser/syntax/ruby/2.2.6.rb +13 -0
- data/lib/regexp_parser/syntax/ruby/2.2.rb +2 -2
- data/lib/regexp_parser/syntax/ruby/2.3.2.rb +13 -0
- data/lib/regexp_parser/syntax/ruby/2.3.rb +2 -2
- data/lib/regexp_parser/syntax/versions.rb +66 -0
- data/lib/regexp_parser/version.rb +1 -1
- data/test/syntax/ruby/test_files.rb +24 -3
- data/test/syntax/test_all.rb +1 -22
- data/test/syntax/test_syntax.rb +56 -0
- metadata +10 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 64caf66c58a7f537eb616c36ebe39525c9977a42
|
4
|
+
data.tar.gz: abfa9f49bd37d2f03ad790244dfebf0ed6a2e6de
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 96b55ce29f554b59027180962f26ce6b02725142495cbd637eec47f24c7f6866f5ba676105f5f1d689c8f35fe6923e3110032737642a3bf3b92a7277b23b4ab9
|
7
|
+
data.tar.gz: edf5a0c7288a929318ce0c9451d934a992ab794fc8baf0e4ded0ad3761a65a6a8127485378033c1bdefa0447b7d07363b0dea7949a4c306495e736dabc1532aa
|
data/ChangeLog
CHANGED
@@ -1,3 +1,9 @@
|
|
1
|
+
Sun Nov 20 2016 Ammar Ali <ammarabuali@gmail.com>
|
2
|
+
|
3
|
+
* Added Syntax.supported? method
|
4
|
+
* Updated ruby versions for latest releases; 2.1.10, 2.2.6, and 2.3.2
|
5
|
+
* Bumped version to 0.4.0
|
6
|
+
|
1
7
|
Wed Jun 8 2016 Ammar Ali <ammarabuali@gmail.com>
|
2
8
|
|
3
9
|
* Thanks to John Backus (https://github.com/backus):
|
data/lib/regexp_parser/syntax.rb
CHANGED
@@ -1,7 +1,13 @@
|
|
1
1
|
require File.expand_path('../syntax/tokens', __FILE__)
|
2
|
+
require File.expand_path('../syntax/base', __FILE__)
|
3
|
+
require File.expand_path('../syntax/any', __FILE__)
|
4
|
+
require File.expand_path('../syntax/versions', __FILE__)
|
2
5
|
|
3
6
|
module Regexp::Syntax
|
4
7
|
|
8
|
+
VERSION_FORMAT = '\Aruby/\d+\.\d+(\.\d+)?\z'
|
9
|
+
VERSION_REGEXP = /#{VERSION_FORMAT}/
|
10
|
+
|
5
11
|
class SyntaxError < StandardError
|
6
12
|
def initialize(what)
|
7
13
|
super what
|
@@ -14,205 +20,41 @@ module Regexp::Syntax
|
|
14
20
|
end
|
15
21
|
end
|
16
22
|
|
17
|
-
class
|
23
|
+
class InvalidVersionNameError < SyntaxError
|
18
24
|
def initialize(name)
|
19
|
-
super "
|
25
|
+
super "Invalid version name '#{name}'. Expected format is '#{VERSION_FORMAT}'"
|
20
26
|
end
|
21
27
|
end
|
22
28
|
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
end
|
27
|
-
end
|
28
|
-
|
29
|
-
SYNTAX_SPEC_ROOT = File.expand_path('../syntax', __FILE__)
|
30
|
-
|
31
|
-
# Loads, and instantiates an instance of the syntax specification class for
|
32
|
-
# the given syntax flavor name. The special names 'any' and '*' returns a
|
33
|
-
# instance of Syntax::Any. See below for more details.
|
29
|
+
# Loads and instantiates an instance of the syntax specification class for
|
30
|
+
# the given syntax version name. The special names 'any' and '*' return an
|
31
|
+
# instance of Syntax::Any.
|
34
32
|
def self.new(name)
|
35
33
|
return Regexp::Syntax::Any.new if
|
36
34
|
['*', 'any'].include?( name.to_s )
|
37
35
|
|
38
|
-
|
39
|
-
self.instantiate(name)
|
40
|
-
end
|
41
|
-
|
42
|
-
def self.instantiate(name)
|
43
|
-
case name
|
44
|
-
# Ruby 1.8.x (NOTE: 1.8.6 is no longer a supported runtime,
|
45
|
-
# but its regex features are still recognized.)
|
46
|
-
when 'ruby/1.8.6'; syntax = Regexp::Syntax::Ruby::V186.new
|
47
|
-
when 'ruby/1.8.7'; syntax = Regexp::Syntax::Ruby::V187.new
|
48
|
-
|
49
|
-
# alias for the latest 1.8 implementation
|
50
|
-
when 'ruby/1.8'; syntax = Regexp::Syntax::Ruby::V18.new
|
51
|
-
|
52
|
-
# Ruby 1.9.x
|
53
|
-
when 'ruby/1.9.1'; syntax = Regexp::Syntax::Ruby::V191.new
|
54
|
-
when 'ruby/1.9.2'; syntax = Regexp::Syntax::Ruby::V192.new
|
55
|
-
when 'ruby/1.9.3'; syntax = Regexp::Syntax::Ruby::V193.new
|
56
|
-
|
57
|
-
# alias for the latest 1.9 implementation
|
58
|
-
when 'ruby/1.9'; syntax = Regexp::Syntax::Ruby::V19.new
|
36
|
+
raise UnknownSyntaxNameError.new(name) unless supported?(name)
|
59
37
|
|
60
|
-
|
61
|
-
when 'ruby/2.0.0'; syntax = Regexp::Syntax::Ruby::V200.new
|
62
|
-
|
63
|
-
# aliases for the latest 2.0 implementations
|
64
|
-
when 'ruby/2.0'; syntax = Regexp::Syntax::Ruby::V20.new
|
65
|
-
|
66
|
-
# Ruby 2.1.x
|
67
|
-
when 'ruby/2.1.0'; syntax = Regexp::Syntax::Ruby::V210.new
|
68
|
-
when 'ruby/2.1.2'; syntax = Regexp::Syntax::Ruby::V212.new
|
69
|
-
when 'ruby/2.1.3'; syntax = Regexp::Syntax::Ruby::V213.new
|
70
|
-
when 'ruby/2.1.4'; syntax = Regexp::Syntax::Ruby::V214.new
|
71
|
-
when 'ruby/2.1.5'; syntax = Regexp::Syntax::Ruby::V215.new
|
72
|
-
when 'ruby/2.1.6'; syntax = Regexp::Syntax::Ruby::V216.new
|
73
|
-
when 'ruby/2.1.7'; syntax = Regexp::Syntax::Ruby::V217.new
|
74
|
-
when 'ruby/2.1.8'; syntax = Regexp::Syntax::Ruby::V218.new
|
75
|
-
when 'ruby/2.1.9'; syntax = Regexp::Syntax::Ruby::V219.new
|
76
|
-
|
77
|
-
# aliases for the latest 2.1 implementations
|
78
|
-
when 'ruby/2.1'; syntax = Regexp::Syntax::Ruby::V21.new
|
79
|
-
|
80
|
-
# Ruby 2.2.x
|
81
|
-
when 'ruby/2.2.0'; syntax = Regexp::Syntax::Ruby::V220.new
|
82
|
-
when 'ruby/2.2.1'; syntax = Regexp::Syntax::Ruby::V221.new
|
83
|
-
when 'ruby/2.2.2'; syntax = Regexp::Syntax::Ruby::V222.new
|
84
|
-
when 'ruby/2.2.3'; syntax = Regexp::Syntax::Ruby::V223.new
|
85
|
-
when 'ruby/2.2.4'; syntax = Regexp::Syntax::Ruby::V224.new
|
86
|
-
when 'ruby/2.2.5'; syntax = Regexp::Syntax::Ruby::V225.new
|
87
|
-
|
88
|
-
# aliases for the latest 2.2 implementations
|
89
|
-
when 'ruby/2.2'; syntax = Regexp::Syntax::Ruby::V22.new
|
90
|
-
|
91
|
-
# Ruby 2.3.x
|
92
|
-
when 'ruby/2.3.0'; syntax = Regexp::Syntax::Ruby::V230.new
|
93
|
-
when 'ruby/2.3.1'; syntax = Regexp::Syntax::Ruby::V231.new
|
94
|
-
|
95
|
-
# alias for the latest 2.3 implementation
|
96
|
-
when 'ruby/2.3'; syntax = Regexp::Syntax::Ruby::V23.new
|
97
|
-
|
98
|
-
else
|
99
|
-
raise UnknownSyntaxNameError.new(name)
|
100
|
-
end
|
38
|
+
version_class(name).new
|
101
39
|
end
|
102
40
|
|
103
|
-
|
104
|
-
|
105
|
-
def self.load(name)
|
106
|
-
full = "#{SYNTAX_SPEC_ROOT}/#{name.downcase}"
|
107
|
-
full = (full[-1, 3] == '.rb') ? full : "#{full}.rb"
|
108
|
-
|
109
|
-
raise MissingSyntaxSpecError.new(name) unless File.exist?(full)
|
110
|
-
require full
|
41
|
+
def self.supported?(name)
|
42
|
+
VERSIONS.include?(name)
|
111
43
|
end
|
112
44
|
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
@implements = {}
|
45
|
+
def self.version_class(version)
|
46
|
+
raise InvalidVersionNameError.new(version) unless
|
47
|
+
version =~ VERSION_REGEXP
|
117
48
|
|
118
|
-
|
119
|
-
implements Token::FreeSpace::Type, Token::FreeSpace::All
|
120
|
-
end
|
121
|
-
|
122
|
-
def implementation
|
123
|
-
@implements
|
124
|
-
end
|
125
|
-
|
126
|
-
def implements(type, tokens)
|
127
|
-
if @implements[type]
|
128
|
-
@implements[type] = (@implements[type] + tokens).uniq
|
129
|
-
else
|
130
|
-
@implements[type] = tokens
|
131
|
-
end
|
132
|
-
end
|
49
|
+
version_const_name = version.scan(/\d+/).join
|
133
50
|
|
134
|
-
#
|
135
|
-
def excludes(type, tokens)
|
136
|
-
if tokens
|
137
|
-
tokens = [tokens] unless tokens.is_a?(Array)
|
138
|
-
end
|
51
|
+
const_name = "Regexp::Syntax::Ruby::V#{version_const_name}"
|
139
52
|
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
else
|
145
|
-
@implements[type] = nil
|
146
|
-
end
|
147
|
-
end
|
53
|
+
if RUBY_VERSION >= '2.0.0'
|
54
|
+
Kernel.const_get(const_name)
|
55
|
+
else
|
56
|
+
Object.module_eval(const_name, __FILE__, __LINE__)
|
148
57
|
end
|
149
|
-
|
150
|
-
def implements?(type, token)
|
151
|
-
return true if @implements[type] and @implements[type].include?(token)
|
152
|
-
false
|
153
|
-
end
|
154
|
-
alias :check? :implements?
|
155
|
-
|
156
|
-
def implements!(type, token)
|
157
|
-
raise NotImplementedError.new(self, type, token) unless
|
158
|
-
implements?(type, token)
|
159
|
-
end
|
160
|
-
alias :check! :implements!
|
161
|
-
|
162
|
-
def normalize(type, token)
|
163
|
-
case type
|
164
|
-
when :group
|
165
|
-
normalize_group(type, token)
|
166
|
-
when :backref
|
167
|
-
normalize_backref(type, token)
|
168
|
-
else
|
169
|
-
[type, token]
|
170
|
-
end
|
171
|
-
end
|
172
|
-
|
173
|
-
def normalize_group(type, token)
|
174
|
-
case token
|
175
|
-
when :named_ab, :named_sq
|
176
|
-
[:group, :named]
|
177
|
-
else
|
178
|
-
[type, token]
|
179
|
-
end
|
180
|
-
end
|
181
|
-
|
182
|
-
def normalize_backref(type, token)
|
183
|
-
case token
|
184
|
-
when :name_ref_ab, :name_ref_sq
|
185
|
-
[:backref, :name_ref]
|
186
|
-
when :name_call_ab, :name_call_sq
|
187
|
-
[:backref, :name_call]
|
188
|
-
when :name_nest_ref_ab, :name_nest_ref_sq
|
189
|
-
[:backref, :name_nest_ref]
|
190
|
-
when :number_ref_ab, :number_ref_sq
|
191
|
-
[:backref, :number_ref]
|
192
|
-
when :number_call_ab, :number_call_sq
|
193
|
-
[:backref, :number_call]
|
194
|
-
when :number_rel_ref_ab, :number_rel_ref_sq
|
195
|
-
[:backref, :number_rel_ref]
|
196
|
-
when :number_rel_call_ab, :number_rel_call_sq
|
197
|
-
[:backref, :number_rel_call]
|
198
|
-
when :number_nest_ref_ab, :number_nest_ref_sq
|
199
|
-
[:backref, :number_nest_ref]
|
200
|
-
else
|
201
|
-
[type, token]
|
202
|
-
end
|
203
|
-
end
|
204
|
-
end
|
205
|
-
|
206
|
-
# A syntax that always returns true, passing all tokens as implemented. This
|
207
|
-
# is useful during development, testing, and should be useful for some types
|
208
|
-
# of transformations as well.
|
209
|
-
class Any < Base
|
210
|
-
def initialize
|
211
|
-
@implements = { :* => [:*] }
|
212
|
-
end
|
213
|
-
|
214
|
-
def implements?(type, token) true end
|
215
|
-
def implements!(type, token) true end
|
216
58
|
end
|
217
59
|
|
218
60
|
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
module Regexp::Syntax
|
2
|
+
|
3
|
+
# A syntax that always returns true, passing all tokens as implemented. This
|
4
|
+
# is useful during development, testing, and should be useful for some types
|
5
|
+
# of transformations as well.
|
6
|
+
class Any < Base
|
7
|
+
def initialize
|
8
|
+
@implements = { :* => [:*] }
|
9
|
+
end
|
10
|
+
|
11
|
+
def implements?(type, token) true end
|
12
|
+
def implements!(type, token) true end
|
13
|
+
end
|
14
|
+
|
15
|
+
end
|
@@ -0,0 +1,102 @@
|
|
1
|
+
module Regexp::Syntax
|
2
|
+
|
3
|
+
class NotImplementedError < SyntaxError
|
4
|
+
def initialize(syntax, type, token)
|
5
|
+
super "#{syntax.class.name} does not implement: [#{type}:#{token}]"
|
6
|
+
end
|
7
|
+
end
|
8
|
+
|
9
|
+
# A lookup map of supported types and tokens in a given syntax
|
10
|
+
class Base
|
11
|
+
def initialize
|
12
|
+
@implements = {}
|
13
|
+
|
14
|
+
implements Token::Literal::Type, Token::Literal::All
|
15
|
+
implements Token::FreeSpace::Type, Token::FreeSpace::All
|
16
|
+
end
|
17
|
+
|
18
|
+
def implementation
|
19
|
+
@implements
|
20
|
+
end
|
21
|
+
|
22
|
+
def implements(type, tokens)
|
23
|
+
if @implements[type]
|
24
|
+
@implements[type] = (@implements[type] + tokens).uniq
|
25
|
+
else
|
26
|
+
@implements[type] = tokens
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
# removes
|
31
|
+
def excludes(type, tokens)
|
32
|
+
if tokens
|
33
|
+
tokens = [tokens] unless tokens.is_a?(Array)
|
34
|
+
end
|
35
|
+
|
36
|
+
if @implements[type]
|
37
|
+
if tokens
|
38
|
+
@implements[type] = @implements[type] - tokens
|
39
|
+
@implements[type] = nil if @implements[type].empty?
|
40
|
+
else
|
41
|
+
@implements[type] = nil
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
def implements?(type, token)
|
47
|
+
return true if @implements[type] and @implements[type].include?(token)
|
48
|
+
false
|
49
|
+
end
|
50
|
+
alias :check? :implements?
|
51
|
+
|
52
|
+
def implements!(type, token)
|
53
|
+
raise NotImplementedError.new(self, type, token) unless
|
54
|
+
implements?(type, token)
|
55
|
+
end
|
56
|
+
alias :check! :implements!
|
57
|
+
|
58
|
+
def normalize(type, token)
|
59
|
+
case type
|
60
|
+
when :group
|
61
|
+
normalize_group(type, token)
|
62
|
+
when :backref
|
63
|
+
normalize_backref(type, token)
|
64
|
+
else
|
65
|
+
[type, token]
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
def normalize_group(type, token)
|
70
|
+
case token
|
71
|
+
when :named_ab, :named_sq
|
72
|
+
[:group, :named]
|
73
|
+
else
|
74
|
+
[type, token]
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
def normalize_backref(type, token)
|
79
|
+
case token
|
80
|
+
when :name_ref_ab, :name_ref_sq
|
81
|
+
[:backref, :name_ref]
|
82
|
+
when :name_call_ab, :name_call_sq
|
83
|
+
[:backref, :name_call]
|
84
|
+
when :name_nest_ref_ab, :name_nest_ref_sq
|
85
|
+
[:backref, :name_nest_ref]
|
86
|
+
when :number_ref_ab, :number_ref_sq
|
87
|
+
[:backref, :number_ref]
|
88
|
+
when :number_call_ab, :number_call_sq
|
89
|
+
[:backref, :number_call]
|
90
|
+
when :number_rel_ref_ab, :number_rel_ref_sq
|
91
|
+
[:backref, :number_rel_ref]
|
92
|
+
when :number_rel_call_ab, :number_rel_call_sq
|
93
|
+
[:backref, :number_rel_call]
|
94
|
+
when :number_nest_ref_ab, :number_nest_ref_sq
|
95
|
+
[:backref, :number_nest_ref]
|
96
|
+
else
|
97
|
+
[type, token]
|
98
|
+
end
|
99
|
+
end
|
100
|
+
end
|
101
|
+
|
102
|
+
end
|
@@ -1,8 +1,8 @@
|
|
1
|
-
require File.expand_path('../2.1.
|
1
|
+
require File.expand_path('../2.1.10', __FILE__)
|
2
2
|
|
3
3
|
module Regexp::Syntax
|
4
4
|
module Ruby
|
5
5
|
# uses the latest 2.1 release
|
6
|
-
class V21 < Regexp::Syntax::Ruby::
|
6
|
+
class V21 < Regexp::Syntax::Ruby::V2110; end
|
7
7
|
end
|
8
8
|
end
|
@@ -1,8 +1,8 @@
|
|
1
|
-
require File.expand_path('../2.2.
|
1
|
+
require File.expand_path('../2.2.6', __FILE__)
|
2
2
|
|
3
3
|
module Regexp::Syntax
|
4
4
|
module Ruby
|
5
5
|
# uses the latest 2.2 release
|
6
|
-
class V22 < Regexp::Syntax::Ruby::
|
6
|
+
class V22 < Regexp::Syntax::Ruby::V226; end
|
7
7
|
end
|
8
8
|
end
|
@@ -1,8 +1,8 @@
|
|
1
|
-
require File.expand_path('../2.3.
|
1
|
+
require File.expand_path('../2.3.2', __FILE__)
|
2
2
|
|
3
3
|
module Regexp::Syntax
|
4
4
|
module Ruby
|
5
5
|
# uses the latest 2.3 release
|
6
|
-
class V23 < Regexp::Syntax::Ruby::
|
6
|
+
class V23 < Regexp::Syntax::Ruby::V232; end
|
7
7
|
end
|
8
8
|
end
|
@@ -0,0 +1,66 @@
|
|
1
|
+
module Regexp::Syntax
|
2
|
+
|
3
|
+
VERSIONS = [
|
4
|
+
# Ruby 1.8.x (NOTE: 1.8.6 is no longer a supported runtime,
|
5
|
+
# but its regex features are still recognized.)
|
6
|
+
'ruby/1.8.6',
|
7
|
+
'ruby/1.8.7',
|
8
|
+
|
9
|
+
# alias for the latest 1.8 implementation
|
10
|
+
'ruby/1.8',
|
11
|
+
|
12
|
+
# Ruby 1.9.x
|
13
|
+
'ruby/1.9.1',
|
14
|
+
'ruby/1.9.2',
|
15
|
+
'ruby/1.9.3',
|
16
|
+
|
17
|
+
# alias for the latest 1.9 implementation
|
18
|
+
'ruby/1.9',
|
19
|
+
|
20
|
+
# Ruby 2.0.x
|
21
|
+
'ruby/2.0.0',
|
22
|
+
|
23
|
+
# alias for the latest 2.0 implementations
|
24
|
+
'ruby/2.0',
|
25
|
+
|
26
|
+
# Ruby 2.1.x
|
27
|
+
'ruby/2.1.0',
|
28
|
+
'ruby/2.1.2',
|
29
|
+
'ruby/2.1.3',
|
30
|
+
'ruby/2.1.4',
|
31
|
+
'ruby/2.1.5',
|
32
|
+
'ruby/2.1.6',
|
33
|
+
'ruby/2.1.7',
|
34
|
+
'ruby/2.1.8',
|
35
|
+
'ruby/2.1.9',
|
36
|
+
'ruby/2.1.10',
|
37
|
+
|
38
|
+
# alias for the latest 2.1 implementations
|
39
|
+
'ruby/2.1',
|
40
|
+
|
41
|
+
# Ruby 2.2.x
|
42
|
+
'ruby/2.2.0',
|
43
|
+
'ruby/2.2.1',
|
44
|
+
'ruby/2.2.2',
|
45
|
+
'ruby/2.2.3',
|
46
|
+
'ruby/2.2.4',
|
47
|
+
'ruby/2.2.5',
|
48
|
+
'ruby/2.2.6',
|
49
|
+
|
50
|
+
# alias for the latest 2.2 implementations
|
51
|
+
'ruby/2.2',
|
52
|
+
|
53
|
+
# Ruby 2.3.x
|
54
|
+
'ruby/2.3.0',
|
55
|
+
'ruby/2.3.1',
|
56
|
+
'ruby/2.3.2',
|
57
|
+
|
58
|
+
# alias for the latest 2.3 implementation
|
59
|
+
'ruby/2.3',
|
60
|
+
]
|
61
|
+
|
62
|
+
end
|
63
|
+
|
64
|
+
Regexp::Syntax::VERSIONS.each do |version|
|
65
|
+
require File.expand_path("../#{version}", __FILE__)
|
66
|
+
end
|
@@ -118,10 +118,17 @@ class TestSyntaxFiles < Test::Unit::TestCase
|
|
118
118
|
assert syntax.kind_of?(Regexp::Syntax::Ruby::V219)
|
119
119
|
end
|
120
120
|
|
121
|
+
def test_syntax_file_2_1_10
|
122
|
+
syntax = Regexp::Syntax.new 'ruby/2.1.10'
|
123
|
+
|
124
|
+
assert syntax.kind_of?(Regexp::Syntax::Ruby::V219)
|
125
|
+
assert syntax.kind_of?(Regexp::Syntax::Ruby::V2110)
|
126
|
+
end
|
127
|
+
|
121
128
|
def test_syntax_file_2_1_alias
|
122
129
|
syntax = Regexp::Syntax.new 'ruby/2.1'
|
123
130
|
|
124
|
-
assert syntax.kind_of?(Regexp::Syntax::Ruby::
|
131
|
+
assert syntax.kind_of?(Regexp::Syntax::Ruby::V2110)
|
125
132
|
end
|
126
133
|
|
127
134
|
|
@@ -163,10 +170,17 @@ class TestSyntaxFiles < Test::Unit::TestCase
|
|
163
170
|
assert syntax.kind_of?(Regexp::Syntax::Ruby::V225)
|
164
171
|
end
|
165
172
|
|
173
|
+
def test_syntax_file_2_2_6
|
174
|
+
syntax = Regexp::Syntax.new 'ruby/2.2.6'
|
175
|
+
|
176
|
+
assert syntax.kind_of?(Regexp::Syntax::Ruby::V225)
|
177
|
+
assert syntax.kind_of?(Regexp::Syntax::Ruby::V226)
|
178
|
+
end
|
179
|
+
|
166
180
|
def test_syntax_file_2_2_alias
|
167
181
|
syntax = Regexp::Syntax.new 'ruby/2.2'
|
168
182
|
|
169
|
-
assert syntax.kind_of?(Regexp::Syntax::Ruby::
|
183
|
+
assert syntax.kind_of?(Regexp::Syntax::Ruby::V226)
|
170
184
|
end
|
171
185
|
|
172
186
|
# 2.3 syntax files
|
@@ -184,9 +198,16 @@ class TestSyntaxFiles < Test::Unit::TestCase
|
|
184
198
|
assert syntax.kind_of?(Regexp::Syntax::Ruby::V231)
|
185
199
|
end
|
186
200
|
|
201
|
+
def test_syntax_file_2_3_2
|
202
|
+
syntax = Regexp::Syntax.new 'ruby/2.3.2'
|
203
|
+
|
204
|
+
assert syntax.kind_of?(Regexp::Syntax::Ruby::V231)
|
205
|
+
assert syntax.kind_of?(Regexp::Syntax::Ruby::V232)
|
206
|
+
end
|
207
|
+
|
187
208
|
def test_syntax_file_2_3_alias
|
188
209
|
syntax = Regexp::Syntax.new 'ruby/2.3'
|
189
210
|
|
190
|
-
assert syntax.kind_of?(Regexp::Syntax::Ruby::
|
211
|
+
assert syntax.kind_of?(Regexp::Syntax::Ruby::V232)
|
191
212
|
end
|
192
213
|
end
|
data/test/syntax/test_all.rb
CHANGED
@@ -1,25 +1,4 @@
|
|
1
1
|
require File.expand_path("../../helpers", __FILE__)
|
2
2
|
|
3
|
+
require File.expand_path("../test_syntax", __FILE__)
|
3
4
|
require File.expand_path("../ruby/test_all", __FILE__)
|
4
|
-
|
5
|
-
class TestSyntax < Test::Unit::TestCase
|
6
|
-
|
7
|
-
def test_syntax_unknown_name
|
8
|
-
assert_raise( Regexp::Syntax::UnknownSyntaxNameError ) {
|
9
|
-
Regexp::Syntax.instantiate('ruby/1.0')
|
10
|
-
}
|
11
|
-
end
|
12
|
-
|
13
|
-
def test_syntax_missing_spec
|
14
|
-
assert_raise( Regexp::Syntax::MissingSyntaxSpecError ) {
|
15
|
-
RL.scan('abc', 'ruby/1.6')
|
16
|
-
}
|
17
|
-
end
|
18
|
-
|
19
|
-
def test_syntax_not_implemented
|
20
|
-
assert_raise( Regexp::Syntax::NotImplementedError ) {
|
21
|
-
RP.parse('\p{alpha}', 'ruby/1.8')
|
22
|
-
}
|
23
|
-
end
|
24
|
-
|
25
|
-
end
|
@@ -0,0 +1,56 @@
|
|
1
|
+
require File.expand_path("../../helpers", __FILE__)
|
2
|
+
|
3
|
+
class TestSyntax < Test::Unit::TestCase
|
4
|
+
|
5
|
+
def test_syntax_unknown_name
|
6
|
+
assert_raise( Regexp::Syntax::UnknownSyntaxNameError ) {
|
7
|
+
Regexp::Syntax.new('ruby/1.0')
|
8
|
+
}
|
9
|
+
end
|
10
|
+
|
11
|
+
def test_syntax_new
|
12
|
+
assert_instance_of Regexp::Syntax::Ruby::V193,
|
13
|
+
Regexp::Syntax.new('ruby/1.9.3')
|
14
|
+
end
|
15
|
+
|
16
|
+
def test_syntax_not_implemented
|
17
|
+
assert_raise( Regexp::Syntax::NotImplementedError ) {
|
18
|
+
RP.parse('\p{alpha}', 'ruby/1.8')
|
19
|
+
}
|
20
|
+
end
|
21
|
+
|
22
|
+
def test_syntax_supported?
|
23
|
+
assert_equal false, Regexp::Syntax.supported?('ruby/1.1.1')
|
24
|
+
|
25
|
+
Regexp::Syntax::VERSIONS.each do |version|
|
26
|
+
assert_equal true, Regexp::Syntax.supported?(version)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
def test_syntax_invalid_version
|
31
|
+
assert_raise( Regexp::Syntax::InvalidVersionNameError ) {
|
32
|
+
Regexp::Syntax.version_class('2.0.0')
|
33
|
+
}
|
34
|
+
|
35
|
+
assert_raise( Regexp::Syntax::InvalidVersionNameError ) {
|
36
|
+
Regexp::Syntax.version_class('ruby/20')
|
37
|
+
}
|
38
|
+
end
|
39
|
+
|
40
|
+
def test_syntax_version_class_tiny_version
|
41
|
+
assert_equal Regexp::Syntax::Ruby::V193,
|
42
|
+
Regexp::Syntax.version_class('ruby/1.9.3')
|
43
|
+
|
44
|
+
assert_equal Regexp::Syntax::Ruby::V231,
|
45
|
+
Regexp::Syntax.version_class('ruby/2.3.1')
|
46
|
+
end
|
47
|
+
|
48
|
+
def test_syntax_version_class_minor_version
|
49
|
+
assert_equal Regexp::Syntax::Ruby::V19,
|
50
|
+
Regexp::Syntax.version_class('ruby/1.9')
|
51
|
+
|
52
|
+
assert_equal Regexp::Syntax::Ruby::V23,
|
53
|
+
Regexp::Syntax.version_class('ruby/2.3')
|
54
|
+
end
|
55
|
+
|
56
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: regexp_parser
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ammar Ali
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-11-20 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: A library for tokenizing, lexing, and parsing Ruby regular expressions.
|
14
14
|
email:
|
@@ -49,6 +49,8 @@ files:
|
|
49
49
|
- lib/regexp_parser/scanner/property.rl
|
50
50
|
- lib/regexp_parser/scanner/scanner.rl
|
51
51
|
- lib/regexp_parser/syntax.rb
|
52
|
+
- lib/regexp_parser/syntax/any.rb
|
53
|
+
- lib/regexp_parser/syntax/base.rb
|
52
54
|
- lib/regexp_parser/syntax/ruby/1.8.6.rb
|
53
55
|
- lib/regexp_parser/syntax/ruby/1.8.7.rb
|
54
56
|
- lib/regexp_parser/syntax/ruby/1.8.rb
|
@@ -59,6 +61,7 @@ files:
|
|
59
61
|
- lib/regexp_parser/syntax/ruby/2.0.0.rb
|
60
62
|
- lib/regexp_parser/syntax/ruby/2.0.rb
|
61
63
|
- lib/regexp_parser/syntax/ruby/2.1.0.rb
|
64
|
+
- lib/regexp_parser/syntax/ruby/2.1.10.rb
|
62
65
|
- lib/regexp_parser/syntax/ruby/2.1.2.rb
|
63
66
|
- lib/regexp_parser/syntax/ruby/2.1.3.rb
|
64
67
|
- lib/regexp_parser/syntax/ruby/2.1.4.rb
|
@@ -74,9 +77,11 @@ files:
|
|
74
77
|
- lib/regexp_parser/syntax/ruby/2.2.3.rb
|
75
78
|
- lib/regexp_parser/syntax/ruby/2.2.4.rb
|
76
79
|
- lib/regexp_parser/syntax/ruby/2.2.5.rb
|
80
|
+
- lib/regexp_parser/syntax/ruby/2.2.6.rb
|
77
81
|
- lib/regexp_parser/syntax/ruby/2.2.rb
|
78
82
|
- lib/regexp_parser/syntax/ruby/2.3.0.rb
|
79
83
|
- lib/regexp_parser/syntax/ruby/2.3.1.rb
|
84
|
+
- lib/regexp_parser/syntax/ruby/2.3.2.rb
|
80
85
|
- lib/regexp_parser/syntax/ruby/2.3.rb
|
81
86
|
- lib/regexp_parser/syntax/tokens.rb
|
82
87
|
- lib/regexp_parser/syntax/tokens/anchor.rb
|
@@ -91,6 +96,7 @@ files:
|
|
91
96
|
- lib/regexp_parser/syntax/tokens/meta.rb
|
92
97
|
- lib/regexp_parser/syntax/tokens/quantifier.rb
|
93
98
|
- lib/regexp_parser/syntax/tokens/unicode_property.rb
|
99
|
+
- lib/regexp_parser/syntax/versions.rb
|
94
100
|
- lib/regexp_parser/token.rb
|
95
101
|
- lib/regexp_parser/version.rb
|
96
102
|
- regexp_parser.gemspec
|
@@ -155,6 +161,7 @@ files:
|
|
155
161
|
- test/syntax/ruby/test_all.rb
|
156
162
|
- test/syntax/ruby/test_files.rb
|
157
163
|
- test/syntax/test_all.rb
|
164
|
+
- test/syntax/test_syntax.rb
|
158
165
|
- test/test_all.rb
|
159
166
|
- test/token/test_all.rb
|
160
167
|
- test/token/test_token.rb
|
@@ -247,6 +254,7 @@ test_files:
|
|
247
254
|
- test/syntax/ruby/test_all.rb
|
248
255
|
- test/syntax/ruby/test_files.rb
|
249
256
|
- test/syntax/test_all.rb
|
257
|
+
- test/syntax/test_syntax.rb
|
250
258
|
- test/test_all.rb
|
251
259
|
- test/token/test_all.rb
|
252
260
|
- test/token/test_token.rb
|