regexp_parser 1.7.0 → 2.9.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (166) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +9 -3
  3. data/LICENSE +1 -1
  4. data/Rakefile +6 -70
  5. data/lib/regexp_parser/error.rb +4 -0
  6. data/lib/regexp_parser/expression/base.rb +76 -0
  7. data/lib/regexp_parser/expression/classes/alternation.rb +1 -1
  8. data/lib/regexp_parser/expression/classes/anchor.rb +0 -2
  9. data/lib/regexp_parser/expression/classes/{backref.rb → backreference.rb} +22 -2
  10. data/lib/regexp_parser/expression/classes/{set → character_set}/range.rb +4 -8
  11. data/lib/regexp_parser/expression/classes/{set.rb → character_set.rb} +4 -8
  12. data/lib/regexp_parser/expression/classes/{type.rb → character_type.rb} +0 -2
  13. data/lib/regexp_parser/expression/classes/conditional.rb +11 -5
  14. data/lib/regexp_parser/expression/classes/{escape.rb → escape_sequence.rb} +15 -7
  15. data/lib/regexp_parser/expression/classes/free_space.rb +5 -5
  16. data/lib/regexp_parser/expression/classes/group.rb +28 -15
  17. data/lib/regexp_parser/expression/classes/keep.rb +2 -0
  18. data/lib/regexp_parser/expression/classes/literal.rb +1 -5
  19. data/lib/regexp_parser/expression/classes/posix_class.rb +5 -5
  20. data/lib/regexp_parser/expression/classes/root.rb +4 -19
  21. data/lib/regexp_parser/expression/classes/{property.rb → unicode_property.rb} +11 -12
  22. data/lib/regexp_parser/expression/methods/construct.rb +41 -0
  23. data/lib/regexp_parser/expression/methods/human_name.rb +43 -0
  24. data/lib/regexp_parser/expression/methods/match_length.rb +11 -7
  25. data/lib/regexp_parser/expression/methods/negative.rb +20 -0
  26. data/lib/regexp_parser/expression/methods/parts.rb +23 -0
  27. data/lib/regexp_parser/expression/methods/printing.rb +26 -0
  28. data/lib/regexp_parser/expression/methods/strfregexp.rb +1 -1
  29. data/lib/regexp_parser/expression/methods/tests.rb +47 -1
  30. data/lib/regexp_parser/expression/methods/traverse.rb +34 -18
  31. data/lib/regexp_parser/expression/quantifier.rb +57 -17
  32. data/lib/regexp_parser/expression/sequence.rb +11 -47
  33. data/lib/regexp_parser/expression/sequence_operation.rb +4 -9
  34. data/lib/regexp_parser/expression/shared.rb +111 -0
  35. data/lib/regexp_parser/expression/subexpression.rb +27 -19
  36. data/lib/regexp_parser/expression.rb +15 -141
  37. data/lib/regexp_parser/lexer.rb +83 -41
  38. data/lib/regexp_parser/parser.rb +372 -429
  39. data/lib/regexp_parser/scanner/char_type.rl +11 -11
  40. data/lib/regexp_parser/scanner/errors/premature_end_error.rb +8 -0
  41. data/lib/regexp_parser/scanner/errors/scanner_error.rb +6 -0
  42. data/lib/regexp_parser/scanner/errors/validation_error.rb +63 -0
  43. data/lib/regexp_parser/scanner/properties/long.csv +651 -0
  44. data/lib/regexp_parser/scanner/properties/short.csv +249 -0
  45. data/lib/regexp_parser/scanner/property.rl +4 -4
  46. data/lib/regexp_parser/scanner/scanner.rl +303 -368
  47. data/lib/regexp_parser/scanner.rb +1423 -1674
  48. data/lib/regexp_parser/syntax/any.rb +2 -7
  49. data/lib/regexp_parser/syntax/base.rb +92 -67
  50. data/lib/regexp_parser/syntax/token/anchor.rb +15 -0
  51. data/lib/regexp_parser/syntax/{tokens → token}/assertion.rb +2 -2
  52. data/lib/regexp_parser/syntax/token/backreference.rb +33 -0
  53. data/lib/regexp_parser/syntax/token/character_set.rb +16 -0
  54. data/lib/regexp_parser/syntax/{tokens → token}/character_type.rb +3 -3
  55. data/lib/regexp_parser/syntax/{tokens → token}/conditional.rb +3 -3
  56. data/lib/regexp_parser/syntax/token/escape.rb +33 -0
  57. data/lib/regexp_parser/syntax/{tokens → token}/group.rb +7 -7
  58. data/lib/regexp_parser/syntax/{tokens → token}/keep.rb +1 -1
  59. data/lib/regexp_parser/syntax/token/meta.rb +20 -0
  60. data/lib/regexp_parser/syntax/{tokens → token}/posix_class.rb +3 -3
  61. data/lib/regexp_parser/syntax/token/quantifier.rb +35 -0
  62. data/lib/regexp_parser/syntax/token/unicode_property.rb +751 -0
  63. data/lib/regexp_parser/syntax/token/virtual.rb +11 -0
  64. data/lib/regexp_parser/syntax/token.rb +45 -0
  65. data/lib/regexp_parser/syntax/version_lookup.rb +19 -36
  66. data/lib/regexp_parser/syntax/versions/1.8.6.rb +13 -20
  67. data/lib/regexp_parser/syntax/versions/1.9.1.rb +10 -17
  68. data/lib/regexp_parser/syntax/versions/1.9.3.rb +3 -10
  69. data/lib/regexp_parser/syntax/versions/2.0.0.rb +8 -15
  70. data/lib/regexp_parser/syntax/versions/2.2.0.rb +3 -9
  71. data/lib/regexp_parser/syntax/versions/2.3.0.rb +3 -9
  72. data/lib/regexp_parser/syntax/versions/2.4.0.rb +3 -9
  73. data/lib/regexp_parser/syntax/versions/2.4.1.rb +2 -8
  74. data/lib/regexp_parser/syntax/versions/2.5.0.rb +3 -9
  75. data/lib/regexp_parser/syntax/versions/2.6.0.rb +3 -9
  76. data/lib/regexp_parser/syntax/versions/2.6.2.rb +3 -9
  77. data/lib/regexp_parser/syntax/versions/2.6.3.rb +3 -9
  78. data/lib/regexp_parser/syntax/versions/3.1.0.rb +4 -0
  79. data/lib/regexp_parser/syntax/versions/3.2.0.rb +4 -0
  80. data/lib/regexp_parser/syntax/versions.rb +3 -1
  81. data/lib/regexp_parser/syntax.rb +8 -6
  82. data/lib/regexp_parser/token.rb +9 -20
  83. data/lib/regexp_parser/version.rb +1 -1
  84. data/lib/regexp_parser.rb +0 -2
  85. data/regexp_parser.gemspec +19 -23
  86. metadata +53 -171
  87. data/CHANGELOG.md +0 -349
  88. data/README.md +0 -470
  89. data/lib/regexp_parser/scanner/properties/long.yml +0 -594
  90. data/lib/regexp_parser/scanner/properties/short.yml +0 -237
  91. data/lib/regexp_parser/syntax/tokens/anchor.rb +0 -15
  92. data/lib/regexp_parser/syntax/tokens/backref.rb +0 -24
  93. data/lib/regexp_parser/syntax/tokens/character_set.rb +0 -13
  94. data/lib/regexp_parser/syntax/tokens/escape.rb +0 -30
  95. data/lib/regexp_parser/syntax/tokens/meta.rb +0 -13
  96. data/lib/regexp_parser/syntax/tokens/quantifier.rb +0 -35
  97. data/lib/regexp_parser/syntax/tokens/unicode_property.rb +0 -675
  98. data/lib/regexp_parser/syntax/tokens.rb +0 -45
  99. data/spec/expression/base_spec.rb +0 -94
  100. data/spec/expression/clone_spec.rb +0 -120
  101. data/spec/expression/conditional_spec.rb +0 -89
  102. data/spec/expression/free_space_spec.rb +0 -27
  103. data/spec/expression/methods/match_length_spec.rb +0 -161
  104. data/spec/expression/methods/match_spec.rb +0 -25
  105. data/spec/expression/methods/strfregexp_spec.rb +0 -224
  106. data/spec/expression/methods/tests_spec.rb +0 -99
  107. data/spec/expression/methods/traverse_spec.rb +0 -161
  108. data/spec/expression/options_spec.rb +0 -128
  109. data/spec/expression/root_spec.rb +0 -9
  110. data/spec/expression/sequence_spec.rb +0 -9
  111. data/spec/expression/subexpression_spec.rb +0 -50
  112. data/spec/expression/to_h_spec.rb +0 -26
  113. data/spec/expression/to_s_spec.rb +0 -100
  114. data/spec/lexer/all_spec.rb +0 -22
  115. data/spec/lexer/conditionals_spec.rb +0 -53
  116. data/spec/lexer/escapes_spec.rb +0 -14
  117. data/spec/lexer/keep_spec.rb +0 -10
  118. data/spec/lexer/literals_spec.rb +0 -89
  119. data/spec/lexer/nesting_spec.rb +0 -99
  120. data/spec/lexer/refcalls_spec.rb +0 -55
  121. data/spec/parser/all_spec.rb +0 -43
  122. data/spec/parser/alternation_spec.rb +0 -88
  123. data/spec/parser/anchors_spec.rb +0 -17
  124. data/spec/parser/conditionals_spec.rb +0 -179
  125. data/spec/parser/errors_spec.rb +0 -30
  126. data/spec/parser/escapes_spec.rb +0 -121
  127. data/spec/parser/free_space_spec.rb +0 -130
  128. data/spec/parser/groups_spec.rb +0 -108
  129. data/spec/parser/keep_spec.rb +0 -6
  130. data/spec/parser/posix_classes_spec.rb +0 -8
  131. data/spec/parser/properties_spec.rb +0 -115
  132. data/spec/parser/quantifiers_spec.rb +0 -51
  133. data/spec/parser/refcalls_spec.rb +0 -112
  134. data/spec/parser/set/intersections_spec.rb +0 -127
  135. data/spec/parser/set/ranges_spec.rb +0 -111
  136. data/spec/parser/sets_spec.rb +0 -178
  137. data/spec/parser/types_spec.rb +0 -18
  138. data/spec/scanner/all_spec.rb +0 -18
  139. data/spec/scanner/anchors_spec.rb +0 -21
  140. data/spec/scanner/conditionals_spec.rb +0 -128
  141. data/spec/scanner/errors_spec.rb +0 -68
  142. data/spec/scanner/escapes_spec.rb +0 -53
  143. data/spec/scanner/free_space_spec.rb +0 -133
  144. data/spec/scanner/groups_spec.rb +0 -52
  145. data/spec/scanner/keep_spec.rb +0 -10
  146. data/spec/scanner/literals_spec.rb +0 -49
  147. data/spec/scanner/meta_spec.rb +0 -18
  148. data/spec/scanner/properties_spec.rb +0 -64
  149. data/spec/scanner/quantifiers_spec.rb +0 -20
  150. data/spec/scanner/refcalls_spec.rb +0 -36
  151. data/spec/scanner/sets_spec.rb +0 -102
  152. data/spec/scanner/types_spec.rb +0 -14
  153. data/spec/spec_helper.rb +0 -15
  154. data/spec/support/runner.rb +0 -42
  155. data/spec/support/shared_examples.rb +0 -77
  156. data/spec/support/warning_extractor.rb +0 -60
  157. data/spec/syntax/syntax_spec.rb +0 -48
  158. data/spec/syntax/syntax_token_map_spec.rb +0 -23
  159. data/spec/syntax/versions/1.8.6_spec.rb +0 -17
  160. data/spec/syntax/versions/1.9.1_spec.rb +0 -10
  161. data/spec/syntax/versions/1.9.3_spec.rb +0 -9
  162. data/spec/syntax/versions/2.0.0_spec.rb +0 -13
  163. data/spec/syntax/versions/2.2.0_spec.rb +0 -9
  164. data/spec/syntax/versions/aliases_spec.rb +0 -37
  165. data/spec/token/token_spec.rb +0 -85
  166. /data/lib/regexp_parser/expression/classes/{set → character_set}/intersection.rb +0 -0
@@ -0,0 +1,11 @@
1
+ module Regexp::Syntax
2
+ module Token
3
+ module Virtual
4
+ Root = %i[root]
5
+ Sequence = %i[sequence]
6
+
7
+ All = %i[root sequence]
8
+ Type = :expression
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,45 @@
1
+ # Define the base module and the simplest of tokens.
2
+ module Regexp::Syntax
3
+ module Token
4
+ Map = {}
5
+
6
+ module Literal
7
+ All = %i[literal]
8
+ Type = :literal
9
+ end
10
+
11
+ module FreeSpace
12
+ All = %i[comment whitespace]
13
+ Type = :free_space
14
+ end
15
+
16
+ Map[FreeSpace::Type] = FreeSpace::All
17
+ Map[Literal::Type] = Literal::All
18
+ end
19
+ end
20
+
21
+
22
+ # Load all the token files, they will populate the Map constant.
23
+ require 'regexp_parser/syntax/token/anchor'
24
+ require 'regexp_parser/syntax/token/assertion'
25
+ require 'regexp_parser/syntax/token/backreference'
26
+ require 'regexp_parser/syntax/token/posix_class'
27
+ require 'regexp_parser/syntax/token/character_set'
28
+ require 'regexp_parser/syntax/token/character_type'
29
+ require 'regexp_parser/syntax/token/conditional'
30
+ require 'regexp_parser/syntax/token/escape'
31
+ require 'regexp_parser/syntax/token/group'
32
+ require 'regexp_parser/syntax/token/keep'
33
+ require 'regexp_parser/syntax/token/meta'
34
+ require 'regexp_parser/syntax/token/quantifier'
35
+ require 'regexp_parser/syntax/token/unicode_property'
36
+
37
+
38
+ # After loading all the tokens the map is full. Extract all tokens and types
39
+ # into the All and Types constants.
40
+ module Regexp::Syntax
41
+ module Token
42
+ All = Map.values.flatten.uniq.sort.freeze
43
+ Types = Map.keys.freeze
44
+ end
45
+ 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
@@ -17,29 +17,30 @@ module Regexp::Syntax
17
17
 
18
18
  module_function
19
19
 
20
- # Loads and instantiates an instance of the syntax specification class for
21
- # the given syntax version name. The special names 'any' and '*' return an
22
- # instance of Syntax::Any.
20
+ # Returns the syntax specification class for the given syntax
21
+ # version name. The special names 'any' and '*' return Syntax::Any.
22
+ def for(name)
23
+ (@alias_map ||= {})[name] ||= version_class(name)
24
+ end
25
+
23
26
  def new(name)
24
- return Regexp::Syntax::Any.new if ['*', 'any'].include?(name.to_s)
25
- version_class(name).new
27
+ warn 'Regexp::Syntax.new is deprecated in favor of Regexp::Syntax.for. '\
28
+ 'It does not return distinct instances and will be removed in v3.0.0.'
29
+ self.for(name)
26
30
  end
27
31
 
28
32
  def supported?(name)
29
- name =~ VERSION_REGEXP &&
30
- comparable_version(name) >= comparable_version('1.8.6')
33
+ name =~ VERSION_REGEXP && comparable(name) >= comparable('1.8.6')
31
34
  end
32
35
 
33
36
  def version_class(version)
37
+ return Regexp::Syntax::Any if ['*', 'any'].include?(version.to_s)
38
+
34
39
  version =~ VERSION_REGEXP || raise(InvalidVersionNameError, version)
35
- version_const_name = version_const_name(version)
40
+ version_const_name = "V#{version.to_s.scan(/\d+/).join('_')}"
36
41
  const_get(version_const_name) || raise(UnknownSyntaxNameError, version)
37
42
  end
38
43
 
39
- def version_const_name(version_string)
40
- "V#{version_string.to_s.scan(/\d+/).join('_')}"
41
- end
42
-
43
44
  def const_missing(const_name)
44
45
  if const_name =~ VERSION_CONST_REGEXP
45
46
  return fallback_version_class(const_name)
@@ -48,35 +49,17 @@ module Regexp::Syntax
48
49
  end
49
50
 
50
51
  def fallback_version_class(version)
51
- sorted_versions = (specified_versions + [version])
52
- .sort_by { |name| comparable_version(name) }
53
- return if (version_index = sorted_versions.index(version)) < 1
54
-
55
- next_lower_version = sorted_versions[version_index - 1]
56
- inherit_from_version(next_lower_version, version)
57
- end
58
-
59
- def inherit_from_version(parent_version, new_version)
60
- new_const = version_const_name(new_version)
61
- parent = const_get(version_const_name(parent_version))
62
- const_defined?(new_const) || const_set(new_const, Class.new(parent))
63
- warn_if_future_version(new_const)
64
- const_get(new_const)
52
+ sorted = (specified_versions + [version]).sort_by { |ver| comparable(ver) }
53
+ index = sorted.index(version)
54
+ index > 0 && const_get(sorted[index - 1])
65
55
  end
66
56
 
67
57
  def specified_versions
68
58
  constants.select { |const_name| const_name =~ VERSION_CONST_REGEXP }
69
59
  end
70
60
 
71
- def comparable_version(name)
61
+ def comparable(name)
72
62
  # add .99 to treat versions without a patch value as latest patch version
73
63
  Gem::Version.new((name.to_s.scan(/\d+/) << 99).join('.'))
74
64
  end
75
-
76
- def warn_if_future_version(const_name)
77
- return if comparable_version(const_name) < comparable_version('3.0.0')
78
-
79
- warn('This library has only been tested up to Ruby 2.x, '\
80
- "but you are running with #{const_get(const_name).inspect}")
81
- end
82
65
  end
@@ -1,21 +1,14 @@
1
- module Regexp::Syntax
2
- class V1_8_6 < Regexp::Syntax::Base
3
- def initialize
4
- super
5
-
6
- implements :anchor, Anchor::All
7
- implements :assertion, Assertion::Lookahead
8
- implements :backref, [:number]
9
- implements :posixclass, PosixClass::Standard
10
- implements :group, Group::All
11
- implements :meta, Meta::Extended
12
- implements :set, CharacterSet::All
13
- implements :type, CharacterType::Extended
14
- implements :escape,
15
- Escape::Basic + Escape::ASCII + Escape::Meta + Escape::Control
16
- implements :quantifier,
17
- Quantifier::Greedy + Quantifier::Reluctant +
18
- Quantifier::Interval + Quantifier::IntervalReluctant
19
- end
20
- end
1
+ class Regexp::Syntax::V1_8_6 < Regexp::Syntax::Base
2
+ implements :anchor, Anchor::All
3
+ implements :assertion, Assertion::Lookahead
4
+ implements :backref, Backreference::V1_8_6
5
+ implements :escape, Escape::Basic + Escape::ASCII + Escape::Meta + Escape::Control
6
+ implements :free_space, FreeSpace::All
7
+ implements :group, Group::V1_8_6
8
+ implements :literal, Literal::All
9
+ implements :meta, Meta::Extended
10
+ implements :posixclass, PosixClass::Standard
11
+ implements :quantifier, Quantifier::V1_8_6
12
+ implements :set, CharacterSet::All
13
+ implements :type, CharacterType::Extended
21
14
  end
@@ -1,18 +1,11 @@
1
- module Regexp::Syntax
2
- class V1_9_1 < Regexp::Syntax::V1_8_6
3
- def initialize
4
- super
5
-
6
- implements :assertion, Assertion::Lookbehind
7
- implements :backref, Backreference::All + SubexpressionCall::All
8
- implements :posixclass, PosixClass::Extensions
9
- implements :nonposixclass, PosixClass::All
10
- implements :escape, Escape::Unicode + Escape::Hex + Escape::Octal
11
- implements :type, CharacterType::Hex
12
- implements :property, UnicodeProperty::V1_9_0
13
- implements :nonproperty, UnicodeProperty::V1_9_0
14
- implements :quantifier,
15
- Quantifier::Possessive + Quantifier::IntervalPossessive
16
- end
17
- end
1
+ class Regexp::Syntax::V1_9_1 < Regexp::Syntax::V1_8_6
2
+ implements :assertion, Assertion::Lookbehind
3
+ implements :backref, Backreference::V1_9_1 + SubexpressionCall::All
4
+ implements :escape, Escape::Unicode + Escape::Hex + Escape::Octal
5
+ implements :posixclass, PosixClass::Extensions
6
+ implements :nonposixclass, PosixClass::All
7
+ implements :property, UnicodeProperty::V1_9_0
8
+ implements :nonproperty, UnicodeProperty::V1_9_0
9
+ implements :quantifier, Quantifier::Possessive + Quantifier::IntervalPossessive
10
+ implements :type, CharacterType::Hex
18
11
  end
@@ -1,11 +1,4 @@
1
- module Regexp::Syntax
2
- class V1_9_3 < Regexp::Syntax::V1_9_1
3
- def initialize
4
- super
5
-
6
- # these were added with update of Oniguruma to Unicode 6.0
7
- implements :property, UnicodeProperty::V1_9_3
8
- implements :nonproperty, UnicodeProperty::V1_9_3
9
- end
10
- end
1
+ class Regexp::Syntax::V1_9_3 < Regexp::Syntax::V1_9_1
2
+ implements :property, UnicodeProperty::V1_9_3
3
+ implements :nonproperty, UnicodeProperty::V1_9_3
11
4
  end
@@ -1,17 +1,10 @@
1
- module Regexp::Syntax
2
- # use the last 1.9 release as the base
3
- class V2_0_0 < Regexp::Syntax::V1_9
4
- def initialize
5
- super
1
+ class Regexp::Syntax::V2_0_0 < Regexp::Syntax::V1_9_3
2
+ implements :keep, Keep::All
3
+ implements :conditional, Conditional::All
4
+ implements :property, UnicodeProperty::V2_0_0
5
+ implements :nonproperty, UnicodeProperty::V2_0_0
6
+ implements :type, CharacterType::Clustered
6
7
 
7
- implements :keep, Keep::All
8
- implements :conditional, Conditional::All
9
- implements :property, UnicodeProperty::V2_0_0
10
- implements :nonproperty, UnicodeProperty::V2_0_0
11
- implements :type, CharacterType::Clustered
12
-
13
- excludes :property, :newline
14
- excludes :nonproperty, :newline
15
- end
16
- end
8
+ excludes :property, %i[newline]
9
+ excludes :nonproperty, %i[newline]
17
10
  end
@@ -1,10 +1,4 @@
1
- module Regexp::Syntax
2
- class V2_2_0 < Regexp::Syntax::V2_1
3
- def initialize
4
- super
5
-
6
- implements :property, UnicodeProperty::V2_2_0
7
- implements :nonproperty, UnicodeProperty::V2_2_0
8
- end
9
- end
1
+ class Regexp::Syntax::V2_2_0 < Regexp::Syntax::V2_0_0
2
+ implements :property, UnicodeProperty::V2_2_0
3
+ implements :nonproperty, UnicodeProperty::V2_2_0
10
4
  end
@@ -1,10 +1,4 @@
1
- module Regexp::Syntax
2
- class V2_3_0 < Regexp::Syntax::V2_2
3
- def initialize
4
- super
5
-
6
- implements :property, UnicodeProperty::V2_3_0
7
- implements :nonproperty, UnicodeProperty::V2_3_0
8
- end
9
- end
1
+ class Regexp::Syntax::V2_3_0 < Regexp::Syntax::V2_2_0
2
+ implements :property, UnicodeProperty::V2_3_0
3
+ implements :nonproperty, UnicodeProperty::V2_3_0
10
4
  end
@@ -1,10 +1,4 @@
1
- module Regexp::Syntax
2
- class V2_4_0 < Regexp::Syntax::V2_3
3
- def initialize
4
- super
5
-
6
- implements :property, UnicodeProperty::V2_4_0
7
- implements :nonproperty, UnicodeProperty::V2_4_0
8
- end
9
- end
1
+ class Regexp::Syntax::V2_4_0 < Regexp::Syntax::V2_3_0
2
+ implements :property, UnicodeProperty::V2_4_0
3
+ implements :nonproperty, UnicodeProperty::V2_4_0
10
4
  end
@@ -1,9 +1,3 @@
1
- module Regexp::Syntax
2
- class V2_4_1 < Regexp::Syntax::V2_4_0
3
- def initialize
4
- super
5
-
6
- implements :group, Group::V2_4_1
7
- end
8
- end
1
+ class Regexp::Syntax::V2_4_1 < Regexp::Syntax::V2_4_0
2
+ implements :group, Group::V2_4_1
9
3
  end
@@ -1,10 +1,4 @@
1
- module Regexp::Syntax
2
- class V2_5_0 < Regexp::Syntax::V2_4
3
- def initialize
4
- super
5
-
6
- implements :property, UnicodeProperty::V2_5_0
7
- implements :nonproperty, UnicodeProperty::V2_5_0
8
- end
9
- end
1
+ class Regexp::Syntax::V2_5_0 < Regexp::Syntax::V2_4_1
2
+ implements :property, UnicodeProperty::V2_5_0
3
+ implements :nonproperty, UnicodeProperty::V2_5_0
10
4
  end
@@ -1,10 +1,4 @@
1
- module Regexp::Syntax
2
- class V2_6_0 < Regexp::Syntax::V2_5
3
- def initialize
4
- super
5
-
6
- implements :property, UnicodeProperty::V2_6_0
7
- implements :nonproperty, UnicodeProperty::V2_6_0
8
- end
9
- end
1
+ class Regexp::Syntax::V2_6_0 < Regexp::Syntax::V2_5_0
2
+ implements :property, UnicodeProperty::V2_6_0
3
+ implements :nonproperty, UnicodeProperty::V2_6_0
10
4
  end
@@ -1,10 +1,4 @@
1
- module Regexp::Syntax
2
- class V2_6_2 < Regexp::Syntax::V2_6_0
3
- def initialize
4
- super
5
-
6
- implements :property, UnicodeProperty::V2_6_2
7
- implements :nonproperty, UnicodeProperty::V2_6_2
8
- end
9
- end
1
+ class Regexp::Syntax::V2_6_2 < Regexp::Syntax::V2_6_0
2
+ implements :property, UnicodeProperty::V2_6_2
3
+ implements :nonproperty, UnicodeProperty::V2_6_2
10
4
  end
@@ -1,10 +1,4 @@
1
- module Regexp::Syntax
2
- class V2_6_3 < Regexp::Syntax::V2_6_2
3
- def initialize
4
- super
5
-
6
- implements :property, UnicodeProperty::V2_6_3
7
- implements :nonproperty, UnicodeProperty::V2_6_3
8
- end
9
- end
1
+ class Regexp::Syntax::V2_6_3 < Regexp::Syntax::V2_6_2
2
+ implements :property, UnicodeProperty::V2_6_3
3
+ implements :nonproperty, UnicodeProperty::V2_6_3
10
4
  end
@@ -0,0 +1,4 @@
1
+ class Regexp::Syntax::V3_1_0 < Regexp::Syntax::V2_6_3
2
+ implements :property, UnicodeProperty::V3_1_0
3
+ implements :nonproperty, UnicodeProperty::V3_1_0
4
+ end
@@ -0,0 +1,4 @@
1
+ class Regexp::Syntax::V3_2_0 < Regexp::Syntax::V3_1_0
2
+ implements :property, UnicodeProperty::V3_2_0
3
+ implements :nonproperty, UnicodeProperty::V3_2_0
4
+ end
@@ -1,6 +1,8 @@
1
- # Ruby 1.8.x is no longer a supported runtime,
1
+ # Ruby 1.x is no longer a supported runtime,
2
2
  # but its regex features are still recognized.
3
3
  #
4
4
  # Aliases for the latest patch version are provided as 'ruby/n.n',
5
5
  # e.g. 'ruby/1.9' refers to Ruby v1.9.3.
6
6
  Dir[File.expand_path('../versions/*.rb', __FILE__)].sort.each { |f| require f }
7
+
8
+ Regexp::Syntax::CURRENT = Regexp::Syntax.for("ruby/#{RUBY_VERSION}")
@@ -1,9 +1,11 @@
1
- require File.expand_path('../syntax/tokens', __FILE__)
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 < StandardError; end
4
+ class SyntaxError < Regexp::Parser::Error; end
9
5
  end
6
+
7
+ require_relative 'syntax/token'
8
+ require_relative 'syntax/base'
9
+ require_relative 'syntax/any'
10
+ require_relative 'syntax/version_lookup'
11
+ require_relative 'syntax/versions'
@@ -1,14 +1,13 @@
1
1
  class Regexp
2
-
3
- TOKEN_KEYS = [
4
- :type,
5
- :token,
6
- :text,
7
- :ts,
8
- :te,
9
- :level,
10
- :set_level,
11
- :conditional_level
2
+ TOKEN_KEYS = %i[
3
+ type
4
+ token
5
+ text
6
+ ts
7
+ te
8
+ level
9
+ set_level
10
+ conditional_level
12
11
  ].freeze
13
12
 
14
13
  Token = Struct.new(*TOKEN_KEYS) do
@@ -21,15 +20,5 @@ class Regexp
21
20
  def length
22
21
  te - ts
23
22
  end
24
-
25
- if RUBY_VERSION < '2.0.0'
26
- def to_h
27
- members.inject({}) do |hash, member|
28
- hash[member.to_sym] = self[member]
29
- hash
30
- end
31
- end
32
- end
33
23
  end
34
-
35
24
  end
@@ -1,5 +1,5 @@
1
1
  class Regexp
2
2
  class Parser
3
- VERSION = '1.7.0'
3
+ VERSION = '2.9.0'
4
4
  end
5
5
  end
data/lib/regexp_parser.rb CHANGED
@@ -1,5 +1,3 @@
1
- # encoding: utf-8
2
-
3
1
  require 'regexp_parser/version'
4
2
  require 'regexp_parser/token'
5
3
  require 'regexp_parser/scanner'
@@ -2,35 +2,31 @@ $:.unshift File.join(File.dirname(__FILE__), 'lib')
2
2
 
3
3
  require 'regexp_parser/version'
4
4
 
5
- Gem::Specification.new do |gem|
6
- gem.name = 'regexp_parser'
7
- gem.version = ::Regexp::Parser::VERSION
5
+ Gem::Specification.new do |spec|
6
+ spec.name = 'regexp_parser'
7
+ spec.version = ::Regexp::Parser::VERSION
8
8
 
9
- gem.summary = "Scanner, lexer, parser for ruby's regular expressions"
10
- gem.description = 'A library for tokenizing, lexing, and parsing Ruby regular expressions.'
11
- gem.homepage = 'https://github.com/ammar/regexp_parser'
9
+ spec.summary = "Scanner, lexer, parser for ruby's regular expressions"
10
+ spec.description = 'A library for tokenizing, lexing, and parsing Ruby regular expressions.'
11
+ spec.homepage = 'https://github.com/ammar/regexp_parser'
12
12
 
13
- if gem.respond_to?(:metadata)
14
- gem.metadata = { 'issue_tracker' => 'https://github.com/ammar/regexp_parser/issues' }
15
- end
13
+ spec.metadata['bug_tracker_uri'] = "#{spec.homepage}/issues"
14
+ spec.metadata['changelog_uri'] = "#{spec.homepage}/blob/master/CHANGELOG.md"
15
+ spec.metadata['homepage_uri'] = spec.homepage
16
+ spec.metadata['source_code_uri'] = spec.homepage
17
+ spec.metadata['wiki_uri'] = "#{spec.homepage}/wiki"
16
18
 
17
- gem.authors = ['Ammar Ali']
18
- gem.email = ['ammarabuali@gmail.com']
19
+ spec.authors = ['Ammar Ali', 'Janosch Müller']
20
+ spec.email = ['ammarabuali@gmail.com', 'janosch84@gmail.com']
19
21
 
20
- gem.license = 'MIT'
22
+ spec.license = 'MIT'
21
23
 
22
- gem.require_paths = ['lib']
24
+ spec.require_paths = ['lib']
23
25
 
24
- gem.files = Dir.glob('{lib,spec}/**/*.rb') +
25
- Dir.glob('lib/**/*.rl') +
26
- Dir.glob('lib/**/*.yml') +
27
- %w(Gemfile Rakefile LICENSE README.md CHANGELOG.md regexp_parser.gemspec)
26
+ spec.files = Dir.glob('lib/**/*.{csv,rb,rl}') +
27
+ %w[Gemfile Rakefile LICENSE regexp_parser.gemspec]
28
28
 
29
- gem.test_files = Dir.glob('spec/**/*.rb')
29
+ spec.platform = Gem::Platform::RUBY
30
30
 
31
- gem.rdoc_options = ["--inline-source", "--charset=UTF-8"]
32
-
33
- gem.platform = Gem::Platform::RUBY
34
-
35
- gem.required_ruby_version = '>= 1.9.1'
31
+ spec.required_ruby_version = '>= 2.0.0'
36
32
  end