regexp_parser 1.7.1 → 2.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +138 -0
- data/Gemfile +6 -1
- data/README.md +23 -11
- data/Rakefile +8 -8
- data/lib/regexp_parser/error.rb +4 -0
- data/lib/regexp_parser/expression.rb +13 -21
- data/lib/regexp_parser/expression/classes/backref.rb +5 -0
- data/lib/regexp_parser/expression/classes/conditional.rb +11 -1
- data/lib/regexp_parser/expression/classes/free_space.rb +2 -2
- data/lib/regexp_parser/expression/classes/group.rb +28 -3
- data/lib/regexp_parser/expression/classes/property.rb +1 -1
- data/lib/regexp_parser/expression/classes/root.rb +4 -16
- data/lib/regexp_parser/expression/classes/set/range.rb +2 -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/expression/quantifier.rb +10 -1
- data/lib/regexp_parser/expression/sequence.rb +3 -19
- data/lib/regexp_parser/expression/subexpression.rb +1 -1
- data/lib/regexp_parser/lexer.rb +6 -6
- data/lib/regexp_parser/parser.rb +325 -344
- data/lib/regexp_parser/scanner.rb +1320 -1385
- data/lib/regexp_parser/scanner/char_type.rl +11 -11
- data/lib/regexp_parser/scanner/property.rl +2 -2
- data/lib/regexp_parser/scanner/scanner.rl +231 -253
- data/lib/regexp_parser/syntax.rb +8 -6
- data/lib/regexp_parser/syntax/any.rb +3 -3
- data/lib/regexp_parser/syntax/base.rb +1 -1
- data/lib/regexp_parser/syntax/version_lookup.rb +4 -4
- data/lib/regexp_parser/version.rb +1 -1
- data/regexp_parser.gemspec +1 -1
- data/spec/expression/base_spec.rb +10 -0
- data/spec/expression/clone_spec.rb +36 -4
- data/spec/expression/free_space_spec.rb +2 -2
- data/spec/expression/methods/match_length_spec.rb +2 -2
- data/spec/expression/subexpression_spec.rb +1 -1
- data/spec/expression/to_s_spec.rb +39 -31
- data/spec/lexer/literals_spec.rb +24 -49
- data/spec/lexer/refcalls_spec.rb +5 -0
- data/spec/parser/all_spec.rb +2 -2
- data/spec/parser/errors_spec.rb +1 -1
- data/spec/parser/escapes_spec.rb +1 -1
- data/spec/parser/options_spec.rb +28 -0
- data/spec/parser/quantifiers_spec.rb +16 -0
- data/spec/parser/refcalls_spec.rb +5 -0
- data/spec/parser/set/ranges_spec.rb +3 -3
- data/spec/scanner/escapes_spec.rb +12 -1
- data/spec/scanner/free_space_spec.rb +32 -0
- data/spec/scanner/groups_spec.rb +10 -1
- data/spec/scanner/literals_spec.rb +28 -38
- data/spec/scanner/options_spec.rb +36 -0
- data/spec/scanner/quantifiers_spec.rb +18 -13
- data/spec/scanner/refcalls_spec.rb +19 -0
- data/spec/scanner/sets_spec.rb +65 -16
- data/spec/spec_helper.rb +1 -0
- metadata +61 -60
- data/spec/expression/root_spec.rb +0 -9
- data/spec/expression/sequence_spec.rb +0 -9
data/lib/regexp_parser/syntax.rb
CHANGED
@@ -1,9 +1,11 @@
|
|
1
|
-
require
|
2
|
-
require File.expand_path('../syntax/base', __FILE__)
|
3
|
-
require File.expand_path('../syntax/any', __FILE__)
|
4
|
-
require File.expand_path('../syntax/version_lookup', __FILE__)
|
5
|
-
require File.expand_path('../syntax/versions', __FILE__)
|
1
|
+
require 'regexp_parser/error'
|
6
2
|
|
7
3
|
module Regexp::Syntax
|
8
|
-
class SyntaxError <
|
4
|
+
class SyntaxError < Regexp::Parser::Error; end
|
9
5
|
end
|
6
|
+
|
7
|
+
require_relative 'syntax/tokens'
|
8
|
+
require_relative 'syntax/base'
|
9
|
+
require_relative 'syntax/any'
|
10
|
+
require_relative 'syntax/version_lookup'
|
11
|
+
require_relative 'syntax/versions'
|
@@ -4,12 +4,12 @@ module Regexp::Syntax
|
|
4
4
|
# is useful during development, testing, and should be useful for some types
|
5
5
|
# of transformations as well.
|
6
6
|
class Any < Base
|
7
|
-
def initialize
|
7
|
+
def initialize # rubocop:disable Lint/MissingSuper
|
8
8
|
@implements = { :* => [:*] }
|
9
9
|
end
|
10
10
|
|
11
|
-
def implements?(
|
12
|
-
def implements!(
|
11
|
+
def implements?(_type, _token) true end
|
12
|
+
def implements!(_type, _token) true end
|
13
13
|
end
|
14
14
|
|
15
15
|
end
|
@@ -3,13 +3,13 @@ module Regexp::Syntax
|
|
3
3
|
VERSION_REGEXP = /#{VERSION_FORMAT}/
|
4
4
|
VERSION_CONST_REGEXP = /\AV\d+_\d+(?:_\d+)?\z/
|
5
5
|
|
6
|
-
class InvalidVersionNameError < SyntaxError
|
6
|
+
class InvalidVersionNameError < Regexp::Syntax::SyntaxError
|
7
7
|
def initialize(name)
|
8
8
|
super "Invalid version name '#{name}'. Expected format is '#{VERSION_FORMAT}'"
|
9
9
|
end
|
10
10
|
end
|
11
11
|
|
12
|
-
class UnknownSyntaxNameError < SyntaxError
|
12
|
+
class UnknownSyntaxNameError < Regexp::Syntax::SyntaxError
|
13
13
|
def initialize(name)
|
14
14
|
super "Unknown syntax name '#{name}'."
|
15
15
|
end
|
@@ -74,9 +74,9 @@ module Regexp::Syntax
|
|
74
74
|
end
|
75
75
|
|
76
76
|
def warn_if_future_version(const_name)
|
77
|
-
return if comparable_version(const_name) < comparable_version('
|
77
|
+
return if comparable_version(const_name) < comparable_version('4.0.0')
|
78
78
|
|
79
|
-
warn('This library has only been tested up to Ruby
|
79
|
+
warn('This library has only been tested up to Ruby 3.x, '\
|
80
80
|
"but you are running with #{const_get(const_name).inspect}")
|
81
81
|
end
|
82
82
|
end
|
data/regexp_parser.gemspec
CHANGED
@@ -91,4 +91,14 @@ RSpec.describe(Regexp::Expression::Base) do
|
|
91
91
|
expect(RP.parse(/a*/)[0].repetitions).to eq 0..(Float::INFINITY)
|
92
92
|
expect(RP.parse(/a+/)[0].repetitions).to eq 1..(Float::INFINITY)
|
93
93
|
end
|
94
|
+
|
95
|
+
specify('#base_length') do
|
96
|
+
expect(RP.parse(/(aa)/)[0].base_length).to eq 4
|
97
|
+
expect(RP.parse(/(aa){42}/)[0].base_length).to eq 4
|
98
|
+
end
|
99
|
+
|
100
|
+
specify('#full_length') do
|
101
|
+
expect(RP.parse(/(aa)/)[0].full_length).to eq 4
|
102
|
+
expect(RP.parse(/(aa){42}/)[0].full_length).to eq 8
|
103
|
+
end
|
94
104
|
end
|
@@ -27,8 +27,8 @@ RSpec.describe('Expression#clone') do
|
|
27
27
|
expect(root_2.quantifier.object_id).not_to eq copy_2.quantifier.object_id
|
28
28
|
|
29
29
|
# regression test
|
30
|
-
expect { root_2.clone }.not_to
|
31
|
-
expect { root_2.clone }.not_to
|
30
|
+
expect { root_2.clone }.not_to(change { root_2.quantifier.object_id })
|
31
|
+
expect { root_2.clone }.not_to(change { root_2.quantifier.text.object_id })
|
32
32
|
end
|
33
33
|
|
34
34
|
specify('Subexpression#clone') do
|
@@ -48,7 +48,7 @@ RSpec.describe('Expression#clone') do
|
|
48
48
|
end
|
49
49
|
|
50
50
|
# regression test
|
51
|
-
expect { root.clone }.not_to
|
51
|
+
expect { root.clone }.not_to(change { root.expressions.object_id })
|
52
52
|
end
|
53
53
|
|
54
54
|
specify('Group::Named#clone') do
|
@@ -69,7 +69,39 @@ RSpec.describe('Expression#clone') do
|
|
69
69
|
end
|
70
70
|
|
71
71
|
# regression test
|
72
|
-
expect { root_1.clone }.not_to
|
72
|
+
expect { root_1.clone }.not_to(change { root_1.name.object_id })
|
73
|
+
end
|
74
|
+
|
75
|
+
specify('Group::Options#clone') do
|
76
|
+
root = RP.parse('foo(?i)bar')
|
77
|
+
copy = root.clone
|
78
|
+
|
79
|
+
expect(copy.to_s).to eq root.to_s
|
80
|
+
|
81
|
+
root_1 = root[1]
|
82
|
+
copy_1 = copy[1]
|
83
|
+
|
84
|
+
expect(root_1.option_changes).to eq copy_1.option_changes
|
85
|
+
expect(root_1.option_changes.object_id).not_to eq copy_1.option_changes.object_id
|
86
|
+
|
87
|
+
# regression test
|
88
|
+
expect { root_1.clone }.not_to(change { root_1.option_changes.object_id })
|
89
|
+
end
|
90
|
+
|
91
|
+
specify('Backreference::Base#clone') do
|
92
|
+
root = RP.parse('(foo)\1')
|
93
|
+
copy = root.clone
|
94
|
+
|
95
|
+
expect(copy.to_s).to eq root.to_s
|
96
|
+
|
97
|
+
root_1 = root[1]
|
98
|
+
copy_1 = copy[1]
|
99
|
+
|
100
|
+
expect(root_1.referenced_expression.to_s).to eq copy_1.referenced_expression.to_s
|
101
|
+
expect(root_1.referenced_expression.object_id).not_to eq copy_1.referenced_expression.object_id
|
102
|
+
|
103
|
+
# regression test
|
104
|
+
expect { root_1.clone }.not_to(change { root_1.referenced_expression.object_id })
|
73
105
|
end
|
74
106
|
|
75
107
|
specify('Sequence#clone') do
|
@@ -10,7 +10,7 @@ RSpec.describe(Regexp::Expression::FreeSpace) do
|
|
10
10
|
space = root[0]
|
11
11
|
|
12
12
|
expect(space).to be_instance_of(FreeSpace::WhiteSpace)
|
13
|
-
expect { space.quantify(:dummy, '#') }.to raise_error(
|
13
|
+
expect { space.quantify(:dummy, '#') }.to raise_error(Regexp::Parser::Error)
|
14
14
|
end
|
15
15
|
|
16
16
|
specify('comment quantify raises error') do
|
@@ -22,6 +22,6 @@ RSpec.describe(Regexp::Expression::FreeSpace) do
|
|
22
22
|
comment = root[3]
|
23
23
|
|
24
24
|
expect(comment).to be_instance_of(FreeSpace::Comment)
|
25
|
-
expect { comment.quantify(:dummy, '#') }.to raise_error(
|
25
|
+
expect { comment.quantify(:dummy, '#') }.to raise_error(Regexp::Parser::Error)
|
26
26
|
end
|
27
27
|
end
|
@@ -1,8 +1,8 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
|
4
|
-
ML = described_class
|
3
|
+
ML = Regexp::MatchLength
|
5
4
|
|
5
|
+
RSpec.describe(Regexp::MatchLength) do
|
6
6
|
specify('literal') { expect(ML.of(/a/).minmax).to eq [1, 1] }
|
7
7
|
specify('literal sequence') { expect(ML.of(/abc/).minmax).to eq [3, 3] }
|
8
8
|
specify('dot') { expect(ML.of(/./).minmax).to eq [1, 1] }
|
@@ -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
|
7
|
+
|
8
|
+
def expect_round_trip(pattern, ruby_version = nil)
|
9
|
+
parsed = parse_frozen(pattern, ruby_version)
|
6
10
|
|
7
|
-
expect(
|
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,8 +85,24 @@ RSpec.describe('Expression#to_s') do
|
|
93
85
|
/x
|
94
86
|
|
95
87
|
str = 'bbbcged'
|
96
|
-
root =
|
88
|
+
root = parse_frozen(multiline)
|
89
|
+
|
90
|
+
expect(Regexp.new(root.to_s, Regexp::EXTENDED).match(str)[0]).to eql(multiline.match(str)[0])
|
91
|
+
end
|
92
|
+
|
93
|
+
# special case: implicit groups used for chained quantifiers produce no parens
|
94
|
+
specify 'chained quantifiers #to_s' do
|
95
|
+
pattern = /a+{1}{2}/
|
96
|
+
root = parse_frozen(pattern)
|
97
|
+
expect(root.to_s).to eql('a+{1}{2}')
|
98
|
+
end
|
97
99
|
|
98
|
-
|
100
|
+
# regression test for https://github.com/ammar/regexp_parser/issues/74
|
101
|
+
specify('non-ascii comment') do
|
102
|
+
pattern = '(?x) 😋 # 😋'
|
103
|
+
root = RP.parse(pattern)
|
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)
|
99
107
|
end
|
100
108
|
end
|
data/spec/lexer/literals_spec.rb
CHANGED
@@ -10,67 +10,42 @@ RSpec.describe('Literal lexing') do
|
|
10
10
|
1 => [:literal, :literal, 'b', 1, 2, 0, 0, 0],
|
11
11
|
2 => [:quantifier, :one_or_more, '+', 2, 3, 0, 0, 0]
|
12
12
|
|
13
|
-
# 2 byte wide characters
|
14
|
-
include_examples 'lex', '
|
15
|
-
0 => [:literal, :literal, '
|
16
|
-
|
17
|
-
|
18
|
-
0 => [:literal, :literal, 'aاbبcت', 0, 9, 0, 0, 0]
|
19
|
-
|
20
|
-
include_examples 'lex', 'aاbبت?',
|
21
|
-
0 => [:literal, :literal, 'aاbب', 0, 6, 0, 0, 0],
|
22
|
-
1 => [:literal, :literal, 'ت', 6, 8, 0, 0, 0],
|
23
|
-
2 => [:quantifier, :zero_or_one, '?', 8, 9, 0, 0, 0]
|
24
|
-
|
25
|
-
include_examples 'lex', 'aا?bبcت+',
|
26
|
-
0 => [:literal, :literal, 'a', 0, 1, 0, 0, 0],
|
27
|
-
1 => [:literal, :literal, 'ا', 1, 3, 0, 0, 0],
|
28
|
-
2 => [:quantifier, :zero_or_one, '?', 3, 4, 0, 0, 0],
|
29
|
-
3 => [:literal, :literal, 'bبc', 4, 8, 0, 0, 0],
|
30
|
-
4 => [:literal, :literal, 'ت', 8, 10, 0, 0, 0],
|
31
|
-
5 => [:quantifier, :one_or_more, '+', 10, 11, 0, 0, 0]
|
32
|
-
|
33
|
-
include_examples 'lex', 'a(اbب+)cت?',
|
34
|
-
0 => [:literal, :literal, 'a', 0, 1, 0, 0, 0],
|
35
|
-
1 => [:group, :capture, '(', 1, 2, 0, 0, 0],
|
36
|
-
2 => [:literal, :literal, 'اb', 2, 5, 1, 0, 0],
|
37
|
-
3 => [:literal, :literal, 'ب', 5, 7, 1, 0, 0],
|
38
|
-
4 => [:quantifier, :one_or_more, '+', 7, 8, 1, 0, 0],
|
39
|
-
5 => [:group, :close, ')', 8, 9, 0, 0, 0],
|
40
|
-
6 => [:literal, :literal, 'c', 9, 10, 0, 0, 0],
|
41
|
-
7 => [:literal, :literal, 'ت', 10, 12, 0, 0, 0],
|
42
|
-
8 => [:quantifier, :zero_or_one, '?', 12, 13, 0, 0, 0]
|
13
|
+
# 2 byte wide characters
|
14
|
+
include_examples 'lex', 'äöü+',
|
15
|
+
0 => [:literal, :literal, 'äö', 0, 2, 0, 0, 0],
|
16
|
+
1 => [:literal, :literal, 'ü', 2, 3, 0, 0, 0],
|
17
|
+
2 => [:quantifier, :one_or_more, '+', 3, 4, 0, 0, 0]
|
43
18
|
|
44
19
|
# 3 byte wide characters, Japanese
|
45
20
|
include_examples 'lex', 'ab?れます+cd',
|
46
21
|
0 => [:literal, :literal, 'a', 0, 1, 0, 0, 0],
|
47
22
|
1 => [:literal, :literal, 'b', 1, 2, 0, 0, 0],
|
48
23
|
2 => [:quantifier, :zero_or_one, '?', 2, 3, 0, 0, 0],
|
49
|
-
3 => [:literal, :literal, 'れま', 3,
|
50
|
-
4 => [:literal, :literal, 'す',
|
51
|
-
5 => [:quantifier, :one_or_more, '+',
|
52
|
-
6 => [:literal, :literal, 'cd',
|
24
|
+
3 => [:literal, :literal, 'れま', 3, 5, 0, 0, 0],
|
25
|
+
4 => [:literal, :literal, 'す', 5, 6, 0, 0, 0],
|
26
|
+
5 => [:quantifier, :one_or_more, '+', 6, 7, 0, 0, 0],
|
27
|
+
6 => [:literal, :literal, 'cd', 7, 9, 0, 0, 0]
|
53
28
|
|
54
29
|
# 4 byte wide characters, Osmanya
|
55
30
|
include_examples 'lex', '𐒀𐒁?𐒂ab+𐒃',
|
56
|
-
0 => [:literal, :literal, '𐒀', 0,
|
57
|
-
1 => [:literal, :literal, '𐒁',
|
58
|
-
2 => [:quantifier, :zero_or_one, '?',
|
59
|
-
3 => [:literal, :literal, '𐒂a',
|
60
|
-
4 => [:literal, :literal, 'b',
|
61
|
-
5 => [:quantifier, :one_or_more, '+',
|
62
|
-
6 => [:literal, :literal, '𐒃',
|
31
|
+
0 => [:literal, :literal, '𐒀', 0, 1, 0, 0, 0],
|
32
|
+
1 => [:literal, :literal, '𐒁', 1, 2, 0, 0, 0],
|
33
|
+
2 => [:quantifier, :zero_or_one, '?', 2, 3, 0, 0, 0],
|
34
|
+
3 => [:literal, :literal, '𐒂a', 3, 5, 0, 0, 0],
|
35
|
+
4 => [:literal, :literal, 'b', 5, 6, 0, 0, 0],
|
36
|
+
5 => [:quantifier, :one_or_more, '+', 6, 7, 0, 0, 0],
|
37
|
+
6 => [:literal, :literal, '𐒃', 7, 8, 0, 0, 0]
|
63
38
|
|
64
39
|
include_examples 'lex', 'mu𝄞?si*𝄫c+',
|
65
40
|
0 => [:literal, :literal, 'mu', 0, 2, 0, 0, 0],
|
66
|
-
1 => [:literal, :literal, '𝄞', 2,
|
67
|
-
2 => [:quantifier, :zero_or_one, '?',
|
68
|
-
3 => [:literal, :literal, 's',
|
69
|
-
4 => [:literal, :literal, 'i',
|
70
|
-
5 => [:quantifier, :zero_or_more, '*',
|
71
|
-
6 => [:literal, :literal, '𝄫',
|
72
|
-
7 => [:literal, :literal, 'c',
|
73
|
-
8 => [:quantifier, :one_or_more, '+',
|
41
|
+
1 => [:literal, :literal, '𝄞', 2, 3, 0, 0, 0],
|
42
|
+
2 => [:quantifier, :zero_or_one, '?', 3, 4, 0, 0, 0],
|
43
|
+
3 => [:literal, :literal, 's', 4, 5, 0, 0, 0],
|
44
|
+
4 => [:literal, :literal, 'i', 5, 6, 0, 0, 0],
|
45
|
+
5 => [:quantifier, :zero_or_more, '*', 6, 7, 0, 0, 0],
|
46
|
+
6 => [:literal, :literal, '𝄫', 7, 8, 0, 0, 0],
|
47
|
+
7 => [:literal, :literal, 'c', 8, 9, 0, 0, 0],
|
48
|
+
8 => [:quantifier, :one_or_more, '+', 9, 10, 0, 0, 0]
|
74
49
|
|
75
50
|
specify('lex single 2 byte char') do
|
76
51
|
tokens = RL.lex("\u0627+")
|
data/spec/lexer/refcalls_spec.rb
CHANGED
@@ -32,6 +32,11 @@ RSpec.describe('RefCall lexing') do
|
|
32
32
|
include_examples 'lex', "(abc)\\g'1'",
|
33
33
|
3 => [:backref, :number_call, "\\g'1'", 5, 10, 0, 0, 0]
|
34
34
|
|
35
|
+
include_examples 'lex', '\g<0>',
|
36
|
+
0 => [:backref, :number_call, '\g<0>', 0, 5, 0, 0, 0]
|
37
|
+
include_examples 'lex', "\\g'0'",
|
38
|
+
0 => [:backref, :number_call, "\\g'0'", 0, 5, 0, 0, 0]
|
39
|
+
|
35
40
|
include_examples 'lex', '(abc)\g<-1>',
|
36
41
|
3 => [:backref, :number_rel_call, '\g<-1>', 5, 11, 0, 0, 0]
|
37
42
|
include_examples 'lex', "(abc)\\g'-1'",
|
data/spec/parser/all_spec.rb
CHANGED
@@ -34,10 +34,10 @@ RSpec.describe(Regexp::Parser) do
|
|
34
34
|
end
|
35
35
|
|
36
36
|
specify('parse no quantifier target raises error') do
|
37
|
-
expect { RP.parse('?abc') }.to raise_error(
|
37
|
+
expect { RP.parse('?abc') }.to raise_error(Regexp::Parser::Error)
|
38
38
|
end
|
39
39
|
|
40
40
|
specify('parse sequence no quantifier target raises error') do
|
41
|
-
expect { RP.parse('abc|?def') }.to raise_error(
|
41
|
+
expect { RP.parse('abc|?def') }.to raise_error(Regexp::Parser::Error)
|
42
42
|
end
|
43
43
|
end
|