regexp_parser 1.6.0 → 1.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 0e084510a97816730f68028cba8be7b9ee576e886347952d8400cd26293f3361
4
- data.tar.gz: f98f2bbb3558c6a50d3415c830ba6dae1f09b2aca944f411b88c1cd65d527f60
3
+ metadata.gz: d7b93dde993f6fe427ff43755738bf7de50f8613cf6e8097c9d791646d803e4c
4
+ data.tar.gz: 993a88720a4ee1d8a34f4c95e167089adc6455289bfeb356de8c028a9bbee63d
5
5
  SHA512:
6
- metadata.gz: 972c429ea4b47e2d2fefbc087cb23362f3e385cbbdbbead8013537d9bfe12b07237dcb1dcfaab6e1793037347d310702fa7fc035ab874dc24722b041493cc3f2
7
- data.tar.gz: 6ace6c2390101f9d95bcc9325ba70c4d4d9d90d5796ab015ffcef1f58b907eb3a2649ee07f3f77e6f2682a2f4803e6f94e634855e39a97480a1fb17f00b97c23
6
+ metadata.gz: 0bf5c142591b2d5a65023c53f76a64a13106074050042d24614963cc14dabda197ea9140fccd93f26ad06885293369b076bb5e9198967a6e3762654df8033455
7
+ data.tar.gz: 1311b3dfa90633ef456edc12abf6ace2d7311c7be8450f3768a436f9c8491c3a87987f3d6ac24c6966b6f4de5363e0f6f874bfe9e1b038a6cf5d9c043553b58e
@@ -1,5 +1,17 @@
1
1
  ## [Unreleased]
2
2
 
3
+ ### [1.7.0] - 2020-02-23 - [Janosch Müller](mailto:janosch84@gmail.com)
4
+
5
+ ### Added
6
+
7
+ - `Expression#each_expression` and `1.#traverse` can now be called without a block
8
+ * this returns an `Enumerator` and allows chaining, e.g. `each_expression.select`
9
+ * thanks to [Masataka Kuwabara](https://github.com/pocke)
10
+
11
+ ### Fixed
12
+
13
+ - `MatchLength#each` no longer ignores the given `limit:` when called without a block
14
+
3
15
  ### [1.6.0] - 2019-06-16 - [Janosch Müller](mailto:janosch84@gmail.com)
4
16
 
5
17
  ### Added
data/Gemfile CHANGED
@@ -3,7 +3,7 @@ source 'https://rubygems.org'
3
3
  gemspec
4
4
 
5
5
  group :development, :test do
6
- gem 'rake', '~> 12.2'
6
+ gem 'rake', '~> 13.0'
7
7
  gem 'regexp_property_values', '~> 1.0'
8
8
  gem 'rspec', '~> 3.8'
9
9
  end
@@ -22,7 +22,7 @@ class Regexp::MatchLength
22
22
  end
23
23
 
24
24
  def each(opts = {})
25
- return enum_for(__method__) unless block_given?
25
+ return enum_for(__method__, opts) unless block_given?
26
26
  limit = opts[:limit] || 1000
27
27
  yielded = 0
28
28
  (min..max).each do |num|
@@ -14,7 +14,7 @@ module Regexp::Expression
14
14
  #
15
15
  # Returns self.
16
16
  def traverse(include_self = false, &block)
17
- raise 'traverse requires a block' unless block_given?
17
+ return enum_for(__method__, include_self) unless block_given?
18
18
 
19
19
  block.call(:enter, self, 0) if include_self
20
20
 
@@ -37,6 +37,8 @@ module Regexp::Expression
37
37
  # Iterates over the expressions of this expression as an array, passing
38
38
  # the expression and its index within its parent to the given block.
39
39
  def each_expression(include_self = false, &block)
40
+ return enum_for(__method__, include_self) unless block_given?
41
+
40
42
  traverse(include_self) do |event, exp, index|
41
43
  yield(exp, index) unless event == :exit
42
44
  end
@@ -1,5 +1,5 @@
1
1
  class Regexp
2
2
  class Parser
3
- VERSION = '1.6.0'
3
+ VERSION = '1.7.0'
4
4
  end
5
5
  end
@@ -120,6 +120,13 @@ RSpec.describe(Regexp::MatchLength) do
120
120
  expect { result.next }.to raise_error(StopIteration)
121
121
  end
122
122
 
123
+ it 'is aware of limit option even if called without a block' do
124
+ result = ML.of(/a?/).each(limit: 1)
125
+ expect(result).to be_a(Enumerator)
126
+ expect(result.next).to eq 0
127
+ expect { result.next }.to raise_error(StopIteration)
128
+ end
129
+
123
130
  it 'is limited to 1000 iterations in case there are infinite match lengths' do
124
131
  expect(ML.of(/a*/).first(3000).size).to eq 1000
125
132
  end
@@ -39,6 +39,17 @@ RSpec.describe('Subexpression#traverse') do
39
39
  expect(visits).to eq 9
40
40
  end
41
41
 
42
+ specify('Subexpression#traverse without a block') do
43
+ root = RP.parse(/abc/)
44
+ enum = root.traverse
45
+
46
+ expect(enum).to be_a(Enumerator)
47
+ event, expr, idx = enum.next
48
+ expect(event).to eq(:visit)
49
+ expect(expr).to be_a(Regexp::Expression::Literal)
50
+ expect(idx).to eq(0)
51
+ end
52
+
42
53
  specify('Subexpression#walk alias') do
43
54
  root = RP.parse(/abc/)
44
55
 
@@ -81,6 +92,16 @@ RSpec.describe('Subexpression#traverse') do
81
92
  expect(indices).to eq [0, 0, 1, 0, 2]
82
93
  end
83
94
 
95
+ specify('Subexpression#each_expression without a block') do
96
+ root = RP.parse(/abc/)
97
+ enum = root.each_expression
98
+
99
+ expect(enum).to be_a(Enumerator)
100
+ expr, idx = enum.next
101
+ expect(expr).to be_a(Regexp::Expression::Literal)
102
+ expect(idx).to eq(0)
103
+ end
104
+
84
105
  specify('Subexpression#flat_map without block') do
85
106
  root = RP.parse(/a(b([c-e]+))?/)
86
107
 
@@ -85,44 +85,44 @@ RSpec.describe('Expression#options') do
85
85
  .and change { exp.unicode_classes? }.from(false).to(true)
86
86
  end
87
87
 
88
- RSpec.shared_examples '#options' do |regexp, klass, at: []|
88
+ RSpec.shared_examples '#options' do |regexp, path, klass|
89
89
  it "works for expression class #{klass}" do
90
- exp = RP.parse(/#{regexp.source}/i).dig(*at)
90
+ exp = RP.parse(/#{regexp.source}/i).dig(*path)
91
91
  expect(exp).to be_a(klass)
92
92
  expect(exp).to be_i
93
93
  expect(exp).not_to be_x
94
94
  end
95
95
  end
96
96
 
97
- include_examples '#options', //, Root
98
- include_examples '#options', /a/, Literal, at: [0]
99
- include_examples '#options', /\A/, Anchor::Base, at: [0]
100
- include_examples '#options', /\d/, CharacterType::Base, at: [0]
101
- include_examples '#options', /\n/, EscapeSequence::Base, at: [0]
102
- include_examples '#options', /\K/, Keep::Mark, at: [0]
103
- include_examples '#options', /./, CharacterType::Any, at: [0]
104
- include_examples '#options', /(a)/, Group::Base, at: [0]
105
- include_examples '#options', /(a)/, Literal, at: [0, 0]
106
- include_examples '#options', /(?=a)/, Assertion::Base, at: [0]
107
- include_examples '#options', /(?=a)/, Literal, at: [0, 0]
108
- include_examples '#options', /(a|b)/, Group::Base, at: [0]
109
- include_examples '#options', /(a|b)/, Alternation, at: [0, 0]
110
- include_examples '#options', /(a|b)/, Alternative, at: [0, 0, 0]
111
- include_examples '#options', /(a|b)/, Literal, at: [0, 0, 0, 0]
112
- include_examples '#options', /(a)\1/, Backreference::Base, at: [1]
113
- include_examples '#options', /(a)\k<1>/, Backreference::Number, at: [1]
114
- include_examples '#options', /(a)\g<1>/, Backreference::NumberCall, at: [1]
115
- include_examples '#options', /[a]/, CharacterSet, at: [0]
116
- include_examples '#options', /[a]/, Literal, at: [0, 0]
117
- include_examples '#options', /[a-z]/, CharacterSet::Range, at: [0, 0]
118
- include_examples '#options', /[a-z]/, Literal, at: [0, 0, 0]
119
- include_examples '#options', /[a&&z]/, CharacterSet::Intersection, at: [0, 0]
120
- include_examples '#options', /[a&&z]/, CharacterSet::IntersectedSequence, at: [0, 0, 0]
121
- include_examples '#options', /[a&&z]/, Literal, at: [0, 0, 0, 0]
122
- include_examples '#options', /[[:ascii:]]/, PosixClass, at: [0, 0]
123
- include_examples '#options', /\p{word}/, UnicodeProperty::Base, at: [0]
124
- include_examples '#options', /(a)(?(1)b|c)/, Conditional::Expression, at: [1]
125
- include_examples '#options', /(a)(?(1)b|c)/, Conditional::Condition, at: [1, 0]
126
- include_examples '#options', /(a)(?(1)b|c)/, Conditional::Branch, at: [1, 1]
127
- include_examples '#options', /(a)(?(1)b|c)/, Literal, at: [1, 1, 0]
97
+ include_examples '#options', //, [], Root
98
+ include_examples '#options', /a/, [0], Literal
99
+ include_examples '#options', /\A/, [0], Anchor::Base
100
+ include_examples '#options', /\d/, [0], CharacterType::Base
101
+ include_examples '#options', /\n/, [0], EscapeSequence::Base
102
+ include_examples '#options', /\K/, [0], Keep::Mark
103
+ include_examples '#options', /./, [0], CharacterType::Any
104
+ include_examples '#options', /(a)/, [0], Group::Base
105
+ include_examples '#options', /(a)/, [0, 0], Literal
106
+ include_examples '#options', /(?=a)/, [0], Assertion::Base
107
+ include_examples '#options', /(?=a)/, [0, 0], Literal
108
+ include_examples '#options', /(a|b)/, [0], Group::Base
109
+ include_examples '#options', /(a|b)/, [0, 0], Alternation
110
+ include_examples '#options', /(a|b)/, [0, 0, 0], Alternative
111
+ include_examples '#options', /(a|b)/, [0, 0, 0, 0], Literal
112
+ include_examples '#options', /(a)\1/, [1], Backreference::Base
113
+ include_examples '#options', /(a)\k<1>/, [1], Backreference::Number
114
+ include_examples '#options', /(a)\g<1>/, [1], Backreference::NumberCall
115
+ include_examples '#options', /[a]/, [0], CharacterSet
116
+ include_examples '#options', /[a]/, [0, 0], Literal
117
+ include_examples '#options', /[a-z]/, [0, 0], CharacterSet::Range
118
+ include_examples '#options', /[a-z]/, [0, 0, 0], Literal
119
+ include_examples '#options', /[a&&z]/, [0, 0], CharacterSet::Intersection
120
+ include_examples '#options', /[a&&z]/, [0, 0, 0], CharacterSet::IntersectedSequence
121
+ include_examples '#options', /[a&&z]/, [0, 0, 0, 0], Literal
122
+ include_examples '#options', /[[:ascii:]]/, [0, 0], PosixClass
123
+ include_examples '#options', /\p{word}/, [0], UnicodeProperty::Base
124
+ include_examples '#options', /(a)(?(1)b|c)/, [1], Conditional::Expression
125
+ include_examples '#options', /(a)(?(1)b|c)/, [1, 0], Conditional::Condition
126
+ include_examples '#options', /(a)(?(1)b|c)/, [1, 1], Conditional::Branch
127
+ include_examples '#options', /(a)(?(1)b|c)/, [1, 1, 0], Literal
128
128
  end
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.6.0
4
+ version: 1.7.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ammar Ali
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-07-16 00:00:00.000000000 Z
11
+ date: 2020-02-23 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: A library for tokenizing, lexing, and parsing Ruby regular expressions.
14
14
  email:
@@ -181,7 +181,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
181
181
  - !ruby/object:Gem::Version
182
182
  version: '0'
183
183
  requirements: []
184
- rubygems_version: 3.0.3
184
+ rubygems_version: 3.1.2
185
185
  signing_key:
186
186
  specification_version: 4
187
187
  summary: Scanner, lexer, parser for ruby's regular expressions