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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 455620204255c774ac81923f080599183cda03da4990605ccdd516b17e60bfed
4
- data.tar.gz: e1617267b3c9b240dd4a5115549ad2c333f054dee05eaa8408071126a4e37eab
3
+ metadata.gz: 06c24147c0b5bb8af2c024688cee07a8c03ebfa3d804139ea3dc767dbb7a6b72
4
+ data.tar.gz: f963948ad72203fec9e8c5cd9d408451718675048c5ca8104fedbdcc34b07483
5
5
  SHA512:
6
- metadata.gz: 9842eb424f88442ff8915b15ebf1754ccb95a86643ada5619a750829d80ccb513e39f65f4b804fbb4d23f18439cd6c09f47d64fe7d2f01c069d459f2a70c685a
7
- data.tar.gz: c6e859ae895a47df11eed8298e943b6b841f6412ae507a16ca852df235aaf8fc0f227752f3d68060d217945829aae5a329f9868b8dd15b1837a6ffc191f911b7
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
@@ -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.license = "BSD-2-Clause"
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.0.1"
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
- require "irb/init"
15
- require "irb/context"
16
- require "irb/extend-command"
15
+ require_relative "irb/init"
16
+ require_relative "irb/context"
17
+ require_relative "irb/extend-command"
17
18
 
18
- require "irb/ruby-lex"
19
- require "irb/input-method"
20
- require "irb/locale"
21
- require "irb/color"
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
- require "irb/version"
24
- require "irb/easter-egg"
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], its will be invoked after execution
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[:AT_EXIT] when the current session quits.
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
- output_value if @context.echo? && (@context.echo_on_assignment? || !assignment_expression?(line))
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 = /\A.*\Z/ !~ str
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
@@ -35,5 +35,3 @@ module IRB
35
35
  end
36
36
  end
37
37
  # :startdoc:
38
-
39
-
@@ -38,4 +38,3 @@ module IRB
38
38
  end
39
39
  end
40
40
  # :startdoc:
41
-
@@ -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 = Gem::Version.new(RUBY_VERSION) >= Gem::Version.new('2.5.0')
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
- lexer = Ripper::Lexer.new(code)
159
- if lexer.respond_to?(:scan) # Ruby 2.7+
160
- lexer.scan.each do |elem|
161
- str = elem.tok
162
- next if allow_last_error and /meets end of file|unexpected end-of-input/ =~ elem.message
163
- next if ([elem.pos[0], elem.pos[1] + str.bytesize] <=> pos) <= 0
164
-
165
- str.each_line do |line|
166
- if line.end_with?("\n")
167
- pos[0] += 1
168
- pos[1] = 0
169
- else
170
- pos[1] += line.bytesize
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
- yield(elem.event, str, elem.state)
175
- end
176
- else
177
- lexer.parse.each do |elem|
178
- yield(elem.event, elem.tok, elem.state)
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
@@ -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
- if Symbol.respond_to?(:all_symbols)
101
- sym = $1
102
- candidates = Symbol.all_symbols.collect{|s| ":" + s.id2name}
103
- candidates.grep(/^#{Regexp.quote(sym)}/)
104
- else
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_]+(\.[0-9_]+)?(([eE][+-]?[0-9]+)?i?|r)?)(?<sep>\.|::)(?<mes>[^.]*)$/
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]
@@ -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 = false
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
- # Uses IRB.conf[:ECHO_ON_ASSIGNMENT] if available, or defaults to +false+.
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
- # #=> omg
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"
@@ -43,4 +43,3 @@ module IRB # :nodoc:
43
43
  end
44
44
  end
45
45
  end
46
-
@@ -153,5 +153,3 @@ module IRB # :nodoc:
153
153
  end
154
154
  end
155
155
  end
156
-
157
-
@@ -126,4 +126,3 @@ module IRB # :nodoc:
126
126
  end
127
127
  end
128
128
  end
129
-
@@ -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 :save_history= if method_defined?(:save_history=)
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) > 0
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
- f.puts(hist[-num..-1] || hist)
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
@@ -82,4 +82,3 @@ module IRB
82
82
 
83
83
  IRB.initialize_tracer
84
84
  end
85
-
@@ -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
-
@@ -64,4 +64,3 @@ module IRB # :nodoc:
64
64
  end
65
65
  end
66
66
  end
67
-
@@ -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
- def #{cmd_name}(\#{args})
173
- ExtendCommand::#{cmd_class}.execute(irb_context, \#{args})
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
@@ -34,4 +34,3 @@ module IRB
34
34
  }
35
35
  end
36
36
  end
37
-
@@ -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}"}
@@ -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
- include Readline
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
- if Readline.respond_to?("basic_word_break_characters=")
201
- Readline.basic_word_break_characters = IRB::InputCompletor::BASIC_WORD_BREAK_CHARACTERS
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
@@ -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
-
@@ -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 = Ripper.lex(code)
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
- RubyVM::InstructionSequence.compile(code)
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/rescue must be Ripper::EXPR_LABEL
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', 'rescue', 'ensure', 'when', 'in'
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/rescue must be Ripper::EXPR_LABEL
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', 'rescue', 'ensure', 'when', 'in'
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
@@ -35,4 +35,3 @@
35
35
  m7 NW H N HSVO1z=?11-
36
36
  NgTH bB kH WBHWWHBHWmQgg&gggggNNN
37
37
  NNggggggNN
38
-
@@ -11,7 +11,7 @@
11
11
  #
12
12
 
13
13
  module IRB # :nodoc:
14
- VERSION = "1.2.3"
14
+ VERSION = "1.2.7"
15
15
  @RELEASE_VERSION = VERSION
16
- @LAST_UPDATE_DATE = "2020-02-15"
16
+ @LAST_UPDATE_DATE = "2020-09-19"
17
17
  end
@@ -10,7 +10,7 @@
10
10
  #
11
11
  #
12
12
 
13
- require "irb"
13
+ require_relative "../irb"
14
14
  require_relative "frame"
15
15
 
16
16
  # An example printer for irb.
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.3
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-02-15 00:00:00.000000000 Z
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.0.1
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.0.1
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: []