irb 1.2.4 → 1.2.5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 0b760eaf9b7cc0f0029395a3a6de59420595d82f9610442b6b382576e030b86b
4
- data.tar.gz: 0e50bdf359e3ccb0e9ae5ec351e47d34601e68a0073a65d9bf310df3fbe95360
3
+ metadata.gz: de71d4d5a30eb0330993cf6bcd6de92b664d80b02cb924e17d0681df9528de64
4
+ data.tar.gz: 12eff61ad92be7895d0ecb010e06b97a7e26429e2fbcf040852e8691fbb4e8f3
5
5
  SHA512:
6
- metadata.gz: e82e4dac7bf886a261f2f2008c5e12eab54adfe75c5a42c6b870eb0c30c8dc87a18f48275857054ba19091737903e96a120ca69a2ccdb9cdcf3b494129997972
7
- data.tar.gz: 40b3e75fb3de5422b6cafaebd94ad0f4283999e957c719b86ef4ade5aca96e9eb47bb94794342985a557061326c93bff333e4b8950cbafe4239879301208e79c
6
+ metadata.gz: 5fdb0bb9301777bfba8e3b26c8b574de58594d8f8884e09704e97a04610c7c7360eeefeb1d3918a380f370856943b627873874bca0cbb3461010e67cf3072e22
7
+ data.tar.gz: e8ba6bd58ebd09ca4cf2a1863d57946d1c538be5873f91e469558d752e0a831783f2e173886d706b259c97c602b74ac7ef606492a11841fb62ee603401b238ad
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",
data/lib/irb.rb CHANGED
@@ -11,17 +11,17 @@
11
11
  #
12
12
  require "ripper"
13
13
 
14
- require "irb/init"
15
- require "irb/context"
16
- require "irb/extend-command"
14
+ require_relative "irb/init"
15
+ require_relative "irb/context"
16
+ require_relative "irb/extend-command"
17
17
 
18
- require "irb/ruby-lex"
19
- require "irb/input-method"
20
- require "irb/locale"
21
- require "irb/color"
18
+ require_relative "irb/ruby-lex"
19
+ require_relative "irb/input-method"
20
+ require_relative "irb/locale"
21
+ require_relative "irb/color"
22
22
 
23
- require "irb/version"
24
- require "irb/easter-egg"
23
+ require_relative "irb/version"
24
+ require_relative "irb/easter-egg"
25
25
 
26
26
  # IRB stands for "interactive Ruby" and is a tool to interactively execute Ruby
27
27
  # expressions read from the standard input.
@@ -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,17 +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 do |s|
103
- ":" + s.id2name.encode(Encoding.default_external)
104
- rescue Encoding::UndefinedConversionError
105
- # ignore
106
- end
107
- candidates.grep(/^#{Regexp.quote(sym)}/)
108
- else
109
- []
99
+ sym = $1
100
+ candidates = Symbol.all_symbols.collect do |s|
101
+ ":" + s.id2name.encode(Encoding.default_external)
102
+ rescue Encoding::UndefinedConversionError
103
+ # ignore
110
104
  end
105
+ candidates.grep(/^#{Regexp.quote(sym)}/)
111
106
 
112
107
  when /^::([A-Z][^:\.\(]*)$/
113
108
  # Absolute Constant or class methods
@@ -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
-
@@ -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
-
@@ -34,4 +34,3 @@ module IRB
34
34
  }
35
35
  end
36
36
  end
37
-
@@ -143,11 +143,17 @@ module IRB
143
143
  end
144
144
 
145
145
  begin
146
- require "readline"
147
146
  class ReadlineInputMethod < InputMethod
148
- include Readline
147
+ def self.initialize_readline
148
+ require "readline"
149
+ rescue LoadError
150
+ else
151
+ include ::Readline
152
+ end
153
+
149
154
  # Creates a new input method object using Readline
150
155
  def initialize
156
+ self.class.initialize_readline
151
157
  if Readline.respond_to?(:encoding_system_needs)
152
158
  IRB.__send__(:set_encoding, Readline.encoding_system_needs.name, override: false)
153
159
  end
@@ -212,12 +218,6 @@ module IRB
212
218
  @stdin.external_encoding
213
219
  end
214
220
 
215
- if Readline.respond_to?("basic_word_break_characters=")
216
- Readline.basic_word_break_characters = IRB::InputCompletor::BASIC_WORD_BREAK_CHARACTERS
217
- end
218
- Readline.completion_append_character = nil
219
- Readline.completion_proc = IRB::InputCompletor::CompletionProc
220
-
221
221
  # For debug message
222
222
  def inspect
223
223
  readline_impl = (defined?(Reline) && Readline == Reline) ? 'Reline' : 'ext/readline'
@@ -227,7 +227,6 @@ module IRB
227
227
  str
228
228
  end
229
229
  end
230
- rescue LoadError
231
230
  end
232
231
 
233
232
  class ReidlineInputMethod < InputMethod
@@ -251,7 +250,7 @@ module IRB
251
250
  Reline.completion_proc = IRB::InputCompletor::CompletionProc
252
251
  Reline.output_modifier_proc =
253
252
  if IRB.conf[:USE_COLORIZE]
254
- proc do |output, complete:|
253
+ proc do |output, complete: |
255
254
  next unless IRB::Color.colorable?
256
255
  IRB::Color.colorize_code(output, complete: complete)
257
256
  end
@@ -327,7 +326,7 @@ module IRB
327
326
  config = Reline::Config.new
328
327
  str = "ReidlineInputMethod with Reline #{Reline::VERSION}"
329
328
  if config.respond_to?(:inputrc_path)
330
- inputrc_path = config.inputrc_path
329
+ inputrc_path = File.expand_path(config.inputrc_path)
331
330
  else
332
331
  inputrc_path = File.expand_path(ENV['INPUTRC'] || '~/.inputrc')
333
332
  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
-
@@ -30,6 +30,18 @@ class RubyLex
30
30
  @prompt = nil
31
31
  end
32
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
+
33
45
  # io functions
34
46
  def set_input(io, p = nil, &block)
35
47
  @io = io
@@ -76,7 +88,10 @@ class RubyLex
76
88
 
77
89
  def ripper_lex_without_warning(code)
78
90
  verbose, $VERBOSE = $VERBOSE, nil
79
- 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
80
95
  $VERBOSE = verbose
81
96
  tokens
82
97
  end
@@ -210,7 +225,9 @@ class RubyLex
210
225
  when 'jruby'
211
226
  JRuby.compile_ir(code)
212
227
  else
213
- 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
214
231
  end
215
232
  rescue EncodingError
216
233
  # This is for a hash with invalid encoding symbol, {"\xAE": 1}
@@ -286,9 +303,33 @@ class RubyLex
286
303
 
287
304
  def process_nesting_level
288
305
  indent = 0
306
+ in_oneliner_def = nil
289
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
+
290
331
  case t[1]
291
- when :on_lbracket, :on_lbrace, :on_lparen
332
+ when :on_lbracket, :on_lbrace, :on_lparen, :on_tlambeg
292
333
  indent += 1
293
334
  when :on_rbracket, :on_rbrace, :on_rparen
294
335
  indent -= 1
@@ -307,7 +348,7 @@ class RubyLex
307
348
  when 'def', 'case', 'for', 'begin', 'class', 'module'
308
349
  indent += 1
309
350
  when 'if', 'unless', 'while', 'until'
310
- # postfix if/unless/while/until/rescue must be Ripper::EXPR_LABEL
351
+ # postfix if/unless/while/until must be Ripper::EXPR_LABEL
311
352
  indent += 1 unless t[3].allbits?(Ripper::EXPR_LABEL)
312
353
  when 'end'
313
354
  indent -= 1
@@ -321,7 +362,31 @@ class RubyLex
321
362
  def check_newline_depth_difference
322
363
  depth_difference = 0
323
364
  open_brace_on_line = 0
365
+ in_oneliner_def = nil
324
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
+
325
390
  case t[1]
326
391
  when :on_ignored_nl, :on_nl, :on_comment
327
392
  if index != (@tokens.size - 1)
@@ -333,7 +398,7 @@ class RubyLex
333
398
  next
334
399
  end
335
400
  case t[1]
336
- when :on_lbracket, :on_lbrace, :on_lparen
401
+ when :on_lbracket, :on_lbrace, :on_lparen, :on_tlambeg
337
402
  depth_difference += 1
338
403
  open_brace_on_line += 1
339
404
  when :on_rbracket, :on_rbrace, :on_rparen
@@ -352,12 +417,12 @@ class RubyLex
352
417
  end
353
418
  when 'def', 'case', 'for', 'begin', 'class', 'module'
354
419
  depth_difference += 1
355
- when 'if', 'unless', 'while', 'until'
420
+ when 'if', 'unless', 'while', 'until', 'rescue'
356
421
  # postfix if/unless/while/until/rescue must be Ripper::EXPR_LABEL
357
422
  unless t[3].allbits?(Ripper::EXPR_LABEL)
358
423
  depth_difference += 1
359
424
  end
360
- when 'else', 'elsif', 'rescue', 'ensure', 'when', 'in'
425
+ when 'else', 'elsif', 'ensure', 'when', 'in'
361
426
  depth_difference += 1
362
427
  end
363
428
  end
@@ -372,7 +437,36 @@ class RubyLex
372
437
  spaces_of_nest = []
373
438
  spaces_at_line_head = 0
374
439
  open_brace_on_line = 0
440
+ in_oneliner_def = nil
375
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
+
376
470
  case t[1]
377
471
  when :on_ignored_nl, :on_nl, :on_comment
378
472
  corresponding_token_depth = nil
@@ -387,7 +481,7 @@ class RubyLex
387
481
  next
388
482
  end
389
483
  case t[1]
390
- when :on_lbracket, :on_lbrace, :on_lparen
484
+ when :on_lbracket, :on_lbrace, :on_lparen, :on_tlambeg
391
485
  spaces_of_nest.push(spaces_at_line_head + open_brace_on_line * 2)
392
486
  open_brace_on_line += 1
393
487
  when :on_rbracket, :on_rbrace, :on_rparen
@@ -403,12 +497,16 @@ class RubyLex
403
497
  case t[2]
404
498
  when 'def', 'do', 'case', 'for', 'begin', 'class', 'module'
405
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
406
504
  when 'if', 'unless', 'while', 'until'
407
- # postfix if/unless/while/until/rescue must be Ripper::EXPR_LABEL
505
+ # postfix if/unless/while/until must be Ripper::EXPR_LABEL
408
506
  unless t[3].allbits?(Ripper::EXPR_LABEL)
409
507
  spaces_of_nest.push(spaces_at_line_head)
410
508
  end
411
- when 'else', 'elsif', 'rescue', 'ensure', 'when', 'in'
509
+ when 'else', 'elsif', 'ensure', 'when', 'in'
412
510
  corresponding_token_depth = spaces_of_nest.last
413
511
  when 'end'
414
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.4"
14
+ VERSION = "1.2.5"
15
15
  @RELEASE_VERSION = VERSION
16
- @LAST_UPDATE_DATE = "2020-05-02"
16
+ @LAST_UPDATE_DATE = "2020-09-14"
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.4
4
+ version: 1.2.5
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-05-02 00:00:00.000000000 Z
11
+ date: 2020-09-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: reline
@@ -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: []