rmtools 2.4.10 → 2.5.0

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: 4d3b07b14c70d3dd59836d63413edd39658d8d58
4
- data.tar.gz: c01da1e9feace4314ed357893e614791f25fa1a3
3
+ metadata.gz: dee4a4cc1321a70502203bf4ac87195beb0a795c
4
+ data.tar.gz: 2d7e0af74476325805077e9fc9d4ff5e670758c2
5
5
  SHA512:
6
- metadata.gz: f6925f901894967db43a03ca37d23ceeae57430a447601b17f38ea02ebda6a8820c4e2b42f5feb59595705795c4b9225a43f9240479f99f0f4f7b08753ff3f54
7
- data.tar.gz: 16e6bbc0c1108d0265a456d8942dc943b9c57a7ee7a598b1ca1ff45d71e013c699277e75165815036693712010c3bd165cbb82f926db89f62fe9b54b5b5a09ee
6
+ metadata.gz: abf7b47f5d572f44f0d7b42644153847f6f8c49a3ba60cc283fbe2cbc859d2cea247ebb9f34739f4582a56a615f58ada88492bc493b7a16fa27d88fb54b5fdc1
7
+ data.tar.gz: 877efa1c90bd97dedc74835e6fd16c232bd88a929e72206f94864ba5a181c3caf7229f9f7913e7c477cfab1ab9a918ae0e7ffef6f6733f46c74a2d359765471a
@@ -13,8 +13,6 @@ class TrueClass
13
13
  def <= obj; !!obj or obj == true end
14
14
  def > obj; !obj end
15
15
  def >= obj; !obj or obj == true end
16
-
17
- def call(*) self end
18
16
  end
19
17
 
20
18
  class FalseClass
@@ -31,8 +29,6 @@ class FalseClass
31
29
  def <= obj; !obj.nil? end
32
30
  def > obj; obj.nil? end
33
31
  def >= obj; !obj end
34
-
35
- def call(*) self end
36
32
  end
37
33
 
38
34
  class NilClass
@@ -1,2 +1,7 @@
1
1
  # encoding: utf-8
2
- RMTools::require __FILE__, '*'
2
+ RMTools::require __FILE__, 'binding'
3
+ RMTools::require __FILE__, 'highlight'
4
+ RMTools::require __FILE__, 'present'
5
+ RMTools::require __FILE__, 'timer'
6
+ RMTools::require __FILE__, 'void'
7
+ RMTools::require __FILE__, 'watching'
@@ -1,8 +1,38 @@
1
- RMTools::require 'text/string_scanner'
1
+ # The MIT License (MIT)
2
+ #
3
+ # Copyright (c) 2010 <tinbka@gmail.com>
4
+ #
5
+ # Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ # of this software and associated documentation files (the "Software"), to deal
7
+ # in the Software without restriction, including without limitation the rights
8
+ # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ # copies of the Software, and to permit persons to whom the Software is
10
+ # furnished to do so, subject to the following conditions:
11
+ #
12
+ # The above copyright notice and this permission notice shall be included in
13
+ # all copies or substantial portions of the Software.
14
+ #
15
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ # THE SOFTWARE.
22
+
23
+ # We trivially can revert string: "foobar" -> "raboof",
24
+ # but could we revert a regular expression and what should it be?
25
+ # Obviously, only revert of a regexp source won't work.
26
+ # If we could match a string written backwards with resulting regexp then it would be a revert regexp.
27
+ # Below is a proof of that concept.
28
+ #
29
+ #
30
+
31
+ require 'strscan'
2
32
 
3
33
  class Regexp
4
34
 
5
- # reverses a regexp just like an ordinal string so one can use it for lookbehind
35
+ # Reverts a regexp just like an ordinal string, so one can use it for lookbehind
6
36
  # /abc(?=>d.+f){1,10}(?=>[^g+h-j]*\w+?)*?$/.reverse
7
37
  ### => /^(?=\w+?[^g+h-j]*>)*?(?=f.+d>){1,10}cba/
8
38
  def reverse
@@ -13,7 +43,11 @@ class Regexp
13
43
  oppose = {'('=>')', ')'=>'(', '^'=>'$', '$'=>'^'}
14
44
  borders = {'Z'=>'\A', 'A'=>'\Z', 'z'=>'\a', 'a'=>'\z'}
15
45
  ext = options&2 != 0
16
- StringScanner(source).each(/./) {|s|
46
+ StringScanner.each(source, /./) {|s|
47
+ $log << s.matched
48
+ $log << new
49
+ $log << {bs: bs, klass: klass, count: count, group_marks: group_marks}
50
+ puts '---'
17
51
  if (m = s.matched) == '\\'
18
52
  (klass || new) << '\\' if !(bs = !bs)
19
53
  else
@@ -71,4 +105,92 @@ private
71
105
  end
72
106
  end
73
107
 
108
+ end
109
+
110
+ class StringScanner
111
+ attr_reader :last
112
+
113
+ # #each( <Regexp>, { <0..255 | :~ | nil> => ->{|self|}, ... } )
114
+ # #each( <Regexp>, [ [ <Regexp>, ->{|self, <MatchData>|} ], ... ] )
115
+ # #each( <Regexp> ) {|self|}
116
+ # Example:
117
+ # ss = StringScanner.new xpath
118
+ # ss.each %r{\[-?\d+\]|\{[^\}]+\}},
119
+ # ?[ => lambda {|ss|
120
+ # if node; node = FindByIndex[node, nslist, ss]
121
+ # else return [] end },
122
+ # ?{ => lambda {|ss|
123
+ # if node; node = FindByProc[node, nslist, ss]
124
+ # else return [] end },
125
+ # nil => lambda {|str|
126
+ # node = node.is(Array) ?
127
+ # node.sum {|n| n.__find(str, nslist).to_a} : node.__find(str, nslist)
128
+ # }
129
+ def each(re, cbs=nil, &cb)
130
+ @last = pos
131
+ res = scan_until re
132
+ if cbs
133
+ if cbs.is Hash
134
+ while res
135
+ if cb = cbs[matched[0]] || cbs[:~]
136
+ cb[self]
137
+ @last = pos
138
+ res = !eos? && scan_until(re)
139
+ else break
140
+ end
141
+ end
142
+ if !eos? and cb = cbs[nil]
143
+ cb[tail]
144
+ end
145
+ else
146
+ while res
147
+ if cb = cbs.find {|pattern, fun| pattern and matched[pattern]}
148
+ # patterns should be as explicit as possible
149
+ cb[1][self, $~] if cb[1]
150
+ @last = pos
151
+ res = !eos? && scan_until(re)
152
+ else break
153
+ end
154
+ end
155
+ if !eos? and cb = cbs.find {|pair| pair[0].nil?}
156
+ cb[1][tail]
157
+ end
158
+ end
159
+ else
160
+ while res
161
+ cb[self]
162
+ @last = pos
163
+ res = !eos? && scan_until(re)
164
+ end
165
+ end
166
+ end
167
+
168
+ def head
169
+ string[@last...pos-matched_size.to_i]
170
+ end
171
+
172
+ def tail
173
+ post_match || string[pos..-1]
174
+ end
175
+
176
+ def hl_next(re)
177
+ (res = scan_until re) && Painter.hl(string[[pos-1000, 0].max..pos+1000], res)
178
+ end
179
+
180
+ def next_in(n)
181
+ string[pos+n-1, 1]
182
+ end
183
+
184
+ def prev_in(n)
185
+ string[pos-matched_size-n, 1]
186
+ end
187
+
188
+ def +; string[pos, 1] end
189
+
190
+ def -; string[pos-matched_size-1, 1] end
191
+
192
+ def self.each string, *args, &b
193
+ new(string).each *args, &b
194
+ end
195
+
74
196
  end
@@ -1,3 +1,3 @@
1
1
  module RMTools
2
- VERSION = '2.4.10'
2
+ VERSION = '2.5.0'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rmtools
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.4.10
4
+ version: 2.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sergey Baev
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-10-27 00:00:00.000000000 Z
11
+ date: 2016-02-10 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: RMTools is a collection of helpers for debug, text/array/file processing
14
14
  and simply easing a coding process