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
data/lib/irb/context.rb CHANGED
@@ -1,24 +1,27 @@
1
1
  #
2
2
  # irb/context.rb - irb context
3
- # $Release Version: 0.9.5$
4
- # $Revision: 11708 $
5
- # $Date: 2007-02-12 15:01:19 -0800 (Mon, 12 Feb 2007) $
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 "irb/workspace"
12
+ require "irb/inspector"
13
13
 
14
14
  module IRB
15
+ # A class that wraps the current state of the irb session, including the
16
+ # configuration of IRB.conf.
15
17
  class Context
18
+ # Creates a new IRB context.
16
19
  #
17
- # Arguments:
18
- # input_method: nil -- stdin or readline
19
- # String -- File
20
- # other -- using this as InputMethod
20
+ # The optional +input_method+ argument:
21
21
  #
22
+ # +nil+:: uses stdin or Readline
23
+ # +String+:: uses a File
24
+ # +other+:: uses this as InputMethod
22
25
  def initialize(irb, workspace = nil, input_method = nil, output_method = nil)
23
26
  @irb = irb
24
27
  if workspace
@@ -35,8 +38,10 @@ module IRB
35
38
  @load_modules = IRB.conf[:LOAD_MODULES]
36
39
 
37
40
  @use_readline = IRB.conf[:USE_READLINE]
38
- @inspect_mode = IRB.conf[:INSPECT_MODE]
41
+ @verbose = IRB.conf[:VERBOSE]
42
+ @io = nil
39
43
 
44
+ self.inspect_mode = IRB.conf[:INSPECT_MODE]
40
45
  self.math_mode = IRB.conf[:MATH_MODE] if IRB.conf[:MATH_MODE]
41
46
  self.use_tracer = IRB.conf[:USE_TRACER] if IRB.conf[:USE_TRACER]
42
47
  self.use_loader = IRB.conf[:USE_LOADER] if IRB.conf[:USE_LOADER]
@@ -46,13 +51,13 @@ module IRB
46
51
  @ignore_eof = IRB.conf[:IGNORE_EOF]
47
52
 
48
53
  @back_trace_limit = IRB.conf[:BACK_TRACE_LIMIT]
49
-
54
+
50
55
  self.prompt_mode = IRB.conf[:PROMPT_MODE]
51
56
 
52
- if IRB.conf[:SINGLE_IRB] or !defined?(JobManager)
57
+ if IRB.conf[:SINGLE_IRB] or !defined?(IRB::JobManager)
53
58
  @irb_name = IRB.conf[:IRB_NAME]
54
59
  else
55
- @irb_name = "irb#"+IRB.JobManager.n_jobs.to_s
60
+ @irb_name = IRB.conf[:IRB_NAME]+"#"+IRB.JobManager.n_jobs.to_s
56
61
  end
57
62
  @irb_path = "(" + @irb_name + ")"
58
63
 
@@ -91,81 +96,177 @@ module IRB
91
96
  @output_method = StdioOutputMethod.new
92
97
  end
93
98
 
94
- @verbose = IRB.conf[:VERBOSE]
95
99
  @echo = IRB.conf[:ECHO]
96
100
  if @echo.nil?
97
101
  @echo = true
98
102
  end
99
- @debug_level = IRB.conf[:DEBUG_LEVEL]
103
+ self.debug_level = IRB.conf[:DEBUG_LEVEL]
100
104
  end
101
105
 
106
+ # The top-level workspace, see WorkSpace#main
102
107
  def main
103
108
  @workspace.main
104
109
  end
105
110
 
111
+ # The toplevel workspace, see #home_workspace
106
112
  attr_reader :workspace_home
113
+ # WorkSpace in the current context
107
114
  attr_accessor :workspace
115
+ # The current thread in this context
108
116
  attr_reader :thread
117
+ # The current input method
118
+ #
119
+ # Can be either StdioInputMethod, ReadlineInputMethod, FileInputMethod or
120
+ # other specified when the context is created. See ::new for more
121
+ # information on +input_method+.
109
122
  attr_accessor :io
110
-
123
+
124
+ # Current irb session
111
125
  attr_accessor :irb
126
+ # A copy of the default <code>IRB.conf[:AP_NAME]</code>
112
127
  attr_accessor :ap_name
128
+ # A copy of the default <code>IRB.conf[:RC]</code>
113
129
  attr_accessor :rc
130
+ # A copy of the default <code>IRB.conf[:LOAD_MODULES]</code>
114
131
  attr_accessor :load_modules
132
+ # Can be either name from <code>IRB.conf[:IRB_NAME]</code>, or the number of
133
+ # the current job set by JobManager, such as <code>irb#2</code>
115
134
  attr_accessor :irb_name
135
+ # Can be either the #irb_name surrounded by parenthesis, or the
136
+ # +input_method+ passed to Context.new
116
137
  attr_accessor :irb_path
117
138
 
139
+ # Whether +Readline+ is enabled or not.
140
+ #
141
+ # A copy of the default <code>IRB.conf[:USE_READLINE]</code>
142
+ #
143
+ # See #use_readline= for more information.
118
144
  attr_reader :use_readline
145
+ # A copy of the default <code>IRB.conf[:INSPECT_MODE]</code>
119
146
  attr_reader :inspect_mode
120
147
 
148
+ # A copy of the default <code>IRB.conf[:PROMPT_MODE]</code>
121
149
  attr_reader :prompt_mode
150
+ # Standard IRB prompt
151
+ #
152
+ # See IRB@Customizing+the+IRB+Prompt for more information.
122
153
  attr_accessor :prompt_i
154
+ # IRB prompt for continuated strings
155
+ #
156
+ # See IRB@Customizing+the+IRB+Prompt for more information.
123
157
  attr_accessor :prompt_s
158
+ # IRB prompt for continuated statement (e.g. immediately after an +if+)
159
+ #
160
+ # See IRB@Customizing+the+IRB+Prompt for more information.
124
161
  attr_accessor :prompt_c
162
+ # See IRB@Customizing+the+IRB+Prompt for more information.
125
163
  attr_accessor :prompt_n
164
+ # Can be either the default <code>IRB.conf[:AUTO_INDENT]</code>, or the
165
+ # mode set by #prompt_mode=
166
+ #
167
+ # To enable auto-indentation in irb:
168
+ #
169
+ # IRB.conf[:AUTO_INDENT] = true
170
+ #
171
+ # or
172
+ #
173
+ # irb_context.auto_indent_mode = true
174
+ #
175
+ # or
176
+ #
177
+ # IRB.CurrentContext.auto_indent_mode = true
178
+ #
179
+ # See IRB@Configuration for more information.
126
180
  attr_accessor :auto_indent_mode
181
+ # The format of the return statement, set by #prompt_mode= using the
182
+ # +:RETURN+ of the +mode+ passed to set the current #prompt_mode.
127
183
  attr_accessor :return_format
128
184
 
185
+ # Whether <code>^C</code> (+control-c+) will be ignored or not.
186
+ #
187
+ # If set to +false+, <code>^C</code> will quit irb.
188
+ #
189
+ # If set to +true+,
190
+ #
191
+ # * during input: cancel input then return to top level.
192
+ # * during execute: abandon current execution.
129
193
  attr_accessor :ignore_sigint
194
+ # Whether <code>^D</code> (+control-d+) will be ignored or not.
195
+ #
196
+ # If set to +false+, <code>^D</code> will quit irb.
130
197
  attr_accessor :ignore_eof
198
+ # Whether to echo the return value to output or not.
199
+ #
200
+ # Uses IRB.conf[:ECHO] if available, or defaults to +true+.
201
+ #
202
+ # puts "hello"
203
+ # # hello
204
+ # #=> nil
205
+ # IRB.CurrentContext.echo = false
206
+ # puts "omg"
207
+ # # omg
131
208
  attr_accessor :echo
209
+ # Whether verbose messages are displayed or not.
210
+ #
211
+ # A copy of the default <code>IRB.conf[:VERBOSE]</code>
132
212
  attr_accessor :verbose
213
+ # The debug level of irb
214
+ #
215
+ # See #debug_level= for more information.
133
216
  attr_reader :debug_level
134
217
 
218
+ # The limit of backtrace lines displayed as top +n+ and tail +n+.
219
+ #
220
+ # The default value is 16.
221
+ #
222
+ # Can also be set using the +--back-trace-limit+ command line option.
223
+ #
224
+ # See IRB@Command+line+options for more command line options.
135
225
  attr_accessor :back_trace_limit
136
226
 
227
+ # Alias for #use_readline
137
228
  alias use_readline? use_readline
229
+ # Alias for #rc
138
230
  alias rc? rc
139
231
  alias ignore_sigint? ignore_sigint
140
232
  alias ignore_eof? ignore_eof
141
233
  alias echo? echo
142
234
 
235
+ # Returns whether messages are displayed or not.
143
236
  def verbose?
144
237
  if @verbose.nil?
145
- if defined?(ReadlineInputMethod) && @io.kind_of?(ReadlineInputMethod)
238
+ if defined?(ReadlineInputMethod) && @io.kind_of?(ReadlineInputMethod)
146
239
  false
147
240
  elsif !STDIN.tty? or @io.kind_of?(FileInputMethod)
148
241
  true
149
242
  else
150
243
  false
151
244
  end
245
+ else
246
+ @verbose
152
247
  end
153
248
  end
154
249
 
250
+ # Whether #verbose? is +true+, and +input_method+ is either
251
+ # StdioInputMethod or ReadlineInputMethod, see #io for more information.
155
252
  def prompting?
156
253
  verbose? || (STDIN.tty? && @io.kind_of?(StdioInputMethod) ||
157
254
  (defined?(ReadlineInputMethod) && @io.kind_of?(ReadlineInputMethod)))
158
255
  end
159
256
 
257
+ # The return value of the last statement evaluated.
160
258
  attr_reader :last_value
161
259
 
260
+ # Sets the return value from the last statement evaluated in this context
261
+ # to #last_value.
162
262
  def set_last_value(value)
163
263
  @last_value = value
164
264
  @workspace.evaluate self, "_ = IRB.CurrentContext.last_value"
165
265
  end
166
266
 
167
- attr_reader :irb_name
168
-
267
+ # Sets the +mode+ of the prompt in this context.
268
+ #
269
+ # See IRB@Customizing+the+IRB+Prompt for more information.
169
270
  def prompt_mode=(mode)
170
271
  @prompt_mode = mode
171
272
  pconf = IRB.conf[:PROMPT][mode]
@@ -180,61 +281,127 @@ module IRB
180
281
  @auto_indent_mode = IRB.conf[:AUTO_INDENT]
181
282
  end
182
283
  end
183
-
284
+
285
+ # Whether #inspect_mode is set or not, see #inspect_mode= for more detail.
184
286
  def inspect?
185
287
  @inspect_mode.nil? or @inspect_mode
186
288
  end
187
289
 
290
+ # Whether #io uses a File for the +input_method+ passed when creating the
291
+ # current context, see ::new
188
292
  def file_input?
189
293
  @io.class == FileInputMethod
190
294
  end
191
295
 
296
+ # Specifies the inspect mode with +opt+:
297
+ #
298
+ # +true+:: display +inspect+
299
+ # +false+:: display +to_s+
300
+ # +nil+:: inspect mode in non-math mode,
301
+ # non-inspect mode in math mode
302
+ #
303
+ # See IRB::Inspector for more information.
304
+ #
305
+ # Can also be set using the +--inspect+ and +--noinspect+ command line
306
+ # options.
307
+ #
308
+ # See IRB@Command+line+options for more command line options.
192
309
  def inspect_mode=(opt)
193
- if opt
310
+
311
+ if i = Inspector::INSPECTORS[opt]
194
312
  @inspect_mode = opt
313
+ @inspect_method = i
314
+ i.init
195
315
  else
196
- @inspect_mode = !@inspect_mode
316
+ case opt
317
+ when nil
318
+ if Inspector.keys_with_inspector(Inspector::INSPECTORS[true]).include?(@inspect_mode)
319
+ self.inspect_mode = false
320
+ elsif Inspector.keys_with_inspector(Inspector::INSPECTORS[false]).include?(@inspect_mode)
321
+ self.inspect_mode = true
322
+ else
323
+ puts "Can't switch inspect mode."
324
+ return
325
+ end
326
+ when /^\s*\{.*\}\s*$/
327
+ begin
328
+ inspector = eval "proc#{opt}"
329
+ rescue Exception
330
+ puts "Can't switch inspect mode(#{opt})."
331
+ return
332
+ end
333
+ self.inspect_mode = inspector
334
+ when Proc
335
+ self.inspect_mode = IRB::Inspector(opt)
336
+ when Inspector
337
+ prefix = "usr%d"
338
+ i = 1
339
+ while Inspector::INSPECTORS[format(prefix, i)]; i += 1; end
340
+ @inspect_mode = format(prefix, i)
341
+ @inspect_method = opt
342
+ Inspector.def_inspector(format(prefix, i), @inspect_method)
343
+ else
344
+ puts "Can't switch inspect mode(#{opt})."
345
+ return
346
+ end
197
347
  end
198
348
  print "Switch to#{unless @inspect_mode; ' non';end} inspect mode.\n" if verbose?
199
349
  @inspect_mode
200
350
  end
201
351
 
352
+ # Obsolete method.
353
+ #
354
+ # Can be set using the +--noreadline+ and +--readline+ command line
355
+ # options.
356
+ #
357
+ # See IRB@Command+line+options for more command line options.
202
358
  def use_readline=(opt)
203
- @use_readline = opt
204
- print "use readline module\n" if @use_readline
359
+ print "This method is obsolete."
360
+ print "Do nothing."
205
361
  end
206
362
 
363
+ # Sets the debug level of irb
364
+ #
365
+ # Can also be set using the +--irb_debug+ command line option.
366
+ #
367
+ # See IRB@Command+line+options for more command line options.
207
368
  def debug_level=(value)
208
369
  @debug_level = value
209
370
  RubyLex.debug_level = value
210
- SLex.debug_level = value
211
371
  end
212
372
 
373
+ # Whether or not debug mode is enabled, see #debug_level=.
213
374
  def debug?
214
375
  @debug_level > 0
215
376
  end
216
377
 
217
- def evaluate(line, line_no)
378
+ def evaluate(line, line_no) # :nodoc:
218
379
  @line_no = line_no
219
380
  set_last_value(@workspace.evaluate(self, line, irb_path, line_no))
220
381
  # @workspace.evaluate("_ = IRB.conf[:MAIN_CONTEXT]._")
221
382
  # @_ = @workspace.evaluate(line, irb_path, line_no)
222
383
  end
223
384
 
385
+ def inspect_last_value # :nodoc:
386
+ @inspect_method.inspect_value(@last_value)
387
+ end
388
+
224
389
  alias __exit__ exit
390
+ # Exits the current session, see IRB.irb_exit
225
391
  def exit(ret = 0)
226
392
  IRB.irb_exit(@irb, ret)
227
393
  end
228
394
 
229
- NOPRINTING_IVARS = ["@last_value"]
230
- NO_INSPECTING_IVARS = ["@irb", "@io"]
231
- IDNAME_IVARS = ["@prompt_mode"]
395
+ NOPRINTING_IVARS = ["@last_value"] # :nodoc:
396
+ NO_INSPECTING_IVARS = ["@irb", "@io"] # :nodoc:
397
+ IDNAME_IVARS = ["@prompt_mode"] # :nodoc:
232
398
 
233
399
  alias __inspect__ inspect
234
- def inspect
400
+ def inspect # :nodoc:
235
401
  array = []
236
402
  for ivar in instance_variables.sort{|e1, e2| e1 <=> e2}
237
- name = ivar.sub(/^@(.*)$/){$1}
403
+ ivar = ivar.to_s
404
+ name = ivar.sub(/^@(.*)$/, '\1')
238
405
  val = instance_eval(ivar)
239
406
  case ivar
240
407
  when *NOPRINTING_IVARS
@@ -1,18 +1,18 @@
1
1
  #
2
- # irb/ext/cb.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/ext/cb.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
+ # Inherited from +TOPLEVEL_BINDING+.
16
16
  def home_workspace
17
17
  if defined? @home_workspace
18
18
  @home_workspace
@@ -21,14 +21,21 @@ module IRB
21
21
  end
22
22
  end
23
23
 
24
+ # Changes the current workspace to given object or binding.
25
+ #
26
+ # If the optional argument is omitted, the workspace will be
27
+ # #home_workspace which is inherited from +TOPLEVEL_BINDING+ or the main
28
+ # object, <code>IRB.conf[:MAIN_CONTEXT]</code> when irb was initialized.
29
+ #
30
+ # See IRB::WorkSpace.new for more information.
24
31
  def change_workspace(*_main)
25
32
  if _main.empty?
26
- @workspace = home_workspace
33
+ @workspace = home_workspace
27
34
  return main
28
35
  end
29
-
36
+
30
37
  @workspace = WorkSpace.new(_main[0])
31
-
38
+
32
39
  if !(class<<main;ancestors;end).include?(ExtendCommandBundle)
33
40
  main.extend ExtendCommandBundle
34
41
  end
@@ -57,6 +64,6 @@ module IRB
57
64
  # end
58
65
  # end
59
66
  # alias change_workspace change_binding
60
- end
67
+ end
61
68
  end
62
69
 
@@ -1,21 +1,21 @@
1
1
  #
2
- # history.rb -
3
- # $Release Version: 0.9.5$
4
- # $Revision: 11708 $
5
- # $Date: 2007-02-12 15:01:19 -0800 (Mon, 12 Feb 2007) $
2
+ # history.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
 
15
14
  class Context
16
15
 
17
16
  NOPRINTING_IVARS.push "@eval_history_values"
18
17
 
18
+ # See #set_last_value
19
19
  alias _set_last_value set_last_value
20
20
 
21
21
  def set_last_value(value)
@@ -30,7 +30,17 @@ module IRB
30
30
  @last_value
31
31
  end
32
32
 
33
+ # The command result history limit.
33
34
  attr_reader :eval_history
35
+ # Sets command result history limit.
36
+ #
37
+ # +no+ is an Integer or +nil+.
38
+ #
39
+ # Returns +no+ of history items if greater than 0.
40
+ #
41
+ # If +no+ is 0, the number of history items is unlimited.
42
+ #
43
+ # If +no+ is +nil+, execution result history isn't used (default).
34
44
  def eval_history=(no)
35
45
  if no
36
46
  if defined?(@eval_history) && @eval_history
@@ -48,8 +58,8 @@ module IRB
48
58
  end
49
59
  end
50
60
 
51
- class History
52
- @RCS_ID='-$Id: history.rb 11708 2007-02-12 23:01:19Z shyouhei $-'
61
+ class History # :nodoc:
62
+ @RCS_ID='-$Id$-'
53
63
 
54
64
  def initialize(size = 16)
55
65
  @size = size
@@ -57,7 +67,7 @@ module IRB
57
67
  end
58
68
 
59
69
  def size(size)
60
- if size != 0 && size < @size
70
+ if size != 0 && size < @size
61
71
  @contents = @contents[@size - size .. @size]
62
72
  end
63
73
  @size = size
@@ -79,7 +89,7 @@ module IRB
79
89
  @contents.push [no, val]
80
90
  @contents.shift if @size != 0 && @contents.size > @size
81
91
  end
82
-
92
+
83
93
  alias real_inspect inspect
84
94
 
85
95
  def inspect