regexp_parser 1.7.0 → 2.9.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (166) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +9 -3
  3. data/LICENSE +1 -1
  4. data/Rakefile +6 -70
  5. data/lib/regexp_parser/error.rb +4 -0
  6. data/lib/regexp_parser/expression/base.rb +76 -0
  7. data/lib/regexp_parser/expression/classes/alternation.rb +1 -1
  8. data/lib/regexp_parser/expression/classes/anchor.rb +0 -2
  9. data/lib/regexp_parser/expression/classes/{backref.rb → backreference.rb} +22 -2
  10. data/lib/regexp_parser/expression/classes/{set → character_set}/range.rb +4 -8
  11. data/lib/regexp_parser/expression/classes/{set.rb → character_set.rb} +4 -8
  12. data/lib/regexp_parser/expression/classes/{type.rb → character_type.rb} +0 -2
  13. data/lib/regexp_parser/expression/classes/conditional.rb +11 -5
  14. data/lib/regexp_parser/expression/classes/{escape.rb → escape_sequence.rb} +15 -7
  15. data/lib/regexp_parser/expression/classes/free_space.rb +5 -5
  16. data/lib/regexp_parser/expression/classes/group.rb +28 -15
  17. data/lib/regexp_parser/expression/classes/keep.rb +2 -0
  18. data/lib/regexp_parser/expression/classes/literal.rb +1 -5
  19. data/lib/regexp_parser/expression/classes/posix_class.rb +5 -5
  20. data/lib/regexp_parser/expression/classes/root.rb +4 -19
  21. data/lib/regexp_parser/expression/classes/{property.rb → unicode_property.rb} +11 -12
  22. data/lib/regexp_parser/expression/methods/construct.rb +41 -0
  23. data/lib/regexp_parser/expression/methods/human_name.rb +43 -0
  24. data/lib/regexp_parser/expression/methods/match_length.rb +11 -7
  25. data/lib/regexp_parser/expression/methods/negative.rb +20 -0
  26. data/lib/regexp_parser/expression/methods/parts.rb +23 -0
  27. data/lib/regexp_parser/expression/methods/printing.rb +26 -0
  28. data/lib/regexp_parser/expression/methods/strfregexp.rb +1 -1
  29. data/lib/regexp_parser/expression/methods/tests.rb +47 -1
  30. data/lib/regexp_parser/expression/methods/traverse.rb +34 -18
  31. data/lib/regexp_parser/expression/quantifier.rb +57 -17
  32. data/lib/regexp_parser/expression/sequence.rb +11 -47
  33. data/lib/regexp_parser/expression/sequence_operation.rb +4 -9
  34. data/lib/regexp_parser/expression/shared.rb +111 -0
  35. data/lib/regexp_parser/expression/subexpression.rb +27 -19
  36. data/lib/regexp_parser/expression.rb +15 -141
  37. data/lib/regexp_parser/lexer.rb +83 -41
  38. data/lib/regexp_parser/parser.rb +372 -429
  39. data/lib/regexp_parser/scanner/char_type.rl +11 -11
  40. data/lib/regexp_parser/scanner/errors/premature_end_error.rb +8 -0
  41. data/lib/regexp_parser/scanner/errors/scanner_error.rb +6 -0
  42. data/lib/regexp_parser/scanner/errors/validation_error.rb +63 -0
  43. data/lib/regexp_parser/scanner/properties/long.csv +651 -0
  44. data/lib/regexp_parser/scanner/properties/short.csv +249 -0
  45. data/lib/regexp_parser/scanner/property.rl +4 -4
  46. data/lib/regexp_parser/scanner/scanner.rl +303 -368
  47. data/lib/regexp_parser/scanner.rb +1423 -1674
  48. data/lib/regexp_parser/syntax/any.rb +2 -7
  49. data/lib/regexp_parser/syntax/base.rb +92 -67
  50. data/lib/regexp_parser/syntax/token/anchor.rb +15 -0
  51. data/lib/regexp_parser/syntax/{tokens → token}/assertion.rb +2 -2
  52. data/lib/regexp_parser/syntax/token/backreference.rb +33 -0
  53. data/lib/regexp_parser/syntax/token/character_set.rb +16 -0
  54. data/lib/regexp_parser/syntax/{tokens → token}/character_type.rb +3 -3
  55. data/lib/regexp_parser/syntax/{tokens → token}/conditional.rb +3 -3
  56. data/lib/regexp_parser/syntax/token/escape.rb +33 -0
  57. data/lib/regexp_parser/syntax/{tokens → token}/group.rb +7 -7
  58. data/lib/regexp_parser/syntax/{tokens → token}/keep.rb +1 -1
  59. data/lib/regexp_parser/syntax/token/meta.rb +20 -0
  60. data/lib/regexp_parser/syntax/{tokens → token}/posix_class.rb +3 -3
  61. data/lib/regexp_parser/syntax/token/quantifier.rb +35 -0
  62. data/lib/regexp_parser/syntax/token/unicode_property.rb +751 -0
  63. data/lib/regexp_parser/syntax/token/virtual.rb +11 -0
  64. data/lib/regexp_parser/syntax/token.rb +45 -0
  65. data/lib/regexp_parser/syntax/version_lookup.rb +19 -36
  66. data/lib/regexp_parser/syntax/versions/1.8.6.rb +13 -20
  67. data/lib/regexp_parser/syntax/versions/1.9.1.rb +10 -17
  68. data/lib/regexp_parser/syntax/versions/1.9.3.rb +3 -10
  69. data/lib/regexp_parser/syntax/versions/2.0.0.rb +8 -15
  70. data/lib/regexp_parser/syntax/versions/2.2.0.rb +3 -9
  71. data/lib/regexp_parser/syntax/versions/2.3.0.rb +3 -9
  72. data/lib/regexp_parser/syntax/versions/2.4.0.rb +3 -9
  73. data/lib/regexp_parser/syntax/versions/2.4.1.rb +2 -8
  74. data/lib/regexp_parser/syntax/versions/2.5.0.rb +3 -9
  75. data/lib/regexp_parser/syntax/versions/2.6.0.rb +3 -9
  76. data/lib/regexp_parser/syntax/versions/2.6.2.rb +3 -9
  77. data/lib/regexp_parser/syntax/versions/2.6.3.rb +3 -9
  78. data/lib/regexp_parser/syntax/versions/3.1.0.rb +4 -0
  79. data/lib/regexp_parser/syntax/versions/3.2.0.rb +4 -0
  80. data/lib/regexp_parser/syntax/versions.rb +3 -1
  81. data/lib/regexp_parser/syntax.rb +8 -6
  82. data/lib/regexp_parser/token.rb +9 -20
  83. data/lib/regexp_parser/version.rb +1 -1
  84. data/lib/regexp_parser.rb +0 -2
  85. data/regexp_parser.gemspec +19 -23
  86. metadata +53 -171
  87. data/CHANGELOG.md +0 -349
  88. data/README.md +0 -470
  89. data/lib/regexp_parser/scanner/properties/long.yml +0 -594
  90. data/lib/regexp_parser/scanner/properties/short.yml +0 -237
  91. data/lib/regexp_parser/syntax/tokens/anchor.rb +0 -15
  92. data/lib/regexp_parser/syntax/tokens/backref.rb +0 -24
  93. data/lib/regexp_parser/syntax/tokens/character_set.rb +0 -13
  94. data/lib/regexp_parser/syntax/tokens/escape.rb +0 -30
  95. data/lib/regexp_parser/syntax/tokens/meta.rb +0 -13
  96. data/lib/regexp_parser/syntax/tokens/quantifier.rb +0 -35
  97. data/lib/regexp_parser/syntax/tokens/unicode_property.rb +0 -675
  98. data/lib/regexp_parser/syntax/tokens.rb +0 -45
  99. data/spec/expression/base_spec.rb +0 -94
  100. data/spec/expression/clone_spec.rb +0 -120
  101. data/spec/expression/conditional_spec.rb +0 -89
  102. data/spec/expression/free_space_spec.rb +0 -27
  103. data/spec/expression/methods/match_length_spec.rb +0 -161
  104. data/spec/expression/methods/match_spec.rb +0 -25
  105. data/spec/expression/methods/strfregexp_spec.rb +0 -224
  106. data/spec/expression/methods/tests_spec.rb +0 -99
  107. data/spec/expression/methods/traverse_spec.rb +0 -161
  108. data/spec/expression/options_spec.rb +0 -128
  109. data/spec/expression/root_spec.rb +0 -9
  110. data/spec/expression/sequence_spec.rb +0 -9
  111. data/spec/expression/subexpression_spec.rb +0 -50
  112. data/spec/expression/to_h_spec.rb +0 -26
  113. data/spec/expression/to_s_spec.rb +0 -100
  114. data/spec/lexer/all_spec.rb +0 -22
  115. data/spec/lexer/conditionals_spec.rb +0 -53
  116. data/spec/lexer/escapes_spec.rb +0 -14
  117. data/spec/lexer/keep_spec.rb +0 -10
  118. data/spec/lexer/literals_spec.rb +0 -89
  119. data/spec/lexer/nesting_spec.rb +0 -99
  120. data/spec/lexer/refcalls_spec.rb +0 -55
  121. data/spec/parser/all_spec.rb +0 -43
  122. data/spec/parser/alternation_spec.rb +0 -88
  123. data/spec/parser/anchors_spec.rb +0 -17
  124. data/spec/parser/conditionals_spec.rb +0 -179
  125. data/spec/parser/errors_spec.rb +0 -30
  126. data/spec/parser/escapes_spec.rb +0 -121
  127. data/spec/parser/free_space_spec.rb +0 -130
  128. data/spec/parser/groups_spec.rb +0 -108
  129. data/spec/parser/keep_spec.rb +0 -6
  130. data/spec/parser/posix_classes_spec.rb +0 -8
  131. data/spec/parser/properties_spec.rb +0 -115
  132. data/spec/parser/quantifiers_spec.rb +0 -51
  133. data/spec/parser/refcalls_spec.rb +0 -112
  134. data/spec/parser/set/intersections_spec.rb +0 -127
  135. data/spec/parser/set/ranges_spec.rb +0 -111
  136. data/spec/parser/sets_spec.rb +0 -178
  137. data/spec/parser/types_spec.rb +0 -18
  138. data/spec/scanner/all_spec.rb +0 -18
  139. data/spec/scanner/anchors_spec.rb +0 -21
  140. data/spec/scanner/conditionals_spec.rb +0 -128
  141. data/spec/scanner/errors_spec.rb +0 -68
  142. data/spec/scanner/escapes_spec.rb +0 -53
  143. data/spec/scanner/free_space_spec.rb +0 -133
  144. data/spec/scanner/groups_spec.rb +0 -52
  145. data/spec/scanner/keep_spec.rb +0 -10
  146. data/spec/scanner/literals_spec.rb +0 -49
  147. data/spec/scanner/meta_spec.rb +0 -18
  148. data/spec/scanner/properties_spec.rb +0 -64
  149. data/spec/scanner/quantifiers_spec.rb +0 -20
  150. data/spec/scanner/refcalls_spec.rb +0 -36
  151. data/spec/scanner/sets_spec.rb +0 -102
  152. data/spec/scanner/types_spec.rb +0 -14
  153. data/spec/spec_helper.rb +0 -15
  154. data/spec/support/runner.rb +0 -42
  155. data/spec/support/shared_examples.rb +0 -77
  156. data/spec/support/warning_extractor.rb +0 -60
  157. data/spec/syntax/syntax_spec.rb +0 -48
  158. data/spec/syntax/syntax_token_map_spec.rb +0 -23
  159. data/spec/syntax/versions/1.8.6_spec.rb +0 -17
  160. data/spec/syntax/versions/1.9.1_spec.rb +0 -10
  161. data/spec/syntax/versions/1.9.3_spec.rb +0 -9
  162. data/spec/syntax/versions/2.0.0_spec.rb +0 -13
  163. data/spec/syntax/versions/2.2.0_spec.rb +0 -9
  164. data/spec/syntax/versions/aliases_spec.rb +0 -37
  165. data/spec/token/token_spec.rb +0 -85
  166. /data/lib/regexp_parser/expression/classes/{set → character_set}/intersection.rb +0 -0
@@ -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,68 +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, 'unbalanced interval', 'a{1,2'
14
- include_examples 'scan error', RS::PrematureEndError, 'eof in property', '\p{asci'
15
- include_examples 'scan error', RS::PrematureEndError, 'incomplete property', '\p{ascii abc'
16
- include_examples 'scan error', RS::PrematureEndError, 'eof options', '(?mix'
17
- include_examples 'scan error', RS::PrematureEndError, 'eof escape', '\\'
18
- include_examples 'scan error', RS::PrematureEndError, 'eof in hex escape', '\x'
19
- include_examples 'scan error', RS::PrematureEndError, 'eof in cp escape', '\u'
20
- include_examples 'scan error', RS::PrematureEndError, 'eof in cp escape', '\u0'
21
- include_examples 'scan error', RS::PrematureEndError, 'eof in cp escape', '\u00'
22
- include_examples 'scan error', RS::PrematureEndError, 'eof in cp escape', '\u000'
23
- include_examples 'scan error', RS::PrematureEndError, 'eof in cp escape', '\u{'
24
- include_examples 'scan error', RS::PrematureEndError, 'eof in cp escape', '\u{00'
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 '
27
- include_examples 'scan error', RS::PrematureEndError, 'eof in cp escape', '\u{0000 0000'
28
- include_examples 'scan error', RS::PrematureEndError, 'eof in c-seq', '\c'
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\M-'
31
- include_examples 'scan error', RS::PrematureEndError, 'eof in c-seq', '\C'
32
- include_examples 'scan error', RS::PrematureEndError, 'eof in c-seq', '\C-'
33
- include_examples 'scan error', RS::PrematureEndError, 'eof in c-seq', '\C-\M'
34
- include_examples 'scan error', RS::PrematureEndError, 'eof in c-seq', '\C-\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-\\'
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::PrematureEndError, 'eof in m-seq', '\M-\C-'
41
- include_examples 'scan error', RS::InvalidSequenceError, 'invalid hex', '\xZ'
42
- include_examples 'scan error', RS::InvalidSequenceError, 'invalid hex', '\xZ0'
43
- include_examples 'scan error', RS::InvalidSequenceError, 'invalid c-seq', '\cü'
44
- include_examples 'scan error', RS::InvalidSequenceError, 'invalid c-seq', '\c\M-ü'
45
- include_examples 'scan error', RS::InvalidSequenceError, 'invalid c-seq', '\C-ü'
46
- include_examples 'scan error', RS::InvalidSequenceError, 'invalid c-seq', '\C-\M-ü'
47
- include_examples 'scan error', RS::InvalidSequenceError, 'invalid m-seq', '\M-ü'
48
- include_examples 'scan error', RS::InvalidSequenceError, 'invalid m-seq', '\M-\cü'
49
- include_examples 'scan error', RS::InvalidSequenceError, 'invalid m-seq', '\M-\C-ü'
50
- include_examples 'scan error', RS::ScannerError, 'invalid c-seq', '\Ca'
51
- include_examples 'scan error', RS::ScannerError, 'invalid m-seq', '\Ma'
52
- include_examples 'scan error', RS::InvalidGroupError, 'invalid group', "(?'')"
53
- include_examples 'scan error', RS::InvalidGroupError, 'invalid group', "(?''empty-name)"
54
- include_examples 'scan error', RS::InvalidGroupError, 'invalid group', '(?<>)'
55
- include_examples 'scan error', RS::InvalidGroupError, 'invalid group', '(?<>empty-name)'
56
- include_examples 'scan error', RS::InvalidGroupOption, 'invalid option', '(?foo)'
57
- include_examples 'scan error', RS::InvalidGroupOption, 'invalid option', '(?mix abc)'
58
- include_examples 'scan error', RS::InvalidGroupOption, 'invalid option', '(?mix^bc'
59
- include_examples 'scan error', RS::InvalidGroupOption, 'invalid option', '(?)'
60
- include_examples 'scan error', RS::InvalidGroupOption, 'invalid neg option', '(?-foo)'
61
- include_examples 'scan error', RS::InvalidGroupOption, 'invalid neg option', '(?-u)'
62
- include_examples 'scan error', RS::InvalidGroupOption, 'invalid neg option', '(?-mixu)'
63
- include_examples 'scan error', RS::InvalidBackrefError, 'empty backref', '\k<>'
64
- include_examples 'scan error', RS::InvalidBackrefError, 'empty backref', '\k\'\''
65
- include_examples 'scan error', RS::InvalidBackrefError, 'empty refcall', '\g<>'
66
- include_examples 'scan error', RS::InvalidBackrefError, 'empty refcall', '\g\'\''
67
- include_examples 'scan error', RS::UnknownUnicodePropertyError, 'unknown property', '\p{foobar}'
68
- end
@@ -1,53 +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
- include_examples 'scan', 'c\qt', 1 => [:escape, :literal, '\q', 1, 3]
15
-
16
- include_examples 'scan', 'a\012c', 1 => [:escape, :octal, '\012', 1, 5]
17
- include_examples 'scan', 'a\0124', 1 => [:escape, :octal, '\012', 1, 5]
18
- include_examples 'scan', '\712+7', 0 => [:escape, :octal, '\712', 0, 4]
19
-
20
- include_examples 'scan', 'a\x24c', 1 => [:escape, :hex, '\x24', 1, 5]
21
- include_examples 'scan', 'a\x0640c', 1 => [:escape, :hex, '\x06', 1, 5]
22
-
23
- include_examples 'scan', 'a\u0640c', 1 => [:escape, :codepoint, '\u0640', 1, 7]
24
- include_examples 'scan', 'a\u{640 0641}c', 1 => [:escape, :codepoint_list, '\u{640 0641}', 1, 13]
25
- include_examples 'scan', 'a\u{10FFFF}c', 1 => [:escape, :codepoint_list, '\u{10FFFF}', 1, 11]
26
-
27
- include_examples 'scan', /a\cBc/, 1 => [:escape, :control, '\cB', 1, 4]
28
- include_examples 'scan', /a\c^c/, 1 => [:escape, :control, '\c^', 1, 4]
29
- include_examples 'scan', /a\c\n/, 1 => [:escape, :control, '\c\n', 1, 5]
30
- include_examples 'scan', /a\c\\b/, 1 => [:escape, :control, '\c\\\\', 1, 5]
31
- include_examples 'scan', /a\C-bc/, 1 => [:escape, :control, '\C-b', 1, 5]
32
- include_examples 'scan', /a\C-^b/, 1 => [:escape, :control, '\C-^', 1, 5]
33
- include_examples 'scan', /a\C-\nb/, 1 => [:escape, :control, '\C-\n', 1, 6]
34
- include_examples 'scan', /a\C-\\b/, 1 => [:escape, :control, '\C-\\\\', 1, 6]
35
- include_examples 'scan', /a\c\M-Bc/n, 1 => [:escape, :control, '\c\M-B', 1, 7]
36
- include_examples 'scan', /a\C-\M-Bc/n, 1 => [:escape, :control, '\C-\M-B', 1, 8]
37
-
38
- include_examples 'scan', /a\M-Bc/n, 1 => [:escape, :meta_sequence, '\M-B', 1, 5]
39
- include_examples 'scan', /a\M-\cBc/n, 1 => [:escape, :meta_sequence, '\M-\cB', 1, 7]
40
- include_examples 'scan', /a\M-\c^/n, 1 => [:escape, :meta_sequence, '\M-\c^', 1, 7]
41
- include_examples 'scan', /a\M-\c\n/n, 1 => [:escape, :meta_sequence, '\M-\c\n', 1, 8]
42
- include_examples 'scan', /a\M-\c\\/n, 1 => [:escape, :meta_sequence, '\M-\c\\\\', 1, 8]
43
- include_examples 'scan', /a\M-\C-Bc/n, 1 => [:escape, :meta_sequence, '\M-\C-B', 1, 8]
44
- include_examples 'scan', /a\M-\C-\\/n, 1 => [:escape, :meta_sequence, '\M-\C-\\\\', 1, 9]
45
-
46
- include_examples 'scan', 'ab\\\xcd', 1 => [:escape, :backslash, '\\\\', 2, 4]
47
- include_examples 'scan', 'ab\\\0cd', 1 => [:escape, :backslash, '\\\\', 2, 4]
48
- include_examples 'scan', 'ab\\\Kcd', 1 => [:escape, :backslash, '\\\\', 2, 4]
49
-
50
- include_examples 'scan', 'ab\^cd', 1 => [:escape, :bol, '\^', 2, 4]
51
- include_examples 'scan', 'ab\$cd', 1 => [:escape, :eol, '\$', 2, 4]
52
- include_examples 'scan', 'ab\[cd', 1 => [:escape, :set_open, '\[', 2, 4]
53
- end
@@ -1,133 +0,0 @@
1
- require 'spec_helper'
2
-
3
- RSpec.describe('FreeSpace scanning') do
4
- describe('scan free space tokens') do
5
- let(:tokens) { RS.scan(/
6
- a
7
- b ? c *
8
- d {2,3}
9
- e + | f +
10
- /x) }
11
-
12
- 0.upto(24).select(&:even?).each do |i|
13
- it "scans #{i} as free space" do
14
- expect(tokens[i][0]).to eq :free_space
15
- expect(tokens[i][1]).to eq :whitespace
16
- end
17
- end
18
- 0.upto(24).reject(&:even?).each do |i|
19
- it "does not scan #{i} as free space" do
20
- expect(tokens[i][0]).not_to eq :free_space
21
- expect(tokens[i][1]).not_to eq :whitespace
22
- end
23
- end
24
-
25
- it 'sets the correct text' do
26
- [0, 2, 10, 14].each { |i| expect(tokens[i][2]).to eq "\n " }
27
- [4, 6, 8, 12].each { |i| expect(tokens[i][2]).to eq ' ' }
28
- end
29
- end
30
-
31
- describe('scan free space comments') do
32
- include_examples 'scan', /
33
- a + # A + comment
34
- b ? # B ? comment
35
- c {2,3} # C {2,3} comment
36
- d + | e + # D|E comment
37
- /x,
38
- 5 => [:free_space, :comment, "# A + comment\n", 11, 25],
39
- 11 => [:free_space, :comment, "# B ? comment\n", 37, 51],
40
- 17 => [:free_space, :comment, "# C {2,3} comment\n", 66, 84],
41
- 29 => [:free_space, :comment, "# D|E comment\n", 100, 114]
42
- end
43
-
44
- describe('scan free space inlined') do
45
- include_examples 'scan', /a b(?x:c d e)f g/,
46
- 0 => [:literal, :literal, 'a b', 0, 3],
47
- 1 => [:group, :options, '(?x:', 3, 7],
48
- 2 => [:literal, :literal, 'c', 7, 8],
49
- 3 => [:free_space, :whitespace, ' ', 8, 9],
50
- 4 => [:literal, :literal, 'd', 9, 10],
51
- 5 => [:free_space, :whitespace, ' ', 10, 11],
52
- 6 => [:literal, :literal, 'e', 11, 12],
53
- 7 => [:group, :close, ')', 12, 13],
54
- 8 => [:literal, :literal, 'f g', 13, 16]
55
- end
56
-
57
- describe('scan free space nested') do
58
- include_examples 'scan', /a b(?x:c d(?-x:e f)g h)i j/,
59
- 0 => [:literal, :literal, 'a b', 0, 3],
60
- 1 => [:group, :options, '(?x:', 3, 7],
61
- 2 => [:literal, :literal, 'c', 7, 8],
62
- 3 => [:free_space, :whitespace, ' ', 8, 9],
63
- 4 => [:literal, :literal, 'd', 9, 10],
64
- 5 => [:group, :options, '(?-x:', 10, 15],
65
- 6 => [:literal, :literal, 'e f', 15, 18],
66
- 7 => [:group, :close, ')', 18, 19],
67
- 8 => [:literal, :literal, 'g', 19, 20],
68
- 9 => [:free_space, :whitespace, ' ', 20, 21],
69
- 10 => [:literal, :literal, 'h', 21, 22],
70
- 11 => [:group, :close, ')', 22, 23],
71
- 12 => [:literal, :literal, 'i j', 23, 26]
72
- end
73
-
74
- describe('scan free space nested groups') do
75
- include_examples 'scan', /(a (b(?x: (c d) (?-x:(e f) )g) h)i j)/,
76
- 0 => [:group, :capture, '(', 0, 1],
77
- 1 => [:literal, :literal, 'a ', 1, 3],
78
- 2 => [:group, :capture, '(', 3, 4],
79
- 3 => [:literal, :literal, 'b', 4, 5],
80
- 4 => [:group, :options, '(?x:', 5, 9],
81
- 5 => [:free_space, :whitespace, ' ', 9, 10],
82
- 6 => [:group, :capture, '(', 10, 11],
83
- 7 => [:literal, :literal, 'c', 11, 12],
84
- 8 => [:free_space, :whitespace, ' ', 12, 13],
85
- 9 => [:literal, :literal, 'd', 13, 14],
86
- 10 => [:group, :close, ')', 14, 15],
87
- 11 => [:free_space, :whitespace, ' ', 15, 16],
88
- 12 => [:group, :options, '(?-x:', 16, 21],
89
- 13 => [:group, :capture, '(', 21, 22],
90
- 14 => [:literal, :literal, 'e f', 22, 25],
91
- 15 => [:group, :close, ')', 25, 26],
92
- 16 => [:literal, :literal, ' ', 26, 27],
93
- 17 => [:group, :close, ')', 27, 28],
94
- 18 => [:literal, :literal, 'g', 28, 29],
95
- 19 => [:group, :close, ')', 29, 30],
96
- 20 => [:literal, :literal, ' h', 30, 32],
97
- 21 => [:group, :close, ')', 32, 33],
98
- 22 => [:literal, :literal, 'i j', 33, 36],
99
- 23 => [:group, :close, ')', 36, 37]
100
- end
101
-
102
- describe('scan free space switch groups') do
103
- include_examples 'scan', /(a (b((?x) (c d) ((?-x)(e f) )g) h)i j)/,
104
- 0 => [:group, :capture, '(', 0, 1],
105
- 1 => [:literal, :literal, 'a ', 1, 3],
106
- 2 => [:group, :capture, '(', 3, 4],
107
- 3 => [:literal, :literal, 'b', 4, 5],
108
- 4 => [:group, :capture, '(', 5, 6],
109
- 5 => [:group, :options_switch, '(?x', 6, 9],
110
- 6 => [:group, :close, ')', 9, 10],
111
- 7 => [:free_space, :whitespace, ' ', 10, 11],
112
- 8 => [:group, :capture, '(', 11, 12],
113
- 9 => [:literal, :literal, 'c', 12, 13],
114
- 10 => [:free_space, :whitespace, ' ', 13, 14],
115
- 11 => [:literal, :literal, 'd', 14, 15],
116
- 12 => [:group, :close, ')', 15, 16],
117
- 13 => [:free_space, :whitespace, ' ', 16, 17],
118
- 14 => [:group, :capture, '(', 17, 18],
119
- 15 => [:group, :options_switch, '(?-x', 18, 22],
120
- 16 => [:group, :close, ')', 22, 23],
121
- 17 => [:group, :capture, '(', 23, 24],
122
- 18 => [:literal, :literal, 'e f', 24, 27],
123
- 19 => [:group, :close, ')', 27, 28],
124
- 20 => [:literal, :literal, ' ', 28, 29],
125
- 21 => [:group, :close, ')', 29, 30],
126
- 22 => [:literal, :literal, 'g', 30, 31],
127
- 23 => [:group, :close, ')', 31, 32],
128
- 24 => [:literal, :literal, ' h', 32, 34],
129
- 25 => [:group, :close, ')', 34, 35],
130
- 26 => [:literal, :literal, 'i j', 35, 38],
131
- 27 => [:group, :close, ')', 38, 39]
132
- end
133
- end
@@ -1,52 +0,0 @@
1
- require 'spec_helper'
2
-
3
- RSpec.describe('Group scanning') do
4
- # Group types
5
- include_examples 'scan', '(?>abc)', 0 => [:group, :atomic, '(?>', 0, 3]
6
- include_examples 'scan', '(abc)', 0 => [:group, :capture, '(', 0, 1]
7
-
8
- include_examples 'scan', '(?<name>abc)', 0 => [:group, :named_ab, '(?<name>', 0, 8]
9
- include_examples 'scan', "(?'name'abc)", 0 => [:group, :named_sq, "(?'name'", 0, 8]
10
-
11
- include_examples 'scan', '(?<name_1>abc)', 0 => [:group, :named_ab, '(?<name_1>', 0,10]
12
- include_examples 'scan', "(?'name_1'abc)", 0 => [:group, :named_sq, "(?'name_1'", 0,10]
13
-
14
- include_examples 'scan', '(?:abc)', 0 => [:group, :passive, '(?:', 0, 3]
15
- include_examples 'scan', '(?:)', 0 => [:group, :passive, '(?:', 0, 3]
16
- include_examples 'scan', '(?::)', 0 => [:group, :passive, '(?:', 0, 3]
17
-
18
- # Comments
19
- include_examples 'scan', '(?#abc)', 0 => [:group, :comment, '(?#abc)', 0, 7]
20
- include_examples 'scan', '(?#)', 0 => [:group, :comment, '(?#)', 0, 4]
21
-
22
- # Assertions
23
- include_examples 'scan', '(?=abc)', 0 => [:assertion, :lookahead, '(?=', 0, 3]
24
- include_examples 'scan', '(?!abc)', 0 => [:assertion, :nlookahead, '(?!', 0, 3]
25
- include_examples 'scan', '(?<=abc)', 0 => [:assertion, :lookbehind, '(?<=', 0, 4]
26
- include_examples 'scan', '(?<!abc)', 0 => [:assertion, :nlookbehind, '(?<!', 0, 4]
27
-
28
- # Options
29
- include_examples 'scan', '(?-mix:abc)', 0 => [:group, :options, '(?-mix:', 0, 7]
30
- include_examples 'scan', '(?m-ix:abc)', 0 => [:group, :options, '(?m-ix:', 0, 7]
31
- include_examples 'scan', '(?mi-x:abc)', 0 => [:group, :options, '(?mi-x:', 0, 7]
32
- include_examples 'scan', '(?mix:abc)', 0 => [:group, :options, '(?mix:', 0, 6]
33
- include_examples 'scan', '(?m:)', 0 => [:group, :options, '(?m:', 0, 4]
34
- include_examples 'scan', '(?i:)', 0 => [:group, :options, '(?i:', 0, 4]
35
- include_examples 'scan', '(?x:)', 0 => [:group, :options, '(?x:', 0, 4]
36
- include_examples 'scan', '(?mix)', 0 => [:group, :options_switch, '(?mix', 0, 5]
37
- include_examples 'scan', '(?d-mix:abc)', 0 => [:group, :options, '(?d-mix:', 0, 8]
38
- include_examples 'scan', '(?a-mix:abc)', 0 => [:group, :options, '(?a-mix:', 0, 8]
39
- include_examples 'scan', '(?u-mix:abc)', 0 => [:group, :options, '(?u-mix:', 0, 8]
40
- include_examples 'scan', '(?da-m:abc)', 0 => [:group, :options, '(?da-m:', 0, 7]
41
- include_examples 'scan', '(?du-x:abc)', 0 => [:group, :options, '(?du-x:', 0, 7]
42
- include_examples 'scan', '(?dau-i:abc)', 0 => [:group, :options, '(?dau-i:', 0, 8]
43
- include_examples 'scan', '(?dau:abc)', 0 => [:group, :options, '(?dau:', 0, 6]
44
- include_examples 'scan', '(?d:)', 0 => [:group, :options, '(?d:', 0, 4]
45
- include_examples 'scan', '(?a:)', 0 => [:group, :options, '(?a:', 0, 4]
46
- include_examples 'scan', '(?u:)', 0 => [:group, :options, '(?u:', 0, 4]
47
- include_examples 'scan', '(?dau)', 0 => [:group, :options_switch, '(?dau', 0, 5]
48
-
49
- if ruby_version_at_least('2.4.1')
50
- include_examples 'scan', '(?~abc)', 0 => [:group, :absence, '(?~', 0, 3]
51
- end
52
- end
@@ -1,10 +0,0 @@
1
- require 'spec_helper'
2
-
3
- RSpec.describe('Keep scanning') do
4
- include_examples 'scan', /ab\Kcd/,
5
- 1 => [:keep, :mark, '\K', 2, 4]
6
-
7
- include_examples 'scan', /(a\Kb)|(c\\\Kd)ef/,
8
- 2 => [:keep, :mark, '\K', 2, 4],
9
- 9 => [:keep, :mark, '\K', 11, 13]
10
- end
@@ -1,49 +0,0 @@
1
- require 'spec_helper'
2
-
3
- RSpec.describe('UTF8 scanning') do
4
- # ascii, single byte characters
5
- include_examples 'scan', 'a', 0 => [:literal, :literal, 'a', 0, 1]
6
-
7
- include_examples 'scan', 'ab+', 0 => [:literal, :literal, 'ab', 0, 2]
8
- include_examples 'scan', 'ab+', 1 => [:quantifier, :one_or_more, '+', 2, 3]
9
-
10
- # 2 byte wide characters, Arabic
11
- include_examples 'scan', 'aاbبcت', 0 => [:literal, :literal, 'aاbبcت', 0, 9]
12
-
13
- include_examples 'scan', 'aاbبت?', 0 => [:literal, :literal, 'aاbبت', 0, 8]
14
- include_examples 'scan', 'aاbبت?', 1 => [:quantifier, :zero_or_one, '?', 8, 9]
15
-
16
- include_examples 'scan', 'aا?bبcت+', 0 => [:literal, :literal, 'aا', 0, 3]
17
- include_examples 'scan', 'aا?bبcت+', 1 => [:quantifier, :zero_or_one, '?', 3, 4]
18
- include_examples 'scan', 'aا?bبcت+', 2 => [:literal, :literal, 'bبcت', 4, 10]
19
- include_examples 'scan', 'aا?bبcت+', 3 => [:quantifier, :one_or_more, '+', 10, 11]
20
-
21
- include_examples 'scan', 'a(اbب+)cت?', 0 => [:literal, :literal, 'a', 0, 1]
22
- include_examples 'scan', 'a(اbب+)cت?', 1 => [:group, :capture, '(', 1, 2]
23
- include_examples 'scan', 'a(اbب+)cت?', 2 => [:literal, :literal, 'اbب', 2, 7]
24
- include_examples 'scan', 'a(اbب+)cت?', 3 => [:quantifier, :one_or_more, '+', 7, 8]
25
- include_examples 'scan', 'a(اbب+)cت?', 4 => [:group, :close, ')', 8, 9]
26
- include_examples 'scan', 'a(اbب+)cت?', 5 => [:literal, :literal, 'cت', 9, 12]
27
- include_examples 'scan', 'a(اbب+)cت?', 6 => [:quantifier, :zero_or_one, '?', 12, 13]
28
-
29
- # 3 byte wide characters, Japanese
30
- include_examples 'scan', 'ab?れます+cd', 0 => [:literal, :literal, 'ab', 0, 2]
31
- include_examples 'scan', 'ab?れます+cd', 1 => [:quantifier, :zero_or_one, '?', 2, 3]
32
- include_examples 'scan', 'ab?れます+cd', 2 => [:literal, :literal, 'れます', 3, 12]
33
- include_examples 'scan', 'ab?れます+cd', 3 => [:quantifier, :one_or_more, '+', 12, 13]
34
- include_examples 'scan', 'ab?れます+cd', 4 => [:literal, :literal, 'cd', 13, 15]
35
-
36
- # 4 byte wide characters, Osmanya
37
- include_examples 'scan', '𐒀𐒁?𐒂ab+𐒃', 0 => [:literal, :literal, '𐒀𐒁', 0, 8]
38
- include_examples 'scan', '𐒀𐒁?𐒂ab+𐒃', 1 => [:quantifier, :zero_or_one, '?', 8, 9]
39
- include_examples 'scan', '𐒀𐒁?𐒂ab+𐒃', 2 => [:literal, :literal, '𐒂ab', 9, 15]
40
- include_examples 'scan', '𐒀𐒁?𐒂ab+𐒃', 3 => [:quantifier, :one_or_more, '+', 15, 16]
41
- include_examples 'scan', '𐒀𐒁?𐒂ab+𐒃', 4 => [:literal, :literal, '𐒃', 16, 20]
42
-
43
- include_examples 'scan', 'mu𝄞?si*𝄫c+', 0 => [:literal, :literal, 'mu𝄞', 0, 6]
44
- include_examples 'scan', 'mu𝄞?si*𝄫c+', 1 => [:quantifier, :zero_or_one, '?', 6, 7]
45
- include_examples 'scan', 'mu𝄞?si*𝄫c+', 2 => [:literal, :literal, 'si', 7, 9]
46
- include_examples 'scan', 'mu𝄞?si*𝄫c+', 3 => [:quantifier, :zero_or_more, '*', 9, 10]
47
- include_examples 'scan', 'mu𝄞?si*𝄫c+', 4 => [:literal, :literal, '𝄫c', 10, 15]
48
- include_examples 'scan', 'mu𝄞?si*𝄫c+', 5 => [:quantifier, :one_or_more, '+', 15, 16]
49
- end
@@ -1,18 +0,0 @@
1
- require 'spec_helper'
2
-
3
- RSpec.describe('Meta scanning') do
4
- include_examples 'scan', /abc??|def*+|ghi+/,
5
- 0 => [:literal, :literal, 'abc', 0, 3],
6
- 1 => [:quantifier, :zero_or_one_reluctant, '??', 3, 5],
7
- 2 => [:meta, :alternation, '|', 5, 6],
8
- 3 => [:literal, :literal, 'def', 6, 9],
9
- 4 => [:quantifier, :zero_or_more_possessive, '*+', 9, 11],
10
- 5 => [:meta, :alternation, '|', 11, 12]
11
-
12
- include_examples 'scan', /(a\|b)|(c|d)\|(e[|]f)/,
13
- 2 => [:escape, :alternation, '\|', 2, 4],
14
- 5 => [:meta, :alternation, '|', 6, 7],
15
- 8 => [:meta, :alternation, '|', 9, 10],
16
- 11 => [:escape, :alternation, '\|', 12, 14],
17
- 15 => [:literal, :literal, '|', 17, 18]
18
- end