regexp_parser 2.1.1 → 2.2.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (129) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +19 -1
  3. data/LICENSE +1 -1
  4. data/README.md +17 -23
  5. data/Rakefile +10 -19
  6. data/lib/regexp_parser/expression/base.rb +123 -0
  7. data/lib/regexp_parser/expression/classes/anchor.rb +0 -2
  8. data/lib/regexp_parser/expression/classes/{backref.rb → backreference.rb} +0 -0
  9. data/lib/regexp_parser/expression/classes/{set → character_set}/intersection.rb +0 -0
  10. data/lib/regexp_parser/expression/classes/{set → character_set}/range.rb +0 -0
  11. data/lib/regexp_parser/expression/classes/{set.rb → character_set.rb} +0 -0
  12. data/lib/regexp_parser/expression/classes/{escape.rb → escape_sequence.rb} +13 -7
  13. data/lib/regexp_parser/expression/classes/free_space.rb +0 -2
  14. data/lib/regexp_parser/expression/classes/literal.rb +1 -5
  15. data/lib/regexp_parser/expression/classes/property.rb +0 -2
  16. data/lib/regexp_parser/expression/classes/root.rb +0 -1
  17. data/lib/regexp_parser/expression/classes/type.rb +0 -2
  18. data/lib/regexp_parser/expression/methods/strfregexp.rb +1 -1
  19. data/lib/regexp_parser/expression/quantifier.rb +1 -1
  20. data/lib/regexp_parser/expression/sequence.rb +0 -1
  21. data/lib/regexp_parser/expression/subexpression.rb +0 -1
  22. data/lib/regexp_parser/expression.rb +6 -130
  23. data/lib/regexp_parser/lexer.rb +7 -5
  24. data/lib/regexp_parser/scanner/properties/long.csv +604 -0
  25. data/lib/regexp_parser/scanner/properties/short.csv +242 -0
  26. data/lib/regexp_parser/scanner/scanner.rl +6 -4
  27. data/lib/regexp_parser/scanner.rb +126 -124
  28. data/lib/regexp_parser/syntax/any.rb +1 -3
  29. data/lib/regexp_parser/syntax/base.rb +12 -14
  30. data/lib/regexp_parser/syntax/token/anchor.rb +15 -0
  31. data/lib/regexp_parser/syntax/{tokens → token}/assertion.rb +2 -2
  32. data/lib/regexp_parser/syntax/token/backreference.rb +30 -0
  33. data/lib/regexp_parser/syntax/{tokens → token}/character_set.rb +2 -2
  34. data/lib/regexp_parser/syntax/{tokens → token}/character_type.rb +3 -3
  35. data/lib/regexp_parser/syntax/{tokens → token}/conditional.rb +3 -3
  36. data/lib/regexp_parser/syntax/token/escape.rb +31 -0
  37. data/lib/regexp_parser/syntax/{tokens → token}/group.rb +7 -7
  38. data/lib/regexp_parser/syntax/{tokens → token}/keep.rb +1 -1
  39. data/lib/regexp_parser/syntax/{tokens → token}/meta.rb +2 -2
  40. data/lib/regexp_parser/syntax/{tokens → token}/posix_class.rb +3 -3
  41. data/lib/regexp_parser/syntax/token/quantifier.rb +35 -0
  42. data/lib/regexp_parser/syntax/token/unicode_property.rb +696 -0
  43. data/lib/regexp_parser/syntax/token.rb +45 -0
  44. data/lib/regexp_parser/syntax/versions/1.8.6.rb +2 -2
  45. data/lib/regexp_parser/syntax/versions/1.9.1.rb +1 -1
  46. data/lib/regexp_parser/syntax/versions/3.1.0.rb +10 -0
  47. data/lib/regexp_parser/syntax.rb +1 -1
  48. data/lib/regexp_parser/token.rb +9 -20
  49. data/lib/regexp_parser/version.rb +1 -1
  50. data/lib/regexp_parser.rb +0 -2
  51. data/regexp_parser.gemspec +20 -22
  52. metadata +32 -164
  53. data/lib/regexp_parser/scanner/properties/long.yml +0 -594
  54. data/lib/regexp_parser/scanner/properties/short.yml +0 -237
  55. data/lib/regexp_parser/syntax/tokens/anchor.rb +0 -15
  56. data/lib/regexp_parser/syntax/tokens/backref.rb +0 -24
  57. data/lib/regexp_parser/syntax/tokens/escape.rb +0 -30
  58. data/lib/regexp_parser/syntax/tokens/quantifier.rb +0 -35
  59. data/lib/regexp_parser/syntax/tokens/unicode_property.rb +0 -675
  60. data/lib/regexp_parser/syntax/tokens.rb +0 -45
  61. data/spec/expression/base_spec.rb +0 -104
  62. data/spec/expression/clone_spec.rb +0 -152
  63. data/spec/expression/conditional_spec.rb +0 -89
  64. data/spec/expression/free_space_spec.rb +0 -27
  65. data/spec/expression/methods/match_length_spec.rb +0 -161
  66. data/spec/expression/methods/match_spec.rb +0 -25
  67. data/spec/expression/methods/strfregexp_spec.rb +0 -224
  68. data/spec/expression/methods/tests_spec.rb +0 -99
  69. data/spec/expression/methods/traverse_spec.rb +0 -161
  70. data/spec/expression/options_spec.rb +0 -128
  71. data/spec/expression/subexpression_spec.rb +0 -50
  72. data/spec/expression/to_h_spec.rb +0 -26
  73. data/spec/expression/to_s_spec.rb +0 -108
  74. data/spec/lexer/all_spec.rb +0 -22
  75. data/spec/lexer/conditionals_spec.rb +0 -53
  76. data/spec/lexer/delimiters_spec.rb +0 -68
  77. data/spec/lexer/escapes_spec.rb +0 -14
  78. data/spec/lexer/keep_spec.rb +0 -10
  79. data/spec/lexer/literals_spec.rb +0 -64
  80. data/spec/lexer/nesting_spec.rb +0 -99
  81. data/spec/lexer/refcalls_spec.rb +0 -60
  82. data/spec/parser/all_spec.rb +0 -43
  83. data/spec/parser/alternation_spec.rb +0 -88
  84. data/spec/parser/anchors_spec.rb +0 -17
  85. data/spec/parser/conditionals_spec.rb +0 -179
  86. data/spec/parser/errors_spec.rb +0 -30
  87. data/spec/parser/escapes_spec.rb +0 -121
  88. data/spec/parser/free_space_spec.rb +0 -130
  89. data/spec/parser/groups_spec.rb +0 -108
  90. data/spec/parser/keep_spec.rb +0 -6
  91. data/spec/parser/options_spec.rb +0 -28
  92. data/spec/parser/posix_classes_spec.rb +0 -8
  93. data/spec/parser/properties_spec.rb +0 -115
  94. data/spec/parser/quantifiers_spec.rb +0 -68
  95. data/spec/parser/refcalls_spec.rb +0 -117
  96. data/spec/parser/set/intersections_spec.rb +0 -127
  97. data/spec/parser/set/ranges_spec.rb +0 -111
  98. data/spec/parser/sets_spec.rb +0 -178
  99. data/spec/parser/types_spec.rb +0 -18
  100. data/spec/scanner/all_spec.rb +0 -18
  101. data/spec/scanner/anchors_spec.rb +0 -21
  102. data/spec/scanner/conditionals_spec.rb +0 -128
  103. data/spec/scanner/delimiters_spec.rb +0 -52
  104. data/spec/scanner/errors_spec.rb +0 -67
  105. data/spec/scanner/escapes_spec.rb +0 -64
  106. data/spec/scanner/free_space_spec.rb +0 -165
  107. data/spec/scanner/groups_spec.rb +0 -61
  108. data/spec/scanner/keep_spec.rb +0 -10
  109. data/spec/scanner/literals_spec.rb +0 -39
  110. data/spec/scanner/meta_spec.rb +0 -18
  111. data/spec/scanner/options_spec.rb +0 -36
  112. data/spec/scanner/properties_spec.rb +0 -64
  113. data/spec/scanner/quantifiers_spec.rb +0 -25
  114. data/spec/scanner/refcalls_spec.rb +0 -55
  115. data/spec/scanner/sets_spec.rb +0 -151
  116. data/spec/scanner/types_spec.rb +0 -14
  117. data/spec/spec_helper.rb +0 -16
  118. data/spec/support/runner.rb +0 -42
  119. data/spec/support/shared_examples.rb +0 -77
  120. data/spec/support/warning_extractor.rb +0 -60
  121. data/spec/syntax/syntax_spec.rb +0 -48
  122. data/spec/syntax/syntax_token_map_spec.rb +0 -23
  123. data/spec/syntax/versions/1.8.6_spec.rb +0 -17
  124. data/spec/syntax/versions/1.9.1_spec.rb +0 -10
  125. data/spec/syntax/versions/1.9.3_spec.rb +0 -9
  126. data/spec/syntax/versions/2.0.0_spec.rb +0 -13
  127. data/spec/syntax/versions/2.2.0_spec.rb +0 -9
  128. data/spec/syntax/versions/aliases_spec.rb +0 -37
  129. data/spec/token/token_spec.rb +0 -85
@@ -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
@@ -1,64 +0,0 @@
1
- require 'spec_helper'
2
-
3
- RSpec.describe('Escape scanning') do
4
- include_examples 'scan', /c\at/, 1 => [:escape, :bell, '\a', 1, 3]
5
-
6
- # not an escape outside a character set
7
- include_examples 'scan', /c\bt/, 1 => [:anchor, :word_boundary, '\b', 1, 3]
8
-
9
- include_examples 'scan', /c\ft/, 1 => [:escape, :form_feed, '\f', 1, 3]
10
- include_examples 'scan', /c\nt/, 1 => [:escape, :newline, '\n', 1, 3]
11
- include_examples 'scan', /c\tt/, 1 => [:escape, :tab, '\t', 1, 3]
12
- include_examples 'scan', /c\vt/, 1 => [:escape, :vertical_tab, '\v', 1, 3]
13
-
14
- # ineffectual literal escapes
15
- # these cause "Unknown escape" warnings in Ruby for ascii chars,
16
- # and simply drop the backslash for non-ascii chars (/\ü/.inspect == '/ü/').
17
- # In terms of matching, Ruby treats them both like non-escaped literals.
18
- include_examples 'scan', 'c\qt', 1 => [:escape, :literal, '\q', 1, 3]
19
- include_examples 'scan', 'a\üc', 1 => [:escape, :literal, '\ü', 1, 3]
20
- include_examples 'scan', 'a\😋c', 1 => [:escape, :literal, '\😋', 1, 3]
21
-
22
- # these incomplete ref/call sequences are treated as literal escapes by Ruby
23
- include_examples 'scan', 'c\gt', 1 => [:escape, :literal, '\g', 1, 3]
24
- include_examples 'scan', 'c\kt', 1 => [:escape, :literal, '\k', 1, 3]
25
-
26
- include_examples 'scan', 'a\012c', 1 => [:escape, :octal, '\012', 1, 5]
27
- include_examples 'scan', 'a\0124', 1 => [:escape, :octal, '\012', 1, 5]
28
- include_examples 'scan', '\712+7', 0 => [:escape, :octal, '\712', 0, 4]
29
-
30
- include_examples 'scan', 'a\xA', 1 => [:escape, :hex, '\xA', 1, 4]
31
- include_examples 'scan', 'a\x24c', 1 => [:escape, :hex, '\x24', 1, 5]
32
- include_examples 'scan', 'a\x0640c', 1 => [:escape, :hex, '\x06', 1, 5]
33
-
34
- include_examples 'scan', 'a\u0640c', 1 => [:escape, :codepoint, '\u0640', 1, 7]
35
- include_examples 'scan', 'a\u{640 0641}c', 1 => [:escape, :codepoint_list, '\u{640 0641}', 1, 13]
36
- include_examples 'scan', 'a\u{10FFFF}c', 1 => [:escape, :codepoint_list, '\u{10FFFF}', 1, 11]
37
-
38
- include_examples 'scan', /a\cBc/, 1 => [:escape, :control, '\cB', 1, 4]
39
- include_examples 'scan', /a\c^c/, 1 => [:escape, :control, '\c^', 1, 4]
40
- include_examples 'scan', /a\c\n/, 1 => [:escape, :control, '\c\n', 1, 5]
41
- include_examples 'scan', /a\c\\b/, 1 => [:escape, :control, '\c\\\\', 1, 5]
42
- include_examples 'scan', /a\C-bc/, 1 => [:escape, :control, '\C-b', 1, 5]
43
- include_examples 'scan', /a\C-^b/, 1 => [:escape, :control, '\C-^', 1, 5]
44
- include_examples 'scan', /a\C-\nb/, 1 => [:escape, :control, '\C-\n', 1, 6]
45
- include_examples 'scan', /a\C-\\b/, 1 => [:escape, :control, '\C-\\\\', 1, 6]
46
- include_examples 'scan', /a\c\M-Bc/n, 1 => [:escape, :control, '\c\M-B', 1, 7]
47
- include_examples 'scan', /a\C-\M-Bc/n, 1 => [:escape, :control, '\C-\M-B', 1, 8]
48
-
49
- include_examples 'scan', /a\M-Bc/n, 1 => [:escape, :meta_sequence, '\M-B', 1, 5]
50
- include_examples 'scan', /a\M-\cBc/n, 1 => [:escape, :meta_sequence, '\M-\cB', 1, 7]
51
- include_examples 'scan', /a\M-\c^/n, 1 => [:escape, :meta_sequence, '\M-\c^', 1, 7]
52
- include_examples 'scan', /a\M-\c\n/n, 1 => [:escape, :meta_sequence, '\M-\c\n', 1, 8]
53
- include_examples 'scan', /a\M-\c\\/n, 1 => [:escape, :meta_sequence, '\M-\c\\\\', 1, 8]
54
- include_examples 'scan', /a\M-\C-Bc/n, 1 => [:escape, :meta_sequence, '\M-\C-B', 1, 8]
55
- include_examples 'scan', /a\M-\C-\\/n, 1 => [:escape, :meta_sequence, '\M-\C-\\\\', 1, 9]
56
-
57
- include_examples 'scan', 'ab\\\xcd', 1 => [:escape, :backslash, '\\\\', 2, 4]
58
- include_examples 'scan', 'ab\\\0cd', 1 => [:escape, :backslash, '\\\\', 2, 4]
59
- include_examples 'scan', 'ab\\\Kcd', 1 => [:escape, :backslash, '\\\\', 2, 4]
60
-
61
- include_examples 'scan', 'ab\^cd', 1 => [:escape, :bol, '\^', 2, 4]
62
- include_examples 'scan', 'ab\$cd', 1 => [:escape, :eol, '\$', 2, 4]
63
- include_examples 'scan', 'ab\[cd', 1 => [:escape, :set_open, '\[', 2, 4]
64
- end