regexp_parser 0.4.3 → 0.4.4

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.
@@ -82,6 +82,7 @@
82
82
 
83
83
  group_atomic = '?>';
84
84
  group_passive = '?:';
85
+ group_absence = '?~';
85
86
 
86
87
  assertion_lookahead = '?=';
87
88
  assertion_nlookahead = '?!';
@@ -107,7 +108,7 @@
107
108
  group_number_ref = group_ref . (('<' . group_number . group_level? '>') |
108
109
  ("'" . group_number . group_level? "'"));
109
110
 
110
- group_type = group_atomic | group_passive | group_named;
111
+ group_type = group_atomic | group_passive | group_absence | group_named;
111
112
 
112
113
 
113
114
  assertion_type = assertion_lookahead | assertion_nlookahead |
@@ -573,6 +574,7 @@
573
574
  # Groups
574
575
  # (?:subexp) passive (non-captured) group
575
576
  # (?>subexp) atomic group, don't backtrack in subexp.
577
+ # (?~subexp) absence group, matches anything that is not subexp
576
578
  # (?<name>subexp) named group
577
579
  # (?'name'subexp) named group (single quoted version)
578
580
  # (subexp) captured group
@@ -581,6 +583,7 @@
581
583
  case text = text(data, ts, te).first
582
584
  when '(?:'; emit(:group, :passive, text, ts, te)
583
585
  when '(?>'; emit(:group, :atomic, text, ts, te)
586
+ when '(?~'; emit(:group, :absence, text, ts, te)
584
587
 
585
588
  when /^\(\?<(\w*)>/
586
589
  empty_name_error(:group, 'named group (ab)') if $1.empty?
@@ -0,0 +1,13 @@
1
+ require File.expand_path('../2.3.3', __FILE__)
2
+
3
+ module Regexp::Syntax
4
+ module Ruby
5
+
6
+ class V234 < Regexp::Syntax::Ruby::V233
7
+ def initialize
8
+ super
9
+ end
10
+ end
11
+
12
+ end
13
+ end
@@ -1,8 +1,8 @@
1
- require File.expand_path('../2.3.3', __FILE__)
1
+ require File.expand_path('../2.3.4', __FILE__)
2
2
 
3
3
  module Regexp::Syntax
4
4
  module Ruby
5
5
  # uses the latest 2.3 release
6
- class V23 < Regexp::Syntax::Ruby::V233; end
6
+ class V23 < Regexp::Syntax::Ruby::V234; end
7
7
  end
8
8
  end
@@ -6,6 +6,8 @@ module Regexp::Syntax
6
6
  class V241 < Regexp::Syntax::Ruby::V240
7
7
  def initialize
8
8
  super
9
+
10
+ implements :group, Group::Absence
9
11
  end
10
12
  end
11
13
 
@@ -13,6 +13,8 @@ module Regexp::Syntax
13
13
  All = Group::Extended + Group::Named + Group::Atomic +
14
14
  Group::Passive + Group::Comment
15
15
 
16
+ Absence = [:absence]
17
+
16
18
  Type = :group
17
19
  end
18
20
 
@@ -55,6 +55,7 @@ module Regexp::Syntax
55
55
  'ruby/2.3.1',
56
56
  'ruby/2.3.2',
57
57
  'ruby/2.3.3',
58
+ 'ruby/2.3.4',
58
59
 
59
60
  # alias for the latest 2.3 implementation
60
61
  'ruby/2.3',
@@ -1,5 +1,5 @@
1
1
  class Regexp
2
2
  module Parser
3
- VERSION = '0.4.3'
3
+ VERSION = '0.4.4'
4
4
  end
5
5
  end
@@ -106,4 +106,17 @@ class TestParserGroups < Test::Unit::TestCase
106
106
  end
107
107
  end
108
108
 
109
+ if RUBY_VERSION >= '2.4.1'
110
+ def test_parse_absence_group
111
+ t = RP.parse('a(?~b)c(?~d)e')
112
+
113
+ [1,3].each do |i|
114
+ assert t.expressions[i].is_a?(Group::Absence),
115
+ "Expected absence group, but got #{t.expressions[i].class.name}"
116
+
117
+ assert_equal :group, t.expressions[i].type
118
+ assert_equal :absence, t.expressions[i].token
119
+ end
120
+ end
121
+ end
109
122
  end
@@ -55,6 +55,13 @@ class ScannerGroups < Test::Unit::TestCase
55
55
  })
56
56
  end
57
57
 
58
+ if RUBY_VERSION >= '2.4.1'
59
+ tests.merge!({
60
+ # New absence operator
61
+ '(?~abc)' => [0, :group, :absence, '(?~', 0, 3],
62
+ })
63
+ end
64
+
58
65
  tests.each_with_index do |(pattern, (index, type, token, text, ts, te)), count|
59
66
  define_method "test_scanner_#{type}_#{token}_#{count}" do
60
67
  tokens = RS.scan(pattern)
@@ -1,4 +1,5 @@
1
1
  require 'set'
2
+ require 'delegate'
2
3
 
3
4
  module RegexpParserTest
4
5
  class Warning
@@ -212,10 +212,17 @@ class TestSyntaxFiles < Test::Unit::TestCase
212
212
  assert syntax.kind_of?(Regexp::Syntax::Ruby::V233)
213
213
  end
214
214
 
215
+ def test_syntax_file_2_3_4
216
+ syntax = Regexp::Syntax.new 'ruby/2.3.4'
217
+
218
+ assert syntax.kind_of?(Regexp::Syntax::Ruby::V233)
219
+ assert syntax.kind_of?(Regexp::Syntax::Ruby::V234)
220
+ end
221
+
215
222
  def test_syntax_file_2_3_alias
216
223
  syntax = Regexp::Syntax.new 'ruby/2.3'
217
224
 
218
- assert syntax.kind_of?(Regexp::Syntax::Ruby::V233)
225
+ assert syntax.kind_of?(Regexp::Syntax::Ruby::V234)
219
226
  end
220
227
 
221
228
  # 2.4 syntax files
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: 0.4.3
4
+ version: 0.4.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ammar Ali
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-03-24 00:00:00.000000000 Z
11
+ date: 2017-07-10 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: A library for tokenizing, lexing, and parsing Ruby regular expressions.
14
14
  email:
@@ -83,6 +83,7 @@ files:
83
83
  - lib/regexp_parser/syntax/ruby/2.3.1.rb
84
84
  - lib/regexp_parser/syntax/ruby/2.3.2.rb
85
85
  - lib/regexp_parser/syntax/ruby/2.3.3.rb
86
+ - lib/regexp_parser/syntax/ruby/2.3.4.rb
86
87
  - lib/regexp_parser/syntax/ruby/2.3.rb
87
88
  - lib/regexp_parser/syntax/ruby/2.4.0.rb
88
89
  - lib/regexp_parser/syntax/ruby/2.4.1.rb