regexp_parser 1.5.0 → 1.8.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/CHANGELOG.md +59 -0
- data/Gemfile +3 -3
- data/README.md +14 -6
- data/Rakefile +3 -4
- data/lib/regexp_parser/expression.rb +6 -43
- data/lib/regexp_parser/expression/classes/conditional.rb +3 -2
- data/lib/regexp_parser/expression/classes/escape.rb +0 -4
- data/lib/regexp_parser/expression/methods/match.rb +13 -0
- data/lib/regexp_parser/expression/methods/match_length.rb +1 -1
- data/lib/regexp_parser/expression/methods/options.rb +35 -0
- data/lib/regexp_parser/expression/methods/strfregexp.rb +0 -1
- data/lib/regexp_parser/expression/methods/tests.rb +6 -15
- data/lib/regexp_parser/expression/methods/traverse.rb +3 -1
- data/lib/regexp_parser/expression/sequence.rb +3 -2
- data/lib/regexp_parser/expression/sequence_operation.rb +2 -6
- data/lib/regexp_parser/lexer.rb +4 -25
- data/lib/regexp_parser/parser.rb +40 -33
- data/lib/regexp_parser/scanner.rb +1208 -1353
- data/lib/regexp_parser/scanner/char_type.rl +0 -3
- data/lib/regexp_parser/scanner/properties/long.yml +15 -1
- data/lib/regexp_parser/scanner/properties/short.yml +5 -0
- data/lib/regexp_parser/scanner/scanner.rl +116 -202
- data/lib/regexp_parser/syntax/tokens/unicode_property.rb +30 -0
- data/lib/regexp_parser/syntax/versions/2.6.2.rb +10 -0
- data/lib/regexp_parser/syntax/versions/2.6.3.rb +10 -0
- data/lib/regexp_parser/version.rb +1 -1
- data/spec/expression/base_spec.rb +14 -0
- data/spec/expression/methods/match_length_spec.rb +20 -0
- data/spec/expression/methods/match_spec.rb +25 -0
- data/spec/expression/methods/tests_spec.rb +2 -0
- data/spec/expression/methods/traverse_spec.rb +21 -0
- data/spec/expression/options_spec.rb +128 -0
- data/spec/expression/root_spec.rb +9 -0
- data/spec/expression/sequence_spec.rb +9 -0
- data/spec/lexer/conditionals_spec.rb +49 -119
- data/spec/lexer/delimiters_spec.rb +68 -0
- data/spec/lexer/escapes_spec.rb +8 -32
- data/spec/lexer/keep_spec.rb +5 -17
- data/spec/lexer/literals_spec.rb +73 -110
- data/spec/lexer/nesting_spec.rb +86 -117
- data/spec/lexer/refcalls_spec.rb +51 -50
- data/spec/parser/all_spec.rb +13 -1
- data/spec/parser/anchors_spec.rb +9 -23
- data/spec/parser/conditionals_spec.rb +9 -9
- data/spec/parser/errors_spec.rb +22 -43
- data/spec/parser/escapes_spec.rb +33 -44
- data/spec/parser/free_space_spec.rb +25 -4
- data/spec/parser/groups_spec.rb +98 -257
- data/spec/parser/keep_spec.rb +2 -15
- data/spec/parser/options_spec.rb +28 -0
- data/spec/parser/posix_classes_spec.rb +5 -24
- data/spec/parser/properties_spec.rb +42 -54
- data/spec/parser/quantifiers_spec.rb +42 -283
- data/spec/parser/refcalls_spec.rb +60 -185
- data/spec/parser/set/intersections_spec.rb +17 -17
- data/spec/parser/set/ranges_spec.rb +17 -17
- data/spec/parser/sets_spec.rb +5 -5
- data/spec/parser/types_spec.rb +11 -36
- data/spec/scanner/anchors_spec.rb +13 -28
- data/spec/scanner/conditionals_spec.rb +121 -173
- data/spec/scanner/delimiters_spec.rb +52 -0
- data/spec/scanner/errors_spec.rb +64 -87
- data/spec/scanner/escapes_spec.rb +53 -50
- data/spec/scanner/free_space_spec.rb +102 -165
- data/spec/scanner/groups_spec.rb +45 -64
- data/spec/scanner/keep_spec.rb +5 -28
- data/spec/scanner/literals_spec.rb +45 -81
- data/spec/scanner/meta_spec.rb +13 -33
- data/spec/scanner/options_spec.rb +36 -0
- data/spec/scanner/properties_spec.rb +43 -286
- data/spec/scanner/quantifiers_spec.rb +13 -28
- data/spec/scanner/refcalls_spec.rb +32 -48
- data/spec/scanner/sets_spec.rb +88 -102
- data/spec/scanner/types_spec.rb +10 -25
- data/spec/spec_helper.rb +1 -0
- data/spec/support/shared_examples.rb +77 -0
- data/spec/syntax/syntax_spec.rb +4 -0
- data/spec/syntax/versions/1.8.6_spec.rb +12 -33
- data/spec/syntax/versions/1.9.1_spec.rb +5 -18
- data/spec/syntax/versions/1.9.3_spec.rb +4 -17
- data/spec/syntax/versions/2.0.0_spec.rb +8 -23
- data/spec/syntax/versions/2.2.0_spec.rb +4 -17
- data/spec/syntax/versions/aliases_spec.rb +27 -109
- metadata +28 -10
- data/spec/scanner/scripts_spec.rb +0 -49
- data/spec/scanner/unicode_blocks_spec.rb +0 -28
@@ -1,293 +1,52 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
RSpec.describe('Quantifier parsing') do
|
4
|
-
|
5
|
-
|
6
|
-
|
4
|
+
RSpec.shared_examples 'quantifier' do |pattern, text, mode, token, min, max|
|
5
|
+
it "parses the quantifier in #{pattern} as #{mode} #{token}" do
|
6
|
+
root = RP.parse(pattern, '*')
|
7
|
+
exp = root[0]
|
8
|
+
|
9
|
+
expect(exp).to be_quantified
|
10
|
+
expect(exp.quantifier.token).to eq token
|
11
|
+
expect(exp.quantifier.min).to eq min
|
12
|
+
expect(exp.quantifier.max).to eq max
|
13
|
+
expect(exp.quantifier.mode).to eq mode
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
include_examples 'quantifier', /a?b/, '?', :greedy, :zero_or_one, 0, 1
|
18
|
+
include_examples 'quantifier', /a??b/, '??', :reluctant, :zero_or_one, 0, 1
|
19
|
+
include_examples 'quantifier', /a?+b/, '?+', :possessive, :zero_or_one, 0, 1
|
20
|
+
include_examples 'quantifier', /a*b/, '*', :greedy, :zero_or_more, 0, -1
|
21
|
+
include_examples 'quantifier', /a*?b/, '*?', :reluctant, :zero_or_more, 0, -1
|
22
|
+
include_examples 'quantifier', /a*+b/, '*+', :possessive, :zero_or_more, 0, -1
|
23
|
+
include_examples 'quantifier', /a+b/, '+', :greedy, :one_or_more, 1, -1
|
24
|
+
include_examples 'quantifier', /a+?b/, '+?', :reluctant, :one_or_more, 1, -1
|
25
|
+
include_examples 'quantifier', /a++b/, '++', :possessive, :one_or_more, 1, -1
|
26
|
+
include_examples 'quantifier', /a{2,4}b/, '{2,4}', :greedy, :interval, 2, 4
|
27
|
+
include_examples 'quantifier', /a{2,4}?b/, '{2,4}?', :reluctant, :interval, 2, 4
|
28
|
+
include_examples 'quantifier', /a{2,4}+b/, '{2,4}+', :possessive, :interval, 2, 4
|
29
|
+
include_examples 'quantifier', /a{2,}b/, '{2,}', :greedy, :interval, 2, -1
|
30
|
+
include_examples 'quantifier', /a{2,}?b/, '{2,}?', :reluctant, :interval, 2, -1
|
31
|
+
include_examples 'quantifier', /a{2,}+b/, '{2,}+', :possessive, :interval, 2, -1
|
32
|
+
include_examples 'quantifier', /a{,3}b/, '{,3}', :greedy, :interval, 0, 3
|
33
|
+
include_examples 'quantifier', /a{,3}?b/, '{,3}?', :reluctant, :interval, 0, 3
|
34
|
+
include_examples 'quantifier', /a{,3}+b/, '{,3}+', :possessive, :interval, 0, 3
|
35
|
+
include_examples 'quantifier', /a{4}b/, '{4}', :greedy, :interval, 4, 4
|
36
|
+
include_examples 'quantifier', /a{4}?b/, '{4}?', :reluctant, :interval, 4, 4
|
37
|
+
include_examples 'quantifier', /a{4}+b/, '{4}+', :possessive, :interval, 4, 4
|
38
|
+
include_examples 'quantifier', /a{004}+b/, '{004}+', :possessive, :interval, 4, 4
|
39
|
+
|
40
|
+
specify('mode-checking methods') do
|
41
|
+
exp = RP.parse(/a??/).first
|
7
42
|
|
8
|
-
expect(exp).to be_quantified
|
9
|
-
expect(exp.quantifier.token).to eq :zero_or_one
|
10
|
-
expect(exp.quantifier.min).to eq 0
|
11
|
-
expect(exp.quantifier.max).to eq 1
|
12
|
-
expect(exp.quantifier.mode).to eq :greedy
|
13
|
-
expect(exp.quantifier).to be_greedy
|
14
|
-
expect(exp).to be_greedy
|
15
|
-
|
16
|
-
expect(exp.quantifier).not_to be_reluctant
|
17
|
-
expect(exp).not_to be_reluctant
|
18
|
-
expect(exp.quantifier).not_to be_possessive
|
19
|
-
expect(exp).not_to be_possessive
|
20
|
-
end
|
21
|
-
|
22
|
-
specify('parse zero or one reluctant') do
|
23
|
-
root = RP.parse('a??bc')
|
24
|
-
exp = root.expressions.first
|
25
|
-
|
26
|
-
expect(exp).to be_quantified
|
27
|
-
expect(exp.quantifier.token).to eq :zero_or_one
|
28
|
-
expect(exp.quantifier.min).to eq 0
|
29
|
-
expect(exp.quantifier.max).to eq 1
|
30
|
-
expect(exp.quantifier.mode).to eq :reluctant
|
31
|
-
expect(exp.quantifier).to be_reluctant
|
32
43
|
expect(exp).to be_reluctant
|
33
|
-
|
34
|
-
expect(exp.quantifier).not_to be_greedy
|
44
|
+
expect(exp).to be_lazy
|
35
45
|
expect(exp).not_to be_greedy
|
36
|
-
expect(exp.quantifier).not_to be_possessive
|
37
46
|
expect(exp).not_to be_possessive
|
38
|
-
end
|
39
|
-
|
40
|
-
specify('parse zero or one possessive') do
|
41
|
-
root = RP.parse('a?+bc', 'ruby/1.9')
|
42
|
-
exp = root.expressions.first
|
43
|
-
|
44
|
-
expect(exp).to be_quantified
|
45
|
-
expect(exp.quantifier.token).to eq :zero_or_one
|
46
|
-
expect(exp.quantifier.min).to eq 0
|
47
|
-
expect(exp.quantifier.max).to eq 1
|
48
|
-
expect(exp.quantifier.mode).to eq :possessive
|
49
|
-
expect(exp.quantifier).to be_possessive
|
50
|
-
expect(exp).to be_possessive
|
51
|
-
|
52
|
-
expect(exp.quantifier).not_to be_greedy
|
53
|
-
expect(exp).not_to be_greedy
|
54
|
-
expect(exp.quantifier).not_to be_reluctant
|
55
|
-
expect(exp).not_to be_reluctant
|
56
|
-
end
|
57
|
-
|
58
|
-
specify('parse zero or more greedy') do
|
59
|
-
root = RP.parse('a*bc')
|
60
|
-
exp = root.expressions.first
|
61
|
-
|
62
|
-
expect(exp).to be_quantified
|
63
|
-
expect(exp.quantifier.token).to eq :zero_or_more
|
64
|
-
expect(exp.quantifier.min).to eq 0
|
65
|
-
expect(exp.quantifier.max).to eq(-1)
|
66
|
-
expect(exp.quantifier.mode).to eq :greedy
|
67
|
-
expect(exp.quantifier).to be_greedy
|
68
|
-
expect(exp).to be_greedy
|
69
|
-
end
|
70
|
-
|
71
|
-
specify('parse zero or more reluctant') do
|
72
|
-
root = RP.parse('a*?bc')
|
73
|
-
exp = root.expressions.first
|
74
|
-
|
75
|
-
expect(exp).to be_quantified
|
76
|
-
expect(exp.quantifier.token).to eq :zero_or_more
|
77
|
-
expect(exp.quantifier.min).to eq 0
|
78
|
-
expect(exp.quantifier.max).to eq(-1)
|
79
|
-
expect(exp.quantifier.mode).to eq :reluctant
|
80
47
|
expect(exp.quantifier).to be_reluctant
|
81
|
-
expect(exp).to
|
82
|
-
|
83
|
-
|
84
|
-
specify('parse zero or more possessive') do
|
85
|
-
root = RP.parse('a*+bc', 'ruby/1.9')
|
86
|
-
exp = root.expressions.first
|
87
|
-
|
88
|
-
expect(exp).to be_quantified
|
89
|
-
expect(exp.quantifier.token).to eq :zero_or_more
|
90
|
-
expect(exp.quantifier.min).to eq 0
|
91
|
-
expect(exp.quantifier.max).to eq(-1)
|
92
|
-
expect(exp.quantifier.mode).to eq :possessive
|
93
|
-
expect(exp.quantifier).to be_possessive
|
94
|
-
expect(exp).to be_possessive
|
95
|
-
end
|
96
|
-
|
97
|
-
specify('parse one or more greedy') do
|
98
|
-
root = RP.parse('a+bc')
|
99
|
-
exp = root.expressions.first
|
100
|
-
|
101
|
-
expect(exp).to be_quantified
|
102
|
-
expect(exp.quantifier.token).to eq :one_or_more
|
103
|
-
expect(exp.quantifier.min).to eq 1
|
104
|
-
expect(exp.quantifier.max).to eq(-1)
|
105
|
-
expect(exp.quantifier.mode).to eq :greedy
|
106
|
-
expect(exp.quantifier).to be_greedy
|
107
|
-
expect(exp).to be_greedy
|
108
|
-
end
|
109
|
-
|
110
|
-
specify('parse one or more reluctant') do
|
111
|
-
root = RP.parse('a+?bc')
|
112
|
-
exp = root.expressions.first
|
113
|
-
|
114
|
-
expect(exp).to be_quantified
|
115
|
-
expect(exp.quantifier.token).to eq :one_or_more
|
116
|
-
expect(exp.quantifier.min).to eq 1
|
117
|
-
expect(exp.quantifier.max).to eq(-1)
|
118
|
-
expect(exp.quantifier.mode).to eq :reluctant
|
119
|
-
expect(exp.quantifier).to be_reluctant
|
120
|
-
expect(exp).to be_reluctant
|
121
|
-
end
|
122
|
-
|
123
|
-
specify('parse one or more possessive') do
|
124
|
-
root = RP.parse('a++bc', 'ruby/1.9')
|
125
|
-
exp = root.expressions.first
|
126
|
-
|
127
|
-
expect(exp).to be_quantified
|
128
|
-
expect(exp.quantifier.token).to eq :one_or_more
|
129
|
-
expect(exp.quantifier.min).to eq 1
|
130
|
-
expect(exp.quantifier.max).to eq(-1)
|
131
|
-
expect(exp.quantifier.mode).to eq :possessive
|
132
|
-
expect(exp.quantifier).to be_possessive
|
133
|
-
expect(exp).to be_possessive
|
134
|
-
end
|
135
|
-
|
136
|
-
specify('parse intervals min max greedy') do
|
137
|
-
root = RP.parse('a{2,4}bc')
|
138
|
-
exp = root.expressions.first
|
139
|
-
|
140
|
-
expect(exp).to be_quantified
|
141
|
-
expect(exp.quantifier.token).to eq :interval
|
142
|
-
expect(exp.quantifier.min).to eq 2
|
143
|
-
expect(exp.quantifier.max).to eq 4
|
144
|
-
expect(exp.quantifier.mode).to eq :greedy
|
145
|
-
expect(exp.quantifier).to be_greedy
|
146
|
-
expect(exp).to be_greedy
|
147
|
-
end
|
148
|
-
|
149
|
-
specify('parse intervals min max reluctant') do
|
150
|
-
root = RP.parse('a{3,5}?bc')
|
151
|
-
exp = root.expressions.first
|
152
|
-
|
153
|
-
expect(exp).to be_quantified
|
154
|
-
expect(exp.quantifier.token).to eq :interval
|
155
|
-
expect(exp.quantifier.min).to eq 3
|
156
|
-
expect(exp.quantifier.max).to eq 5
|
157
|
-
expect(exp.quantifier.mode).to eq :reluctant
|
158
|
-
expect(exp.quantifier).to be_reluctant
|
159
|
-
expect(exp).to be_reluctant
|
160
|
-
end
|
161
|
-
|
162
|
-
specify('parse intervals min max possessive') do
|
163
|
-
root = RP.parse('a{2,4}+bc', 'ruby/1.9')
|
164
|
-
exp = root.expressions.first
|
165
|
-
|
166
|
-
expect(exp).to be_quantified
|
167
|
-
expect(exp.quantifier.token).to eq :interval
|
168
|
-
expect(exp.quantifier.min).to eq 2
|
169
|
-
expect(exp.quantifier.max).to eq 4
|
170
|
-
expect(exp.quantifier.mode).to eq :possessive
|
171
|
-
expect(exp.quantifier).to be_possessive
|
172
|
-
expect(exp).to be_possessive
|
173
|
-
end
|
174
|
-
|
175
|
-
specify('parse intervals min only greedy') do
|
176
|
-
root = RP.parse('a{2,}bc')
|
177
|
-
exp = root.expressions.first
|
178
|
-
|
179
|
-
expect(exp).to be_quantified
|
180
|
-
expect(exp.quantifier.token).to eq :interval
|
181
|
-
expect(exp.quantifier.min).to eq 2
|
182
|
-
expect(exp.quantifier.max).to eq(-1)
|
183
|
-
expect(exp.quantifier.mode).to eq :greedy
|
184
|
-
expect(exp.quantifier).to be_greedy
|
185
|
-
expect(exp).to be_greedy
|
186
|
-
end
|
187
|
-
|
188
|
-
specify('parse intervals min only reluctant') do
|
189
|
-
root = RP.parse('a{2,}?bc')
|
190
|
-
exp = root.expressions.first
|
191
|
-
|
192
|
-
expect(exp).to be_quantified
|
193
|
-
expect(exp.quantifier.token).to eq :interval
|
194
|
-
expect(exp.quantifier.text).to eq '{2,}?'
|
195
|
-
expect(exp.quantifier.min).to eq 2
|
196
|
-
expect(exp.quantifier.max).to eq(-1)
|
197
|
-
expect(exp.quantifier.mode).to eq :reluctant
|
198
|
-
expect(exp.quantifier).to be_reluctant
|
199
|
-
expect(exp).to be_reluctant
|
200
|
-
end
|
201
|
-
|
202
|
-
specify('parse intervals min only possessive') do
|
203
|
-
root = RP.parse('a{3,}+bc', 'ruby/1.9')
|
204
|
-
exp = root.expressions.first
|
205
|
-
|
206
|
-
expect(exp).to be_quantified
|
207
|
-
expect(exp.quantifier.token).to eq :interval
|
208
|
-
expect(exp.quantifier.text).to eq '{3,}+'
|
209
|
-
expect(exp.quantifier.min).to eq 3
|
210
|
-
expect(exp.quantifier.max).to eq(-1)
|
211
|
-
expect(exp.quantifier.mode).to eq :possessive
|
212
|
-
expect(exp.quantifier).to be_possessive
|
213
|
-
expect(exp).to be_possessive
|
214
|
-
end
|
215
|
-
|
216
|
-
specify('parse intervals max only greedy') do
|
217
|
-
root = RP.parse('a{,2}bc')
|
218
|
-
exp = root.expressions.first
|
219
|
-
|
220
|
-
expect(exp).to be_quantified
|
221
|
-
expect(exp.quantifier.token).to eq :interval
|
222
|
-
expect(exp.quantifier.min).to eq 0
|
223
|
-
expect(exp.quantifier.max).to eq 2
|
224
|
-
expect(exp.quantifier.mode).to eq :greedy
|
225
|
-
expect(exp.quantifier).to be_greedy
|
226
|
-
expect(exp).to be_greedy
|
227
|
-
end
|
228
|
-
|
229
|
-
specify('parse intervals max only reluctant') do
|
230
|
-
root = RP.parse('a{,4}?bc')
|
231
|
-
exp = root.expressions.first
|
232
|
-
|
233
|
-
expect(exp).to be_quantified
|
234
|
-
expect(exp.quantifier.token).to eq :interval
|
235
|
-
expect(exp.quantifier.min).to eq 0
|
236
|
-
expect(exp.quantifier.max).to eq 4
|
237
|
-
expect(exp.quantifier.mode).to eq :reluctant
|
238
|
-
expect(exp.quantifier).to be_reluctant
|
239
|
-
expect(exp).to be_reluctant
|
240
|
-
end
|
241
|
-
|
242
|
-
specify('parse intervals max only possessive') do
|
243
|
-
root = RP.parse('a{,3}+bc', 'ruby/1.9')
|
244
|
-
exp = root.expressions.first
|
245
|
-
|
246
|
-
expect(exp).to be_quantified
|
247
|
-
expect(exp.quantifier.token).to eq :interval
|
248
|
-
expect(exp.quantifier.min).to eq 0
|
249
|
-
expect(exp.quantifier.max).to eq 3
|
250
|
-
expect(exp.quantifier.mode).to eq :possessive
|
251
|
-
expect(exp.quantifier).to be_possessive
|
252
|
-
expect(exp).to be_possessive
|
253
|
-
end
|
254
|
-
|
255
|
-
specify('parse intervals exact greedy') do
|
256
|
-
root = RP.parse('a{2}bc')
|
257
|
-
exp = root.expressions.first
|
258
|
-
|
259
|
-
expect(exp).to be_quantified
|
260
|
-
expect(exp.quantifier.token).to eq :interval
|
261
|
-
expect(exp.quantifier.min).to eq 2
|
262
|
-
expect(exp.quantifier.max).to eq 2
|
263
|
-
expect(exp.quantifier.mode).to eq :greedy
|
264
|
-
expect(exp.quantifier).to be_greedy
|
265
|
-
expect(exp).to be_greedy
|
266
|
-
end
|
267
|
-
|
268
|
-
specify('parse intervals exact reluctant') do
|
269
|
-
root = RP.parse('a{3}?bc')
|
270
|
-
exp = root.expressions.first
|
271
|
-
|
272
|
-
expect(exp).to be_quantified
|
273
|
-
expect(exp.quantifier.token).to eq :interval
|
274
|
-
expect(exp.quantifier.min).to eq 3
|
275
|
-
expect(exp.quantifier.max).to eq 3
|
276
|
-
expect(exp.quantifier.mode).to eq :reluctant
|
277
|
-
expect(exp.quantifier).to be_reluctant
|
278
|
-
expect(exp).to be_reluctant
|
279
|
-
end
|
280
|
-
|
281
|
-
specify('parse intervals exact possessive') do
|
282
|
-
root = RP.parse('a{3}+bc', 'ruby/1.9')
|
283
|
-
exp = root.expressions.first
|
284
|
-
|
285
|
-
expect(exp).to be_quantified
|
286
|
-
expect(exp.quantifier.token).to eq :interval
|
287
|
-
expect(exp.quantifier.min).to eq 3
|
288
|
-
expect(exp.quantifier.max).to eq 3
|
289
|
-
expect(exp.quantifier.mode).to eq :possessive
|
290
|
-
expect(exp.quantifier).to be_possessive
|
291
|
-
expect(exp).to be_possessive
|
48
|
+
expect(exp.quantifier).to be_lazy
|
49
|
+
expect(exp.quantifier).not_to be_greedy
|
50
|
+
expect(exp.quantifier).not_to be_possessive
|
292
51
|
end
|
293
52
|
end
|
@@ -1,61 +1,66 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
RSpec.describe('Refcall parsing') do
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
4
|
+
include_examples 'parse', /(abc)\1/,
|
5
|
+
1 => [:backref, :number, Backreference::Number, number: 1]
|
6
|
+
|
7
|
+
include_examples 'parse', /(?<X>abc)\k<X>/,
|
8
|
+
1 => [:backref, :name_ref, Backreference::Name, name: 'X']
|
9
|
+
include_examples 'parse', /(?<X>abc)\k'X'/,
|
10
|
+
1 => [:backref, :name_ref, Backreference::Name, name: 'X']
|
11
|
+
|
12
|
+
include_examples 'parse', /(abc)\k<1>/,
|
13
|
+
1 => [:backref, :number_ref, Backreference::Number, number: 1]
|
14
|
+
include_examples 'parse', /(abc)\k'1'/,
|
15
|
+
1 => [:backref, :number_ref, Backreference::Number, number: 1]
|
16
|
+
|
17
|
+
include_examples 'parse', /(abc)\k<-1>/,
|
18
|
+
1 => [:backref, :number_rel_ref, Backreference::NumberRelative, number: -1]
|
19
|
+
include_examples 'parse', /(abc)\k'-1'/,
|
20
|
+
1 => [:backref, :number_rel_ref, Backreference::NumberRelative, number: -1]
|
21
|
+
|
22
|
+
include_examples 'parse', /(?<X>abc)\g<X>/,
|
23
|
+
1 => [:backref, :name_call, Backreference::NameCall, name: 'X']
|
24
|
+
include_examples 'parse', /(?<X>abc)\g'X'/,
|
25
|
+
1 => [:backref, :name_call, Backreference::NameCall, name: 'X']
|
26
|
+
|
27
|
+
include_examples 'parse', /(abc)\g<1>/,
|
28
|
+
1 => [:backref, :number_call, Backreference::NumberCall, number: 1]
|
29
|
+
include_examples 'parse', /(abc)\g'1'/,
|
30
|
+
1 => [:backref, :number_call, Backreference::NumberCall, number: 1]
|
31
|
+
|
32
|
+
include_examples 'parse', /(abc)\g<-1>/,
|
33
|
+
1 => [:backref, :number_rel_call, Backreference::NumberCallRelative, number: -1]
|
34
|
+
include_examples 'parse', /(abc)\g'-1'/,
|
35
|
+
1 => [:backref, :number_rel_call, Backreference::NumberCallRelative, number: -1]
|
36
|
+
|
37
|
+
include_examples 'parse', /\g<+1>(abc)/,
|
38
|
+
0 => [:backref, :number_rel_call, Backreference::NumberCallRelative, number: 1]
|
39
|
+
include_examples 'parse', /\g'+1'(abc)/,
|
40
|
+
0 => [:backref, :number_rel_call, Backreference::NumberCallRelative, number: 1]
|
41
|
+
|
42
|
+
include_examples 'parse', /(?<X>abc)\k<X-0>/,
|
43
|
+
1 => [:backref, :name_recursion_ref, Backreference::NameRecursionLevel,
|
44
|
+
name: 'X', recursion_level: 0]
|
45
|
+
include_examples 'parse', /(?<X>abc)\k'X-0'/,
|
46
|
+
1 => [:backref, :name_recursion_ref, Backreference::NameRecursionLevel,
|
47
|
+
name: 'X', recursion_level: 0]
|
48
|
+
|
49
|
+
include_examples 'parse', /(abc)\k<1-0>/,
|
50
|
+
1 => [:backref, :number_recursion_ref, Backreference::NumberRecursionLevel,
|
51
|
+
number: 1, recursion_level: 0]
|
52
|
+
include_examples 'parse', /(abc)\k'1-0'/,
|
53
|
+
1 => [:backref, :number_recursion_ref, Backreference::NumberRecursionLevel,
|
54
|
+
number: 1, recursion_level: 0]
|
55
|
+
include_examples 'parse', /(abc)\k'-1+0'/,
|
56
|
+
1 => [:backref, :number_recursion_ref, Backreference::NumberRecursionLevel,
|
57
|
+
number: -1, recursion_level: 0]
|
58
|
+
include_examples 'parse', /(abc)\k'1+1'/,
|
59
|
+
1 => [:backref, :number_recursion_ref, Backreference::NumberRecursionLevel,
|
60
|
+
number: 1, recursion_level: 1]
|
61
|
+
include_examples 'parse', /(abc)\k'1-1'/,
|
62
|
+
1 => [:backref, :number_recursion_ref, Backreference::NumberRecursionLevel,
|
63
|
+
number: 1, recursion_level: -1]
|
59
64
|
|
60
65
|
specify('parse backref effective_number') do
|
61
66
|
root = RP.parse('(abc)(def)\\k<-1>(ghi)\\k<-3>\\k<-1>', 'ruby/1.9')
|
@@ -76,76 +81,11 @@ RSpec.describe('Refcall parsing') do
|
|
76
81
|
exp3 = root[5]
|
77
82
|
|
78
83
|
expect([exp1, exp2, exp3]).to all be_instance_of(Backreference::NumberRelative)
|
79
|
-
|
80
84
|
expect(exp1.referenced_expression.to_s).to eq '(def)'
|
81
85
|
expect(exp2.referenced_expression.to_s).to eq '(abc)'
|
82
86
|
expect(exp3.referenced_expression.to_s).to eq '(ghi)'
|
83
87
|
end
|
84
88
|
|
85
|
-
specify('parse backref name call ab') do
|
86
|
-
root = RP.parse('(?<X>abc)\\g<X>', 'ruby/1.9')
|
87
|
-
exp = root[1]
|
88
|
-
|
89
|
-
expect(exp).to be_instance_of(Backreference::NameCall)
|
90
|
-
expect(exp.name).to eq 'X'
|
91
|
-
end
|
92
|
-
|
93
|
-
specify('parse backref name call sq') do
|
94
|
-
root = RP.parse("(?<X>abc)\\g'X'", 'ruby/1.9')
|
95
|
-
exp = root[1]
|
96
|
-
|
97
|
-
expect(exp).to be_instance_of(Backreference::NameCall)
|
98
|
-
expect(exp.name).to eq 'X'
|
99
|
-
end
|
100
|
-
|
101
|
-
specify('parse backref number call ab') do
|
102
|
-
root = RP.parse('(abc)\\g<1>', 'ruby/1.9')
|
103
|
-
exp = root[1]
|
104
|
-
|
105
|
-
expect(exp).to be_instance_of(Backreference::NumberCall)
|
106
|
-
expect(exp.number).to eq 1
|
107
|
-
end
|
108
|
-
|
109
|
-
specify('parse backref number call sq') do
|
110
|
-
root = RP.parse("(abc)\\g'1'", 'ruby/1.9')
|
111
|
-
exp = root[1]
|
112
|
-
|
113
|
-
expect(exp).to be_instance_of(Backreference::NumberCall)
|
114
|
-
expect(exp.number).to eq 1
|
115
|
-
end
|
116
|
-
|
117
|
-
specify('parse backref number relative call ab') do
|
118
|
-
root = RP.parse('(abc)\\g<-1>', 'ruby/1.9')
|
119
|
-
exp = root[1]
|
120
|
-
|
121
|
-
expect(exp).to be_instance_of(Backreference::NumberCallRelative)
|
122
|
-
expect(exp.number).to eq(-1)
|
123
|
-
end
|
124
|
-
|
125
|
-
specify('parse backref number relative call sq') do
|
126
|
-
root = RP.parse("(abc)\\g'-1'", 'ruby/1.9')
|
127
|
-
exp = root[1]
|
128
|
-
|
129
|
-
expect(exp).to be_instance_of(Backreference::NumberCallRelative)
|
130
|
-
expect(exp.number).to eq(-1)
|
131
|
-
end
|
132
|
-
|
133
|
-
specify('parse backref number relative forward call ab') do
|
134
|
-
root = RP.parse('\\g<+1>(abc)', 'ruby/1.9')
|
135
|
-
exp = root[0]
|
136
|
-
|
137
|
-
expect(exp).to be_instance_of(Backreference::NumberCallRelative)
|
138
|
-
expect(exp.number).to eq 1
|
139
|
-
end
|
140
|
-
|
141
|
-
specify('parse backref number relative forward call sq') do
|
142
|
-
root = RP.parse("\\g'+1'(abc)", 'ruby/1.9')
|
143
|
-
exp = root[0]
|
144
|
-
|
145
|
-
expect(exp).to be_instance_of(Backreference::NumberCallRelative)
|
146
|
-
expect(exp.number).to eq 1
|
147
|
-
end
|
148
|
-
|
149
89
|
specify('parse backref call effective_number') do
|
150
90
|
root = RP.parse('\\g<+1>(abc)\\g<+2>(def)(ghi)\\g<-2>', 'ruby/1.9')
|
151
91
|
exp1 = root[0]
|
@@ -153,7 +93,6 @@ RSpec.describe('Refcall parsing') do
|
|
153
93
|
exp3 = root[5]
|
154
94
|
|
155
95
|
expect([exp1, exp2, exp3]).to all be_instance_of(Backreference::NumberCallRelative)
|
156
|
-
|
157
96
|
expect(exp1.effective_number).to eq 1
|
158
97
|
expect(exp2.effective_number).to eq 3
|
159
98
|
expect(exp3.effective_number).to eq 2
|
@@ -166,72 +105,8 @@ RSpec.describe('Refcall parsing') do
|
|
166
105
|
exp3 = root[5]
|
167
106
|
|
168
107
|
expect([exp1, exp2, exp3]).to all be_instance_of(Backreference::NumberCallRelative)
|
169
|
-
|
170
108
|
expect(exp1.referenced_expression.to_s).to eq '(abc)'
|
171
109
|
expect(exp2.referenced_expression.to_s).to eq '(ghi)'
|
172
110
|
expect(exp3.referenced_expression.to_s).to eq '(def)'
|
173
111
|
end
|
174
|
-
|
175
|
-
specify('parse backref name recursion level ab') do
|
176
|
-
root = RP.parse('(?<X>abc)\\k<X-0>', 'ruby/1.9')
|
177
|
-
exp = root[1]
|
178
|
-
|
179
|
-
expect(exp).to be_instance_of(Backreference::NameRecursionLevel)
|
180
|
-
expect(exp.name).to eq 'X'
|
181
|
-
expect(exp.recursion_level).to eq 0
|
182
|
-
end
|
183
|
-
|
184
|
-
specify('parse backref name recursion level sq') do
|
185
|
-
root = RP.parse("(?<X>abc)\\k'X-0'", 'ruby/1.9')
|
186
|
-
exp = root[1]
|
187
|
-
|
188
|
-
expect(exp).to be_instance_of(Backreference::NameRecursionLevel)
|
189
|
-
expect(exp.name).to eq 'X'
|
190
|
-
expect(exp.recursion_level).to eq 0
|
191
|
-
end
|
192
|
-
|
193
|
-
specify('parse backref number recursion level ab') do
|
194
|
-
root = RP.parse('(abc)\\k<1-0>', 'ruby/1.9')
|
195
|
-
exp = root[1]
|
196
|
-
|
197
|
-
expect(exp).to be_instance_of(Backreference::NumberRecursionLevel)
|
198
|
-
expect(exp.number).to eq 1
|
199
|
-
expect(exp.recursion_level).to eq 0
|
200
|
-
end
|
201
|
-
|
202
|
-
specify('parse backref number recursion level sq') do
|
203
|
-
root = RP.parse("(abc)\\k'1-0'", 'ruby/1.9')
|
204
|
-
exp = root[1]
|
205
|
-
|
206
|
-
expect(exp).to be_instance_of(Backreference::NumberRecursionLevel)
|
207
|
-
expect(exp.number).to eq 1
|
208
|
-
expect(exp.recursion_level).to eq 0
|
209
|
-
end
|
210
|
-
|
211
|
-
specify('parse backref negative number recursion level') do
|
212
|
-
root = RP.parse("(abc)\\k'-1+0'", 'ruby/1.9')
|
213
|
-
exp = root[1]
|
214
|
-
|
215
|
-
expect(exp).to be_instance_of(Backreference::NumberRecursionLevel)
|
216
|
-
expect(exp.number).to eq(-1)
|
217
|
-
expect(exp.recursion_level).to eq 0
|
218
|
-
end
|
219
|
-
|
220
|
-
specify('parse backref number positive recursion level') do
|
221
|
-
root = RP.parse("(abc)\\k'1+1'", 'ruby/1.9')
|
222
|
-
exp = root[1]
|
223
|
-
|
224
|
-
expect(exp).to be_instance_of(Backreference::NumberRecursionLevel)
|
225
|
-
expect(exp.number).to eq 1
|
226
|
-
expect(exp.recursion_level).to eq 1
|
227
|
-
end
|
228
|
-
|
229
|
-
specify('parse backref number negative recursion level') do
|
230
|
-
root = RP.parse("(abc)\\k'1-1'", 'ruby/1.9')
|
231
|
-
exp = root[1]
|
232
|
-
|
233
|
-
expect(exp).to be_instance_of(Backreference::NumberRecursionLevel)
|
234
|
-
expect(exp.number).to eq 1
|
235
|
-
expect(exp.recursion_level).to eq(-1)
|
236
|
-
end
|
237
112
|
end
|