regexp-examples 0.5.2 → 0.5.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/coverage-badge.png +0 -0
- data/lib/regexp-examples/backreferences.rb +2 -0
- data/lib/regexp-examples/groups.rb +10 -0
- data/lib/regexp-examples/parser.rb +21 -17
- data/lib/regexp-examples/version.rb +1 -1
- data/spec/regexp-examples_spec.rb +10 -18
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9a3253848cbd5e95b1b662848d999c23863fcbbf
|
4
|
+
data.tar.gz: b18197c5e6c64813fef50dbb35d1f8d73a9ca703
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2d83e121338b0a2a70d4c9615f33571d782bb026c9fb231b72ae517f0b7a9b78e957874452358566514fac71c082c6d57bd57745f65777d60b1cccc67188e790
|
7
|
+
data.tar.gz: 0ec1e6b521e9a5cf8e6a66ab0674d365829ef4096ece2ff5fb0501126e0f77d05b65b8d5d417f8ddcc03d741f51eb0c73ead5cd6fe0c1cdca72d684482faa232
|
data/README.md
CHANGED
@@ -77,7 +77,7 @@ Using any of the following will raise a RegexpExamples::IllegalSyntax exception:
|
|
77
77
|
|
78
78
|
* Lookarounds, e.g. `/foo(?=bar)/`, `/foo(?!bar)/`, `/(?<=foo)bar/`, `/(?<!foo)bar/`
|
79
79
|
* [Anchors](http://ruby-doc.org/core-2.2.0/Regexp.html#class-Regexp-label-Anchors) (`\b`, `\B`, `\G`, `^`, `\A`, `$`, `\z`, `\Z`), e.g. `/\bword\b/`, `/line1\n^line2/`
|
80
|
-
* However, a special case has been made to allow
|
80
|
+
* However, a special case has been made to allow `^`, `\A` and `\G` at the start of a pattern; and to allow `$`, `\z` and `\Z` at the end of pattern. In such cases, the characters are effectively just ignored.
|
81
81
|
|
82
82
|
(Note: Backreferences are not really "regular" either, but I got these to work with a bit of hackery!)
|
83
83
|
|
data/coverage/coverage-badge.png
CHANGED
Binary file
|
@@ -20,6 +20,8 @@ module RegexpExamples
|
|
20
20
|
full_example.all_subgroups.detect do |subgroup|
|
21
21
|
subgroup.group_id == group_id
|
22
22
|
end || raise(RegexpExamples::BackrefNotFound)
|
23
|
+
# TODO: Regex like /\10/ should match the octal representation of their character code,
|
24
|
+
# if there is no nth grouped subexpression. For example, `/\10/.examples` should return `["\x08"]`
|
23
25
|
end
|
24
26
|
|
25
27
|
end
|
@@ -48,6 +48,16 @@ module RegexpExamples
|
|
48
48
|
end
|
49
49
|
end
|
50
50
|
|
51
|
+
# Used as a workaround for when a grep is expected to be returned,
|
52
|
+
# but there are no results for the group.
|
53
|
+
# i.e. PlaceHolderGroup.new.result == '' == SingleCharGroup.new('').result
|
54
|
+
# (But using PlaceHolderGroup makes it clearer what the intention is!)
|
55
|
+
class PlaceHolderGroup
|
56
|
+
def result
|
57
|
+
[GroupResult.new('')]
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
51
61
|
class CharGroup
|
52
62
|
prepend GroupWithIgnoreCase
|
53
63
|
def initialize(chars, ignorecase)
|
@@ -44,22 +44,22 @@ module RegexpExamples
|
|
44
44
|
group = parse_or_group(repeaters)
|
45
45
|
when '\\'
|
46
46
|
group = parse_after_backslash_group
|
47
|
-
when '^'
|
47
|
+
when '^'
|
48
48
|
if @current_position == 0
|
49
|
-
group =
|
49
|
+
group = PlaceHolderGroup.new # Ignore the "illegal" character
|
50
50
|
else
|
51
|
-
raise IllegalSyntaxError, "Anchors cannot be supported, as they are not regular"
|
51
|
+
raise IllegalSyntaxError, "Anchors ('#{next_char}') cannot be supported, as they are not regular"
|
52
52
|
end
|
53
|
-
when '$'
|
53
|
+
when '$'
|
54
54
|
if @current_position == (regexp_string.length - 1)
|
55
|
-
group =
|
55
|
+
group = PlaceHolderGroup.new # Ignore the "illegal" character
|
56
56
|
else
|
57
|
-
raise IllegalSyntaxError, "Anchors cannot be supported, as they are not regular"
|
57
|
+
raise IllegalSyntaxError, "Anchors ('#{next_char}') cannot be supported, as they are not regular"
|
58
58
|
end
|
59
59
|
when /[#\s]/
|
60
60
|
if @extended
|
61
61
|
parse_extended_whitespace
|
62
|
-
group =
|
62
|
+
group = PlaceHolderGroup.new # Ignore the whitespace/comment
|
63
63
|
else
|
64
64
|
group = parse_single_char_group(next_char)
|
65
65
|
end
|
@@ -103,22 +103,26 @@ module RegexpExamples
|
|
103
103
|
when rest_of_string =~ /\Ap\{([^}]+)\}/ # Named properties
|
104
104
|
@current_position += ($1.length + 2)
|
105
105
|
raise UnsupportedSyntaxError, "Named properties ({\\p#{$1}}) are not yet supported"
|
106
|
-
when
|
106
|
+
when next_char == 'K' # Keep (special lookbehind that CAN be supported safely!)
|
107
|
+
group = PlaceHolderGroup.new
|
108
|
+
when next_char == 'R' # Linebreak
|
109
|
+
group = CharGroup.new(["\r\n", "\n", "\v", "\f", "\r"], @ignorecase) # A bit hacky...
|
110
|
+
when next_char == 'g' # Subexpression call
|
107
111
|
# TODO: Should this be IllegalSyntaxError ?
|
108
112
|
raise UnsupportedSyntaxError, "Subexpression calls (\g) are not yet supported"
|
109
|
-
when
|
110
|
-
raise IllegalSyntaxError, "Anchors cannot be supported, as they are not regular"
|
111
|
-
when
|
113
|
+
when next_char =~ /[bB]/ # Anchors
|
114
|
+
raise IllegalSyntaxError, "Anchors ('\\#{next_char}') cannot be supported, as they are not regular"
|
115
|
+
when next_char =~ /[AG]/ # Start of string
|
112
116
|
if @current_position == 1
|
113
|
-
group =
|
117
|
+
group = PlaceHolderGroup.new
|
114
118
|
else
|
115
|
-
raise IllegalSyntaxError, "Anchors cannot be supported, as they are not regular"
|
119
|
+
raise IllegalSyntaxError, "Anchors ('\\#{next_char}') cannot be supported, as they are not regular"
|
116
120
|
end
|
117
|
-
when
|
121
|
+
when next_char =~ /[zZ]/ # End of string
|
118
122
|
if @current_position == (regexp_string.length - 1)
|
119
|
-
group =
|
123
|
+
group = PlaceHolderGroup.new
|
120
124
|
else
|
121
|
-
raise IllegalSyntaxError, "Anchors cannot be supported, as they are not regular"
|
125
|
+
raise IllegalSyntaxError, "Anchors ('\\#{next_char}') cannot be supported, as they are not regular"
|
122
126
|
end
|
123
127
|
else
|
124
128
|
group = parse_single_char_group( next_char )
|
@@ -182,7 +186,7 @@ module RegexpExamples
|
|
182
186
|
if next_char == ':' # e.g. /(?i:subexpr)/
|
183
187
|
@current_position += 1
|
184
188
|
else
|
185
|
-
return
|
189
|
+
return PlaceHolderGroup.new
|
186
190
|
end
|
187
191
|
when %w(! =).include?(match[2]) # e.g. /(?=lookahead)/, /(?!neglookahead)/
|
188
192
|
raise IllegalSyntaxError, "Lookaheads are not regular; cannot generate examples"
|
@@ -103,23 +103,15 @@ RSpec.describe Regexp, "#examples" do
|
|
103
103
|
end
|
104
104
|
|
105
105
|
context "for escaped characters" do
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
/\t/,
|
116
|
-
/\n/,
|
117
|
-
/\f/,
|
118
|
-
/\a/,
|
119
|
-
/\v/,
|
120
|
-
/\e/,
|
121
|
-
/[\b]/
|
122
|
-
)
|
106
|
+
all_letters = Array('a'..'z') | Array('A'..'Z')
|
107
|
+
special_letters = %w(b c g p u x z A B C G M P Z)
|
108
|
+
valid_letters = all_letters - special_letters
|
109
|
+
|
110
|
+
valid_letters.each do |char|
|
111
|
+
backslash_char = "\\#{char}"
|
112
|
+
examples_exist_and_match( /#{backslash_char}/ )
|
113
|
+
end
|
114
|
+
examples_exist_and_match( /[\b]/ )
|
123
115
|
end
|
124
116
|
|
125
117
|
context "for backreferences" do
|
@@ -158,7 +150,6 @@ RSpec.describe Regexp, "#examples" do
|
|
158
150
|
/(?<!neglookbehind)/,
|
159
151
|
/\bword-boundary/,
|
160
152
|
/no\Bn-word-boundary/,
|
161
|
-
/\Glast-match/,
|
162
153
|
/start-of\A-string/,
|
163
154
|
/start-of^-line/,
|
164
155
|
/end-of\Z-string/,
|
@@ -170,6 +161,7 @@ RSpec.describe Regexp, "#examples" do
|
|
170
161
|
context "ignore start/end anchors if at start/end" do
|
171
162
|
examples_exist_and_match(
|
172
163
|
/\Astart/,
|
164
|
+
/\Glast-match/,
|
173
165
|
/^start/,
|
174
166
|
/end$/,
|
175
167
|
/end\z/,
|
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: 0.5.
|
4
|
+
version: 0.5.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: 2015-02-
|
11
|
+
date: 2015-02-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -86,7 +86,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
86
86
|
version: '0'
|
87
87
|
requirements: []
|
88
88
|
rubyforge_project:
|
89
|
-
rubygems_version: 2.
|
89
|
+
rubygems_version: 2.2.2
|
90
90
|
signing_key:
|
91
91
|
specification_version: 4
|
92
92
|
summary: Extends the Regexp class with '#examples'
|