regexp_parser 2.2.0 → 2.2.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (88) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +14 -2
  3. data/LICENSE +1 -1
  4. data/README.md +2 -2
  5. data/Rakefile +5 -8
  6. data/lib/regexp_parser/expression/classes/escape_sequence.rb +12 -7
  7. data/lib/regexp_parser/expression/methods/strfregexp.rb +1 -1
  8. data/lib/regexp_parser/scanner/properties/long.csv +604 -0
  9. data/lib/regexp_parser/scanner/properties/short.csv +242 -0
  10. data/lib/regexp_parser/scanner/scanner.rl +6 -4
  11. data/lib/regexp_parser/scanner.rb +126 -124
  12. data/lib/regexp_parser/syntax/base.rb +3 -5
  13. data/lib/regexp_parser/syntax/token/backreference.rb +7 -2
  14. data/lib/regexp_parser/syntax/versions/1.8.6.rb +2 -2
  15. data/lib/regexp_parser/syntax/versions/1.9.1.rb +1 -1
  16. data/lib/regexp_parser/version.rb +1 -1
  17. data/regexp_parser.gemspec +20 -22
  18. metadata +11 -143
  19. data/lib/regexp_parser/scanner/properties/long.yml +0 -607
  20. data/lib/regexp_parser/scanner/properties/short.yml +0 -245
  21. data/spec/expression/base_spec.rb +0 -104
  22. data/spec/expression/clone_spec.rb +0 -152
  23. data/spec/expression/conditional_spec.rb +0 -89
  24. data/spec/expression/free_space_spec.rb +0 -27
  25. data/spec/expression/methods/match_length_spec.rb +0 -161
  26. data/spec/expression/methods/match_spec.rb +0 -25
  27. data/spec/expression/methods/strfregexp_spec.rb +0 -224
  28. data/spec/expression/methods/tests_spec.rb +0 -99
  29. data/spec/expression/methods/traverse_spec.rb +0 -161
  30. data/spec/expression/options_spec.rb +0 -128
  31. data/spec/expression/subexpression_spec.rb +0 -50
  32. data/spec/expression/to_h_spec.rb +0 -26
  33. data/spec/expression/to_s_spec.rb +0 -108
  34. data/spec/lexer/all_spec.rb +0 -22
  35. data/spec/lexer/conditionals_spec.rb +0 -53
  36. data/spec/lexer/delimiters_spec.rb +0 -68
  37. data/spec/lexer/escapes_spec.rb +0 -14
  38. data/spec/lexer/keep_spec.rb +0 -10
  39. data/spec/lexer/literals_spec.rb +0 -64
  40. data/spec/lexer/nesting_spec.rb +0 -99
  41. data/spec/lexer/refcalls_spec.rb +0 -60
  42. data/spec/parser/all_spec.rb +0 -43
  43. data/spec/parser/alternation_spec.rb +0 -88
  44. data/spec/parser/anchors_spec.rb +0 -17
  45. data/spec/parser/conditionals_spec.rb +0 -179
  46. data/spec/parser/errors_spec.rb +0 -30
  47. data/spec/parser/escapes_spec.rb +0 -133
  48. data/spec/parser/free_space_spec.rb +0 -130
  49. data/spec/parser/groups_spec.rb +0 -108
  50. data/spec/parser/keep_spec.rb +0 -6
  51. data/spec/parser/options_spec.rb +0 -28
  52. data/spec/parser/posix_classes_spec.rb +0 -8
  53. data/spec/parser/properties_spec.rb +0 -117
  54. data/spec/parser/quantifiers_spec.rb +0 -68
  55. data/spec/parser/refcalls_spec.rb +0 -117
  56. data/spec/parser/set/intersections_spec.rb +0 -127
  57. data/spec/parser/set/ranges_spec.rb +0 -121
  58. data/spec/parser/sets_spec.rb +0 -178
  59. data/spec/parser/types_spec.rb +0 -18
  60. data/spec/scanner/all_spec.rb +0 -18
  61. data/spec/scanner/anchors_spec.rb +0 -21
  62. data/spec/scanner/conditionals_spec.rb +0 -128
  63. data/spec/scanner/delimiters_spec.rb +0 -52
  64. data/spec/scanner/errors_spec.rb +0 -67
  65. data/spec/scanner/escapes_spec.rb +0 -73
  66. data/spec/scanner/free_space_spec.rb +0 -165
  67. data/spec/scanner/groups_spec.rb +0 -61
  68. data/spec/scanner/keep_spec.rb +0 -10
  69. data/spec/scanner/literals_spec.rb +0 -39
  70. data/spec/scanner/meta_spec.rb +0 -18
  71. data/spec/scanner/options_spec.rb +0 -36
  72. data/spec/scanner/properties_spec.rb +0 -64
  73. data/spec/scanner/quantifiers_spec.rb +0 -25
  74. data/spec/scanner/refcalls_spec.rb +0 -55
  75. data/spec/scanner/sets_spec.rb +0 -151
  76. data/spec/scanner/types_spec.rb +0 -14
  77. data/spec/spec_helper.rb +0 -28
  78. data/spec/support/capturing_stderr.rb +0 -9
  79. data/spec/support/shared_examples.rb +0 -77
  80. data/spec/syntax/syntax_spec.rb +0 -48
  81. data/spec/syntax/syntax_token_map_spec.rb +0 -23
  82. data/spec/syntax/versions/1.8.6_spec.rb +0 -17
  83. data/spec/syntax/versions/1.9.1_spec.rb +0 -10
  84. data/spec/syntax/versions/1.9.3_spec.rb +0 -9
  85. data/spec/syntax/versions/2.0.0_spec.rb +0 -13
  86. data/spec/syntax/versions/2.2.0_spec.rb +0 -9
  87. data/spec/syntax/versions/aliases_spec.rb +0 -38
  88. data/spec/token/token_spec.rb +0 -85
@@ -1,121 +0,0 @@
1
- require 'spec_helper'
2
-
3
- RSpec.describe('CharacterSet::Range parsing') do
4
- # Some edge-case patterns are evaluated with #match to make sure that
5
- # their behavior still reflects the way they are parsed.
6
- # #capturing_stderr is used to skip any warnings generated by this.
7
-
8
- specify('parse set range') do
9
- root = RP.parse('[a-z]')
10
- set = root[0]
11
- range = set[0]
12
-
13
- expect(set.count).to eq 1
14
- expect(range).to be_instance_of(CharacterSet::Range)
15
- expect(range.count).to eq 2
16
- expect(range.first.to_s).to eq 'a'
17
- expect(range.first).to be_instance_of(Literal)
18
- expect(range.last.to_s).to eq 'z'
19
- expect(range.last).to be_instance_of(Literal)
20
- capturing_stderr { expect(set).to match 'm' }
21
- end
22
-
23
- specify('parse set range hex') do
24
- root = RP.parse('[\\x00-\\x22]')
25
- set = root[0]
26
- range = set[0]
27
-
28
- expect(set.count).to eq 1
29
- expect(range).to be_instance_of(CharacterSet::Range)
30
- expect(range.count).to eq 2
31
- expect(range.first.to_s).to eq '\\x00'
32
- expect(range.first).to be_instance_of(EscapeSequence::Hex)
33
- expect(range.last.to_s).to eq '\\x22'
34
- expect(range.last).to be_instance_of(EscapeSequence::Hex)
35
- capturing_stderr { expect(set).to match "\x11" }
36
- end
37
-
38
- specify('parse set range unicode') do
39
- root = RP.parse('[\\u{40 42}-\\u1234]')
40
- set = root[0]
41
- range = set[0]
42
-
43
- expect(set.count).to eq 1
44
- expect(range).to be_instance_of(CharacterSet::Range)
45
- expect(range.count).to eq 2
46
- expect(range.first.to_s).to eq '\\u{40 42}'
47
- expect(range.first).to be_instance_of(EscapeSequence::CodepointList)
48
- expect(range.last.to_s).to eq '\\u1234'
49
- expect(range.last).to be_instance_of(EscapeSequence::Codepoint)
50
- capturing_stderr { expect(set).to match '\\u600' }
51
- end
52
-
53
- specify('parse set range edge case leading dash') do
54
- root = RP.parse('[--z]')
55
- set = root[0]
56
- range = set[0]
57
-
58
- expect(set.count).to eq 1
59
- expect(range.count).to eq 2
60
- capturing_stderr { expect(set).to match 'a' }
61
- end
62
-
63
- specify('parse set range edge case trailing dash') do
64
- root = RP.parse('[!--]')
65
- set = root[0]
66
- range = set[0]
67
-
68
- expect(set.count).to eq 1
69
- expect(range.count).to eq 2
70
- capturing_stderr { expect(set).to match '$' }
71
- end
72
-
73
- specify('parse set range edge case leading negate') do
74
- root = RP.parse('[^-z]')
75
- set = root[0]
76
-
77
- expect(set.count).to eq 2
78
- capturing_stderr do
79
- expect(set).to match 'a'
80
- expect(set).not_to match 'z'
81
- end
82
- end
83
-
84
- specify('parse set range edge case trailing negate') do
85
- root = RP.parse('[!-^]')
86
- set = root[0]
87
- range = set[0]
88
-
89
- expect(set.count).to eq 1
90
- expect(range.count).to eq 2
91
- capturing_stderr { expect(set).to match '$' }
92
- end
93
-
94
- specify('parse set range edge case leading intersection') do
95
- root = RP.parse('[[\\-ab]&&-bc]')
96
- set = root[0]
97
-
98
- expect(set.count).to eq 1
99
- expect(set.first.last.to_s).to eq '-bc'
100
- capturing_stderr do
101
- expect(set).to match '-'
102
- expect(set).to match 'b'
103
- expect(set).not_to match 'a'
104
- expect(set).not_to match 'c'
105
- end
106
- end
107
-
108
- specify('parse set range edge case trailing intersection') do
109
- root = RP.parse('[bc-&&[\\-ab]]')
110
- set = root[0]
111
-
112
- expect(set.count).to eq 1
113
- expect(set.first.first.to_s).to eq 'bc-'
114
- capturing_stderr do
115
- expect(set).to match '-'
116
- expect(set).to match 'b'
117
- expect(set).not_to match 'a'
118
- expect(set).not_to match 'c'
119
- end
120
- end
121
- end
@@ -1,178 +0,0 @@
1
- require 'spec_helper'
2
-
3
- RSpec.describe('CharacterSet parsing') do
4
- specify('parse set basic') do
5
- root = RP.parse('[ab]+')
6
- exp = root[0]
7
-
8
- expect(exp).to be_instance_of(CharacterSet)
9
- expect(exp.count).to eq 2
10
-
11
- expect(exp[0]).to be_instance_of(Literal)
12
- expect(exp[0].text).to eq 'a'
13
- expect(exp[1]).to be_instance_of(Literal)
14
- expect(exp[1].text).to eq 'b'
15
-
16
- expect(exp).to be_quantified
17
- expect(exp.quantifier.min).to eq 1
18
- expect(exp.quantifier.max).to eq(-1)
19
- end
20
-
21
- specify('parse set char type') do
22
- root = RP.parse('[a\\dc]')
23
- exp = root[0]
24
-
25
- expect(exp).to be_instance_of(CharacterSet)
26
- expect(exp.count).to eq 3
27
-
28
- expect(exp[1]).to be_instance_of(CharacterType::Digit)
29
- expect(exp[1].text).to eq '\\d'
30
- end
31
-
32
- specify('parse set escape sequence backspace') do
33
- root = RP.parse('[a\\bc]')
34
- exp = root[0]
35
-
36
- expect(exp).to be_instance_of(CharacterSet)
37
- expect(exp.count).to eq 3
38
-
39
- expect(exp[1]).to be_instance_of(EscapeSequence::Backspace)
40
- expect(exp[1].text).to eq '\\b'
41
-
42
- expect(exp).to match 'a'
43
- expect(exp).to match "\b"
44
- expect(exp).not_to match 'b'
45
- expect(exp).to match 'c'
46
- end
47
-
48
- specify('parse set escape sequence hex') do
49
- root = RP.parse('[a\\x20c]', :any)
50
- exp = root[0]
51
-
52
- expect(exp).to be_instance_of(CharacterSet)
53
- expect(exp.count).to eq 3
54
-
55
- expect(exp[1]).to be_instance_of(EscapeSequence::Hex)
56
- expect(exp[1].text).to eq '\\x20'
57
- end
58
-
59
- specify('parse set escape sequence codepoint') do
60
- root = RP.parse('[a\\u0640]')
61
- exp = root[0]
62
-
63
- expect(exp).to be_instance_of(CharacterSet)
64
- expect(exp.count).to eq 2
65
-
66
- expect(exp[1]).to be_instance_of(EscapeSequence::Codepoint)
67
- expect(exp[1].text).to eq '\\u0640'
68
- end
69
-
70
- specify('parse set escape sequence codepoint list') do
71
- root = RP.parse('[a\\u{41 1F60D}]')
72
- exp = root[0]
73
-
74
- expect(exp).to be_instance_of(CharacterSet)
75
- expect(exp.count).to eq 2
76
-
77
- expect(exp[1]).to be_instance_of(EscapeSequence::CodepointList)
78
- expect(exp[1].text).to eq '\\u{41 1F60D}'
79
- end
80
-
81
- specify('parse set posix class') do
82
- root = RP.parse('[[:digit:][:^lower:]]+')
83
- exp = root[0]
84
-
85
- expect(exp).to be_instance_of(CharacterSet)
86
- expect(exp.count).to eq 2
87
-
88
- expect(exp[0]).to be_instance_of(PosixClass)
89
- expect(exp[0].text).to eq '[:digit:]'
90
- expect(exp[1]).to be_instance_of(PosixClass)
91
- expect(exp[1].text).to eq '[:^lower:]'
92
- end
93
-
94
- specify('parse set nesting') do
95
- root = RP.parse('[a[b[c]d]e]')
96
-
97
- exp = root[0]
98
- expect(exp).to be_instance_of(CharacterSet)
99
- expect(exp.count).to eq 3
100
- expect(exp[0]).to be_instance_of(Literal)
101
- expect(exp[2]).to be_instance_of(Literal)
102
-
103
- subset1 = exp[1]
104
- expect(subset1).to be_instance_of(CharacterSet)
105
- expect(subset1.count).to eq 3
106
- expect(subset1[0]).to be_instance_of(Literal)
107
- expect(subset1[2]).to be_instance_of(Literal)
108
-
109
- subset2 = subset1[1]
110
- expect(subset2).to be_instance_of(CharacterSet)
111
- expect(subset2.count).to eq 1
112
- expect(subset2[0]).to be_instance_of(Literal)
113
- end
114
-
115
- specify('parse set nesting negative') do
116
- root = RP.parse('[a[^b[c]]]')
117
- exp = root[0]
118
-
119
- expect(exp).to be_instance_of(CharacterSet)
120
- expect(exp.count).to eq 2
121
- expect(exp[0]).to be_instance_of(Literal)
122
- expect(exp).not_to be_negative
123
-
124
- subset1 = exp[1]
125
- expect(subset1).to be_instance_of(CharacterSet)
126
- expect(subset1.count).to eq 2
127
- expect(subset1[0]).to be_instance_of(Literal)
128
- expect(subset1).to be_negative
129
-
130
- subset2 = subset1[1]
131
- expect(subset2).to be_instance_of(CharacterSet)
132
- expect(subset2.count).to eq 1
133
- expect(subset2[0]).to be_instance_of(Literal)
134
- expect(subset2).not_to be_negative
135
- end
136
-
137
- specify('parse set nesting #to_s') do
138
- pattern = '[a[b[^c]]]'
139
- root = RP.parse(pattern)
140
-
141
- expect(root.to_s).to eq pattern
142
- end
143
-
144
- specify('parse set literals are not merged') do
145
- root = RP.parse("[#{('a' * 10)}]")
146
- exp = root[0]
147
-
148
- expect(exp.count).to eq 10
149
- end
150
-
151
- specify('parse set whitespace is not merged') do
152
- root = RP.parse("[#{(' ' * 10)}]")
153
- exp = root[0]
154
-
155
- expect(exp.count).to eq 10
156
- end
157
-
158
- specify('parse set whitespace is not merged in x mode') do
159
- root = RP.parse("(?x)[#{(' ' * 10)}]")
160
- exp = root[1]
161
-
162
- expect(exp.count).to eq 10
163
- end
164
-
165
- specify('parse set collating sequence') do
166
- root = RP.parse('[a[.span-ll.]h]', :any)
167
- exp = root[0]
168
-
169
- expect(exp[1].to_s).to eq '[.span-ll.]'
170
- end
171
-
172
- specify('parse set character equivalents') do
173
- root = RP.parse('[a[=e=]h]', :any)
174
- exp = root[0]
175
-
176
- expect(exp[1].to_s).to eq '[=e=]'
177
- end
178
- end
@@ -1,18 +0,0 @@
1
- require 'spec_helper'
2
-
3
- RSpec.describe('CharacterType parsing') do
4
- include_examples 'parse', /a\dc/, 1 => [:type, :digit, CharacterType::Digit]
5
- include_examples 'parse', /a\Dc/, 1 => [:type, :nondigit, CharacterType::NonDigit]
6
-
7
- include_examples 'parse', /a\sc/, 1 => [:type, :space, CharacterType::Space]
8
- include_examples 'parse', /a\Sc/, 1 => [:type, :nonspace, CharacterType::NonSpace]
9
-
10
- include_examples 'parse', /a\hc/, 1 => [:type, :hex, CharacterType::Hex]
11
- include_examples 'parse', /a\Hc/, 1 => [:type, :nonhex, CharacterType::NonHex]
12
-
13
- include_examples 'parse', /a\wc/, 1 => [:type, :word, CharacterType::Word]
14
- include_examples 'parse', /a\Wc/, 1 => [:type, :nonword, CharacterType::NonWord]
15
-
16
- include_examples 'parse', 'a\\Rc', 1 => [:type, :linebreak, CharacterType::Linebreak]
17
- include_examples 'parse', 'a\\Xc', 1 => [:type, :xgrapheme, CharacterType::ExtendedGrapheme]
18
- end
@@ -1,18 +0,0 @@
1
- require 'spec_helper'
2
-
3
- RSpec.describe(Regexp::Scanner) do
4
- specify('scanner returns an array') do
5
- expect(RS.scan('abc')).to be_instance_of(Array)
6
- end
7
-
8
- specify('scanner returns tokens as arrays') do
9
- tokens = RS.scan('^abc+[^one]{2,3}\\b\\d\\\\C-C$')
10
- expect(tokens).to all(be_a Array)
11
- expect(tokens.map(&:length)).to all(eq 5)
12
- end
13
-
14
- specify('scanner token count') do
15
- re = /^(one|two){2,3}([^d\]efm-qz\,\-]*)(ghi)+$/i
16
- expect(RS.scan(re).length).to eq 28
17
- end
18
- end
@@ -1,21 +0,0 @@
1
- require 'spec_helper'
2
-
3
- RSpec.describe('Anchor scanning') do
4
- include_examples 'scan', '^abc', 0 => [:anchor, :bol, '^', 0, 1]
5
- include_examples 'scan', 'abc$', 1 => [:anchor, :eol, '$', 3, 4]
6
-
7
- include_examples 'scan', '\Aabc', 0 => [:anchor, :bos, '\A', 0, 2]
8
- include_examples 'scan', 'abc\z', 1 => [:anchor, :eos, '\z', 3, 5]
9
- include_examples 'scan', 'abc\Z', 1 => [:anchor, :eos_ob_eol, '\Z', 3, 5]
10
-
11
- include_examples 'scan', 'a\bc', 1 => [:anchor, :word_boundary, '\b', 1, 3]
12
- include_examples 'scan', 'a\Bc', 1 => [:anchor, :nonword_boundary, '\B', 1, 3]
13
-
14
- include_examples 'scan', 'a\Gc', 1 => [:anchor, :match_start, '\G', 1, 3]
15
-
16
- include_examples 'scan', "\\\\Ac", 0 => [:escape, :backslash, '\\\\', 0, 2]
17
- include_examples 'scan', "a\\\\z", 1 => [:escape, :backslash, '\\\\', 1, 3]
18
- include_examples 'scan', "a\\\\Z", 1 => [:escape, :backslash, '\\\\', 1, 3]
19
- include_examples 'scan', "a\\\\bc", 1 => [:escape, :backslash, '\\\\', 1, 3]
20
- include_examples 'scan', "a\\\\Bc", 1 => [:escape, :backslash, '\\\\', 1, 3]
21
- end
@@ -1,128 +0,0 @@
1
- require 'spec_helper'
2
-
3
- RSpec.describe('Conditional scanning') do
4
- include_examples 'scan', /(a)(?(1)T|F)1/, 3 => [:conditional, :open, '(?', 3, 5]
5
- include_examples 'scan', /(a)(?(1)T|F)2/, 4 => [:conditional, :condition_open, '(', 5, 6]
6
- include_examples 'scan', /(a)(?(1)T|F)3/, 5 => [:conditional, :condition, '1', 6, 7]
7
- include_examples 'scan', /(a)(?(1)T|F)4/, 6 => [:conditional, :condition_close, ')', 7, 8]
8
- include_examples 'scan', /(a)(?(1)T|F)5/, 7 => [:literal, :literal, 'T', 8, 9]
9
- include_examples 'scan', /(a)(?(1)T|F)6/, 8 => [:conditional, :separator, '|', 9, 10]
10
- include_examples 'scan', /(a)(?(1)T|F)7/, 9 => [:literal, :literal, 'F', 10, 11]
11
- include_examples 'scan', /(a)(?(1)T|F)8/, 10 => [:conditional, :close, ')', 11, 12]
12
- include_examples 'scan', /(a)(?(1)TRUE)9/, 8 => [:conditional, :close, ')', 12, 13]
13
- include_examples 'scan', /(a)(?(1)TRUE|)10/, 8 => [:conditional, :separator, '|', 12, 13]
14
- include_examples 'scan', /(a)(?(1)TRUE|)11/, 9 => [:conditional, :close, ')', 13, 14]
15
- include_examples 'scan', /(?<N>A)(?(<N>)T|F)1/, 5 => [:conditional, :condition, '<N>', 10, 13]
16
- include_examples 'scan', /(?'N'A)(?('N')T|F)2/, 5 => [:conditional, :condition, "'N'", 10, 13]
17
-
18
- include_examples 'scan', /(a(b(c)))(?(1)(?(2)d|(?(3)e|f))|(?(2)(?(1)g|h)))/,
19
- 0 => [:group, :capture, '(', 0, 1],
20
- 1 => [:literal, :literal, 'a', 1, 2],
21
- 2 => [:group, :capture, '(', 2, 3],
22
- 3 => [:literal, :literal, 'b', 3, 4],
23
- 4 => [:group, :capture, '(', 4, 5],
24
- 5 => [:literal, :literal, 'c', 5, 6],
25
- 6 => [:group, :close, ')', 6, 7],
26
- 7 => [:group, :close, ')', 7, 8],
27
- 8 => [:group, :close, ')', 8, 9],
28
- 9 => [:conditional, :open, '(?', 9, 11],
29
- 10 => [:conditional, :condition_open, '(', 11, 12],
30
- 11 => [:conditional, :condition, '1', 12, 13],
31
- 12 => [:conditional, :condition_close, ')', 13, 14],
32
- 13 => [:conditional, :open, '(?', 14, 16],
33
- 14 => [:conditional, :condition_open, '(', 16, 17],
34
- 15 => [:conditional, :condition, '2', 17, 18],
35
- 16 => [:conditional, :condition_close, ')', 18, 19],
36
- 17 => [:literal, :literal, 'd', 19, 20],
37
- 18 => [:conditional, :separator, '|', 20, 21],
38
- 19 => [:conditional, :open, '(?', 21, 23],
39
- 20 => [:conditional, :condition_open, '(', 23, 24],
40
- 21 => [:conditional, :condition, '3', 24, 25],
41
- 22 => [:conditional, :condition_close, ')', 25, 26],
42
- 23 => [:literal, :literal, 'e', 26, 27],
43
- 24 => [:conditional, :separator, '|', 27, 28],
44
- 25 => [:literal, :literal, 'f', 28, 29],
45
- 26 => [:conditional, :close, ')', 29, 30],
46
- 27 => [:conditional, :close, ')', 30, 31],
47
- 28 => [:conditional, :separator, '|', 31, 32],
48
- 29 => [:conditional, :open, '(?', 32, 34],
49
- 30 => [:conditional, :condition_open, '(', 34, 35],
50
- 31 => [:conditional, :condition, '2', 35, 36],
51
- 32 => [:conditional, :condition_close, ')', 36, 37],
52
- 33 => [:conditional, :open, '(?', 37, 39],
53
- 34 => [:conditional, :condition_open, '(', 39, 40],
54
- 35 => [:conditional, :condition, '1', 40, 41],
55
- 36 => [:conditional, :condition_close, ')', 41, 42],
56
- 37 => [:literal, :literal, 'g', 42, 43],
57
- 38 => [:conditional, :separator, '|', 43, 44],
58
- 39 => [:literal, :literal, 'h', 44, 45],
59
- 40 => [:conditional, :close, ')', 45, 46],
60
- 41 => [:conditional, :close, ')', 46, 47],
61
- 42 => [:conditional, :close, ')', 47, 48]
62
-
63
- include_examples 'scan', /((a)|(b)|((?(2)(c(d|e)+)?|(?(3)f|(?(4)(g|(h)(i)))))))/,
64
- 0 => [:group, :capture, '(', 0, 1],
65
- 1 => [:group, :capture, '(', 1, 2],
66
- 2 => [:literal, :literal, 'a', 2, 3],
67
- 3 => [:group, :close, ')', 3, 4],
68
- 4 => [:meta, :alternation, '|', 4, 5],
69
- 5 => [:group, :capture, '(', 5, 6],
70
- 6 => [:literal, :literal, 'b', 6, 7],
71
- 7 => [:group, :close, ')', 7, 8],
72
- 8 => [:meta, :alternation, '|', 8, 9],
73
- 9 => [:group, :capture, '(', 9, 10],
74
- 10 => [:conditional, :open, '(?', 10, 12],
75
- 11 => [:conditional, :condition_open, '(', 12, 13],
76
- 12 => [:conditional, :condition, '2', 13, 14],
77
- 13 => [:conditional, :condition_close, ')', 14, 15],
78
- 14 => [:group, :capture, '(', 15, 16],
79
- 15 => [:literal, :literal, 'c', 16, 17],
80
- 16 => [:group, :capture, '(', 17, 18],
81
- 17 => [:literal, :literal, 'd', 18, 19],
82
- 18 => [:meta, :alternation, '|', 19, 20],
83
- 19 => [:literal, :literal, 'e', 20, 21],
84
- 20 => [:group, :close, ')', 21, 22],
85
- 21 => [:quantifier, :one_or_more, '+', 22, 23],
86
- 22 => [:group, :close, ')', 23, 24],
87
- 23 => [:quantifier, :zero_or_one, '?', 24, 25],
88
- 24 => [:conditional, :separator, '|', 25, 26],
89
- 25 => [:conditional, :open, '(?', 26, 28],
90
- 26 => [:conditional, :condition_open, '(', 28, 29],
91
- 27 => [:conditional, :condition, '3', 29, 30],
92
- 28 => [:conditional, :condition_close, ')', 30, 31],
93
- 29 => [:literal, :literal, 'f', 31, 32],
94
- 30 => [:conditional, :separator, '|', 32, 33],
95
- 31 => [:conditional, :open, '(?', 33, 35],
96
- 32 => [:conditional, :condition_open, '(', 35, 36],
97
- 33 => [:conditional, :condition, '4', 36, 37],
98
- 34 => [:conditional, :condition_close, ')', 37, 38],
99
- 35 => [:group, :capture, '(', 38, 39],
100
- 36 => [:literal, :literal, 'g', 39, 40],
101
- 37 => [:meta, :alternation, '|', 40, 41],
102
- 38 => [:group, :capture, '(', 41, 42],
103
- 39 => [:literal, :literal, 'h', 42, 43],
104
- 40 => [:group, :close, ')', 43, 44],
105
- 41 => [:group, :capture, '(', 44, 45],
106
- 42 => [:literal, :literal, 'i', 45, 46],
107
- 43 => [:group, :close, ')', 46, 47],
108
- 44 => [:group, :close, ')', 47, 48],
109
- 45 => [:conditional, :close, ')', 48, 49],
110
- 46 => [:conditional, :close, ')', 49, 50],
111
- 47 => [:conditional, :close, ')', 50, 51],
112
- 48 => [:group, :close, ')', 51, 52],
113
- 49 => [:group, :close, ')', 52, 53]
114
-
115
- include_examples 'scan', /(a)(?(1)(b|c|d)|(e|f|g))(h)(?(2)(i|j|k)|(l|m|n))|o|p/,
116
- 9 => [:meta, :alternation, '|', 10, 11],
117
- 11 => [:meta, :alternation, '|', 12, 13],
118
- 14 => [:conditional, :separator, '|', 15, 16],
119
- 17 => [:meta, :alternation, '|', 18, 19],
120
- 19 => [:meta, :alternation, '|', 20, 21],
121
- 32 => [:meta, :alternation, '|', 34, 35],
122
- 34 => [:meta, :alternation, '|', 36, 37],
123
- 37 => [:conditional, :separator, '|', 39, 40],
124
- 40 => [:meta, :alternation, '|', 42, 43],
125
- 42 => [:meta, :alternation, '|', 44, 45],
126
- 46 => [:meta, :alternation, '|', 48, 49],
127
- 48 => [:meta, :alternation, '|', 50, 51]
128
- end
@@ -1,52 +0,0 @@
1
- require 'spec_helper'
2
-
3
- RSpec.describe('Literal delimiter scanning') do
4
- include_examples 'scan', '}',
5
- 0 => [:literal, :literal, '}', 0, 1]
6
-
7
- include_examples 'scan', '}}',
8
- 0 => [:literal, :literal, '}}', 0, 2]
9
-
10
- include_examples 'scan', '{',
11
- 0 => [:literal, :literal, '{', 0, 1]
12
-
13
- include_examples 'scan', '{{',
14
- 0 => [:literal, :literal, '{{', 0, 2]
15
-
16
- include_examples 'scan', '{}',
17
- 0 => [:literal, :literal, '{}', 0, 2]
18
-
19
- include_examples 'scan', '}{',
20
- 0 => [:literal, :literal, '}{', 0, 2]
21
-
22
- include_examples 'scan', '}{+',
23
- 0 => [:literal, :literal, '}{', 0, 2]
24
-
25
- include_examples 'scan', '{{var}}',
26
- 0 => [:literal, :literal, '{{var}}', 0, 7]
27
-
28
- include_examples 'scan', 'a{1,2',
29
- 0 => [:literal, :literal, 'a{1,2', 0, 5]
30
-
31
- include_examples 'scan', '({.+})',
32
- 0 => [:group, :capture, '(', 0, 1],
33
- 1 => [:literal, :literal, '{', 1, 2],
34
- 2 => [:meta, :dot, '.', 2, 3],
35
- 3 => [:quantifier, :one_or_more, '+', 3, 4],
36
- 4 => [:literal, :literal, '}', 4, 5],
37
- 5 => [:group, :close, ')', 5, 6]
38
-
39
- include_examples 'scan', ']',
40
- 0 => [:literal, :literal, ']', 0, 1]
41
-
42
- include_examples 'scan', ']]',
43
- 0 => [:literal, :literal, ']]', 0, 2]
44
-
45
- include_examples 'scan', ']\[',
46
- 0 => [:literal, :literal, ']', 0, 1],
47
- 1 => [:escape, :set_open, '\[', 1, 3]
48
-
49
- include_examples 'scan', '()',
50
- 0 => [:group, :capture, '(', 0, 1],
51
- 1 => [:group, :close, ')', 1, 2]
52
- end
@@ -1,67 +0,0 @@
1
- require 'spec_helper'
2
-
3
- RSpec.describe(Regexp::Scanner) do
4
- RSpec.shared_examples 'scan error' do |error, issue, source|
5
- it "raises #{error} for #{issue} `#{source}`" do
6
- expect { RS.scan(source) }.to raise_error(error)
7
- end
8
- end
9
-
10
- include_examples 'scan error', RS::PrematureEndError, 'unbalanced set', '[a'
11
- include_examples 'scan error', RS::PrematureEndError, 'unbalanced set', '[[:alpha:]'
12
- include_examples 'scan error', RS::PrematureEndError, 'unbalanced group', '(abc'
13
- include_examples 'scan error', RS::PrematureEndError, 'eof in property', '\p{asci'
14
- include_examples 'scan error', RS::PrematureEndError, 'incomplete property', '\p{ascii abc'
15
- include_examples 'scan error', RS::PrematureEndError, 'eof options', '(?mix'
16
- include_examples 'scan error', RS::PrematureEndError, 'eof escape', '\\'
17
- include_examples 'scan error', RS::PrematureEndError, 'eof in hex escape', '\x'
18
- include_examples 'scan error', RS::PrematureEndError, 'eof in cp escape', '\u'
19
- include_examples 'scan error', RS::PrematureEndError, 'eof in cp escape', '\u0'
20
- include_examples 'scan error', RS::PrematureEndError, 'eof in cp escape', '\u00'
21
- include_examples 'scan error', RS::PrematureEndError, 'eof in cp escape', '\u000'
22
- include_examples 'scan error', RS::PrematureEndError, 'eof in cp escape', '\u{'
23
- include_examples 'scan error', RS::PrematureEndError, 'eof in cp escape', '\u{00'
24
- include_examples 'scan error', RS::PrematureEndError, 'eof in cp escape', '\u{0000'
25
- include_examples 'scan error', RS::PrematureEndError, 'eof in cp escape', '\u{0000 '
26
- include_examples 'scan error', RS::PrematureEndError, 'eof in cp escape', '\u{0000 0000'
27
- include_examples 'scan error', RS::PrematureEndError, 'eof in c-seq', '\c'
28
- include_examples 'scan error', RS::PrematureEndError, 'eof in c-seq', '\c\M'
29
- include_examples 'scan error', RS::PrematureEndError, 'eof in c-seq', '\c\M-'
30
- include_examples 'scan error', RS::PrematureEndError, 'eof in c-seq', '\C'
31
- include_examples 'scan error', RS::PrematureEndError, 'eof in c-seq', '\C-'
32
- include_examples 'scan error', RS::PrematureEndError, 'eof in c-seq', '\C-\M'
33
- include_examples 'scan error', RS::PrematureEndError, 'eof in c-seq', '\C-\M-'
34
- include_examples 'scan error', RS::PrematureEndError, 'eof in m-seq', '\M'
35
- include_examples 'scan error', RS::PrematureEndError, 'eof in m-seq', '\M-'
36
- include_examples 'scan error', RS::PrematureEndError, 'eof in m-seq', '\M-\\'
37
- include_examples 'scan error', RS::PrematureEndError, 'eof in m-seq', '\M-\c'
38
- include_examples 'scan error', RS::PrematureEndError, 'eof in m-seq', '\M-\C'
39
- include_examples 'scan error', RS::PrematureEndError, 'eof in m-seq', '\M-\C-'
40
- include_examples 'scan error', RS::InvalidSequenceError, 'invalid hex', '\xZ'
41
- include_examples 'scan error', RS::InvalidSequenceError, 'invalid hex', '\xZ0'
42
- include_examples 'scan error', RS::InvalidSequenceError, 'invalid c-seq', '\cü'
43
- include_examples 'scan error', RS::InvalidSequenceError, 'invalid c-seq', '\c\M-ü'
44
- include_examples 'scan error', RS::InvalidSequenceError, 'invalid c-seq', '\C-ü'
45
- include_examples 'scan error', RS::InvalidSequenceError, 'invalid c-seq', '\C-\M-ü'
46
- include_examples 'scan error', RS::InvalidSequenceError, 'invalid m-seq', '\M-ü'
47
- include_examples 'scan error', RS::InvalidSequenceError, 'invalid m-seq', '\M-\cü'
48
- include_examples 'scan error', RS::InvalidSequenceError, 'invalid m-seq', '\M-\C-ü'
49
- include_examples 'scan error', RS::ScannerError, 'invalid c-seq', '\Ca'
50
- include_examples 'scan error', RS::ScannerError, 'invalid m-seq', '\Ma'
51
- include_examples 'scan error', RS::InvalidGroupError, 'invalid group', "(?'')"
52
- include_examples 'scan error', RS::InvalidGroupError, 'invalid group', "(?''empty-name)"
53
- include_examples 'scan error', RS::InvalidGroupError, 'invalid group', '(?<>)'
54
- include_examples 'scan error', RS::InvalidGroupError, 'invalid group', '(?<>empty-name)'
55
- include_examples 'scan error', RS::InvalidGroupOption, 'invalid option', '(?foo)'
56
- include_examples 'scan error', RS::InvalidGroupOption, 'invalid option', '(?mix abc)'
57
- include_examples 'scan error', RS::InvalidGroupOption, 'invalid option', '(?mix^bc'
58
- include_examples 'scan error', RS::InvalidGroupOption, 'invalid option', '(?)'
59
- include_examples 'scan error', RS::InvalidGroupOption, 'invalid neg option', '(?-foo)'
60
- include_examples 'scan error', RS::InvalidGroupOption, 'invalid neg option', '(?-u)'
61
- include_examples 'scan error', RS::InvalidGroupOption, 'invalid neg option', '(?-mixu)'
62
- include_examples 'scan error', RS::InvalidBackrefError, 'empty backref', '\k<>'
63
- include_examples 'scan error', RS::InvalidBackrefError, 'empty backref', '\k\'\''
64
- include_examples 'scan error', RS::InvalidBackrefError, 'empty refcall', '\g<>'
65
- include_examples 'scan error', RS::InvalidBackrefError, 'empty refcall', '\g\'\''
66
- include_examples 'scan error', RS::UnknownUnicodePropertyError, 'unknown property', '\p{foobar}'
67
- end