rubysl-irb 1.0.0

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 (51) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +17 -0
  3. data/.travis.yml +8 -0
  4. data/Gemfile +4 -0
  5. data/LICENSE +25 -0
  6. data/README.md +29 -0
  7. data/Rakefile +1 -0
  8. data/lib/irb/cmd/chws.rb +33 -0
  9. data/lib/irb/cmd/fork.rb +39 -0
  10. data/lib/irb/cmd/help.rb +31 -0
  11. data/lib/irb/cmd/load.rb +67 -0
  12. data/lib/irb/cmd/nop.rb +39 -0
  13. data/lib/irb/cmd/pushws.rb +39 -0
  14. data/lib/irb/cmd/subirb.rb +43 -0
  15. data/lib/irb/completion.rb +205 -0
  16. data/lib/irb/context.rb +255 -0
  17. data/lib/irb/ext/change-ws.rb +62 -0
  18. data/lib/irb/ext/history.rb +110 -0
  19. data/lib/irb/ext/loader.rb +120 -0
  20. data/lib/irb/ext/math-mode.rb +37 -0
  21. data/lib/irb/ext/multi-irb.rb +241 -0
  22. data/lib/irb/ext/save-history.rb +70 -0
  23. data/lib/irb/ext/tracer.rb +61 -0
  24. data/lib/irb/ext/use-loader.rb +65 -0
  25. data/lib/irb/ext/workspaces.rb +56 -0
  26. data/lib/irb/extend-command.rb +264 -0
  27. data/lib/irb/frame.rb +67 -0
  28. data/lib/irb/help.rb +35 -0
  29. data/lib/irb/init.rb +258 -0
  30. data/lib/irb/input-method.rb +120 -0
  31. data/lib/irb/lc/error.rb +30 -0
  32. data/lib/irb/lc/help-message.rb +37 -0
  33. data/lib/irb/lc/ja/error.rb +27 -0
  34. data/lib/irb/lc/ja/help-message +36 -0
  35. data/lib/irb/locale.rb +184 -0
  36. data/lib/irb/notifier.rb +145 -0
  37. data/lib/irb/output-method.rb +85 -0
  38. data/lib/irb/rubinius.rb +55 -0
  39. data/lib/irb/ruby-lex.rb +1149 -0
  40. data/lib/irb/ruby-token.rb +273 -0
  41. data/lib/irb/slex.rb +285 -0
  42. data/lib/irb/version.rb +16 -0
  43. data/lib/irb/workspace.rb +107 -0
  44. data/lib/irb/ws-for-case-2.rb +15 -0
  45. data/lib/irb/xmp.rb +86 -0
  46. data/lib/irb.rb +1 -0
  47. data/lib/rubysl/irb/irb.rb +356 -0
  48. data/lib/rubysl/irb/version.rb +5 -0
  49. data/lib/rubysl/irb.rb +2 -0
  50. data/rubysl-irb.gemspec +31 -0
  51. metadata +219 -0
@@ -0,0 +1,37 @@
1
+ #
2
+ # math-mode.rb -
3
+ # $Release Version: 0.9.5$
4
+ # $Revision: 11708 $
5
+ # $Date: 2007-02-12 15:01:19 -0800 (Mon, 12 Feb 2007) $
6
+ # by Keiju ISHITSUKA(keiju@ruby-lang.org)
7
+ #
8
+ # --
9
+ #
10
+ #
11
+ #
12
+ require "mathn"
13
+
14
+ module IRB
15
+ class Context
16
+ attr_reader :math_mode
17
+ alias math? math_mode
18
+
19
+ def math_mode=(opt)
20
+ if @math_mode == true && opt == false
21
+ IRB.fail CantReturnToNormalMode
22
+ return
23
+ end
24
+
25
+ @math_mode = opt
26
+ if math_mode
27
+ main.extend Math
28
+ print "start math mode\n" if verbose?
29
+ end
30
+ end
31
+
32
+ def inspect?
33
+ @inspect_mode.nil? && !@math_mode or @inspect_mode
34
+ end
35
+ end
36
+ end
37
+
@@ -0,0 +1,241 @@
1
+ #
2
+ # irb/multi-irb.rb - multiple irb module
3
+ # $Release Version: 0.9.5$
4
+ # $Revision: 11708 $
5
+ # $Date: 2007-02-12 15:01:19 -0800 (Mon, 12 Feb 2007) $
6
+ # by Keiju ISHITSUKA(keiju@ruby-lang.org)
7
+ #
8
+ # --
9
+ #
10
+ #
11
+ #
12
+ IRB.fail CantShiftToMultiIrbMode unless defined?(Thread)
13
+ require "thread"
14
+
15
+ module IRB
16
+ # job management class
17
+ class JobManager
18
+ @RCS_ID='-$Id: multi-irb.rb 11708 2007-02-12 23:01:19Z shyouhei $-'
19
+
20
+ def initialize
21
+ # @jobs = [[thread, irb],...]
22
+ @jobs = []
23
+ @current_job = nil
24
+ end
25
+
26
+ attr_accessor :current_job
27
+
28
+ def n_jobs
29
+ @jobs.size
30
+ end
31
+
32
+ def thread(key)
33
+ th, irb = search(key)
34
+ th
35
+ end
36
+
37
+ def irb(key)
38
+ th, irb = search(key)
39
+ irb
40
+ end
41
+
42
+ def main_thread
43
+ @jobs[0][0]
44
+ end
45
+
46
+ def main_irb
47
+ @jobs[0][1]
48
+ end
49
+
50
+ def insert(irb)
51
+ @jobs.push [Thread.current, irb]
52
+ end
53
+
54
+ def switch(key)
55
+ th, irb = search(key)
56
+ IRB.fail IrbAlreadyDead unless th.alive?
57
+ IRB.fail IrbSwitchedToCurrentThread if th == Thread.current
58
+ @current_job = irb
59
+ th.run
60
+ Thread.stop
61
+ @current_job = irb(Thread.current)
62
+ end
63
+
64
+ def kill(*keys)
65
+ for key in keys
66
+ th, irb = search(key)
67
+ IRB.fail IrbAlreadyDead unless th.alive?
68
+ th.exit
69
+ end
70
+ end
71
+
72
+ def search(key)
73
+ case key
74
+ when Integer
75
+ @jobs[key]
76
+ when Irb
77
+ @jobs.find{|k, v| v.equal?(key)}
78
+ when Thread
79
+ @jobs.assoc(key)
80
+ else
81
+ assoc = @jobs.find{|k, v| v.context.main.equal?(key)}
82
+ IRB.fail NoSuchJob, key if assoc.nil?
83
+ assoc
84
+ end
85
+ end
86
+
87
+ def delete(key)
88
+ case key
89
+ when Integer
90
+ IRB.fail NoSuchJob, key unless @jobs[key]
91
+ @jobs[key] = nil
92
+ else
93
+ catch(:EXISTS) do
94
+ @jobs.each_index do
95
+ |i|
96
+ if @jobs[i] and (@jobs[i][0] == key ||
97
+ @jobs[i][1] == key ||
98
+ @jobs[i][1].context.main.equal?(key))
99
+ @jobs[i] = nil
100
+ throw :EXISTS
101
+ end
102
+ end
103
+ IRB.fail NoSuchJob, key
104
+ end
105
+ end
106
+ until assoc = @jobs.pop; end unless @jobs.empty?
107
+ @jobs.push assoc
108
+ end
109
+
110
+ def inspect
111
+ ary = []
112
+ @jobs.each_index do
113
+ |i|
114
+ th, irb = @jobs[i]
115
+ next if th.nil?
116
+
117
+ if th.alive?
118
+ if th.stop?
119
+ t_status = "stop"
120
+ else
121
+ t_status = "running"
122
+ end
123
+ else
124
+ t_status = "exited"
125
+ end
126
+ ary.push format("#%d->%s on %s (%s: %s)",
127
+ i,
128
+ irb.context.irb_name,
129
+ irb.context.main,
130
+ th,
131
+ t_status)
132
+ end
133
+ ary.join("\n")
134
+ end
135
+ end
136
+
137
+ @JobManager = JobManager.new
138
+
139
+ def IRB.JobManager
140
+ @JobManager
141
+ end
142
+
143
+ def IRB.CurrentContext
144
+ IRB.JobManager.irb(Thread.current).context
145
+ end
146
+
147
+ # invoke multi-irb
148
+ def IRB.irb(file = nil, *main)
149
+ workspace = WorkSpace.new(*main)
150
+ parent_thread = Thread.current
151
+ Thread.start do
152
+ begin
153
+ irb = Irb.new(workspace, file)
154
+ rescue
155
+ print "Subirb can't start with context(self): ", workspace.main.inspect, "\n"
156
+ print "return to main irb\n"
157
+ Thread.pass
158
+ Thread.main.wakeup
159
+ Thread.exit
160
+ end
161
+ @CONF[:IRB_RC].call(irb.context) if @CONF[:IRB_RC]
162
+ @JobManager.insert(irb)
163
+ @JobManager.current_job = irb
164
+ begin
165
+ system_exit = false
166
+ catch(:IRB_EXIT) do
167
+ irb.eval_input
168
+ end
169
+ rescue SystemExit
170
+ system_exit = true
171
+ raise
172
+ #fail
173
+ ensure
174
+ unless system_exit
175
+ @JobManager.delete(irb)
176
+ if parent_thread.alive?
177
+ @JobManager.current_job = @JobManager.irb(parent_thread)
178
+ parent_thread.run
179
+ else
180
+ @JobManager.current_job = @JobManager.main_irb
181
+ @JobManager.main_thread.run
182
+ end
183
+ end
184
+ end
185
+ end
186
+ Thread.stop
187
+ @JobManager.current_job = @JobManager.irb(Thread.current)
188
+ end
189
+
190
+ # class Context
191
+ # def set_last_value(value)
192
+ # @last_value = value
193
+ # @workspace.evaluate "_ = IRB.JobManager.irb(Thread.current).context.last_value"
194
+ # if @eval_history #and !@__.equal?(@last_value)
195
+ # @eval_history_values.push @line_no, @last_value
196
+ # @workspace.evaluate "__ = IRB.JobManager.irb(Thread.current).context.instance_eval{@eval_history_values}"
197
+ # end
198
+ # @last_value
199
+ # end
200
+ # end
201
+
202
+ # module ExtendCommand
203
+ # def irb_context
204
+ # IRB.JobManager.irb(Thread.current).context
205
+ # end
206
+ # # alias conf irb_context
207
+ # end
208
+
209
+ @CONF[:SINGLE_IRB_MODE] = false
210
+ @JobManager.insert(@CONF[:MAIN_CONTEXT].irb)
211
+ @JobManager.current_job = @CONF[:MAIN_CONTEXT].irb
212
+
213
+ class Irb
214
+ def signal_handle
215
+ unless @context.ignore_sigint?
216
+ print "\nabort!!\n" if @context.verbose?
217
+ exit
218
+ end
219
+
220
+ case @signal_status
221
+ when :IN_INPUT
222
+ print "^C\n"
223
+ IRB.JobManager.thread(self).raise RubyLex::TerminateLineInput
224
+ when :IN_EVAL
225
+ IRB.irb_abort(self)
226
+ when :IN_LOAD
227
+ IRB.irb_abort(self, LoadAbort)
228
+ when :IN_IRB
229
+ # ignore
230
+ else
231
+ # ignore other cases as well
232
+ end
233
+ end
234
+ end
235
+
236
+ trap("SIGINT") do
237
+ @JobManager.current_job.signal_handle
238
+ Thread.stop
239
+ end
240
+
241
+ end
@@ -0,0 +1,70 @@
1
+ #!/usr/local/bin/ruby
2
+ #
3
+ # save-history.rb -
4
+ # $Release Version: 0.9.5$
5
+ # $Revision: 11708 $
6
+ # $Date: 2007-02-12 15:01:19 -0800 (Mon, 12 Feb 2007) $
7
+ # by Keiju ISHITSUKAkeiju@ruby-lang.org)
8
+ #
9
+ # --
10
+ #
11
+ #
12
+ #
13
+
14
+ require "readline"
15
+
16
+ module IRB
17
+ class Context
18
+ def init_save_history
19
+ hist = IRB.conf[:HISTORY_FILE]
20
+ hist = IRB.rc_file("_history") unless hist
21
+ if File.exist?(hist)
22
+ open(hist) do |f|
23
+ f.each {|l| Readline::HISTORY << l.chomp}
24
+ end
25
+ end
26
+
27
+ at_exit do
28
+ if num = IRB.conf[:SAVE_HISTORY] and (num = num.to_i) > 0
29
+ if hf = IRB.conf[:HISTORY_FILE]
30
+ file = File.expand_path(hf)
31
+ end
32
+ file = IRB.rc_file("_history") unless file
33
+
34
+ open(file, 'w' ) do |f|
35
+ prev_line = nil
36
+ Readline::HISTORY.each do |line|
37
+ unless line == prev_line
38
+ f.puts line
39
+ end
40
+
41
+ prev_line = line
42
+ end
43
+ end
44
+ end
45
+ end
46
+ end
47
+
48
+ def save_history
49
+ IRB.conf[:SAVE_HISTORY]
50
+ end
51
+
52
+ def save_history=(val)
53
+ IRB.conf[:SAVE_HISTORY] = val
54
+ if val
55
+ main_context = IRB.conf[:MAIN_CONTEXT]
56
+ main_context = self unless main_context
57
+ main_context.init_save_history
58
+ end
59
+ end
60
+
61
+ def history_file
62
+ IRB.conf[:HISTORY_FILE]
63
+ end
64
+
65
+ def history_file=(hist)
66
+ IRB.conf[:HISTORY_FILE] = hist
67
+ end
68
+ end
69
+ end
70
+
@@ -0,0 +1,61 @@
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) $
6
+ # by Keiju ISHITSUKA(keiju@ruby-lang.org)
7
+ #
8
+ # --
9
+ #
10
+ #
11
+ #
12
+ require "tracer"
13
+
14
+ module IRB
15
+
16
+ # initialize tracing function
17
+ def IRB.initialize_tracer
18
+ Tracer.verbose = false
19
+ Tracer.add_filter {
20
+ |event, file, line, id, binding, *rests|
21
+ /^#{Regexp.quote(@CONF[:IRB_LIB_PATH])}/ !~ file and
22
+ File::basename(file) != "irb.rb"
23
+ }
24
+ end
25
+
26
+ class Context
27
+ attr_reader :use_tracer
28
+ alias use_tracer? use_tracer
29
+
30
+ def use_tracer=(opt)
31
+ if opt
32
+ Tracer.set_get_line_procs(@irb_path) {
33
+ |line_no, *rests|
34
+ @io.line(line_no)
35
+ }
36
+ elsif !opt && @use_tracer
37
+ Tracer.off
38
+ end
39
+ @use_tracer=opt
40
+ end
41
+ end
42
+
43
+ class WorkSpace
44
+ alias __evaluate__ evaluate
45
+ def evaluate(context, statements, file = nil, line = nil)
46
+ if context.use_tracer? && file != nil && line != nil
47
+ Tracer.on
48
+ begin
49
+ __evaluate__(context, statements, file, line)
50
+ ensure
51
+ Tracer.off
52
+ end
53
+ else
54
+ __evaluate__(context, statements, file || __FILE__, line || __LINE__)
55
+ end
56
+ end
57
+ end
58
+
59
+ IRB.initialize_tracer
60
+ end
61
+
@@ -0,0 +1,65 @@
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) $
6
+ # by Keiju ISHITSUKA(keiju@ruby-lang.org)
7
+ #
8
+ # --
9
+ #
10
+ #
11
+ #
12
+
13
+ require "irb/cmd/load"
14
+ require "irb/ext/loader"
15
+
16
+ class Object
17
+ alias __original__load__IRB_use_loader__ load
18
+ alias __original__require__IRB_use_loader__ require
19
+ end
20
+
21
+ module IRB
22
+ module ExtendCommandBundle
23
+ def irb_load(*opts, &b)
24
+ ExtendCommand::Load.execute(irb_context, *opts, &b)
25
+ end
26
+ def irb_require(*opts, &b)
27
+ ExtendCommand::Require.execute(irb_context, *opts, &b)
28
+ end
29
+ end
30
+
31
+ class Context
32
+
33
+ IRB.conf[:USE_LOADER] = false
34
+
35
+ def use_loader
36
+ IRB.conf[:USE_LOADER]
37
+ end
38
+
39
+ alias use_loader? use_loader
40
+
41
+ def use_loader=(opt)
42
+
43
+ if IRB.conf[:USE_LOADER] != opt
44
+ IRB.conf[:USE_LOADER] = opt
45
+ if opt
46
+ if !$".include?("irb/cmd/load")
47
+ end
48
+ (class<<@workspace.main;self;end).instance_eval {
49
+ alias_method :load, :irb_load
50
+ alias_method :require, :irb_require
51
+ }
52
+ else
53
+ (class<<@workspace.main;self;end).instance_eval {
54
+ alias_method :load, :__original__load__IRB_use_loader__
55
+ alias_method :require, :__original__require__IRB_use_loader__
56
+ }
57
+ end
58
+ end
59
+ print "Switch to load/require#{unless use_loader; ' non';end} trace mode.\n" if verbose?
60
+ opt
61
+ end
62
+ end
63
+ end
64
+
65
+