irb 1.3.2 → 1.3.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/irb.gemspec +1 -0
- data/lib/irb.rb +1 -1
- data/lib/irb/cmd/info.rb +24 -0
- data/lib/irb/cmd/measure.rb +10 -4
- data/lib/irb/cmd/nop.rb +2 -2
- data/lib/irb/color_printer.rb +15 -5
- data/lib/irb/ext/loader.rb +46 -19
- data/lib/irb/init.rb +11 -1
- data/lib/irb/input-method.rb +18 -2
- data/lib/irb/ruby-lex.rb +57 -7
- data/lib/irb/version.rb +2 -2
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: cd13d45b58713bde6589b963fc6d2a93c166d340aaba132c9b7981ffe88062cb
|
4
|
+
data.tar.gz: 56d4e5c73fb369f36cc34bbda1462492a0db7b7393f9b3e15a4e1a54e2ad1ec7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: cd6725cf6479552499418c3a93058ef9adb471f44fff49bd30d382e6c534dac1aa43086d002a93b06a856c2bffd5d5decdd2a79c1e9b3d31c344ecccf6cfc60f
|
7
|
+
data.tar.gz: 064efe186e582ca440903e98f7b2b5cfab38867c7f3812ffe6f2e8bd1bc3c01b64ca4828c9d38ba26c0b9d6c7ceba76f4e1974484527a9ba6cbea249970cb067
|
data/irb.gemspec
CHANGED
data/lib/irb.rb
CHANGED
data/lib/irb/cmd/info.rb
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
# frozen_string_literal: false
|
2
|
+
|
3
|
+
require_relative "nop"
|
4
|
+
|
5
|
+
# :stopdoc:
|
6
|
+
module IRB
|
7
|
+
module ExtendCommand
|
8
|
+
class Info < Nop
|
9
|
+
def execute
|
10
|
+
Class.new {
|
11
|
+
def inspect
|
12
|
+
str = "Ruby version: #{RUBY_VERSION}\n"
|
13
|
+
str += "IRB version: #{IRB.version}\n"
|
14
|
+
str += "InputMethod: #{IRB.CurrentContext.io.inspect}\n"
|
15
|
+
str += ".irbrc path: #{IRB.rc_file}\n" if File.exist?(IRB.rc_file)
|
16
|
+
str
|
17
|
+
end
|
18
|
+
alias_method :to_s, :inspect
|
19
|
+
}.new
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
# :startdoc:
|
data/lib/irb/cmd/measure.rb
CHANGED
@@ -8,7 +8,7 @@ module IRB
|
|
8
8
|
super(*args)
|
9
9
|
end
|
10
10
|
|
11
|
-
def execute(type = nil, arg = nil)
|
11
|
+
def execute(type = nil, arg = nil, &block)
|
12
12
|
case type
|
13
13
|
when :off
|
14
14
|
IRB.conf[:MEASURE] = nil
|
@@ -22,9 +22,15 @@ module IRB
|
|
22
22
|
added = IRB.set_measure_callback(type, arg)
|
23
23
|
puts "#{added[0]} is added." if added
|
24
24
|
else
|
25
|
-
|
26
|
-
|
27
|
-
|
25
|
+
if block_given?
|
26
|
+
IRB.conf[:MEASURE] = true
|
27
|
+
added = IRB.set_measure_callback(&block)
|
28
|
+
puts "#{added[0]} is added." if added
|
29
|
+
else
|
30
|
+
IRB.conf[:MEASURE] = true
|
31
|
+
added = IRB.set_measure_callback(type, arg)
|
32
|
+
puts "#{added[0]} is added." if added
|
33
|
+
end
|
28
34
|
end
|
29
35
|
nil
|
30
36
|
end
|
data/lib/irb/cmd/nop.rb
CHANGED
data/lib/irb/color_printer.rb
CHANGED
@@ -4,11 +4,21 @@ require 'irb/color'
|
|
4
4
|
|
5
5
|
module IRB
|
6
6
|
class ColorPrinter < ::PP
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
7
|
+
class << self
|
8
|
+
def pp(obj, out = $>, width = screen_width)
|
9
|
+
q = ColorPrinter.new(out, width)
|
10
|
+
q.guard_inspect_key {q.pp obj}
|
11
|
+
q.flush
|
12
|
+
out << "\n"
|
13
|
+
end
|
14
|
+
|
15
|
+
private
|
16
|
+
|
17
|
+
def screen_width
|
18
|
+
Reline.get_screen_size.last
|
19
|
+
rescue Errno::EINVAL # in `winsize': Invalid argument - <STDIN>
|
20
|
+
79
|
21
|
+
end
|
12
22
|
end
|
13
23
|
|
14
24
|
def text(str, width = nil)
|
data/lib/irb/ext/loader.rb
CHANGED
@@ -31,8 +31,31 @@ module IRB # :nodoc:
|
|
31
31
|
load_file(path, priv)
|
32
32
|
end
|
33
33
|
|
34
|
+
if File.respond_to?(:absolute_path?)
|
35
|
+
def absolute_path?(path)
|
36
|
+
File.absolute_path?(path)
|
37
|
+
end
|
38
|
+
else
|
39
|
+
separator =
|
40
|
+
if File::ALT_SEPARATOR
|
41
|
+
File::SEPARATOR
|
42
|
+
else
|
43
|
+
"[#{Regexp.quote(File::SEPARATOR + File::ALT_SEPARATOR)}]"
|
44
|
+
end
|
45
|
+
ABSOLUTE_PATH_PATTERN = # :nodoc:
|
46
|
+
case Dir.pwd
|
47
|
+
when /\A\w:/, /\A#{separator}{2}/
|
48
|
+
/\A(?:\w:|#{separator})#{separator}/
|
49
|
+
else
|
50
|
+
/\A#{separator}/
|
51
|
+
end
|
52
|
+
def absolute_path?(path)
|
53
|
+
ABSOLUTE_PATH_PATTERN =~ path
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
34
57
|
def search_file_from_ruby_path(fn) # :nodoc:
|
35
|
-
if
|
58
|
+
if absolute_path?(fn)
|
36
59
|
return fn if File.exist?(fn)
|
37
60
|
return nil
|
38
61
|
end
|
@@ -50,16 +73,18 @@ module IRB # :nodoc:
|
|
50
73
|
# See Irb#suspend_input_method for more information.
|
51
74
|
def source_file(path)
|
52
75
|
irb.suspend_name(path, File.basename(path)) do
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
else
|
59
|
-
begin
|
76
|
+
FileInputMethod.open(path) do |io|
|
77
|
+
irb.suspend_input_method(io) do
|
78
|
+
|back_io|
|
79
|
+
irb.signal_status(:IN_LOAD) do
|
80
|
+
if back_io.kind_of?(FileInputMethod)
|
60
81
|
irb.eval_input
|
61
|
-
|
62
|
-
|
82
|
+
else
|
83
|
+
begin
|
84
|
+
irb.eval_input
|
85
|
+
rescue LoadAbort
|
86
|
+
print "load abort!!\n"
|
87
|
+
end
|
63
88
|
end
|
64
89
|
end
|
65
90
|
end
|
@@ -79,16 +104,18 @@ module IRB # :nodoc:
|
|
79
104
|
ws = WorkSpace.new
|
80
105
|
end
|
81
106
|
irb.suspend_workspace(ws) do
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
else
|
88
|
-
begin
|
107
|
+
FileInputMethod.open(path) do |io|
|
108
|
+
irb.suspend_input_method(io) do
|
109
|
+
|back_io|
|
110
|
+
irb.signal_status(:IN_LOAD) do
|
111
|
+
if back_io.kind_of?(FileInputMethod)
|
89
112
|
irb.eval_input
|
90
|
-
|
91
|
-
|
113
|
+
else
|
114
|
+
begin
|
115
|
+
irb.eval_input
|
116
|
+
rescue LoadAbort
|
117
|
+
print "load abort!!\n"
|
118
|
+
end
|
92
119
|
end
|
93
120
|
end
|
94
121
|
end
|
data/lib/irb/init.rb
CHANGED
@@ -146,7 +146,7 @@ module IRB # :nodoc:
|
|
146
146
|
@CONF[:AT_EXIT] = []
|
147
147
|
end
|
148
148
|
|
149
|
-
def IRB.set_measure_callback(type = nil, arg = nil)
|
149
|
+
def IRB.set_measure_callback(type = nil, arg = nil, &block)
|
150
150
|
added = nil
|
151
151
|
if type
|
152
152
|
type_sym = type.upcase.to_sym
|
@@ -155,6 +155,16 @@ module IRB # :nodoc:
|
|
155
155
|
end
|
156
156
|
elsif IRB.conf[:MEASURE_PROC][:CUSTOM]
|
157
157
|
added = [:CUSTOM, IRB.conf[:MEASURE_PROC][:CUSTOM], arg]
|
158
|
+
elsif block_given?
|
159
|
+
added = [:BLOCK, block, arg]
|
160
|
+
found = IRB.conf[:MEASURE_CALLBACKS].find{ |m| m[0] == added[0] && m[2] == added[2] }
|
161
|
+
if found
|
162
|
+
found[1] = block
|
163
|
+
return added
|
164
|
+
else
|
165
|
+
IRB.conf[:MEASURE_CALLBACKS] << added
|
166
|
+
return added
|
167
|
+
end
|
158
168
|
else
|
159
169
|
added = [:TIME, IRB.conf[:MEASURE_PROC][:TIME], arg]
|
160
170
|
end
|
data/lib/irb/input-method.rb
CHANGED
@@ -124,10 +124,22 @@ module IRB
|
|
124
124
|
|
125
125
|
# Use a File for IO with irb, see InputMethod
|
126
126
|
class FileInputMethod < InputMethod
|
127
|
+
class << self
|
128
|
+
def open(file, &block)
|
129
|
+
begin
|
130
|
+
io = new(file)
|
131
|
+
block.call(io)
|
132
|
+
ensure
|
133
|
+
io&.close
|
134
|
+
end
|
135
|
+
end
|
136
|
+
end
|
137
|
+
|
127
138
|
# Creates a new input method object
|
128
139
|
def initialize(file)
|
129
140
|
super
|
130
141
|
@io = IRB::MagicFile.open(file)
|
142
|
+
@external_encoding = @io.external_encoding
|
131
143
|
end
|
132
144
|
# The file name of this input method, usually given during initialization.
|
133
145
|
attr_reader :file_name
|
@@ -137,7 +149,7 @@ module IRB
|
|
137
149
|
#
|
138
150
|
# See IO#eof? for more information.
|
139
151
|
def eof?
|
140
|
-
@io.eof?
|
152
|
+
@io.closed? || @io.eof?
|
141
153
|
end
|
142
154
|
|
143
155
|
# Reads the next line from this input method.
|
@@ -150,13 +162,17 @@ module IRB
|
|
150
162
|
|
151
163
|
# The external encoding for standard input.
|
152
164
|
def encoding
|
153
|
-
@
|
165
|
+
@external_encoding
|
154
166
|
end
|
155
167
|
|
156
168
|
# For debug message
|
157
169
|
def inspect
|
158
170
|
'FileInputMethod'
|
159
171
|
end
|
172
|
+
|
173
|
+
def close
|
174
|
+
@io.close
|
175
|
+
end
|
160
176
|
end
|
161
177
|
|
162
178
|
begin
|
data/lib/irb/ruby-lex.rb
CHANGED
@@ -223,7 +223,10 @@ class RubyLex
|
|
223
223
|
throw :TERM_INPUT if @line == ''
|
224
224
|
else
|
225
225
|
@line_no += l.count("\n")
|
226
|
-
|
226
|
+
if l == "\n"
|
227
|
+
@exp_line_no += 1
|
228
|
+
next
|
229
|
+
end
|
227
230
|
@line.concat l
|
228
231
|
if @code_block_open or @ltype or @continue or @indent > 0
|
229
232
|
next
|
@@ -233,7 +236,7 @@ class RubyLex
|
|
233
236
|
@line.force_encoding(@io.encoding)
|
234
237
|
yield @line, @exp_line_no
|
235
238
|
end
|
236
|
-
|
239
|
+
raise TerminateLineInput if @io.eof?
|
237
240
|
@line = ''
|
238
241
|
@exp_line_no = @line_no
|
239
242
|
|
@@ -424,14 +427,30 @@ class RubyLex
|
|
424
427
|
indent
|
425
428
|
end
|
426
429
|
|
430
|
+
def is_method_calling?(tokens, index)
|
431
|
+
tk = tokens[index]
|
432
|
+
if tk[3].anybits?(Ripper::EXPR_CMDARG) and tk[1] == :on_ident
|
433
|
+
# The target method call to pass the block with "do".
|
434
|
+
return true
|
435
|
+
elsif tk[3].anybits?(Ripper::EXPR_ARG) and tk[1] == :on_ident
|
436
|
+
non_sp_index = tokens[0..(index - 1)].rindex{ |t| t[1] != :on_sp }
|
437
|
+
if non_sp_index
|
438
|
+
prev_tk = tokens[non_sp_index]
|
439
|
+
if prev_tk[3].anybits?(Ripper::EXPR_DOT) and prev_tk[1] == :on_period
|
440
|
+
# The target method call with receiver to pass the block with "do".
|
441
|
+
return true
|
442
|
+
end
|
443
|
+
end
|
444
|
+
end
|
445
|
+
false
|
446
|
+
end
|
447
|
+
|
427
448
|
def take_corresponding_syntax_to_kw_do(tokens, index)
|
428
449
|
syntax_of_do = nil
|
429
450
|
# Finding a syntax correnponding to "do".
|
430
451
|
index.downto(0) do |i|
|
431
452
|
tk = tokens[i]
|
432
453
|
# In "continue", the token isn't the corresponding syntax to "do".
|
433
|
-
#is_continue = process_continue(@tokens[0..(i - 1)])
|
434
|
-
# continue ではなく、直前に (:on_ignored_nl|:on_nl|:on_comment):on_sp* みたいなのがあるかどうかを調べる
|
435
454
|
non_sp_index = tokens[0..(i - 1)].rindex{ |t| t[1] != :on_sp }
|
436
455
|
first_in_fomula = false
|
437
456
|
if non_sp_index.nil?
|
@@ -439,8 +458,7 @@ class RubyLex
|
|
439
458
|
elsif [:on_ignored_nl, :on_nl, :on_comment].include?(tokens[non_sp_index][1])
|
440
459
|
first_in_fomula = true
|
441
460
|
end
|
442
|
-
if
|
443
|
-
# The target method call to pass the block with "do".
|
461
|
+
if is_method_calling?(tokens, i)
|
444
462
|
syntax_of_do = :method_calling
|
445
463
|
break if first_in_fomula
|
446
464
|
elsif tk[1] == :on_kw && %w{while until for}.include?(tk[2])
|
@@ -458,6 +476,34 @@ class RubyLex
|
|
458
476
|
syntax_of_do
|
459
477
|
end
|
460
478
|
|
479
|
+
def is_the_in_correspond_to_a_for(tokens, index)
|
480
|
+
syntax_of_in = nil
|
481
|
+
# Finding a syntax correnponding to "do".
|
482
|
+
index.downto(0) do |i|
|
483
|
+
tk = tokens[i]
|
484
|
+
# In "continue", the token isn't the corresponding syntax to "do".
|
485
|
+
non_sp_index = tokens[0..(i - 1)].rindex{ |t| t[1] != :on_sp }
|
486
|
+
first_in_fomula = false
|
487
|
+
if non_sp_index.nil?
|
488
|
+
first_in_fomula = true
|
489
|
+
elsif [:on_ignored_nl, :on_nl, :on_comment].include?(tokens[non_sp_index][1])
|
490
|
+
first_in_fomula = true
|
491
|
+
end
|
492
|
+
if tk[1] == :on_kw && tk[2] == 'for'
|
493
|
+
# A loop syntax in front of "do" found.
|
494
|
+
#
|
495
|
+
# while cond do # also "until" or "for"
|
496
|
+
# end
|
497
|
+
#
|
498
|
+
# This "do" doesn't increment indent because the loop syntax already
|
499
|
+
# incremented.
|
500
|
+
syntax_of_in = :for
|
501
|
+
end
|
502
|
+
break if first_in_fomula
|
503
|
+
end
|
504
|
+
syntax_of_in
|
505
|
+
end
|
506
|
+
|
461
507
|
def check_newline_depth_difference
|
462
508
|
depth_difference = 0
|
463
509
|
open_brace_on_line = 0
|
@@ -513,8 +559,12 @@ class RubyLex
|
|
513
559
|
unless t[3].allbits?(Ripper::EXPR_LABEL)
|
514
560
|
depth_difference += 1
|
515
561
|
end
|
516
|
-
when 'else', 'elsif', 'ensure', 'when'
|
562
|
+
when 'else', 'elsif', 'ensure', 'when'
|
517
563
|
depth_difference += 1
|
564
|
+
when 'in'
|
565
|
+
unless is_the_in_correspond_to_a_for(@tokens, index)
|
566
|
+
depth_difference += 1
|
567
|
+
end
|
518
568
|
when 'end'
|
519
569
|
depth_difference -= 1
|
520
570
|
end
|
data/lib/irb/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: irb
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.3.
|
4
|
+
version: 1.3.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Keiju ISHITSUKA
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-
|
11
|
+
date: 2021-02-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: reline
|
@@ -75,6 +75,7 @@ files:
|
|
75
75
|
- lib/irb/cmd/chws.rb
|
76
76
|
- lib/irb/cmd/fork.rb
|
77
77
|
- lib/irb/cmd/help.rb
|
78
|
+
- lib/irb/cmd/info.rb
|
78
79
|
- lib/irb/cmd/load.rb
|
79
80
|
- lib/irb/cmd/measure.rb
|
80
81
|
- lib/irb/cmd/nop.rb
|