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.
Files changed (95) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +7 -5
  3. data/LICENSE +1 -1
  4. data/Rakefile +5 -3
  5. data/lib/regexp_parser/error.rb +2 -0
  6. data/lib/regexp_parser/expression/base.rb +2 -7
  7. data/lib/regexp_parser/expression/classes/alternation.rb +3 -1
  8. data/lib/regexp_parser/expression/classes/anchor.rb +2 -0
  9. data/lib/regexp_parser/expression/classes/backreference.rb +7 -26
  10. data/lib/regexp_parser/expression/classes/character_set/intersection.rb +2 -0
  11. data/lib/regexp_parser/expression/classes/character_set/range.rb +4 -7
  12. data/lib/regexp_parser/expression/classes/character_set.rb +6 -8
  13. data/lib/regexp_parser/expression/classes/character_type.rb +2 -0
  14. data/lib/regexp_parser/expression/classes/conditional.rb +4 -28
  15. data/lib/regexp_parser/expression/classes/escape_sequence.rb +29 -96
  16. data/lib/regexp_parser/expression/classes/free_space.rb +5 -1
  17. data/lib/regexp_parser/expression/classes/group.rb +2 -22
  18. data/lib/regexp_parser/expression/classes/keep.rb +3 -1
  19. data/lib/regexp_parser/expression/classes/literal.rb +2 -0
  20. data/lib/regexp_parser/expression/classes/posix_class.rb +7 -5
  21. data/lib/regexp_parser/expression/classes/root.rb +2 -0
  22. data/lib/regexp_parser/expression/classes/unicode_property.rb +13 -11
  23. data/lib/regexp_parser/expression/methods/construct.rb +4 -4
  24. data/lib/regexp_parser/expression/methods/escape_sequence_char.rb +7 -0
  25. data/lib/regexp_parser/expression/methods/escape_sequence_codepoint.rb +76 -0
  26. data/lib/regexp_parser/expression/methods/human_name.rb +2 -0
  27. data/lib/regexp_parser/expression/methods/match.rb +2 -0
  28. data/lib/regexp_parser/expression/methods/match_length.rb +2 -0
  29. data/lib/regexp_parser/expression/methods/negative.rb +22 -0
  30. data/lib/regexp_parser/expression/methods/options.rb +2 -0
  31. data/lib/regexp_parser/expression/methods/parts.rb +25 -0
  32. data/lib/regexp_parser/expression/methods/printing.rb +28 -0
  33. data/lib/regexp_parser/expression/methods/referenced_expressions.rb +30 -0
  34. data/lib/regexp_parser/expression/methods/strfregexp.rb +2 -0
  35. data/lib/regexp_parser/expression/methods/tests.rb +42 -3
  36. data/lib/regexp_parser/expression/methods/traverse.rb +35 -20
  37. data/lib/regexp_parser/expression/quantifier.rb +33 -18
  38. data/lib/regexp_parser/expression/sequence.rb +7 -9
  39. data/lib/regexp_parser/expression/sequence_operation.rb +6 -9
  40. data/lib/regexp_parser/expression/shared.rb +40 -24
  41. data/lib/regexp_parser/expression/subexpression.rb +22 -18
  42. data/lib/regexp_parser/expression.rb +39 -31
  43. data/lib/regexp_parser/lexer.rb +17 -7
  44. data/lib/regexp_parser/parser.rb +101 -95
  45. data/lib/regexp_parser/scanner/errors/premature_end_error.rb +10 -0
  46. data/lib/regexp_parser/scanner/errors/scanner_error.rb +8 -0
  47. data/lib/regexp_parser/scanner/errors/validation_error.rb +65 -0
  48. data/lib/regexp_parser/scanner/properties/long.csv +61 -0
  49. data/lib/regexp_parser/scanner/properties/short.csv +15 -0
  50. data/lib/regexp_parser/scanner/property.rl +1 -1
  51. data/lib/regexp_parser/scanner/scanner.rl +90 -140
  52. data/lib/regexp_parser/scanner.rb +1336 -1450
  53. data/lib/regexp_parser/syntax/any.rb +2 -0
  54. data/lib/regexp_parser/syntax/base.rb +2 -0
  55. data/lib/regexp_parser/syntax/token/anchor.rb +5 -3
  56. data/lib/regexp_parser/syntax/token/assertion.rb +4 -2
  57. data/lib/regexp_parser/syntax/token/backreference.rb +11 -6
  58. data/lib/regexp_parser/syntax/token/character_set.rb +6 -1
  59. data/lib/regexp_parser/syntax/token/character_type.rb +6 -4
  60. data/lib/regexp_parser/syntax/token/conditional.rb +5 -3
  61. data/lib/regexp_parser/syntax/token/escape.rb +12 -8
  62. data/lib/regexp_parser/syntax/token/group.rb +8 -6
  63. data/lib/regexp_parser/syntax/token/keep.rb +3 -1
  64. data/lib/regexp_parser/syntax/token/meta.rb +11 -2
  65. data/lib/regexp_parser/syntax/token/posix_class.rb +4 -2
  66. data/lib/regexp_parser/syntax/token/quantifier.rb +8 -6
  67. data/lib/regexp_parser/syntax/token/unicode_property.rb +164 -70
  68. data/lib/regexp_parser/syntax/token/virtual.rb +13 -0
  69. data/lib/regexp_parser/syntax/token.rb +18 -16
  70. data/lib/regexp_parser/syntax/version_lookup.rb +4 -2
  71. data/lib/regexp_parser/syntax/versions/1.8.6.rb +2 -0
  72. data/lib/regexp_parser/syntax/versions/1.9.1.rb +2 -0
  73. data/lib/regexp_parser/syntax/versions/1.9.3.rb +2 -0
  74. data/lib/regexp_parser/syntax/versions/2.0.0.rb +2 -0
  75. data/lib/regexp_parser/syntax/versions/2.2.0.rb +2 -0
  76. data/lib/regexp_parser/syntax/versions/2.3.0.rb +2 -0
  77. data/lib/regexp_parser/syntax/versions/2.4.0.rb +2 -0
  78. data/lib/regexp_parser/syntax/versions/2.4.1.rb +2 -0
  79. data/lib/regexp_parser/syntax/versions/2.5.0.rb +2 -0
  80. data/lib/regexp_parser/syntax/versions/2.6.0.rb +2 -0
  81. data/lib/regexp_parser/syntax/versions/2.6.2.rb +2 -0
  82. data/lib/regexp_parser/syntax/versions/2.6.3.rb +2 -0
  83. data/lib/regexp_parser/syntax/versions/3.1.0.rb +2 -0
  84. data/lib/regexp_parser/syntax/versions/3.2.0.rb +2 -0
  85. data/lib/regexp_parser/syntax/versions/3.5.0.rb +4 -0
  86. data/lib/regexp_parser/syntax/versions/4.0.0.rb +4 -0
  87. data/lib/regexp_parser/syntax/versions.rb +3 -1
  88. data/lib/regexp_parser/syntax.rb +3 -1
  89. data/lib/regexp_parser/token.rb +2 -0
  90. data/lib/regexp_parser/version.rb +3 -1
  91. data/lib/regexp_parser.rb +8 -6
  92. data/regexp_parser.gemspec +7 -5
  93. metadata +19 -11
  94. data/CHANGELOG.md +0 -632
  95. data/README.md +0 -503
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 04af46818e9d560362fea9b3fd24802b557ac145ed95f6e02580dd7cf5e8ddfc
4
- data.tar.gz: 75b7d30241f48ddf90c8cd68228fa928904ab6055ea755f4bdcf28361e645a4b
3
+ metadata.gz: aa5734a20a0705226c021d9a0efef48a6ca24b5b18f15f93b34c12ffe5021d1e
4
+ data.tar.gz: fa77ac98b3bd17d6bdba43d387ebbbd84a6a0a5fa86123c7eee68646e90ce37c
5
5
  SHA512:
6
- metadata.gz: 407025a9b14af76463260fca2a48f9fef4ab863e3dddf3f7f54101c1348611afa49d9973e850d9e1c84d6e5faf8f1a9d3d2da5dceaefe8dc4fefe7069ecd9280
7
- data.tar.gz: 9f3d2eb4264318511a82e9034c4c4a8a8e73e67e427945f0c9f745fd37b2f2f0ae8e30ba942f0920da3109b59436a5518dfc5e2f7669317de0214a0deb6f0e07
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 'ice_nine', '~> 0.11.2'
7
- gem 'rake', '~> 13.0'
8
- gem 'regexp_property_values', '~> 1.3'
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', '~> 1.7'
14
+ gem 'gouteur', '~> 1.1'
15
+ gem 'rubocop', '>= 1.80.2'
14
16
  end
15
17
  end
data/LICENSE CHANGED
@@ -1,4 +1,4 @@
1
- Copyright (c) 2010, 2012-2022, Ammar Ali
1
+ Copyright (c) 2010, 2012-2025, Ammar Ali
2
2
 
3
3
  Permission is hereby granted, free of charge, to any person
4
4
  obtaining a copy of this software and associated documentation
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: [:'ragel:rb', :spec]
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:rb before building the gem"
23
- task :build => ['ragel:rb']
24
+ desc "Runs ragel before building the gem"
25
+ task build: :ragel
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  class Regexp::Parser
2
4
  # base class for all gem-specific errors
3
5
  class Error < StandardError; end
@@ -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 alternative.
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,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Regexp::Expression
2
4
  module Anchor
3
5
  class Base < Regexp::Expression::Base; end
@@ -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[token.token.equal?(:number) ? 1..-1 : 3..-2].to_i
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,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Regexp::Expression
2
4
  class CharacterSet < Regexp::Expression::Subexpression
3
5
  class IntersectedSequence < Regexp::Expression::Sequence; 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 starts_at
5
- expressions.first.starts_at
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 CharacterType
3
5
  class Base < Regexp::Expression::Base; end
@@ -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
- class Base < Regexp::Expression::Base
5
- def codepoint
6
- char.ord
7
- end
8
-
9
- if ''.respond_to?(:undump)
10
- def char
11
- %("#{text}").undump
12
- end
13
- else
14
- # poor man's unescape without using eval
15
- require 'yaml'
16
- def char
17
- YAML.load(%Q(---\n"#{text}"\n))
18
- end
19
- end
20
- end
21
-
22
- class Literal < EscapeSequence::Base
23
- def char
24
- text[1..-1]
25
- end
26
- end
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; end
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
- # TOOD: in regexp_parser v3.0.0 this should possibly be a Subexpression
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,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Regexp::Expression
2
4
  class Literal < Regexp::Expression::Base; end
3
5
  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
- token.to_s
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,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Regexp::Expression
2
4
  class Root < Regexp::Expression::Subexpression
3
5
  def self.build(options = {})
@@ -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
- (Regexp::Scanner.short_prop_map.rassoc(token.to_s) || []).first
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 < UnicodeProperty::Base; end
114
- class Derived < UnicodeProperty::Base; end
115
- class Emoji < UnicodeProperty::Base; end
116
- class Script < UnicodeProperty::Base; end
117
- class Block < UnicodeProperty::Base; end
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 & token class names for alt., dot, escapes in v3.0.0
29
- elsif self == Alternation || self == CharacterType::Any
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
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ Regexp::Expression::EscapeSequence::Base.class_eval do
4
+ def char
5
+ codepoint.chr('utf-8')
6
+ end
7
+ end