regexp_parser 1.6.0 → 1.7.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +12 -0
- data/Gemfile +1 -1
- data/lib/regexp_parser/expression/methods/match_length.rb +1 -1
- data/lib/regexp_parser/expression/methods/traverse.rb +3 -1
- data/lib/regexp_parser/version.rb +1 -1
- data/spec/expression/methods/match_length_spec.rb +7 -0
- data/spec/expression/methods/traverse_spec.rb +21 -0
- data/spec/expression/options_spec.rb +33 -33
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d7b93dde993f6fe427ff43755738bf7de50f8613cf6e8097c9d791646d803e4c
|
4
|
+
data.tar.gz: 993a88720a4ee1d8a34f4c95e167089adc6455289bfeb356de8c028a9bbee63d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0bf5c142591b2d5a65023c53f76a64a13106074050042d24614963cc14dabda197ea9140fccd93f26ad06885293369b076bb5e9198967a6e3762654df8033455
|
7
|
+
data.tar.gz: 1311b3dfa90633ef456edc12abf6ace2d7311c7be8450f3768a436f9c8491c3a87987f3d6ac24c6966b6f4de5363e0f6f874bfe9e1b038a6cf5d9c043553b58e
|
data/CHANGELOG.md
CHANGED
@@ -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
@@ -14,7 +14,7 @@ module Regexp::Expression
|
|
14
14
|
#
|
15
15
|
# Returns self.
|
16
16
|
def traverse(include_self = false, &block)
|
17
|
-
|
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
|
@@ -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,
|
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(*
|
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/,
|
99
|
-
include_examples '#options', /\A/, Anchor::Base
|
100
|
-
include_examples '#options', /\d/, CharacterType::Base
|
101
|
-
include_examples '#options', /\n/, EscapeSequence::Base
|
102
|
-
include_examples '#options', /\K/, Keep::Mark
|
103
|
-
include_examples '#options', /./, CharacterType::Any
|
104
|
-
include_examples '#options', /(a)/, Group::Base
|
105
|
-
include_examples '#options', /(a)/,
|
106
|
-
include_examples '#options', /(?=a)/, Assertion::Base
|
107
|
-
include_examples '#options', /(?=a)/,
|
108
|
-
include_examples '#options', /(a|b)/, Group::Base
|
109
|
-
include_examples '#options', /(a|b)/,
|
110
|
-
include_examples '#options', /(a|b)/,
|
111
|
-
include_examples '#options', /(a|b)/,
|
112
|
-
include_examples '#options', /(a)\1/, Backreference::Base
|
113
|
-
include_examples '#options', /(a)\k<1>/, Backreference::Number
|
114
|
-
include_examples '#options', /(a)\g<1>/, Backreference::NumberCall
|
115
|
-
include_examples '#options', /[a]/,
|
116
|
-
include_examples '#options', /[a]/,
|
117
|
-
include_examples '#options', /[a-z]/,
|
118
|
-
include_examples '#options', /[a-z]/,
|
119
|
-
include_examples '#options', /[a&&z]/,
|
120
|
-
include_examples '#options', /[a&&z]/,
|
121
|
-
include_examples '#options', /[a&&z]/,
|
122
|
-
include_examples '#options', /[[:ascii:]]/,
|
123
|
-
include_examples '#options', /\p{word}/, UnicodeProperty::Base
|
124
|
-
include_examples '#options', /(a)(?(1)b|c)/, Conditional::Expression
|
125
|
-
include_examples '#options', /(a)(?(1)b|c)/,
|
126
|
-
include_examples '#options', /(a)(?(1)b|c)/,
|
127
|
-
include_examples '#options', /(a)(?(1)b|c)/,
|
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.
|
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:
|
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.
|
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
|