list_matcher 1.0.2 → 1.0.3
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.
- checksums.yaml +4 -4
- data/README.md +4 -1
- data/lib/list_matcher.rb +23 -3
- data/lib/list_matcher/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: bb59b6999ba70e7b3548710341764da658e460b3
|
4
|
+
data.tar.gz: d0781937d67e22497b6c0005497c4e734a39582a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
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
|
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
|
data/lib/list_matcher/version.rb
CHANGED
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.
|
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-
|
11
|
+
date: 2015-08-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|