irb 1.1.0 → 1.1.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 2ea14a93083cae06cb1b6acb7df716a4b674fe0179df78133a5e9d515f814de5
4
- data.tar.gz: e5c48bf9b0407c3bf8c278a999a333bcf6cc514d467292eb578f0a434992d06c
3
+ metadata.gz: fc28457f7b997cac6ec910290d58677ee4d21b71bb769c421840b77242dddc04
4
+ data.tar.gz: af7a068e8bbef2cc1aec4be90b907b959da162bc0442183cee45d4ef0e39bea5
5
5
  SHA512:
6
- metadata.gz: 57da5191caf04ded2eebea073a511f721bb66c511c0821fe4055aa582333209e9293380af20680fcebee290d109e30df73d1752cc32893729e8df0a7712c1192
7
- data.tar.gz: eab5b941d5db5d0582e32d7dc3fb77955024c3ca852e83816fc4bf8c4c3442910dff2a3cba7c41a9e0e357943371e371646e8c1b23721fd2e1d8e2c3cfa2fa84
6
+ metadata.gz: 0770a8ef428fd8f604509b67ee2e796672f243b3736e385b128e0dc9354cb6283531612ff60d46fffcb06d89b6de65d1eaf7fb0f6e8e032a9058f349285c6b3d
7
+ data.tar.gz: 48d11c9ddabe1639331330cc8aa5f30a5f5306b5852c404377dda2527ed86e8767d783811f20e8b02783447df9adb5315d4fa1bce4422aab7774ab8140075e44
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+ Gemfile.lock
@@ -0,0 +1,6 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.5.1
5
+ - ruby-head
6
+ before_install: gem install bundler -v 1.16.2
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/README.md CHANGED
@@ -31,9 +31,9 @@ $ irb
31
31
  irb(main):001:0> 1+2
32
32
  #=> 3
33
33
  irb(main):002:0> class Foo
34
- irb(main):003:1> def foo
35
- irb(main):004:2> print 1
36
- irb(main):005:2> end
34
+ irb(main):003:1> def foo
35
+ irb(main):004:2> print 1
36
+ irb(main):005:2> end
37
37
  irb(main):006:1> end
38
38
  #=> nil
39
39
  ```
@@ -16,69 +16,11 @@ Gem::Specification.new do |spec|
16
16
  spec.homepage = "https://github.com/ruby/irb"
17
17
  spec.license = "BSD-2-Clause"
18
18
 
19
- spec.files = [
20
- "Gemfile",
21
- "LICENSE.txt",
22
- "README.md",
23
- "Rakefile",
24
- "bin/console",
25
- "bin/setup",
26
- "doc/irb/irb-tools.rd.ja",
27
- "doc/irb/irb.rd.ja",
28
- "exe/irb",
29
- "irb.gemspec",
30
- "lib/irb.rb",
31
- "lib/irb/cmd/chws.rb",
32
- "lib/irb/cmd/fork.rb",
33
- "lib/irb/cmd/help.rb",
34
- "lib/irb/cmd/load.rb",
35
- "lib/irb/cmd/nop.rb",
36
- "lib/irb/cmd/pushws.rb",
37
- "lib/irb/cmd/subirb.rb",
38
- "lib/irb/color.rb",
39
- "lib/irb/completion.rb",
40
- "lib/irb/context.rb",
41
- "lib/irb/ext/change-ws.rb",
42
- "lib/irb/ext/history.rb",
43
- "lib/irb/ext/loader.rb",
44
- "lib/irb/ext/multi-irb.rb",
45
- "lib/irb/ext/save-history.rb",
46
- "lib/irb/ext/tracer.rb",
47
- "lib/irb/ext/use-loader.rb",
48
- "lib/irb/ext/workspaces.rb",
49
- "lib/irb/extend-command.rb",
50
- "lib/irb/frame.rb",
51
- "lib/irb/help.rb",
52
- "lib/irb/init.rb",
53
- "lib/irb/input-method.rb",
54
- "lib/irb/inspector.rb",
55
- "lib/irb/lc/.document",
56
- "lib/irb/lc/error.rb",
57
- "lib/irb/lc/help-message",
58
- "lib/irb/lc/ja/encoding_aliases.rb",
59
- "lib/irb/lc/ja/error.rb",
60
- "lib/irb/lc/ja/help-message",
61
- "lib/irb/locale.rb",
62
- "lib/irb/magic-file.rb",
63
- "lib/irb/notifier.rb",
64
- "lib/irb/output-method.rb",
65
- "lib/irb/ruby-lex.rb",
66
- "lib/irb/ruby_logo.aa",
67
- "lib/irb/slex.rb",
68
- "lib/irb/src_encoding.rb",
69
- "lib/irb/version.rb",
70
- "lib/irb/workspace.rb",
71
- "lib/irb/ws-for-case-2.rb",
72
- "lib/irb/xmp.rb",
73
- "man/irb.1",
74
- ]
19
+ spec.files = [".gitignore", ".travis.yml", "Gemfile", "LICENSE.txt", "README.md", "Rakefile", "bin/console", "bin/setup", "exe/irb", "irb.gemspec", "lib/irb.rb", "lib/irb/cmd/chws.rb", "lib/irb/cmd/fork.rb", "lib/irb/cmd/help.rb", "lib/irb/cmd/load.rb", "lib/irb/cmd/nop.rb", "lib/irb/cmd/pushws.rb", "lib/irb/cmd/subirb.rb", "lib/irb/completion.rb", "lib/irb/context.rb", "lib/irb/ext/change-ws.rb", "lib/irb/ext/history.rb", "lib/irb/ext/loader.rb", "lib/irb/ext/multi-irb.rb", "lib/irb/ext/save-history.rb", "lib/irb/ext/tracer.rb", "lib/irb/ext/use-loader.rb", "lib/irb/ext/workspaces.rb", "lib/irb/extend-command.rb", "lib/irb/frame.rb", "lib/irb/help.rb", "lib/irb/init.rb", "lib/irb/input-method.rb", "lib/irb/inspector.rb", "lib/irb/lc/.document", "lib/irb/lc/error.rb", "lib/irb/lc/help-message", "lib/irb/lc/ja/encoding_aliases.rb", "lib/irb/lc/ja/error.rb", "lib/irb/lc/ja/help-message", "lib/irb/locale.rb", "lib/irb/magic-file.rb", "lib/irb/notifier.rb", "lib/irb/output-method.rb", "lib/irb/ruby-lex.rb", "lib/irb/ruby-token.rb", "lib/irb/slex.rb", "lib/irb/src_encoding.rb", "lib/irb/version.rb", "lib/irb/workspace.rb", "lib/irb/ws-for-case-2.rb", "lib/irb/xmp.rb"]
75
20
  spec.bindir = "exe"
76
21
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
77
22
  spec.require_paths = ["lib"]
78
23
 
79
- spec.required_ruby_version = Gem::Requirement.new(">= 2.4")
80
-
81
- spec.add_dependency "reline", ">= 0.0.1"
82
24
  spec.add_development_dependency "bundler"
83
25
  spec.add_development_dependency "rake"
84
26
  end
data/lib/irb.rb CHANGED
@@ -10,7 +10,6 @@
10
10
  #
11
11
  #
12
12
  require "e2mmap"
13
- require "ripper"
14
13
 
15
14
  require "irb/init"
16
15
  require "irb/context"
@@ -19,7 +18,6 @@ require "irb/extend-command"
19
18
  require "irb/ruby-lex"
20
19
  require "irb/input-method"
21
20
  require "irb/locale"
22
- require "irb/color"
23
21
 
24
22
  require "irb/version"
25
23
 
@@ -45,8 +43,8 @@ require "irb/version"
45
43
  # irb(main):006:1> end
46
44
  # #=> nil
47
45
  #
48
- # The singleline editor module or multiline editor module can be used with irb.
49
- # Use of multiline editor is default if it's installed.
46
+ # The Readline extension module can be used with irb. Use of Readline is
47
+ # default if it's installed.
50
48
  #
51
49
  # == Command line options
52
50
  #
@@ -61,24 +59,21 @@ require "irb/version"
61
59
  # -W[level=2] Same as `ruby -W`
62
60
  # --inspect Use `inspect' for output (default except for bc mode)
63
61
  # --noinspect Don't use inspect for output
64
- # --multiline Use multiline editor module
65
- # --nomultiline Don't use multiline editor module
66
- # --singleline Use singleline editor module
67
- # --nosingleline Don't use singleline editor module
68
- # --colorize Use colorization
69
- # --nocolorize Don't use colorization
62
+ # --readline Use Readline extension module
63
+ # --noreadline Don't use Readline extension module
70
64
  # --prompt prompt-mode
71
65
  # --prompt-mode prompt-mode
72
66
  # Switch prompt mode. Pre-defined prompt modes are
73
67
  # `default', `simple', `xmp' and `inf-ruby'
74
68
  # --inf-ruby-mode Use prompt appropriate for inf-ruby-mode on emacs.
75
- # Suppresses --multiline and --singleline.
69
+ # Suppresses --readline.
76
70
  # --simple-prompt Simple prompt mode
77
71
  # --noprompt No prompt mode
78
72
  # --tracer Display trace for each execution of commands.
79
73
  # --back-trace-limit n
80
74
  # Display backtrace top n and tail n. The default
81
75
  # value is 16.
76
+ # --irb_debug n Set internal debug level to n (not for popular use)
82
77
  # -v, --version Print the version of irb
83
78
  #
84
79
  # == Configuration
@@ -100,20 +95,19 @@ require "irb/version"
100
95
  # IRB.conf[:IRB_RC] = nil
101
96
  # IRB.conf[:BACK_TRACE_LIMIT]=16
102
97
  # IRB.conf[:USE_LOADER] = false
103
- # IRB.conf[:USE_MULTILINE] = nil
104
- # IRB.conf[:USE_SINGLELINE] = nil
105
- # IRB.conf[:USE_COLORIZE] = true
98
+ # IRB.conf[:USE_READLINE] = nil
106
99
  # IRB.conf[:USE_TRACER] = false
107
100
  # IRB.conf[:IGNORE_SIGINT] = true
108
101
  # IRB.conf[:IGNORE_EOF] = false
109
102
  # IRB.conf[:PROMPT_MODE] = :DEFAULT
110
103
  # IRB.conf[:PROMPT] = {...}
104
+ # IRB.conf[:DEBUG_LEVEL]=0
111
105
  #
112
106
  # === Auto indentation
113
107
  #
114
- # To disable auto-indent mode in irb, add the following to your +.irbrc+:
108
+ # To enable auto-indent mode in irb, add the following to your +.irbrc+:
115
109
  #
116
- # IRB.conf[:AUTO_INDENT] = false
110
+ # IRB.conf[:AUTO_INDENT] = true
117
111
  #
118
112
  # === Autocompletion
119
113
  #
@@ -123,22 +117,15 @@ require "irb/version"
123
117
  #
124
118
  # === History
125
119
  #
126
- # By default, irb will store the last 1000 commands you used in
127
- # <code>IRB.conf[:HISTORY_FILE]</code> (<code>~/.irb_history</code> by default).
120
+ # By default, irb disables history and will not store any commands you used.
128
121
  #
129
- # If you want to disable history, add the following to your +.irbrc+:
122
+ # If you want to enable history, add the following to your +.irbrc+:
130
123
  #
131
- # IRB.conf[:SAVE_HISTORY] = nil
124
+ # IRB.conf[:SAVE_HISTORY] = 1000
132
125
  #
133
- # See IRB::Context#save_history= for more information.
134
- #
135
- # The history of _resuls_ of commands evaluated is not stored by default,
136
- # but can be turned on to be stored with this +.irbrc+ setting:
126
+ # This will now store the last 1000 commands in <code>~/.irb_history</code>.
137
127
  #
138
- # IRB.conf[:EVAL_HISTORY] = <number>
139
- #
140
- # See IRB::Context#eval_history= and History class. The history of command
141
- # results is not permanently saved in any file.
128
+ # See IRB::Context#save_history= for more information.
142
129
  #
143
130
  # == Customizing the IRB Prompt
144
131
  #
@@ -149,7 +136,7 @@ require "irb/version"
149
136
  # This example can be used in your +.irbrc+
150
137
  #
151
138
  # IRB.conf[:PROMPT][:MY_PROMPT] = { # name of prompt mode
152
- # :AUTO_INDENT => false, # disables auto-indent mode
139
+ # :AUTO_INDENT => true, # enables auto-indent mode
153
140
  # :PROMPT_I => ">> ", # simple prompt
154
141
  # :PROMPT_S => nil, # prompt for continuated strings
155
142
  # :PROMPT_C => nil, # prompt for continuated statement
@@ -178,7 +165,6 @@ require "irb/version"
178
165
  #
179
166
  # IRB.conf[:PROMPT_MODE][:DEFAULT] = {
180
167
  # :PROMPT_I => "%N(%m):%03n:%i> ",
181
- # :PROMPT_N => "%N(%m):%03n:%i> ",
182
168
  # :PROMPT_S => "%N(%m):%03n:%i%l ",
183
169
  # :PROMPT_C => "%N(%m):%03n:%i* ",
184
170
  # :RETURN => "%s\n" # used to printf
@@ -282,9 +268,7 @@ require "irb/version"
282
268
  # <code>_</code>::
283
269
  # The value command executed, as a local variable
284
270
  # <code>__</code>::
285
- # The history of evaluated commands. Available only if
286
- # <code>IRB.conf[:EVAL_HISTORY]</code> is not +nil+ (which is the default).
287
- # See also IRB::Context#eval_history= and IRB::History.
271
+ # The history of evaluated commands
288
272
  # <code>__[line_no]</code>::
289
273
  # Returns the evaluation value at the given line number, +line_no+.
290
274
  # If +line_no+ is a negative, the return value +line_no+ many lines before
@@ -421,41 +405,14 @@ module IRB
421
405
  end
422
406
 
423
407
  class Irb
424
- ASSIGNMENT_NODE_TYPES = [
425
- # Local, instance, global, class, constant, instance, and index assignment:
426
- # "foo = bar",
427
- # "@foo = bar",
428
- # "$foo = bar",
429
- # "@@foo = bar",
430
- # "::Foo = bar",
431
- # "a::Foo = bar",
432
- # "Foo = bar"
433
- # "foo.bar = 1"
434
- # "foo[1] = bar"
435
- :assign,
436
-
437
- # Operation assignment:
438
- # "foo += bar"
439
- # "foo -= bar"
440
- # "foo ||= bar"
441
- # "foo &&= bar"
442
- :opassign,
443
-
444
- # Multiple assignment:
445
- # "foo, bar = 1, 2
446
- :massign,
447
- ]
448
- # Note: instance and index assignment expressions could also be written like:
449
- # "foo.bar=(1)" and "foo.[]=(1, bar)", when expressed that way, the former
450
- # be parsed as :assign and echo will be suppressed, but the latter is
451
- # parsed as a :method_add_arg and the output won't be suppressed
452
-
453
408
  # Creates a new irb session
454
- def initialize(workspace = nil, input_method = nil)
455
- @context = Context.new(self, workspace, input_method)
409
+ def initialize(workspace = nil, input_method = nil, output_method = nil)
410
+ @context = Context.new(self, workspace, input_method, output_method)
456
411
  @context.main.extend ExtendCommandBundle
457
412
  @signal_status = :IN_IRB
413
+
458
414
  @scanner = RubyLex.new
415
+ @scanner.exception_on_syntax_error = false
459
416
  end
460
417
 
461
418
  def run(conf = IRB.conf)
@@ -501,16 +458,14 @@ module IRB
501
458
  else
502
459
  @context.io.prompt = p = ""
503
460
  end
504
- if @context.auto_indent_mode and !@context.io.respond_to?(:auto_indent)
461
+ if @context.auto_indent_mode
505
462
  unless ltype
506
- prompt_i = @context.prompt_i.nil? ? "" : @context.prompt_i
507
- ind = prompt(prompt_i, ltype, indent, line_no)[/.*\z/].size +
463
+ ind = prompt(@context.prompt_i, ltype, indent, line_no)[/.*\z/].size +
508
464
  indent * 2 - p.size
509
465
  ind += 2 if continue
510
466
  @context.io.prompt = p + " " * ind if ind > 0
511
467
  end
512
468
  end
513
- @context.io.prompt
514
469
  end
515
470
 
516
471
  @scanner.set_input(@context.io) do
@@ -531,14 +486,12 @@ module IRB
531
486
  end
532
487
  end
533
488
 
534
- @scanner.set_auto_indent(@context) if @context.auto_indent_mode
535
-
536
489
  @scanner.each_top_level_statement do |line, line_no|
537
490
  signal_status(:IN_EVAL) do
538
491
  begin
539
- line.untaint if RUBY_VERSION < '2.7'
492
+ line.untaint
540
493
  @context.evaluate(line, line_no, exception: exc)
541
- output_value if @context.echo? && (@context.echo_on_assignment? || !assignment_expression?(line))
494
+ output_value if @context.echo?
542
495
  rescue Interrupt => exc
543
496
  rescue SystemExit, SignalException
544
497
  raise
@@ -710,18 +663,10 @@ module IRB
710
663
  when "l"
711
664
  ltype
712
665
  when "i"
713
- if indent < 0
714
- if $1
715
- "-".rjust($1.to_i)
716
- else
717
- "-"
718
- end
666
+ if $1
667
+ format("%" + $1 + "d", indent)
719
668
  else
720
- if $1
721
- format("%" + $1 + "d", indent)
722
- else
723
- indent.to_s
724
- end
669
+ indent.to_s
725
670
  end
726
671
  when "n"
727
672
  if $1
@@ -757,21 +702,6 @@ module IRB
757
702
  format("#<%s: %s>", self.class, ary.join(", "))
758
703
  end
759
704
 
760
- def assignment_expression?(line)
761
- # Try to parse the line and check if the last of possibly multiple
762
- # expressions is an assignment type.
763
-
764
- # If the expression is invalid, Ripper.sexp should return nil which will
765
- # result in false being returned. Any valid expression should return an
766
- # s-expression where the second selement of the top level array is an
767
- # array of parsed expressions. The first element of each expression is the
768
- # expression's type.
769
- verbose, $VERBOSE = $VERBOSE, nil
770
- result = ASSIGNMENT_NODE_TYPES.include?(Ripper.sexp(line)&.dig(1,-1,0))
771
- $VERBOSE = verbose
772
- result
773
- end
774
-
775
705
  ATTR_TTY = "\e[%sm"
776
706
  def ATTR_TTY.[](*a) self % a.join(";"); end
777
707
  ATTR_PLAIN = ""
@@ -819,8 +749,8 @@ class Binding
819
749
  #
820
750
  # Potato.new
821
751
  #
822
- # Running <code>ruby potato.rb</code> will open an IRB session where
823
- # +binding.irb+ is called, and you will see the following:
752
+ # Running +ruby potato.rb+ will open an IRB session where +binding.irb+ is
753
+ # called, and you will see the following:
824
754
  #
825
755
  # $ ruby potato.rb
826
756
  #
@@ -850,7 +780,7 @@ class Binding
850
780
  # irb(#<Potato:0x00007feea1916670>):004:0> @cooked = true
851
781
  # => true
852
782
  #
853
- # You can exit the IRB session with the +exit+ command. Note that exiting will
783
+ # You can exit the IRB session with the `exit` command. Note that exiting will
854
784
  # resume execution where +binding.irb+ had paused it, as you can see from the
855
785
  # output printed to standard output in this example:
856
786
  #
@@ -860,11 +790,9 @@ class Binding
860
790
  #
861
791
  # See IRB@IRB+Usage for more information.
862
792
  def irb
863
- IRB.setup(source_location[0], argv: [])
793
+ IRB.setup(eval("__FILE__"), argv: [])
864
794
  workspace = IRB::WorkSpace.new(self)
865
795
  STDOUT.print(workspace.code_around_binding)
866
- binding_irb = IRB::Irb.new(workspace)
867
- binding_irb.context.irb_path = File.expand_path(source_location[0])
868
- binding_irb.run(IRB.conf)
796
+ IRB::Irb.new(workspace).run(IRB.conf)
869
797
  end
870
798
  end
@@ -21,7 +21,7 @@ module IRB
21
21
  class << self
22
22
  alias_method :exit, ExtendCommand.irb_original_method_name('exit')
23
23
  end
24
- if block_given?
24
+ if iterator?
25
25
  begin
26
26
  yield
27
27
  ensure
@@ -9,18 +9,17 @@
9
9
  #
10
10
  #
11
11
 
12
+ require 'rdoc/ri/driver'
13
+
12
14
  require_relative "nop"
13
15
 
14
16
  # :stopdoc:
15
17
  module IRB
16
18
  module ExtendCommand
17
19
  class Help < Nop
18
- def execute(*names)
19
- require 'rdoc/ri/driver'
20
- IRB::ExtendCommand::Help.const_set(:Ri, RDoc::RI::Driver.new)
21
- rescue LoadError, SystemExit
22
- IRB::ExtendCommand::Help.remove_method(:execute)
23
- # raise NoMethodError in ensure
20
+ begin
21
+ Ri = RDoc::RI::Driver.new
22
+ rescue SystemExit
24
23
  else
25
24
  def execute(*names)
26
25
  if names.empty?
@@ -36,9 +35,6 @@ module IRB
36
35
  end
37
36
  nil
38
37
  end
39
- nil
40
- ensure
41
- execute(*names)
42
38
  end
43
39
  end
44
40
  end