regexp_parser 1.8.2 → 2.0.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (41) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +62 -0
  3. data/Gemfile +1 -0
  4. data/README.md +1 -4
  5. data/Rakefile +2 -2
  6. data/lib/regexp_parser/expression.rb +4 -17
  7. data/lib/regexp_parser/expression/classes/free_space.rb +1 -1
  8. data/lib/regexp_parser/expression/classes/group.rb +22 -2
  9. data/lib/regexp_parser/expression/classes/root.rb +4 -16
  10. data/lib/regexp_parser/expression/methods/match_length.rb +2 -2
  11. data/lib/regexp_parser/expression/methods/traverse.rb +2 -2
  12. data/lib/regexp_parser/expression/quantifier.rb +9 -0
  13. data/lib/regexp_parser/expression/sequence.rb +0 -10
  14. data/lib/regexp_parser/lexer.rb +2 -2
  15. data/lib/regexp_parser/parser.rb +27 -2
  16. data/lib/regexp_parser/scanner.rb +1194 -1272
  17. data/lib/regexp_parser/scanner/char_type.rl +11 -11
  18. data/lib/regexp_parser/scanner/property.rl +2 -2
  19. data/lib/regexp_parser/scanner/scanner.rl +178 -186
  20. data/lib/regexp_parser/syntax.rb +4 -4
  21. data/lib/regexp_parser/syntax/any.rb +2 -2
  22. data/lib/regexp_parser/syntax/base.rb +1 -1
  23. data/lib/regexp_parser/syntax/version_lookup.rb +2 -2
  24. data/lib/regexp_parser/version.rb +1 -1
  25. data/spec/expression/base_spec.rb +10 -0
  26. data/spec/expression/subexpression_spec.rb +1 -1
  27. data/spec/expression/to_s_spec.rb +39 -31
  28. data/spec/lexer/literals_spec.rb +24 -49
  29. data/spec/parser/errors_spec.rb +1 -1
  30. data/spec/parser/escapes_spec.rb +1 -1
  31. data/spec/parser/quantifiers_spec.rb +16 -0
  32. data/spec/parser/set/ranges_spec.rb +3 -3
  33. data/spec/scanner/escapes_spec.rb +7 -0
  34. data/spec/scanner/groups_spec.rb +10 -1
  35. data/spec/scanner/literals_spec.rb +28 -38
  36. data/spec/scanner/quantifiers_spec.rb +18 -13
  37. data/spec/scanner/sets_spec.rb +23 -5
  38. data/spec/spec_helper.rb +1 -0
  39. metadata +3 -7
  40. data/spec/expression/root_spec.rb +0 -9
  41. data/spec/expression/sequence_spec.rb +0 -9
@@ -1,20 +1,25 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  RSpec.describe('Quantifier scanning') do
4
- include_examples 'scan', 'a?', 1 => [:quantifier, :zero_or_one, '?', 1, 2]
5
- include_examples 'scan', 'a??', 1 => [:quantifier, :zero_or_one_reluctant, '??', 1, 3]
6
- include_examples 'scan', 'a?+', 1 => [:quantifier, :zero_or_one_possessive, '?+', 1, 3]
4
+ include_examples 'scan', 'a?', 1 => [:quantifier, :zero_or_one, '?', 1, 2]
5
+ include_examples 'scan', 'a??', 1 => [:quantifier, :zero_or_one_reluctant, '??', 1, 3]
6
+ include_examples 'scan', 'a?+', 1 => [:quantifier, :zero_or_one_possessive, '?+', 1, 3]
7
7
 
8
- include_examples 'scan', 'a*', 1 => [:quantifier, :zero_or_more, '*', 1, 2]
9
- include_examples 'scan', 'a*?', 1 => [:quantifier, :zero_or_more_reluctant, '*?', 1, 3]
10
- include_examples 'scan', 'a*+', 1 => [:quantifier, :zero_or_more_possessive, '*+', 1, 3]
8
+ include_examples 'scan', 'a*', 1 => [:quantifier, :zero_or_more, '*', 1, 2]
9
+ include_examples 'scan', 'a*?', 1 => [:quantifier, :zero_or_more_reluctant, '*?', 1, 3]
10
+ include_examples 'scan', 'a*+', 1 => [:quantifier, :zero_or_more_possessive, '*+', 1, 3]
11
11
 
12
- include_examples 'scan', 'a+', 1 => [:quantifier, :one_or_more, '+', 1, 2]
13
- include_examples 'scan', 'a+?', 1 => [:quantifier, :one_or_more_reluctant, '+?', 1, 3]
14
- include_examples 'scan', 'a++', 1 => [:quantifier, :one_or_more_possessive, '++', 1, 3]
12
+ include_examples 'scan', 'a+', 1 => [:quantifier, :one_or_more, '+', 1, 2]
13
+ include_examples 'scan', 'a+?', 1 => [:quantifier, :one_or_more_reluctant, '+?', 1, 3]
14
+ include_examples 'scan', 'a++', 1 => [:quantifier, :one_or_more_possessive, '++', 1, 3]
15
15
 
16
- include_examples 'scan', 'a{2}', 1 => [:quantifier, :interval, '{2}', 1, 4]
17
- include_examples 'scan', 'a{2,}', 1 => [:quantifier, :interval, '{2,}', 1, 5]
18
- include_examples 'scan', 'a{,2}', 1 => [:quantifier, :interval, '{,2}', 1, 5]
19
- include_examples 'scan', 'a{2,4}', 1 => [:quantifier, :interval, '{2,4}', 1, 6]
16
+ include_examples 'scan', 'a{2}', 1 => [:quantifier, :interval, '{2}', 1, 4]
17
+ include_examples 'scan', 'a{2,}', 1 => [:quantifier, :interval, '{2,}', 1, 5]
18
+ include_examples 'scan', 'a{,2}', 1 => [:quantifier, :interval, '{,2}', 1, 5]
19
+ include_examples 'scan', 'a{2,4}', 1 => [:quantifier, :interval, '{2,4}', 1, 6]
20
+
21
+ # special case: chained quantifiers
22
+ include_examples 'scan', 'a+{2}{3}', 1 => [:quantifier, :one_or_more, '+', 1, 2]
23
+ include_examples 'scan', 'a+{2}{3}', 2 => [:quantifier, :interval, '{2}', 2, 5]
24
+ include_examples 'scan', 'a+{2}{3}', 3 => [:quantifier, :interval, '{3}', 5, 8]
20
25
  end
@@ -18,8 +18,6 @@ RSpec.describe('Set scanning') do
18
18
  include_examples 'scan', /[<]/, 1 => [:literal, :literal, '<', 1, 2]
19
19
  include_examples 'scan', /[>]/, 1 => [:literal, :literal, '>', 1, 2]
20
20
 
21
- include_examples 'scan', /[äöü]/, 2 => [:literal, :literal, 'ö', 3, 5]
22
-
23
21
  include_examples 'scan', /[\x20]/, 1 => [:escape, :hex, '\x20', 1, 5]
24
22
 
25
23
  include_examples 'scan', '[\.]', 1 => [:escape, :dot, '\.', 1, 3]
@@ -63,9 +61,6 @@ RSpec.describe('Set scanning') do
63
61
  include_examples 'scan', /[[:digit:][:space:]]/, 2 => [:posixclass, :space, '[:space:]', 10, 19]
64
62
  include_examples 'scan', /[[:^digit:]]/, 1 => [:nonposixclass, :digit, '[:^digit:]', 1, 11]
65
63
 
66
- include_examples 'scan', /[a[.a-b.]c]/, 2 => [:set, :collation, '[.a-b.]', 2, 9]
67
- include_examples 'scan', /[a[=e=]c]/, 2 => [:set, :equivalent, '[=e=]', 2, 7]
68
-
69
64
  include_examples 'scan', /[a-d&&g-h]/, 4 => [:set, :intersection, '&&', 4, 6]
70
65
  include_examples 'scan', /[a&&]/, 2 => [:set, :intersection, '&&', 2, 4]
71
66
  include_examples 'scan', /[&&z]/, 1 => [:set, :intersection, '&&', 1, 3]
@@ -90,6 +85,29 @@ RSpec.describe('Set scanning') do
90
85
  8 => [:set, :range, '-', 9, 10],
91
86
  10=> [:set, :close, ']', 11, 12]
92
87
 
88
+ # Collations/collating sequences and character equivalents are not enabled
89
+ # in Ruby at the moment. If they ever are, enable them in the scanner,
90
+ # add them to a new syntax version, and handle them in the parser. Until then,
91
+ # expect them to be scanned as regular subsets containing literals.
92
+ # include_examples 'scan', /[a[.a-b.]c]/, 2 => [:set, :collation, '[.a-b.]', 2, 9]
93
+ # include_examples 'scan', /[a[=e=]c]/, 2 => [:set, :equivalent, '[=e=]', 2, 7]
94
+ include_examples 'scan', '[a[.a-b.]c]',
95
+ 2 => [:set, :open, '[', 2, 3],
96
+ 3 => [:literal, :literal, '.', 3, 4],
97
+ 4 => [:literal, :literal, 'a', 4, 5]
98
+ include_examples 'scan', '[a[=e=]c]',
99
+ 2 => [:set, :open, '[', 2, 3],
100
+ 3 => [:literal, :literal, '=', 3, 4],
101
+ 4 => [:literal, :literal, 'e', 4, 5]
102
+
103
+ # multi-byte characters should not affect indices
104
+ include_examples 'scan', /[れます]/,
105
+ 0 => [:set, :open, '[', 0, 1],
106
+ 1 => [:literal, :literal, 'れ', 1, 2],
107
+ 2 => [:literal, :literal, 'ま', 2, 3],
108
+ 3 => [:literal, :literal, 'す', 3, 4],
109
+ 4 => [:set, :close, ']', 4, 5]
110
+
93
111
  specify('set literal encoding') do
94
112
  text = RS.scan('[a]')[1][2].to_s
95
113
  expect(text).to eq 'a'
@@ -1,3 +1,4 @@
1
+ require 'ice_nine'
1
2
  require 'regexp_parser'
2
3
  require 'regexp_property_values'
3
4
  require_relative 'support/shared_examples'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: regexp_parser
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.8.2
4
+ version: 2.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ammar Ali
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-10-11 00:00:00.000000000 Z
11
+ date: 2020-12-28 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: A library for tokenizing, lexing, and parsing Ruby regular expressions.
14
14
  email:
@@ -102,8 +102,6 @@ files:
102
102
  - spec/expression/methods/tests_spec.rb
103
103
  - spec/expression/methods/traverse_spec.rb
104
104
  - spec/expression/options_spec.rb
105
- - spec/expression/root_spec.rb
106
- - spec/expression/sequence_spec.rb
107
105
  - spec/expression/subexpression_spec.rb
108
106
  - spec/expression/to_h_spec.rb
109
107
  - spec/expression/to_s_spec.rb
@@ -185,7 +183,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
185
183
  - !ruby/object:Gem::Version
186
184
  version: '0'
187
185
  requirements: []
188
- rubygems_version: 3.2.0.rc.1
186
+ rubygems_version: 3.2.0
189
187
  signing_key:
190
188
  specification_version: 4
191
189
  summary: Scanner, lexer, parser for ruby's regular expressions
@@ -200,8 +198,6 @@ test_files:
200
198
  - spec/expression/methods/tests_spec.rb
201
199
  - spec/expression/methods/traverse_spec.rb
202
200
  - spec/expression/options_spec.rb
203
- - spec/expression/root_spec.rb
204
- - spec/expression/sequence_spec.rb
205
201
  - spec/expression/subexpression_spec.rb
206
202
  - spec/expression/to_h_spec.rb
207
203
  - spec/expression/to_s_spec.rb
@@ -1,9 +0,0 @@
1
- require 'spec_helper'
2
-
3
- RSpec.describe(Regexp::Expression::Root) do
4
- describe('#initialize') do
5
- it 'supports the old, nonstandard arity for backwards compatibility' do
6
- expect { Root.new }.to output.to_stderr
7
- end
8
- end
9
- end
@@ -1,9 +0,0 @@
1
- require 'spec_helper'
2
-
3
- RSpec.describe(Regexp::Expression::Sequence) do
4
- describe('#initialize') do
5
- it 'supports the old, nonstandard arity for backwards compatibility' do
6
- expect { Sequence.new(0, 0, 0) }.to output.to_stderr
7
- end
8
- end
9
- end