regexp-examples 0.2.2 → 0.2.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +1 -1
- data/coverage/.resultset.json +89 -69
- data/coverage/coverage-badge.png +0 -0
- data/coverage/index.html +481 -361
- data/lib/regexp-examples/parser.rb +9 -1
- data/lib/regexp-examples/repeaters.rb +1 -1
- data/lib/regexp-examples/version.rb +1 -1
- data/spec/regexp-examples_spec.rb +12 -0
- metadata +2 -2
@@ -54,6 +54,9 @@ module RegexpExamples
|
|
54
54
|
when BackslashCharMap.keys.include?(regexp_string[@current_position])
|
55
55
|
group = CharGroup.new(
|
56
56
|
BackslashCharMap[regexp_string[@current_position]])
|
57
|
+
when rest_of_string =~ /\Ac(.)/ # Control character
|
58
|
+
@current_position += 1
|
59
|
+
group = parse_single_char_group( parse_control_character($1) )
|
57
60
|
# TODO: There are also a bunch of multi-char matches to watch out for:
|
58
61
|
# http://en.wikibooks.org/wiki/Ruby_Programming/Syntax/Literals
|
59
62
|
else
|
@@ -148,6 +151,11 @@ module RegexpExamples
|
|
148
151
|
BackReferenceGroup.new(match)
|
149
152
|
end
|
150
153
|
|
154
|
+
def parse_control_character(char)
|
155
|
+
# TODO: Is there a better way of doing this? I.e. not just brute-force
|
156
|
+
(0..255).detect { |x| x.chr =~ Regexp.new("\\c#{char}") }.chr
|
157
|
+
end
|
158
|
+
|
151
159
|
def parse_star_repeater(group)
|
152
160
|
@current_position += 1
|
153
161
|
StarRepeater.new(group)
|
@@ -164,7 +172,7 @@ module RegexpExamples
|
|
164
172
|
end
|
165
173
|
|
166
174
|
def parse_range_repeater(group)
|
167
|
-
match = rest_of_string.match(/\A\{(\d+)(,)?(\d+)?\}/)
|
175
|
+
match = rest_of_string.match(/\A\{(\d+)?(,)?(\d+)?\}/)
|
168
176
|
@current_position += match[0].size
|
169
177
|
min = match[1].to_i if match[1]
|
170
178
|
has_comma = !match[2].nil?
|
@@ -30,6 +30,7 @@ RSpec.describe Regexp, "#examples" do
|
|
30
30
|
/a?/,
|
31
31
|
/a{1}/,
|
32
32
|
/a{1,}/,
|
33
|
+
/a{,2}/,
|
33
34
|
/a{1,2}/
|
34
35
|
)
|
35
36
|
end
|
@@ -120,5 +121,16 @@ RSpec.describe Regexp, "#examples" do
|
|
120
121
|
/(?<!neglookbehind)/
|
121
122
|
)
|
122
123
|
end
|
124
|
+
|
125
|
+
context "for control characters" do
|
126
|
+
examples_exist_and_match(
|
127
|
+
/\ca/,
|
128
|
+
/\cZ/,
|
129
|
+
/\c9/,
|
130
|
+
/\c[/,
|
131
|
+
/\c#/,
|
132
|
+
/\c?/
|
133
|
+
)
|
134
|
+
end
|
123
135
|
end
|
124
136
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: regexp-examples
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tom Lord
|
@@ -112,7 +112,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
112
112
|
version: '0'
|
113
113
|
requirements: []
|
114
114
|
rubyforge_project:
|
115
|
-
rubygems_version: 2.
|
115
|
+
rubygems_version: 2.2.2
|
116
116
|
signing_key:
|
117
117
|
specification_version: 4
|
118
118
|
summary: Extends the Regexp class with '#examples'
|