regexp_parser 2.0.1 → 2.0.2
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 +4 -4
- data/CHANGELOG.md +7 -0
- data/Gemfile +1 -0
- data/Rakefile +2 -2
- data/lib/regexp_parser/expression/classes/free_space.rb +1 -1
- data/lib/regexp_parser/expression/classes/group.rb +6 -1
- data/lib/regexp_parser/expression/methods/match_length.rb +2 -2
- data/lib/regexp_parser/expression/methods/traverse.rb +2 -2
- data/lib/regexp_parser/syntax/any.rb +2 -2
- data/lib/regexp_parser/version.rb +1 -1
- data/spec/expression/subexpression_spec.rb +1 -1
- data/spec/expression/to_s_spec.rb +28 -36
- data/spec/parser/errors_spec.rb +1 -1
- data/spec/parser/quantifiers_spec.rb +1 -0
- data/spec/spec_helper.rb +1 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a3d9161fb969c7c5aac0798a31054ed4f0d5da8992b8167afa7025492d1042c9
|
4
|
+
data.tar.gz: 8321d42545c5dbfc810ad3f32fb03677e95d1dba3f3145f20af2e655f1ca45c3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: def5d282e5720c260bcb581e666704d04579534f8e04986867382836e58f4949d1eea0d3f7b3b2efdb71c5796b3bc6e5c4f92594aab9c9cd61985de18627c026
|
7
|
+
data.tar.gz: 3e2671325e18a6b4d61b5cd9da410f21a3cdc24382f415b9517498437d2c5e8e473ebe481aeb610667f33aa9d538d05d43b3fae5565b1fb856690e81377e82e5
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,12 @@
|
|
1
1
|
## [Unreleased]
|
2
2
|
|
3
|
+
## [2.0.2] - 2020-12-25 - [Janosch Müller](mailto:janosch84@gmail.com)
|
4
|
+
|
5
|
+
### Fixed
|
6
|
+
|
7
|
+
- fixed `FrozenError` when calling `#to_s` on a frozen `Group::Passive`
|
8
|
+
* thanks to [Daniel Gollahon](https://github.com/dgollahon)
|
9
|
+
|
3
10
|
## [2.0.1] - 2020-12-20 - [Janosch Müller](mailto:janosch84@gmail.com)
|
4
11
|
|
5
12
|
### Fixed
|
data/Gemfile
CHANGED
data/Rakefile
CHANGED
@@ -25,7 +25,7 @@ end
|
|
25
25
|
|
26
26
|
namespace :ragel do
|
27
27
|
desc "Process the ragel source files and output ruby code"
|
28
|
-
task :rb do
|
28
|
+
task :rb do
|
29
29
|
RAGEL_SOURCE_FILES.each do |file|
|
30
30
|
output_file = "#{RAGEL_OUTPUT_DIR}/#{file}.rb"
|
31
31
|
# using faster flat table driven FSM, about 25% larger code, but about 30% faster
|
@@ -42,7 +42,7 @@ namespace :ragel do
|
|
42
42
|
end
|
43
43
|
|
44
44
|
desc "Delete the ragel generated source file(s)"
|
45
|
-
task :clean do
|
45
|
+
task :clean do
|
46
46
|
RAGEL_SOURCE_FILES.each do |file|
|
47
47
|
sh "rm -f #{RAGEL_OUTPUT_DIR}/#{file}.rb"
|
48
48
|
end
|
@@ -1,7 +1,7 @@
|
|
1
1
|
module Regexp::Expression
|
2
2
|
|
3
3
|
class FreeSpace < Regexp::Expression::Base
|
4
|
-
def quantify(
|
4
|
+
def quantify(_token, _text, _min = nil, _max = nil, _mode = :greedy)
|
5
5
|
raise "Can not quantify a free space object"
|
6
6
|
end
|
7
7
|
end
|
@@ -13,6 +13,11 @@ module Regexp::Expression
|
|
13
13
|
class Passive < Group::Base
|
14
14
|
attr_writer :implicit
|
15
15
|
|
16
|
+
def initialize(*)
|
17
|
+
@implicit = false
|
18
|
+
super
|
19
|
+
end
|
20
|
+
|
16
21
|
def to_s(format = :full)
|
17
22
|
if implicit?
|
18
23
|
"#{expressions.join}#{quantifier_affix(format)}"
|
@@ -22,7 +27,7 @@ module Regexp::Expression
|
|
22
27
|
end
|
23
28
|
|
24
29
|
def implicit?
|
25
|
-
@implicit
|
30
|
+
@implicit
|
26
31
|
end
|
27
32
|
end
|
28
33
|
|
@@ -10,7 +10,7 @@ class Regexp::MatchLength
|
|
10
10
|
self.exp_class = exp.class
|
11
11
|
self.min_rep = exp.repetitions.min
|
12
12
|
self.max_rep = exp.repetitions.max
|
13
|
-
if base = opts[:base]
|
13
|
+
if (base = opts[:base])
|
14
14
|
self.base_min = base
|
15
15
|
self.base_max = base
|
16
16
|
self.reify = ->{ '.' * base }
|
@@ -32,7 +32,7 @@ class Regexp::MatchLength
|
|
32
32
|
end
|
33
33
|
end
|
34
34
|
|
35
|
-
def endless_each
|
35
|
+
def endless_each
|
36
36
|
return enum_for(__method__) unless block_given?
|
37
37
|
(min..max).each { |num| yield(num) if include?(num) }
|
38
38
|
end
|
@@ -36,7 +36,7 @@ module Regexp::Expression
|
|
36
36
|
|
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
|
-
def each_expression(include_self = false
|
39
|
+
def each_expression(include_self = false)
|
40
40
|
return enum_for(__method__, include_self) unless block_given?
|
41
41
|
|
42
42
|
traverse(include_self) do |event, exp, index|
|
@@ -47,7 +47,7 @@ module Regexp::Expression
|
|
47
47
|
# Returns a new array with the results of calling the given block once
|
48
48
|
# for every expression. If a block is not given, returns an array with
|
49
49
|
# each expression and its level index as an array.
|
50
|
-
def flat_map(include_self = false
|
50
|
+
def flat_map(include_self = false)
|
51
51
|
result = []
|
52
52
|
|
53
53
|
each_expression(include_self) do |exp, index|
|
@@ -32,7 +32,7 @@ RSpec.describe(Regexp::Expression::Subexpression) do
|
|
32
32
|
}
|
33
33
|
|
34
34
|
root.each_expression do |exp|
|
35
|
-
next unless expected_nesting_level = tests.delete(exp.to_s)
|
35
|
+
next unless (expected_nesting_level = tests.delete(exp.to_s))
|
36
36
|
expect(expected_nesting_level).to eq exp.nesting_level
|
37
37
|
end
|
38
38
|
|
@@ -1,58 +1,50 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
RSpec.describe('Expression#to_s') do
|
4
|
-
|
5
|
-
pattern
|
4
|
+
def parse_frozen(pattern, ruby_version = nil)
|
5
|
+
IceNine.deep_freeze(RP.parse(pattern, *ruby_version))
|
6
|
+
end
|
6
7
|
|
7
|
-
|
8
|
+
def expect_round_trip(pattern, ruby_version = nil)
|
9
|
+
parsed = parse_frozen(pattern, ruby_version)
|
10
|
+
|
11
|
+
expect(parsed.to_s).to eql(pattern)
|
8
12
|
end
|
9
13
|
|
10
|
-
specify('
|
11
|
-
|
14
|
+
specify('literal alternation') do
|
15
|
+
expect_round_trip('abcd|ghij|klmn|pqur')
|
16
|
+
end
|
12
17
|
|
13
|
-
|
18
|
+
specify('quantified alternations') do
|
19
|
+
expect_round_trip('(?:a?[b]+(c){2}|d+[e]*(f)?)|(?:g+[h]?(i){2,3}|j*[k]{3,5}(l)?)')
|
14
20
|
end
|
15
21
|
|
16
22
|
specify('quantified sets') do
|
17
|
-
|
18
|
-
|
19
|
-
expect(RP.parse(pattern).to_s).to eq pattern
|
23
|
+
expect_round_trip('[abc]+|[^def]{3,6}')
|
20
24
|
end
|
21
25
|
|
22
26
|
specify('property sets') do
|
23
|
-
|
24
|
-
|
25
|
-
expect(RP.parse(pattern, 'ruby/1.9').to_s).to eq pattern
|
27
|
+
expect_round_trip('[\\a\\b\\p{Lu}\\P{Z}\\c\\d]+', 'ruby/1.9')
|
26
28
|
end
|
27
29
|
|
28
30
|
specify('groups') do
|
29
|
-
|
30
|
-
|
31
|
-
expect(RP.parse(pattern, 'ruby/1.9').to_s).to eq pattern
|
31
|
+
expect_round_trip("(a(?>b(?:c(?<n>d(?'N'e)??f)+g)*+h)*i)++", 'ruby/1.9')
|
32
32
|
end
|
33
33
|
|
34
34
|
specify('assertions') do
|
35
|
-
|
36
|
-
|
37
|
-
expect(RP.parse(pattern, 'ruby/1.9').to_s).to eq pattern
|
35
|
+
expect_round_trip('(a+(?=b+(?!c+(?<=d+(?<!e+)?f+)?g+)?h+)?i+)?', 'ruby/1.9')
|
38
36
|
end
|
39
37
|
|
40
38
|
specify('comments') do
|
41
|
-
|
42
|
-
|
43
|
-
expect(RP.parse(pattern).to_s).to eq pattern
|
39
|
+
expect_round_trip('(?#start)a(?#middle)b(?#end)')
|
44
40
|
end
|
45
41
|
|
46
42
|
specify('options') do
|
47
|
-
|
48
|
-
|
49
|
-
expect(RP.parse(pattern).to_s).to eq pattern
|
43
|
+
expect_round_trip('(?mix:start)a(?-mix:middle)b(?i-mx:end)')
|
50
44
|
end
|
51
45
|
|
52
46
|
specify('url') do
|
53
|
-
|
54
|
-
|
55
|
-
expect(RP.parse(pattern).to_s).to eq pattern
|
47
|
+
expect_round_trip('(^$)|(^(http|https):\\/\\/[a-z0-9]+([\\-\\.]{1}[a-z0-9]+)*' + '\\.[a-z]{2,5}(([0-9]{1,5})?\\/.*)?$)')
|
56
48
|
end
|
57
49
|
|
58
50
|
specify('multiline source') do
|
@@ -64,7 +56,7 @@ RSpec.describe('Expression#to_s') do
|
|
64
56
|
\z
|
65
57
|
/x
|
66
58
|
|
67
|
-
expect(
|
59
|
+
expect(parse_frozen(multiline).to_s).to eql(multiline.source)
|
68
60
|
end
|
69
61
|
|
70
62
|
specify('multiline #to_s') do
|
@@ -76,7 +68,7 @@ RSpec.describe('Expression#to_s') do
|
|
76
68
|
\z
|
77
69
|
/x
|
78
70
|
|
79
|
-
|
71
|
+
expect_round_trip(multiline.to_s)
|
80
72
|
end
|
81
73
|
|
82
74
|
# Free spacing expressions that use spaces between quantifiers and their
|
@@ -93,24 +85,24 @@ RSpec.describe('Expression#to_s') do
|
|
93
85
|
/x
|
94
86
|
|
95
87
|
str = 'bbbcged'
|
96
|
-
root =
|
88
|
+
root = parse_frozen(multiline)
|
97
89
|
|
98
|
-
expect(Regexp.new(root.to_s, Regexp::EXTENDED).match(str)[0]).to
|
90
|
+
expect(Regexp.new(root.to_s, Regexp::EXTENDED).match(str)[0]).to eql(multiline.match(str)[0])
|
99
91
|
end
|
100
92
|
|
101
93
|
# special case: implicit groups used for chained quantifiers produce no parens
|
102
94
|
specify 'chained quantifiers #to_s' do
|
103
95
|
pattern = /a+{1}{2}/
|
104
|
-
root =
|
105
|
-
expect(root.to_s).to
|
96
|
+
root = parse_frozen(pattern)
|
97
|
+
expect(root.to_s).to eql('a+{1}{2}')
|
106
98
|
end
|
107
99
|
|
108
100
|
# regression test for https://github.com/ammar/regexp_parser/issues/74
|
109
101
|
specify('non-ascii comment') do
|
110
102
|
pattern = '(?x) 😋 # 😋'
|
111
103
|
root = RP.parse(pattern)
|
112
|
-
expect(root.last).to be_a
|
113
|
-
expect(root.last.to_s).to
|
114
|
-
expect(root.to_s).to
|
104
|
+
expect(root.last).to be_a(Regexp::Expression::Comment)
|
105
|
+
expect(root.last.to_s).to eql('# 😋')
|
106
|
+
expect(root.to_s).to eql(pattern)
|
115
107
|
end
|
116
108
|
end
|
data/spec/parser/errors_spec.rb
CHANGED
@@ -9,7 +9,7 @@ RSpec.describe('Parsing errors') do
|
|
9
9
|
.to raise_error(Regexp::Parser::UnknownTokenTypeError)
|
10
10
|
end
|
11
11
|
|
12
|
-
RSpec.shared_examples 'UnknownTokenError' do |type
|
12
|
+
RSpec.shared_examples 'UnknownTokenError' do |type|
|
13
13
|
it "raises for unkown tokens of type #{type}" do
|
14
14
|
expect { parser.send(:parse_token, Regexp::Token.new(type, :foo)) }
|
15
15
|
.to raise_error(Regexp::Parser::UnknownTokenError)
|
data/spec/spec_helper.rb
CHANGED
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: 2.0.
|
4
|
+
version: 2.0.2
|
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-12-
|
11
|
+
date: 2020-12-25 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: A library for tokenizing, lexing, and parsing Ruby regular expressions.
|
14
14
|
email:
|