irb 1.3.8.pre.11 → 1.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile +2 -2
- data/irb.gemspec +1 -1
- data/lib/irb/cmd/info.rb +2 -1
- data/lib/irb/cmd/show_source.rb +2 -5
- data/lib/irb/completion.rb +1 -1
- data/lib/irb/context.rb +14 -8
- data/lib/irb/init.rb +4 -0
- data/lib/irb/input-method.rb +4 -1
- data/lib/irb/lc/help-message +1 -0
- data/lib/irb/ruby-lex.rb +93 -65
- data/lib/irb/version.rb +2 -2
- data/lib/irb.rb +6 -2
- data/man/irb.1 +4 -0
- metadata +6 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6c52cb722e3095862479d2b3238107929c9aacb7d0abdaef02a3ae11ad4d81be
|
4
|
+
data.tar.gz: f933953b4a52be77dad05d3f39f4a590f08593c4c29782086c1d59c2f00fc9d5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a6ab46115c8484ec6818876b7a00fd264b3981be71b9a86d0fe4964ea670685ebb6e15bc3d1a6cdc6a0699883088cc75027c77fa67b2f8098c45226d19348f25
|
7
|
+
data.tar.gz: 346676856d7c18ad4ac921aa2be2669b988752585ea147283674d614b5646574b7eb7127f9a488e1fe2d1519875674fe18f4daa1179d145fcb333ae2d17b70e0
|
data/Gemfile
CHANGED
@@ -5,8 +5,8 @@ gemspec
|
|
5
5
|
group :development do
|
6
6
|
is_unix = RUBY_PLATFORM =~ /(aix|darwin|linux|(net|free|open)bsd|cygwin|solaris|irix|hpux)/i
|
7
7
|
is_truffleruby = RUBY_DESCRIPTION =~ /truffleruby/
|
8
|
-
gem
|
9
|
-
gem
|
8
|
+
gem "vterm", ">= 0.0.5" if is_unix && ENV['WITH_VTERM']
|
9
|
+
gem "yamatanooroti", ">= 0.0.6"
|
10
10
|
gem "rake"
|
11
11
|
gem "stackprof" if is_unix && !is_truffleruby
|
12
12
|
gem "test-unit"
|
data/irb.gemspec
CHANGED
data/lib/irb/cmd/info.rb
CHANGED
@@ -16,8 +16,9 @@ module IRB
|
|
16
16
|
str += "RUBY_PLATFORM: #{RUBY_PLATFORM}\n"
|
17
17
|
str += "LANG env: #{ENV["LANG"]}\n" if ENV["LANG"] && !ENV["LANG"].empty?
|
18
18
|
str += "LC_ALL env: #{ENV["LC_ALL"]}\n" if ENV["LC_ALL"] && !ENV["LC_ALL"].empty?
|
19
|
+
str += "East Asian Ambiguous Width: #{Reline.ambiguous_width.inspect}\n"
|
19
20
|
if RbConfig::CONFIG['host_os'] =~ /mswin|msys|mingw|cygwin|bccwin|wince|emc/
|
20
|
-
codepage = `chcp`.sub(/.*: (\d+)\n/, '\1')
|
21
|
+
codepage = `chcp`.b.sub(/.*: (\d+)\n/, '\1')
|
21
22
|
str += "Code page: #{codepage}\n"
|
22
23
|
end
|
23
24
|
str
|
data/lib/irb/cmd/show_source.rb
CHANGED
@@ -61,15 +61,12 @@ module IRB
|
|
61
61
|
lex = RubyLex.new
|
62
62
|
lines = File.read(file).lines[(first_line - 1)..-1]
|
63
63
|
tokens = RubyLex.ripper_lex_without_warning(lines.join)
|
64
|
-
|
65
|
-
code = +""
|
66
64
|
prev_tokens = []
|
67
65
|
|
68
66
|
# chunk with line number
|
69
|
-
tokens.chunk { |tok| tok[0]
|
70
|
-
code
|
67
|
+
tokens.chunk { |tok| tok.pos[0] }.each do |lnum, chunk|
|
68
|
+
code = lines[0..lnum].join
|
71
69
|
prev_tokens.concat chunk
|
72
|
-
|
73
70
|
continue = lex.process_continue(prev_tokens)
|
74
71
|
code_block_open = lex.check_code_block(code, prev_tokens)
|
75
72
|
if !continue && !code_block_open
|
data/lib/irb/completion.rb
CHANGED
data/lib/irb/context.rb
CHANGED
@@ -125,6 +125,8 @@ module IRB
|
|
125
125
|
end
|
126
126
|
self.save_history = IRB.conf[:SAVE_HISTORY] if IRB.conf[:SAVE_HISTORY]
|
127
127
|
|
128
|
+
@extra_doc_dirs = IRB.conf[:EXTRA_DOC_DIRS]
|
129
|
+
|
128
130
|
@echo = IRB.conf[:ECHO]
|
129
131
|
if @echo.nil?
|
130
132
|
@echo = true
|
@@ -148,18 +150,18 @@ module IRB
|
|
148
150
|
|
149
151
|
# The toplevel workspace, see #home_workspace
|
150
152
|
attr_reader :workspace_home
|
151
|
-
# WorkSpace in the current context
|
153
|
+
# WorkSpace in the current context.
|
152
154
|
attr_accessor :workspace
|
153
|
-
# The current thread in this context
|
155
|
+
# The current thread in this context.
|
154
156
|
attr_reader :thread
|
155
|
-
# The current input method
|
157
|
+
# The current input method.
|
156
158
|
#
|
157
159
|
# Can be either StdioInputMethod, ReadlineInputMethod,
|
158
160
|
# ReidlineInputMethod, FileInputMethod or other specified when the
|
159
161
|
# context is created. See ::new for more # information on +input_method+.
|
160
162
|
attr_accessor :io
|
161
163
|
|
162
|
-
# Current irb session
|
164
|
+
# Current irb session.
|
163
165
|
attr_accessor :irb
|
164
166
|
# A copy of the default <code>IRB.conf[:AP_NAME]</code>
|
165
167
|
attr_accessor :ap_name
|
@@ -193,15 +195,15 @@ module IRB
|
|
193
195
|
|
194
196
|
# A copy of the default <code>IRB.conf[:PROMPT_MODE]</code>
|
195
197
|
attr_reader :prompt_mode
|
196
|
-
# Standard IRB prompt
|
198
|
+
# Standard IRB prompt.
|
197
199
|
#
|
198
200
|
# See IRB@Customizing+the+IRB+Prompt for more information.
|
199
201
|
attr_accessor :prompt_i
|
200
|
-
# IRB prompt for continuated strings
|
202
|
+
# IRB prompt for continuated strings.
|
201
203
|
#
|
202
204
|
# See IRB@Customizing+the+IRB+Prompt for more information.
|
203
205
|
attr_accessor :prompt_s
|
204
|
-
# IRB prompt for continuated statement (e.g. immediately after an +if+)
|
206
|
+
# IRB prompt for continuated statement. (e.g. immediately after an +if+)
|
205
207
|
#
|
206
208
|
# See IRB@Customizing+the+IRB+Prompt for more information.
|
207
209
|
attr_accessor :prompt_c
|
@@ -241,6 +243,9 @@ module IRB
|
|
241
243
|
#
|
242
244
|
# If set to +false+, <code>^D</code> will quit irb.
|
243
245
|
attr_accessor :ignore_eof
|
246
|
+
# Specify the installation locations of the ri file to be displayed in the
|
247
|
+
# document dialog.
|
248
|
+
attr_accessor :extra_doc_dirs
|
244
249
|
# Whether to echo the return value to output or not.
|
245
250
|
#
|
246
251
|
# Uses <code>IRB.conf[:ECHO]</code> if available, or defaults to +true+.
|
@@ -252,7 +257,7 @@ module IRB
|
|
252
257
|
# puts "omg"
|
253
258
|
# # omg
|
254
259
|
attr_accessor :echo
|
255
|
-
# Whether to echo for assignment expressions
|
260
|
+
# Whether to echo for assignment expressions.
|
256
261
|
#
|
257
262
|
# If set to +false+, the value of assignment will not be shown.
|
258
263
|
#
|
@@ -386,6 +391,7 @@ module IRB
|
|
386
391
|
@prompt_c = pconf[:PROMPT_C]
|
387
392
|
@prompt_n = pconf[:PROMPT_N]
|
388
393
|
@return_format = pconf[:RETURN]
|
394
|
+
@return_format = "%s\n" if @return_format == nil
|
389
395
|
if ai = pconf.include?(:AUTO_INDENT)
|
390
396
|
@auto_indent_mode = ai
|
391
397
|
else
|
data/lib/irb/init.rb
CHANGED
@@ -51,6 +51,7 @@ module IRB # :nodoc:
|
|
51
51
|
@CONF[:USE_LOADER] = false
|
52
52
|
@CONF[:IGNORE_SIGINT] = true
|
53
53
|
@CONF[:IGNORE_EOF] = false
|
54
|
+
@CONF[:EXTRA_DOC_DIRS] = []
|
54
55
|
@CONF[:ECHO] = nil
|
55
56
|
@CONF[:ECHO_ON_ASSIGNMENT] = nil
|
56
57
|
@CONF[:VERBOSE] = nil
|
@@ -257,6 +258,9 @@ module IRB # :nodoc:
|
|
257
258
|
@CONF[:USE_MULTILINE] = true
|
258
259
|
when "--nomultiline", "--noreidline"
|
259
260
|
@CONF[:USE_MULTILINE] = false
|
261
|
+
when /^--extra-doc-dir(?:=(.+))?/
|
262
|
+
opt = $1 || argv.shift
|
263
|
+
@CONF[:EXTRA_DOC_DIRS] << opt
|
260
264
|
when "--echo"
|
261
265
|
@CONF[:ECHO] = true
|
262
266
|
when "--noecho"
|
data/lib/irb/input-method.rb
CHANGED
@@ -318,6 +318,7 @@ module IRB
|
|
318
318
|
dialog.trap_key = nil
|
319
319
|
alt_d = [
|
320
320
|
[Reline::Key.new(nil, 0xE4, true)], # Normal Alt+d.
|
321
|
+
[27, 100], # Normal Alt+d when convert-meta isn't used.
|
321
322
|
[195, 164] # The "ä" that appears when Alt+d is pressed on xterm.
|
322
323
|
]
|
323
324
|
|
@@ -329,7 +330,9 @@ module IRB
|
|
329
330
|
name = result[pointer]
|
330
331
|
name = IRB::InputCompletor.retrieve_completion_data(name, doc_namespace: true)
|
331
332
|
|
332
|
-
|
333
|
+
options = {}
|
334
|
+
options[:extra_doc_dirs] = IRB.conf[:EXTRA_DOC_DIRS] unless IRB.conf[:EXTRA_DOC_DIRS].empty?
|
335
|
+
driver = RDoc::RI::Driver.new(options)
|
333
336
|
|
334
337
|
if key.match?(dialog.name)
|
335
338
|
begin
|
data/lib/irb/lc/help-message
CHANGED
@@ -20,6 +20,7 @@ Usage: irb.rb [options] [programfile] [arguments]
|
|
20
20
|
-W[level=2] Same as `ruby -W`
|
21
21
|
--context-mode n Set n[0-4] to method to create Binding Object,
|
22
22
|
when new workspace was created
|
23
|
+
--extra-doc-dir Add an extra doc dir for the doc dialog
|
23
24
|
--echo Show result (default)
|
24
25
|
--noecho Don't show result
|
25
26
|
--echo-on-assignment
|
data/lib/irb/ruby-lex.rb
CHANGED
@@ -87,8 +87,8 @@ class RubyLex
|
|
87
87
|
tokens.each do |t|
|
88
88
|
partial_tokens << t
|
89
89
|
unprocessed_tokens << t
|
90
|
-
if t
|
91
|
-
t_str = t
|
90
|
+
if t.tok.include?("\n")
|
91
|
+
t_str = t.tok
|
92
92
|
t_str.each_line("\n") do |s|
|
93
93
|
code << s << "\n"
|
94
94
|
ltype, indent, continue, code_block_open = check_state(code, partial_tokens, context: context)
|
@@ -97,9 +97,10 @@ class RubyLex
|
|
97
97
|
end
|
98
98
|
unprocessed_tokens = []
|
99
99
|
else
|
100
|
-
code << t
|
100
|
+
code << t.tok
|
101
101
|
end
|
102
102
|
end
|
103
|
+
|
103
104
|
unless unprocessed_tokens.empty?
|
104
105
|
ltype, indent, continue, code_block_open = check_state(code, unprocessed_tokens, context: context)
|
105
106
|
result << @prompt.call(ltype, indent, continue || code_block_open, @line_no + line_num_offset)
|
@@ -107,6 +108,7 @@ class RubyLex
|
|
107
108
|
result
|
108
109
|
end
|
109
110
|
end
|
111
|
+
|
110
112
|
if p.respond_to?(:call)
|
111
113
|
@input = p
|
112
114
|
elsif block_given?
|
@@ -153,19 +155,19 @@ class RubyLex
|
|
153
155
|
pos_to_index = {}
|
154
156
|
lexer.scan.each do |t|
|
155
157
|
next if t.pos.first == 0
|
156
|
-
if pos_to_index.has_key?(t
|
157
|
-
index = pos_to_index[t
|
158
|
+
if pos_to_index.has_key?(t.pos)
|
159
|
+
index = pos_to_index[t.pos]
|
158
160
|
found_tk = tokens[index]
|
159
|
-
if ERROR_TOKENS.include?(found_tk
|
161
|
+
if ERROR_TOKENS.include?(found_tk.event) && !ERROR_TOKENS.include?(t.event)
|
160
162
|
tokens[index] = t
|
161
163
|
end
|
162
164
|
else
|
163
|
-
pos_to_index[t
|
165
|
+
pos_to_index[t.pos] = tokens.size
|
164
166
|
tokens << t
|
165
167
|
end
|
166
168
|
end
|
167
169
|
else
|
168
|
-
tokens = lexer.parse
|
170
|
+
tokens = lexer.parse.reject { |it| it.pos.first == 0 }
|
169
171
|
end
|
170
172
|
end
|
171
173
|
tokens
|
@@ -175,17 +177,17 @@ class RubyLex
|
|
175
177
|
|
176
178
|
def find_prev_spaces(line_index)
|
177
179
|
return 0 if @tokens.size == 0
|
178
|
-
md = @tokens[0]
|
180
|
+
md = @tokens[0].tok.match(/(\A +)/)
|
179
181
|
prev_spaces = md.nil? ? 0 : md[1].count(' ')
|
180
182
|
line_count = 0
|
181
183
|
@tokens.each_with_index do |t, i|
|
182
|
-
if t
|
183
|
-
line_count += t
|
184
|
+
if t.tok.include?("\n")
|
185
|
+
line_count += t.tok.count("\n")
|
184
186
|
if line_count >= line_index
|
185
187
|
return prev_spaces
|
186
188
|
end
|
187
189
|
if (@tokens.size - 1) > i
|
188
|
-
md = @tokens[i + 1]
|
190
|
+
md = @tokens[i + 1].tok.match(/(\A +)/)
|
189
191
|
prev_spaces = md.nil? ? 0 : md[1].count(' ')
|
190
192
|
end
|
191
193
|
end
|
@@ -295,18 +297,18 @@ class RubyLex
|
|
295
297
|
|
296
298
|
def process_continue(tokens = @tokens)
|
297
299
|
# last token is always newline
|
298
|
-
if tokens.size >= 2 and tokens[-2]
|
300
|
+
if tokens.size >= 2 and tokens[-2].event == :on_regexp_end
|
299
301
|
# end of regexp literal
|
300
302
|
return false
|
301
|
-
elsif tokens.size >= 2 and tokens[-2]
|
303
|
+
elsif tokens.size >= 2 and tokens[-2].event == :on_semicolon
|
302
304
|
return false
|
303
|
-
elsif tokens.size >= 2 and tokens[-2]
|
305
|
+
elsif tokens.size >= 2 and tokens[-2].event == :on_kw and ['begin', 'else', 'ensure'].include?(tokens[-2].tok)
|
304
306
|
return false
|
305
|
-
elsif !tokens.empty? and tokens.last
|
307
|
+
elsif !tokens.empty? and tokens.last.tok == "\\\n"
|
306
308
|
return true
|
307
|
-
elsif tokens.size >= 1 and tokens[-1]
|
309
|
+
elsif tokens.size >= 1 and tokens[-1].event == :on_heredoc_end # "EOH\n"
|
308
310
|
return false
|
309
|
-
elsif tokens.size >= 2 and defined?(Ripper::EXPR_BEG) and tokens[-2]
|
311
|
+
elsif tokens.size >= 2 and defined?(Ripper::EXPR_BEG) and tokens[-2].state.anybits?(Ripper::EXPR_BEG | Ripper::EXPR_FNAME) and tokens[-2].tok !~ /\A\.\.\.?\z/
|
310
312
|
# end of literal except for regexp
|
311
313
|
# endless range at end of line is not a continue
|
312
314
|
return true
|
@@ -316,7 +318,7 @@ class RubyLex
|
|
316
318
|
|
317
319
|
def check_code_block(code, tokens = @tokens)
|
318
320
|
return true if tokens.empty?
|
319
|
-
if tokens.last
|
321
|
+
if tokens.last.event == :on_heredoc_beg
|
320
322
|
return true
|
321
323
|
end
|
322
324
|
|
@@ -388,7 +390,7 @@ class RubyLex
|
|
388
390
|
end
|
389
391
|
|
390
392
|
if defined?(Ripper::EXPR_BEG)
|
391
|
-
last_lex_state = tokens.last
|
393
|
+
last_lex_state = tokens.last.state
|
392
394
|
if last_lex_state.allbits?(Ripper::EXPR_BEG)
|
393
395
|
return false
|
394
396
|
elsif last_lex_state.allbits?(Ripper::EXPR_DOT)
|
@@ -413,14 +415,14 @@ class RubyLex
|
|
413
415
|
tokens.each_with_index { |t, index|
|
414
416
|
# detecting one-liner method definition
|
415
417
|
if in_oneliner_def.nil?
|
416
|
-
if t
|
418
|
+
if t.state.allbits?(Ripper::EXPR_ENDFN)
|
417
419
|
in_oneliner_def = :ENDFN
|
418
420
|
end
|
419
421
|
else
|
420
|
-
if t
|
422
|
+
if t.state.allbits?(Ripper::EXPR_ENDFN)
|
421
423
|
# continuing
|
422
|
-
elsif t
|
423
|
-
if t
|
424
|
+
elsif t.state.allbits?(Ripper::EXPR_BEG)
|
425
|
+
if t.tok == '='
|
424
426
|
in_oneliner_def = :BODY
|
425
427
|
end
|
426
428
|
else
|
@@ -432,14 +434,14 @@ class RubyLex
|
|
432
434
|
end
|
433
435
|
end
|
434
436
|
|
435
|
-
case t
|
437
|
+
case t.event
|
436
438
|
when :on_lbracket, :on_lbrace, :on_lparen, :on_tlambeg
|
437
439
|
indent += 1
|
438
440
|
when :on_rbracket, :on_rbrace, :on_rparen
|
439
441
|
indent -= 1
|
440
442
|
when :on_kw
|
441
|
-
next if index > 0 and tokens[index - 1]
|
442
|
-
case t
|
443
|
+
next if index > 0 and tokens[index - 1].state.allbits?(Ripper::EXPR_FNAME)
|
444
|
+
case t.tok
|
443
445
|
when 'do'
|
444
446
|
syntax_of_do = take_corresponding_syntax_to_kw_do(tokens, index)
|
445
447
|
indent += 1 if syntax_of_do == :method_calling
|
@@ -447,7 +449,7 @@ class RubyLex
|
|
447
449
|
indent += 1
|
448
450
|
when 'if', 'unless', 'while', 'until'
|
449
451
|
# postfix if/unless/while/until must be Ripper::EXPR_LABEL
|
450
|
-
indent += 1 unless t
|
452
|
+
indent += 1 unless t.state.allbits?(Ripper::EXPR_LABEL)
|
451
453
|
when 'end'
|
452
454
|
indent -= 1
|
453
455
|
end
|
@@ -459,14 +461,14 @@ class RubyLex
|
|
459
461
|
|
460
462
|
def is_method_calling?(tokens, index)
|
461
463
|
tk = tokens[index]
|
462
|
-
if tk
|
464
|
+
if tk.state.anybits?(Ripper::EXPR_CMDARG) and tk.event == :on_ident
|
463
465
|
# The target method call to pass the block with "do".
|
464
466
|
return true
|
465
|
-
elsif tk
|
466
|
-
non_sp_index = tokens[0..(index - 1)].rindex{ |t| t
|
467
|
+
elsif tk.state.anybits?(Ripper::EXPR_ARG) and tk.event == :on_ident
|
468
|
+
non_sp_index = tokens[0..(index - 1)].rindex{ |t| t.event != :on_sp }
|
467
469
|
if non_sp_index
|
468
470
|
prev_tk = tokens[non_sp_index]
|
469
|
-
if prev_tk
|
471
|
+
if prev_tk.state.anybits?(Ripper::EXPR_DOT) and prev_tk.event == :on_period
|
470
472
|
# The target method call with receiver to pass the block with "do".
|
471
473
|
return true
|
472
474
|
end
|
@@ -481,17 +483,17 @@ class RubyLex
|
|
481
483
|
index.downto(0) do |i|
|
482
484
|
tk = tokens[i]
|
483
485
|
# In "continue", the token isn't the corresponding syntax to "do".
|
484
|
-
non_sp_index = tokens[0..(i - 1)].rindex{ |t| t
|
486
|
+
non_sp_index = tokens[0..(i - 1)].rindex{ |t| t.event != :on_sp }
|
485
487
|
first_in_fomula = false
|
486
488
|
if non_sp_index.nil?
|
487
489
|
first_in_fomula = true
|
488
|
-
elsif [:on_ignored_nl, :on_nl, :on_comment].include?(tokens[non_sp_index]
|
490
|
+
elsif [:on_ignored_nl, :on_nl, :on_comment].include?(tokens[non_sp_index].event)
|
489
491
|
first_in_fomula = true
|
490
492
|
end
|
491
493
|
if is_method_calling?(tokens, i)
|
492
494
|
syntax_of_do = :method_calling
|
493
495
|
break if first_in_fomula
|
494
|
-
elsif tk
|
496
|
+
elsif tk.event == :on_kw && %w{while until for}.include?(tk.tok)
|
495
497
|
# A loop syntax in front of "do" found.
|
496
498
|
#
|
497
499
|
# while cond do # also "until" or "for"
|
@@ -512,14 +514,14 @@ class RubyLex
|
|
512
514
|
index.downto(0) do |i|
|
513
515
|
tk = tokens[i]
|
514
516
|
# In "continue", the token isn't the corresponding syntax to "do".
|
515
|
-
non_sp_index = tokens[0..(i - 1)].rindex{ |t| t
|
517
|
+
non_sp_index = tokens[0..(i - 1)].rindex{ |t| t.event != :on_sp }
|
516
518
|
first_in_fomula = false
|
517
519
|
if non_sp_index.nil?
|
518
520
|
first_in_fomula = true
|
519
|
-
elsif [:on_ignored_nl, :on_nl, :on_comment].include?(tokens[non_sp_index]
|
521
|
+
elsif [:on_ignored_nl, :on_nl, :on_comment].include?(tokens[non_sp_index].event)
|
520
522
|
first_in_fomula = true
|
521
523
|
end
|
522
|
-
if tk
|
524
|
+
if tk.event == :on_kw && tk.tok == 'for'
|
523
525
|
# A loop syntax in front of "do" found.
|
524
526
|
#
|
525
527
|
# while cond do # also "until" or "for"
|
@@ -541,14 +543,14 @@ class RubyLex
|
|
541
543
|
@tokens.each_with_index do |t, index|
|
542
544
|
# detecting one-liner method definition
|
543
545
|
if in_oneliner_def.nil?
|
544
|
-
if t
|
546
|
+
if t.state.allbits?(Ripper::EXPR_ENDFN)
|
545
547
|
in_oneliner_def = :ENDFN
|
546
548
|
end
|
547
549
|
else
|
548
|
-
if t
|
550
|
+
if t.state.allbits?(Ripper::EXPR_ENDFN)
|
549
551
|
# continuing
|
550
|
-
elsif t
|
551
|
-
if t
|
552
|
+
elsif t.state.allbits?(Ripper::EXPR_BEG)
|
553
|
+
if t.tok == '='
|
552
554
|
in_oneliner_def = :BODY
|
553
555
|
end
|
554
556
|
else
|
@@ -560,7 +562,7 @@ class RubyLex
|
|
560
562
|
end
|
561
563
|
end
|
562
564
|
|
563
|
-
case t
|
565
|
+
case t.event
|
564
566
|
when :on_ignored_nl, :on_nl, :on_comment
|
565
567
|
if index != (@tokens.size - 1) and in_oneliner_def != :BODY
|
566
568
|
depth_difference = 0
|
@@ -570,15 +572,16 @@ class RubyLex
|
|
570
572
|
when :on_sp
|
571
573
|
next
|
572
574
|
end
|
573
|
-
|
575
|
+
|
576
|
+
case t.event
|
574
577
|
when :on_lbracket, :on_lbrace, :on_lparen, :on_tlambeg
|
575
578
|
depth_difference += 1
|
576
579
|
open_brace_on_line += 1
|
577
580
|
when :on_rbracket, :on_rbrace, :on_rparen
|
578
581
|
depth_difference -= 1 if open_brace_on_line > 0
|
579
582
|
when :on_kw
|
580
|
-
next if index > 0 and @tokens[index - 1]
|
581
|
-
case t
|
583
|
+
next if index > 0 and @tokens[index - 1].state.allbits?(Ripper::EXPR_FNAME)
|
584
|
+
case t.tok
|
582
585
|
when 'do'
|
583
586
|
syntax_of_do = take_corresponding_syntax_to_kw_do(@tokens, index)
|
584
587
|
depth_difference += 1 if syntax_of_do == :method_calling
|
@@ -586,7 +589,7 @@ class RubyLex
|
|
586
589
|
depth_difference += 1
|
587
590
|
when 'if', 'unless', 'while', 'until', 'rescue'
|
588
591
|
# postfix if/unless/while/until/rescue must be Ripper::EXPR_LABEL
|
589
|
-
unless t
|
592
|
+
unless t.state.allbits?(Ripper::EXPR_LABEL)
|
590
593
|
depth_difference += 1
|
591
594
|
end
|
592
595
|
when 'else', 'elsif', 'ensure', 'when'
|
@@ -619,14 +622,14 @@ class RubyLex
|
|
619
622
|
@tokens.each_with_index do |t, index|
|
620
623
|
# detecting one-liner method definition
|
621
624
|
if in_oneliner_def.nil?
|
622
|
-
if t
|
625
|
+
if t.state.allbits?(Ripper::EXPR_ENDFN)
|
623
626
|
in_oneliner_def = :ENDFN
|
624
627
|
end
|
625
628
|
else
|
626
|
-
if t
|
629
|
+
if t.state.allbits?(Ripper::EXPR_ENDFN)
|
627
630
|
# continuing
|
628
|
-
elsif t
|
629
|
-
if t
|
631
|
+
elsif t.state.allbits?(Ripper::EXPR_BEG)
|
632
|
+
if t.tok == '='
|
630
633
|
in_oneliner_def = :BODY
|
631
634
|
end
|
632
635
|
else
|
@@ -643,7 +646,7 @@ class RubyLex
|
|
643
646
|
end
|
644
647
|
end
|
645
648
|
|
646
|
-
case t
|
649
|
+
case t.event
|
647
650
|
when :on_ignored_nl, :on_nl, :on_comment
|
648
651
|
if in_oneliner_def != :BODY
|
649
652
|
corresponding_token_depth = nil
|
@@ -654,11 +657,12 @@ class RubyLex
|
|
654
657
|
end
|
655
658
|
next
|
656
659
|
when :on_sp
|
657
|
-
spaces_at_line_head = t
|
660
|
+
spaces_at_line_head = t.tok.count(' ') if is_first_spaces_of_line
|
658
661
|
is_first_spaces_of_line = false
|
659
662
|
next
|
660
663
|
end
|
661
|
-
|
664
|
+
|
665
|
+
case t.event
|
662
666
|
when :on_lbracket, :on_lbrace, :on_lparen, :on_tlambeg
|
663
667
|
spaces_of_nest.push(spaces_at_line_head + open_brace_on_line * 2)
|
664
668
|
open_brace_on_line += 1
|
@@ -671,8 +675,8 @@ class RubyLex
|
|
671
675
|
end
|
672
676
|
open_brace_on_line -= 1
|
673
677
|
when :on_kw
|
674
|
-
next if index > 0 and @tokens[index - 1]
|
675
|
-
case t
|
678
|
+
next if index > 0 and @tokens[index - 1].state.allbits?(Ripper::EXPR_FNAME)
|
679
|
+
case t.tok
|
676
680
|
when 'do'
|
677
681
|
syntax_of_do = take_corresponding_syntax_to_kw_do(@tokens, index)
|
678
682
|
if syntax_of_do == :method_calling
|
@@ -681,16 +685,20 @@ class RubyLex
|
|
681
685
|
when 'def', 'case', 'for', 'begin', 'class', 'module'
|
682
686
|
spaces_of_nest.push(spaces_at_line_head)
|
683
687
|
when 'rescue'
|
684
|
-
unless t
|
688
|
+
unless t.state.allbits?(Ripper::EXPR_LABEL)
|
685
689
|
corresponding_token_depth = spaces_of_nest.last
|
686
690
|
end
|
687
691
|
when 'if', 'unless', 'while', 'until'
|
688
692
|
# postfix if/unless/while/until must be Ripper::EXPR_LABEL
|
689
|
-
unless t
|
693
|
+
unless t.state.allbits?(Ripper::EXPR_LABEL)
|
690
694
|
spaces_of_nest.push(spaces_at_line_head)
|
691
695
|
end
|
692
|
-
when 'else', 'elsif', 'ensure', 'when'
|
696
|
+
when 'else', 'elsif', 'ensure', 'when'
|
693
697
|
corresponding_token_depth = spaces_of_nest.last
|
698
|
+
when 'in'
|
699
|
+
if in_keyword_case_scope?
|
700
|
+
corresponding_token_depth = spaces_of_nest.last
|
701
|
+
end
|
694
702
|
when 'end'
|
695
703
|
if is_first_printable_of_line
|
696
704
|
corresponding_token_depth = spaces_of_nest.pop
|
@@ -712,7 +720,7 @@ class RubyLex
|
|
712
720
|
end_type = []
|
713
721
|
while i < tokens.size
|
714
722
|
t = tokens[i]
|
715
|
-
case t
|
723
|
+
case t.event
|
716
724
|
when *end_type.last
|
717
725
|
start_token.pop
|
718
726
|
end_type.pop
|
@@ -725,7 +733,7 @@ class RubyLex
|
|
725
733
|
when :on_symbeg
|
726
734
|
acceptable_single_tokens = %i{on_ident on_const on_op on_cvar on_ivar on_gvar on_kw on_int on_backtick}
|
727
735
|
if (i + 1) < tokens.size
|
728
|
-
if acceptable_single_tokens.all?{ |st| tokens[i + 1]
|
736
|
+
if acceptable_single_tokens.all?{ |st| tokens[i + 1].event != st }
|
729
737
|
start_token << t
|
730
738
|
end_type << :on_tstring_end
|
731
739
|
else
|
@@ -744,14 +752,16 @@ class RubyLex
|
|
744
752
|
end
|
745
753
|
i += 1
|
746
754
|
end
|
747
|
-
start_token.last.nil? ?
|
755
|
+
start_token.last.nil? ? nil : start_token.last
|
748
756
|
end
|
749
757
|
|
750
758
|
def process_literal_type(tokens = @tokens)
|
751
759
|
start_token = check_string_literal(tokens)
|
752
|
-
|
760
|
+
return nil if start_token == ""
|
761
|
+
|
762
|
+
case start_token&.event
|
753
763
|
when :on_tstring_beg
|
754
|
-
case start_token
|
764
|
+
case start_token&.tok
|
755
765
|
when ?" then ?"
|
756
766
|
when /^%.$/ then ?"
|
757
767
|
when /^%Q.$/ then ?"
|
@@ -766,7 +776,7 @@ class RubyLex
|
|
766
776
|
when :on_qsymbols_beg then ?]
|
767
777
|
when :on_symbols_beg then ?]
|
768
778
|
when :on_heredoc_beg
|
769
|
-
start_token
|
779
|
+
start_token&.tok =~ /<<[-~]?(['"`])[_a-zA-Z0-9]+\1/
|
770
780
|
case $1
|
771
781
|
when ?" then ?"
|
772
782
|
when ?' then ?'
|
@@ -794,6 +804,7 @@ class RubyLex
|
|
794
804
|
false
|
795
805
|
end
|
796
806
|
end
|
807
|
+
|
797
808
|
if index
|
798
809
|
first_token = nil
|
799
810
|
last_line_tokens = tokens[(index + 1)..(tokens.size - 1)]
|
@@ -803,6 +814,7 @@ class RubyLex
|
|
803
814
|
break
|
804
815
|
end
|
805
816
|
end
|
817
|
+
|
806
818
|
if first_token.nil?
|
807
819
|
return false
|
808
820
|
elsif first_token && first_token.state == Ripper::EXPR_DOT
|
@@ -829,5 +841,21 @@ class RubyLex
|
|
829
841
|
heredoc_tokens = @tokens.select { |t| [:on_heredoc_beg, :on_heredoc_end].include?(t.event) }
|
830
842
|
heredoc_tokens[-1]&.event == :on_heredoc_beg
|
831
843
|
end
|
844
|
+
|
845
|
+
def in_keyword_case_scope?
|
846
|
+
kw_tokens = @tokens.select { |t| t.event == :on_kw && ['case', 'for', 'end'].include?(t.tok) }
|
847
|
+
counter = 0
|
848
|
+
kw_tokens.reverse.each do |t|
|
849
|
+
if t.tok == 'case'
|
850
|
+
return true if counter.zero?
|
851
|
+
counter += 1
|
852
|
+
elsif t.tok == 'for'
|
853
|
+
counter += 1
|
854
|
+
elsif t.tok == 'end'
|
855
|
+
counter -= 1
|
856
|
+
end
|
857
|
+
end
|
858
|
+
false
|
859
|
+
end
|
832
860
|
end
|
833
861
|
# :startdoc:
|
data/lib/irb/version.rb
CHANGED
data/lib/irb.rb
CHANGED
@@ -62,6 +62,7 @@ require_relative "irb/easter-egg"
|
|
62
62
|
# -W[level=2] Same as `ruby -W`
|
63
63
|
# --context-mode n Set n[0-4] to method to create Binding Object,
|
64
64
|
# when new workspace was created
|
65
|
+
# --extra-doc-dir Add an extra doc dir for the doc dialog
|
65
66
|
# --echo Show result (default)
|
66
67
|
# --noecho Don't show result
|
67
68
|
# --echo-on-assignment
|
@@ -823,17 +824,20 @@ module IRB
|
|
823
824
|
diff_size = output_width - Reline::Unicode.calculate_width(first_line, true)
|
824
825
|
if diff_size.positive? and output_width > winwidth
|
825
826
|
lines, _ = Reline::Unicode.split_by_width(first_line, winwidth - diff_size - 3)
|
826
|
-
str = "%s
|
827
|
+
str = "%s..." % lines.first
|
828
|
+
str += "\e[0m" if @context.use_colorize
|
827
829
|
multiline_p = false
|
828
830
|
else
|
829
831
|
str = str.gsub(/(\A.*?\n).*/m, "\\1...")
|
832
|
+
str += "\e[0m" if @context.use_colorize
|
830
833
|
end
|
831
834
|
else
|
832
835
|
output_width = Reline::Unicode.calculate_width(@context.return_format % str, true)
|
833
836
|
diff_size = output_width - Reline::Unicode.calculate_width(str, true)
|
834
837
|
if diff_size.positive? and output_width > winwidth
|
835
838
|
lines, _ = Reline::Unicode.split_by_width(str, winwidth - diff_size - 3)
|
836
|
-
str = "%s
|
839
|
+
str = "%s..." % lines.first
|
840
|
+
str += "\e[0m" if @context.use_colorize
|
837
841
|
end
|
838
842
|
end
|
839
843
|
end
|
data/man/irb.1
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.
|
4
|
+
version: 1.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Keiju ISHITSUKA
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-
|
11
|
+
date: 2021-12-24 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.3.0
|
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.3.0
|
27
27
|
description: Interactive Ruby command-line tool for REPL (Read Eval Print Loop).
|
28
28
|
email:
|
29
29
|
- keiju@ruby-lang.org
|
@@ -108,9 +108,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
108
108
|
version: '2.5'
|
109
109
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
110
110
|
requirements:
|
111
|
-
- - "
|
111
|
+
- - ">="
|
112
112
|
- !ruby/object:Gem::Version
|
113
|
-
version:
|
113
|
+
version: '0'
|
114
114
|
requirements: []
|
115
115
|
rubygems_version: 3.2.22
|
116
116
|
signing_key:
|