irb 1.6.4 → 1.7.1
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/irb_info.rb +14 -18
- data/lib/irb/cmd/ls.rb +5 -2
- data/lib/irb/cmd/nop.rb +4 -8
- data/lib/irb/cmd/show_doc.rb +48 -0
- data/lib/irb/cmd/show_source.rb +7 -6
- data/lib/irb/completion.rb +2 -2
- data/lib/irb/context.rb +19 -16
- data/lib/irb/ext/loader.rb +2 -0
- data/lib/irb/ext/tracer.rb +1 -1
- data/lib/irb/extend-command.rb +6 -2
- 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/nesting_parser.rb +227 -0
- data/lib/irb/ruby-lex.rb +266 -559
- data/lib/irb/version.rb +2 -2
- data/lib/irb.rb +25 -31
- metadata +5 -6
- data/lib/irb/cmd/fork.rb +0 -34
- data/lib/irb/lc/ja/encoding_aliases.rb +0 -13
- data/lib/irb/magic-file.rb +0 -38
data/lib/irb/version.rb
CHANGED
data/lib/irb.rb
CHANGED
@@ -506,8 +506,6 @@ module IRB
|
|
506
506
|
|
507
507
|
# Evaluates input for this session.
|
508
508
|
def eval_input
|
509
|
-
exc = nil
|
510
|
-
|
511
509
|
@scanner.set_prompt do
|
512
510
|
|ltype, indent, continue, line_no|
|
513
511
|
if ltype
|
@@ -537,7 +535,7 @@ module IRB
|
|
537
535
|
@context.io.prompt
|
538
536
|
end
|
539
537
|
|
540
|
-
@scanner.set_input
|
538
|
+
@scanner.set_input do
|
541
539
|
signal_status(:IN_INPUT) do
|
542
540
|
if l = @context.io.gets
|
543
541
|
print l if @context.verbose?
|
@@ -555,31 +553,15 @@ module IRB
|
|
555
553
|
end
|
556
554
|
end
|
557
555
|
|
558
|
-
@scanner.
|
556
|
+
@scanner.configure_io(@context.io)
|
559
557
|
|
560
558
|
@scanner.each_top_level_statement do |line, line_no|
|
561
559
|
signal_status(:IN_EVAL) do
|
562
560
|
begin
|
563
|
-
if
|
564
|
-
IRB.set_measure_callback
|
565
|
-
end
|
566
|
-
# Assignment expression check should be done before @context.evaluate to handle code like `a /2#/ if false; a = 1`
|
561
|
+
# Assignment expression check should be done before evaluate_line to handle code like `a /2#/ if false; a = 1`
|
567
562
|
is_assignment = assignment_expression?(line)
|
568
|
-
|
569
|
-
|
570
|
-
last_proc = proc{ result = @context.evaluate(line, line_no, exception: exc) }
|
571
|
-
IRB.conf[:MEASURE_CALLBACKS].inject(last_proc) { |chain, item|
|
572
|
-
_name, callback, arg = item
|
573
|
-
proc {
|
574
|
-
callback.(@context, line, line_no, arg, exception: exc) do
|
575
|
-
chain.call
|
576
|
-
end
|
577
|
-
}
|
578
|
-
}.call
|
579
|
-
@context.set_last_value(result)
|
580
|
-
else
|
581
|
-
@context.evaluate(line, line_no, exception: exc)
|
582
|
-
end
|
563
|
+
evaluate_line(line, line_no)
|
564
|
+
|
583
565
|
if @context.echo?
|
584
566
|
if is_assignment
|
585
567
|
if @context.echo_on_assignment?
|
@@ -589,21 +571,33 @@ module IRB
|
|
589
571
|
output_value
|
590
572
|
end
|
591
573
|
end
|
592
|
-
rescue Interrupt => exc
|
593
574
|
rescue SystemExit, SignalException
|
594
575
|
raise
|
595
|
-
rescue Exception => exc
|
596
|
-
|
597
|
-
exc
|
598
|
-
next
|
576
|
+
rescue Interrupt, Exception => exc
|
577
|
+
handle_exception(exc)
|
578
|
+
@context.workspace.local_variable_set(:_, exc)
|
599
579
|
end
|
600
|
-
handle_exception(exc)
|
601
|
-
@context.workspace.local_variable_set(:_, exc)
|
602
|
-
exc = nil
|
603
580
|
end
|
604
581
|
end
|
605
582
|
end
|
606
583
|
|
584
|
+
def evaluate_line(line, line_no)
|
585
|
+
# Transform a non-identifier alias (@, $) or keywords (next, break)
|
586
|
+
command, args = line.split(/\s/, 2)
|
587
|
+
if original = @context.command_aliases[command.to_sym]
|
588
|
+
line = line.gsub(/\A#{Regexp.escape(command)}/, original.to_s)
|
589
|
+
command = original
|
590
|
+
end
|
591
|
+
|
592
|
+
# Hook command-specific transformation
|
593
|
+
command_class = ExtendCommandBundle.load_command(command)
|
594
|
+
if command_class&.respond_to?(:transform_args)
|
595
|
+
line = "#{command} #{command_class.transform_args(args)}"
|
596
|
+
end
|
597
|
+
|
598
|
+
@context.evaluate(line, line_no)
|
599
|
+
end
|
600
|
+
|
607
601
|
def convert_invalid_byte_sequence(str, enc)
|
608
602
|
str.force_encoding(enc)
|
609
603
|
str.scrub { |c|
|
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.1
|
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-
|
12
|
+
date: 2023-07-02 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: reline
|
@@ -55,7 +55,6 @@ files:
|
|
55
55
|
- lib/irb/cmd/delete.rb
|
56
56
|
- lib/irb/cmd/edit.rb
|
57
57
|
- lib/irb/cmd/finish.rb
|
58
|
-
- lib/irb/cmd/fork.rb
|
59
58
|
- lib/irb/cmd/help.rb
|
60
59
|
- lib/irb/cmd/info.rb
|
61
60
|
- lib/irb/cmd/irb_info.rb
|
@@ -66,6 +65,7 @@ files:
|
|
66
65
|
- lib/irb/cmd/nop.rb
|
67
66
|
- lib/irb/cmd/pushws.rb
|
68
67
|
- lib/irb/cmd/show_cmds.rb
|
68
|
+
- lib/irb/cmd/show_doc.rb
|
69
69
|
- lib/irb/cmd/show_source.rb
|
70
70
|
- lib/irb/cmd/step.rb
|
71
71
|
- lib/irb/cmd/subirb.rb
|
@@ -91,11 +91,10 @@ files:
|
|
91
91
|
- lib/irb/inspector.rb
|
92
92
|
- lib/irb/lc/error.rb
|
93
93
|
- lib/irb/lc/help-message
|
94
|
-
- lib/irb/lc/ja/encoding_aliases.rb
|
95
94
|
- lib/irb/lc/ja/error.rb
|
96
95
|
- lib/irb/lc/ja/help-message
|
97
96
|
- lib/irb/locale.rb
|
98
|
-
- lib/irb/
|
97
|
+
- lib/irb/nesting_parser.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/cmd/fork.rb
DELETED
@@ -1,34 +0,0 @@
|
|
1
|
-
# frozen_string_literal: false
|
2
|
-
#
|
3
|
-
# fork.rb -
|
4
|
-
# by Keiju ISHITSUKA(keiju@ruby-lang.org)
|
5
|
-
#
|
6
|
-
|
7
|
-
require_relative "nop"
|
8
|
-
|
9
|
-
module IRB
|
10
|
-
# :stopdoc:
|
11
|
-
|
12
|
-
module ExtendCommand
|
13
|
-
class Fork < Nop
|
14
|
-
def execute
|
15
|
-
pid = __send__ ExtendCommand.irb_original_method_name("fork")
|
16
|
-
unless pid
|
17
|
-
class << self
|
18
|
-
alias_method :exit, ExtendCommand.irb_original_method_name('exit')
|
19
|
-
end
|
20
|
-
if block_given?
|
21
|
-
begin
|
22
|
-
yield
|
23
|
-
ensure
|
24
|
-
exit
|
25
|
-
end
|
26
|
-
end
|
27
|
-
end
|
28
|
-
pid
|
29
|
-
end
|
30
|
-
end
|
31
|
-
end
|
32
|
-
|
33
|
-
# :startdoc:
|
34
|
-
end
|
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
|