rubysl-irb 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
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,255 @@
1
+ #
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) $
6
+ # by Keiju ISHITSUKA(keiju@ruby-lang.org)
7
+ #
8
+ # --
9
+ #
10
+ #
11
+ #
12
+ require "irb/workspace"
13
+
14
+ module IRB
15
+ class Context
16
+ #
17
+ # Arguments:
18
+ # input_method: nil -- stdin or readline
19
+ # String -- File
20
+ # other -- using this as InputMethod
21
+ #
22
+ def initialize(irb, workspace = nil, input_method = nil, output_method = nil)
23
+ @irb = irb
24
+ if workspace
25
+ @workspace = workspace
26
+ else
27
+ @workspace = WorkSpace.new
28
+ end
29
+ @thread = Thread.current if defined? Thread
30
+ # @irb_level = 0
31
+
32
+ # copy of default configuration
33
+ @ap_name = IRB.conf[:AP_NAME]
34
+ @rc = IRB.conf[:RC]
35
+ @load_modules = IRB.conf[:LOAD_MODULES]
36
+
37
+ @use_readline = IRB.conf[:USE_READLINE]
38
+ @inspect_mode = IRB.conf[:INSPECT_MODE]
39
+
40
+ self.math_mode = IRB.conf[:MATH_MODE] if IRB.conf[:MATH_MODE]
41
+ self.use_tracer = IRB.conf[:USE_TRACER] if IRB.conf[:USE_TRACER]
42
+ self.use_loader = IRB.conf[:USE_LOADER] if IRB.conf[:USE_LOADER]
43
+ self.eval_history = IRB.conf[:EVAL_HISTORY] if IRB.conf[:EVAL_HISTORY]
44
+
45
+ @ignore_sigint = IRB.conf[:IGNORE_SIGINT]
46
+ @ignore_eof = IRB.conf[:IGNORE_EOF]
47
+
48
+ @back_trace_limit = IRB.conf[:BACK_TRACE_LIMIT]
49
+
50
+ self.prompt_mode = IRB.conf[:PROMPT_MODE]
51
+
52
+ if IRB.conf[:SINGLE_IRB] or !defined?(JobManager)
53
+ @irb_name = IRB.conf[:IRB_NAME]
54
+ else
55
+ @irb_name = "irb#"+IRB.JobManager.n_jobs.to_s
56
+ end
57
+ @irb_path = "(" + @irb_name + ")"
58
+
59
+ case input_method
60
+ when nil
61
+ case use_readline?
62
+ when nil
63
+ if (defined?(ReadlineInputMethod) && STDIN.tty? &&
64
+ IRB.conf[:PROMPT_MODE] != :INF_RUBY)
65
+ @io = ReadlineInputMethod.new
66
+ else
67
+ @io = StdioInputMethod.new
68
+ end
69
+ when false
70
+ @io = StdioInputMethod.new
71
+ when true
72
+ if defined?(ReadlineInputMethod)
73
+ @io = ReadlineInputMethod.new
74
+ else
75
+ @io = StdioInputMethod.new
76
+ end
77
+ end
78
+
79
+ when String
80
+ @io = FileInputMethod.new(input_method)
81
+ @irb_name = File.basename(input_method)
82
+ @irb_path = input_method
83
+ else
84
+ @io = input_method
85
+ end
86
+ self.save_history = IRB.conf[:SAVE_HISTORY] if IRB.conf[:SAVE_HISTORY]
87
+
88
+ if output_method
89
+ @output_method = output_method
90
+ else
91
+ @output_method = StdioOutputMethod.new
92
+ end
93
+
94
+ @verbose = IRB.conf[:VERBOSE]
95
+ @echo = IRB.conf[:ECHO]
96
+ if @echo.nil?
97
+ @echo = true
98
+ end
99
+ @debug_level = IRB.conf[:DEBUG_LEVEL]
100
+ end
101
+
102
+ def main
103
+ @workspace.main
104
+ end
105
+
106
+ attr_reader :workspace_home
107
+ attr_accessor :workspace
108
+ attr_reader :thread
109
+ attr_accessor :io
110
+
111
+ attr_accessor :irb
112
+ attr_accessor :ap_name
113
+ attr_accessor :rc
114
+ attr_accessor :load_modules
115
+ attr_accessor :irb_name
116
+ attr_accessor :irb_path
117
+
118
+ attr_reader :use_readline
119
+ attr_reader :inspect_mode
120
+
121
+ attr_reader :prompt_mode
122
+ attr_accessor :prompt_i
123
+ attr_accessor :prompt_s
124
+ attr_accessor :prompt_c
125
+ attr_accessor :prompt_n
126
+ attr_accessor :auto_indent_mode
127
+ attr_accessor :return_format
128
+
129
+ attr_accessor :ignore_sigint
130
+ attr_accessor :ignore_eof
131
+ attr_accessor :echo
132
+ attr_accessor :verbose
133
+ attr_reader :debug_level
134
+
135
+ attr_accessor :back_trace_limit
136
+
137
+ alias use_readline? use_readline
138
+ alias rc? rc
139
+ alias ignore_sigint? ignore_sigint
140
+ alias ignore_eof? ignore_eof
141
+ alias echo? echo
142
+
143
+ def verbose?
144
+ if @verbose.nil?
145
+ if defined?(ReadlineInputMethod) && @io.kind_of?(ReadlineInputMethod)
146
+ false
147
+ elsif !STDIN.tty? or @io.kind_of?(FileInputMethod)
148
+ true
149
+ else
150
+ false
151
+ end
152
+ end
153
+ end
154
+
155
+ def prompting?
156
+ verbose? || (STDIN.tty? && @io.kind_of?(StdioInputMethod) ||
157
+ (defined?(ReadlineInputMethod) && @io.kind_of?(ReadlineInputMethod)))
158
+ end
159
+
160
+ attr_reader :last_value
161
+
162
+ def set_last_value(value)
163
+ @last_value = value
164
+ @workspace.evaluate self, "_ = IRB.CurrentContext.last_value"
165
+ end
166
+
167
+ attr_reader :irb_name
168
+
169
+ def prompt_mode=(mode)
170
+ @prompt_mode = mode
171
+ pconf = IRB.conf[:PROMPT][mode]
172
+ @prompt_i = pconf[:PROMPT_I]
173
+ @prompt_s = pconf[:PROMPT_S]
174
+ @prompt_c = pconf[:PROMPT_C]
175
+ @prompt_n = pconf[:PROMPT_N]
176
+ @return_format = pconf[:RETURN]
177
+ if ai = pconf.include?(:AUTO_INDENT)
178
+ @auto_indent_mode = ai
179
+ else
180
+ @auto_indent_mode = IRB.conf[:AUTO_INDENT]
181
+ end
182
+ end
183
+
184
+ def inspect?
185
+ @inspect_mode.nil? or @inspect_mode
186
+ end
187
+
188
+ def file_input?
189
+ @io.class == FileInputMethod
190
+ end
191
+
192
+ def inspect_mode=(opt)
193
+ if opt
194
+ @inspect_mode = opt
195
+ else
196
+ @inspect_mode = !@inspect_mode
197
+ end
198
+ print "Switch to#{unless @inspect_mode; ' non';end} inspect mode.\n" if verbose?
199
+ @inspect_mode
200
+ end
201
+
202
+ def use_readline=(opt)
203
+ @use_readline = opt
204
+ print "use readline module\n" if @use_readline
205
+ end
206
+
207
+ def debug_level=(value)
208
+ @debug_level = value
209
+ RubyLex.debug_level = value
210
+ SLex.debug_level = value
211
+ end
212
+
213
+ def debug?
214
+ @debug_level > 0
215
+ end
216
+
217
+ def evaluate(line, line_no)
218
+ @line_no = line_no
219
+ set_last_value(@workspace.evaluate(self, line, irb_path, line_no))
220
+ # @workspace.evaluate("_ = IRB.conf[:MAIN_CONTEXT]._")
221
+ # @_ = @workspace.evaluate(line, irb_path, line_no)
222
+ end
223
+
224
+ alias __exit__ exit
225
+ def exit(ret = 0)
226
+ IRB.irb_exit(@irb, ret)
227
+ end
228
+
229
+ NOPRINTING_IVARS = ["@last_value"]
230
+ NO_INSPECTING_IVARS = ["@irb", "@io"]
231
+ IDNAME_IVARS = ["@prompt_mode"]
232
+
233
+ alias __inspect__ inspect
234
+ def inspect
235
+ array = []
236
+ for ivar in instance_variables.sort{|e1, e2| e1 <=> e2}
237
+ name = ivar.sub(/^@(.*)$/){$1}
238
+ val = instance_eval(ivar)
239
+ case ivar
240
+ when *NOPRINTING_IVARS
241
+ array.push format("conf.%s=%s", name, "...")
242
+ when *NO_INSPECTING_IVARS
243
+ array.push format("conf.%s=%s", name, val.to_s)
244
+ when *IDNAME_IVARS
245
+ array.push format("conf.%s=:%s", name, val.id2name)
246
+ else
247
+ array.push format("conf.%s=%s", name, val.inspect)
248
+ end
249
+ end
250
+ array.join("\n")
251
+ end
252
+ alias __to_s__ to_s
253
+ alias to_s inspect
254
+ end
255
+ end
@@ -0,0 +1,62 @@
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) $
6
+ # by Keiju ISHITSUKA(keiju@ruby-lang.org)
7
+ #
8
+ # --
9
+ #
10
+ #
11
+ #
12
+
13
+ module IRB
14
+ class Context
15
+
16
+ def home_workspace
17
+ if defined? @home_workspace
18
+ @home_workspace
19
+ else
20
+ @home_workspace = @workspace
21
+ end
22
+ end
23
+
24
+ def change_workspace(*_main)
25
+ if _main.empty?
26
+ @workspace = home_workspace
27
+ return main
28
+ end
29
+
30
+ @workspace = WorkSpace.new(_main[0])
31
+
32
+ if !(class<<main;ancestors;end).include?(ExtendCommandBundle)
33
+ main.extend ExtendCommandBundle
34
+ end
35
+ end
36
+
37
+ # def change_binding(*_main)
38
+ # back = @workspace
39
+ # @workspace = WorkSpace.new(*_main)
40
+ # unless _main.empty?
41
+ # begin
42
+ # main.extend ExtendCommandBundle
43
+ # rescue
44
+ # print "can't change binding to: ", main.inspect, "\n"
45
+ # @workspace = back
46
+ # return nil
47
+ # end
48
+ # end
49
+ # @irb_level += 1
50
+ # begin
51
+ # catch(:SU_EXIT) do
52
+ # @irb.eval_input
53
+ # end
54
+ # ensure
55
+ # @irb_level -= 1
56
+ # @workspace = back
57
+ # end
58
+ # end
59
+ # alias change_workspace change_binding
60
+ end
61
+ end
62
+
@@ -0,0 +1,110 @@
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) $
6
+ # by Keiju ISHITSUKA(keiju@ruby-lang.org)
7
+ #
8
+ # --
9
+ #
10
+ #
11
+ #
12
+
13
+ module IRB
14
+
15
+ class Context
16
+
17
+ NOPRINTING_IVARS.push "@eval_history_values"
18
+
19
+ alias _set_last_value set_last_value
20
+
21
+ def set_last_value(value)
22
+ _set_last_value(value)
23
+
24
+ # @workspace.evaluate self, "_ = IRB.CurrentContext.last_value"
25
+ if @eval_history #and !@eval_history_values.equal?(llv)
26
+ @eval_history_values.push @line_no, @last_value
27
+ @workspace.evaluate self, "__ = IRB.CurrentContext.instance_eval{@eval_history_values}"
28
+ end
29
+
30
+ @last_value
31
+ end
32
+
33
+ attr_reader :eval_history
34
+ def eval_history=(no)
35
+ if no
36
+ if defined?(@eval_history) && @eval_history
37
+ @eval_history_values.size(no)
38
+ else
39
+ @eval_history_values = History.new(no)
40
+ IRB.conf[:__TMP__EHV__] = @eval_history_values
41
+ @workspace.evaluate(self, "__ = IRB.conf[:__TMP__EHV__]")
42
+ IRB.conf.delete(:__TMP_EHV__)
43
+ end
44
+ else
45
+ @eval_history_values = nil
46
+ end
47
+ @eval_history = no
48
+ end
49
+ end
50
+
51
+ class History
52
+ @RCS_ID='-$Id: history.rb 11708 2007-02-12 23:01:19Z shyouhei $-'
53
+
54
+ def initialize(size = 16)
55
+ @size = size
56
+ @contents = []
57
+ end
58
+
59
+ def size(size)
60
+ if size != 0 && size < @size
61
+ @contents = @contents[@size - size .. @size]
62
+ end
63
+ @size = size
64
+ end
65
+
66
+ def [](idx)
67
+ begin
68
+ if idx >= 0
69
+ @contents.find{|no, val| no == idx}[1]
70
+ else
71
+ @contents[idx][1]
72
+ end
73
+ rescue NameError
74
+ nil
75
+ end
76
+ end
77
+
78
+ def push(no, val)
79
+ @contents.push [no, val]
80
+ @contents.shift if @size != 0 && @contents.size > @size
81
+ end
82
+
83
+ alias real_inspect inspect
84
+
85
+ def inspect
86
+ if @contents.empty?
87
+ return real_inspect
88
+ end
89
+
90
+ unless (last = @contents.pop)[1].equal?(self)
91
+ @contents.push last
92
+ last = nil
93
+ end
94
+ str = @contents.collect{|no, val|
95
+ if val.equal?(self)
96
+ "#{no} ...self-history..."
97
+ else
98
+ "#{no} #{val.inspect}"
99
+ end
100
+ }.join("\n")
101
+ if str == ""
102
+ str = "Empty."
103
+ end
104
+ @contents.push last if last
105
+ str
106
+ end
107
+ end
108
+ end
109
+
110
+
@@ -0,0 +1,120 @@
1
+ #
2
+ # 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
+
14
+ module IRB
15
+ class LoadAbort < Exception;end
16
+
17
+ module IrbLoader
18
+ @RCS_ID='-$Id: loader.rb 11708 2007-02-12 23:01:19Z shyouhei $-'
19
+
20
+ alias ruby_load load
21
+ alias ruby_require require
22
+
23
+ def irb_load(fn, priv = nil)
24
+ path = search_file_from_ruby_path(fn)
25
+ raise LoadError, "No such file to load -- #{fn}" unless path
26
+
27
+ load_file(path, priv)
28
+ end
29
+
30
+ def search_file_from_ruby_path(fn)
31
+ if /^#{Regexp.quote(File::Separator)}/ =~ fn
32
+ return fn if File.exist?(fn)
33
+ return nil
34
+ end
35
+
36
+ for path in $:
37
+ if File.exist?(f = File.join(path, fn))
38
+ return f
39
+ end
40
+ end
41
+ return nil
42
+ end
43
+
44
+ def source_file(path)
45
+ irb.suspend_name(path, File.basename(path)) do
46
+ irb.suspend_input_method(FileInputMethod.new(path)) do
47
+ |back_io|
48
+ irb.signal_status(:IN_LOAD) do
49
+ if back_io.kind_of?(FileInputMethod)
50
+ irb.eval_input
51
+ else
52
+ begin
53
+ irb.eval_input
54
+ rescue LoadAbort
55
+ print "load abort!!\n"
56
+ end
57
+ end
58
+ end
59
+ end
60
+ end
61
+ end
62
+
63
+ def load_file(path, priv = nil)
64
+ irb.suspend_name(path, File.basename(path)) do
65
+
66
+ if priv
67
+ ws = WorkSpace.new(Module.new)
68
+ else
69
+ ws = WorkSpace.new
70
+ end
71
+ irb.suspend_workspace(ws) do
72
+ irb.suspend_input_method(FileInputMethod.new(path)) do
73
+ |back_io|
74
+ irb.signal_status(:IN_LOAD) do
75
+ # p irb.conf
76
+ if back_io.kind_of?(FileInputMethod)
77
+ irb.eval_input
78
+ else
79
+ begin
80
+ irb.eval_input
81
+ rescue LoadAbort
82
+ print "load abort!!\n"
83
+ end
84
+ end
85
+ end
86
+ end
87
+ end
88
+ end
89
+ end
90
+
91
+ def old
92
+ back_io = @io
93
+ back_path = @irb_path
94
+ back_name = @irb_name
95
+ back_scanner = @irb.scanner
96
+ begin
97
+ @io = FileInputMethod.new(path)
98
+ @irb_name = File.basename(path)
99
+ @irb_path = path
100
+ @irb.signal_status(:IN_LOAD) do
101
+ if back_io.kind_of?(FileInputMethod)
102
+ @irb.eval_input
103
+ else
104
+ begin
105
+ @irb.eval_input
106
+ rescue LoadAbort
107
+ print "load abort!!\n"
108
+ end
109
+ end
110
+ end
111
+ ensure
112
+ @io = back_io
113
+ @irb_name = back_name
114
+ @irb_path = back_path
115
+ @irb.scanner = back_scanner
116
+ end
117
+ end
118
+ end
119
+ end
120
+