list_matcher 1.0.2 → 1.0.3

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
  SHA1:
3
- metadata.gz: 7af9157cc2a2c829220e00e56fac87000c3bf5d4
4
- data.tar.gz: d7dee5b5521351a63b7f61a5e30dd61cb69d6071
3
+ metadata.gz: bb59b6999ba70e7b3548710341764da658e460b3
4
+ data.tar.gz: d0781937d67e22497b6c0005497c4e734a39582a
5
5
  SHA512:
6
- metadata.gz: 085ce4508c859a091ea44ca3c5e5a68db8b184ad37abe599723f02492870f533db63a179e3049d326690a274706fd3dc1448189cea1bcd5455894723c0448b19
7
- data.tar.gz: 99c1e1da688674e227234d03098573a48a273f2f46022eae0f254233030b0e8de1f16d9073f47c4c9b0576031c92cf3e5989e3e3181513801b422d890555e54a
6
+ metadata.gz: 5e564cd5377d7018748417535b90f4fcd6347ed129ab8739590a038c8109039e1fd53b8f66ea740331cae0a2dbf48d9d55142c21f6c105106a496ff28e55f5b8
7
+ data.tar.gz: 5357e73c0623e503befdf927d26c11d052105368f7ad12b9325c8e0b9eb192c4430c9e1aee920a6442e58862e94a54040e02cabdd454938b39fa5cecea40688e
data/README.md CHANGED
@@ -116,7 +116,7 @@ List::Matcher.pattern %w( cat dog ), backtracking: false # "(?>cat|dog)"
116
116
  default: false
117
117
  ```
118
118
 
119
- Whether boundary expressions should be attached to the margins of every expression in the list. If this value is simply true, this means
119
+ Whether boundary expressions should be attached to the margins of every expression in the list (but see note below). If this value is simply true, this means
120
120
  each item's marginal characters, the first and the last, are tested to see whether they are word characters and if so the word
121
121
  boundary symbol, `\b`, is appended to them where appropriate. There are several variants on this, however:
122
122
 
@@ -163,6 +163,9 @@ List::Matcher.pattern (1...1000).to_a, bound: { test: /\d/, left: '(?<!\d)', rig
163
163
  # "(?:(?<!\\d)[1-9](?:\\d\\d?)?(?!\\d))"
164
164
  ```
165
165
 
166
+ **NOTE** Because boundary tests cannot be applied to symbols, the bound option will give you strange results if you use it
167
+ with a list any of whose items have a symbol at their leading or trailing margin.
168
+
166
169
  ### strip
167
170
 
168
171
  ```ruby
data/lib/list_matcher.rb CHANGED
@@ -186,14 +186,14 @@ module List
186
186
  end
187
187
  c1 = tree c[0], symbols
188
188
  c2 = tree c[1], symbols
189
- c2.optional = optional
189
+ c2 = c2.optionalize optional
190
190
  Sequence.new self, c1, c2
191
191
  elsif c = best_suffix(list) # found a fixed-width suffix pattern
192
192
  if optional = c[0].include?('')
193
- c[0].reject!{ |w| w == '' }
193
+ c[0].reject!{ |w| w == '' } # TODO make this faster with index
194
194
  end
195
195
  c1 = tree c[0], symbols
196
- c1.optional = optional
196
+ c1 = c1.optionalize optional
197
197
  c2 = tree c[1], symbols
198
198
  Sequence.new self, c1, c2
199
199
  else
@@ -476,6 +476,13 @@ module List
476
476
  engine.quote s
477
477
  end
478
478
 
479
+ def optionalize(bool)
480
+ if bool
481
+ self.optional = bool
482
+ end
483
+ self
484
+ end
485
+
479
486
  end
480
487
 
481
488
  class SpecialPattern < Node
@@ -490,6 +497,10 @@ module List
490
497
  @right = !!word_right
491
498
  end
492
499
 
500
+ def dup
501
+ self.class.new engine, char, var, pat, atomic: atomic?, word_left: left?, word_right: right?
502
+ end
503
+
493
504
  def left?
494
505
  @left
495
506
  end
@@ -510,6 +521,15 @@ module List
510
521
  rx = @pat
511
522
  finalize rx
512
523
  end
524
+
525
+ def optionalize(bool)
526
+ n = self
527
+ if bool
528
+ n = n.dup
529
+ n.optional = bool
530
+ end
531
+ n
532
+ end
513
533
  end
514
534
 
515
535
  class Sequence < Node
@@ -1,3 +1,3 @@
1
1
  module ListMatcher
2
- VERSION = "1.0.2"
2
+ VERSION = "1.0.3"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: list_matcher
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.2
4
+ version: 1.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - dfhoughton
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-08-16 00:00:00.000000000 Z
11
+ date: 2015-08-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler