regexp_parser 1.5.0 → 1.5.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +14 -0
- 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/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/sequence.rb +3 -2
- data/lib/regexp_parser/expression/sequence_operation.rb +2 -6
- data/lib/regexp_parser/lexer.rb +0 -21
- data/lib/regexp_parser/parser.rb +22 -21
- data/lib/regexp_parser/scanner.rb +1159 -1329
- data/lib/regexp_parser/scanner/char_type.rl +0 -3
- data/lib/regexp_parser/scanner/scanner.rl +82 -190
- data/lib/regexp_parser/version.rb +1 -1
- data/spec/expression/base_spec.rb +14 -0
- data/spec/expression/methods/match_length_spec.rb +13 -0
- data/spec/expression/methods/match_spec.rb +25 -0
- data/spec/expression/methods/tests_spec.rb +2 -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/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/groups_spec.rb +98 -257
- data/spec/parser/keep_spec.rb +2 -15
- data/spec/parser/posix_classes_spec.rb +5 -24
- data/spec/parser/properties_spec.rb +42 -54
- data/spec/parser/quantifiers_spec.rb +41 -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/errors_spec.rb +65 -87
- data/spec/scanner/escapes_spec.rb +49 -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/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 +25 -109
- metadata +14 -6
- data/spec/scanner/scripts_spec.rb +0 -49
- data/spec/scanner/unicode_blocks_spec.rb +0 -28
data/spec/parser/keep_spec.rb
CHANGED
@@ -1,19 +1,6 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
RSpec.describe('Keep parsing') do
|
4
|
-
|
5
|
-
|
6
|
-
root = RP.parse(regexp)
|
7
|
-
|
8
|
-
expect(root[1]).to be_instance_of(Keep::Mark)
|
9
|
-
expect(root[1].text).to eq '\\K'
|
10
|
-
end
|
11
|
-
|
12
|
-
specify('parse keep nested') do
|
13
|
-
regexp = /(a\\\Kb)/
|
14
|
-
root = RP.parse(regexp)
|
15
|
-
|
16
|
-
expect(root[0][2]).to be_instance_of(Keep::Mark)
|
17
|
-
expect(root[0][2].text).to eq '\\K'
|
18
|
-
end
|
4
|
+
include_examples 'parse', /ab\Kcd/, 1 => [:keep, :mark, Keep::Mark, text: '\K']
|
5
|
+
include_examples 'parse', /(a\K)/, [0, 1] => [:keep, :mark, Keep::Mark, text: '\K']
|
19
6
|
end
|
@@ -1,27 +1,8 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
RSpec.describe('
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
expect(exp).to be_instance_of(PosixClass)
|
9
|
-
expect(exp.type).to eq :posixclass
|
10
|
-
expect(exp.token).to eq :word
|
11
|
-
expect(exp.name).to eq 'word'
|
12
|
-
expect(exp.text).to eq '[:word:]'
|
13
|
-
expect(exp).not_to be_negative
|
14
|
-
end
|
15
|
-
|
16
|
-
specify('parse negative posix class') do
|
17
|
-
root = RP.parse('[[:^word:]]')
|
18
|
-
exp = root[0][0]
|
19
|
-
|
20
|
-
expect(exp).to be_instance_of(PosixClass)
|
21
|
-
expect(exp.type).to eq :nonposixclass
|
22
|
-
expect(exp.token).to eq :word
|
23
|
-
expect(exp.name).to eq 'word'
|
24
|
-
expect(exp.text).to eq '[:^word:]'
|
25
|
-
expect(exp).to be_negative
|
26
|
-
end
|
3
|
+
RSpec.describe('PosixClass parsing') do
|
4
|
+
include_examples 'parse', /[[:word:]]/, [0, 0] => [:posixclass, :word, PosixClass,
|
5
|
+
name: 'word', text: '[:word:]', negative?: false]
|
6
|
+
include_examples 'parse', /[[:^word:]]/, [0, 0] => [:nonposixclass, :word, PosixClass,
|
7
|
+
name: 'word', text: '[:^word:]', negative?: true]
|
27
8
|
end
|
@@ -1,7 +1,6 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
RSpec.describe('Property parsing') do
|
4
|
-
modes = %w[p P]
|
5
4
|
example_props = [
|
6
5
|
'Alnum',
|
7
6
|
'Any',
|
@@ -20,108 +19,97 @@ RSpec.describe('Property parsing') do
|
|
20
19
|
'InChessSymbols'
|
21
20
|
]
|
22
21
|
|
23
|
-
|
24
|
-
|
22
|
+
example_props.each do |name|
|
23
|
+
it("parses property #{name}") do
|
24
|
+
exp = RP.parse("ab\\p{#{name}}", '*').last
|
25
25
|
|
26
|
-
|
27
|
-
|
28
|
-
|
26
|
+
expect(exp).to be_a(UnicodeProperty::Base)
|
27
|
+
expect(exp.type).to eq :property
|
28
|
+
expect(exp.name).to eq name
|
29
|
+
end
|
29
30
|
|
30
|
-
|
31
|
+
it("parses nonproperty #{name}") do
|
32
|
+
exp = RP.parse("ab\\P{#{name}}", '*').last
|
31
33
|
|
32
|
-
|
33
|
-
|
34
|
-
|
34
|
+
expect(exp).to be_a(UnicodeProperty::Base)
|
35
|
+
expect(exp.type).to eq :nonproperty
|
36
|
+
expect(exp.name).to eq name
|
35
37
|
end
|
36
38
|
end
|
37
39
|
|
38
40
|
specify('parse all properties of current ruby') do
|
39
41
|
unsupported = RegexpPropertyValues.all_for_current_ruby.reject do |prop|
|
40
|
-
|
41
|
-
RP.parse("\\p{#{prop}}")
|
42
|
-
rescue SyntaxError, StandardError
|
43
|
-
nil
|
44
|
-
end
|
42
|
+
RP.parse("\\p{#{prop}}") rescue false
|
45
43
|
end
|
46
44
|
expect(unsupported).to be_empty
|
47
45
|
end
|
48
46
|
|
49
47
|
specify('parse property negative') do
|
50
|
-
|
51
|
-
|
52
|
-
expect(t[1]).not_to be_negative
|
48
|
+
root = RP.parse('ab\p{L}cd', 'ruby/1.9')
|
49
|
+
expect(root[1]).not_to be_negative
|
53
50
|
end
|
54
51
|
|
55
52
|
specify('parse nonproperty negative') do
|
56
|
-
|
57
|
-
|
58
|
-
expect(t[1]).to be_negative
|
53
|
+
root = RP.parse('ab\P{L}cd', 'ruby/1.9')
|
54
|
+
expect(root[1]).to be_negative
|
59
55
|
end
|
60
56
|
|
61
57
|
specify('parse caret nonproperty negative') do
|
62
|
-
|
63
|
-
|
64
|
-
expect(t[1]).to be_negative
|
58
|
+
root = RP.parse('ab\p{^L}cd', 'ruby/1.9')
|
59
|
+
expect(root[1]).to be_negative
|
65
60
|
end
|
66
61
|
|
67
62
|
specify('parse double negated property negative') do
|
68
|
-
|
69
|
-
|
70
|
-
expect(t[1]).not_to be_negative
|
63
|
+
root = RP.parse('ab\P{^L}cd', 'ruby/1.9')
|
64
|
+
expect(root[1]).not_to be_negative
|
71
65
|
end
|
72
66
|
|
73
67
|
specify('parse property shortcut') do
|
74
|
-
expect(RP.parse('
|
75
|
-
expect(RP.parse('
|
76
|
-
expect(RP.parse('
|
68
|
+
expect(RP.parse('\p{mark}')[0].shortcut).to eq 'm'
|
69
|
+
expect(RP.parse('\p{sc}')[0].shortcut).to eq 'sc'
|
70
|
+
expect(RP.parse('\p{in_bengali}')[0].shortcut).to be_nil
|
77
71
|
end
|
78
72
|
|
79
73
|
specify('parse property age') do
|
80
|
-
|
81
|
-
|
82
|
-
expect(t[1]).to be_a(UnicodeProperty::Age)
|
74
|
+
root = RP.parse('ab\p{age=5.2}cd', 'ruby/1.9')
|
75
|
+
expect(root[1]).to be_a(UnicodeProperty::Age)
|
83
76
|
end
|
84
77
|
|
85
78
|
specify('parse property derived') do
|
86
|
-
|
87
|
-
|
88
|
-
expect(t[1]).to be_a(UnicodeProperty::Derived)
|
79
|
+
root = RP.parse('ab\p{Math}cd', 'ruby/1.9')
|
80
|
+
expect(root[1]).to be_a(UnicodeProperty::Derived)
|
89
81
|
end
|
90
82
|
|
91
83
|
specify('parse property script') do
|
92
|
-
|
93
|
-
|
94
|
-
expect(t[1]).to be_a(UnicodeProperty::Script)
|
84
|
+
root = RP.parse('ab\p{Hiragana}cd', 'ruby/1.9')
|
85
|
+
expect(root[1]).to be_a(UnicodeProperty::Script)
|
95
86
|
end
|
96
87
|
|
97
88
|
specify('parse property script V1 9 3') do
|
98
|
-
|
99
|
-
|
100
|
-
expect(t[1]).to be_a(UnicodeProperty::Script)
|
89
|
+
root = RP.parse('ab\p{Brahmi}cd', 'ruby/1.9.3')
|
90
|
+
expect(root[1]).to be_a(UnicodeProperty::Script)
|
101
91
|
end
|
102
92
|
|
103
93
|
specify('parse property script V2 2 0') do
|
104
|
-
|
105
|
-
|
106
|
-
expect(t[1]).to be_a(UnicodeProperty::Script)
|
94
|
+
root = RP.parse('ab\p{Caucasian_Albanian}cd', 'ruby/2.2')
|
95
|
+
expect(root[1]).to be_a(UnicodeProperty::Script)
|
107
96
|
end
|
108
97
|
|
109
98
|
specify('parse property block') do
|
110
|
-
|
111
|
-
|
112
|
-
expect(t[1]).to be_a(UnicodeProperty::Block)
|
99
|
+
root = RP.parse('ab\p{InArmenian}cd', 'ruby/1.9')
|
100
|
+
expect(root[1]).to be_a(UnicodeProperty::Block)
|
113
101
|
end
|
114
102
|
|
115
103
|
specify('parse property following literal') do
|
116
|
-
|
117
|
-
|
118
|
-
expect(t[2]).to be_a(Literal)
|
104
|
+
root = RP.parse('ab\p{Lu}cd', 'ruby/1.9')
|
105
|
+
expect(root[2]).to be_a(Literal)
|
119
106
|
end
|
120
107
|
|
121
108
|
specify('parse abandoned newline property') do
|
122
|
-
|
123
|
-
expect(
|
109
|
+
root = RP.parse('\p{newline}', 'ruby/1.9')
|
110
|
+
expect(root.expressions.last).to be_a(UnicodeProperty::Base)
|
124
111
|
|
125
|
-
expect { RP.parse('
|
112
|
+
expect { RP.parse('\p{newline}', 'ruby/2.0') }
|
113
|
+
.to raise_error(Regexp::Syntax::NotImplementedError)
|
126
114
|
end
|
127
115
|
end
|
@@ -1,293 +1,51 @@
|
|
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
|
+
|
39
|
+
specify('mode-checking methods') do
|
40
|
+
exp = RP.parse(/a??/).first
|
7
41
|
|
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
42
|
expect(exp).to be_reluctant
|
33
|
-
|
34
|
-
expect(exp.quantifier).not_to be_greedy
|
43
|
+
expect(exp).to be_lazy
|
35
44
|
expect(exp).not_to be_greedy
|
36
|
-
expect(exp.quantifier).not_to be_possessive
|
37
45
|
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
46
|
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
|
47
|
+
expect(exp.quantifier).to be_lazy
|
48
|
+
expect(exp.quantifier).not_to be_greedy
|
49
|
+
expect(exp.quantifier).not_to be_possessive
|
292
50
|
end
|
293
51
|
end
|