YkLib 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +11 -0
- data/.rspec +3 -0
- data/.travis.yml +6 -0
- data/CODE_OF_CONDUCT.md +74 -0
- data/Gemfile +7 -0
- data/Gemfile.lock +34 -0
- data/LICENSE.txt +21 -0
- data/README.md +44 -0
- data/Rakefile +6 -0
- data/YkLib.gemspec +29 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/lib/YkLib/Yk/__advance__.rb +151 -0
- data/lib/YkLib/Yk/__defun__.rb +44 -0
- data/lib/YkLib/Yk/__hook__.rb +244 -0
- data/lib/YkLib/Yk/__minmax__.rb +123 -0
- data/lib/YkLib/Yk/__stdlog.rb +329 -0
- data/lib/YkLib/Yk/adhocLiterals/email.rb +119 -0
- data/lib/YkLib/Yk/adhocLiterals/path.rb +402 -0
- data/lib/YkLib/Yk/adhocLiterals/tag.rb +19 -0
- data/lib/YkLib/Yk/adhocLiterals/url.rb +36 -0
- data/lib/YkLib/Yk/adhocLiterals.rb +199 -0
- data/lib/YkLib/Yk/auto_escseq.rb +5 -0
- data/lib/YkLib/Yk/auto_pstore.rb +179 -0
- data/lib/YkLib/Yk/bsearch.rb +120 -0
- data/lib/YkLib/Yk/clambda.rb +309 -0
- data/lib/YkLib/Yk/confLine.rb +423 -0
- data/lib/YkLib/Yk/create_tty_width_available.rb +24 -0
- data/lib/YkLib/Yk/crypt.rb +26 -0
- data/lib/YkLib/Yk/debug2 +1 -0
- data/lib/YkLib/Yk/debug2.rb +473 -0
- data/lib/YkLib/Yk/debugout.rb +139 -0
- data/lib/YkLib/Yk/email_tz.rb +533 -0
- data/lib/YkLib/Yk/enum_expect.rb +170 -0
- data/lib/YkLib/Yk/errlog.rb +5 -0
- data/lib/YkLib/Yk/escseq.rb +59 -0
- data/lib/YkLib/Yk/eval_alt.rb +281 -0
- data/lib/YkLib/Yk/expector.rb +93 -0
- data/lib/YkLib/Yk/fetch.rb +556 -0
- data/lib/YkLib/Yk/fetch_old.rb +290 -0
- data/lib/YkLib/Yk/fib.rb +158 -0
- data/lib/YkLib/Yk/file_aux.rb +843 -0
- data/lib/YkLib/Yk/file_aux2.rb +919 -0
- data/lib/YkLib/Yk/file_aux_old.rb +160 -0
- data/lib/YkLib/Yk/filemod.rb +19 -0
- data/lib/YkLib/Yk/force_escseq.rb +3 -0
- data/lib/YkLib/Yk/generator__.rb +144 -0
- data/lib/YkLib/Yk/generator__.rb.org +139 -0
- data/lib/YkLib/Yk/indenter/argless_case.rb +46 -0
- data/lib/YkLib/Yk/indenter/each_token.rb +671 -0
- data/lib/YkLib/Yk/indenter/free_case.rb +313 -0
- data/lib/YkLib/Yk/indenter/if_less.rb +53 -0
- data/lib/YkLib/Yk/indenter/independent_ensure.rb +23 -0
- data/lib/YkLib/Yk/indenter/independent_rescue.rb +23 -0
- data/lib/YkLib/Yk/indenter/operand_circumflex.rb +0 -0
- data/lib/YkLib/Yk/indenter/operand_period.rb +16 -0
- data/lib/YkLib/Yk/indenter/parenless_and.rb +37 -0
- data/lib/YkLib/Yk/indenter/post_test.rb +48 -0
- data/lib/YkLib/Yk/indenter/token.rb +1525 -0
- data/lib/YkLib/Yk/indenter.rb +1382 -0
- data/lib/YkLib/Yk/inot.rb +265 -0
- data/lib/YkLib/Yk/intf.rb +815 -0
- data/lib/YkLib/Yk/io_aux.rb +1332 -0
- data/lib/YkLib/Yk/ioctl.rb +60 -0
- data/lib/YkLib/Yk/ipcc.rb +87 -0
- data/lib/YkLib/Yk/ipcountry.rb +207 -0
- data/lib/YkLib/Yk/ipv4adr.rb +318 -0
- data/lib/YkLib/Yk/localmail.rb +276 -0
- data/lib/YkLib/Yk/method_chain.rb +359 -0
- data/lib/YkLib/Yk/misc_tz.rb +1716 -0
- data/lib/YkLib/Yk/missing_method.rb +50 -0
- data/lib/YkLib/Yk/mojiConv.rb +257 -0
- data/lib/YkLib/Yk/nostdlog.rb +4 -0
- data/lib/YkLib/Yk/on_marshal.rb +20 -0
- data/lib/YkLib/Yk/overrider.rb +47 -0
- data/lib/YkLib/Yk/path.rb +293 -0
- data/lib/YkLib/Yk/path_aux.rb +883 -0
- data/lib/YkLib/Yk/path_aux_alt.rb +0 -0
- data/lib/YkLib/Yk/path_rep.rb +1267 -0
- data/lib/YkLib/Yk/pg_setup.rb +917 -0
- data/lib/YkLib/Yk/procinfo.rb +314 -0
- data/lib/YkLib/Yk/proclist.rb +492 -0
- data/lib/YkLib/Yk/property.rb +863 -0
- data/lib/YkLib/Yk/ranger.rb +606 -0
- data/lib/YkLib/Yk/resolv_tz.rb +88 -0
- data/lib/YkLib/Yk/rlprompt.rb +73 -0
- data/lib/YkLib/Yk/rootexec.rb +48 -0
- data/lib/YkLib/Yk/rpm-packageproxy.rb +784 -0
- data/lib/YkLib/Yk/rpm-packageproxy2.rb +1430 -0
- data/lib/YkLib/Yk/rwhen.rb +21 -0
- data/lib/YkLib/Yk/selector.rb +124 -0
- data/lib/YkLib/Yk/set.rb +170 -0
- data/lib/YkLib/Yk/shellquote.rb +300 -0
- data/lib/YkLib/Yk/sio.rb +1001 -0
- data/lib/YkLib/Yk/sio0.rb +835 -0
- data/lib/YkLib/Yk/sio_aux.rb +1524 -0
- data/lib/YkLib/Yk/sio_inot.rb +86 -0
- data/lib/YkLib/Yk/sock_aux.rb +42 -0
- data/lib/YkLib/Yk/spipe.rb +843 -0
- data/lib/YkLib/Yk/sql_table.rb +565 -0
- data/lib/YkLib/Yk/stdlog.rb +4 -0
- data/lib/YkLib/Yk/syscommand.rb +173 -0
- data/lib/YkLib/Yk/sysinit.rb +75 -0
- data/lib/YkLib/Yk/ttyFontWidth.rb +46113 -0
- data/lib/YkLib/Yk/tty_char.dump +0 -0
- data/lib/YkLib/Yk/tty_char.rb +47 -0
- data/lib/YkLib/Yk/tty_char_create.rb +437031 -0
- data/lib/YkLib/Yk/tty_char_static.rb +437016 -0
- data/lib/YkLib/Yk/tty_rewrite.rb +142 -0
- data/lib/YkLib/Yk/tty_str.rb +461 -0
- data/lib/YkLib/Yk/tty_width.dat.rb +114 -0
- data/lib/YkLib/Yk/tty_width.rb +180 -0
- data/lib/YkLib/Yk/tty_width_available +569 -0
- data/lib/YkLib/Yk/tty_width_list +0 -0
- data/lib/YkLib/Yk/tty_width_list.linux +280 -0
- data/lib/YkLib/Yk/tty_width_list.windows +324 -0
- data/lib/YkLib/Yk/tz_tty +0 -0
- data/lib/YkLib/Yk/tz_tty.rb +0 -0
- data/lib/YkLib/Yk/uprepos.rb +94 -0
- data/lib/YkLib/Yk/userinfo.rb +91 -0
- data/lib/YkLib/Yk/with.rb +109 -0
- data/lib/YkLib/version.rb +3 -0
- data/lib/YkLib.rb +6 -0
- metadata +170 -0
@@ -0,0 +1,556 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
|
4
|
+
require 'continuation'
|
5
|
+
|
6
|
+
|
7
|
+
class Fetch
|
8
|
+
def self.caller_binding
|
9
|
+
cc = nil # must be present to work within lambda
|
10
|
+
count = 0 # counter of returns
|
11
|
+
|
12
|
+
set_trace_func lambda { |event, file, lineno, id, binding, klass|
|
13
|
+
# First return gets to the caller of this method
|
14
|
+
# (which already know its own binding).
|
15
|
+
# Second return gets to the caller of the caller.
|
16
|
+
# That's we want!
|
17
|
+
if count == 2
|
18
|
+
set_trace_func nil
|
19
|
+
# Will return the binding to the callcc below.
|
20
|
+
cc.call binding
|
21
|
+
elsif event == "return"
|
22
|
+
count += 1
|
23
|
+
end
|
24
|
+
}
|
25
|
+
# First time it'll set the cc and return nil to the caller.
|
26
|
+
# So it's important to the caller to return again
|
27
|
+
# if it gets nil, then we get the second return.
|
28
|
+
# Second time it'll return the binding.
|
29
|
+
return callcc { |cont| cc = cont ; nil}
|
30
|
+
end
|
31
|
+
#module_function :caller_binding
|
32
|
+
|
33
|
+
BlockStrList = Hash.new
|
34
|
+
ANON = Object.new
|
35
|
+
attr :direct_mode, true
|
36
|
+
def initialize obj
|
37
|
+
@obj = obj
|
38
|
+
end
|
39
|
+
class BlockInfo
|
40
|
+
class Select < Array
|
41
|
+
def initialize *args
|
42
|
+
args.each do |e|
|
43
|
+
push e
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
attr :params, true
|
48
|
+
def self.each_match item, pat
|
49
|
+
if pat == ANON
|
50
|
+
true
|
51
|
+
elsif pat.is_a? Select
|
52
|
+
pat.each do |e|
|
53
|
+
if each_match(item, e)
|
54
|
+
return true
|
55
|
+
end
|
56
|
+
end
|
57
|
+
return false
|
58
|
+
elsif !item.is_a?(Array) || !pat.is_a?(Array)
|
59
|
+
item == pat
|
60
|
+
else # both is array
|
61
|
+
if pat.size <= item.size
|
62
|
+
pat.each_with_index do |e, i|
|
63
|
+
if !each_match(item[i], e)
|
64
|
+
return false
|
65
|
+
end
|
66
|
+
end
|
67
|
+
#pp ["item", item]
|
68
|
+
#pp ["pat", pat]
|
69
|
+
true
|
70
|
+
else
|
71
|
+
false
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
75
|
+
def self.rec_find_match sexe, pat
|
76
|
+
return sexe if each_match sexe, pat
|
77
|
+
case sexe.size
|
78
|
+
when 0
|
79
|
+
pat == []
|
80
|
+
when 1
|
81
|
+
item = sexe[0]
|
82
|
+
if each_match item, pat
|
83
|
+
item
|
84
|
+
elsif item.is_a?(Array) || (item.respond_to?(:to_ary) && (item = item.to_ary))
|
85
|
+
rec_find_match item, pat
|
86
|
+
end
|
87
|
+
else
|
88
|
+
m = sexe.size.div(2)
|
89
|
+
rec_find_match(sexe[0 ... m], pat) or rec_find_match(sexe[m .. -1], pat)
|
90
|
+
end
|
91
|
+
end
|
92
|
+
def self.rec_find_match_all sexe, pat, ret = []
|
93
|
+
case sexe.size
|
94
|
+
when 0
|
95
|
+
ret
|
96
|
+
when 1
|
97
|
+
item = sexe[0]
|
98
|
+
if each_match item, pat
|
99
|
+
ret.push item
|
100
|
+
elsif item.is_a?(Array) || (item.respond_to(:to_ary) && (item = item.to_ary))
|
101
|
+
rec_find_match_all item, pat, ret
|
102
|
+
end
|
103
|
+
else
|
104
|
+
m = sexe.size.div(2)
|
105
|
+
rec_find_match_all(sexe[0 ... m], pat, ret)
|
106
|
+
rec_find_match_all(sexe[m .. -1], pat, ret)
|
107
|
+
end
|
108
|
+
ret
|
109
|
+
end
|
110
|
+
def self.dosexp path
|
111
|
+
require 'ripper'
|
112
|
+
sexpBuilder2 = Ripper.new(path, "-", 1)
|
113
|
+
(class << sexpBuilder2; self; end).module_eval do #:nodoc:
|
114
|
+
private
|
115
|
+
|
116
|
+
::Ripper::PARSER_EVENT_TABLE.each do |event, arity|
|
117
|
+
if /_new\z/ =~ event.to_s and arity == 0
|
118
|
+
module_eval(<<-End, __FILE__, __LINE__ + 1)
|
119
|
+
def on_#{event}
|
120
|
+
[]
|
121
|
+
end
|
122
|
+
End
|
123
|
+
elsif /_add\z/ =~ event.to_s
|
124
|
+
module_eval(<<-End, __FILE__, __LINE__ + 1)
|
125
|
+
def on_#{event}(list, item)
|
126
|
+
list.push item
|
127
|
+
list
|
128
|
+
end
|
129
|
+
End
|
130
|
+
else
|
131
|
+
module_eval(<<-End, __FILE__, __LINE__ + 1)
|
132
|
+
def on_#{event}(*args)
|
133
|
+
[[:#{event}, [lineno(), column()]], *args]
|
134
|
+
end
|
135
|
+
End
|
136
|
+
end
|
137
|
+
end
|
138
|
+
|
139
|
+
::Ripper::SCANNER_EVENTS.each do |event|
|
140
|
+
module_eval(<<-End, __FILE__, __LINE__ + 1)
|
141
|
+
def on_#{event}(tok)
|
142
|
+
[:@#{event}, tok, [lineno(), column()]]
|
143
|
+
end
|
144
|
+
End
|
145
|
+
end
|
146
|
+
self
|
147
|
+
end
|
148
|
+
sexpBuilder2.parse
|
149
|
+
end
|
150
|
+
|
151
|
+
List = Hash.new
|
152
|
+
def self.getPosAfter all, lno, expr
|
153
|
+
i = 0
|
154
|
+
all.each_line do |ln|
|
155
|
+
i += 1
|
156
|
+
if lno == i && ln =~ expr
|
157
|
+
return [i, $`.size + $&.size + 1]
|
158
|
+
end
|
159
|
+
end
|
160
|
+
return nil
|
161
|
+
end
|
162
|
+
def self.getContent all, from, to
|
163
|
+
if from[0] > to[0] || (from[0] == to[0] && from[1] > to[1])
|
164
|
+
raise Exception.new "range error"
|
165
|
+
end
|
166
|
+
i = 0
|
167
|
+
lns = ""
|
168
|
+
all.each_line do |ln|
|
169
|
+
i += 1
|
170
|
+
if i == from[0]
|
171
|
+
if from[0] != to[0]
|
172
|
+
lns += ln[from[1] - 1 .. -1]
|
173
|
+
else
|
174
|
+
lns += ln[from[1] - 1 .. to[1] - 1]
|
175
|
+
if lns[-1] == "d"
|
176
|
+
lns = lns[0..-4]
|
177
|
+
elsif lns[-1] == "}"
|
178
|
+
lns = lns[0..-2]
|
179
|
+
end
|
180
|
+
if lns[0] == "|"
|
181
|
+
lns = lns[1..-1]
|
182
|
+
end
|
183
|
+
return lns
|
184
|
+
end
|
185
|
+
elsif i == to[0]
|
186
|
+
lns += ln[0 .. to[1] - 1]
|
187
|
+
if lns[-1] == "d"
|
188
|
+
lns = lns[0..-4]
|
189
|
+
elsif lns[-1] == "}"
|
190
|
+
lns = lns[0..-2]
|
191
|
+
end
|
192
|
+
if lns[0] == "|"
|
193
|
+
lns = lns[1..-1]
|
194
|
+
end
|
195
|
+
return lns
|
196
|
+
elsif from[0] < i && i < to[0]
|
197
|
+
lns += ln
|
198
|
+
end
|
199
|
+
end
|
200
|
+
raise Exception.new "range error"
|
201
|
+
end
|
202
|
+
attr :blockBody
|
203
|
+
def initialize params, path, lno, bstr
|
204
|
+
@params = params
|
205
|
+
@path = path
|
206
|
+
@lineNo = lno
|
207
|
+
if bstr
|
208
|
+
@blockBody = %{
|
209
|
+
Proc.new do |#{["_f", *params].join(", ")}|
|
210
|
+
#{bstr}
|
211
|
+
end
|
212
|
+
}
|
213
|
+
end
|
214
|
+
List[path + ":#{lno}"] = self
|
215
|
+
end
|
216
|
+
FILE_CONTENT = Hash.new
|
217
|
+
FILE_SEXP = Hash.new
|
218
|
+
OldCleared = Hash.new
|
219
|
+
def self.clearOld ph, t, forceTrue = true
|
220
|
+
found = false
|
221
|
+
if File.directory? ph
|
222
|
+
Dir.open ph do |d|
|
223
|
+
d.each do |f|
|
224
|
+
if f != "." && f != ".."
|
225
|
+
f = ph + "/" + f
|
226
|
+
if File.directory?(f)
|
227
|
+
if !clearOld f, t, false
|
228
|
+
require "fileutils"
|
229
|
+
FileUtils.rmdir f
|
230
|
+
end
|
231
|
+
elsif File.mtime(f) < t
|
232
|
+
File.unlink f
|
233
|
+
else
|
234
|
+
found = true
|
235
|
+
end
|
236
|
+
end
|
237
|
+
end
|
238
|
+
end
|
239
|
+
end
|
240
|
+
return forceTrue ? true: found
|
241
|
+
end
|
242
|
+
def self.createFromFiles path, lno, pth, ph
|
243
|
+
params = nil
|
244
|
+
blockContent = nil
|
245
|
+
w = pth + "/" + ".params"
|
246
|
+
t = File.mtime(path)
|
247
|
+
if File.exist?(w) && File.mtime(w) > t
|
248
|
+
File.open w do |f|
|
249
|
+
f.flock File::LOCK_SH
|
250
|
+
params = f.read.split /\s+/
|
251
|
+
end
|
252
|
+
end
|
253
|
+
w = pth + "/" + ".blockContent"
|
254
|
+
if File.exist?(w) && File.mtime(w) > t
|
255
|
+
File.open w do |f|
|
256
|
+
f.flock File::LOCK_SH
|
257
|
+
blockContent = f.read
|
258
|
+
end
|
259
|
+
end
|
260
|
+
if !params
|
261
|
+
OldCleared[path] ||= clearOld(ph, t)
|
262
|
+
return nil
|
263
|
+
end
|
264
|
+
self.new params, path, lno, blockContent
|
265
|
+
end
|
266
|
+
def self.getBlockInfo path, lno, key, label, blKey
|
267
|
+
label = label.to_s
|
268
|
+
pth = (ph = File.expand_path("~/.tmp") + "/Yk/site_ruby/fetch.rb/" + path) + "/" + lno.to_s + "/" + key + "/" + label
|
269
|
+
item = List[path + ":#{lno}"] || createFromFiles(path, lno, pth, ph)
|
270
|
+
if item
|
271
|
+
return item
|
272
|
+
end
|
273
|
+
all = FILE_CONTENT[path] ||= IO.read(path)
|
274
|
+
sexp = FILE_SEXP[path] ||= dosexp(all)
|
275
|
+
lst = rec_find_match sexp,
|
276
|
+
[[:method_add_block],
|
277
|
+
[[:call],
|
278
|
+
[[:call],
|
279
|
+
ANON,
|
280
|
+
:".",
|
281
|
+
[:@ident, key]
|
282
|
+
],
|
283
|
+
:".",
|
284
|
+
[:@ident, label, [lno]]
|
285
|
+
],
|
286
|
+
[[Select.new(:do_block, :brace_block)]]
|
287
|
+
]
|
288
|
+
if lst
|
289
|
+
pLst = rec_find_match lst,
|
290
|
+
[ [:method_add_block],
|
291
|
+
[[:call],
|
292
|
+
[[:call],
|
293
|
+
ANON,
|
294
|
+
:".",
|
295
|
+
[:@ident, key]
|
296
|
+
],
|
297
|
+
:".",
|
298
|
+
[:@ident, label, [lno]]
|
299
|
+
],
|
300
|
+
[[Select.new(:do_block, :brace_block)],
|
301
|
+
[[:block_var], [[:params]]]
|
302
|
+
]
|
303
|
+
]
|
304
|
+
params = []
|
305
|
+
if pLst
|
306
|
+
if pLst[2][1][1][1]
|
307
|
+
pLst[2][1][1][1].each do |e|
|
308
|
+
params.push e[1]
|
309
|
+
end
|
310
|
+
end
|
311
|
+
pLst[2][1][1].each do |e|
|
312
|
+
if e.is_a?(Array) && e[0].is_a?(Array) && e[0][0] == :rest_param
|
313
|
+
params.push "*" + e[1][1]
|
314
|
+
end
|
315
|
+
end
|
316
|
+
end
|
317
|
+
require "pathname"
|
318
|
+
Pathname.new(pth).mkpath
|
319
|
+
File.open pth + "/.params", "w" do |fw|
|
320
|
+
fw.flock File::LOCK_EX
|
321
|
+
fw.write params.join(" ")
|
322
|
+
end
|
323
|
+
if params[0] =~ /^_f/
|
324
|
+
self.new params, path, lno, nil
|
325
|
+
else
|
326
|
+
c = pLst && getContent(all, pLst[2][1][0][1], pLst[2][0][1])
|
327
|
+
c ||= getContent(all, getPosAfter(all, lno, /\b#{key}\s*\.\s*#{label}\b.*(\bdo\b|\{)/), lst[2][0][1])
|
328
|
+
File.open pth + "/.blockContent", "w" do |fw|
|
329
|
+
fw.flock File::LOCK_EX
|
330
|
+
fw.write c
|
331
|
+
end
|
332
|
+
self.new params, path, lno, c
|
333
|
+
end
|
334
|
+
else
|
335
|
+
nil
|
336
|
+
end
|
337
|
+
|
338
|
+
end
|
339
|
+
end
|
340
|
+
def method_missing label, *fargs, &bl
|
341
|
+
@label = label
|
342
|
+
super if !@obj.respond_to? @label
|
343
|
+
loc = caller_locations(1)[0]
|
344
|
+
if @blockInfo = BlockInfo.getBlockInfo(loc.path, loc.lineno, "__fetch__", @label, "fetch")
|
345
|
+
bd = @blockInfo.blockBody
|
346
|
+
if bd
|
347
|
+
return unless bnd = Fetch.caller_binding
|
348
|
+
@block = bnd.eval(bd)
|
349
|
+
end
|
350
|
+
end
|
351
|
+
@block ||= bl
|
352
|
+
entity *fargs
|
353
|
+
end
|
354
|
+
def normArray a
|
355
|
+
if a.size == 1
|
356
|
+
if a[0].is_a?(Array)
|
357
|
+
return a[0]
|
358
|
+
elsif a[0].respond_to? :to_ary
|
359
|
+
return a.to_ary
|
360
|
+
end
|
361
|
+
end
|
362
|
+
return a
|
363
|
+
end
|
364
|
+
def entity *fargs
|
365
|
+
if callcc{|cc| @start = cc; true}
|
366
|
+
@iter_rval = iterate *fargs
|
367
|
+
@setup_iter_rval.call false
|
368
|
+
else
|
369
|
+
@start = nil
|
370
|
+
@bl_rval = nil
|
371
|
+
loop do
|
372
|
+
count = 0
|
373
|
+
a = @args
|
374
|
+
if @blockInfo.params.size > (@blockInfo.blockBody ? 1 : 2)
|
375
|
+
a = normArray(a)
|
376
|
+
end
|
377
|
+
#p [__LINE__, @args, a]
|
378
|
+
set_trace_func lambda { |event, file, lineno, id, binding, klass|
|
379
|
+
if event == "line"
|
380
|
+
count += 1
|
381
|
+
if count == 2
|
382
|
+
@blBind = binding
|
383
|
+
set_trace_func nil
|
384
|
+
end
|
385
|
+
end
|
386
|
+
}
|
387
|
+
@bl_rval = @block.call self, *a
|
388
|
+
if !callcc{|cc| @setup_iter_rval = cc; true}
|
389
|
+
break @iter_rval
|
390
|
+
end
|
391
|
+
if callcc{|cc| @block_cont = cc; true}
|
392
|
+
@iterate_cont.call false;
|
393
|
+
end
|
394
|
+
end
|
395
|
+
end
|
396
|
+
end
|
397
|
+
def iterate *fargs
|
398
|
+
@obj.__send__(@label, *fargs, &self)
|
399
|
+
end
|
400
|
+
def evaluate
|
401
|
+
if @blockInfo.params.size > (@blockInfo.blockBody ? 1 : 2)
|
402
|
+
@args = normArray(@args)
|
403
|
+
end
|
404
|
+
@blockInfo.params.each_with_index do |vl, im|
|
405
|
+
i = @blockInfo.blockBody ? im : im - 1
|
406
|
+
if i == -1
|
407
|
+
@blBind.eval("#{vl} = ObjectSpace._id2ref(#{self.__id__})");
|
408
|
+
else
|
409
|
+
if @args.size <= i
|
410
|
+
if vl[0..0] == "*"
|
411
|
+
@blBind.eval("#{vl} = []")
|
412
|
+
else
|
413
|
+
@blBind.eval("#{vl} = nil")
|
414
|
+
end
|
415
|
+
else
|
416
|
+
if vl[0..0] == "*"
|
417
|
+
estr = "#{vl[1..-1]} = ["
|
418
|
+
i.upto @args.size - 1 do |j|
|
419
|
+
if j != i
|
420
|
+
estr += ","
|
421
|
+
end
|
422
|
+
estr += "ObjectSpace._id2ref(#{@args[j].__id__})"
|
423
|
+
end
|
424
|
+
estr += "]"
|
425
|
+
@blBind.eval estr
|
426
|
+
else
|
427
|
+
@blBind.eval("#{vl} = ObjectSpace._id2ref(#{@args[i].__id__})");
|
428
|
+
end
|
429
|
+
end
|
430
|
+
end
|
431
|
+
end
|
432
|
+
end
|
433
|
+
def fetch fret = nil
|
434
|
+
if callcc{|cc| @fetch = cc; true}
|
435
|
+
@bl_rval = fret
|
436
|
+
@iterate_cont.call false
|
437
|
+
else
|
438
|
+
@fetch = nil
|
439
|
+
evaluate
|
440
|
+
end
|
441
|
+
true
|
442
|
+
end
|
443
|
+
def call *args
|
444
|
+
@args = args
|
445
|
+
if callcc{|cc| @iterate_cont = cc; true}
|
446
|
+
if @start
|
447
|
+
@start.call false
|
448
|
+
elsif @fetch
|
449
|
+
@fetch.call false
|
450
|
+
else
|
451
|
+
@block_cont.call false
|
452
|
+
end
|
453
|
+
else
|
454
|
+
@bl_rval
|
455
|
+
end
|
456
|
+
end
|
457
|
+
def to_proc
|
458
|
+
Proc.new do |*args|
|
459
|
+
call *args
|
460
|
+
end
|
461
|
+
end
|
462
|
+
def self.find
|
463
|
+
loc = caller_locations(2)[0]
|
464
|
+
FetchRangeList.find loc
|
465
|
+
end
|
466
|
+
end
|
467
|
+
|
468
|
+
|
469
|
+
def fetch *frets
|
470
|
+
return unless bnd = Fetch.caller_binding
|
471
|
+
f = bnd.eval("_f")
|
472
|
+
if !f.is_a? Fetch
|
473
|
+
raise Exception.new("JumpError")
|
474
|
+
end
|
475
|
+
case frets.size
|
476
|
+
when 0
|
477
|
+
fret = nil
|
478
|
+
when 1
|
479
|
+
fret = frets[0]
|
480
|
+
else
|
481
|
+
fret = frets
|
482
|
+
end
|
483
|
+
f.fetch fret
|
484
|
+
end
|
485
|
+
|
486
|
+
|
487
|
+
class Object
|
488
|
+
def __fetch__ &bl
|
489
|
+
f = Fetch.new self
|
490
|
+
if bl
|
491
|
+
f.direct_mode = true
|
492
|
+
bl.call f
|
493
|
+
else
|
494
|
+
f
|
495
|
+
end
|
496
|
+
end
|
497
|
+
end
|
498
|
+
|
499
|
+
|
500
|
+
if File.expand_path($0) == __FILE__
|
501
|
+
|
502
|
+
# [1, 2, 3, 4, 5].__fetch__.each do |e|
|
503
|
+
# if e == 3
|
504
|
+
# print "[#{e}, #{(fetch and e)}], "
|
505
|
+
# else
|
506
|
+
# print "#{e}, "
|
507
|
+
# end
|
508
|
+
# end
|
509
|
+
|
510
|
+
def test
|
511
|
+
[1, 2, 3, 4, 5].__fetch__.each { |_f, e|
|
512
|
+
if e == 3
|
513
|
+
print "[#{e}, #{(fetch and e)}], "
|
514
|
+
else
|
515
|
+
print "#{e}, "
|
516
|
+
end
|
517
|
+
}
|
518
|
+
end
|
519
|
+
|
520
|
+
print "\n"
|
521
|
+
test
|
522
|
+
print "\n"
|
523
|
+
test
|
524
|
+
test
|
525
|
+
|
526
|
+
|
527
|
+
i = 0
|
528
|
+
[[1, 2, 3], 4, 5, [6, 7], [8, 9, 10, 11], 12, 13].__fetch__.each do |*j|
|
529
|
+
if i == 3
|
530
|
+
print "("
|
531
|
+
end
|
532
|
+
print "[#{j}]"
|
533
|
+
if i == 3
|
534
|
+
fetch
|
535
|
+
print ", [#{j}])"
|
536
|
+
end
|
537
|
+
print "\n"
|
538
|
+
i += 1
|
539
|
+
end
|
540
|
+
|
541
|
+
[[1, 2, 3], 4, 5, [6, 7], [8, 9, 10, 11], 12, 13].each do |*j|
|
542
|
+
if i == 3
|
543
|
+
print "["
|
544
|
+
end
|
545
|
+
print "[#{j}]"
|
546
|
+
print "\n"
|
547
|
+
i += 1
|
548
|
+
end
|
549
|
+
|
550
|
+
end
|
551
|
+
|
552
|
+
|
553
|
+
print "\n"
|
554
|
+
|
555
|
+
|
556
|
+
|