irb 1.2.4 → 1.2.7
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile +0 -5
- data/irb.gemspec +2 -2
- data/lib/irb.rb +43 -11
- data/lib/irb/cmd/fork.rb +0 -2
- data/lib/irb/cmd/pushws.rb +0 -1
- data/lib/irb/color.rb +23 -21
- data/lib/irb/completion.rb +6 -11
- data/lib/irb/context.rb +14 -3
- data/lib/irb/ext/change-ws.rb +0 -1
- data/lib/irb/ext/history.rb +0 -2
- data/lib/irb/ext/loader.rb +0 -1
- data/lib/irb/ext/save-history.rb +8 -5
- data/lib/irb/ext/tracer.rb +0 -1
- data/lib/irb/ext/use-loader.rb +0 -2
- data/lib/irb/ext/workspaces.rb +0 -1
- data/lib/irb/help.rb +0 -1
- data/lib/irb/init.rb +2 -0
- data/lib/irb/input-method.rb +19 -11
- data/lib/irb/inspector.rb +1 -5
- data/lib/irb/ruby-lex.rb +108 -10
- data/lib/irb/ruby_logo.aa +0 -1
- data/lib/irb/version.rb +2 -2
- data/lib/irb/xmp.rb +1 -1
- metadata +8 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 06c24147c0b5bb8af2c024688cee07a8c03ebfa3d804139ea3dc767dbb7a6b72
|
4
|
+
data.tar.gz: f963948ad72203fec9e8c5cd9d408451718675048c5ca8104fedbdcc34b07483
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: eefceccb8108975077b8158a8a8a7e03600e3180b039970e729bc3919b414de18505ac817be670a8c8dd108099ce232d8db06f6dc04a74e1c963e369962df158
|
7
|
+
data.tar.gz: e5ad1fcece6c08e3d807bead5e63950b1e34f6021ae75c40e647ae94bb075ec9e9b07b92e1665eb873e4397c69ab30d15794520e5ae8b765bb97127cddbaf8db
|
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
|
data/irb.gemspec
CHANGED
@@ -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.
|
17
|
+
spec.licenses = ["Ruby", "BSD-2-Clause"]
|
18
18
|
|
19
19
|
spec.files = [
|
20
20
|
".document",
|
@@ -78,7 +78,7 @@ Gem::Specification.new do |spec|
|
|
78
78
|
|
79
79
|
spec.required_ruby_version = Gem::Requirement.new(">= 2.5")
|
80
80
|
|
81
|
-
spec.add_dependency "reline", ">= 0.
|
81
|
+
spec.add_dependency "reline", ">= 0.1.5"
|
82
82
|
spec.add_development_dependency "bundler"
|
83
83
|
spec.add_development_dependency "rake"
|
84
84
|
end
|
data/lib/irb.rb
CHANGED
@@ -10,18 +10,19 @@
|
|
10
10
|
#
|
11
11
|
#
|
12
12
|
require "ripper"
|
13
|
+
require "reline"
|
13
14
|
|
14
|
-
|
15
|
-
|
16
|
-
|
15
|
+
require_relative "irb/init"
|
16
|
+
require_relative "irb/context"
|
17
|
+
require_relative "irb/extend-command"
|
17
18
|
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
19
|
+
require_relative "irb/ruby-lex"
|
20
|
+
require_relative "irb/input-method"
|
21
|
+
require_relative "irb/locale"
|
22
|
+
require_relative "irb/color"
|
22
23
|
|
23
|
-
|
24
|
-
|
24
|
+
require_relative "irb/version"
|
25
|
+
require_relative "irb/easter-egg"
|
25
26
|
|
26
27
|
# IRB stands for "interactive Ruby" and is a tool to interactively execute Ruby
|
27
28
|
# expressions read from the standard input.
|
@@ -538,7 +539,15 @@ module IRB
|
|
538
539
|
begin
|
539
540
|
line.untaint if RUBY_VERSION < '2.7'
|
540
541
|
@context.evaluate(line, line_no, exception: exc)
|
541
|
-
|
542
|
+
if @context.echo?
|
543
|
+
if assignment_expression?(line)
|
544
|
+
if @context.echo_on_assignment?
|
545
|
+
output_value(@context.echo_on_assignment? == :truncate)
|
546
|
+
end
|
547
|
+
else
|
548
|
+
output_value
|
549
|
+
end
|
550
|
+
end
|
542
551
|
rescue Interrupt => exc
|
543
552
|
rescue SystemExit, SignalException
|
544
553
|
raise
|
@@ -737,9 +746,32 @@ module IRB
|
|
737
746
|
p
|
738
747
|
end
|
739
748
|
|
740
|
-
def output_value # :nodoc:
|
749
|
+
def output_value(omit = false) # :nodoc:
|
741
750
|
str = @context.inspect_last_value
|
742
751
|
multiline_p = str.include?("\n")
|
752
|
+
if omit
|
753
|
+
winwidth = @context.io.winsize.last
|
754
|
+
if multiline_p
|
755
|
+
first_line = str.split("\n").first
|
756
|
+
result = @context.newline_before_multiline_output? ? (@context.return_format % first_line) : first_line
|
757
|
+
output_width = Reline::Unicode.calculate_width(result, true)
|
758
|
+
diff_size = output_width - Reline::Unicode.calculate_width(first_line, true)
|
759
|
+
if diff_size.positive? and output_width > winwidth
|
760
|
+
lines, _ = Reline::Unicode.split_by_width(first_line, winwidth - diff_size - 3)
|
761
|
+
str = "%s...\e[0m" % lines.first
|
762
|
+
multiline_p = false
|
763
|
+
else
|
764
|
+
str.gsub!(/(\A.*?\n).*/m, "\\1...")
|
765
|
+
end
|
766
|
+
else
|
767
|
+
output_width = Reline::Unicode.calculate_width(@context.return_format % str, true)
|
768
|
+
diff_size = output_width - Reline::Unicode.calculate_width(str, true)
|
769
|
+
if diff_size.positive? and output_width > winwidth
|
770
|
+
lines, _ = Reline::Unicode.split_by_width(str, winwidth - diff_size - 3)
|
771
|
+
str = "%s...\e[0m" % lines.first
|
772
|
+
end
|
773
|
+
end
|
774
|
+
end
|
743
775
|
if multiline_p && @context.newline_before_multiline_output?
|
744
776
|
printf @context.return_format, "\n#{str}"
|
745
777
|
else
|
data/lib/irb/cmd/fork.rb
CHANGED
data/lib/irb/cmd/pushws.rb
CHANGED
data/lib/irb/color.rb
CHANGED
@@ -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 =
|
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
|
-
|
159
|
-
|
160
|
-
lexer.scan
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
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
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
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
|
data/lib/irb/completion.rb
CHANGED
@@ -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
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
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
|
data/lib/irb/context.rb
CHANGED
@@ -131,7 +131,7 @@ module IRB
|
|
131
131
|
|
132
132
|
@echo_on_assignment = IRB.conf[:ECHO_ON_ASSIGNMENT]
|
133
133
|
if @echo_on_assignment.nil?
|
134
|
-
@echo_on_assignment =
|
134
|
+
@echo_on_assignment = :truncate
|
135
135
|
end
|
136
136
|
|
137
137
|
@newline_before_multiline_output = IRB.conf[:NEWLINE_BEFORE_MULTILINE_OUTPUT]
|
@@ -251,12 +251,23 @@ module IRB
|
|
251
251
|
attr_accessor :echo
|
252
252
|
# Whether to echo for assignment expressions
|
253
253
|
#
|
254
|
-
#
|
254
|
+
# If set to +false+, the value of assignment will not be shown.
|
255
|
+
#
|
256
|
+
# If set to +true+, the value of assignment will be shown.
|
257
|
+
#
|
258
|
+
# If set to +:truncate+, the value of assignment will be shown and truncated.
|
259
|
+
#
|
260
|
+
# It defaults to +:truncate+.
|
255
261
|
#
|
256
262
|
# a = "omg"
|
263
|
+
# #=> omg
|
264
|
+
# a = "omg" * 10
|
265
|
+
# #=> omgomgomgomgomgomgomg...
|
266
|
+
# IRB.CurrentContext.echo_on_assignment = false
|
267
|
+
# a = "omg"
|
257
268
|
# IRB.CurrentContext.echo_on_assignment = true
|
258
269
|
# a = "omg"
|
259
|
-
# #=>
|
270
|
+
# #=> omgomgomgomgomgomgomgomgomgomg
|
260
271
|
attr_accessor :echo_on_assignment
|
261
272
|
# Whether a newline is put before multiline output.
|
262
273
|
#
|
data/lib/irb/ext/change-ws.rb
CHANGED
data/lib/irb/ext/history.rb
CHANGED
data/lib/irb/ext/loader.rb
CHANGED
data/lib/irb/ext/save-history.rb
CHANGED
@@ -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
|
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)
|
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
|
-
|
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
|
data/lib/irb/ext/tracer.rb
CHANGED
data/lib/irb/ext/use-loader.rb
CHANGED
data/lib/irb/ext/workspaces.rb
CHANGED
data/lib/irb/help.rb
CHANGED
data/lib/irb/init.rb
CHANGED
@@ -177,6 +177,8 @@ module IRB # :nodoc:
|
|
177
177
|
@CONF[:ECHO_ON_ASSIGNMENT] = true
|
178
178
|
when "--noecho-on-assignment"
|
179
179
|
@CONF[:ECHO_ON_ASSIGNMENT] = false
|
180
|
+
when "--truncate-echo-on-assignment"
|
181
|
+
@CONF[:ECHO_ON_ASSIGNMENT] = :truncate
|
180
182
|
when "--verbose"
|
181
183
|
@CONF[:VERBOSE] = true
|
182
184
|
when "--noverbose"
|
data/lib/irb/input-method.rb
CHANGED
@@ -12,6 +12,7 @@
|
|
12
12
|
require_relative 'src_encoding'
|
13
13
|
require_relative 'magic-file'
|
14
14
|
require_relative 'completion'
|
15
|
+
require 'io/console'
|
15
16
|
require 'reline'
|
16
17
|
|
17
18
|
module IRB
|
@@ -36,6 +37,14 @@ module IRB
|
|
36
37
|
end
|
37
38
|
public :gets
|
38
39
|
|
40
|
+
def winsize
|
41
|
+
if instance_variable_defined?(:@stdout)
|
42
|
+
@stdout.winsize
|
43
|
+
else
|
44
|
+
[24, 80]
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
39
48
|
# Whether this input method is still readable when there is no more data to
|
40
49
|
# read.
|
41
50
|
#
|
@@ -143,11 +152,17 @@ module IRB
|
|
143
152
|
end
|
144
153
|
|
145
154
|
begin
|
146
|
-
require "readline"
|
147
155
|
class ReadlineInputMethod < InputMethod
|
148
|
-
|
156
|
+
def self.initialize_readline
|
157
|
+
require "readline"
|
158
|
+
rescue LoadError
|
159
|
+
else
|
160
|
+
include ::Readline
|
161
|
+
end
|
162
|
+
|
149
163
|
# Creates a new input method object using Readline
|
150
164
|
def initialize
|
165
|
+
self.class.initialize_readline
|
151
166
|
if Readline.respond_to?(:encoding_system_needs)
|
152
167
|
IRB.__send__(:set_encoding, Readline.encoding_system_needs.name, override: false)
|
153
168
|
end
|
@@ -212,12 +227,6 @@ module IRB
|
|
212
227
|
@stdin.external_encoding
|
213
228
|
end
|
214
229
|
|
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
230
|
# For debug message
|
222
231
|
def inspect
|
223
232
|
readline_impl = (defined?(Reline) && Readline == Reline) ? 'Reline' : 'ext/readline'
|
@@ -227,7 +236,6 @@ module IRB
|
|
227
236
|
str
|
228
237
|
end
|
229
238
|
end
|
230
|
-
rescue LoadError
|
231
239
|
end
|
232
240
|
|
233
241
|
class ReidlineInputMethod < InputMethod
|
@@ -251,7 +259,7 @@ module IRB
|
|
251
259
|
Reline.completion_proc = IRB::InputCompletor::CompletionProc
|
252
260
|
Reline.output_modifier_proc =
|
253
261
|
if IRB.conf[:USE_COLORIZE]
|
254
|
-
proc do |output, complete
|
262
|
+
proc do |output, complete: |
|
255
263
|
next unless IRB::Color.colorable?
|
256
264
|
IRB::Color.colorize_code(output, complete: complete)
|
257
265
|
end
|
@@ -327,7 +335,7 @@ module IRB
|
|
327
335
|
config = Reline::Config.new
|
328
336
|
str = "ReidlineInputMethod with Reline #{Reline::VERSION}"
|
329
337
|
if config.respond_to?(:inputrc_path)
|
330
|
-
inputrc_path = config.inputrc_path
|
338
|
+
inputrc_path = File.expand_path(config.inputrc_path)
|
331
339
|
else
|
332
340
|
inputrc_path = File.expand_path(ENV['INPUTRC'] || '~/.inputrc')
|
333
341
|
end
|
data/lib/irb/inspector.rb
CHANGED
@@ -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
|
-
|
data/lib/irb/ruby-lex.rb
CHANGED
@@ -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 =
|
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
|
-
|
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
|
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', '
|
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
|
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', '
|
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
|
data/lib/irb/ruby_logo.aa
CHANGED
data/lib/irb/version.rb
CHANGED
data/lib/irb/xmp.rb
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.2.
|
4
|
+
version: 1.2.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: 2020-
|
11
|
+
date: 2020-09-18 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.1.5
|
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.1.5
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: bundler
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -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: []
|