regexp-examples 0.2.4 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.travis.yml +5 -0
- data/README.md +10 -7
- data/coverage/.resultset.json +151 -79
- data/coverage/index.html +896 -464
- data/lib/regexp-examples/parser.rb +40 -5
- data/lib/regexp-examples/version.rb +1 -1
- data/regexp-examples.gemspec +2 -2
- data/spec/regexp-examples_spec.rb +39 -2
- metadata +4 -3
@@ -36,6 +36,18 @@ module RegexpExamples
|
|
36
36
|
group = parse_or_group(repeaters)
|
37
37
|
when '\\'
|
38
38
|
group = parse_after_backslash_group
|
39
|
+
when '^', 'A'
|
40
|
+
if @current_position == 0
|
41
|
+
group = parse_single_char_group('') # Ignore the "illegal" character
|
42
|
+
else
|
43
|
+
raise IllegalSyntaxError, "Anchors cannot be supported, as they are not regular"
|
44
|
+
end
|
45
|
+
when '$', 'z', 'Z'
|
46
|
+
if @current_position == (regexp_string.length - 1)
|
47
|
+
group = parse_single_char_group('') # Ignore the "illegal" character
|
48
|
+
else
|
49
|
+
raise IllegalSyntaxError, "Anchors cannot be supported, as they are not regular"
|
50
|
+
end
|
39
51
|
else
|
40
52
|
group = parse_single_char_group(char)
|
41
53
|
end
|
@@ -55,15 +67,35 @@ module RegexpExamples
|
|
55
67
|
group = CharGroup.new(
|
56
68
|
BackslashCharMap[regexp_string[@current_position]])
|
57
69
|
when rest_of_string =~ /\A(c|C-)(.)/ # Control character
|
58
|
-
# http://en.wikibooks.org/wiki/Ruby_Programming/Syntax/Literals
|
59
70
|
@current_position += $1.length
|
60
71
|
group = parse_single_char_group( parse_control_character($2) )
|
61
72
|
when rest_of_string =~ /\Ax(\h{1,2})/ # Escape sequence
|
62
73
|
@current_position += $1.length
|
63
74
|
group = parse_single_char_group( parse_escape_sequence($1) )
|
64
|
-
when rest_of_string =~ /\Au(\h{4})/ # Unicode sequence
|
65
|
-
@current_position +=
|
66
|
-
|
75
|
+
when rest_of_string =~ /\Au(\h{4}|\{\h{1,4}\})/ # Unicode sequence
|
76
|
+
@current_position += $1.length
|
77
|
+
sequence = $1.match(/\h{1,4}/)[0] # Strip off "{" and "}"
|
78
|
+
group = parse_single_char_group( parse_unicode_sequence(sequence) )
|
79
|
+
when rest_of_string =~ /\Ap\{([^}]+)\}/ # Named properties
|
80
|
+
@current_position += ($1.length + 2)
|
81
|
+
raise UnsupportedSyntaxError, "Named properties ({\\p#{$1}}) are not yet supported"
|
82
|
+
when rest_of_string =~ /\Ag/ # Subexpression call
|
83
|
+
# TODO: Should this be IllegalSyntaxError ?
|
84
|
+
raise UnsupportedSyntaxError, "Subexpression calls (\g) are not yet supported"
|
85
|
+
when rest_of_string =~ /\A[GbB]/ # Anchors
|
86
|
+
raise IllegalSyntaxError, "Anchors cannot be supported, as they are not regular"
|
87
|
+
when rest_of_string =~ /\AA/ # Start of string
|
88
|
+
if @current_position == 1
|
89
|
+
group = parse_single_char_group('') # Ignore the "illegal" character
|
90
|
+
else
|
91
|
+
raise IllegalSyntaxError, "Anchors cannot be supported, as they are not regular"
|
92
|
+
end
|
93
|
+
when rest_of_string =~ /\A[zZ]/ # End of string
|
94
|
+
if @current_position == (regexp_string.length - 1)
|
95
|
+
group = parse_single_char_group('') # Ignore the "illegal" character
|
96
|
+
else
|
97
|
+
raise IllegalSyntaxError, "Anchors cannot be supported, as they are not regular"
|
98
|
+
end
|
67
99
|
else
|
68
100
|
group = parse_single_char_group( regexp_string[@current_position] )
|
69
101
|
# TODO: What about cases like \A, \z, \Z ?
|
@@ -117,6 +149,9 @@ module RegexpExamples
|
|
117
149
|
end
|
118
150
|
|
119
151
|
def parse_char_group
|
152
|
+
if rest_of_string =~ /\A\[\[:[^:]+:\]\]/
|
153
|
+
raise UnsupportedSyntaxError, "POSIX bracket expressions are not yet implemented"
|
154
|
+
end
|
120
155
|
chars = []
|
121
156
|
@current_position += 1
|
122
157
|
if regexp_string[@current_position] == ']'
|
@@ -166,7 +201,7 @@ module RegexpExamples
|
|
166
201
|
end
|
167
202
|
|
168
203
|
def parse_unicode_sequence(match)
|
169
|
-
eval "?\\u#{match}"
|
204
|
+
eval "?\\u{#{match}}"
|
170
205
|
end
|
171
206
|
|
172
207
|
def parse_star_repeater(group)
|
data/regexp-examples.gemspec
CHANGED
@@ -6,7 +6,7 @@ Gem::Specification.new do |s|
|
|
6
6
|
s.date = '2014-11-04'
|
7
7
|
s.summary = "Extends the Regexp class with '#examples'"
|
8
8
|
s.description =
|
9
|
-
'Regexp#examples returns a list of strings
|
9
|
+
'Regexp#examples returns a list of strings that are matched by the regex'
|
10
10
|
s.authors = ['Tom Lord']
|
11
11
|
s.email = 'lord.thom@gmail.com'
|
12
12
|
s.files = `git ls-files -z`.split("\x0")
|
@@ -18,5 +18,5 @@ Gem::Specification.new do |s|
|
|
18
18
|
s.add_development_dependency "bundler", "~> 1.7"
|
19
19
|
s.add_development_dependency "rake", "~> 10.0"
|
20
20
|
s.license = 'MIT'
|
21
|
-
s.required_ruby_version = '>=
|
21
|
+
s.required_ruby_version = '>= 2.0.0'
|
22
22
|
end
|
@@ -21,6 +21,14 @@ RSpec.describe Regexp, "#examples" do
|
|
21
21
|
end
|
22
22
|
end
|
23
23
|
|
24
|
+
def self.examples_raise_unsupported_syntax_error(*regexps)
|
25
|
+
regexps.each do |regexp|
|
26
|
+
it do
|
27
|
+
expect{regexp.examples}.to raise_error RegexpExamples::UnsupportedSyntaxError
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
24
32
|
context 'returns matching strings' do
|
25
33
|
context "for basic repeaters" do
|
26
34
|
examples_exist_and_match(
|
@@ -118,7 +126,35 @@ RSpec.describe Regexp, "#examples" do
|
|
118
126
|
/(?=lookahead)/,
|
119
127
|
/(?!neglookahead)/,
|
120
128
|
/(?<=lookbehind)/,
|
121
|
-
/(?<!neglookbehind)
|
129
|
+
/(?<!neglookbehind)/,
|
130
|
+
/\bword-boundary/,
|
131
|
+
/no\Bn-word-boundary/,
|
132
|
+
/\Glast-match/,
|
133
|
+
/start-of\A-string/,
|
134
|
+
/start-of^-line/,
|
135
|
+
/end-of\Z-string/,
|
136
|
+
/end-of\z-string/,
|
137
|
+
/end-of$-line/
|
138
|
+
)
|
139
|
+
end
|
140
|
+
|
141
|
+
context "ignore start/end anchors if at start/end" do
|
142
|
+
examples_exist_and_match(
|
143
|
+
/\Astart/,
|
144
|
+
/^start/,
|
145
|
+
/end$/,
|
146
|
+
/end\z/,
|
147
|
+
/end\Z/
|
148
|
+
)
|
149
|
+
end
|
150
|
+
|
151
|
+
context "for unsupported syntax" do
|
152
|
+
examples_raise_unsupported_syntax_error(
|
153
|
+
/\p{L}/,
|
154
|
+
/\p{Arabic}/,
|
155
|
+
/\p{^Ll}/,
|
156
|
+
/(?<name> ... \g<name>*)/,
|
157
|
+
/[[:space:]]/
|
122
158
|
)
|
123
159
|
end
|
124
160
|
|
@@ -147,7 +183,8 @@ RSpec.describe Regexp, "#examples" do
|
|
147
183
|
context "for unicode sequences" do
|
148
184
|
examples_exist_and_match(
|
149
185
|
/\u6829/,
|
150
|
-
/\uabcd
|
186
|
+
/\uabcd/,
|
187
|
+
/\u{42}word/
|
151
188
|
)
|
152
189
|
end
|
153
190
|
|
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.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tom Lord
|
@@ -38,7 +38,7 @@ dependencies:
|
|
38
38
|
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '10.0'
|
41
|
-
description: Regexp#examples returns a list of strings
|
41
|
+
description: Regexp#examples returns a list of strings that are matched by the regex
|
42
42
|
email: lord.thom@gmail.com
|
43
43
|
executables: []
|
44
44
|
extensions: []
|
@@ -46,6 +46,7 @@ extra_rdoc_files: []
|
|
46
46
|
files:
|
47
47
|
- ".gitignore"
|
48
48
|
- ".rspec"
|
49
|
+
- ".travis.yml"
|
49
50
|
- Gemfile
|
50
51
|
- LICENSE.txt
|
51
52
|
- README.md
|
@@ -104,7 +105,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
104
105
|
requirements:
|
105
106
|
- - ">="
|
106
107
|
- !ruby/object:Gem::Version
|
107
|
-
version:
|
108
|
+
version: 2.0.0
|
108
109
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
109
110
|
requirements:
|
110
111
|
- - ">="
|