irb 1.1.0.pre.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (49) hide show
  1. checksums.yaml +7 -0
  2. data/LICENSE.txt +22 -0
  3. data/README.md +55 -0
  4. data/exe/irb +11 -0
  5. data/irb.gemspec +29 -0
  6. data/lib/irb.rb +855 -0
  7. data/lib/irb/cmd/chws.rb +34 -0
  8. data/lib/irb/cmd/fork.rb +39 -0
  9. data/lib/irb/cmd/help.rb +46 -0
  10. data/lib/irb/cmd/load.rb +67 -0
  11. data/lib/irb/cmd/nop.rb +39 -0
  12. data/lib/irb/cmd/pushws.rb +41 -0
  13. data/lib/irb/cmd/subirb.rb +43 -0
  14. data/lib/irb/color.rb +218 -0
  15. data/lib/irb/completion.rb +339 -0
  16. data/lib/irb/context.rb +459 -0
  17. data/lib/irb/ext/change-ws.rb +46 -0
  18. data/lib/irb/ext/history.rb +120 -0
  19. data/lib/irb/ext/loader.rb +129 -0
  20. data/lib/irb/ext/multi-irb.rb +265 -0
  21. data/lib/irb/ext/save-history.rb +117 -0
  22. data/lib/irb/ext/tracer.rb +72 -0
  23. data/lib/irb/ext/use-loader.rb +77 -0
  24. data/lib/irb/ext/workspaces.rb +67 -0
  25. data/lib/irb/extend-command.rb +328 -0
  26. data/lib/irb/frame.rb +81 -0
  27. data/lib/irb/help.rb +37 -0
  28. data/lib/irb/init.rb +312 -0
  29. data/lib/irb/input-method.rb +298 -0
  30. data/lib/irb/inspector.rb +142 -0
  31. data/lib/irb/lc/.document +4 -0
  32. data/lib/irb/lc/error.rb +32 -0
  33. data/lib/irb/lc/help-message +50 -0
  34. data/lib/irb/lc/ja/encoding_aliases.rb +11 -0
  35. data/lib/irb/lc/ja/error.rb +31 -0
  36. data/lib/irb/lc/ja/help-message +52 -0
  37. data/lib/irb/locale.rb +182 -0
  38. data/lib/irb/magic-file.rb +38 -0
  39. data/lib/irb/notifier.rb +232 -0
  40. data/lib/irb/output-method.rb +92 -0
  41. data/lib/irb/ruby-lex.rb +492 -0
  42. data/lib/irb/ruby-token.rb +267 -0
  43. data/lib/irb/slex.rb +282 -0
  44. data/lib/irb/src_encoding.rb +7 -0
  45. data/lib/irb/version.rb +17 -0
  46. data/lib/irb/workspace.rb +190 -0
  47. data/lib/irb/ws-for-case-2.rb +15 -0
  48. data/lib/irb/xmp.rb +170 -0
  49. metadata +133 -0
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: false
2
+ # DO NOT WRITE ANY MAGIC COMMENT HERE.
3
+ module IRB
4
+ def self.default_src_encoding
5
+ return __ENCODING__
6
+ end
7
+ end
@@ -0,0 +1,17 @@
1
+ # frozen_string_literal: false
2
+ #
3
+ # irb/version.rb - irb version definition file
4
+ # $Release Version: 0.9.6$
5
+ # $Revision$
6
+ # by Keiju ISHITSUKA(keiju@ishitsuka.com)
7
+ #
8
+ # --
9
+ #
10
+ #
11
+ #
12
+
13
+ module IRB # :nodoc:
14
+ VERSION = "1.1.0.pre.3"
15
+ @RELEASE_VERSION = VERSION
16
+ @LAST_UPDATE_DATE = "2019-09-01"
17
+ end
@@ -0,0 +1,190 @@
1
+ # frozen_string_literal: false
2
+ #
3
+ # irb/workspace-binding.rb -
4
+ # $Release Version: 0.9.6$
5
+ # $Revision$
6
+ # by Keiju ISHITSUKA(keiju@ruby-lang.org)
7
+ #
8
+ # --
9
+ #
10
+ #
11
+ #
12
+
13
+ require "delegate"
14
+
15
+ module IRB # :nodoc:
16
+ class WorkSpace
17
+ # Creates a new workspace.
18
+ #
19
+ # set self to main if specified, otherwise
20
+ # inherit main from TOPLEVEL_BINDING.
21
+ def initialize(*main)
22
+ if main[0].kind_of?(Binding)
23
+ @binding = main.shift
24
+ elsif IRB.conf[:SINGLE_IRB]
25
+ @binding = TOPLEVEL_BINDING
26
+ else
27
+ case IRB.conf[:CONTEXT_MODE]
28
+ when 0 # binding in proc on TOPLEVEL_BINDING
29
+ @binding = eval("proc{binding}.call",
30
+ TOPLEVEL_BINDING,
31
+ __FILE__,
32
+ __LINE__)
33
+ when 1 # binding in loaded file
34
+ require "tempfile"
35
+ f = Tempfile.open("irb-binding")
36
+ f.print <<EOF
37
+ $binding = binding
38
+ EOF
39
+ f.close
40
+ load f.path
41
+ @binding = $binding
42
+
43
+ when 2 # binding in loaded file(thread use)
44
+ unless defined? BINDING_QUEUE
45
+ IRB.const_set(:BINDING_QUEUE, Thread::SizedQueue.new(1))
46
+ Thread.abort_on_exception = true
47
+ Thread.start do
48
+ eval "require \"irb/ws-for-case-2\"", TOPLEVEL_BINDING, __FILE__, __LINE__
49
+ end
50
+ Thread.pass
51
+ end
52
+ @binding = BINDING_QUEUE.pop
53
+
54
+ when 3 # binding in function on TOPLEVEL_BINDING(default)
55
+ @binding = eval("self.class.send(:remove_method, :irb_binding) if defined?(irb_binding); private; def irb_binding; binding; end; irb_binding",
56
+ TOPLEVEL_BINDING,
57
+ __FILE__,
58
+ __LINE__ - 3)
59
+ end
60
+ end
61
+
62
+ if main.empty?
63
+ @main = eval("self", @binding)
64
+ else
65
+ @main = main[0]
66
+ end
67
+ IRB.conf[:__MAIN__] = @main
68
+
69
+ unless main.empty?
70
+ case @main
71
+ when Module
72
+ @binding = eval("IRB.conf[:__MAIN__].module_eval('binding', __FILE__, __LINE__)", @binding, __FILE__, __LINE__)
73
+ else
74
+ begin
75
+ @binding = eval("IRB.conf[:__MAIN__].instance_eval('binding', __FILE__, __LINE__)", @binding, __FILE__, __LINE__)
76
+ rescue TypeError
77
+ IRB.fail CantChangeBinding, @main.inspect
78
+ end
79
+ end
80
+ end
81
+
82
+ case @main
83
+ when Object
84
+ use_delegator = @main.frozen?
85
+ else
86
+ use_delegator = true
87
+ end
88
+
89
+ if use_delegator
90
+ @main = SimpleDelegator.new(@main)
91
+ IRB.conf[:__MAIN__] = @main
92
+ @main.singleton_class.class_eval do
93
+ private
94
+ define_method(:exit) do |*a, &b|
95
+ # Do nothing, will be overridden
96
+ end
97
+ define_method(:binding, Kernel.instance_method(:binding))
98
+ define_method(:local_variables, Kernel.instance_method(:local_variables))
99
+ end
100
+ @binding = eval("IRB.conf[:__MAIN__].instance_eval('binding', __FILE__, __LINE__)", @binding, *@binding.source_location)
101
+ end
102
+
103
+ @binding.local_variable_set(:_, nil)
104
+ end
105
+
106
+ # The Binding of this workspace
107
+ attr_reader :binding
108
+ # The top-level workspace of this context, also available as
109
+ # <code>IRB.conf[:__MAIN__]</code>
110
+ attr_reader :main
111
+
112
+ # Evaluate the given +statements+ within the context of this workspace.
113
+ def evaluate(context, statements, file = __FILE__, line = __LINE__)
114
+ eval(statements, @binding, file, line)
115
+ end
116
+
117
+ def local_variable_set(name, value)
118
+ @binding.local_variable_set(name, value)
119
+ end
120
+
121
+ def local_variable_get(name)
122
+ @binding.local_variable_get(name)
123
+ end
124
+
125
+ # error message manipulator
126
+ def filter_backtrace(bt)
127
+ case IRB.conf[:CONTEXT_MODE]
128
+ when 0
129
+ return nil if bt =~ /\(irb_local_binding\)/
130
+ when 1
131
+ if(bt =~ %r!/tmp/irb-binding! or
132
+ bt =~ %r!irb/.*\.rb! or
133
+ bt =~ /irb\.rb/)
134
+ return nil
135
+ end
136
+ when 2
137
+ return nil if bt =~ /irb\/.*\.rb/
138
+ return nil if bt =~ /irb\.rb/
139
+ when 3
140
+ return nil if bt =~ /irb\/.*\.rb/
141
+ return nil if bt =~ /irb\.rb/
142
+ bt = bt.sub(/:\s*in `irb_binding'/, '')
143
+ end
144
+ bt
145
+ end
146
+
147
+ def code_around_binding
148
+ if @binding.respond_to?(:source_location)
149
+ file, pos = @binding.source_location
150
+ else
151
+ file, pos = @binding.eval('[__FILE__, __LINE__]')
152
+ end
153
+
154
+ if defined?(::SCRIPT_LINES__[file]) && lines = ::SCRIPT_LINES__[file]
155
+ code = ::SCRIPT_LINES__[file].join('')
156
+ else
157
+ begin
158
+ code = File.read(file)
159
+ rescue SystemCallError
160
+ return
161
+ end
162
+ end
163
+
164
+ # NOT using #use_colorize? of IRB.conf[:MAIN_CONTEXT] because this method may be called before IRB::Irb#run
165
+ use_colorize = IRB.conf.fetch(:USE_COLORIZE, true)
166
+ if use_colorize
167
+ lines = Color.colorize_code(code).lines
168
+ else
169
+ lines = code.lines
170
+ end
171
+ pos -= 1
172
+
173
+ start_pos = [pos - 5, 0].max
174
+ end_pos = [pos + 5, lines.size - 1].min
175
+
176
+ if use_colorize
177
+ fmt = " %2s #{Color.colorize("%#{end_pos.to_s.length}d", [:BLUE, :BOLD])}: %s"
178
+ else
179
+ fmt = " %2s %#{end_pos.to_s.length}d: %s"
180
+ end
181
+ body = (start_pos..end_pos).map do |current_pos|
182
+ sprintf(fmt, pos == current_pos ? '=>' : '', current_pos + 1, lines[current_pos])
183
+ end.join("")
184
+ "\nFrom: #{file} @ line #{pos + 1} :\n\n#{body}#{Color.clear}\n"
185
+ end
186
+
187
+ def IRB.delete_caller
188
+ end
189
+ end
190
+ end
@@ -0,0 +1,15 @@
1
+ # frozen_string_literal: false
2
+ #
3
+ # irb/ws-for-case-2.rb -
4
+ # $Release Version: 0.9.6$
5
+ # $Revision$
6
+ # by Keiju ISHITSUKA(keiju@ruby-lang.org)
7
+ #
8
+ # --
9
+ #
10
+ #
11
+ #
12
+
13
+ while true
14
+ IRB::BINDING_QUEUE.push _ = binding
15
+ end
@@ -0,0 +1,170 @@
1
+ # frozen_string_literal: false
2
+ #
3
+ # xmp.rb - irb version of gotoken xmp
4
+ # $Release Version: 0.9$
5
+ # $Revision$
6
+ # by Keiju ISHITSUKA(Nippon Rational Inc.)
7
+ #
8
+ # --
9
+ #
10
+ #
11
+ #
12
+
13
+ require "irb"
14
+ require_relative "frame"
15
+
16
+ # An example printer for irb.
17
+ #
18
+ # It's much like the standard library PrettyPrint, that shows the value of each
19
+ # expression as it runs.
20
+ #
21
+ # In order to use this library, you must first require it:
22
+ #
23
+ # require 'irb/xmp'
24
+ #
25
+ # Now, you can take advantage of the Object#xmp convenience method.
26
+ #
27
+ # xmp <<END
28
+ # foo = "bar"
29
+ # baz = 42
30
+ # END
31
+ # #=> foo = "bar"
32
+ # #==>"bar"
33
+ # #=> baz = 42
34
+ # #==>42
35
+ #
36
+ # You can also create an XMP object, with an optional binding to print
37
+ # expressions in the given binding:
38
+ #
39
+ # ctx = binding
40
+ # x = XMP.new ctx
41
+ # x.puts
42
+ # #=> today = "a good day"
43
+ # #==>"a good day"
44
+ # ctx.eval 'today # is what?'
45
+ # #=> "a good day"
46
+ class XMP
47
+
48
+ # Creates a new XMP object.
49
+ #
50
+ # The top-level binding or, optional +bind+ parameter will be used when
51
+ # creating the workspace. See WorkSpace.new for more information.
52
+ #
53
+ # This uses the +:XMP+ prompt mode, see IRB@Customizing+the+IRB+Prompt for
54
+ # full detail.
55
+ def initialize(bind = nil)
56
+ IRB.init_config(nil)
57
+
58
+ IRB.conf[:PROMPT_MODE] = :XMP
59
+
60
+ bind = IRB::Frame.top(1) unless bind
61
+ ws = IRB::WorkSpace.new(bind)
62
+ @io = StringInputMethod.new
63
+ @irb = IRB::Irb.new(ws, @io)
64
+ @irb.context.ignore_sigint = false
65
+
66
+ IRB.conf[:MAIN_CONTEXT] = @irb.context
67
+ end
68
+
69
+ # Evaluates the given +exps+, for example:
70
+ #
71
+ # require 'irb/xmp'
72
+ # x = XMP.new
73
+ #
74
+ # x.puts '{:a => 1, :b => 2, :c => 3}'
75
+ # #=> {:a => 1, :b => 2, :c => 3}
76
+ # # ==>{:a=>1, :b=>2, :c=>3}
77
+ # x.puts 'foo = "bar"'
78
+ # # => foo = "bar"
79
+ # # ==>"bar"
80
+ def puts(exps)
81
+ @io.puts exps
82
+
83
+ if @irb.context.ignore_sigint
84
+ begin
85
+ trap_proc_b = trap("SIGINT"){@irb.signal_handle}
86
+ catch(:IRB_EXIT) do
87
+ @irb.eval_input
88
+ end
89
+ ensure
90
+ trap("SIGINT", trap_proc_b)
91
+ end
92
+ else
93
+ catch(:IRB_EXIT) do
94
+ @irb.eval_input
95
+ end
96
+ end
97
+ end
98
+
99
+ # A custom InputMethod class used by XMP for evaluating string io.
100
+ class StringInputMethod < IRB::InputMethod
101
+ # Creates a new StringInputMethod object
102
+ def initialize
103
+ super
104
+ @exps = []
105
+ end
106
+
107
+ # Whether there are any expressions left in this printer.
108
+ def eof?
109
+ @exps.empty?
110
+ end
111
+
112
+ # Reads the next expression from this printer.
113
+ #
114
+ # See IO#gets for more information.
115
+ def gets
116
+ while l = @exps.shift
117
+ next if /^\s+$/ =~ l
118
+ l.concat "\n"
119
+ print @prompt, l
120
+ break
121
+ end
122
+ l
123
+ end
124
+
125
+ # Concatenates all expressions in this printer, separated by newlines.
126
+ #
127
+ # An Encoding::CompatibilityError is raised of the given +exps+'s encoding
128
+ # doesn't match the previous expression evaluated.
129
+ def puts(exps)
130
+ if @encoding and exps.encoding != @encoding
131
+ enc = Encoding.compatible?(@exps.join("\n"), exps)
132
+ if enc.nil?
133
+ raise Encoding::CompatibilityError, "Encoding in which the passed expression is encoded is not compatible to the preceding's one"
134
+ else
135
+ @encoding = enc
136
+ end
137
+ else
138
+ @encoding = exps.encoding
139
+ end
140
+ @exps.concat exps.split(/\n/)
141
+ end
142
+
143
+ # Returns the encoding of last expression printed by #puts.
144
+ attr_reader :encoding
145
+ end
146
+ end
147
+
148
+ # A convenience method that's only available when the you require the IRB::XMP standard library.
149
+ #
150
+ # Creates a new XMP object, using the given expressions as the +exps+
151
+ # parameter, and optional binding as +bind+ or uses the top-level binding. Then
152
+ # evaluates the given expressions using the +:XMP+ prompt mode.
153
+ #
154
+ # For example:
155
+ #
156
+ # require 'irb/xmp'
157
+ # ctx = binding
158
+ # xmp 'foo = "bar"', ctx
159
+ # #=> foo = "bar"
160
+ # #==>"bar"
161
+ # ctx.eval 'foo'
162
+ # #=> "bar"
163
+ #
164
+ # See XMP.new for more information.
165
+ def xmp(exps, bind = nil)
166
+ bind = IRB::Frame.top(1) unless bind
167
+ xmp = XMP.new(bind)
168
+ xmp.puts exps
169
+ xmp
170
+ end
metadata ADDED
@@ -0,0 +1,133 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: irb
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.1.0.pre.3
5
+ platform: ruby
6
+ authors:
7
+ - Keiju ISHITSUKA
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2019-09-01 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: reline
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: 0.0.1
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: 0.0.1
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ description: Interactive Ruby command-line tool for REPL (Read Eval Print Loop).
56
+ email:
57
+ - keiju@ruby-lang.org
58
+ executables:
59
+ - irb
60
+ extensions: []
61
+ extra_rdoc_files: []
62
+ files:
63
+ - LICENSE.txt
64
+ - README.md
65
+ - exe/irb
66
+ - irb.gemspec
67
+ - lib/irb.rb
68
+ - lib/irb/cmd/chws.rb
69
+ - lib/irb/cmd/fork.rb
70
+ - lib/irb/cmd/help.rb
71
+ - lib/irb/cmd/load.rb
72
+ - lib/irb/cmd/nop.rb
73
+ - lib/irb/cmd/pushws.rb
74
+ - lib/irb/cmd/subirb.rb
75
+ - lib/irb/color.rb
76
+ - lib/irb/completion.rb
77
+ - lib/irb/context.rb
78
+ - lib/irb/ext/change-ws.rb
79
+ - lib/irb/ext/history.rb
80
+ - lib/irb/ext/loader.rb
81
+ - lib/irb/ext/multi-irb.rb
82
+ - lib/irb/ext/save-history.rb
83
+ - lib/irb/ext/tracer.rb
84
+ - lib/irb/ext/use-loader.rb
85
+ - lib/irb/ext/workspaces.rb
86
+ - lib/irb/extend-command.rb
87
+ - lib/irb/frame.rb
88
+ - lib/irb/help.rb
89
+ - lib/irb/init.rb
90
+ - lib/irb/input-method.rb
91
+ - lib/irb/inspector.rb
92
+ - lib/irb/lc/.document
93
+ - lib/irb/lc/error.rb
94
+ - lib/irb/lc/help-message
95
+ - lib/irb/lc/ja/encoding_aliases.rb
96
+ - lib/irb/lc/ja/error.rb
97
+ - lib/irb/lc/ja/help-message
98
+ - lib/irb/locale.rb
99
+ - lib/irb/magic-file.rb
100
+ - lib/irb/notifier.rb
101
+ - lib/irb/output-method.rb
102
+ - lib/irb/ruby-lex.rb
103
+ - lib/irb/ruby-token.rb
104
+ - lib/irb/slex.rb
105
+ - lib/irb/src_encoding.rb
106
+ - lib/irb/version.rb
107
+ - lib/irb/workspace.rb
108
+ - lib/irb/ws-for-case-2.rb
109
+ - lib/irb/xmp.rb
110
+ homepage: https://github.com/ruby/irb
111
+ licenses:
112
+ - BSD-2-Clause
113
+ metadata: {}
114
+ post_install_message:
115
+ rdoc_options: []
116
+ require_paths:
117
+ - lib
118
+ required_ruby_version: !ruby/object:Gem::Requirement
119
+ requirements:
120
+ - - ">="
121
+ - !ruby/object:Gem::Version
122
+ version: '2.4'
123
+ required_rubygems_version: !ruby/object:Gem::Requirement
124
+ requirements:
125
+ - - ">"
126
+ - !ruby/object:Gem::Version
127
+ version: 1.3.1
128
+ requirements: []
129
+ rubygems_version: 3.0.3
130
+ signing_key:
131
+ specification_version: 4
132
+ summary: Interactive Ruby command-line tool for REPL (Read Eval Print Loop).
133
+ test_files: []