irb 1.3.1 → 1.3.6

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.
@@ -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
- @io.external_encoding
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
@@ -264,6 +280,7 @@ module IRB
264
280
  Reline.basic_word_break_characters = IRB::InputCompletor::BASIC_WORD_BREAK_CHARACTERS
265
281
  end
266
282
  Reline.completion_append_character = nil
283
+ Reline.completer_quote_characters = ''
267
284
  Reline.completion_proc = IRB::InputCompletor::CompletionProc
268
285
  Reline.output_modifier_proc =
269
286
  if IRB.conf[:USE_COLORIZE]
@@ -10,7 +10,7 @@
10
10
  #
11
11
  #
12
12
  Usage: irb.rb [options] [programfile] [arguments]
13
- -f Suppress read of ~/.irbrc
13
+ -f Suppress read of ~/.irbrc
14
14
  -d Set $DEBUG to true (same as `ruby -d')
15
15
  -r load-module Same as `ruby -r'
16
16
  -I path Specify $LOAD_PATH directory
@@ -18,7 +18,7 @@ Usage: irb.rb [options] [programfile] [arguments]
18
18
  -E enc Same as `ruby -E`
19
19
  -w Same as `ruby -w`
20
20
  -W[level=2] Same as `ruby -W`
21
- --context-mode n Set n[0-3] to method to create Binding Object,
21
+ --context-mode n Set n[0-4] to method to create Binding Object,
22
22
  when new workspace was created
23
23
  --echo Show result(default)
24
24
  --noecho Don't show result
@@ -31,8 +31,8 @@ Usage: irb.rb [options] [programfile] [arguments]
31
31
  --colorize Use colorization
32
32
  --nocolorize Don't use colorization
33
33
  --prompt prompt-mode/--prompt-mode prompt-mode
34
- Switch prompt mode. Pre-defined prompt modes are
35
- `default', `simple', `xmp' and `inf-ruby'
34
+ Switch prompt mode. Pre-defined prompt modes are
35
+ `default', `simple', `xmp' and `inf-ruby'
36
36
  --inf-ruby-mode Use prompt appropriate for inf-ruby-mode on emacs.
37
37
  Suppresses --multiline and --singleline.
38
38
  --sample-book-mode/--simple-prompt
@@ -41,8 +41,8 @@ Usage: irb.rb [options] [programfile] [arguments]
41
41
  --single-irb Share self with sub-irb.
42
42
  --tracer Display trace for each execution of commands.
43
43
  --back-trace-limit n
44
- Display backtrace top n and tail n. The default
45
- value is 16.
44
+ Display backtrace top n and tail n. The default
45
+ value is 16.
46
46
  --verbose Show details
47
47
  --noverbose Don't show details
48
48
  -v, --version Print the version of irb
data/lib/irb/ruby-lex.rb CHANGED
@@ -47,12 +47,26 @@ class RubyLex
47
47
  @io = io
48
48
  if @io.respond_to?(:check_termination)
49
49
  @io.check_termination do |code|
50
- code.gsub!(/\s*\z/, '').concat("\n")
51
- ltype, indent, continue, code_block_open = check_state(code)
52
- if ltype or indent > 0 or continue or code_block_open
53
- false
50
+ if Reline::IOGate.in_pasting?
51
+ lex = RubyLex.new
52
+ rest = lex.check_termination_in_prev_line(code)
53
+ if rest
54
+ Reline.delete_text
55
+ rest.bytes.reverse_each do |c|
56
+ Reline.ungetc(c)
57
+ end
58
+ true
59
+ else
60
+ false
61
+ end
54
62
  else
55
- true
63
+ code.gsub!(/\s*\z/, '').concat("\n")
64
+ ltype, indent, continue, code_block_open = check_state(code)
65
+ if ltype or indent > 0 or continue or code_block_open
66
+ false
67
+ else
68
+ true
69
+ end
56
70
  end
57
71
  end
58
72
  end
@@ -60,7 +74,7 @@ class RubyLex
60
74
  @io.dynamic_prompt do |lines|
61
75
  lines << '' if lines.empty?
62
76
  result = []
63
- tokens = ripper_lex_without_warning(lines.map{ |l| l + "\n" }.join)
77
+ tokens = self.class.ripper_lex_without_warning(lines.map{ |l| l + "\n" }.join)
64
78
  code = String.new
65
79
  partial_tokens = []
66
80
  unprocessed_tokens = []
@@ -115,10 +129,10 @@ class RubyLex
115
129
  :on_param_error
116
130
  ]
117
131
 
118
- def ripper_lex_without_warning(code)
132
+ def self.ripper_lex_without_warning(code)
119
133
  verbose, $VERBOSE = $VERBOSE, nil
120
134
  tokens = nil
121
- self.class.compile_with_errors_suppressed(code) do |inner_code, line_no|
135
+ compile_with_errors_suppressed(code) do |inner_code, line_no|
122
136
  lexer = Ripper::Lexer.new(inner_code, '-', line_no)
123
137
  if lexer.respond_to?(:scan) # Ruby 2.7+
124
138
  tokens = []
@@ -168,7 +182,7 @@ class RubyLex
168
182
  if @io.respond_to?(:auto_indent) and context.auto_indent_mode
169
183
  @io.auto_indent do |lines, line_index, byte_pointer, is_newline|
170
184
  if is_newline
171
- @tokens = ripper_lex_without_warning(lines[0..line_index].join("\n"))
185
+ @tokens = self.class.ripper_lex_without_warning(lines[0..line_index].join("\n"))
172
186
  prev_spaces = find_prev_spaces(line_index)
173
187
  depth_difference = check_newline_depth_difference
174
188
  depth_difference = 0 if depth_difference < 0
@@ -177,7 +191,7 @@ class RubyLex
177
191
  code = line_index.zero? ? '' : lines[0..(line_index - 1)].map{ |l| l + "\n" }.join
178
192
  last_line = lines[line_index]&.byteslice(0, byte_pointer)
179
193
  code += last_line if last_line
180
- @tokens = ripper_lex_without_warning(code)
194
+ @tokens = self.class.ripper_lex_without_warning(code)
181
195
  corresponding_token_depth = check_corresponding_token_depth
182
196
  if corresponding_token_depth
183
197
  corresponding_token_depth
@@ -190,7 +204,7 @@ class RubyLex
190
204
  end
191
205
 
192
206
  def check_state(code, tokens = nil)
193
- tokens = ripper_lex_without_warning(code) unless tokens
207
+ tokens = self.class.ripper_lex_without_warning(code) unless tokens
194
208
  ltype = process_literal_type(tokens)
195
209
  indent = process_nesting_level(tokens)
196
210
  continue = process_continue(tokens)
@@ -223,7 +237,10 @@ class RubyLex
223
237
  throw :TERM_INPUT if @line == ''
224
238
  else
225
239
  @line_no += l.count("\n")
226
- next if l == "\n"
240
+ if l == "\n"
241
+ @exp_line_no += 1
242
+ next
243
+ end
227
244
  @line.concat l
228
245
  if @code_block_open or @ltype or @continue or @indent > 0
229
246
  next
@@ -233,7 +250,7 @@ class RubyLex
233
250
  @line.force_encoding(@io.encoding)
234
251
  yield @line, @exp_line_no
235
252
  end
236
- break if @io.eof?
253
+ raise TerminateLineInput if @io.eof?
237
254
  @line = ''
238
255
  @exp_line_no = @line_no
239
256
 
@@ -253,7 +270,7 @@ class RubyLex
253
270
  end
254
271
  code = @line + (line.nil? ? '' : line)
255
272
  code.gsub!(/\s*\z/, '').concat("\n")
256
- @tokens = ripper_lex_without_warning(code)
273
+ @tokens = self.class.ripper_lex_without_warning(code)
257
274
  @continue = process_continue
258
275
  @code_block_open = check_code_block(code)
259
276
  @indent = process_nesting_level
@@ -274,8 +291,9 @@ class RubyLex
274
291
  return true
275
292
  elsif tokens.size >= 1 and tokens[-1][1] == :on_heredoc_end # "EOH\n"
276
293
  return false
277
- elsif tokens.size >= 2 and defined?(Ripper::EXPR_BEG) and tokens[-2][3].anybits?(Ripper::EXPR_BEG | Ripper::EXPR_FNAME)
294
+ elsif tokens.size >= 2 and defined?(Ripper::EXPR_BEG) and tokens[-2][3].anybits?(Ripper::EXPR_BEG | Ripper::EXPR_FNAME) and tokens[-2][2] !~ /\A\.\.\.?\z/
278
295
  # end of literal except for regexp
296
+ # endless range at end of line is not a continue
279
297
  return true
280
298
  end
281
299
  false
@@ -321,7 +339,7 @@ class RubyLex
321
339
  # "syntax error, unexpected end-of-input, expecting keyword_end"
322
340
  #
323
341
  # example:
324
- # if ture
342
+ # if true
325
343
  # hoge
326
344
  # if false
327
345
  # fuga
@@ -424,14 +442,30 @@ class RubyLex
424
442
  indent
425
443
  end
426
444
 
445
+ def is_method_calling?(tokens, index)
446
+ tk = tokens[index]
447
+ if tk[3].anybits?(Ripper::EXPR_CMDARG) and tk[1] == :on_ident
448
+ # The target method call to pass the block with "do".
449
+ return true
450
+ elsif tk[3].anybits?(Ripper::EXPR_ARG) and tk[1] == :on_ident
451
+ non_sp_index = tokens[0..(index - 1)].rindex{ |t| t[1] != :on_sp }
452
+ if non_sp_index
453
+ prev_tk = tokens[non_sp_index]
454
+ if prev_tk[3].anybits?(Ripper::EXPR_DOT) and prev_tk[1] == :on_period
455
+ # The target method call with receiver to pass the block with "do".
456
+ return true
457
+ end
458
+ end
459
+ end
460
+ false
461
+ end
462
+
427
463
  def take_corresponding_syntax_to_kw_do(tokens, index)
428
464
  syntax_of_do = nil
429
465
  # Finding a syntax correnponding to "do".
430
466
  index.downto(0) do |i|
431
467
  tk = tokens[i]
432
468
  # 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
469
  non_sp_index = tokens[0..(i - 1)].rindex{ |t| t[1] != :on_sp }
436
470
  first_in_fomula = false
437
471
  if non_sp_index.nil?
@@ -439,8 +473,7 @@ class RubyLex
439
473
  elsif [:on_ignored_nl, :on_nl, :on_comment].include?(tokens[non_sp_index][1])
440
474
  first_in_fomula = true
441
475
  end
442
- if tk[3].anybits?(Ripper::EXPR_CMDARG) and tk[1] == :on_ident
443
- # The target method call to pass the block with "do".
476
+ if is_method_calling?(tokens, i)
444
477
  syntax_of_do = :method_calling
445
478
  break if first_in_fomula
446
479
  elsif tk[1] == :on_kw && %w{while until for}.include?(tk[2])
@@ -458,6 +491,34 @@ class RubyLex
458
491
  syntax_of_do
459
492
  end
460
493
 
494
+ def is_the_in_correspond_to_a_for(tokens, index)
495
+ syntax_of_in = nil
496
+ # Finding a syntax correnponding to "do".
497
+ index.downto(0) do |i|
498
+ tk = tokens[i]
499
+ # In "continue", the token isn't the corresponding syntax to "do".
500
+ non_sp_index = tokens[0..(i - 1)].rindex{ |t| t[1] != :on_sp }
501
+ first_in_fomula = false
502
+ if non_sp_index.nil?
503
+ first_in_fomula = true
504
+ elsif [:on_ignored_nl, :on_nl, :on_comment].include?(tokens[non_sp_index][1])
505
+ first_in_fomula = true
506
+ end
507
+ if tk[1] == :on_kw && tk[2] == 'for'
508
+ # A loop syntax in front of "do" found.
509
+ #
510
+ # while cond do # also "until" or "for"
511
+ # end
512
+ #
513
+ # This "do" doesn't increment indent because the loop syntax already
514
+ # incremented.
515
+ syntax_of_in = :for
516
+ end
517
+ break if first_in_fomula
518
+ end
519
+ syntax_of_in
520
+ end
521
+
461
522
  def check_newline_depth_difference
462
523
  depth_difference = 0
463
524
  open_brace_on_line = 0
@@ -513,8 +574,12 @@ class RubyLex
513
574
  unless t[3].allbits?(Ripper::EXPR_LABEL)
514
575
  depth_difference += 1
515
576
  end
516
- when 'else', 'elsif', 'ensure', 'when', 'in'
577
+ when 'else', 'elsif', 'ensure', 'when'
517
578
  depth_difference += 1
579
+ when 'in'
580
+ unless is_the_in_correspond_to_a_for(@tokens, index)
581
+ depth_difference += 1
582
+ end
518
583
  when 'end'
519
584
  depth_difference -= 1
520
585
  end
@@ -688,5 +753,50 @@ class RubyLex
688
753
  nil
689
754
  end
690
755
  end
756
+
757
+ def check_termination_in_prev_line(code)
758
+ tokens = self.class.ripper_lex_without_warning(code)
759
+ past_first_newline = false
760
+ index = tokens.rindex do |t|
761
+ # traverse first token before last line
762
+ if past_first_newline
763
+ if t.tok.include?("\n")
764
+ true
765
+ end
766
+ elsif t.tok.include?("\n")
767
+ past_first_newline = true
768
+ false
769
+ else
770
+ false
771
+ end
772
+ end
773
+ if index
774
+ first_token = nil
775
+ last_line_tokens = tokens[(index + 1)..(tokens.size - 1)]
776
+ last_line_tokens.each do |t|
777
+ unless [:on_sp, :on_ignored_sp, :on_comment].include?(t.event)
778
+ first_token = t
779
+ break
780
+ end
781
+ end
782
+ if first_token.nil?
783
+ return false
784
+ elsif first_token && first_token.state == Ripper::EXPR_DOT
785
+ return false
786
+ else
787
+ tokens_without_last_line = tokens[0..index]
788
+ ltype = process_literal_type(tokens_without_last_line)
789
+ indent = process_nesting_level(tokens_without_last_line)
790
+ continue = process_continue(tokens_without_last_line)
791
+ code_block_open = check_code_block(tokens_without_last_line.map(&:tok).join(''), tokens_without_last_line)
792
+ if ltype or indent > 0 or continue or code_block_open
793
+ return false
794
+ else
795
+ return last_line_tokens.map(&:tok).join('')
796
+ end
797
+ end
798
+ end
799
+ false
800
+ end
691
801
  end
692
802
  # :startdoc:
data/lib/irb/version.rb CHANGED
@@ -11,7 +11,7 @@
11
11
  #
12
12
 
13
13
  module IRB # :nodoc:
14
- VERSION = "1.3.1"
14
+ VERSION = "1.3.6"
15
15
  @RELEASE_VERSION = VERSION
16
- @LAST_UPDATE_DATE = "2021-01-12"
16
+ @LAST_UPDATE_DATE = "2021-06-19"
17
17
  end
data/lib/irb/workspace.rb CHANGED
@@ -128,6 +128,7 @@ EOF
128
128
  def filter_backtrace(bt)
129
129
  return nil if bt =~ /\/irb\/.*\.rb/
130
130
  return nil if bt =~ /\/irb\.rb/
131
+ return nil if bt =~ /tool\/lib\/.*\.rb|runner\.rb/ # for tests in Ruby repository
131
132
  case IRB.conf[:CONTEXT_MODE]
132
133
  when 1
133
134
  return nil if bt =~ %r!/tmp/irb-binding!
@@ -174,7 +175,7 @@ EOF
174
175
  body = (start_pos..end_pos).map do |current_pos|
175
176
  sprintf(fmt, pos == current_pos ? '=>' : '', current_pos + 1, lines[current_pos])
176
177
  end.join("")
177
- "\nFrom: #{file} @ line #{pos + 1} :\n\n#{body}#{Color.clear}\n"
178
+ "\nFrom: #{file} @ line #{pos + 1} :\n\n#{body}#{Color.clear if use_colorize}\n"
178
179
  end
179
180
 
180
181
  def IRB.delete_caller
metadata CHANGED
@@ -1,57 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: irb
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.3.1
4
+ version: 1.3.6
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: 2021-01-11 00:00:00.000000000 Z
11
+ date: 2021-06-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: reline
15
- requirement: !ruby/object:Gem::Requirement
16
- requirements:
17
- - - ">="
18
- - !ruby/object:Gem::Version
19
- version: 0.1.5
20
- type: :runtime
21
- prerelease: false
22
- version_requirements: !ruby/object:Gem::Requirement
23
- requirements:
24
- - - ">="
25
- - !ruby/object:Gem::Version
26
- version: 0.1.5
27
- - !ruby/object:Gem::Dependency
28
- name: bundler
29
- requirement: !ruby/object:Gem::Requirement
30
- requirements:
31
- - - ">="
32
- - !ruby/object:Gem::Version
33
- version: '0'
34
- type: :development
35
15
  prerelease: false
36
- version_requirements: !ruby/object:Gem::Requirement
37
- requirements:
38
- - - ">="
39
- - !ruby/object:Gem::Version
40
- version: '0'
41
- - !ruby/object:Gem::Dependency
42
- name: rake
43
16
  requirement: !ruby/object:Gem::Requirement
44
17
  requirements:
45
18
  - - ">="
46
19
  - !ruby/object:Gem::Version
47
- version: '0'
48
- type: :development
49
- prerelease: false
20
+ version: 0.2.5
21
+ type: :runtime
50
22
  version_requirements: !ruby/object:Gem::Requirement
51
23
  requirements:
52
24
  - - ">="
53
25
  - !ruby/object:Gem::Version
54
- version: '0'
26
+ version: 0.2.5
55
27
  description: Interactive Ruby command-line tool for REPL (Read Eval Print Loop).
56
28
  email:
57
29
  - keiju@ruby-lang.org
@@ -75,11 +47,15 @@ files:
75
47
  - lib/irb/cmd/chws.rb
76
48
  - lib/irb/cmd/fork.rb
77
49
  - lib/irb/cmd/help.rb
50
+ - lib/irb/cmd/info.rb
78
51
  - lib/irb/cmd/load.rb
52
+ - lib/irb/cmd/ls.rb
79
53
  - lib/irb/cmd/measure.rb
80
54
  - lib/irb/cmd/nop.rb
81
55
  - lib/irb/cmd/pushws.rb
56
+ - lib/irb/cmd/show_source.rb
82
57
  - lib/irb/cmd/subirb.rb
58
+ - lib/irb/cmd/whereami.rb
83
59
  - lib/irb/color.rb
84
60
  - lib/irb/color_printer.rb
85
61
  - lib/irb/completion.rb
@@ -121,7 +97,7 @@ licenses:
121
97
  - Ruby
122
98
  - BSD-2-Clause
123
99
  metadata: {}
124
- post_install_message:
100
+ post_install_message:
125
101
  rdoc_options: []
126
102
  require_paths:
127
103
  - lib
@@ -136,8 +112,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
136
112
  - !ruby/object:Gem::Version
137
113
  version: '0'
138
114
  requirements: []
139
- rubygems_version: 3.2.3
140
- signing_key:
115
+ rubygems_version: 3.1.4
116
+ signing_key:
141
117
  specification_version: 4
142
118
  summary: Interactive Ruby command-line tool for REPL (Read Eval Print Loop).
143
119
  test_files: []