irb 1.6.4 → 1.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/irb/cmd/help.rb +12 -46
- data/lib/irb/cmd/ls.rb +5 -2
- data/lib/irb/cmd/show_doc.rb +48 -0
- data/lib/irb/cmd/show_source.rb +4 -3
- data/lib/irb/ext/tracer.rb +1 -1
- data/lib/irb/extend-command.rb +5 -1
- data/lib/irb/help.rb +1 -3
- data/lib/irb/input-method.rb +4 -3
- data/lib/irb/locale.rb +10 -43
- data/lib/irb/ruby-lex.rb +70 -88
- data/lib/irb/version.rb +2 -2
- data/lib/irb.rb +2 -2
- metadata +4 -5
- data/lib/irb/lc/ja/encoding_aliases.rb +0 -13
- data/lib/irb/magic-file.rb +0 -38
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fa3c9603f48d730988d34f454a10b58021caa677ab8832d9764e39e61bb49abb
|
4
|
+
data.tar.gz: c46d1e32c81a8f22593e174af095070159af6a61508c97b3ef4b0b9d28301d58
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3e99185c909180d01a3310f7db11437181268b930d267f2fe365c06cd7a442ad3a8cdf7d5863fb19e17885a23aad46b993a2e5c21fb8632ff2f91285e469be4b
|
7
|
+
data.tar.gz: 44978be86d00d0fc435e81e4cadc5abad08d47519a189db02e34d7eb3435e9ac0cc0adf470e845edba1e7d866574298e1b7b8bba5190d8be538c396cd0179d07
|
data/lib/irb/cmd/help.rb
CHANGED
@@ -1,57 +1,23 @@
|
|
1
|
-
# frozen_string_literal:
|
2
|
-
#
|
3
|
-
# help.rb - helper using ri
|
4
|
-
#
|
1
|
+
# frozen_string_literal: true
|
5
2
|
|
6
|
-
require_relative "
|
3
|
+
require_relative "show_doc"
|
7
4
|
|
8
5
|
module IRB
|
9
|
-
# :stopdoc:
|
10
|
-
|
11
6
|
module ExtendCommand
|
12
|
-
class Help <
|
13
|
-
class << self
|
14
|
-
def transform_args(args)
|
15
|
-
# Return a string literal as is for backward compatibility
|
16
|
-
if args.empty? || string_literal?(args)
|
17
|
-
args
|
18
|
-
else # Otherwise, consider the input as a String for convenience
|
19
|
-
args.strip.dump
|
20
|
-
end
|
21
|
-
end
|
22
|
-
end
|
23
|
-
|
7
|
+
class Help < ShowDoc
|
24
8
|
category "Context"
|
25
|
-
description "Enter the mode to look up RI documents."
|
9
|
+
description "[DEPRECATED] Enter the mode to look up RI documents."
|
10
|
+
|
11
|
+
DEPRECATION_MESSAGE = <<~MSG
|
12
|
+
[Deprecation] The `help` command will be repurposed to display command help in the future.
|
13
|
+
For RI document lookup, please use the `show_doc` command instead.
|
14
|
+
For command help, please use `show_cmds` for now.
|
15
|
+
MSG
|
26
16
|
|
27
17
|
def execute(*names)
|
28
|
-
|
29
|
-
|
30
|
-
IRB::ExtendCommand::Help.const_set(:Ri, RDoc::RI::Driver.new(opts))
|
31
|
-
rescue LoadError, SystemExit
|
32
|
-
IRB::ExtendCommand::Help.remove_method(:execute)
|
33
|
-
# raise NoMethodError in ensure
|
34
|
-
else
|
35
|
-
def execute(*names)
|
36
|
-
if names.empty?
|
37
|
-
Ri.interactive
|
38
|
-
return
|
39
|
-
end
|
40
|
-
names.each do |name|
|
41
|
-
begin
|
42
|
-
Ri.display_name(name.to_s)
|
43
|
-
rescue RDoc::RI::Error
|
44
|
-
puts $!.message
|
45
|
-
end
|
46
|
-
end
|
47
|
-
nil
|
48
|
-
end
|
49
|
-
nil
|
50
|
-
ensure
|
51
|
-
execute(*names)
|
18
|
+
warn DEPRECATION_MESSAGE
|
19
|
+
super
|
52
20
|
end
|
53
21
|
end
|
54
22
|
end
|
55
|
-
|
56
|
-
# :startdoc:
|
57
23
|
end
|
data/lib/irb/cmd/ls.rb
CHANGED
@@ -39,8 +39,12 @@ module IRB
|
|
39
39
|
def dump_methods(o, klass, obj)
|
40
40
|
singleton_class = begin obj.singleton_class; rescue TypeError; nil end
|
41
41
|
dumped_mods = Array.new
|
42
|
+
ancestors = klass.ancestors
|
43
|
+
ancestors = ancestors.reject { |c| c >= Object } if klass < Object
|
44
|
+
singleton_ancestors = (singleton_class&.ancestors || []).reject { |c| c >= Class }
|
45
|
+
|
42
46
|
# singleton_class' ancestors should be at the front
|
43
|
-
maps = class_method_map(
|
47
|
+
maps = class_method_map(singleton_ancestors, dumped_mods) + class_method_map(ancestors, dumped_mods)
|
44
48
|
maps.each do |mod, methods|
|
45
49
|
name = mod == singleton_class ? "#{klass}.methods" : "#{mod}#methods"
|
46
50
|
o.dump(name, methods)
|
@@ -49,7 +53,6 @@ module IRB
|
|
49
53
|
|
50
54
|
def class_method_map(classes, dumped_mods)
|
51
55
|
dumped_methods = Array.new
|
52
|
-
classes = classes.reject { |mod| mod >= Object }
|
53
56
|
classes.map do |mod|
|
54
57
|
next if dumped_mods.include? mod
|
55
58
|
|
@@ -0,0 +1,48 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative "nop"
|
4
|
+
|
5
|
+
module IRB
|
6
|
+
module ExtendCommand
|
7
|
+
class ShowDoc < Nop
|
8
|
+
class << self
|
9
|
+
def transform_args(args)
|
10
|
+
# Return a string literal as is for backward compatibility
|
11
|
+
if args.empty? || string_literal?(args)
|
12
|
+
args
|
13
|
+
else # Otherwise, consider the input as a String for convenience
|
14
|
+
args.strip.dump
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
category "Context"
|
20
|
+
description "Enter the mode to look up RI documents."
|
21
|
+
|
22
|
+
def execute(*names)
|
23
|
+
require 'rdoc/ri/driver'
|
24
|
+
|
25
|
+
unless ShowDoc.const_defined?(:Ri)
|
26
|
+
opts = RDoc::RI::Driver.process_args([])
|
27
|
+
ShowDoc.const_set(:Ri, RDoc::RI::Driver.new(opts))
|
28
|
+
end
|
29
|
+
|
30
|
+
if names.empty?
|
31
|
+
Ri.interactive
|
32
|
+
else
|
33
|
+
names.each do |name|
|
34
|
+
begin
|
35
|
+
Ri.display_name(name.to_s)
|
36
|
+
rescue RDoc::RI::Error
|
37
|
+
puts $!.message
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
nil
|
43
|
+
rescue LoadError, SystemExit
|
44
|
+
warn "Can't display document because `rdoc` is not installed."
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
data/lib/irb/cmd/show_source.rb
CHANGED
@@ -31,13 +31,14 @@ module IRB
|
|
31
31
|
when /\A(?<owner>[A-Z]\w*(::[A-Z]\w*)*)#(?<method>[^ :.]+)\z/ # Class#method
|
32
32
|
owner = eval(Regexp.last_match[:owner], irb_context.workspace.binding)
|
33
33
|
method = Regexp.last_match[:method]
|
34
|
-
if owner.respond_to?(:instance_method)
|
35
|
-
|
34
|
+
if owner.respond_to?(:instance_method)
|
35
|
+
methods = owner.instance_methods + owner.private_instance_methods
|
36
|
+
file, line = owner.instance_method(method).source_location if methods.include?(method.to_sym)
|
36
37
|
end
|
37
38
|
when /\A((?<receiver>.+)(\.|::))?(?<method>[^ :.]+)\z/ # method, receiver.method, receiver::method
|
38
39
|
receiver = eval(Regexp.last_match[:receiver] || 'self', irb_context.workspace.binding)
|
39
40
|
method = Regexp.last_match[:method]
|
40
|
-
file, line = receiver.method(method).source_location if receiver.respond_to?(method)
|
41
|
+
file, line = receiver.method(method).source_location if receiver.respond_to?(method, true)
|
41
42
|
end
|
42
43
|
if file && line
|
43
44
|
Source.new(file: file, first_line: line, last_line: find_end(file, line, irb_context))
|
data/lib/irb/ext/tracer.rb
CHANGED
@@ -7,7 +7,7 @@
|
|
7
7
|
begin
|
8
8
|
require "tracer"
|
9
9
|
rescue LoadError
|
10
|
-
$stderr.puts "Tracer extension of IRB is enabled but tracer gem
|
10
|
+
$stderr.puts "Tracer extension of IRB is enabled but tracer gem wasn't found."
|
11
11
|
module IRB
|
12
12
|
class Context
|
13
13
|
def use_tracer=(opt)
|
data/lib/irb/extend-command.rb
CHANGED
@@ -157,10 +157,14 @@ module IRB # :nodoc:
|
|
157
157
|
|
158
158
|
[
|
159
159
|
:irb_help, :Help, "cmd/help",
|
160
|
-
[:show_doc, NO_OVERRIDE],
|
161
160
|
[:help, NO_OVERRIDE],
|
162
161
|
],
|
163
162
|
|
163
|
+
[
|
164
|
+
:irb_show_doc, :ShowDoc, "cmd/show_doc",
|
165
|
+
[:show_doc, NO_OVERRIDE],
|
166
|
+
],
|
167
|
+
|
164
168
|
[
|
165
169
|
:irb_info, :IrbInfo, "cmd/irb_info"
|
166
170
|
],
|
data/lib/irb/help.rb
CHANGED
@@ -4,15 +4,13 @@
|
|
4
4
|
# by Keiju ISHITSUKA(keiju@ishitsuka.com)
|
5
5
|
#
|
6
6
|
|
7
|
-
require_relative 'magic-file'
|
8
|
-
|
9
7
|
module IRB
|
10
8
|
# Outputs the irb help message, see IRB@Command+line+options.
|
11
9
|
def IRB.print_usage
|
12
10
|
lc = IRB.conf[:LC_MESSAGES]
|
13
11
|
path = lc.find("irb/help-message")
|
14
12
|
space_line = false
|
15
|
-
|
13
|
+
File.open(path){|f|
|
16
14
|
f.each_line do |l|
|
17
15
|
if /^\s*$/ =~ l
|
18
16
|
lc.puts l unless space_line
|
data/lib/irb/input-method.rb
CHANGED
@@ -5,7 +5,6 @@
|
|
5
5
|
#
|
6
6
|
|
7
7
|
require_relative 'src_encoding'
|
8
|
-
require_relative 'magic-file'
|
9
8
|
require_relative 'completion'
|
10
9
|
require 'io/console'
|
11
10
|
require 'reline'
|
@@ -132,7 +131,7 @@ module IRB
|
|
132
131
|
# Creates a new input method object
|
133
132
|
def initialize(file)
|
134
133
|
super
|
135
|
-
@io = file.is_a?(IO) ? file :
|
134
|
+
@io = file.is_a?(IO) ? file : File.open(file)
|
136
135
|
@external_encoding = @io.external_encoding
|
137
136
|
end
|
138
137
|
# The file name of this input method, usually given during initialization.
|
@@ -399,8 +398,10 @@ module IRB
|
|
399
398
|
formatter = RDoc::Markup::ToAnsi.new
|
400
399
|
formatter.width = width
|
401
400
|
dialog.trap_key = alt_d
|
402
|
-
|
401
|
+
mod_key = RUBY_PLATFORM.match?(/darwin/) ? "Option" : "Alt"
|
402
|
+
message = "Press #{mod_key}+d to read the full document"
|
403
403
|
contents = [message] + doc.accept(formatter).split("\n")
|
404
|
+
contents = contents.take(preferred_dialog_height) if respond_to?(:preferred_dialog_height)
|
404
405
|
|
405
406
|
y = cursor_pos_to_render.y
|
406
407
|
DialogRenderInfo.new(pos: Reline::CursorPos.new(x, y), contents: contents, width: width, bg_color: '49')
|
data/lib/irb/locale.rb
CHANGED
@@ -15,7 +15,11 @@ module IRB # :nodoc:
|
|
15
15
|
]x
|
16
16
|
LOCALE_DIR = "/lc/"
|
17
17
|
|
18
|
-
|
18
|
+
LEGACY_ENCODING_ALIAS_MAP = {
|
19
|
+
'ujis' => Encoding::EUC_JP,
|
20
|
+
'euc' => Encoding::EUC_JP
|
21
|
+
}
|
22
|
+
|
19
23
|
@@loaded = []
|
20
24
|
|
21
25
|
def initialize(locale = nil)
|
@@ -26,11 +30,11 @@ module IRB # :nodoc:
|
|
26
30
|
@lang, @territory, @encoding_name, @modifier = m[:language], m[:territory], m[:codeset], m[:modifier]
|
27
31
|
|
28
32
|
if @encoding_name
|
29
|
-
|
30
|
-
if @encoding = @@legacy_encoding_alias_map[@encoding_name]
|
33
|
+
if @encoding = LEGACY_ENCODING_ALIAS_MAP[@encoding_name]
|
31
34
|
warn(("%s is obsolete. use %s" % ["#{@lang}_#{@territory}.#{@encoding_name}", "#{@lang}_#{@territory}.#{@encoding.name}"]), uplevel: 1)
|
35
|
+
else
|
36
|
+
@encoding = Encoding.find(@encoding_name) rescue nil
|
32
37
|
end
|
33
|
-
@encoding = Encoding.find(@encoding_name) rescue nil
|
34
38
|
end
|
35
39
|
end
|
36
40
|
@encoding ||= (Encoding.find('locale') rescue Encoding::ASCII_8BIT)
|
@@ -78,39 +82,12 @@ module IRB # :nodoc:
|
|
78
82
|
super(*ary)
|
79
83
|
end
|
80
84
|
|
81
|
-
def
|
82
|
-
rex = Regexp.new("lc/#{Regexp.quote(file)}\.(so|o|sl|rb)?")
|
83
|
-
return false if $".find{|f| f =~ rex}
|
84
|
-
|
85
|
-
case file
|
86
|
-
when /\.rb$/
|
87
|
-
begin
|
88
|
-
load(file, priv)
|
89
|
-
$".push file
|
90
|
-
return true
|
91
|
-
rescue LoadError
|
92
|
-
end
|
93
|
-
when /\.(so|o|sl)$/
|
94
|
-
return super
|
95
|
-
end
|
96
|
-
|
97
|
-
begin
|
98
|
-
load(f = file + ".rb")
|
99
|
-
$".push f #"
|
100
|
-
return true
|
101
|
-
rescue LoadError
|
102
|
-
return ruby_require(file)
|
103
|
-
end
|
104
|
-
end
|
105
|
-
|
106
|
-
alias toplevel_load load
|
107
|
-
|
108
|
-
def load(file, priv=nil)
|
85
|
+
def load(file)
|
109
86
|
found = find(file)
|
110
87
|
if found
|
111
88
|
unless @@loaded.include?(found)
|
112
89
|
@@loaded << found # cache
|
113
|
-
|
90
|
+
Kernel.load(found)
|
114
91
|
end
|
115
92
|
else
|
116
93
|
raise LoadError, "No such file to load -- #{file}"
|
@@ -129,16 +106,6 @@ module IRB # :nodoc:
|
|
129
106
|
end
|
130
107
|
end
|
131
108
|
|
132
|
-
private
|
133
|
-
def real_load(path, priv)
|
134
|
-
src = MagicFile.open(path){|f| f.read}
|
135
|
-
if priv
|
136
|
-
eval("self", TOPLEVEL_BINDING).extend(Module.new {eval(src, nil, path)})
|
137
|
-
else
|
138
|
-
eval(src, TOPLEVEL_BINDING, path)
|
139
|
-
end
|
140
|
-
end
|
141
|
-
|
142
109
|
# @param paths load paths in which IRB find a localized file.
|
143
110
|
# @param dir directory
|
144
111
|
# @param file basename to be localized
|
data/lib/irb/ruby-lex.rb
CHANGED
@@ -18,10 +18,7 @@ class RubyLex
|
|
18
18
|
|
19
19
|
def initialize(context)
|
20
20
|
@context = context
|
21
|
-
@
|
22
|
-
@indent = 0
|
23
|
-
@continue = false
|
24
|
-
@line = ""
|
21
|
+
@line_no = 1
|
25
22
|
@prompt = nil
|
26
23
|
end
|
27
24
|
|
@@ -42,8 +39,17 @@ class RubyLex
|
|
42
39
|
result
|
43
40
|
end
|
44
41
|
|
42
|
+
def single_line_command?(code)
|
43
|
+
command = code.split(/\s/, 2).first
|
44
|
+
@context.symbol_alias?(command) || @context.transform_args?(command)
|
45
|
+
end
|
46
|
+
|
45
47
|
# io functions
|
46
|
-
def set_input(
|
48
|
+
def set_input(&block)
|
49
|
+
@input = block
|
50
|
+
end
|
51
|
+
|
52
|
+
def configure_io(io)
|
47
53
|
@io = io
|
48
54
|
if @io.respond_to?(:check_termination)
|
49
55
|
@io.check_termination do |code|
|
@@ -61,14 +67,9 @@ class RubyLex
|
|
61
67
|
end
|
62
68
|
else
|
63
69
|
# Accept any single-line input for symbol aliases or commands that transform args
|
64
|
-
|
65
|
-
if @context.symbol_alias?(command) || @context.transform_args?(command)
|
66
|
-
next true
|
67
|
-
end
|
70
|
+
next true if single_line_command?(code)
|
68
71
|
|
69
|
-
|
70
|
-
tokens = self.class.ripper_lex_without_warning(code, context: @context)
|
71
|
-
ltype, indent, continue, code_block_open = check_state(code, tokens)
|
72
|
+
ltype, indent, continue, code_block_open = check_code_state(code)
|
72
73
|
if ltype or indent > 0 or continue or code_block_open
|
73
74
|
false
|
74
75
|
else
|
@@ -112,10 +113,22 @@ class RubyLex
|
|
112
113
|
end
|
113
114
|
end
|
114
115
|
|
115
|
-
if
|
116
|
-
@
|
117
|
-
|
118
|
-
|
116
|
+
if @io.respond_to?(:auto_indent) and @context.auto_indent_mode
|
117
|
+
@io.auto_indent do |lines, line_index, byte_pointer, is_newline|
|
118
|
+
if is_newline
|
119
|
+
@tokens = self.class.ripper_lex_without_warning(lines[0..line_index].join("\n"), context: @context)
|
120
|
+
prev_spaces = find_prev_spaces(line_index)
|
121
|
+
depth_difference = check_newline_depth_difference
|
122
|
+
depth_difference = 0 if depth_difference < 0
|
123
|
+
prev_spaces + depth_difference * 2
|
124
|
+
else
|
125
|
+
code = line_index.zero? ? '' : lines[0..(line_index - 1)].map{ |l| l + "\n" }.join
|
126
|
+
last_line = lines[line_index]&.byteslice(0, byte_pointer)
|
127
|
+
code += last_line if last_line
|
128
|
+
@tokens = self.class.ripper_lex_without_warning(code, context: @context)
|
129
|
+
check_corresponding_token_depth(lines, line_index)
|
130
|
+
end
|
131
|
+
end
|
119
132
|
end
|
120
133
|
end
|
121
134
|
|
@@ -184,26 +197,6 @@ class RubyLex
|
|
184
197
|
prev_spaces
|
185
198
|
end
|
186
199
|
|
187
|
-
def set_auto_indent
|
188
|
-
if @io.respond_to?(:auto_indent) and @context.auto_indent_mode
|
189
|
-
@io.auto_indent do |lines, line_index, byte_pointer, is_newline|
|
190
|
-
if is_newline
|
191
|
-
@tokens = self.class.ripper_lex_without_warning(lines[0..line_index].join("\n"), context: @context)
|
192
|
-
prev_spaces = find_prev_spaces(line_index)
|
193
|
-
depth_difference = check_newline_depth_difference
|
194
|
-
depth_difference = 0 if depth_difference < 0
|
195
|
-
prev_spaces + depth_difference * 2
|
196
|
-
else
|
197
|
-
code = line_index.zero? ? '' : lines[0..(line_index - 1)].map{ |l| l + "\n" }.join
|
198
|
-
last_line = lines[line_index]&.byteslice(0, byte_pointer)
|
199
|
-
code += last_line if last_line
|
200
|
-
@tokens = self.class.ripper_lex_without_warning(code, context: @context)
|
201
|
-
check_corresponding_token_depth(lines, line_index)
|
202
|
-
end
|
203
|
-
end
|
204
|
-
end
|
205
|
-
end
|
206
|
-
|
207
200
|
def check_state(code, tokens)
|
208
201
|
ltype = process_literal_type(tokens)
|
209
202
|
indent = process_nesting_level(tokens)
|
@@ -214,67 +207,56 @@ class RubyLex
|
|
214
207
|
[ltype, indent, continue, code_block_open]
|
215
208
|
end
|
216
209
|
|
217
|
-
def
|
218
|
-
|
219
|
-
|
220
|
-
|
210
|
+
def check_code_state(code)
|
211
|
+
check_target_code = code.gsub(/\s*\z/, '').concat("\n")
|
212
|
+
tokens = self.class.ripper_lex_without_warning(check_target_code, context: @context)
|
213
|
+
check_state(check_target_code, tokens)
|
221
214
|
end
|
222
215
|
|
223
|
-
def
|
224
|
-
|
225
|
-
@indent
|
226
|
-
@continue = false
|
227
|
-
@line = ""
|
228
|
-
@exp_line_no = @line_no
|
229
|
-
@code_block_open = false
|
216
|
+
def save_prompt_to_context_io(ltype, indent, continue, line_num_offset)
|
217
|
+
# Implicitly saves prompt string to `@context.io.prompt`. This will be used in the next `@input.call`.
|
218
|
+
@prompt.call(ltype, indent, continue, @line_no + line_num_offset)
|
230
219
|
end
|
231
220
|
|
232
|
-
def
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
end
|
246
|
-
@line.concat l
|
247
|
-
if @code_block_open or @ltype or @continue or @indent > 0
|
248
|
-
next
|
249
|
-
end
|
250
|
-
end
|
251
|
-
if @line != "\n"
|
252
|
-
@line.force_encoding(@io.encoding)
|
253
|
-
yield @line, @exp_line_no
|
254
|
-
end
|
255
|
-
raise TerminateLineInput if @io.eof?
|
256
|
-
@line = ''
|
257
|
-
@exp_line_no = @line_no
|
258
|
-
|
259
|
-
@indent = 0
|
260
|
-
rescue TerminateLineInput
|
261
|
-
initialize_input
|
262
|
-
prompt
|
263
|
-
end
|
221
|
+
def readmultiline
|
222
|
+
save_prompt_to_context_io(nil, 0, false, 0)
|
223
|
+
|
224
|
+
# multiline
|
225
|
+
return @input.call if @io.respond_to?(:check_termination)
|
226
|
+
|
227
|
+
# nomultiline
|
228
|
+
code = ''
|
229
|
+
line_offset = 0
|
230
|
+
loop do
|
231
|
+
line = @input.call
|
232
|
+
unless line
|
233
|
+
return code.empty? ? nil : code
|
264
234
|
end
|
235
|
+
|
236
|
+
code << line
|
237
|
+
# Accept any single-line input for symbol aliases or commands that transform args
|
238
|
+
return code if single_line_command?(code)
|
239
|
+
|
240
|
+
ltype, indent, continue, code_block_open = check_code_state(code)
|
241
|
+
return code unless ltype or indent > 0 or continue or code_block_open
|
242
|
+
|
243
|
+
line_offset += 1
|
244
|
+
save_prompt_to_context_io(ltype, indent, continue, line_offset)
|
265
245
|
end
|
266
246
|
end
|
267
247
|
|
268
|
-
def
|
269
|
-
|
270
|
-
|
271
|
-
|
248
|
+
def each_top_level_statement
|
249
|
+
loop do
|
250
|
+
code = readmultiline
|
251
|
+
break unless code
|
252
|
+
|
253
|
+
if code != "\n"
|
254
|
+
code.force_encoding(@io.encoding)
|
255
|
+
yield code, @line_no
|
256
|
+
end
|
257
|
+
@line_no += code.count("\n")
|
258
|
+
rescue TerminateLineInput
|
272
259
|
end
|
273
|
-
code = @line + (line.nil? ? '' : line)
|
274
|
-
code.gsub!(/\s*\z/, '').concat("\n")
|
275
|
-
@tokens = self.class.ripper_lex_without_warning(code, context: @context)
|
276
|
-
@ltype, @indent, @continue, @code_block_open = check_state(code, @tokens)
|
277
|
-
line
|
278
260
|
end
|
279
261
|
|
280
262
|
def process_continue(tokens)
|
data/lib/irb/version.rb
CHANGED
data/lib/irb.rb
CHANGED
@@ -537,7 +537,7 @@ module IRB
|
|
537
537
|
@context.io.prompt
|
538
538
|
end
|
539
539
|
|
540
|
-
@scanner.set_input
|
540
|
+
@scanner.set_input do
|
541
541
|
signal_status(:IN_INPUT) do
|
542
542
|
if l = @context.io.gets
|
543
543
|
print l if @context.verbose?
|
@@ -555,7 +555,7 @@ module IRB
|
|
555
555
|
end
|
556
556
|
end
|
557
557
|
|
558
|
-
@scanner.
|
558
|
+
@scanner.configure_io(@context.io)
|
559
559
|
|
560
560
|
@scanner.each_top_level_statement do |line, line_no|
|
561
561
|
signal_status(:IN_EVAL) do
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: irb
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.7.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- aycabta
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: exe
|
11
11
|
cert_chain: []
|
12
|
-
date: 2023-04
|
12
|
+
date: 2023-06-04 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: reline
|
@@ -66,6 +66,7 @@ files:
|
|
66
66
|
- lib/irb/cmd/nop.rb
|
67
67
|
- lib/irb/cmd/pushws.rb
|
68
68
|
- lib/irb/cmd/show_cmds.rb
|
69
|
+
- lib/irb/cmd/show_doc.rb
|
69
70
|
- lib/irb/cmd/show_source.rb
|
70
71
|
- lib/irb/cmd/step.rb
|
71
72
|
- lib/irb/cmd/subirb.rb
|
@@ -91,11 +92,9 @@ files:
|
|
91
92
|
- lib/irb/inspector.rb
|
92
93
|
- lib/irb/lc/error.rb
|
93
94
|
- lib/irb/lc/help-message
|
94
|
-
- lib/irb/lc/ja/encoding_aliases.rb
|
95
95
|
- lib/irb/lc/ja/error.rb
|
96
96
|
- lib/irb/lc/ja/help-message
|
97
97
|
- lib/irb/locale.rb
|
98
|
-
- lib/irb/magic-file.rb
|
99
98
|
- lib/irb/notifier.rb
|
100
99
|
- lib/irb/output-method.rb
|
101
100
|
- lib/irb/ruby-lex.rb
|
@@ -130,7 +129,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
130
129
|
- !ruby/object:Gem::Version
|
131
130
|
version: '0'
|
132
131
|
requirements: []
|
133
|
-
rubygems_version: 3.
|
132
|
+
rubygems_version: 3.5.0.dev
|
134
133
|
signing_key:
|
135
134
|
specification_version: 4
|
136
135
|
summary: Interactive Ruby command-line tool for REPL (Read Eval Print Loop).
|
data/lib/irb/magic-file.rb
DELETED
@@ -1,38 +0,0 @@
|
|
1
|
-
# frozen_string_literal: false
|
2
|
-
module IRB
|
3
|
-
class << (MagicFile = Object.new)
|
4
|
-
# see parser_magic_comment in parse.y
|
5
|
-
ENCODING_SPEC_RE = %r"coding\s*[=:]\s*([[:alnum:]\-_]+)"
|
6
|
-
|
7
|
-
def open(path)
|
8
|
-
io = File.open(path, 'rb')
|
9
|
-
line = io.gets
|
10
|
-
line = io.gets if line[0,2] == "#!"
|
11
|
-
encoding = detect_encoding(line)
|
12
|
-
internal_encoding = encoding
|
13
|
-
encoding ||= IRB.default_src_encoding
|
14
|
-
io.rewind
|
15
|
-
io.set_encoding(encoding, internal_encoding)
|
16
|
-
|
17
|
-
if block_given?
|
18
|
-
begin
|
19
|
-
return (yield io)
|
20
|
-
ensure
|
21
|
-
io.close
|
22
|
-
end
|
23
|
-
else
|
24
|
-
return io
|
25
|
-
end
|
26
|
-
end
|
27
|
-
|
28
|
-
private
|
29
|
-
def detect_encoding(line)
|
30
|
-
return unless line[0] == ?#
|
31
|
-
line = line[1..-1]
|
32
|
-
line = $1 if line[/-\*-\s*(.*?)\s*-*-$/]
|
33
|
-
return nil unless ENCODING_SPEC_RE =~ line
|
34
|
-
encoding = $1
|
35
|
-
return encoding.sub(/-(?:mac|dos|unix)/i, '')
|
36
|
-
end
|
37
|
-
end
|
38
|
-
end
|