regexp_parser 2.7.0 → 2.12.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 +4 -4
- data/Gemfile +7 -5
- data/LICENSE +1 -1
- data/Rakefile +5 -3
- data/lib/regexp_parser/error.rb +2 -0
- data/lib/regexp_parser/expression/base.rb +2 -7
- data/lib/regexp_parser/expression/classes/alternation.rb +3 -1
- data/lib/regexp_parser/expression/classes/anchor.rb +2 -0
- data/lib/regexp_parser/expression/classes/backreference.rb +7 -26
- data/lib/regexp_parser/expression/classes/character_set/intersection.rb +2 -0
- data/lib/regexp_parser/expression/classes/character_set/range.rb +4 -7
- data/lib/regexp_parser/expression/classes/character_set.rb +6 -8
- data/lib/regexp_parser/expression/classes/character_type.rb +2 -0
- data/lib/regexp_parser/expression/classes/conditional.rb +4 -28
- data/lib/regexp_parser/expression/classes/escape_sequence.rb +29 -96
- data/lib/regexp_parser/expression/classes/free_space.rb +5 -1
- data/lib/regexp_parser/expression/classes/group.rb +2 -22
- data/lib/regexp_parser/expression/classes/keep.rb +3 -1
- data/lib/regexp_parser/expression/classes/literal.rb +2 -0
- data/lib/regexp_parser/expression/classes/posix_class.rb +7 -5
- data/lib/regexp_parser/expression/classes/root.rb +2 -0
- data/lib/regexp_parser/expression/classes/unicode_property.rb +13 -11
- data/lib/regexp_parser/expression/methods/construct.rb +4 -4
- data/lib/regexp_parser/expression/methods/escape_sequence_char.rb +7 -0
- data/lib/regexp_parser/expression/methods/escape_sequence_codepoint.rb +76 -0
- data/lib/regexp_parser/expression/methods/human_name.rb +2 -0
- data/lib/regexp_parser/expression/methods/match.rb +2 -0
- data/lib/regexp_parser/expression/methods/match_length.rb +2 -0
- data/lib/regexp_parser/expression/methods/negative.rb +22 -0
- data/lib/regexp_parser/expression/methods/options.rb +2 -0
- data/lib/regexp_parser/expression/methods/parts.rb +25 -0
- data/lib/regexp_parser/expression/methods/printing.rb +28 -0
- data/lib/regexp_parser/expression/methods/referenced_expressions.rb +30 -0
- data/lib/regexp_parser/expression/methods/strfregexp.rb +2 -0
- data/lib/regexp_parser/expression/methods/tests.rb +42 -3
- data/lib/regexp_parser/expression/methods/traverse.rb +35 -20
- data/lib/regexp_parser/expression/quantifier.rb +33 -18
- data/lib/regexp_parser/expression/sequence.rb +7 -9
- data/lib/regexp_parser/expression/sequence_operation.rb +6 -9
- data/lib/regexp_parser/expression/shared.rb +40 -24
- data/lib/regexp_parser/expression/subexpression.rb +22 -18
- data/lib/regexp_parser/expression.rb +39 -31
- data/lib/regexp_parser/lexer.rb +17 -7
- data/lib/regexp_parser/parser.rb +101 -95
- data/lib/regexp_parser/scanner/errors/premature_end_error.rb +10 -0
- data/lib/regexp_parser/scanner/errors/scanner_error.rb +8 -0
- data/lib/regexp_parser/scanner/errors/validation_error.rb +65 -0
- data/lib/regexp_parser/scanner/properties/long.csv +61 -0
- data/lib/regexp_parser/scanner/properties/short.csv +15 -0
- data/lib/regexp_parser/scanner/property.rl +1 -1
- data/lib/regexp_parser/scanner/scanner.rl +90 -140
- data/lib/regexp_parser/scanner.rb +1336 -1450
- data/lib/regexp_parser/syntax/any.rb +2 -0
- data/lib/regexp_parser/syntax/base.rb +2 -0
- data/lib/regexp_parser/syntax/token/anchor.rb +5 -3
- data/lib/regexp_parser/syntax/token/assertion.rb +4 -2
- data/lib/regexp_parser/syntax/token/backreference.rb +11 -6
- data/lib/regexp_parser/syntax/token/character_set.rb +6 -1
- data/lib/regexp_parser/syntax/token/character_type.rb +6 -4
- data/lib/regexp_parser/syntax/token/conditional.rb +5 -3
- data/lib/regexp_parser/syntax/token/escape.rb +12 -8
- data/lib/regexp_parser/syntax/token/group.rb +8 -6
- data/lib/regexp_parser/syntax/token/keep.rb +3 -1
- data/lib/regexp_parser/syntax/token/meta.rb +11 -2
- data/lib/regexp_parser/syntax/token/posix_class.rb +4 -2
- data/lib/regexp_parser/syntax/token/quantifier.rb +8 -6
- data/lib/regexp_parser/syntax/token/unicode_property.rb +164 -70
- data/lib/regexp_parser/syntax/token/virtual.rb +13 -0
- data/lib/regexp_parser/syntax/token.rb +18 -16
- data/lib/regexp_parser/syntax/version_lookup.rb +4 -2
- data/lib/regexp_parser/syntax/versions/1.8.6.rb +2 -0
- data/lib/regexp_parser/syntax/versions/1.9.1.rb +2 -0
- data/lib/regexp_parser/syntax/versions/1.9.3.rb +2 -0
- data/lib/regexp_parser/syntax/versions/2.0.0.rb +2 -0
- data/lib/regexp_parser/syntax/versions/2.2.0.rb +2 -0
- data/lib/regexp_parser/syntax/versions/2.3.0.rb +2 -0
- data/lib/regexp_parser/syntax/versions/2.4.0.rb +2 -0
- data/lib/regexp_parser/syntax/versions/2.4.1.rb +2 -0
- data/lib/regexp_parser/syntax/versions/2.5.0.rb +2 -0
- data/lib/regexp_parser/syntax/versions/2.6.0.rb +2 -0
- data/lib/regexp_parser/syntax/versions/2.6.2.rb +2 -0
- data/lib/regexp_parser/syntax/versions/2.6.3.rb +2 -0
- data/lib/regexp_parser/syntax/versions/3.1.0.rb +2 -0
- data/lib/regexp_parser/syntax/versions/3.2.0.rb +2 -0
- data/lib/regexp_parser/syntax/versions/3.5.0.rb +4 -0
- data/lib/regexp_parser/syntax/versions/4.0.0.rb +4 -0
- data/lib/regexp_parser/syntax/versions.rb +3 -1
- data/lib/regexp_parser/syntax.rb +3 -1
- data/lib/regexp_parser/token.rb +2 -0
- data/lib/regexp_parser/version.rb +3 -1
- data/lib/regexp_parser.rb +8 -6
- data/regexp_parser.gemspec +7 -5
- metadata +19 -11
- data/CHANGELOG.md +0 -632
- data/README.md +0 -503
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: aa5734a20a0705226c021d9a0efef48a6ca24b5b18f15f93b34c12ffe5021d1e
|
|
4
|
+
data.tar.gz: fa77ac98b3bd17d6bdba43d387ebbbd84a6a0a5fa86123c7eee68646e90ce37c
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 4bb62063aaa64e3828c5abf551fbf5ce83f726b5ebeb56af3e9210fd7e8c110c7f8f9ba1fcafd0dd0f66b8e8f36f04c1d72e5a739c4ace8fa19978dfc1a794b1
|
|
7
|
+
data.tar.gz: a82384912534ec3ca98d7665434c655468b15e4d75d6c1f13405f0b777d818746c6686d36049a158f0df9b829c129026487e5c3e6cf8a8f7c7ca65155a937db3
|
data/Gemfile
CHANGED
|
@@ -1,15 +1,17 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
source 'https://rubygems.org'
|
|
2
4
|
|
|
3
5
|
gemspec
|
|
4
6
|
|
|
5
7
|
group :development, :test do
|
|
6
|
-
gem '
|
|
7
|
-
gem 'rake', '~> 13.
|
|
8
|
-
gem 'regexp_property_values', '~> 1.
|
|
8
|
+
gem 'leto', '~> 2.1'
|
|
9
|
+
gem 'rake', '~> 13.1'
|
|
10
|
+
gem 'regexp_property_values', '~> 1.5'
|
|
9
11
|
gem 'rspec', '~> 3.10'
|
|
10
12
|
if RUBY_VERSION.to_f >= 2.7
|
|
11
13
|
gem 'benchmark-ips', '~> 2.1'
|
|
12
|
-
gem 'gouteur'
|
|
13
|
-
gem 'rubocop', '
|
|
14
|
+
gem 'gouteur', '~> 1.1'
|
|
15
|
+
gem 'rubocop', '>= 1.80.2'
|
|
14
16
|
end
|
|
15
17
|
end
|
data/LICENSE
CHANGED
data/Rakefile
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
require 'bundler'
|
|
2
4
|
require 'rubygems'
|
|
3
5
|
require 'rubygems/package_task'
|
|
@@ -14,10 +16,10 @@ RSpec::Core::RakeTask.new(:spec)
|
|
|
14
16
|
task :default => [:'test:full']
|
|
15
17
|
|
|
16
18
|
namespace :test do
|
|
17
|
-
task full: [:
|
|
19
|
+
task full: [:ragel, :spec]
|
|
18
20
|
end
|
|
19
21
|
|
|
20
22
|
# Add ragel task as a prerequisite for building the gem to ensure that the
|
|
21
23
|
# latest scanner code is generated and included in the build.
|
|
22
|
-
desc "Runs ragel
|
|
23
|
-
task :
|
|
24
|
+
desc "Runs ragel before building the gem"
|
|
25
|
+
task build: :ragel
|
data/lib/regexp_parser/error.rb
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
module Regexp::Expression
|
|
2
4
|
class Base
|
|
3
5
|
include Regexp::Expression::Shared
|
|
@@ -6,13 +8,6 @@ module Regexp::Expression
|
|
|
6
8
|
init_from_token_and_options(token, options)
|
|
7
9
|
end
|
|
8
10
|
|
|
9
|
-
def initialize_copy(orig)
|
|
10
|
-
self.text = orig.text.dup if orig.text
|
|
11
|
-
self.options = orig.options.dup if orig.options
|
|
12
|
-
self.quantifier = orig.quantifier.clone if orig.quantifier
|
|
13
|
-
super
|
|
14
|
-
end
|
|
15
|
-
|
|
16
11
|
def to_re(format = :full)
|
|
17
12
|
if set_level > 0
|
|
18
13
|
warn "Calling #to_re on character set members is deprecated - "\
|
|
@@ -1,5 +1,7 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
module Regexp::Expression
|
|
2
|
-
# A sequence of expressions, used by Alternation as one of its
|
|
4
|
+
# A sequence of expressions, used by Alternation as one of its alternatives.
|
|
3
5
|
class Alternative < Regexp::Expression::Sequence; end
|
|
4
6
|
|
|
5
7
|
class Alternation < Regexp::Expression::SequenceOperation
|
|
@@ -1,37 +1,15 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
module Regexp::Expression
|
|
2
|
-
# TODO: unify name with token :backref, one way or the other, in v3.0.0
|
|
3
4
|
module Backreference
|
|
4
|
-
class Base < Regexp::Expression::Base
|
|
5
|
-
attr_accessor :referenced_expression
|
|
6
|
-
|
|
7
|
-
def initialize_copy(orig)
|
|
8
|
-
exp_id = [self.class, self.starts_at]
|
|
9
|
-
|
|
10
|
-
# prevent infinite recursion for recursive subexp calls
|
|
11
|
-
copied = @@copied ||= {}
|
|
12
|
-
self.referenced_expression =
|
|
13
|
-
if copied[exp_id]
|
|
14
|
-
orig.referenced_expression
|
|
15
|
-
else
|
|
16
|
-
copied[exp_id] = true
|
|
17
|
-
orig.referenced_expression.dup
|
|
18
|
-
end
|
|
19
|
-
copied.clear
|
|
20
|
-
|
|
21
|
-
super
|
|
22
|
-
end
|
|
23
|
-
|
|
24
|
-
def referential?
|
|
25
|
-
true
|
|
26
|
-
end
|
|
27
|
-
end
|
|
5
|
+
class Base < Regexp::Expression::Base; end
|
|
28
6
|
|
|
29
7
|
class Number < Backreference::Base
|
|
30
8
|
attr_reader :number
|
|
31
9
|
alias reference number
|
|
32
10
|
|
|
33
11
|
def initialize(token, options = {})
|
|
34
|
-
@number = token.text[
|
|
12
|
+
@number = token.text[/-?\d+/].to_i
|
|
35
13
|
super
|
|
36
14
|
end
|
|
37
15
|
end
|
|
@@ -74,4 +52,7 @@ module Regexp::Expression
|
|
|
74
52
|
end
|
|
75
53
|
end
|
|
76
54
|
end
|
|
55
|
+
|
|
56
|
+
# alias for symmetry between token symbol and Expression class name
|
|
57
|
+
Backref = Backreference
|
|
77
58
|
end
|
|
@@ -1,10 +1,11 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
module Regexp::Expression
|
|
2
4
|
class CharacterSet < Regexp::Expression::Subexpression
|
|
3
5
|
class Range < Regexp::Expression::Subexpression
|
|
4
|
-
def
|
|
5
|
-
expressions.first.
|
|
6
|
+
def ts
|
|
7
|
+
(head = expressions.first) ? head.ts : @ts
|
|
6
8
|
end
|
|
7
|
-
alias :ts :starts_at
|
|
8
9
|
|
|
9
10
|
def <<(exp)
|
|
10
11
|
complete? and raise Regexp::Parser::Error,
|
|
@@ -15,10 +16,6 @@ module Regexp::Expression
|
|
|
15
16
|
def complete?
|
|
16
17
|
count == 2
|
|
17
18
|
end
|
|
18
|
-
|
|
19
|
-
def parts
|
|
20
|
-
intersperse(expressions, text.dup)
|
|
21
|
-
end
|
|
22
19
|
end
|
|
23
20
|
end
|
|
24
21
|
end
|
|
@@ -1,10 +1,9 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
module Regexp::Expression
|
|
2
4
|
class CharacterSet < Regexp::Expression::Subexpression
|
|
3
5
|
attr_accessor :closed, :negative
|
|
4
|
-
|
|
5
|
-
alias :negative? :negative
|
|
6
|
-
alias :negated? :negative
|
|
7
|
-
alias :closed? :closed
|
|
6
|
+
alias :closed? :closed
|
|
8
7
|
|
|
9
8
|
def initialize(token, options = {})
|
|
10
9
|
self.negative = false
|
|
@@ -19,9 +18,8 @@ module Regexp::Expression
|
|
|
19
18
|
def close
|
|
20
19
|
self.closed = true
|
|
21
20
|
end
|
|
22
|
-
|
|
23
|
-
def parts
|
|
24
|
-
["#{text}#{'^' if negated?}", *expressions, ']']
|
|
25
|
-
end
|
|
26
21
|
end
|
|
22
|
+
|
|
23
|
+
# alias for symmetry between token symbol and Expression class name
|
|
24
|
+
Set = CharacterSet
|
|
27
25
|
end # module Regexp::Expression
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
module Regexp::Expression
|
|
2
4
|
module Conditional
|
|
3
5
|
class TooManyBranches < Regexp::Parser::Error
|
|
@@ -7,37 +9,24 @@ module Regexp::Expression
|
|
|
7
9
|
end
|
|
8
10
|
|
|
9
11
|
class Condition < Regexp::Expression::Base
|
|
10
|
-
attr_accessor :referenced_expression
|
|
11
|
-
|
|
12
12
|
# Name or number of the referenced capturing group that determines state.
|
|
13
13
|
# Returns a String if reference is by name, Integer if by number.
|
|
14
14
|
def reference
|
|
15
15
|
ref = text.tr("'<>()", "")
|
|
16
16
|
ref =~ /\D/ ? ref : Integer(ref)
|
|
17
17
|
end
|
|
18
|
-
|
|
19
|
-
def initialize_copy(orig)
|
|
20
|
-
self.referenced_expression = orig.referenced_expression.dup
|
|
21
|
-
super
|
|
22
|
-
end
|
|
23
|
-
|
|
24
|
-
def referential?
|
|
25
|
-
true
|
|
26
|
-
end
|
|
27
18
|
end
|
|
28
19
|
|
|
29
20
|
class Branch < Regexp::Expression::Sequence; end
|
|
30
21
|
|
|
31
22
|
class Expression < Regexp::Expression::Subexpression
|
|
32
|
-
attr_accessor :referenced_expression
|
|
33
|
-
|
|
34
23
|
def <<(exp)
|
|
35
24
|
expressions.last << exp
|
|
36
25
|
end
|
|
37
26
|
|
|
38
|
-
def add_sequence(active_opts = {})
|
|
27
|
+
def add_sequence(active_opts = {}, params = { ts: 0 })
|
|
39
28
|
raise TooManyBranches.new if branches.length == 2
|
|
40
|
-
params = { conditional_level: conditional_level + 1 }
|
|
29
|
+
params = params.merge({ conditional_level: conditional_level + 1 })
|
|
41
30
|
Branch.add_to(self, params, active_opts)
|
|
42
31
|
end
|
|
43
32
|
alias :branch :add_sequence
|
|
@@ -58,19 +47,6 @@ module Regexp::Expression
|
|
|
58
47
|
def reference
|
|
59
48
|
condition.reference
|
|
60
49
|
end
|
|
61
|
-
|
|
62
|
-
def referential?
|
|
63
|
-
true
|
|
64
|
-
end
|
|
65
|
-
|
|
66
|
-
def parts
|
|
67
|
-
[text.dup, condition, *intersperse(branches, '|'), ')']
|
|
68
|
-
end
|
|
69
|
-
|
|
70
|
-
def initialize_copy(orig)
|
|
71
|
-
self.referenced_expression = orig.referenced_expression.dup
|
|
72
|
-
super
|
|
73
|
-
end
|
|
74
50
|
end
|
|
75
51
|
end
|
|
76
52
|
end
|
|
@@ -1,100 +1,33 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
module Regexp::Expression
|
|
2
|
-
# TODO: unify naming with Token::Escape, one way or the other, in v3.0.0
|
|
3
4
|
module EscapeSequence
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
class AsciiEscape < EscapeSequence::Base; end
|
|
29
|
-
class Backspace < EscapeSequence::Base; end
|
|
30
|
-
class Bell < EscapeSequence::Base; end
|
|
31
|
-
class FormFeed < EscapeSequence::Base; end
|
|
32
|
-
class Newline < EscapeSequence::Base; end
|
|
33
|
-
class Return < EscapeSequence::Base; end
|
|
34
|
-
class Tab < EscapeSequence::Base; end
|
|
35
|
-
class VerticalTab < EscapeSequence::Base; end
|
|
36
|
-
|
|
37
|
-
class Hex < EscapeSequence::Base; end
|
|
38
|
-
class Codepoint < EscapeSequence::Base; end
|
|
39
|
-
|
|
40
|
-
class CodepointList < EscapeSequence::Base
|
|
41
|
-
def char
|
|
42
|
-
raise NoMethodError, 'CodepointList responds only to #chars'
|
|
43
|
-
end
|
|
44
|
-
|
|
45
|
-
def codepoint
|
|
46
|
-
raise NoMethodError, 'CodepointList responds only to #codepoints'
|
|
47
|
-
end
|
|
48
|
-
|
|
49
|
-
def chars
|
|
50
|
-
codepoints.map { |cp| cp.chr('utf-8') }
|
|
51
|
-
end
|
|
52
|
-
|
|
53
|
-
def codepoints
|
|
54
|
-
text.scan(/\h+/).map(&:hex)
|
|
55
|
-
end
|
|
56
|
-
end
|
|
57
|
-
|
|
58
|
-
class Octal < EscapeSequence::Base
|
|
59
|
-
def char
|
|
60
|
-
text[1..-1].to_i(8).chr('utf-8')
|
|
61
|
-
end
|
|
62
|
-
end
|
|
63
|
-
|
|
64
|
-
class AbstractMetaControlSequence < EscapeSequence::Base
|
|
65
|
-
def char
|
|
66
|
-
codepoint.chr('utf-8')
|
|
67
|
-
end
|
|
68
|
-
|
|
69
|
-
private
|
|
70
|
-
|
|
71
|
-
def control_sequence_to_s(control_sequence)
|
|
72
|
-
five_lsb = control_sequence.unpack('B*').first[-5..-1]
|
|
73
|
-
["000#{five_lsb}"].pack('B*')
|
|
74
|
-
end
|
|
75
|
-
|
|
76
|
-
def meta_char_to_codepoint(meta_char)
|
|
77
|
-
byte_value = meta_char.ord
|
|
78
|
-
byte_value < 128 ? byte_value + 128 : byte_value
|
|
79
|
-
end
|
|
80
|
-
end
|
|
81
|
-
|
|
82
|
-
class Control < AbstractMetaControlSequence
|
|
83
|
-
def codepoint
|
|
84
|
-
control_sequence_to_s(text).ord
|
|
85
|
-
end
|
|
86
|
-
end
|
|
87
|
-
|
|
88
|
-
class Meta < AbstractMetaControlSequence
|
|
89
|
-
def codepoint
|
|
90
|
-
meta_char_to_codepoint(text[-1])
|
|
91
|
-
end
|
|
92
|
-
end
|
|
93
|
-
|
|
94
|
-
class MetaControl < AbstractMetaControlSequence
|
|
95
|
-
def codepoint
|
|
96
|
-
meta_char_to_codepoint(control_sequence_to_s(text))
|
|
97
|
-
end
|
|
98
|
-
end
|
|
5
|
+
Base = Class.new(Regexp::Expression::Base)
|
|
6
|
+
|
|
7
|
+
AsciiEscape = Class.new(Base) # \e
|
|
8
|
+
Backspace = Class.new(Base) # \b
|
|
9
|
+
Bell = Class.new(Base) # \a
|
|
10
|
+
FormFeed = Class.new(Base) # \f
|
|
11
|
+
Newline = Class.new(Base) # \n
|
|
12
|
+
Return = Class.new(Base) # \r
|
|
13
|
+
Tab = Class.new(Base) # \t
|
|
14
|
+
VerticalTab = Class.new(Base) # \v
|
|
15
|
+
|
|
16
|
+
Literal = Class.new(Base) # e.g. \j, \@, \😀 (ineffectual escapes)
|
|
17
|
+
|
|
18
|
+
Octal = Class.new(Base) # e.g. \012
|
|
19
|
+
Hex = Class.new(Base) # e.g. \x0A
|
|
20
|
+
Codepoint = Class.new(Base) # e.g. \u000A
|
|
21
|
+
|
|
22
|
+
CodepointList = Class.new(Base) # e.g. \u{A B}
|
|
23
|
+
UTF8Hex = Class.new(Base) # e.g. \xE2\x82\xAC
|
|
24
|
+
|
|
25
|
+
AbstractMetaControlSequence = Class.new(Base)
|
|
26
|
+
Control = Class.new(AbstractMetaControlSequence) # e.g. \cB
|
|
27
|
+
Meta = Class.new(AbstractMetaControlSequence) # e.g. \M-Z
|
|
28
|
+
MetaControl = Class.new(AbstractMetaControlSequence) # e.g. \M-\cX
|
|
99
29
|
end
|
|
30
|
+
|
|
31
|
+
# alias for symmetry between Token::* and Expression::*
|
|
32
|
+
Escape = EscapeSequence
|
|
100
33
|
end
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
module Regexp::Expression
|
|
2
4
|
class FreeSpace < Regexp::Expression::Base
|
|
3
5
|
def quantify(*_args)
|
|
@@ -5,10 +7,12 @@ module Regexp::Expression
|
|
|
5
7
|
end
|
|
6
8
|
end
|
|
7
9
|
|
|
8
|
-
class Comment < Regexp::Expression::FreeSpace
|
|
10
|
+
class Comment < Regexp::Expression::FreeSpace
|
|
11
|
+
end
|
|
9
12
|
|
|
10
13
|
class WhiteSpace < Regexp::Expression::FreeSpace
|
|
11
14
|
def merge(exp)
|
|
15
|
+
warn("#{self.class}##{__method__} is deprecated and will be removed in v3.0.0.")
|
|
12
16
|
text << exp.text
|
|
13
17
|
end
|
|
14
18
|
end
|
|
@@ -1,13 +1,8 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
module Regexp::Expression
|
|
2
4
|
module Group
|
|
3
5
|
class Base < Regexp::Expression::Subexpression
|
|
4
|
-
def parts
|
|
5
|
-
[text.dup, *expressions, ')']
|
|
6
|
-
end
|
|
7
|
-
|
|
8
|
-
def capturing?; false end
|
|
9
|
-
|
|
10
|
-
def comment?; false end
|
|
11
6
|
end
|
|
12
7
|
|
|
13
8
|
class Passive < Group::Base
|
|
@@ -18,14 +13,6 @@ module Regexp::Expression
|
|
|
18
13
|
super
|
|
19
14
|
end
|
|
20
15
|
|
|
21
|
-
def parts
|
|
22
|
-
if implicit?
|
|
23
|
-
expressions
|
|
24
|
-
else
|
|
25
|
-
super
|
|
26
|
-
end
|
|
27
|
-
end
|
|
28
|
-
|
|
29
16
|
def implicit?
|
|
30
17
|
@implicit
|
|
31
18
|
end
|
|
@@ -55,8 +42,6 @@ module Regexp::Expression
|
|
|
55
42
|
class Capture < Group::Base
|
|
56
43
|
attr_accessor :number, :number_at_level
|
|
57
44
|
alias identifier number
|
|
58
|
-
|
|
59
|
-
def capturing?; true end
|
|
60
45
|
end
|
|
61
46
|
|
|
62
47
|
class Named < Group::Capture
|
|
@@ -75,11 +60,6 @@ module Regexp::Expression
|
|
|
75
60
|
end
|
|
76
61
|
|
|
77
62
|
class Comment < Group::Base
|
|
78
|
-
def parts
|
|
79
|
-
[text.dup]
|
|
80
|
-
end
|
|
81
|
-
|
|
82
|
-
def comment?; true end
|
|
83
63
|
end
|
|
84
64
|
end
|
|
85
65
|
|
|
@@ -1,6 +1,8 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
module Regexp::Expression
|
|
2
4
|
module Keep
|
|
3
|
-
#
|
|
5
|
+
# TODO: in regexp_parser v3.0.0 this should possibly be a Subexpression
|
|
4
6
|
# that contains all expressions to its left.
|
|
5
7
|
class Mark < Regexp::Expression::Base; end
|
|
6
8
|
end
|
|
@@ -1,11 +1,13 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
module Regexp::Expression
|
|
2
4
|
class PosixClass < Regexp::Expression::Base
|
|
3
|
-
def negative?
|
|
4
|
-
type == :nonposixclass
|
|
5
|
-
end
|
|
6
|
-
|
|
7
5
|
def name
|
|
8
|
-
|
|
6
|
+
text[/\w+/]
|
|
9
7
|
end
|
|
10
8
|
end
|
|
9
|
+
|
|
10
|
+
# alias for symmetry between token symbol and Expression class name
|
|
11
|
+
Posixclass = PosixClass
|
|
12
|
+
Nonposixclass = PosixClass
|
|
11
13
|
end
|
|
@@ -1,17 +1,14 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
module Regexp::Expression
|
|
2
|
-
# TODO: unify name with token :property, one way or the other, in v3.0.0
|
|
3
4
|
module UnicodeProperty
|
|
4
5
|
class Base < Regexp::Expression::Base
|
|
5
|
-
def negative?
|
|
6
|
-
type == :nonproperty
|
|
7
|
-
end
|
|
8
|
-
|
|
9
6
|
def name
|
|
10
7
|
text[/\A\\[pP]\{([^}]+)\}\z/, 1]
|
|
11
8
|
end
|
|
12
9
|
|
|
13
10
|
def shortcut
|
|
14
|
-
|
|
11
|
+
Regexp::Scanner.short_prop_map.key(token.to_s)
|
|
15
12
|
end
|
|
16
13
|
end
|
|
17
14
|
|
|
@@ -110,10 +107,15 @@ module Regexp::Expression
|
|
|
110
107
|
class Unassigned < Codepoint::Base; end
|
|
111
108
|
end
|
|
112
109
|
|
|
113
|
-
class Age
|
|
114
|
-
class
|
|
115
|
-
class
|
|
116
|
-
class
|
|
117
|
-
class
|
|
110
|
+
class Age < UnicodeProperty::Base; end
|
|
111
|
+
class Block < UnicodeProperty::Base; end
|
|
112
|
+
class Derived < UnicodeProperty::Base; end
|
|
113
|
+
class Emoji < UnicodeProperty::Base; end
|
|
114
|
+
class Enumerated < UnicodeProperty::Base; end
|
|
115
|
+
class Script < UnicodeProperty::Base; end
|
|
118
116
|
end
|
|
117
|
+
|
|
118
|
+
# alias for symmetry between token symbol and Expression class name
|
|
119
|
+
Property = UnicodeProperty
|
|
120
|
+
Nonproperty = UnicodeProperty
|
|
119
121
|
end # module Regexp::Expression
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
module Regexp::Expression
|
|
2
4
|
module Shared
|
|
3
5
|
module ClassMethods
|
|
@@ -25,11 +27,9 @@ module Regexp::Expression
|
|
|
25
27
|
def token_class
|
|
26
28
|
if self == Root || self < Sequence
|
|
27
29
|
nil # no token class because these objects are Parser-generated
|
|
28
|
-
# TODO: synch exp
|
|
29
|
-
elsif self ==
|
|
30
|
+
# TODO: synch exp class, token class & type names for this in v3.0.0
|
|
31
|
+
elsif self == CharacterType::Any
|
|
30
32
|
Regexp::Syntax::Token::Meta
|
|
31
|
-
elsif self <= EscapeSequence::Base
|
|
32
|
-
Regexp::Syntax::Token::Escape
|
|
33
33
|
else
|
|
34
34
|
Regexp::Syntax::Token.const_get(name.split('::')[2])
|
|
35
35
|
end
|