regexp-examples 1.4.2 → 1.4.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.travis.yml +4 -3
- data/README.md +7 -8
- data/lib/regexp-examples/groups.rb +1 -1
- data/lib/regexp-examples/parser_helpers/parse_multi_group_helper.rb +19 -1
- data/lib/regexp-examples/version.rb +1 -1
- data/spec/regexp-examples_spec.rb +8 -1
- data/spec/regexp-examples_spec_2.4.1.rb +7 -0
- metadata +5 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 9ee8a454e1238f6a09e9d5df9b3e462fa497bea2
|
4
|
+
data.tar.gz: 30c836039ede81f568c55f2552c42eec951505ef
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: dbef5b7698904308ab77ce262ab00d806936cde7fe00f567733cb4aba8bf71a75e714f9e2c525d00b5dca4e5ab11b2d9b1713e2b58dabfbc0210c9ef21e80e76
|
7
|
+
data.tar.gz: be725e51de4a04371d78fe99844d3778c104a6a0951059655d99f2bfa98c1b269b412f4d688b852a85e86466323e48e0d7dcdac53d40e4781cfab10f7681028b
|
data/.travis.yml
CHANGED
data/README.md
CHANGED
@@ -57,6 +57,7 @@ Obviously, you will get different (random) results if you try these yourself!
|
|
57
57
|
* MRI 2.2.x
|
58
58
|
* MRI 2.3.x
|
59
59
|
* MRI 2.4.x
|
60
|
+
* MRI 2.5.x
|
60
61
|
|
61
62
|
MRI ≤ 1.9.3 are not supported. This is primarily because MRI 2.0.0 introduced a new
|
62
63
|
regexp engine (`Oniguruma` was replaced by `Onigmo`). Whilst *most* of this gem could
|
@@ -110,6 +111,9 @@ Long answer:
|
|
110
111
|
* ...and even if nested or optional, e.g. `/(even(this(works?))) \1 \2 \3/`, `/what about (this)? \1/`
|
111
112
|
* Non-capture groups, e.g. `/(?:foo)/`
|
112
113
|
* Comment groups, e.g. `/foo(?#comment)bar/`
|
114
|
+
* [Absent operator groups, e.g. `/(?~exp)/`](https://medium.com/rubyinside/the-new-absent-operator-in-ruby-s-regular-expressions-7c3ef6cd0b99)
|
115
|
+
This feature is available in ruby version `>= 2.4.1`.
|
116
|
+
However, support in this gem is [limited](https://github.com/tom-lord/regexp-examples/issues/22).
|
113
117
|
* Control characters, e.g. `/\ca/`, `/\cZ/`, `/\C-9/`
|
114
118
|
* Escape sequences, e.g. `/\x42/`, `/\x5word/`, `/#{"\x80".force_encoding("ASCII-8BIT")}/`
|
115
119
|
* Unicode characters, e.g. `/\u0123/`, `/\uabcd/`, `/\u{789}/`
|
@@ -200,15 +204,10 @@ All forms of configuration mentioned above **are thread safe**.
|
|
200
204
|
|
201
205
|
## Bugs and TODOs
|
202
206
|
|
203
|
-
There are no known major bugs with this library. However, there are a few obscure issues that you *may* encounter
|
207
|
+
There are no known major bugs with this library. However, there are a few obscure issues that you *may* encounter.
|
204
208
|
|
205
|
-
|
206
|
-
|
207
|
-
to ever write regexes like this!)
|
208
|
-
* A new ["absent operator" (`/(?~exp)/`)](https://medium.com/rubyinside/the-new-absent-operator-in-ruby-s-regular-expressions-7c3ef6cd0b99)
|
209
|
-
was added to Ruby version `2.4.1`. This gem does not yet support it (or gracefully fail when used).
|
210
|
-
* Ideally, `regexp#examples` should always return up to `max_results_limit`. Currenty, it usually "aborts" before this limit is reached.
|
211
|
-
(I.e. the exact number of examples generated can be hard to predict, for complex patterns.)
|
209
|
+
All known bugs/missing features are [documented in GitHub](https://github.com/tom-lord/regexp-examples/issues).
|
210
|
+
Please discuss known issues there, or raise a new issue if required. Pull requests are welcome!
|
212
211
|
|
213
212
|
Some of the most obscure regexp features are not even mentioned in [the ruby docs](http://ruby-doc.org/core/Regexp.html).
|
214
213
|
However, full documentation on all the intricate obscurities in the ruby (version 2.x) regexp parser can be found
|
@@ -125,7 +125,7 @@ module RegexpExamples
|
|
125
125
|
# Generates the result of each contained group
|
126
126
|
# and adds the filled group of each result to itself
|
127
127
|
def result
|
128
|
-
strings = @groups.map { |repeater| repeater.public_send(
|
128
|
+
strings = @groups.map { |repeater| repeater.public_send(__callee__) }
|
129
129
|
RegexpExamples.permutations_of_strings(strings).map do |result|
|
130
130
|
GroupResult.new(result, group_id)
|
131
131
|
end
|
@@ -18,6 +18,7 @@ module RegexpExamples
|
|
18
18
|
|! # Neglookahead
|
19
19
|
|= # Lookahead
|
20
20
|
|\# # Comment group
|
21
|
+
|~ # Absent operator (ruby 2.4.1+)
|
21
22
|
|< # Lookbehind or named capture
|
22
23
|
(
|
23
24
|
! # Neglookbehind
|
@@ -31,10 +32,27 @@ module RegexpExamples
|
|
31
32
|
if match[1].nil? # e.g. /(normal)/
|
32
33
|
group_id = @num_groups.to_s
|
33
34
|
elsif match[2] == ':' # e.g. /(?:nocapture)/
|
35
|
+
@num_groups -= 1
|
34
36
|
@current_position += 2
|
35
37
|
elsif match[2] == '#' # e.g. /(?#comment)/
|
36
|
-
|
38
|
+
@num_groups -= 1
|
39
|
+
comment_group = rest_of_string.match(/.*?[^\\](?:\\{2})*(?=\))/)[0]
|
37
40
|
@current_position += comment_group.length
|
41
|
+
return PlaceHolderGroup.new
|
42
|
+
elsif match[2] == '~' # e.g. /(?~absent operator)/
|
43
|
+
# The "best" way to replicate this is with a negative lookbehind:
|
44
|
+
# e.g. (?~abc) --> (?:.(?<!abc))*
|
45
|
+
# But since look-behinds are irregular, this library cannot support
|
46
|
+
# that! A possible workaround would be to replace the group with a
|
47
|
+
# repetition of the first letter negated, e.g.
|
48
|
+
# (?~abc) --> (?:[^a]*)
|
49
|
+
# However (!!) this generalisation is not always possible:
|
50
|
+
# (?~\wa|\Wb) --> ???
|
51
|
+
# Therefore, the only 100% reliable option is just to match "nothing"
|
52
|
+
@num_groups -= 1 # "Absence groups" are not counted as backrefs
|
53
|
+
absence_group = rest_of_string.match(/.*?[^\\](?:\\{2})*(?=\))/)[0]
|
54
|
+
@current_position += absence_group.length
|
55
|
+
return PlaceHolderGroup.new
|
38
56
|
elsif match[2] =~ /\A(?=[mix-]+)([mix]*)-?([mix]*)/ # e.g. /(?i-mx)/
|
39
57
|
regexp_options_toggle(Regexp.last_match(1), Regexp.last_match(2))
|
40
58
|
@num_groups -= 1 # Toggle "groups" should not increase backref group count
|
@@ -1,3 +1,8 @@
|
|
1
|
+
# Load from a separate file to avoid unrescuable SyntaxError
|
2
|
+
if RUBY_VERSION >= '2.4.1'
|
3
|
+
require_relative 'regexp-examples_spec_2.4.1'
|
4
|
+
end
|
5
|
+
|
1
6
|
RSpec.describe Regexp, '#examples' do
|
2
7
|
def self.examples_exist_and_match(*regexps)
|
3
8
|
regexps.each do |regexp|
|
@@ -69,7 +74,7 @@ RSpec.describe Regexp, '#examples' do
|
|
69
74
|
/[abc-e]/,
|
70
75
|
/[^a-zA-Z]/,
|
71
76
|
/[\w]/,
|
72
|
-
/[]]/,
|
77
|
+
/[]]/,
|
73
78
|
/[\]]/,
|
74
79
|
/[\\]/,
|
75
80
|
/[\\\]]/,
|
@@ -92,6 +97,7 @@ RSpec.describe Regexp, '#examples' do
|
|
92
97
|
examples_exist_and_match(
|
93
98
|
/(normal)/,
|
94
99
|
/(?:nocapture)/,
|
100
|
+
/(?:nocapture)(normal) \1/, # Ensure the group counter is correct
|
95
101
|
/(?<name>namedgroup)/,
|
96
102
|
/(?<name>namedgroup) \k<name>/,
|
97
103
|
/(?<name>namedgroup) \k'name'/
|
@@ -268,6 +274,7 @@ RSpec.describe Regexp, '#examples' do
|
|
268
274
|
context 'for comment groups' do
|
269
275
|
examples_exist_and_match(
|
270
276
|
/a(?#comment)b/,
|
277
|
+
/(?#comment)(group1)\1/, # Ensure the group counter is correct
|
271
278
|
/a(?#ugly backslashy\ comment\\\))b/
|
272
279
|
)
|
273
280
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: regexp-examples
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.4.
|
4
|
+
version: 1.4.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tom Lord
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2018-07-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -81,6 +81,7 @@ files:
|
|
81
81
|
- spec/config_spec.rb
|
82
82
|
- spec/helpers.rb
|
83
83
|
- spec/regexp-examples_spec.rb
|
84
|
+
- spec/regexp-examples_spec_2.4.1.rb
|
84
85
|
- spec/regexp-random_example_spec.rb
|
85
86
|
- spec/spec_helper.rb
|
86
87
|
homepage: http://rubygems.org/gems/regexp-examples
|
@@ -103,7 +104,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
103
104
|
version: '0'
|
104
105
|
requirements: []
|
105
106
|
rubyforge_project:
|
106
|
-
rubygems_version: 2.
|
107
|
+
rubygems_version: 2.6.14.1
|
107
108
|
signing_key:
|
108
109
|
specification_version: 4
|
109
110
|
summary: Extends the Regexp class with '#examples' and '#random_example'
|
@@ -111,5 +112,6 @@ test_files:
|
|
111
112
|
- spec/config_spec.rb
|
112
113
|
- spec/helpers.rb
|
113
114
|
- spec/regexp-examples_spec.rb
|
115
|
+
- spec/regexp-examples_spec_2.4.1.rb
|
114
116
|
- spec/regexp-random_example_spec.rb
|
115
117
|
- spec/spec_helper.rb
|