regexp_parser 1.6.0 → 1.8.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +57 -0
- data/Gemfile +1 -1
- data/README.md +24 -12
- data/lib/regexp_parser/expression.rb +6 -2
- data/lib/regexp_parser/expression/methods/match_length.rb +1 -1
- data/lib/regexp_parser/expression/methods/traverse.rb +3 -1
- data/lib/regexp_parser/lexer.rb +4 -4
- data/lib/regexp_parser/parser.rb +18 -12
- data/lib/regexp_parser/scanner.rb +1023 -992
- data/lib/regexp_parser/scanner/scanner.rl +42 -18
- data/lib/regexp_parser/syntax/version_lookup.rb +2 -2
- data/lib/regexp_parser/version.rb +1 -1
- data/regexp_parser.gemspec +1 -1
- data/spec/expression/methods/match_length_spec.rb +7 -0
- data/spec/expression/methods/traverse_spec.rb +21 -0
- data/spec/expression/options_spec.rb +33 -33
- data/spec/lexer/delimiters_spec.rb +68 -0
- data/spec/parser/options_spec.rb +28 -0
- data/spec/parser/quantifiers_spec.rb +1 -0
- data/spec/scanner/delimiters_spec.rb +52 -0
- data/spec/scanner/errors_spec.rb +0 -1
- data/spec/scanner/escapes_spec.rb +4 -0
- data/spec/scanner/free_space_spec.rb +32 -0
- data/spec/scanner/options_spec.rb +36 -0
- metadata +67 -59
data/spec/scanner/errors_spec.rb
CHANGED
@@ -10,7 +10,6 @@ RSpec.describe(Regexp::Scanner) do
|
|
10
10
|
include_examples 'scan error', RS::PrematureEndError, 'unbalanced set', '[a'
|
11
11
|
include_examples 'scan error', RS::PrematureEndError, 'unbalanced set', '[[:alpha:]'
|
12
12
|
include_examples 'scan error', RS::PrematureEndError, 'unbalanced group', '(abc'
|
13
|
-
include_examples 'scan error', RS::PrematureEndError, 'unbalanced interval', 'a{1,2'
|
14
13
|
include_examples 'scan error', RS::PrematureEndError, 'eof in property', '\p{asci'
|
15
14
|
include_examples 'scan error', RS::PrematureEndError, 'incomplete property', '\p{ascii abc'
|
16
15
|
include_examples 'scan error', RS::PrematureEndError, 'eof options', '(?mix'
|
@@ -13,6 +13,10 @@ RSpec.describe('Escape scanning') do
|
|
13
13
|
|
14
14
|
include_examples 'scan', 'c\qt', 1 => [:escape, :literal, '\q', 1, 3]
|
15
15
|
|
16
|
+
# these incomplete ref/call sequences are treated as literal escapes by Ruby
|
17
|
+
include_examples 'scan', 'c\gt', 1 => [:escape, :literal, '\g', 1, 3]
|
18
|
+
include_examples 'scan', 'c\kt', 1 => [:escape, :literal, '\k', 1, 3]
|
19
|
+
|
16
20
|
include_examples 'scan', 'a\012c', 1 => [:escape, :octal, '\012', 1, 5]
|
17
21
|
include_examples 'scan', 'a\0124', 1 => [:escape, :octal, '\012', 1, 5]
|
18
22
|
include_examples 'scan', '\712+7', 0 => [:escape, :octal, '\712', 0, 4]
|
@@ -39,6 +39,17 @@ RSpec.describe('FreeSpace scanning') do
|
|
39
39
|
11 => [:free_space, :comment, "# B ? comment\n", 37, 51],
|
40
40
|
17 => [:free_space, :comment, "# C {2,3} comment\n", 66, 84],
|
41
41
|
29 => [:free_space, :comment, "# D|E comment\n", 100, 114]
|
42
|
+
|
43
|
+
# single line / no trailing newline (c.f. issue #66)
|
44
|
+
include_examples 'scan', /a # b/x,
|
45
|
+
0 => [:literal, :literal, 'a', 0, 1],
|
46
|
+
1 => [:free_space, :whitespace, ' ', 1, 2],
|
47
|
+
2 => [:free_space, :comment, "# b", 2, 5]
|
48
|
+
|
49
|
+
# without spaces (c.f. issue #66)
|
50
|
+
include_examples 'scan', /a#b/x,
|
51
|
+
0 => [:literal, :literal, 'a', 0, 1],
|
52
|
+
1 => [:free_space, :comment, "#b", 1, 3]
|
42
53
|
end
|
43
54
|
|
44
55
|
describe('scan free space inlined') do
|
@@ -130,4 +141,25 @@ RSpec.describe('FreeSpace scanning') do
|
|
130
141
|
26 => [:literal, :literal, 'i j', 35, 38],
|
131
142
|
27 => [:group, :close, ')', 38, 39]
|
132
143
|
end
|
144
|
+
|
145
|
+
describe('scanning `#` in regular (non-x mode)') do # c.f. issue 70
|
146
|
+
include_examples 'scan', /a#bcd/,
|
147
|
+
0 => [:literal, :literal, 'a#bcd', 0, 5]
|
148
|
+
include_examples 'scan', /a # bcd/,
|
149
|
+
0 => [:literal, :literal, 'a # bcd', 0, 7]
|
150
|
+
|
151
|
+
include_examples 'scan', /a#\d/,
|
152
|
+
0 => [:literal, :literal, 'a#', 0, 2],
|
153
|
+
1 => [:type, :digit, '\d', 2, 4]
|
154
|
+
include_examples 'scan', /a # \d/,
|
155
|
+
0 => [:literal, :literal, 'a # ', 0, 4],
|
156
|
+
1 => [:type, :digit, '\d', 4, 6]
|
157
|
+
|
158
|
+
include_examples 'scan', /a#()/,
|
159
|
+
0 => [:literal, :literal, 'a#', 0, 2],
|
160
|
+
1 => [:group, :capture, '(', 2, 3]
|
161
|
+
include_examples 'scan', /a # ()/,
|
162
|
+
0 => [:literal, :literal, 'a # ', 0, 4],
|
163
|
+
1 => [:group, :capture, '(', 4, 5]
|
164
|
+
end
|
133
165
|
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
RSpec.describe('passing options to scan') do
|
4
|
+
def expect_type_tokens(tokens, type_tokens)
|
5
|
+
expect(tokens.map { |type, token, *| [type, token] }).to eq(type_tokens)
|
6
|
+
end
|
7
|
+
|
8
|
+
it 'raises if if scanning from a Regexp and options are passed' do
|
9
|
+
expect { RS.scan(/a+/, options: ::Regexp::EXTENDED) }.to raise_error(
|
10
|
+
ArgumentError,
|
11
|
+
'options cannot be supplied unless scanning a String'
|
12
|
+
)
|
13
|
+
end
|
14
|
+
|
15
|
+
it 'sets free_spacing based on options if scanning from a String' do
|
16
|
+
expect_type_tokens(
|
17
|
+
RS.scan('a+#c', options: ::Regexp::MULTILINE | ::Regexp::EXTENDED),
|
18
|
+
[
|
19
|
+
%i[literal literal],
|
20
|
+
%i[quantifier one_or_more],
|
21
|
+
%i[free_space comment]
|
22
|
+
]
|
23
|
+
)
|
24
|
+
end
|
25
|
+
|
26
|
+
it 'does not set free_spacing if scanning from a String and passing no options' do
|
27
|
+
expect_type_tokens(
|
28
|
+
RS.scan('a+#c'),
|
29
|
+
[
|
30
|
+
%i[literal literal],
|
31
|
+
%i[quantifier one_or_more],
|
32
|
+
%i[literal literal]
|
33
|
+
]
|
34
|
+
)
|
35
|
+
end
|
36
|
+
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: 1.
|
4
|
+
version: 1.8.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ammar Ali
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2020-10-11 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: A library for tokenizing, lexing, and parsing Ruby regular expressions.
|
14
14
|
email:
|
@@ -109,6 +109,7 @@ files:
|
|
109
109
|
- spec/expression/to_s_spec.rb
|
110
110
|
- spec/lexer/all_spec.rb
|
111
111
|
- spec/lexer/conditionals_spec.rb
|
112
|
+
- spec/lexer/delimiters_spec.rb
|
112
113
|
- spec/lexer/escapes_spec.rb
|
113
114
|
- spec/lexer/keep_spec.rb
|
114
115
|
- spec/lexer/literals_spec.rb
|
@@ -123,6 +124,7 @@ files:
|
|
123
124
|
- spec/parser/free_space_spec.rb
|
124
125
|
- spec/parser/groups_spec.rb
|
125
126
|
- spec/parser/keep_spec.rb
|
127
|
+
- spec/parser/options_spec.rb
|
126
128
|
- spec/parser/posix_classes_spec.rb
|
127
129
|
- spec/parser/properties_spec.rb
|
128
130
|
- spec/parser/quantifiers_spec.rb
|
@@ -134,6 +136,7 @@ files:
|
|
134
136
|
- spec/scanner/all_spec.rb
|
135
137
|
- spec/scanner/anchors_spec.rb
|
136
138
|
- spec/scanner/conditionals_spec.rb
|
139
|
+
- spec/scanner/delimiters_spec.rb
|
137
140
|
- spec/scanner/errors_spec.rb
|
138
141
|
- spec/scanner/escapes_spec.rb
|
139
142
|
- spec/scanner/free_space_spec.rb
|
@@ -141,6 +144,7 @@ files:
|
|
141
144
|
- spec/scanner/keep_spec.rb
|
142
145
|
- spec/scanner/literals_spec.rb
|
143
146
|
- spec/scanner/meta_spec.rb
|
147
|
+
- spec/scanner/options_spec.rb
|
144
148
|
- spec/scanner/properties_spec.rb
|
145
149
|
- spec/scanner/quantifiers_spec.rb
|
146
150
|
- spec/scanner/refcalls_spec.rb
|
@@ -164,7 +168,7 @@ licenses:
|
|
164
168
|
- MIT
|
165
169
|
metadata:
|
166
170
|
issue_tracker: https://github.com/ammar/regexp_parser/issues
|
167
|
-
post_install_message:
|
171
|
+
post_install_message:
|
168
172
|
rdoc_options:
|
169
173
|
- "--inline-source"
|
170
174
|
- "--charset=UTF-8"
|
@@ -174,82 +178,86 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
174
178
|
requirements:
|
175
179
|
- - ">="
|
176
180
|
- !ruby/object:Gem::Version
|
177
|
-
version:
|
181
|
+
version: 2.0.0
|
178
182
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
179
183
|
requirements:
|
180
184
|
- - ">="
|
181
185
|
- !ruby/object:Gem::Version
|
182
186
|
version: '0'
|
183
187
|
requirements: []
|
184
|
-
rubygems_version: 3.0.
|
185
|
-
signing_key:
|
188
|
+
rubygems_version: 3.2.0.rc.1
|
189
|
+
signing_key:
|
186
190
|
specification_version: 4
|
187
191
|
summary: Scanner, lexer, parser for ruby's regular expressions
|
188
192
|
test_files:
|
189
|
-
- spec/
|
190
|
-
- spec/
|
191
|
-
- spec/
|
192
|
-
- spec/
|
193
|
+
- spec/expression/base_spec.rb
|
194
|
+
- spec/expression/clone_spec.rb
|
195
|
+
- spec/expression/conditional_spec.rb
|
196
|
+
- spec/expression/free_space_spec.rb
|
197
|
+
- spec/expression/methods/match_length_spec.rb
|
198
|
+
- spec/expression/methods/match_spec.rb
|
199
|
+
- spec/expression/methods/strfregexp_spec.rb
|
200
|
+
- spec/expression/methods/tests_spec.rb
|
201
|
+
- spec/expression/methods/traverse_spec.rb
|
202
|
+
- spec/expression/options_spec.rb
|
203
|
+
- spec/expression/root_spec.rb
|
204
|
+
- spec/expression/sequence_spec.rb
|
205
|
+
- spec/expression/subexpression_spec.rb
|
206
|
+
- spec/expression/to_h_spec.rb
|
207
|
+
- spec/expression/to_s_spec.rb
|
193
208
|
- spec/lexer/all_spec.rb
|
194
209
|
- spec/lexer/conditionals_spec.rb
|
210
|
+
- spec/lexer/delimiters_spec.rb
|
211
|
+
- spec/lexer/escapes_spec.rb
|
212
|
+
- spec/lexer/keep_spec.rb
|
213
|
+
- spec/lexer/literals_spec.rb
|
195
214
|
- spec/lexer/nesting_spec.rb
|
196
215
|
- spec/lexer/refcalls_spec.rb
|
197
|
-
- spec/lexer/literals_spec.rb
|
198
|
-
- spec/parser/escapes_spec.rb
|
199
|
-
- spec/parser/properties_spec.rb
|
200
|
-
- spec/parser/sets_spec.rb
|
201
|
-
- spec/parser/free_space_spec.rb
|
202
|
-
- spec/parser/keep_spec.rb
|
203
216
|
- spec/parser/all_spec.rb
|
204
|
-
- spec/parser/conditionals_spec.rb
|
205
|
-
- spec/parser/types_spec.rb
|
206
|
-
- spec/parser/anchors_spec.rb
|
207
217
|
- spec/parser/alternation_spec.rb
|
208
|
-
- spec/parser/
|
209
|
-
- spec/parser/
|
210
|
-
- spec/parser/set/intersections_spec.rb
|
218
|
+
- spec/parser/anchors_spec.rb
|
219
|
+
- spec/parser/conditionals_spec.rb
|
211
220
|
- spec/parser/errors_spec.rb
|
212
|
-
- spec/parser/
|
221
|
+
- spec/parser/escapes_spec.rb
|
222
|
+
- spec/parser/free_space_spec.rb
|
213
223
|
- spec/parser/groups_spec.rb
|
224
|
+
- spec/parser/keep_spec.rb
|
225
|
+
- spec/parser/options_spec.rb
|
226
|
+
- spec/parser/posix_classes_spec.rb
|
227
|
+
- spec/parser/properties_spec.rb
|
214
228
|
- spec/parser/quantifiers_spec.rb
|
215
|
-
- spec/
|
216
|
-
- spec/
|
217
|
-
- spec/
|
218
|
-
- spec/
|
219
|
-
- spec/
|
220
|
-
- spec/expression/methods/match_length_spec.rb
|
221
|
-
- spec/expression/methods/traverse_spec.rb
|
222
|
-
- spec/expression/methods/strfregexp_spec.rb
|
223
|
-
- spec/expression/methods/tests_spec.rb
|
224
|
-
- spec/expression/free_space_spec.rb
|
225
|
-
- spec/expression/options_spec.rb
|
226
|
-
- spec/expression/to_s_spec.rb
|
227
|
-
- spec/expression/root_spec.rb
|
228
|
-
- spec/expression/sequence_spec.rb
|
229
|
-
- spec/expression/clone_spec.rb
|
230
|
-
- spec/expression/to_h_spec.rb
|
231
|
-
- spec/expression/conditional_spec.rb
|
232
|
-
- spec/expression/base_spec.rb
|
233
|
-
- spec/syntax/syntax_spec.rb
|
234
|
-
- spec/syntax/syntax_token_map_spec.rb
|
235
|
-
- spec/syntax/versions/1.9.3_spec.rb
|
236
|
-
- spec/syntax/versions/2.2.0_spec.rb
|
237
|
-
- spec/syntax/versions/1.9.1_spec.rb
|
238
|
-
- spec/syntax/versions/2.0.0_spec.rb
|
239
|
-
- spec/syntax/versions/1.8.6_spec.rb
|
240
|
-
- spec/syntax/versions/aliases_spec.rb
|
241
|
-
- spec/scanner/escapes_spec.rb
|
242
|
-
- spec/scanner/properties_spec.rb
|
243
|
-
- spec/scanner/sets_spec.rb
|
244
|
-
- spec/scanner/free_space_spec.rb
|
245
|
-
- spec/scanner/keep_spec.rb
|
229
|
+
- spec/parser/refcalls_spec.rb
|
230
|
+
- spec/parser/set/intersections_spec.rb
|
231
|
+
- spec/parser/set/ranges_spec.rb
|
232
|
+
- spec/parser/sets_spec.rb
|
233
|
+
- spec/parser/types_spec.rb
|
246
234
|
- spec/scanner/all_spec.rb
|
247
|
-
- spec/scanner/conditionals_spec.rb
|
248
|
-
- spec/scanner/types_spec.rb
|
249
235
|
- spec/scanner/anchors_spec.rb
|
250
|
-
- spec/scanner/
|
236
|
+
- spec/scanner/conditionals_spec.rb
|
237
|
+
- spec/scanner/delimiters_spec.rb
|
251
238
|
- spec/scanner/errors_spec.rb
|
252
|
-
- spec/scanner/
|
239
|
+
- spec/scanner/escapes_spec.rb
|
240
|
+
- spec/scanner/free_space_spec.rb
|
253
241
|
- spec/scanner/groups_spec.rb
|
242
|
+
- spec/scanner/keep_spec.rb
|
254
243
|
- spec/scanner/literals_spec.rb
|
244
|
+
- spec/scanner/meta_spec.rb
|
245
|
+
- spec/scanner/options_spec.rb
|
246
|
+
- spec/scanner/properties_spec.rb
|
255
247
|
- spec/scanner/quantifiers_spec.rb
|
248
|
+
- spec/scanner/refcalls_spec.rb
|
249
|
+
- spec/scanner/sets_spec.rb
|
250
|
+
- spec/scanner/types_spec.rb
|
251
|
+
- spec/spec_helper.rb
|
252
|
+
- spec/support/runner.rb
|
253
|
+
- spec/support/shared_examples.rb
|
254
|
+
- spec/support/warning_extractor.rb
|
255
|
+
- spec/syntax/syntax_spec.rb
|
256
|
+
- spec/syntax/syntax_token_map_spec.rb
|
257
|
+
- spec/syntax/versions/1.8.6_spec.rb
|
258
|
+
- spec/syntax/versions/1.9.1_spec.rb
|
259
|
+
- spec/syntax/versions/1.9.3_spec.rb
|
260
|
+
- spec/syntax/versions/2.0.0_spec.rb
|
261
|
+
- spec/syntax/versions/2.2.0_spec.rb
|
262
|
+
- spec/syntax/versions/aliases_spec.rb
|
263
|
+
- spec/token/token_spec.rb
|