irb 0.9.6

Sign up to get free protection for your applications and to get access to all the features.
Files changed (54) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +9 -0
  3. data/.travis.yml +6 -0
  4. data/Gemfile +5 -0
  5. data/LICENSE.txt +22 -0
  6. data/README.md +55 -0
  7. data/Rakefile +10 -0
  8. data/bin/console +6 -0
  9. data/bin/setup +6 -0
  10. data/exe/irb +11 -0
  11. data/irb.gemspec +26 -0
  12. data/lib/irb.rb +798 -0
  13. data/lib/irb/cmd/chws.rb +34 -0
  14. data/lib/irb/cmd/fork.rb +39 -0
  15. data/lib/irb/cmd/help.rb +42 -0
  16. data/lib/irb/cmd/load.rb +67 -0
  17. data/lib/irb/cmd/nop.rb +39 -0
  18. data/lib/irb/cmd/pushws.rb +41 -0
  19. data/lib/irb/cmd/subirb.rb +43 -0
  20. data/lib/irb/completion.rb +244 -0
  21. data/lib/irb/context.rb +425 -0
  22. data/lib/irb/ext/change-ws.rb +46 -0
  23. data/lib/irb/ext/history.rb +119 -0
  24. data/lib/irb/ext/loader.rb +129 -0
  25. data/lib/irb/ext/multi-irb.rb +265 -0
  26. data/lib/irb/ext/save-history.rb +105 -0
  27. data/lib/irb/ext/tracer.rb +72 -0
  28. data/lib/irb/ext/use-loader.rb +74 -0
  29. data/lib/irb/ext/workspaces.rb +67 -0
  30. data/lib/irb/extend-command.rb +306 -0
  31. data/lib/irb/frame.rb +81 -0
  32. data/lib/irb/help.rb +37 -0
  33. data/lib/irb/init.rb +302 -0
  34. data/lib/irb/input-method.rb +192 -0
  35. data/lib/irb/inspector.rb +132 -0
  36. data/lib/irb/lc/.document +4 -0
  37. data/lib/irb/lc/error.rb +32 -0
  38. data/lib/irb/lc/help-message +49 -0
  39. data/lib/irb/lc/ja/encoding_aliases.rb +11 -0
  40. data/lib/irb/lc/ja/error.rb +31 -0
  41. data/lib/irb/lc/ja/help-message +52 -0
  42. data/lib/irb/locale.rb +182 -0
  43. data/lib/irb/magic-file.rb +38 -0
  44. data/lib/irb/notifier.rb +232 -0
  45. data/lib/irb/output-method.rb +92 -0
  46. data/lib/irb/ruby-lex.rb +1180 -0
  47. data/lib/irb/ruby-token.rb +267 -0
  48. data/lib/irb/slex.rb +282 -0
  49. data/lib/irb/src_encoding.rb +7 -0
  50. data/lib/irb/version.rb +17 -0
  51. data/lib/irb/workspace.rb +143 -0
  52. data/lib/irb/ws-for-case-2.rb +15 -0
  53. data/lib/irb/xmp.rb +170 -0
  54. metadata +125 -0
@@ -0,0 +1,34 @@
1
+ # frozen_string_literal: false
2
+ #
3
+ # change-ws.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_relative "nop"
14
+ require_relative "../ext/change-ws"
15
+
16
+ # :stopdoc:
17
+ module IRB
18
+ module ExtendCommand
19
+
20
+ class CurrentWorkingWorkspace < Nop
21
+ def execute(*obj)
22
+ irb_context.main
23
+ end
24
+ end
25
+
26
+ class ChangeWorkspace < Nop
27
+ def execute(*obj)
28
+ irb_context.change_workspace(*obj)
29
+ irb_context.main
30
+ end
31
+ end
32
+ end
33
+ end
34
+ # :startdoc:
@@ -0,0 +1,39 @@
1
+ # frozen_string_literal: false
2
+ #
3
+ # fork.rb -
4
+ # $Release Version: 0.9.6 $
5
+ # $Revision$
6
+ # by Keiju ISHITSUKA(keiju@ruby-lang.org)
7
+ #
8
+ # --
9
+ #
10
+ #
11
+ #
12
+
13
+
14
+ # :stopdoc:
15
+ module IRB
16
+ module ExtendCommand
17
+ class Fork < Nop
18
+ def execute
19
+ pid = send ExtendCommand.irb_original_method_name("fork")
20
+ unless pid
21
+ class << self
22
+ alias_method :exit, ExtendCommand.irb_original_method_name('exit')
23
+ end
24
+ if iterator?
25
+ begin
26
+ yield
27
+ ensure
28
+ exit
29
+ end
30
+ end
31
+ end
32
+ pid
33
+ end
34
+ end
35
+ end
36
+ end
37
+ # :startdoc:
38
+
39
+
@@ -0,0 +1,42 @@
1
+ # frozen_string_literal: false
2
+ #
3
+ # help.rb - helper using ri
4
+ # $Release Version: 0.9.6$
5
+ # $Revision$
6
+ #
7
+ # --
8
+ #
9
+ #
10
+ #
11
+
12
+ require 'rdoc/ri/driver'
13
+
14
+ require_relative "nop"
15
+
16
+ # :stopdoc:
17
+ module IRB
18
+ module ExtendCommand
19
+ class Help < Nop
20
+ begin
21
+ Ri = RDoc::RI::Driver.new
22
+ rescue SystemExit
23
+ else
24
+ def execute(*names)
25
+ if names.empty?
26
+ Ri.interactive
27
+ return
28
+ end
29
+ names.each do |name|
30
+ begin
31
+ Ri.display_name(name.to_s)
32
+ rescue RDoc::RI::Error
33
+ puts $!.message
34
+ end
35
+ end
36
+ nil
37
+ end
38
+ end
39
+ end
40
+ end
41
+ end
42
+ # :startdoc:
@@ -0,0 +1,67 @@
1
+ # frozen_string_literal: false
2
+ #
3
+ # load.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_relative "nop"
14
+ require_relative "../ext/loader"
15
+
16
+ # :stopdoc:
17
+ module IRB
18
+ module ExtendCommand
19
+ class Load < Nop
20
+ include IrbLoader
21
+
22
+ def execute(file_name, priv = nil)
23
+ return irb_load(file_name, priv)
24
+ end
25
+ end
26
+
27
+ class Require < Nop
28
+ include IrbLoader
29
+
30
+ def execute(file_name)
31
+
32
+ rex = Regexp.new("#{Regexp.quote(file_name)}(\.o|\.rb)?")
33
+ return false if $".find{|f| f =~ rex}
34
+
35
+ case file_name
36
+ when /\.rb$/
37
+ begin
38
+ if irb_load(file_name)
39
+ $".push file_name
40
+ return true
41
+ end
42
+ rescue LoadError
43
+ end
44
+ when /\.(so|o|sl)$/
45
+ return ruby_require(file_name)
46
+ end
47
+
48
+ begin
49
+ irb_load(f = file_name + ".rb")
50
+ $".push f
51
+ return true
52
+ rescue LoadError
53
+ return ruby_require(file_name)
54
+ end
55
+ end
56
+ end
57
+
58
+ class Source < Nop
59
+ include IrbLoader
60
+ def execute(file_name)
61
+ source_file(file_name)
62
+ end
63
+ end
64
+ end
65
+
66
+ end
67
+ # :startdoc:
@@ -0,0 +1,39 @@
1
+ # frozen_string_literal: false
2
+ #
3
+ # nop.rb -
4
+ # $Release Version: 0.9.6$
5
+ # $Revision$
6
+ # by Keiju ISHITSUKA(keiju@ruby-lang.org)
7
+ #
8
+ # --
9
+ #
10
+ #
11
+ #
12
+ # :stopdoc:
13
+ module IRB
14
+ module ExtendCommand
15
+ class Nop
16
+
17
+
18
+ def self.execute(conf, *opts)
19
+ command = new(conf)
20
+ command.execute(*opts)
21
+ end
22
+
23
+ def initialize(conf)
24
+ @irb_context = conf
25
+ end
26
+
27
+ attr_reader :irb_context
28
+
29
+ def irb
30
+ @irb_context.irb
31
+ end
32
+
33
+ def execute(*opts)
34
+ #nop
35
+ end
36
+ end
37
+ end
38
+ end
39
+ # :startdoc:
@@ -0,0 +1,41 @@
1
+ # frozen_string_literal: false
2
+ #
3
+ # change-ws.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_relative "nop"
14
+ require_relative "../ext/workspaces"
15
+
16
+ # :stopdoc:
17
+ module IRB
18
+ module ExtendCommand
19
+ class Workspaces < Nop
20
+ def execute(*obj)
21
+ irb_context.workspaces.collect{|ws| ws.main}
22
+ end
23
+ end
24
+
25
+ class PushWorkspace < Workspaces
26
+ def execute(*obj)
27
+ irb_context.push_workspace(*obj)
28
+ super
29
+ end
30
+ end
31
+
32
+ class PopWorkspace < Workspaces
33
+ def execute(*obj)
34
+ irb_context.pop_workspace(*obj)
35
+ super
36
+ end
37
+ end
38
+ end
39
+ end
40
+ # :startdoc:
41
+
@@ -0,0 +1,43 @@
1
+ # frozen_string_literal: false
2
+ # multi.rb -
3
+ # $Release Version: 0.9.6$
4
+ # $Revision$
5
+ # by Keiju ISHITSUKA(keiju@ruby-lang.org)
6
+ #
7
+ # --
8
+ #
9
+ #
10
+ #
11
+
12
+ require_relative "nop"
13
+ require_relative "../ext/multi-irb"
14
+
15
+ # :stopdoc:
16
+ module IRB
17
+ module ExtendCommand
18
+ class IrbCommand < Nop
19
+ def execute(*obj)
20
+ IRB.irb(nil, *obj)
21
+ end
22
+ end
23
+
24
+ class Jobs < Nop
25
+ def execute
26
+ IRB.JobManager
27
+ end
28
+ end
29
+
30
+ class Foreground < Nop
31
+ def execute(key)
32
+ IRB.JobManager.switch(key)
33
+ end
34
+ end
35
+
36
+ class Kill < Nop
37
+ def execute(*keys)
38
+ IRB.JobManager.kill(*keys)
39
+ end
40
+ end
41
+ end
42
+ end
43
+ # :startdoc:
@@ -0,0 +1,244 @@
1
+ # frozen_string_literal: false
2
+ #
3
+ # irb/completion.rb -
4
+ # $Release Version: 0.9$
5
+ # $Revision$
6
+ # by Keiju ISHITSUKA(keiju@ishitsuka.com)
7
+ # From Original Idea of shugo@ruby-lang.org
8
+ #
9
+
10
+ require "readline"
11
+
12
+ module IRB
13
+ module InputCompletor # :nodoc:
14
+
15
+
16
+ # Set of reserved words used by Ruby, you should not use these for
17
+ # constants or variables
18
+ ReservedWords = %w[
19
+ BEGIN END
20
+ alias and
21
+ begin break
22
+ case class
23
+ def defined do
24
+ else elsif end ensure
25
+ false for
26
+ if in
27
+ module
28
+ next nil not
29
+ or
30
+ redo rescue retry return
31
+ self super
32
+ then true
33
+ undef unless until
34
+ when while
35
+ yield
36
+ ]
37
+
38
+ CompletionProc = proc { |input|
39
+ bind = IRB.conf[:MAIN_CONTEXT].workspace.binding
40
+
41
+ case input
42
+ when /^((["'`]).*\2)\.([^.]*)$/
43
+ # String
44
+ receiver = $1
45
+ message = Regexp.quote($3)
46
+
47
+ candidates = String.instance_methods.collect{|m| m.to_s}
48
+ select_message(receiver, message, candidates)
49
+
50
+ when /^(\/[^\/]*\/)\.([^.]*)$/
51
+ # Regexp
52
+ receiver = $1
53
+ message = Regexp.quote($2)
54
+
55
+ candidates = Regexp.instance_methods.collect{|m| m.to_s}
56
+ select_message(receiver, message, candidates)
57
+
58
+ when /^([^\]]*\])\.([^.]*)$/
59
+ # Array
60
+ receiver = $1
61
+ message = Regexp.quote($2)
62
+
63
+ candidates = Array.instance_methods.collect{|m| m.to_s}
64
+ select_message(receiver, message, candidates)
65
+
66
+ when /^([^\}]*\})\.([^.]*)$/
67
+ # Proc or Hash
68
+ receiver = $1
69
+ message = Regexp.quote($2)
70
+
71
+ candidates = Proc.instance_methods.collect{|m| m.to_s}
72
+ candidates |= Hash.instance_methods.collect{|m| m.to_s}
73
+ select_message(receiver, message, candidates)
74
+
75
+ when /^(:[^:.]*)$/
76
+ # Symbol
77
+ if Symbol.respond_to?(:all_symbols)
78
+ sym = $1
79
+ candidates = Symbol.all_symbols.collect{|s| ":" + s.id2name}
80
+ candidates.grep(/^#{Regexp.quote(sym)}/)
81
+ else
82
+ []
83
+ end
84
+
85
+ when /^::([A-Z][^:\.\(]*)$/
86
+ # Absolute Constant or class methods
87
+ receiver = $1
88
+ candidates = Object.constants.collect{|m| m.to_s}
89
+ candidates.grep(/^#{receiver}/).collect{|e| "::" + e}
90
+
91
+ when /^([A-Z].*)::([^:.]*)$/
92
+ # Constant or class methods
93
+ receiver = $1
94
+ message = Regexp.quote($2)
95
+ begin
96
+ candidates = eval("#{receiver}.constants.collect{|m| m.to_s}", bind)
97
+ candidates |= eval("#{receiver}.methods.collect{|m| m.to_s}", bind)
98
+ rescue Exception
99
+ candidates = []
100
+ end
101
+ select_message(receiver, message, candidates, "::")
102
+
103
+ when /^(:[^:.]+)(\.|::)([^.]*)$/
104
+ # Symbol
105
+ receiver = $1
106
+ sep = $2
107
+ message = Regexp.quote($3)
108
+
109
+ candidates = Symbol.instance_methods.collect{|m| m.to_s}
110
+ select_message(receiver, message, candidates, sep)
111
+
112
+ when /^(-?(0[dbo])?[0-9_]+(\.[0-9_]+)?([eE]-?[0-9]+)?)(\.|::)([^.]*)$/
113
+ # Numeric
114
+ receiver = $1
115
+ sep = $5
116
+ message = Regexp.quote($6)
117
+
118
+ begin
119
+ candidates = eval(receiver, bind).methods.collect{|m| m.to_s}
120
+ rescue Exception
121
+ candidates = []
122
+ end
123
+ select_message(receiver, message, candidates, sep)
124
+
125
+ when /^(-?0x[0-9a-fA-F_]+)(\.|::)([^.]*)$/
126
+ # Numeric(0xFFFF)
127
+ receiver = $1
128
+ sep = $2
129
+ message = Regexp.quote($3)
130
+
131
+ begin
132
+ candidates = eval(receiver, bind).methods.collect{|m| m.to_s}
133
+ rescue Exception
134
+ candidates = []
135
+ end
136
+ select_message(receiver, message, candidates, sep)
137
+
138
+ when /^(\$[^.]*)$/
139
+ # global var
140
+ regmessage = Regexp.new(Regexp.quote($1))
141
+ candidates = global_variables.collect{|m| m.to_s}.grep(regmessage)
142
+
143
+ when /^([^."].*)(\.|::)([^.]*)$/
144
+ # variable.func or func.func
145
+ receiver = $1
146
+ sep = $2
147
+ message = Regexp.quote($3)
148
+
149
+ gv = eval("global_variables", bind).collect{|m| m.to_s}
150
+ lv = eval("local_variables", bind).collect{|m| m.to_s}
151
+ iv = eval("instance_variables", bind).collect{|m| m.to_s}
152
+ cv = eval("self.class.constants", bind).collect{|m| m.to_s}
153
+
154
+ if (gv | lv | iv | cv).include?(receiver) or /^[A-Z]/ =~ receiver && /\./ !~ receiver
155
+ # foo.func and foo is var. OR
156
+ # foo::func and foo is var. OR
157
+ # foo::Const and foo is var. OR
158
+ # Foo::Bar.func
159
+ begin
160
+ candidates = []
161
+ rec = eval(receiver, bind)
162
+ if sep == "::" and rec.kind_of?(Module)
163
+ candidates = rec.constants.collect{|m| m.to_s}
164
+ end
165
+ candidates |= rec.methods.collect{|m| m.to_s}
166
+ rescue Exception
167
+ candidates = []
168
+ end
169
+ else
170
+ # func1.func2
171
+ candidates = []
172
+ to_ignore = ignored_modules
173
+ ObjectSpace.each_object(Module){|m|
174
+ next if (to_ignore.include?(m) rescue true)
175
+ candidates.concat m.instance_methods(false).collect{|x| x.to_s}
176
+ }
177
+ candidates.sort!
178
+ candidates.uniq!
179
+ end
180
+ select_message(receiver, message, candidates, sep)
181
+
182
+ when /^\.([^.]*)$/
183
+ # unknown(maybe String)
184
+
185
+ receiver = ""
186
+ message = Regexp.quote($1)
187
+
188
+ candidates = String.instance_methods(true).collect{|m| m.to_s}
189
+ select_message(receiver, message, candidates)
190
+
191
+ else
192
+ candidates = eval("methods | private_methods | local_variables | instance_variables | self.class.constants", bind).collect{|m| m.to_s}
193
+
194
+ (candidates|ReservedWords).grep(/^#{Regexp.quote(input)}/)
195
+ end
196
+ }
197
+
198
+ # Set of available operators in Ruby
199
+ Operators = %w[% & * ** + - / < << <= <=> == === =~ > >= >> [] []= ^ ! != !~]
200
+
201
+ def self.select_message(receiver, message, candidates, sep = ".")
202
+ candidates.grep(/^#{message}/).collect do |e|
203
+ case e
204
+ when /^[a-zA-Z_]/
205
+ receiver + sep + e
206
+ when /^[0-9]/
207
+ when *Operators
208
+ #receiver + " " + e
209
+ end
210
+ end
211
+ end
212
+
213
+ def self.ignored_modules
214
+ # We could cache the result, but this is very fast already.
215
+ # By using this approach, we avoid Module#name calls, which are
216
+ # relatively slow when there are a lot of anonymous modules defined.
217
+ s = {}
218
+
219
+ scanner = lambda do |m|
220
+ next if s.include?(m) # IRB::ExtendCommandBundle::EXCB recurses.
221
+ s[m] = true
222
+ m.constants(false).each do |c|
223
+ value = m.const_get(c)
224
+ scanner.call(value) if value.is_a?(Module)
225
+ end
226
+ end
227
+
228
+ %i(IRB SLex RubyLex RubyToken).each do |sym|
229
+ next unless Object.const_defined?(sym)
230
+ scanner.call(Object.const_get(sym))
231
+ end
232
+
233
+ s.delete(IRB::Context) if defined?(IRB::Context)
234
+
235
+ s
236
+ end
237
+ end
238
+ end
239
+
240
+ if Readline.respond_to?("basic_word_break_characters=")
241
+ Readline.basic_word_break_characters= " \t\n`><=;|&{("
242
+ end
243
+ Readline.completion_append_character = nil
244
+ Readline.completion_proc = IRB::InputCompletor::CompletionProc