irb 1.3.6 → 1.3.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 +4 -4
- data/irb.gemspec +1 -1
- data/lib/irb.rb +1 -1
- data/lib/irb/cmd/info.rb +6 -0
- data/lib/irb/cmd/ls.rb +9 -15
- data/lib/irb/cmd/measure.rb +3 -0
- data/lib/irb/cmd/show_source.rb +13 -3
- data/lib/irb/ruby-lex.rb +33 -18
- data/lib/irb/version.rb +2 -2
- metadata +9 -9
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ddb63fc9d57700014a7da313e20504596ca42dfee0952547fa545d726f08d7d6
|
4
|
+
data.tar.gz: cc4ee2f880d56dc7f792ecc406f489f8555601d19499f45d8f8828cc260ed1b0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c5b128b8ce5457862489e313231af33167802619c3847da526dda30c83f7fc96d1a248d2916e17da4cbd45f8d30aee8c181237182b97b5741cf4bc4c13568bfb
|
7
|
+
data.tar.gz: 61147b2b4e76f34076043feaa84feeb2e893a140d3d7d1e5013a00f87f27f694802f8ae21788709a7ee03c5b41ee445735aec93bfedbeaa9fcf02d6bf06f705d
|
data/irb.gemspec
CHANGED
data/lib/irb.rb
CHANGED
data/lib/irb/cmd/info.rb
CHANGED
@@ -14,6 +14,12 @@ module IRB
|
|
14
14
|
str += "InputMethod: #{IRB.CurrentContext.io.inspect}\n"
|
15
15
|
str += ".irbrc path: #{IRB.rc_file}\n" if File.exist?(IRB.rc_file)
|
16
16
|
str += "RUBY_PLATFORM: #{RUBY_PLATFORM}\n"
|
17
|
+
str += "LANG env: #{ENV["LANG"]}\n" if ENV["LANG"] && !ENV["LANG"].empty?
|
18
|
+
str += "LC_ALL env: #{ENV["LC_ALL"]}\n" if ENV["LC_ALL"] && !ENV["LC_ALL"].empty?
|
19
|
+
if RbConfig::CONFIG['host_os'] =~ /mswin|msys|mingw|cygwin|bccwin|wince|emc/
|
20
|
+
codepage = `chcp`.sub(/.*: (\d+)\n/, '\1')
|
21
|
+
str += "Code page: #{codepage}\n"
|
22
|
+
end
|
17
23
|
str
|
18
24
|
end
|
19
25
|
alias_method :to_s, :inspect
|
data/lib/irb/cmd/ls.rb
CHANGED
@@ -1,7 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require "reline"
|
4
|
-
require 'set'
|
5
4
|
require_relative "nop"
|
6
5
|
require_relative "../color"
|
7
6
|
|
@@ -17,32 +16,27 @@ module IRB
|
|
17
16
|
klass = (obj.class == Class || obj.class == Module ? obj : obj.class)
|
18
17
|
|
19
18
|
o.dump("constants", obj.constants) if obj.respond_to?(:constants)
|
20
|
-
|
21
|
-
dump_instance_methods(o, klass)
|
19
|
+
dump_methods(o, klass, obj)
|
22
20
|
o.dump("instance variables", obj.instance_variables)
|
23
21
|
o.dump("class variables", klass.class_variables)
|
24
22
|
o.dump("locals", locals)
|
25
23
|
end
|
26
24
|
|
27
|
-
def
|
28
|
-
|
25
|
+
def dump_methods(o, klass, obj)
|
26
|
+
singleton_class = begin obj.singleton_class; rescue TypeError; nil end
|
27
|
+
maps = class_method_map((singleton_class || klass).ancestors)
|
29
28
|
maps.each do |mod, methods|
|
30
|
-
name = mod ==
|
29
|
+
name = mod == singleton_class ? "#{klass}.methods" : "#{mod}#methods"
|
31
30
|
o.dump(name, methods)
|
32
31
|
end
|
33
32
|
end
|
34
33
|
|
35
|
-
def dump_instance_methods(o, klass)
|
36
|
-
maps = class_method_map(klass.ancestors)
|
37
|
-
maps.each do |mod, methods|
|
38
|
-
o.dump("#{mod}#methods", methods)
|
39
|
-
end
|
40
|
-
end
|
41
|
-
|
42
34
|
def class_method_map(classes)
|
43
|
-
dumped =
|
35
|
+
dumped = Array.new
|
44
36
|
classes.reject { |mod| mod >= Object }.map do |mod|
|
45
|
-
methods = mod.public_instance_methods(false).select
|
37
|
+
methods = mod.public_instance_methods(false).select do |m|
|
38
|
+
dumped.push(m) unless dumped.include?(m)
|
39
|
+
end
|
46
40
|
[mod, methods]
|
47
41
|
end.reverse
|
48
42
|
end
|
data/lib/irb/cmd/measure.rb
CHANGED
@@ -9,6 +9,9 @@ module IRB
|
|
9
9
|
end
|
10
10
|
|
11
11
|
def execute(type = nil, arg = nil, &block)
|
12
|
+
# Please check IRB.init_config in lib/irb/init.rb that sets
|
13
|
+
# IRB.conf[:MEASURE_PROC] to register default "measure" methods,
|
14
|
+
# "measure :time" (abbreviated as "measure") and "measure :stackprof".
|
12
15
|
case type
|
13
16
|
when :off
|
14
17
|
IRB.conf[:MEASURE] = nil
|
data/lib/irb/cmd/show_source.rb
CHANGED
@@ -59,11 +59,21 @@ module IRB
|
|
59
59
|
def find_end(file, first_line)
|
60
60
|
return first_line unless File.exist?(file)
|
61
61
|
lex = RubyLex.new
|
62
|
+
lines = File.read(file).lines[(first_line - 1)..-1]
|
63
|
+
tokens = RubyLex.ripper_lex_without_warning(lines.join)
|
64
|
+
|
62
65
|
code = +""
|
63
|
-
|
64
|
-
|
66
|
+
prev_tokens = []
|
67
|
+
|
68
|
+
# chunk with line number
|
69
|
+
tokens.chunk { |tok| tok[0][0] }.each do |lnum, chunk|
|
70
|
+
code << lines[lnum]
|
71
|
+
prev_tokens.concat chunk
|
72
|
+
|
73
|
+
continue = lex.process_continue(prev_tokens)
|
74
|
+
code_block_open = lex.check_code_block(code, prev_tokens)
|
65
75
|
if !continue && !code_block_open
|
66
|
-
return first_line +
|
76
|
+
return first_line + lnum
|
67
77
|
end
|
68
78
|
end
|
69
79
|
first_line
|
data/lib/irb/ruby-lex.rb
CHANGED
@@ -30,26 +30,31 @@ class RubyLex
|
|
30
30
|
@prompt = nil
|
31
31
|
end
|
32
32
|
|
33
|
-
def self.compile_with_errors_suppressed(code)
|
34
|
-
line_no = 1
|
33
|
+
def self.compile_with_errors_suppressed(code, line_no: 1)
|
35
34
|
begin
|
36
35
|
result = yield code, line_no
|
37
36
|
rescue ArgumentError
|
37
|
+
# Ruby can issue an error for the code if there is an
|
38
|
+
# incomplete magic comment for encoding in it. Force an
|
39
|
+
# expression with a new line before the code in this
|
40
|
+
# case to prevent magic comment handling. To make sure
|
41
|
+
# line numbers in the lexed code remain the same,
|
42
|
+
# decrease the line number by one.
|
38
43
|
code = ";\n#{code}"
|
39
|
-
line_no
|
44
|
+
line_no -= 1
|
40
45
|
result = yield code, line_no
|
41
46
|
end
|
42
47
|
result
|
43
48
|
end
|
44
49
|
|
45
50
|
# io functions
|
46
|
-
def set_input(io, p = nil, &block)
|
51
|
+
def set_input(io, p = nil, context: nil, &block)
|
47
52
|
@io = io
|
48
53
|
if @io.respond_to?(:check_termination)
|
49
54
|
@io.check_termination do |code|
|
50
55
|
if Reline::IOGate.in_pasting?
|
51
56
|
lex = RubyLex.new
|
52
|
-
rest = lex.check_termination_in_prev_line(code)
|
57
|
+
rest = lex.check_termination_in_prev_line(code, context: context)
|
53
58
|
if rest
|
54
59
|
Reline.delete_text
|
55
60
|
rest.bytes.reverse_each do |c|
|
@@ -61,7 +66,7 @@ class RubyLex
|
|
61
66
|
end
|
62
67
|
else
|
63
68
|
code.gsub!(/\s*\z/, '').concat("\n")
|
64
|
-
ltype, indent, continue, code_block_open = check_state(code)
|
69
|
+
ltype, indent, continue, code_block_open = check_state(code, context: context)
|
65
70
|
if ltype or indent > 0 or continue or code_block_open
|
66
71
|
false
|
67
72
|
else
|
@@ -74,7 +79,7 @@ class RubyLex
|
|
74
79
|
@io.dynamic_prompt do |lines|
|
75
80
|
lines << '' if lines.empty?
|
76
81
|
result = []
|
77
|
-
tokens = self.class.ripper_lex_without_warning(lines.map{ |l| l + "\n" }.join)
|
82
|
+
tokens = self.class.ripper_lex_without_warning(lines.map{ |l| l + "\n" }.join, context: context)
|
78
83
|
code = String.new
|
79
84
|
partial_tokens = []
|
80
85
|
unprocessed_tokens = []
|
@@ -86,7 +91,7 @@ class RubyLex
|
|
86
91
|
t_str = t[2]
|
87
92
|
t_str.each_line("\n") do |s|
|
88
93
|
code << s << "\n"
|
89
|
-
ltype, indent, continue, code_block_open = check_state(code, partial_tokens)
|
94
|
+
ltype, indent, continue, code_block_open = check_state(code, partial_tokens, context: context)
|
90
95
|
result << @prompt.call(ltype, indent, continue || code_block_open, @line_no + line_num_offset)
|
91
96
|
line_num_offset += 1
|
92
97
|
end
|
@@ -96,7 +101,7 @@ class RubyLex
|
|
96
101
|
end
|
97
102
|
end
|
98
103
|
unless unprocessed_tokens.empty?
|
99
|
-
ltype, indent, continue, code_block_open = check_state(code, unprocessed_tokens)
|
104
|
+
ltype, indent, continue, code_block_open = check_state(code, unprocessed_tokens, context: context)
|
100
105
|
result << @prompt.call(ltype, indent, continue || code_block_open, @line_no + line_num_offset)
|
101
106
|
end
|
102
107
|
result
|
@@ -129,15 +134,25 @@ class RubyLex
|
|
129
134
|
:on_param_error
|
130
135
|
]
|
131
136
|
|
132
|
-
def self.ripper_lex_without_warning(code)
|
137
|
+
def self.ripper_lex_without_warning(code, context: nil)
|
133
138
|
verbose, $VERBOSE = $VERBOSE, nil
|
139
|
+
if context
|
140
|
+
lvars = context&.workspace&.binding&.local_variables
|
141
|
+
if lvars && !lvars.empty?
|
142
|
+
code = "#{lvars.join('=')}=nil\n#{code}"
|
143
|
+
line_no = 0
|
144
|
+
else
|
145
|
+
line_no = 1
|
146
|
+
end
|
147
|
+
end
|
134
148
|
tokens = nil
|
135
|
-
compile_with_errors_suppressed(code) do |inner_code, line_no|
|
149
|
+
compile_with_errors_suppressed(code, line_no: line_no) do |inner_code, line_no|
|
136
150
|
lexer = Ripper::Lexer.new(inner_code, '-', line_no)
|
137
151
|
if lexer.respond_to?(:scan) # Ruby 2.7+
|
138
152
|
tokens = []
|
139
153
|
pos_to_index = {}
|
140
154
|
lexer.scan.each do |t|
|
155
|
+
next if t.pos.first == 0
|
141
156
|
if pos_to_index.has_key?(t[0])
|
142
157
|
index = pos_to_index[t[0]]
|
143
158
|
found_tk = tokens[index]
|
@@ -182,7 +197,7 @@ class RubyLex
|
|
182
197
|
if @io.respond_to?(:auto_indent) and context.auto_indent_mode
|
183
198
|
@io.auto_indent do |lines, line_index, byte_pointer, is_newline|
|
184
199
|
if is_newline
|
185
|
-
@tokens = self.class.ripper_lex_without_warning(lines[0..line_index].join("\n"))
|
200
|
+
@tokens = self.class.ripper_lex_without_warning(lines[0..line_index].join("\n"), context: context)
|
186
201
|
prev_spaces = find_prev_spaces(line_index)
|
187
202
|
depth_difference = check_newline_depth_difference
|
188
203
|
depth_difference = 0 if depth_difference < 0
|
@@ -191,7 +206,7 @@ class RubyLex
|
|
191
206
|
code = line_index.zero? ? '' : lines[0..(line_index - 1)].map{ |l| l + "\n" }.join
|
192
207
|
last_line = lines[line_index]&.byteslice(0, byte_pointer)
|
193
208
|
code += last_line if last_line
|
194
|
-
@tokens = self.class.ripper_lex_without_warning(code)
|
209
|
+
@tokens = self.class.ripper_lex_without_warning(code, context: context)
|
195
210
|
corresponding_token_depth = check_corresponding_token_depth
|
196
211
|
if corresponding_token_depth
|
197
212
|
corresponding_token_depth
|
@@ -203,8 +218,8 @@ class RubyLex
|
|
203
218
|
end
|
204
219
|
end
|
205
220
|
|
206
|
-
def check_state(code, tokens = nil)
|
207
|
-
tokens = self.class.ripper_lex_without_warning(code) unless tokens
|
221
|
+
def check_state(code, tokens = nil, context: nil)
|
222
|
+
tokens = self.class.ripper_lex_without_warning(code, context: context) unless tokens
|
208
223
|
ltype = process_literal_type(tokens)
|
209
224
|
indent = process_nesting_level(tokens)
|
210
225
|
continue = process_continue(tokens)
|
@@ -700,7 +715,7 @@ class RubyLex
|
|
700
715
|
start_token << t
|
701
716
|
end_type << :on_regexp_end
|
702
717
|
when :on_symbeg
|
703
|
-
acceptable_single_tokens = %i{on_ident on_const on_op on_cvar on_ivar on_gvar on_kw}
|
718
|
+
acceptable_single_tokens = %i{on_ident on_const on_op on_cvar on_ivar on_gvar on_kw on_int}
|
704
719
|
if (i + 1) < tokens.size and acceptable_single_tokens.all?{ |st| tokens[i + 1][1] != st }
|
705
720
|
start_token << t
|
706
721
|
end_type << :on_tstring_end
|
@@ -754,8 +769,8 @@ class RubyLex
|
|
754
769
|
end
|
755
770
|
end
|
756
771
|
|
757
|
-
def check_termination_in_prev_line(code)
|
758
|
-
tokens = self.class.ripper_lex_without_warning(code)
|
772
|
+
def check_termination_in_prev_line(code, context: nil)
|
773
|
+
tokens = self.class.ripper_lex_without_warning(code, context: context)
|
759
774
|
past_first_newline = false
|
760
775
|
index = tokens.rindex do |t|
|
761
776
|
# traverse first token before last line
|
data/lib/irb/version.rb
CHANGED
metadata
CHANGED
@@ -1,29 +1,29 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: irb
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.3.
|
4
|
+
version: 1.3.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: 2021-
|
11
|
+
date: 2021-08-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: reline
|
15
|
-
prerelease: false
|
16
15
|
requirement: !ruby/object:Gem::Requirement
|
17
16
|
requirements:
|
18
17
|
- - ">="
|
19
18
|
- !ruby/object:Gem::Version
|
20
|
-
version: 0.2.
|
19
|
+
version: 0.2.7
|
21
20
|
type: :runtime
|
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.2.
|
26
|
+
version: 0.2.7
|
27
27
|
description: Interactive Ruby command-line tool for REPL (Read Eval Print Loop).
|
28
28
|
email:
|
29
29
|
- keiju@ruby-lang.org
|
@@ -97,7 +97,7 @@ licenses:
|
|
97
97
|
- Ruby
|
98
98
|
- BSD-2-Clause
|
99
99
|
metadata: {}
|
100
|
-
post_install_message:
|
100
|
+
post_install_message:
|
101
101
|
rdoc_options: []
|
102
102
|
require_paths:
|
103
103
|
- lib
|
@@ -112,8 +112,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
112
112
|
- !ruby/object:Gem::Version
|
113
113
|
version: '0'
|
114
114
|
requirements: []
|
115
|
-
rubygems_version: 3.
|
116
|
-
signing_key:
|
115
|
+
rubygems_version: 3.2.22
|
116
|
+
signing_key:
|
117
117
|
specification_version: 4
|
118
118
|
summary: Interactive Ruby command-line tool for REPL (Read Eval Print Loop).
|
119
119
|
test_files: []
|