regexp_parser 1.8.0 → 1.8.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 9c8e3ba5269d32f57fdcad4ba98f16bc88b74713106a23f63ba2728fa89cf802
4
- data.tar.gz: bbb1fe8c3f72b750a707a9f6c237c752455b4cd34d2bc8b0f255284fd32d4ed3
3
+ metadata.gz: 047ef5746234f1e25d914d669596a9811f6c5871e3f8c2516434470d561a7c92
4
+ data.tar.gz: b3ec51e10f4331a7c0563ad7ab6f78ead20482baa1eb3c32a0de0d1f769bdcc0
5
5
  SHA512:
6
- metadata.gz: 93f94773ee6cb173771608ecdaf67e9e444e1ba7922cd97b8124a6ec90868e94b484ad6bdd0599d9ae9c2247e2a1627cdb03c620ce85f62d320ba8b1fdbb63bb
7
- data.tar.gz: 9e1927e7c10d182bce099f24964f8c7e88ac76d479d22c632ab09406bc37711c9cc78af53892d46b009d0f12c8c3ffcd2221b2a1b2ca5365b3d3c1797448f3f2
6
+ metadata.gz: e06fee359a02e12a0c142ea1175b96de4d7bbc2af2d9ec83255fa2849e8922bfdf04ad3f26e2b10a1d2f57e87830e864feaa9b444c714de54799b97bda62ce4b
7
+ data.tar.gz: 8de81ed00adc5f760d3770ddf40c200b20d3671b4ee3832d43dcdd0956d7cfe4557bf30a8f7e994bbe82436ab3f8c62038c3088214ddf0907af0c301e2ffd58c
@@ -1,5 +1,15 @@
1
1
  ## [Unreleased]
2
2
 
3
+ ### [1.8.1] - 2020-09-28 - [Janosch Müller](mailto:janosch84@gmail.com)
4
+
5
+ ### Fixed
6
+
7
+ - fixed scanning of comment-like text in normal mode
8
+ * this was an old bug, but had become more prevalent in v1.8.0
9
+ * thanks to [Tietew](https://github.com/Tietew) for the report
10
+ - specified correct minimum Ruby version in gemspec
11
+ * it said 1.9 but really required 2.0 as of v1.8.0
12
+
3
13
  ### [1.8.0] - 2020-09-20 - [Janosch Müller](mailto:janosch84@gmail.com)
4
14
 
5
15
  ### Changed
@@ -2,7 +2,7 @@
2
2
 
3
3
  # line 1 "/Users/jannoschmuller/code/regexp_parser/lib/regexp_parser/scanner/scanner.rl"
4
4
 
5
- # line 676 "/Users/jannoschmuller/code/regexp_parser/lib/regexp_parser/scanner/scanner.rl"
5
+ # line 678 "/Users/jannoschmuller/code/regexp_parser/lib/regexp_parser/scanner/scanner.rl"
6
6
 
7
7
 
8
8
  # THIS IS A GENERATED FILE, DO NOT EDIT DIRECTLY
@@ -1131,7 +1131,7 @@ end
1131
1131
  self.re_scanner_en_main = 110;
1132
1132
 
1133
1133
 
1134
- # line 763 "/Users/jannoschmuller/code/regexp_parser/lib/regexp_parser/scanner/scanner.rl"
1134
+ # line 765 "/Users/jannoschmuller/code/regexp_parser/lib/regexp_parser/scanner/scanner.rl"
1135
1135
 
1136
1136
  # line 1136 "/Users/jannoschmuller/code/regexp_parser/lib/regexp_parser/scanner.rb"
1137
1137
  begin
@@ -1144,7 +1144,7 @@ begin
1144
1144
  act = 0
1145
1145
  end
1146
1146
 
1147
- # line 764 "/Users/jannoschmuller/code/regexp_parser/lib/regexp_parser/scanner/scanner.rl"
1147
+ # line 766 "/Users/jannoschmuller/code/regexp_parser/lib/regexp_parser/scanner/scanner.rl"
1148
1148
 
1149
1149
  # line 1149 "/Users/jannoschmuller/code/regexp_parser/lib/regexp_parser/scanner.rb"
1150
1150
  begin
@@ -2035,7 +2035,10 @@ te = p+1
2035
2035
  if free_spacing
2036
2036
  emit(:free_space, :comment, *text(data, ts, te))
2037
2037
  else
2038
- append_literal(data, ts, te)
2038
+ # consume only the pound sign (#) and backtrack to do regular scanning
2039
+ append_literal(data, ts, ts + 1)
2040
+ begin p = (( ts + 1))-1; end
2041
+
2039
2042
  end
2040
2043
  end
2041
2044
  end
@@ -2135,12 +2138,15 @@ p = p - 1; begin
2135
2138
  if free_spacing
2136
2139
  emit(:free_space, :comment, *text(data, ts, te))
2137
2140
  else
2138
- append_literal(data, ts, te)
2141
+ # consume only the pound sign (#) and backtrack to do regular scanning
2142
+ append_literal(data, ts, ts + 1)
2143
+ begin p = (( ts + 1))-1; end
2144
+
2139
2145
  end
2140
2146
  end
2141
2147
  end
2142
2148
  when 43 then
2143
- # line 656 "/Users/jannoschmuller/code/regexp_parser/lib/regexp_parser/scanner/scanner.rl"
2149
+ # line 658 "/Users/jannoschmuller/code/regexp_parser/lib/regexp_parser/scanner/scanner.rl"
2144
2150
  begin
2145
2151
  te = p
2146
2152
  p = p - 1; begin
@@ -2152,7 +2158,7 @@ p = p - 1; begin
2152
2158
  end
2153
2159
  end
2154
2160
  when 42 then
2155
- # line 671 "/Users/jannoschmuller/code/regexp_parser/lib/regexp_parser/scanner/scanner.rl"
2161
+ # line 673 "/Users/jannoschmuller/code/regexp_parser/lib/regexp_parser/scanner/scanner.rl"
2156
2162
  begin
2157
2163
  te = p
2158
2164
  p = p - 1; begin
@@ -2559,7 +2565,7 @@ act = 19; end
2559
2565
  begin
2560
2566
  te = p+1
2561
2567
  end
2562
- # line 671 "/Users/jannoschmuller/code/regexp_parser/lib/regexp_parser/scanner/scanner.rl"
2568
+ # line 673 "/Users/jannoschmuller/code/regexp_parser/lib/regexp_parser/scanner/scanner.rl"
2563
2569
  begin
2564
2570
  act = 56; end
2565
2571
  when 47 then
@@ -2573,7 +2579,7 @@ te = p+1
2573
2579
  # line 149 "/Users/jannoschmuller/code/regexp_parser/lib/regexp_parser/scanner/scanner.rl"
2574
2580
  begin
2575
2581
  self.group_depth = group_depth + 1 end
2576
- # line 2576 "/Users/jannoschmuller/code/regexp_parser/lib/regexp_parser/scanner.rb"
2582
+ # line 2582 "/Users/jannoschmuller/code/regexp_parser/lib/regexp_parser/scanner.rb"
2577
2583
  end
2578
2584
  end
2579
2585
  end
@@ -2591,7 +2597,7 @@ ts = nil; end
2591
2597
  begin
2592
2598
  act = 0
2593
2599
  end
2594
- # line 2594 "/Users/jannoschmuller/code/regexp_parser/lib/regexp_parser/scanner.rb"
2600
+ # line 2600 "/Users/jannoschmuller/code/regexp_parser/lib/regexp_parser/scanner.rb"
2595
2601
  end
2596
2602
 
2597
2603
  if cs == 0
@@ -2625,7 +2631,7 @@ act = 0
2625
2631
  text = ts ? copy(data, ts-1..-1) : data.pack('c*')
2626
2632
  raise PrematureEndError.new( text )
2627
2633
  end
2628
- # line 2628 "/Users/jannoschmuller/code/regexp_parser/lib/regexp_parser/scanner.rb"
2634
+ # line 2634 "/Users/jannoschmuller/code/regexp_parser/lib/regexp_parser/scanner.rb"
2629
2635
  end
2630
2636
  end
2631
2637
 
@@ -2636,7 +2642,7 @@ act = 0
2636
2642
  end
2637
2643
  end
2638
2644
 
2639
- # line 765 "/Users/jannoschmuller/code/regexp_parser/lib/regexp_parser/scanner/scanner.rl"
2645
+ # line 767 "/Users/jannoschmuller/code/regexp_parser/lib/regexp_parser/scanner/scanner.rl"
2640
2646
 
2641
2647
  # to avoid "warning: assigned but unused variable - testEof"
2642
2648
  testEof = testEof
@@ -649,7 +649,9 @@
649
649
  if free_spacing
650
650
  emit(:free_space, :comment, *text(data, ts, te))
651
651
  else
652
- append_literal(data, ts, te)
652
+ # consume only the pound sign (#) and backtrack to do regular scanning
653
+ append_literal(data, ts, ts + 1)
654
+ fexec ts + 1;
653
655
  end
654
656
  };
655
657
 
@@ -1,5 +1,5 @@
1
1
  class Regexp
2
2
  class Parser
3
- VERSION = '1.8.0'
3
+ VERSION = '1.8.1'
4
4
  end
5
5
  end
@@ -32,5 +32,5 @@ Gem::Specification.new do |gem|
32
32
 
33
33
  gem.platform = Gem::Platform::RUBY
34
34
 
35
- gem.required_ruby_version = '>= 1.9.1'
35
+ gem.required_ruby_version = '>= 2.0.0'
36
36
  end
@@ -24,34 +24,13 @@ RSpec.describe('FreeSpace parsing') do
24
24
  expect(root.first.text).to eq 'a b c d'
25
25
  end
26
26
 
27
- specify('parse single-line free space comments without spaces') do
28
- regexp = /a#b/x
29
-
30
- root = RP.parse(regexp)
31
- expect(root.length).to eq 2
32
-
33
- expect(root[0]).to be_instance_of(Literal)
34
- expect(root[1]).to be_instance_of(Comment)
35
- end
36
-
37
- specify('parse single-line free space comments with spaces') do
38
- regexp = /a # b/x
39
-
40
- root = RP.parse(regexp)
41
- expect(root.length).to eq 3
42
-
43
- expect(root[0]).to be_instance_of(Literal)
44
- expect(root[1]).to be_instance_of(WhiteSpace)
45
- expect(root[2]).to be_instance_of(Comment)
46
- end
47
-
48
27
  specify('parse free space comments') do
49
28
  regexp = /
50
29
  a ? # One letter
51
30
  b {2,5} # Another one
52
31
  [c-g] + # A set
53
32
  (h|i|j) | # A group
54
- klm#nospace before or after comment hash
33
+ klm *
55
34
  nop +
56
35
  /x
57
36
 
@@ -72,11 +51,11 @@ RSpec.describe('FreeSpace parsing') do
72
51
 
73
52
  alt_2 = alt.alternatives.last
74
53
  expect(alt_2).to be_instance_of(Alternative)
75
- expect(alt_2.length).to eq 8
54
+ expect(alt_2.length).to eq 7
76
55
 
77
- [0, 2, 5, 7].each { |i| expect(alt_2[i].class).to eq WhiteSpace }
56
+ [0, 2, 4, 6].each { |i| expect(alt_2[i].class).to eq WhiteSpace }
78
57
 
79
- [1, 4].each { |i| expect(alt_2[i]).to be_instance_of(Comment) }
58
+ expect(alt_2[1]).to be_instance_of(Comment)
80
59
  end
81
60
 
82
61
  specify('parse free space nested comments') do
@@ -39,6 +39,17 @@ RSpec.describe('FreeSpace scanning') do
39
39
  11 => [:free_space, :comment, "# B ? comment\n", 37, 51],
40
40
  17 => [:free_space, :comment, "# C {2,3} comment\n", 66, 84],
41
41
  29 => [:free_space, :comment, "# D|E comment\n", 100, 114]
42
+
43
+ # single line / no trailing newline (c.f. issue #66)
44
+ include_examples 'scan', /a # b/x,
45
+ 0 => [:literal, :literal, 'a', 0, 1],
46
+ 1 => [:free_space, :whitespace, ' ', 1, 2],
47
+ 2 => [:free_space, :comment, "# b", 2, 5]
48
+
49
+ # without spaces (c.f. issue #66)
50
+ include_examples 'scan', /a#b/x,
51
+ 0 => [:literal, :literal, 'a', 0, 1],
52
+ 1 => [:free_space, :comment, "#b", 1, 3]
42
53
  end
43
54
 
44
55
  describe('scan free space inlined') do
@@ -130,4 +141,25 @@ RSpec.describe('FreeSpace scanning') do
130
141
  26 => [:literal, :literal, 'i j', 35, 38],
131
142
  27 => [:group, :close, ')', 38, 39]
132
143
  end
144
+
145
+ describe('scanning `#` in regular (non-x mode)') do # c.f. issue 70
146
+ include_examples 'scan', /a#bcd/,
147
+ 0 => [:literal, :literal, 'a#bcd', 0, 5]
148
+ include_examples 'scan', /a # bcd/,
149
+ 0 => [:literal, :literal, 'a # bcd', 0, 7]
150
+
151
+ include_examples 'scan', /a#\d/,
152
+ 0 => [:literal, :literal, 'a#', 0, 2],
153
+ 1 => [:type, :digit, '\d', 2, 4]
154
+ include_examples 'scan', /a # \d/,
155
+ 0 => [:literal, :literal, 'a # ', 0, 4],
156
+ 1 => [:type, :digit, '\d', 4, 6]
157
+
158
+ include_examples 'scan', /a#()/,
159
+ 0 => [:literal, :literal, 'a#', 0, 2],
160
+ 1 => [:group, :capture, '(', 2, 3]
161
+ include_examples 'scan', /a # ()/,
162
+ 0 => [:literal, :literal, 'a # ', 0, 4],
163
+ 1 => [:group, :capture, '(', 4, 5]
164
+ end
133
165
  end
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: 1.8.0
4
+ version: 1.8.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ammar Ali
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-09-20 00:00:00.000000000 Z
11
+ date: 2020-09-28 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: A library for tokenizing, lexing, and parsing Ruby regular expressions.
14
14
  email:
@@ -178,7 +178,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
178
178
  requirements:
179
179
  - - ">="
180
180
  - !ruby/object:Gem::Version
181
- version: 1.9.1
181
+ version: 2.0.0
182
182
  required_rubygems_version: !ruby/object:Gem::Requirement
183
183
  requirements:
184
184
  - - ">="