irb 1.2.3 → 1.2.7
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/Gemfile +0 -5
- data/irb.gemspec +2 -2
- data/lib/irb.rb +48 -15
- data/lib/irb/cmd/fork.rb +0 -2
- data/lib/irb/cmd/pushws.rb +0 -1
- data/lib/irb/color.rb +23 -21
- data/lib/irb/completion.rb +7 -8
- data/lib/irb/context.rb +16 -5
- data/lib/irb/ext/change-ws.rb +0 -1
- data/lib/irb/ext/history.rb +0 -2
- data/lib/irb/ext/loader.rb +0 -1
- data/lib/irb/ext/save-history.rb +8 -5
- data/lib/irb/ext/tracer.rb +0 -1
- data/lib/irb/ext/use-loader.rb +1 -3
- data/lib/irb/ext/workspaces.rb +0 -1
- data/lib/irb/extend-command.rb +10 -3
- data/lib/irb/help.rb +0 -1
- data/lib/irb/init.rb +11 -0
- data/lib/irb/input-method.rb +53 -8
- data/lib/irb/inspector.rb +1 -5
- data/lib/irb/ruby-lex.rb +111 -10
- data/lib/irb/ruby_logo.aa +0 -1
- data/lib/irb/version.rb +2 -2
- data/lib/irb/xmp.rb +1 -1
- metadata +8 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 06c24147c0b5bb8af2c024688cee07a8c03ebfa3d804139ea3dc767dbb7a6b72
|
4
|
+
data.tar.gz: f963948ad72203fec9e8c5cd9d408451718675048c5ca8104fedbdcc34b07483
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: eefceccb8108975077b8158a8a8a7e03600e3180b039970e729bc3919b414de18505ac817be670a8c8dd108099ce232d8db06f6dc04a74e1c963e369962df158
|
7
|
+
data.tar.gz: e5ad1fcece6c08e3d807bead5e63950b1e34f6021ae75c40e647ae94bb075ec9e9b07b92e1665eb873e4397c69ab30d15794520e5ae8b765bb97127cddbaf8db
|
data/Gemfile
CHANGED
@@ -3,8 +3,3 @@ source "https://rubygems.org"
|
|
3
3
|
git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
|
4
4
|
|
5
5
|
gemspec
|
6
|
-
|
7
|
-
# TODO: remove this when reline with `Reline::Unicode.escape_for_print` is released.
|
8
|
-
if Gem::Version.new(RUBY_VERSION) < Gem::Version.new('2.7.0')
|
9
|
-
gem "reline", github: "ruby/reline"
|
10
|
-
end
|
data/irb.gemspec
CHANGED
@@ -14,7 +14,7 @@ Gem::Specification.new do |spec|
|
|
14
14
|
spec.summary = %q{Interactive Ruby command-line tool for REPL (Read Eval Print Loop).}
|
15
15
|
spec.description = %q{Interactive Ruby command-line tool for REPL (Read Eval Print Loop).}
|
16
16
|
spec.homepage = "https://github.com/ruby/irb"
|
17
|
-
spec.
|
17
|
+
spec.licenses = ["Ruby", "BSD-2-Clause"]
|
18
18
|
|
19
19
|
spec.files = [
|
20
20
|
".document",
|
@@ -78,7 +78,7 @@ Gem::Specification.new do |spec|
|
|
78
78
|
|
79
79
|
spec.required_ruby_version = Gem::Requirement.new(">= 2.5")
|
80
80
|
|
81
|
-
spec.add_dependency "reline", ">= 0.
|
81
|
+
spec.add_dependency "reline", ">= 0.1.5"
|
82
82
|
spec.add_development_dependency "bundler"
|
83
83
|
spec.add_development_dependency "rake"
|
84
84
|
end
|
data/lib/irb.rb
CHANGED
@@ -10,18 +10,19 @@
|
|
10
10
|
#
|
11
11
|
#
|
12
12
|
require "ripper"
|
13
|
+
require "reline"
|
13
14
|
|
14
|
-
|
15
|
-
|
16
|
-
|
15
|
+
require_relative "irb/init"
|
16
|
+
require_relative "irb/context"
|
17
|
+
require_relative "irb/extend-command"
|
17
18
|
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
19
|
+
require_relative "irb/ruby-lex"
|
20
|
+
require_relative "irb/input-method"
|
21
|
+
require_relative "irb/locale"
|
22
|
+
require_relative "irb/color"
|
22
23
|
|
23
|
-
|
24
|
-
|
24
|
+
require_relative "irb/version"
|
25
|
+
require_relative "irb/easter-egg"
|
25
26
|
|
26
27
|
# IRB stands for "interactive Ruby" and is a tool to interactively execute Ruby
|
27
28
|
# expressions read from the standard input.
|
@@ -271,7 +272,7 @@ require "irb/easter-egg"
|
|
271
272
|
# On the other hand, each conf in IRB@Command+line+options is used to
|
272
273
|
# individually configure IRB.irb.
|
273
274
|
#
|
274
|
-
# If a proc is set for IRB.conf[:IRB_RC]
|
275
|
+
# If a proc is set for <code>IRB.conf[:IRB_RC]</code>, its will be invoked after execution
|
275
276
|
# of that proc with the context of the current session as its argument. Each
|
276
277
|
# session can be configured using this mechanism.
|
277
278
|
#
|
@@ -399,7 +400,7 @@ module IRB
|
|
399
400
|
irb.run(@CONF)
|
400
401
|
end
|
401
402
|
|
402
|
-
# Calls each event hook of IRB.conf[:
|
403
|
+
# Calls each event hook of <code>IRB.conf[:TA_EXIT]</code> when the current session quits.
|
403
404
|
def IRB.irb_at_exit
|
404
405
|
@CONF[:AT_EXIT].each{|hook| hook.call}
|
405
406
|
end
|
@@ -538,7 +539,15 @@ module IRB
|
|
538
539
|
begin
|
539
540
|
line.untaint if RUBY_VERSION < '2.7'
|
540
541
|
@context.evaluate(line, line_no, exception: exc)
|
541
|
-
|
542
|
+
if @context.echo?
|
543
|
+
if assignment_expression?(line)
|
544
|
+
if @context.echo_on_assignment?
|
545
|
+
output_value(@context.echo_on_assignment? == :truncate)
|
546
|
+
end
|
547
|
+
else
|
548
|
+
output_value
|
549
|
+
end
|
550
|
+
end
|
542
551
|
rescue Interrupt => exc
|
543
552
|
rescue SystemExit, SignalException
|
544
553
|
raise
|
@@ -554,7 +563,8 @@ module IRB
|
|
554
563
|
|
555
564
|
def handle_exception(exc)
|
556
565
|
if exc.backtrace && exc.backtrace[0] =~ /\/irb(2)?(\/.*|-.*|\.rb)?:/ && exc.class.to_s !~ /^IRB/ &&
|
557
|
-
!(SyntaxError === exc)
|
566
|
+
!(SyntaxError === exc) && !(EncodingError === exc)
|
567
|
+
# The backtrace of invalid encoding hash (ex. {"\xAE": 1}) raises EncodingError without lineno.
|
558
568
|
irb_bug = true
|
559
569
|
else
|
560
570
|
irb_bug = false
|
@@ -736,9 +746,32 @@ module IRB
|
|
736
746
|
p
|
737
747
|
end
|
738
748
|
|
739
|
-
def output_value # :nodoc:
|
749
|
+
def output_value(omit = false) # :nodoc:
|
740
750
|
str = @context.inspect_last_value
|
741
|
-
multiline_p =
|
751
|
+
multiline_p = str.include?("\n")
|
752
|
+
if omit
|
753
|
+
winwidth = @context.io.winsize.last
|
754
|
+
if multiline_p
|
755
|
+
first_line = str.split("\n").first
|
756
|
+
result = @context.newline_before_multiline_output? ? (@context.return_format % first_line) : first_line
|
757
|
+
output_width = Reline::Unicode.calculate_width(result, true)
|
758
|
+
diff_size = output_width - Reline::Unicode.calculate_width(first_line, true)
|
759
|
+
if diff_size.positive? and output_width > winwidth
|
760
|
+
lines, _ = Reline::Unicode.split_by_width(first_line, winwidth - diff_size - 3)
|
761
|
+
str = "%s...\e[0m" % lines.first
|
762
|
+
multiline_p = false
|
763
|
+
else
|
764
|
+
str.gsub!(/(\A.*?\n).*/m, "\\1...")
|
765
|
+
end
|
766
|
+
else
|
767
|
+
output_width = Reline::Unicode.calculate_width(@context.return_format % str, true)
|
768
|
+
diff_size = output_width - Reline::Unicode.calculate_width(str, true)
|
769
|
+
if diff_size.positive? and output_width > winwidth
|
770
|
+
lines, _ = Reline::Unicode.split_by_width(str, winwidth - diff_size - 3)
|
771
|
+
str = "%s...\e[0m" % lines.first
|
772
|
+
end
|
773
|
+
end
|
774
|
+
end
|
742
775
|
if multiline_p && @context.newline_before_multiline_output?
|
743
776
|
printf @context.return_format, "\n#{str}"
|
744
777
|
else
|
data/lib/irb/cmd/fork.rb
CHANGED
data/lib/irb/cmd/pushws.rb
CHANGED
data/lib/irb/color.rb
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
require 'reline'
|
3
3
|
require 'ripper'
|
4
|
+
require 'irb/ruby-lex'
|
4
5
|
|
5
6
|
module IRB # :nodoc:
|
6
7
|
module Color
|
@@ -145,37 +146,38 @@ module IRB # :nodoc:
|
|
145
146
|
seen.delete(obj)
|
146
147
|
end
|
147
148
|
|
148
|
-
# Ripper::Lexer::Elem#state is supported on Ruby 2.5+
|
149
149
|
def supported?
|
150
150
|
return @supported if defined?(@supported)
|
151
|
-
@supported =
|
151
|
+
@supported = Ripper::Lexer::Elem.method_defined?(:state)
|
152
152
|
end
|
153
153
|
|
154
154
|
def scan(code, allow_last_error:)
|
155
155
|
pos = [1, 0]
|
156
156
|
|
157
157
|
verbose, $VERBOSE = $VERBOSE, nil
|
158
|
-
|
159
|
-
|
160
|
-
lexer.scan
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
158
|
+
RubyLex.compile_with_errors_suppressed(code) do |inner_code, line_no|
|
159
|
+
lexer = Ripper::Lexer.new(inner_code, '(ripper)', line_no)
|
160
|
+
if lexer.respond_to?(:scan) # Ruby 2.7+
|
161
|
+
lexer.scan.each do |elem|
|
162
|
+
str = elem.tok
|
163
|
+
next if allow_last_error and /meets end of file|unexpected end-of-input/ =~ elem.message
|
164
|
+
next if ([elem.pos[0], elem.pos[1] + str.bytesize] <=> pos) <= 0
|
165
|
+
|
166
|
+
str.each_line do |line|
|
167
|
+
if line.end_with?("\n")
|
168
|
+
pos[0] += 1
|
169
|
+
pos[1] = 0
|
170
|
+
else
|
171
|
+
pos[1] += line.bytesize
|
172
|
+
end
|
171
173
|
end
|
172
|
-
end
|
173
174
|
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
175
|
+
yield(elem.event, str, elem.state)
|
176
|
+
end
|
177
|
+
else
|
178
|
+
lexer.parse.each do |elem|
|
179
|
+
yield(elem.event, elem.tok, elem.state)
|
180
|
+
end
|
179
181
|
end
|
180
182
|
end
|
181
183
|
$VERBOSE = verbose
|
data/lib/irb/completion.rb
CHANGED
@@ -7,7 +7,6 @@
|
|
7
7
|
# From Original Idea of shugo@ruby-lang.org
|
8
8
|
#
|
9
9
|
|
10
|
-
require "readline"
|
11
10
|
autoload :RDoc, "rdoc"
|
12
11
|
|
13
12
|
module IRB
|
@@ -97,13 +96,13 @@ module IRB
|
|
97
96
|
when /^(:[^:.]*)$/
|
98
97
|
# Symbol
|
99
98
|
return nil if doc_namespace
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
[]
|
99
|
+
sym = $1
|
100
|
+
candidates = Symbol.all_symbols.collect do |s|
|
101
|
+
":" + s.id2name.encode(Encoding.default_external)
|
102
|
+
rescue Encoding::UndefinedConversionError
|
103
|
+
# ignore
|
106
104
|
end
|
105
|
+
candidates.grep(/^#{Regexp.quote(sym)}/)
|
107
106
|
|
108
107
|
when /^::([A-Z][^:\.\(]*)$/
|
109
108
|
# Absolute Constant or class methods
|
@@ -144,7 +143,7 @@ module IRB
|
|
144
143
|
select_message(receiver, message, candidates, sep)
|
145
144
|
end
|
146
145
|
|
147
|
-
when /^(?<num>-?(0[dbo])?[0-9_]+(
|
146
|
+
when /^(?<num>-?(?:0[dbo])?[0-9_]+(?:\.[0-9_]+)?(?:(?:[eE][+-]?[0-9]+)?i?|r)?)(?<sep>\.|::)(?<mes>[^.]*)$/
|
148
147
|
# Numeric
|
149
148
|
receiver = $~[:num]
|
150
149
|
sep = $~[:sep]
|
data/lib/irb/context.rb
CHANGED
@@ -131,7 +131,7 @@ module IRB
|
|
131
131
|
|
132
132
|
@echo_on_assignment = IRB.conf[:ECHO_ON_ASSIGNMENT]
|
133
133
|
if @echo_on_assignment.nil?
|
134
|
-
@echo_on_assignment =
|
134
|
+
@echo_on_assignment = :truncate
|
135
135
|
end
|
136
136
|
|
137
137
|
@newline_before_multiline_output = IRB.conf[:NEWLINE_BEFORE_MULTILINE_OUTPUT]
|
@@ -240,7 +240,7 @@ module IRB
|
|
240
240
|
attr_accessor :ignore_eof
|
241
241
|
# Whether to echo the return value to output or not.
|
242
242
|
#
|
243
|
-
# Uses IRB.conf[:ECHO] if available, or defaults to +true+.
|
243
|
+
# Uses <code>IRB.conf[:ECHO]</code> if available, or defaults to +true+.
|
244
244
|
#
|
245
245
|
# puts "hello"
|
246
246
|
# # hello
|
@@ -251,16 +251,27 @@ module IRB
|
|
251
251
|
attr_accessor :echo
|
252
252
|
# Whether to echo for assignment expressions
|
253
253
|
#
|
254
|
-
#
|
254
|
+
# If set to +false+, the value of assignment will not be shown.
|
255
|
+
#
|
256
|
+
# If set to +true+, the value of assignment will be shown.
|
257
|
+
#
|
258
|
+
# If set to +:truncate+, the value of assignment will be shown and truncated.
|
259
|
+
#
|
260
|
+
# It defaults to +:truncate+.
|
255
261
|
#
|
256
262
|
# a = "omg"
|
263
|
+
# #=> omg
|
264
|
+
# a = "omg" * 10
|
265
|
+
# #=> omgomgomgomgomgomgomg...
|
266
|
+
# IRB.CurrentContext.echo_on_assignment = false
|
267
|
+
# a = "omg"
|
257
268
|
# IRB.CurrentContext.echo_on_assignment = true
|
258
269
|
# a = "omg"
|
259
|
-
# #=>
|
270
|
+
# #=> omgomgomgomgomgomgomgomgomgomg
|
260
271
|
attr_accessor :echo_on_assignment
|
261
272
|
# Whether a newline is put before multiline output.
|
262
273
|
#
|
263
|
-
# Uses IRB.conf[:NEWLINE_BEFORE_MULTILINE_OUTPUT] if available,
|
274
|
+
# Uses <code>IRB.conf[:NEWLINE_BEFORE_MULTILINE_OUTPUT]</code> if available,
|
264
275
|
# or defaults to +true+.
|
265
276
|
#
|
266
277
|
# "abc\ndef"
|
data/lib/irb/ext/change-ws.rb
CHANGED
data/lib/irb/ext/history.rb
CHANGED
data/lib/irb/ext/loader.rb
CHANGED
data/lib/irb/ext/save-history.rb
CHANGED
@@ -9,8 +9,6 @@
|
|
9
9
|
#
|
10
10
|
#
|
11
11
|
|
12
|
-
require "readline"
|
13
|
-
|
14
12
|
module IRB
|
15
13
|
module HistorySavingAbility # :nodoc:
|
16
14
|
end
|
@@ -27,7 +25,7 @@ module IRB
|
|
27
25
|
IRB.conf[:SAVE_HISTORY]
|
28
26
|
end
|
29
27
|
|
30
|
-
remove_method
|
28
|
+
remove_method(:save_history=) if method_defined?(:save_history=)
|
31
29
|
# Sets <code>IRB.conf[:SAVE_HISTORY]</code> to the given +val+ and calls
|
32
30
|
# #init_save_history with this context.
|
33
31
|
#
|
@@ -89,7 +87,7 @@ module IRB
|
|
89
87
|
def save_history
|
90
88
|
return unless self.class.const_defined?(:HISTORY)
|
91
89
|
history = self.class::HISTORY
|
92
|
-
if num = IRB.conf[:SAVE_HISTORY] and (num = num.to_i)
|
90
|
+
if num = IRB.conf[:SAVE_HISTORY] and (num = num.to_i) != 0
|
93
91
|
if history_file = IRB.conf[:HISTORY_FILE]
|
94
92
|
history_file = File.expand_path(history_file)
|
95
93
|
end
|
@@ -109,7 +107,12 @@ module IRB
|
|
109
107
|
|
110
108
|
open(history_file, "w:#{IRB.conf[:LC_MESSAGES].encoding}", 0600) do |f|
|
111
109
|
hist = history.map{ |l| l.split("\n").join("\\\n") }
|
112
|
-
|
110
|
+
begin
|
111
|
+
hist = hist.last(num) if hist.size > num and num > 0
|
112
|
+
rescue RangeError # bignum too big to convert into `long'
|
113
|
+
# Do nothing because the bignum should be treated as inifinity
|
114
|
+
end
|
115
|
+
f.puts(hist)
|
113
116
|
end
|
114
117
|
end
|
115
118
|
end
|
data/lib/irb/ext/tracer.rb
CHANGED
data/lib/irb/ext/use-loader.rb
CHANGED
@@ -47,7 +47,7 @@ module IRB
|
|
47
47
|
alias use_loader? use_loader
|
48
48
|
|
49
49
|
remove_method :use_loader= if method_defined?(:use_loader=)
|
50
|
-
# Sets IRB.conf[:USE_LOADER]
|
50
|
+
# Sets <code>IRB.conf[:USE_LOADER]</code>
|
51
51
|
#
|
52
52
|
# See #use_loader for more information.
|
53
53
|
def use_loader=(opt)
|
@@ -73,5 +73,3 @@ module IRB
|
|
73
73
|
end
|
74
74
|
end
|
75
75
|
end
|
76
|
-
|
77
|
-
|
data/lib/irb/ext/workspaces.rb
CHANGED
data/lib/irb/extend-command.rb
CHANGED
@@ -121,6 +121,10 @@ module IRB # :nodoc:
|
|
121
121
|
[:help, NO_OVERRIDE],
|
122
122
|
],
|
123
123
|
|
124
|
+
[
|
125
|
+
:irb_info, :Info, "irb/cmd/info"
|
126
|
+
],
|
127
|
+
|
124
128
|
]
|
125
129
|
|
126
130
|
# Installs the default irb commands:
|
@@ -169,11 +173,14 @@ module IRB # :nodoc:
|
|
169
173
|
args << "&block"
|
170
174
|
args = args.join(", ")
|
171
175
|
line = __LINE__; eval %[
|
172
|
-
|
173
|
-
|
176
|
+
unless self.class.class_variable_defined?(:@@#{cmd_name}_)
|
177
|
+
self.class.class_variable_set(:@@#{cmd_name}_, true)
|
178
|
+
def #{cmd_name}_(\#{args})
|
179
|
+
ExtendCommand::#{cmd_class}.execute(irb_context, \#{args})
|
180
|
+
end
|
174
181
|
end
|
175
182
|
], nil, __FILE__, line
|
176
|
-
send :#{cmd_name}, *opts, &b
|
183
|
+
send :#{cmd_name}_, *opts, &b
|
177
184
|
end
|
178
185
|
], nil, __FILE__, line
|
179
186
|
else
|
data/lib/irb/help.rb
CHANGED
data/lib/irb/init.rb
CHANGED
@@ -177,6 +177,8 @@ module IRB # :nodoc:
|
|
177
177
|
@CONF[:ECHO_ON_ASSIGNMENT] = true
|
178
178
|
when "--noecho-on-assignment"
|
179
179
|
@CONF[:ECHO_ON_ASSIGNMENT] = false
|
180
|
+
when "--truncate-echo-on-assignment"
|
181
|
+
@CONF[:ECHO_ON_ASSIGNMENT] = :truncate
|
180
182
|
when "--verbose"
|
181
183
|
@CONF[:VERBOSE] = true
|
182
184
|
when "--noverbose"
|
@@ -271,10 +273,19 @@ module IRB # :nodoc:
|
|
271
273
|
if irbrc = ENV["IRBRC"]
|
272
274
|
yield proc{|rc| rc == "rc" ? irbrc : irbrc+rc}
|
273
275
|
end
|
276
|
+
if xdg_config_home = ENV["XDG_CONFIG_HOME"]
|
277
|
+
irb_home = File.join(xdg_config_home, "irb")
|
278
|
+
unless File.exist? irb_home
|
279
|
+
require 'fileutils'
|
280
|
+
FileUtils.mkdir_p irb_home
|
281
|
+
end
|
282
|
+
yield proc{|rc| irb_home + "/irb#{rc}"}
|
283
|
+
end
|
274
284
|
if home = ENV["HOME"]
|
275
285
|
yield proc{|rc| home+"/.irb#{rc}"}
|
276
286
|
end
|
277
287
|
current_dir = Dir.pwd
|
288
|
+
yield proc{|rc| current_dir+"/.config/irb/irb#{rc}"}
|
278
289
|
yield proc{|rc| current_dir+"/.irb#{rc}"}
|
279
290
|
yield proc{|rc| current_dir+"/irb#{rc.sub(/\A_?/, '.')}"}
|
280
291
|
yield proc{|rc| current_dir+"/_irb#{rc}"}
|
data/lib/irb/input-method.rb
CHANGED
@@ -12,6 +12,7 @@
|
|
12
12
|
require_relative 'src_encoding'
|
13
13
|
require_relative 'magic-file'
|
14
14
|
require_relative 'completion'
|
15
|
+
require 'io/console'
|
15
16
|
require 'reline'
|
16
17
|
|
17
18
|
module IRB
|
@@ -36,6 +37,14 @@ module IRB
|
|
36
37
|
end
|
37
38
|
public :gets
|
38
39
|
|
40
|
+
def winsize
|
41
|
+
if instance_variable_defined?(:@stdout)
|
42
|
+
@stdout.winsize
|
43
|
+
else
|
44
|
+
[24, 80]
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
39
48
|
# Whether this input method is still readable when there is no more data to
|
40
49
|
# read.
|
41
50
|
#
|
@@ -43,6 +52,11 @@ module IRB
|
|
43
52
|
def readable_after_eof?
|
44
53
|
false
|
45
54
|
end
|
55
|
+
|
56
|
+
# For debug message
|
57
|
+
def inspect
|
58
|
+
'Abstract InputMethod'
|
59
|
+
end
|
46
60
|
end
|
47
61
|
|
48
62
|
class StdioInputMethod < InputMethod
|
@@ -93,6 +107,11 @@ module IRB
|
|
93
107
|
def encoding
|
94
108
|
@stdin.external_encoding
|
95
109
|
end
|
110
|
+
|
111
|
+
# For debug message
|
112
|
+
def inspect
|
113
|
+
'StdioInputMethod'
|
114
|
+
end
|
96
115
|
end
|
97
116
|
|
98
117
|
# Use a File for IO with irb, see InputMethod
|
@@ -125,14 +144,25 @@ module IRB
|
|
125
144
|
def encoding
|
126
145
|
@io.external_encoding
|
127
146
|
end
|
147
|
+
|
148
|
+
# For debug message
|
149
|
+
def inspect
|
150
|
+
'FileInputMethod'
|
151
|
+
end
|
128
152
|
end
|
129
153
|
|
130
154
|
begin
|
131
|
-
require "readline"
|
132
155
|
class ReadlineInputMethod < InputMethod
|
133
|
-
|
156
|
+
def self.initialize_readline
|
157
|
+
require "readline"
|
158
|
+
rescue LoadError
|
159
|
+
else
|
160
|
+
include ::Readline
|
161
|
+
end
|
162
|
+
|
134
163
|
# Creates a new input method object using Readline
|
135
164
|
def initialize
|
165
|
+
self.class.initialize_readline
|
136
166
|
if Readline.respond_to?(:encoding_system_needs)
|
137
167
|
IRB.__send__(:set_encoding, Readline.encoding_system_needs.name, override: false)
|
138
168
|
end
|
@@ -197,13 +227,15 @@ module IRB
|
|
197
227
|
@stdin.external_encoding
|
198
228
|
end
|
199
229
|
|
200
|
-
|
201
|
-
|
230
|
+
# For debug message
|
231
|
+
def inspect
|
232
|
+
readline_impl = (defined?(Reline) && Readline == Reline) ? 'Reline' : 'ext/readline'
|
233
|
+
str = "ReadlineInputMethod with #{readline_impl} #{Readline::VERSION}"
|
234
|
+
inputrc_path = File.expand_path(ENV['INPUTRC'] || '~/.inputrc')
|
235
|
+
str += " and #{inputrc_path}" if File.exist?(inputrc_path)
|
236
|
+
str
|
202
237
|
end
|
203
|
-
Readline.completion_append_character = nil
|
204
|
-
Readline.completion_proc = IRB::InputCompletor::CompletionProc
|
205
238
|
end
|
206
|
-
rescue LoadError
|
207
239
|
end
|
208
240
|
|
209
241
|
class ReidlineInputMethod < InputMethod
|
@@ -227,7 +259,7 @@ module IRB
|
|
227
259
|
Reline.completion_proc = IRB::InputCompletor::CompletionProc
|
228
260
|
Reline.output_modifier_proc =
|
229
261
|
if IRB.conf[:USE_COLORIZE]
|
230
|
-
proc do |output, complete
|
262
|
+
proc do |output, complete: |
|
231
263
|
next unless IRB::Color.colorable?
|
232
264
|
IRB::Color.colorize_code(output, complete: complete)
|
233
265
|
end
|
@@ -297,5 +329,18 @@ module IRB
|
|
297
329
|
def encoding
|
298
330
|
@stdin.external_encoding
|
299
331
|
end
|
332
|
+
|
333
|
+
# For debug message
|
334
|
+
def inspect
|
335
|
+
config = Reline::Config.new
|
336
|
+
str = "ReidlineInputMethod with Reline #{Reline::VERSION}"
|
337
|
+
if config.respond_to?(:inputrc_path)
|
338
|
+
inputrc_path = File.expand_path(config.inputrc_path)
|
339
|
+
else
|
340
|
+
inputrc_path = File.expand_path(ENV['INPUTRC'] || '~/.inputrc')
|
341
|
+
end
|
342
|
+
str += " and #{inputrc_path}" if File.exist?(inputrc_path)
|
343
|
+
str
|
344
|
+
end
|
300
345
|
end
|
301
346
|
end
|
data/lib/irb/inspector.rb
CHANGED
@@ -113,6 +113,7 @@ module IRB # :nodoc:
|
|
113
113
|
result
|
114
114
|
rescue NoMethodError
|
115
115
|
puts "(Object doesn't support #inspect)"
|
116
|
+
''
|
116
117
|
end
|
117
118
|
}
|
118
119
|
Inspector.def_inspector([:pp, :pretty_inspect], proc{require "pp"}){|v|
|
@@ -135,8 +136,3 @@ module IRB # :nodoc:
|
|
135
136
|
Marshal.dump(v)
|
136
137
|
}
|
137
138
|
end
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
data/lib/irb/ruby-lex.rb
CHANGED
@@ -11,6 +11,7 @@
|
|
11
11
|
#
|
12
12
|
|
13
13
|
require "ripper"
|
14
|
+
require "jruby" if RUBY_ENGINE == "jruby"
|
14
15
|
|
15
16
|
# :stopdoc:
|
16
17
|
class RubyLex
|
@@ -29,6 +30,18 @@ class RubyLex
|
|
29
30
|
@prompt = nil
|
30
31
|
end
|
31
32
|
|
33
|
+
def self.compile_with_errors_suppressed(code)
|
34
|
+
line_no = 1
|
35
|
+
begin
|
36
|
+
result = yield code, line_no
|
37
|
+
rescue ArgumentError
|
38
|
+
code = ";\n#{code}"
|
39
|
+
line_no = 0
|
40
|
+
result = yield code, line_no
|
41
|
+
end
|
42
|
+
result
|
43
|
+
end
|
44
|
+
|
32
45
|
# io functions
|
33
46
|
def set_input(io, p = nil, &block)
|
34
47
|
@io = io
|
@@ -75,7 +88,10 @@ class RubyLex
|
|
75
88
|
|
76
89
|
def ripper_lex_without_warning(code)
|
77
90
|
verbose, $VERBOSE = $VERBOSE, nil
|
78
|
-
tokens =
|
91
|
+
tokens = nil
|
92
|
+
self.class.compile_with_errors_suppressed(code) do |inner_code, line_no|
|
93
|
+
tokens = Ripper.lex(inner_code, '-', line_no)
|
94
|
+
end
|
79
95
|
$VERBOSE = verbose
|
80
96
|
tokens
|
81
97
|
end
|
@@ -209,8 +225,12 @@ class RubyLex
|
|
209
225
|
when 'jruby'
|
210
226
|
JRuby.compile_ir(code)
|
211
227
|
else
|
212
|
-
|
228
|
+
self.class.compile_with_errors_suppressed(code) do |inner_code, line_no|
|
229
|
+
RubyVM::InstructionSequence.compile(inner_code, nil, nil, line_no)
|
230
|
+
end
|
213
231
|
end
|
232
|
+
rescue EncodingError
|
233
|
+
# This is for a hash with invalid encoding symbol, {"\xAE": 1}
|
214
234
|
rescue SyntaxError => e
|
215
235
|
case e.message
|
216
236
|
when /unterminated (?:string|regexp) meets end of file/
|
@@ -283,9 +303,33 @@ class RubyLex
|
|
283
303
|
|
284
304
|
def process_nesting_level
|
285
305
|
indent = 0
|
306
|
+
in_oneliner_def = nil
|
286
307
|
@tokens.each_with_index { |t, index|
|
308
|
+
# detecting one-liner method definition
|
309
|
+
if in_oneliner_def.nil?
|
310
|
+
if t[3].allbits?(Ripper::EXPR_ENDFN)
|
311
|
+
in_oneliner_def = :ENDFN
|
312
|
+
end
|
313
|
+
else
|
314
|
+
if t[3].allbits?(Ripper::EXPR_ENDFN)
|
315
|
+
# continuing
|
316
|
+
elsif t[3].allbits?(Ripper::EXPR_BEG)
|
317
|
+
if t[2] == '='
|
318
|
+
in_oneliner_def = :BODY
|
319
|
+
end
|
320
|
+
elsif t[3].allbits?(Ripper::EXPR_END)
|
321
|
+
if in_oneliner_def == :BODY
|
322
|
+
# one-liner method definition
|
323
|
+
indent -= 1
|
324
|
+
end
|
325
|
+
in_oneliner_def = nil
|
326
|
+
else
|
327
|
+
in_oneliner_def = nil
|
328
|
+
end
|
329
|
+
end
|
330
|
+
|
287
331
|
case t[1]
|
288
|
-
when :on_lbracket, :on_lbrace, :on_lparen
|
332
|
+
when :on_lbracket, :on_lbrace, :on_lparen, :on_tlambeg
|
289
333
|
indent += 1
|
290
334
|
when :on_rbracket, :on_rbrace, :on_rparen
|
291
335
|
indent -= 1
|
@@ -304,7 +348,7 @@ class RubyLex
|
|
304
348
|
when 'def', 'case', 'for', 'begin', 'class', 'module'
|
305
349
|
indent += 1
|
306
350
|
when 'if', 'unless', 'while', 'until'
|
307
|
-
# postfix if/unless/while/until
|
351
|
+
# postfix if/unless/while/until must be Ripper::EXPR_LABEL
|
308
352
|
indent += 1 unless t[3].allbits?(Ripper::EXPR_LABEL)
|
309
353
|
when 'end'
|
310
354
|
indent -= 1
|
@@ -318,7 +362,31 @@ class RubyLex
|
|
318
362
|
def check_newline_depth_difference
|
319
363
|
depth_difference = 0
|
320
364
|
open_brace_on_line = 0
|
365
|
+
in_oneliner_def = nil
|
321
366
|
@tokens.each_with_index do |t, index|
|
367
|
+
# detecting one-liner method definition
|
368
|
+
if in_oneliner_def.nil?
|
369
|
+
if t[3].allbits?(Ripper::EXPR_ENDFN)
|
370
|
+
in_oneliner_def = :ENDFN
|
371
|
+
end
|
372
|
+
else
|
373
|
+
if t[3].allbits?(Ripper::EXPR_ENDFN)
|
374
|
+
# continuing
|
375
|
+
elsif t[3].allbits?(Ripper::EXPR_BEG)
|
376
|
+
if t[2] == '='
|
377
|
+
in_oneliner_def = :BODY
|
378
|
+
end
|
379
|
+
elsif t[3].allbits?(Ripper::EXPR_END)
|
380
|
+
if in_oneliner_def == :BODY
|
381
|
+
# one[-liner method definition
|
382
|
+
depth_difference -= 1
|
383
|
+
end
|
384
|
+
in_oneliner_def = nil
|
385
|
+
else
|
386
|
+
in_oneliner_def = nil
|
387
|
+
end
|
388
|
+
end
|
389
|
+
|
322
390
|
case t[1]
|
323
391
|
when :on_ignored_nl, :on_nl, :on_comment
|
324
392
|
if index != (@tokens.size - 1)
|
@@ -330,7 +398,7 @@ class RubyLex
|
|
330
398
|
next
|
331
399
|
end
|
332
400
|
case t[1]
|
333
|
-
when :on_lbracket, :on_lbrace, :on_lparen
|
401
|
+
when :on_lbracket, :on_lbrace, :on_lparen, :on_tlambeg
|
334
402
|
depth_difference += 1
|
335
403
|
open_brace_on_line += 1
|
336
404
|
when :on_rbracket, :on_rbrace, :on_rparen
|
@@ -349,12 +417,12 @@ class RubyLex
|
|
349
417
|
end
|
350
418
|
when 'def', 'case', 'for', 'begin', 'class', 'module'
|
351
419
|
depth_difference += 1
|
352
|
-
when 'if', 'unless', 'while', 'until'
|
420
|
+
when 'if', 'unless', 'while', 'until', 'rescue'
|
353
421
|
# postfix if/unless/while/until/rescue must be Ripper::EXPR_LABEL
|
354
422
|
unless t[3].allbits?(Ripper::EXPR_LABEL)
|
355
423
|
depth_difference += 1
|
356
424
|
end
|
357
|
-
when 'else', 'elsif', '
|
425
|
+
when 'else', 'elsif', 'ensure', 'when', 'in'
|
358
426
|
depth_difference += 1
|
359
427
|
end
|
360
428
|
end
|
@@ -369,7 +437,36 @@ class RubyLex
|
|
369
437
|
spaces_of_nest = []
|
370
438
|
spaces_at_line_head = 0
|
371
439
|
open_brace_on_line = 0
|
440
|
+
in_oneliner_def = nil
|
372
441
|
@tokens.each_with_index do |t, index|
|
442
|
+
# detecting one-liner method definition
|
443
|
+
if in_oneliner_def.nil?
|
444
|
+
if t[3].allbits?(Ripper::EXPR_ENDFN)
|
445
|
+
in_oneliner_def = :ENDFN
|
446
|
+
end
|
447
|
+
else
|
448
|
+
if t[3].allbits?(Ripper::EXPR_ENDFN)
|
449
|
+
# continuing
|
450
|
+
elsif t[3].allbits?(Ripper::EXPR_BEG)
|
451
|
+
if t[2] == '='
|
452
|
+
in_oneliner_def = :BODY
|
453
|
+
end
|
454
|
+
elsif t[3].allbits?(Ripper::EXPR_END)
|
455
|
+
if in_oneliner_def == :BODY
|
456
|
+
# one-liner method definition
|
457
|
+
if is_first_printable_of_line
|
458
|
+
corresponding_token_depth = spaces_of_nest.pop
|
459
|
+
else
|
460
|
+
spaces_of_nest.pop
|
461
|
+
corresponding_token_depth = nil
|
462
|
+
end
|
463
|
+
end
|
464
|
+
in_oneliner_def = nil
|
465
|
+
else
|
466
|
+
in_oneliner_def = nil
|
467
|
+
end
|
468
|
+
end
|
469
|
+
|
373
470
|
case t[1]
|
374
471
|
when :on_ignored_nl, :on_nl, :on_comment
|
375
472
|
corresponding_token_depth = nil
|
@@ -384,7 +481,7 @@ class RubyLex
|
|
384
481
|
next
|
385
482
|
end
|
386
483
|
case t[1]
|
387
|
-
when :on_lbracket, :on_lbrace, :on_lparen
|
484
|
+
when :on_lbracket, :on_lbrace, :on_lparen, :on_tlambeg
|
388
485
|
spaces_of_nest.push(spaces_at_line_head + open_brace_on_line * 2)
|
389
486
|
open_brace_on_line += 1
|
390
487
|
when :on_rbracket, :on_rbrace, :on_rparen
|
@@ -400,12 +497,16 @@ class RubyLex
|
|
400
497
|
case t[2]
|
401
498
|
when 'def', 'do', 'case', 'for', 'begin', 'class', 'module'
|
402
499
|
spaces_of_nest.push(spaces_at_line_head)
|
500
|
+
when 'rescue'
|
501
|
+
unless t[3].allbits?(Ripper::EXPR_LABEL)
|
502
|
+
corresponding_token_depth = spaces_of_nest.last
|
503
|
+
end
|
403
504
|
when 'if', 'unless', 'while', 'until'
|
404
|
-
# postfix if/unless/while/until
|
505
|
+
# postfix if/unless/while/until must be Ripper::EXPR_LABEL
|
405
506
|
unless t[3].allbits?(Ripper::EXPR_LABEL)
|
406
507
|
spaces_of_nest.push(spaces_at_line_head)
|
407
508
|
end
|
408
|
-
when 'else', 'elsif', '
|
509
|
+
when 'else', 'elsif', 'ensure', 'when', 'in'
|
409
510
|
corresponding_token_depth = spaces_of_nest.last
|
410
511
|
when 'end'
|
411
512
|
if is_first_printable_of_line
|
data/lib/irb/ruby_logo.aa
CHANGED
data/lib/irb/version.rb
CHANGED
data/lib/irb/xmp.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.2.
|
4
|
+
version: 1.2.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Keiju ISHITSUKA
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-
|
11
|
+
date: 2020-09-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: reline
|
@@ -16,14 +16,14 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: 0.
|
19
|
+
version: 0.1.5
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: 0.
|
26
|
+
version: 0.1.5
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: bundler
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -116,9 +116,10 @@ files:
|
|
116
116
|
- man/irb.1
|
117
117
|
homepage: https://github.com/ruby/irb
|
118
118
|
licenses:
|
119
|
+
- Ruby
|
119
120
|
- BSD-2-Clause
|
120
121
|
metadata: {}
|
121
|
-
post_install_message:
|
122
|
+
post_install_message:
|
122
123
|
rdoc_options: []
|
123
124
|
require_paths:
|
124
125
|
- lib
|
@@ -134,7 +135,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
134
135
|
version: '0'
|
135
136
|
requirements: []
|
136
137
|
rubygems_version: 3.1.2
|
137
|
-
signing_key:
|
138
|
+
signing_key:
|
138
139
|
specification_version: 4
|
139
140
|
summary: Interactive Ruby command-line tool for REPL (Read Eval Print Loop).
|
140
141
|
test_files: []
|