rubysl-irb 1.0.2 → 2.0.3

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.
Files changed (48) hide show
  1. checksums.yaml +4 -4
  2. data/.travis.yml +3 -2
  3. data/lib/irb/cmd/chws.rb +6 -6
  4. data/lib/irb/cmd/fork.rb +10 -10
  5. data/lib/irb/cmd/help.rb +24 -14
  6. data/lib/irb/cmd/load.rb +8 -7
  7. data/lib/irb/cmd/nop.rb +8 -8
  8. data/lib/irb/cmd/pushws.rb +6 -5
  9. data/lib/irb/cmd/subirb.rb +6 -7
  10. data/lib/irb/completion.rb +90 -58
  11. data/lib/irb/context.rb +197 -30
  12. data/lib/irb/ext/change-ws.rb +17 -10
  13. data/lib/irb/ext/history.rb +20 -10
  14. data/lib/irb/ext/loader.rb +22 -12
  15. data/lib/irb/ext/math-mode.rb +16 -6
  16. data/lib/irb/ext/multi-irb.rb +69 -24
  17. data/lib/irb/ext/save-history.rb +87 -37
  18. data/lib/irb/ext/tracer.rb +17 -7
  19. data/lib/irb/ext/use-loader.rb +14 -6
  20. data/lib/irb/ext/workspaces.rb +16 -6
  21. data/lib/irb/extend-command.rb +92 -34
  22. data/lib/irb/frame.rb +18 -5
  23. data/lib/irb/help.rb +20 -19
  24. data/lib/irb/init.rb +156 -104
  25. data/lib/irb/input-method.rb +96 -23
  26. data/lib/irb/inspector.rb +145 -0
  27. data/lib/irb/lc/.document +4 -0
  28. data/lib/irb/lc/error.rb +8 -7
  29. data/lib/irb/lc/{help-message.rb → help-message} +14 -11
  30. data/lib/irb/lc/ja/encoding_aliases.rb +10 -0
  31. data/lib/irb/lc/ja/error.rb +19 -16
  32. data/lib/irb/lc/ja/help-message +33 -28
  33. data/lib/irb/locale.rb +83 -85
  34. data/lib/irb/magic-file.rb +37 -0
  35. data/lib/irb/notifier.rb +101 -15
  36. data/lib/irb/output-method.rb +38 -32
  37. data/lib/irb/ruby-lex.rb +143 -81
  38. data/lib/irb/ruby-token.rb +13 -19
  39. data/lib/irb/slex.rb +26 -27
  40. data/lib/irb/src_encoding.rb +4 -0
  41. data/lib/irb/version.rb +6 -7
  42. data/lib/irb/workspace.rb +22 -15
  43. data/lib/irb/ws-for-case-2.rb +5 -6
  44. data/lib/irb/xmp.rb +91 -4
  45. data/lib/rubysl/irb/irb.rb +523 -175
  46. data/lib/rubysl/irb/version.rb +1 -1
  47. data/rubysl-irb.gemspec +7 -6
  48. metadata +35 -15
@@ -1,13 +1,12 @@
1
1
  #
2
- # irb/lib/tracer.rb -
3
- # $Release Version: 0.9.5$
4
- # $Revision: 11708 $
5
- # $Date: 2007-02-12 15:01:19 -0800 (Mon, 12 Feb 2007) $
2
+ # irb/lib/tracer.rb -
3
+ # $Release Version: 0.9.6$
4
+ # $Revision$
6
5
  # by Keiju ISHITSUKA(keiju@ruby-lang.org)
7
6
  #
8
7
  # --
9
8
  #
10
- #
9
+ #
11
10
  #
12
11
  require "tracer"
13
12
 
@@ -24,9 +23,16 @@ module IRB
24
23
  end
25
24
 
26
25
  class Context
26
+ # Whether Tracer is used when evaluating statements in this context.
27
+ #
28
+ # See +lib/tracer.rb+ for more information.
27
29
  attr_reader :use_tracer
28
30
  alias use_tracer? use_tracer
29
31
 
32
+ # Sets whether or not to use the Tracer library when evaluating statements
33
+ # in this context.
34
+ #
35
+ # See +lib/tracer.rb+ for more information.
30
36
  def use_tracer=(opt)
31
37
  if opt
32
38
  Tracer.set_get_line_procs(@irb_path) {
@@ -42,9 +48,13 @@ module IRB
42
48
 
43
49
  class WorkSpace
44
50
  alias __evaluate__ evaluate
51
+ # Evaluate the context of this workspace and use the Tracer library to
52
+ # output the exact lines of code are being executed in chronological order.
53
+ #
54
+ # See +lib/tracer.rb+ for more information.
45
55
  def evaluate(context, statements, file = nil, line = nil)
46
56
  if context.use_tracer? && file != nil && line != nil
47
- Tracer.on
57
+ Tracer.on
48
58
  begin
49
59
  __evaluate__(context, statements, file, line)
50
60
  ensure
@@ -58,4 +68,4 @@ module IRB
58
68
 
59
69
  IRB.initialize_tracer
60
70
  end
61
-
71
+
@@ -1,13 +1,12 @@
1
1
  #
2
- # use-loader.rb -
3
- # $Release Version: 0.9.5$
4
- # $Revision: 11708 $
5
- # $Date: 2007-02-12 15:01:19 -0800 (Mon, 12 Feb 2007) $
2
+ # use-loader.rb -
3
+ # $Release Version: 0.9.6$
4
+ # $Revision$
6
5
  # by Keiju ISHITSUKA(keiju@ruby-lang.org)
7
6
  #
8
7
  # --
9
8
  #
10
- #
9
+ #
11
10
  #
12
11
 
13
12
  require "irb/cmd/load"
@@ -20,9 +19,11 @@ end
20
19
 
21
20
  module IRB
22
21
  module ExtendCommandBundle
22
+ # Loads the given file similarly to Kernel#load, see IrbLoader#irb_load
23
23
  def irb_load(*opts, &b)
24
24
  ExtendCommand::Load.execute(irb_context, *opts, &b)
25
25
  end
26
+ # Loads the given file similarly to Kernel#require
26
27
  def irb_require(*opts, &b)
27
28
  ExtendCommand::Require.execute(irb_context, *opts, &b)
28
29
  end
@@ -31,13 +32,20 @@ module IRB
31
32
  class Context
32
33
 
33
34
  IRB.conf[:USE_LOADER] = false
34
-
35
+
36
+ # Returns whether +irb+'s own file reader method is used by
37
+ # +load+/+require+ or not.
38
+ #
39
+ # This mode is globally affected (irb-wide).
35
40
  def use_loader
36
41
  IRB.conf[:USE_LOADER]
37
42
  end
38
43
 
39
44
  alias use_loader? use_loader
40
45
 
46
+ # Sets IRB.conf[:USE_LOADER]
47
+ #
48
+ # See #use_loader for more information.
41
49
  def use_loader=(opt)
42
50
 
43
51
  if IRB.conf[:USE_LOADER] != opt
@@ -1,22 +1,23 @@
1
1
  #
2
- # push-ws.rb -
3
- # $Release Version: 0.9.5$
4
- # $Revision: 11708 $
5
- # $Date: 2007-02-12 15:01:19 -0800 (Mon, 12 Feb 2007) $
2
+ # push-ws.rb -
3
+ # $Release Version: 0.9.6$
4
+ # $Revision$
6
5
  # by Keiju ISHITSUKA(keiju@ruby-lang.org)
7
6
  #
8
7
  # --
9
8
  #
10
- #
9
+ #
11
10
  #
12
11
 
13
- module IRB
12
+ module IRB # :nodoc:
14
13
  class Context
15
14
 
15
+ # Size of the current WorkSpace stack
16
16
  def irb_level
17
17
  workspace_stack.size
18
18
  end
19
19
 
20
+ # WorkSpaces in the current stack
20
21
  def workspaces
21
22
  if defined? @workspaces
22
23
  @workspaces
@@ -25,6 +26,11 @@ module IRB
25
26
  end
26
27
  end
27
28
 
29
+ # Creates a new workspace with the given object or binding, and appends it
30
+ # onto the current #workspaces stack.
31
+ #
32
+ # See IRB::Context#change_workspace and IRB::WorkSpace.new for more
33
+ # information.
28
34
  def push_workspace(*_main)
29
35
  if _main.empty?
30
36
  if workspaces.empty?
@@ -44,6 +50,10 @@ module IRB
44
50
  end
45
51
  end
46
52
 
53
+ # Removes the last element from the current #workspaces stack and returns
54
+ # it, or +nil+ if the current workspace stack is empty.
55
+ #
56
+ # Also, see #push_workspace.
47
57
  def pop_workspace
48
58
  if workspaces.empty?
49
59
  print "workspace stack empty\n"
@@ -1,29 +1,37 @@
1
1
  #
2
- # irb/extend-command.rb - irb extend command
3
- # $Release Version: 0.9.5$
4
- # $Revision: 11708 $
5
- # $Date: 2007-02-12 15:01:19 -0800 (Mon, 12 Feb 2007) $
2
+ # irb/extend-command.rb - irb extend command
3
+ # $Release Version: 0.9.6$
4
+ # $Revision$
6
5
  # by Keiju ISHITSUKA(keiju@ruby-lang.org)
7
6
  #
8
7
  # --
9
8
  #
10
- #
11
9
  #
12
- module IRB
13
- #
14
- # IRB extended command
15
- #
10
+ #
11
+ module IRB # :nodoc:
12
+ # Installs the default irb extensions command bundle.
16
13
  module ExtendCommandBundle
17
- EXCB = ExtendCommandBundle
14
+ EXCB = ExtendCommandBundle # :nodoc:
18
15
 
16
+ # See #install_alias_method.
19
17
  NO_OVERRIDE = 0
18
+ # See #install_alias_method.
20
19
  OVERRIDE_PRIVATE_ONLY = 0x01
20
+ # See #install_alias_method.
21
21
  OVERRIDE_ALL = 0x02
22
22
 
23
+ # Quits the current irb context
24
+ #
25
+ # +ret+ is the optional signal or message to send to Context#exit
26
+ #
27
+ # Same as <code>IRB.CurrentContext.exit</code>.
23
28
  def irb_exit(ret = 0)
24
29
  irb_context.exit(ret)
25
30
  end
26
31
 
32
+ # Displays current configuration.
33
+ #
34
+ # Modifing the configuration is achieved by sending a message to IRB.conf.
27
35
  def irb_context
28
36
  IRB.CurrentContext
29
37
  end
@@ -90,15 +98,15 @@ module IRB
90
98
 
91
99
  [:irb_load, :Load, "irb/cmd/load"],
92
100
  [:irb_require, :Require, "irb/cmd/load"],
93
- [:irb_source, :Source, "irb/cmd/load",
101
+ [:irb_source, :Source, "irb/cmd/load",
94
102
  [:source, NO_OVERRIDE]],
95
103
 
96
104
  [:irb, :IrbCommand, "irb/cmd/subirb"],
97
- [:irb_jobs, :Jobs, "irb/cmd/subirb",
105
+ [:irb_jobs, :Jobs, "irb/cmd/subirb",
98
106
  [:jobs, NO_OVERRIDE]],
99
- [:irb_fg, :Foreground, "irb/cmd/subirb",
107
+ [:irb_fg, :Foreground, "irb/cmd/subirb",
100
108
  [:fg, NO_OVERRIDE]],
101
- [:irb_kill, :Kill, "irb/cmd/subirb",
109
+ [:irb_kill, :Kill, "irb/cmd/subirb",
102
110
  [:kill, OVERRIDE_PRIVATE_ONLY]],
103
111
 
104
112
  [:irb_help, :Help, "irb/cmd/help",
@@ -106,13 +114,33 @@ module IRB
106
114
 
107
115
  ]
108
116
 
117
+ # Installs the default irb commands:
118
+ #
119
+ # +irb_current_working_workspace+:: Context#main
120
+ # +irb_change_workspace+:: Context#change_workspace
121
+ # +irb_workspaces+:: Context#workspaces
122
+ # +irb_push_workspace+:: Context#push_workspace
123
+ # +irb_pop_workspace+:: Context#pop_workspace
124
+ # +irb_load+:: #irb_load
125
+ # +irb_require+:: #irb_require
126
+ # +irb_source+:: IrbLoader#source_file
127
+ # +irb+:: IRB.irb
128
+ # +irb_jobs+:: JobManager
129
+ # +irb_fg+:: JobManager#switch
130
+ # +irb_kill+:: JobManager#kill
131
+ # +irb_help+:: IRB@Command+line+options
109
132
  def self.install_extend_commands
110
133
  for args in @EXTEND_COMMANDS
111
134
  def_extend_command(*args)
112
135
  end
113
136
  end
114
137
 
115
- # aliases = [commans_alias, flag], ...
138
+ # Evaluate the given +cmd_name+ on the given +cmd_class+ Class.
139
+ #
140
+ # Will also define any given +aliases+ for the method.
141
+ #
142
+ # The optional +load_file+ parameter will be required within the method
143
+ # definition.
116
144
  def self.def_extend_command(cmd_name, cmd_class, load_file = nil, *aliases)
117
145
  case cmd_class
118
146
  when Symbol
@@ -123,23 +151,28 @@ module IRB
123
151
  end
124
152
 
125
153
  if load_file
126
- eval %[
154
+ line = __LINE__; eval %[
127
155
  def #{cmd_name}(*opts, &b)
128
156
  require "#{load_file}"
129
- eval %[
130
- def #{cmd_name}(*opts, &b)
131
- ExtendCommand::#{cmd_class}.execute(irb_context, *opts, &b)
157
+ arity = ExtendCommand::#{cmd_class}.instance_method(:execute).arity
158
+ args = (1..(arity < 0 ? ~arity : arity)).map {|i| "arg" + i.to_s }
159
+ args << "*opts" if arity < 0
160
+ args << "&block"
161
+ args = args.join(", ")
162
+ line = __LINE__; eval %[
163
+ def #{cmd_name}(\#{args})
164
+ ExtendCommand::#{cmd_class}.execute(irb_context, \#{args})
132
165
  end
133
- ]
166
+ ], nil, __FILE__, line
134
167
  send :#{cmd_name}, *opts, &b
135
168
  end
136
- ]
169
+ ], nil, __FILE__, line
137
170
  else
138
- eval %[
171
+ line = __LINE__; eval %[
139
172
  def #{cmd_name}(*opts, &b)
140
173
  ExtendCommand::#{cmd_class}.execute(irb_context, *opts, &b)
141
174
  end
142
- ]
175
+ ], nil, __FILE__, line
143
176
  end
144
177
 
145
178
  for ali, flag in aliases
@@ -147,7 +180,8 @@ module IRB
147
180
  end
148
181
  end
149
182
 
150
- # override = {NO_OVERRIDE, OVERRIDE_PRIVATE_ONLY, OVERRIDE_ALL}
183
+ # Installs alias methods for the default irb commands, see
184
+ # ::install_extend_commands.
151
185
  def install_alias_method(to, from, override = NO_OVERRIDE)
152
186
  to = to.id2name unless to.kind_of?(String)
153
187
  from = from.id2name unless from.kind_of?(String)
@@ -156,10 +190,10 @@ module IRB
156
190
  (override == OVERRIDE_PRIVATE_ONLY) && !respond_to?(to) or
157
191
  (override == NO_OVERRIDE) && !respond_to?(to, true)
158
192
  target = self
159
- (class<<self;self;end).instance_eval{
160
- if target.respond_to?(to, true) &&
193
+ (class << self; self; end).instance_eval{
194
+ if target.respond_to?(to, true) &&
161
195
  !target.respond_to?(EXCB.irb_original_method_name(to), true)
162
- alias_method(EXCB.irb_original_method_name(to), to)
196
+ alias_method(EXCB.irb_original_method_name(to), to)
163
197
  end
164
198
  alias_method to, from
165
199
  }
@@ -168,12 +202,14 @@ module IRB
168
202
  end
169
203
  end
170
204
 
171
- def self.irb_original_method_name(method_name)
205
+ def self.irb_original_method_name(method_name) # :nodoc:
172
206
  "irb_" + method_name + "_org"
173
207
  end
174
208
 
209
+ # Installs alias methods for the default irb commands on the given object
210
+ # using #install_alias_method.
175
211
  def self.extend_object(obj)
176
- unless (class<<obj;ancestors;end).include?(EXCB)
212
+ unless (class << obj; ancestors; end).include?(EXCB)
177
213
  super
178
214
  for ali, com, flg in @ALIASES
179
215
  obj.install_alias_method(ali, com, flg)
@@ -184,9 +220,9 @@ module IRB
184
220
  install_extend_commands
185
221
  end
186
222
 
187
- # extension support for Context
223
+ # Extends methods for the Context module
188
224
  module ContextExtender
189
- CE = ContextExtender
225
+ CE = ContextExtender # :nodoc:
190
226
 
191
227
  @EXTEND_COMMANDS = [
192
228
  [:eval_history=, "irb/ext/history.rb"],
@@ -196,14 +232,25 @@ module IRB
196
232
  [:save_history=, "irb/ext/save-history.rb"],
197
233
  ]
198
234
 
235
+ # Installs the default context extensions as irb commands:
236
+ #
237
+ # Context#eval_history=:: +irb/ext/history.rb+
238
+ # Context#use_tracer=:: +irb/ext/tracer.rb+
239
+ # Context#math_mode=:: +irb/ext/math-mode.rb+
240
+ # Context#use_loader=:: +irb/ext/use-loader.rb+
241
+ # Context#save_history=:: +irb/ext/save-history.rb+
199
242
  def self.install_extend_commands
200
243
  for args in @EXTEND_COMMANDS
201
244
  def_extend_command(*args)
202
245
  end
203
246
  end
204
247
 
248
+ # Evaluate the given +command+ from the given +load_file+ on the Context
249
+ # module.
250
+ #
251
+ # Will also define any given +aliases+ for the method.
205
252
  def self.def_extend_command(cmd_name, load_file, *aliases)
206
- Context.module_eval %[
253
+ line = __LINE__; Context.module_eval %[
207
254
  def #{cmd_name}(*opts, &b)
208
255
  Context.module_eval {remove_method(:#{cmd_name})}
209
256
  require "#{load_file}"
@@ -212,13 +259,16 @@ module IRB
212
259
  for ali in aliases
213
260
  alias_method ali, cmd_name
214
261
  end
215
- ]
262
+ ], __FILE__, line
216
263
  end
217
264
 
218
265
  CE.install_extend_commands
219
266
  end
220
267
 
268
+ # A convenience module for extending Ruby methods.
221
269
  module MethodExtender
270
+ # Extends the given +base_method+ with a prefix call to the given
271
+ # +extend_method+.
222
272
  def def_pre_proc(base_method, extend_method)
223
273
  base_method = base_method.to_s
224
274
  extend_method = extend_method.to_s
@@ -233,6 +283,8 @@ module IRB
233
283
  ]
234
284
  end
235
285
 
286
+ # Extends the given +base_method+ with a postfix call to the given
287
+ # +extend_method+.
236
288
  def def_post_proc(base_method, extend_method)
237
289
  base_method = base_method.to_s
238
290
  extend_method = extend_method.to_s
@@ -247,7 +299,13 @@ module IRB
247
299
  ]
248
300
  end
249
301
 
250
- # return #{prefix}#{name}#{postfix}<num>
302
+ # Returns a unique method name to use as an alias for the given +name+.
303
+ #
304
+ # Usually returns <code>#{prefix}#{name}#{postfix}<num></code>, example:
305
+ #
306
+ # new_alias_name('foo') #=> __alias_of__foo__
307
+ # def bar; end
308
+ # new_alias_name('bar') #=> __alias_of__bar__2
251
309
  def new_alias_name(name, prefix = "__alias_of__", postfix = "__")
252
310
  base_name = "#{prefix}#{name}#{postfix}"
253
311
  all_methods = instance_methods(true) + private_instance_methods(true)
data/lib/irb/frame.rb CHANGED
@@ -1,13 +1,12 @@
1
1
  #
2
- # frame.rb -
2
+ # frame.rb -
3
3
  # $Release Version: 0.9$
4
- # $Revision: 11708 $
5
- # $Date: 2007-02-12 15:01:19 -0800 (Mon, 12 Feb 2007) $
4
+ # $Revision$
6
5
  # by Keiju ISHITSUKA(Nihon Rational Software Co.,Ltd)
7
6
  #
8
7
  # --
9
8
  #
10
- #
9
+ #
11
10
  #
12
11
 
13
12
  require "e2mmap"
@@ -18,13 +17,17 @@ module IRB
18
17
  def_exception :FrameOverflow, "frame overflow"
19
18
  def_exception :FrameUnderflow, "frame underflow"
20
19
 
20
+ # Default number of stack frames
21
21
  INIT_STACK_TIMES = 3
22
+ # Default number of frames offset
22
23
  CALL_STACK_OFFSET = 3
23
24
 
25
+ # Creates a new stack frame
24
26
  def initialize
25
27
  @frames = [TOPLEVEL_BINDING] * INIT_STACK_TIMES
26
28
  end
27
29
 
30
+ # Used by Kernel#set_trace_func to register each event in the call stack
28
31
  def trace_func(event, file, line, id, binding)
29
32
  case event
30
33
  when 'call', 'class'
@@ -34,27 +37,37 @@ module IRB
34
37
  end
35
38
  end
36
39
 
40
+ # Returns the +n+ number of frames on the call stack from the last frame
41
+ # initialized.
42
+ #
43
+ # Raises FrameUnderflow if there are no frames in the given stack range.
37
44
  def top(n = 0)
38
45
  bind = @frames[-(n + CALL_STACK_OFFSET)]
39
46
  Fail FrameUnderflow unless bind
40
47
  bind
41
48
  end
42
49
 
50
+ # Returns the +n+ number of frames on the call stack from the first frame
51
+ # initialized.
52
+ #
53
+ # Raises FrameOverflow if there are no frames in the given stack range.
43
54
  def bottom(n = 0)
44
55
  bind = @frames[n]
45
56
  Fail FrameOverflow unless bind
46
57
  bind
47
58
  end
48
59
 
49
- # singleton functions
60
+ # Convenience method for Frame#bottom
50
61
  def Frame.bottom(n = 0)
51
62
  @backtrace.bottom(n)
52
63
  end
53
64
 
65
+ # Convenience method for Frame#top
54
66
  def Frame.top(n = 0)
55
67
  @backtrace.top(n)
56
68
  end
57
69
 
70
+ # Returns the binding context of the caller from the last frame initialized
58
71
  def Frame.sender
59
72
  eval "self", @backtrace.top
60
73
  end