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.
- checksums.yaml +7 -0
- data/.gitignore +17 -0
- data/.travis.yml +8 -0
- data/Gemfile +4 -0
- data/LICENSE +25 -0
- data/README.md +29 -0
- data/Rakefile +1 -0
- data/lib/irb/cmd/chws.rb +33 -0
- data/lib/irb/cmd/fork.rb +39 -0
- data/lib/irb/cmd/help.rb +31 -0
- data/lib/irb/cmd/load.rb +67 -0
- data/lib/irb/cmd/nop.rb +39 -0
- data/lib/irb/cmd/pushws.rb +39 -0
- data/lib/irb/cmd/subirb.rb +43 -0
- data/lib/irb/completion.rb +205 -0
- data/lib/irb/context.rb +255 -0
- data/lib/irb/ext/change-ws.rb +62 -0
- data/lib/irb/ext/history.rb +110 -0
- data/lib/irb/ext/loader.rb +120 -0
- data/lib/irb/ext/math-mode.rb +37 -0
- data/lib/irb/ext/multi-irb.rb +241 -0
- data/lib/irb/ext/save-history.rb +70 -0
- data/lib/irb/ext/tracer.rb +61 -0
- data/lib/irb/ext/use-loader.rb +65 -0
- data/lib/irb/ext/workspaces.rb +56 -0
- data/lib/irb/extend-command.rb +264 -0
- data/lib/irb/frame.rb +67 -0
- data/lib/irb/help.rb +35 -0
- data/lib/irb/init.rb +258 -0
- data/lib/irb/input-method.rb +120 -0
- data/lib/irb/lc/error.rb +30 -0
- data/lib/irb/lc/help-message.rb +37 -0
- data/lib/irb/lc/ja/error.rb +27 -0
- data/lib/irb/lc/ja/help-message +36 -0
- data/lib/irb/locale.rb +184 -0
- data/lib/irb/notifier.rb +145 -0
- data/lib/irb/output-method.rb +85 -0
- data/lib/irb/rubinius.rb +55 -0
- data/lib/irb/ruby-lex.rb +1149 -0
- data/lib/irb/ruby-token.rb +273 -0
- data/lib/irb/slex.rb +285 -0
- data/lib/irb/version.rb +16 -0
- data/lib/irb/workspace.rb +107 -0
- data/lib/irb/ws-for-case-2.rb +15 -0
- data/lib/irb/xmp.rb +86 -0
- data/lib/irb.rb +1 -0
- data/lib/rubysl/irb/irb.rb +356 -0
- data/lib/rubysl/irb/version.rb +5 -0
- data/lib/rubysl/irb.rb +2 -0
- data/rubysl-irb.gemspec +31 -0
- metadata +219 -0
@@ -0,0 +1,56 @@
|
|
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) $
|
6
|
+
# by Keiju ISHITSUKA(keiju@ruby-lang.org)
|
7
|
+
#
|
8
|
+
# --
|
9
|
+
#
|
10
|
+
#
|
11
|
+
#
|
12
|
+
|
13
|
+
module IRB
|
14
|
+
class Context
|
15
|
+
|
16
|
+
def irb_level
|
17
|
+
workspace_stack.size
|
18
|
+
end
|
19
|
+
|
20
|
+
def workspaces
|
21
|
+
if defined? @workspaces
|
22
|
+
@workspaces
|
23
|
+
else
|
24
|
+
@workspaces = []
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
def push_workspace(*_main)
|
29
|
+
if _main.empty?
|
30
|
+
if workspaces.empty?
|
31
|
+
print "No other workspace\n"
|
32
|
+
return nil
|
33
|
+
end
|
34
|
+
ws = workspaces.pop
|
35
|
+
workspaces.push @workspace
|
36
|
+
@workspace = ws
|
37
|
+
return workspaces
|
38
|
+
end
|
39
|
+
|
40
|
+
workspaces.push @workspace
|
41
|
+
@workspace = WorkSpace.new(@workspace.binding, _main[0])
|
42
|
+
if !(class<<main;ancestors;end).include?(ExtendCommandBundle)
|
43
|
+
main.extend ExtendCommandBundle
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
def pop_workspace
|
48
|
+
if workspaces.empty?
|
49
|
+
print "workspace stack empty\n"
|
50
|
+
return
|
51
|
+
end
|
52
|
+
@workspace = workspaces.pop
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
@@ -0,0 +1,264 @@
|
|
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) $
|
6
|
+
# by Keiju ISHITSUKA(keiju@ruby-lang.org)
|
7
|
+
#
|
8
|
+
# --
|
9
|
+
#
|
10
|
+
#
|
11
|
+
#
|
12
|
+
module IRB
|
13
|
+
#
|
14
|
+
# IRB extended command
|
15
|
+
#
|
16
|
+
module ExtendCommandBundle
|
17
|
+
EXCB = ExtendCommandBundle
|
18
|
+
|
19
|
+
NO_OVERRIDE = 0
|
20
|
+
OVERRIDE_PRIVATE_ONLY = 0x01
|
21
|
+
OVERRIDE_ALL = 0x02
|
22
|
+
|
23
|
+
def irb_exit(ret = 0)
|
24
|
+
irb_context.exit(ret)
|
25
|
+
end
|
26
|
+
|
27
|
+
def irb_context
|
28
|
+
IRB.CurrentContext
|
29
|
+
end
|
30
|
+
|
31
|
+
@ALIASES = [
|
32
|
+
[:context, :irb_context, NO_OVERRIDE],
|
33
|
+
[:conf, :irb_context, NO_OVERRIDE],
|
34
|
+
[:irb_quit, :irb_exit, OVERRIDE_PRIVATE_ONLY],
|
35
|
+
[:exit, :irb_exit, OVERRIDE_PRIVATE_ONLY],
|
36
|
+
[:quit, :irb_exit, OVERRIDE_PRIVATE_ONLY],
|
37
|
+
]
|
38
|
+
|
39
|
+
@EXTEND_COMMANDS = [
|
40
|
+
[:irb_current_working_workspace, :CurrentWorkingWorkspace, "irb/cmd/chws",
|
41
|
+
[:irb_print_working_workspace, OVERRIDE_ALL],
|
42
|
+
[:irb_cwws, OVERRIDE_ALL],
|
43
|
+
[:irb_pwws, OVERRIDE_ALL],
|
44
|
+
# [:irb_cww, OVERRIDE_ALL],
|
45
|
+
# [:irb_pww, OVERRIDE_ALL],
|
46
|
+
[:cwws, NO_OVERRIDE],
|
47
|
+
[:pwws, NO_OVERRIDE],
|
48
|
+
# [:cww, NO_OVERRIDE],
|
49
|
+
# [:pww, NO_OVERRIDE],
|
50
|
+
[:irb_current_working_binding, OVERRIDE_ALL],
|
51
|
+
[:irb_print_working_binding, OVERRIDE_ALL],
|
52
|
+
[:irb_cwb, OVERRIDE_ALL],
|
53
|
+
[:irb_pwb, OVERRIDE_ALL],
|
54
|
+
# [:cwb, NO_OVERRIDE],
|
55
|
+
# [:pwb, NO_OVERRIDE]
|
56
|
+
],
|
57
|
+
[:irb_change_workspace, :ChangeWorkspace, "irb/cmd/chws",
|
58
|
+
[:irb_chws, OVERRIDE_ALL],
|
59
|
+
# [:irb_chw, OVERRIDE_ALL],
|
60
|
+
[:irb_cws, OVERRIDE_ALL],
|
61
|
+
# [:irb_cw, OVERRIDE_ALL],
|
62
|
+
[:chws, NO_OVERRIDE],
|
63
|
+
# [:chw, NO_OVERRIDE],
|
64
|
+
[:cws, NO_OVERRIDE],
|
65
|
+
# [:cw, NO_OVERRIDE],
|
66
|
+
[:irb_change_binding, OVERRIDE_ALL],
|
67
|
+
[:irb_cb, OVERRIDE_ALL],
|
68
|
+
[:cb, NO_OVERRIDE]],
|
69
|
+
|
70
|
+
[:irb_workspaces, :Workspaces, "irb/cmd/pushws",
|
71
|
+
[:workspaces, NO_OVERRIDE],
|
72
|
+
[:irb_bindings, OVERRIDE_ALL],
|
73
|
+
[:bindings, NO_OVERRIDE]],
|
74
|
+
[:irb_push_workspace, :PushWorkspace, "irb/cmd/pushws",
|
75
|
+
[:irb_pushws, OVERRIDE_ALL],
|
76
|
+
# [:irb_pushw, OVERRIDE_ALL],
|
77
|
+
[:pushws, NO_OVERRIDE],
|
78
|
+
# [:pushw, NO_OVERRIDE],
|
79
|
+
[:irb_push_binding, OVERRIDE_ALL],
|
80
|
+
[:irb_pushb, OVERRIDE_ALL],
|
81
|
+
[:pushb, NO_OVERRIDE]],
|
82
|
+
[:irb_pop_workspace, :PopWorkspace, "irb/cmd/pushws",
|
83
|
+
[:irb_popws, OVERRIDE_ALL],
|
84
|
+
# [:irb_popw, OVERRIDE_ALL],
|
85
|
+
[:popws, NO_OVERRIDE],
|
86
|
+
# [:popw, NO_OVERRIDE],
|
87
|
+
[:irb_pop_binding, OVERRIDE_ALL],
|
88
|
+
[:irb_popb, OVERRIDE_ALL],
|
89
|
+
[:popb, NO_OVERRIDE]],
|
90
|
+
|
91
|
+
[:irb_load, :Load, "irb/cmd/load"],
|
92
|
+
[:irb_require, :Require, "irb/cmd/load"],
|
93
|
+
[:irb_source, :Source, "irb/cmd/load",
|
94
|
+
[:source, NO_OVERRIDE]],
|
95
|
+
|
96
|
+
[:irb, :IrbCommand, "irb/cmd/subirb"],
|
97
|
+
[:irb_jobs, :Jobs, "irb/cmd/subirb",
|
98
|
+
[:jobs, NO_OVERRIDE]],
|
99
|
+
[:irb_fg, :Foreground, "irb/cmd/subirb",
|
100
|
+
[:fg, NO_OVERRIDE]],
|
101
|
+
[:irb_kill, :Kill, "irb/cmd/subirb",
|
102
|
+
[:kill, OVERRIDE_PRIVATE_ONLY]],
|
103
|
+
|
104
|
+
[:irb_help, :Help, "irb/cmd/help",
|
105
|
+
[:help, NO_OVERRIDE]],
|
106
|
+
|
107
|
+
]
|
108
|
+
|
109
|
+
def self.install_extend_commands
|
110
|
+
for args in @EXTEND_COMMANDS
|
111
|
+
def_extend_command(*args)
|
112
|
+
end
|
113
|
+
end
|
114
|
+
|
115
|
+
# aliases = [commans_alias, flag], ...
|
116
|
+
def self.def_extend_command(cmd_name, cmd_class, load_file = nil, *aliases)
|
117
|
+
case cmd_class
|
118
|
+
when Symbol
|
119
|
+
cmd_class = cmd_class.id2name
|
120
|
+
when String
|
121
|
+
when Class
|
122
|
+
cmd_class = cmd_class.name
|
123
|
+
end
|
124
|
+
|
125
|
+
if load_file
|
126
|
+
eval %[
|
127
|
+
def #{cmd_name}(*opts, &b)
|
128
|
+
require "#{load_file}"
|
129
|
+
eval %[
|
130
|
+
def #{cmd_name}(*opts, &b)
|
131
|
+
ExtendCommand::#{cmd_class}.execute(irb_context, *opts, &b)
|
132
|
+
end
|
133
|
+
]
|
134
|
+
send :#{cmd_name}, *opts, &b
|
135
|
+
end
|
136
|
+
]
|
137
|
+
else
|
138
|
+
eval %[
|
139
|
+
def #{cmd_name}(*opts, &b)
|
140
|
+
ExtendCommand::#{cmd_class}.execute(irb_context, *opts, &b)
|
141
|
+
end
|
142
|
+
]
|
143
|
+
end
|
144
|
+
|
145
|
+
for ali, flag in aliases
|
146
|
+
@ALIASES.push [ali, cmd_name, flag]
|
147
|
+
end
|
148
|
+
end
|
149
|
+
|
150
|
+
# override = {NO_OVERRIDE, OVERRIDE_PRIVATE_ONLY, OVERRIDE_ALL}
|
151
|
+
def install_alias_method(to, from, override = NO_OVERRIDE)
|
152
|
+
to = to.id2name unless to.kind_of?(String)
|
153
|
+
from = from.id2name unless from.kind_of?(String)
|
154
|
+
|
155
|
+
if override == OVERRIDE_ALL or
|
156
|
+
(override == OVERRIDE_PRIVATE_ONLY) && !respond_to?(to) or
|
157
|
+
(override == NO_OVERRIDE) && !respond_to?(to, true)
|
158
|
+
target = self
|
159
|
+
(class<<self;self;end).instance_eval{
|
160
|
+
if target.respond_to?(to, true) &&
|
161
|
+
!target.respond_to?(EXCB.irb_original_method_name(to), true)
|
162
|
+
alias_method(EXCB.irb_original_method_name(to), to)
|
163
|
+
end
|
164
|
+
alias_method to, from
|
165
|
+
}
|
166
|
+
else
|
167
|
+
print "irb: warn: can't alias #{to} from #{from}.\n"
|
168
|
+
end
|
169
|
+
end
|
170
|
+
|
171
|
+
def self.irb_original_method_name(method_name)
|
172
|
+
"irb_" + method_name + "_org"
|
173
|
+
end
|
174
|
+
|
175
|
+
def self.extend_object(obj)
|
176
|
+
unless (class<<obj;ancestors;end).include?(EXCB)
|
177
|
+
super
|
178
|
+
for ali, com, flg in @ALIASES
|
179
|
+
obj.install_alias_method(ali, com, flg)
|
180
|
+
end
|
181
|
+
end
|
182
|
+
end
|
183
|
+
|
184
|
+
install_extend_commands
|
185
|
+
end
|
186
|
+
|
187
|
+
# extension support for Context
|
188
|
+
module ContextExtender
|
189
|
+
CE = ContextExtender
|
190
|
+
|
191
|
+
@EXTEND_COMMANDS = [
|
192
|
+
[:eval_history=, "irb/ext/history.rb"],
|
193
|
+
[:use_tracer=, "irb/ext/tracer.rb"],
|
194
|
+
[:math_mode=, "irb/ext/math-mode.rb"],
|
195
|
+
[:use_loader=, "irb/ext/use-loader.rb"],
|
196
|
+
[:save_history=, "irb/ext/save-history.rb"],
|
197
|
+
]
|
198
|
+
|
199
|
+
def self.install_extend_commands
|
200
|
+
for args in @EXTEND_COMMANDS
|
201
|
+
def_extend_command(*args)
|
202
|
+
end
|
203
|
+
end
|
204
|
+
|
205
|
+
def self.def_extend_command(cmd_name, load_file, *aliases)
|
206
|
+
Context.module_eval %[
|
207
|
+
def #{cmd_name}(*opts, &b)
|
208
|
+
Context.module_eval {remove_method(:#{cmd_name})}
|
209
|
+
require "#{load_file}"
|
210
|
+
send :#{cmd_name}, *opts, &b
|
211
|
+
end
|
212
|
+
for ali in aliases
|
213
|
+
alias_method ali, cmd_name
|
214
|
+
end
|
215
|
+
]
|
216
|
+
end
|
217
|
+
|
218
|
+
CE.install_extend_commands
|
219
|
+
end
|
220
|
+
|
221
|
+
module MethodExtender
|
222
|
+
def def_pre_proc(base_method, extend_method)
|
223
|
+
base_method = base_method.to_s
|
224
|
+
extend_method = extend_method.to_s
|
225
|
+
|
226
|
+
alias_name = new_alias_name(base_method)
|
227
|
+
module_eval %[
|
228
|
+
alias_method alias_name, base_method
|
229
|
+
def #{base_method}(*opts)
|
230
|
+
send :#{extend_method}, *opts
|
231
|
+
send :#{alias_name}, *opts
|
232
|
+
end
|
233
|
+
]
|
234
|
+
end
|
235
|
+
|
236
|
+
def def_post_proc(base_method, extend_method)
|
237
|
+
base_method = base_method.to_s
|
238
|
+
extend_method = extend_method.to_s
|
239
|
+
|
240
|
+
alias_name = new_alias_name(base_method)
|
241
|
+
module_eval %[
|
242
|
+
alias_method alias_name, base_method
|
243
|
+
def #{base_method}(*opts)
|
244
|
+
send :#{alias_name}, *opts
|
245
|
+
send :#{extend_method}, *opts
|
246
|
+
end
|
247
|
+
]
|
248
|
+
end
|
249
|
+
|
250
|
+
# return #{prefix}#{name}#{postfix}<num>
|
251
|
+
def new_alias_name(name, prefix = "__alias_of__", postfix = "__")
|
252
|
+
base_name = "#{prefix}#{name}#{postfix}"
|
253
|
+
all_methods = instance_methods(true) + private_instance_methods(true)
|
254
|
+
same_methods = all_methods.grep(/^#{Regexp.quote(base_name)}[0-9]*$/)
|
255
|
+
return base_name if same_methods.empty?
|
256
|
+
no = same_methods.size
|
257
|
+
while !same_methods.include?(alias_name = base_name + no)
|
258
|
+
no += 1
|
259
|
+
end
|
260
|
+
alias_name
|
261
|
+
end
|
262
|
+
end
|
263
|
+
end
|
264
|
+
|
data/lib/irb/frame.rb
ADDED
@@ -0,0 +1,67 @@
|
|
1
|
+
#
|
2
|
+
# frame.rb -
|
3
|
+
# $Release Version: 0.9$
|
4
|
+
# $Revision: 11708 $
|
5
|
+
# $Date: 2007-02-12 15:01:19 -0800 (Mon, 12 Feb 2007) $
|
6
|
+
# by Keiju ISHITSUKA(Nihon Rational Software Co.,Ltd)
|
7
|
+
#
|
8
|
+
# --
|
9
|
+
#
|
10
|
+
#
|
11
|
+
#
|
12
|
+
|
13
|
+
require "e2mmap"
|
14
|
+
|
15
|
+
module IRB
|
16
|
+
class Frame
|
17
|
+
extend Exception2MessageMapper
|
18
|
+
def_exception :FrameOverflow, "frame overflow"
|
19
|
+
def_exception :FrameUnderflow, "frame underflow"
|
20
|
+
|
21
|
+
INIT_STACK_TIMES = 3
|
22
|
+
CALL_STACK_OFFSET = 3
|
23
|
+
|
24
|
+
def initialize
|
25
|
+
@frames = [TOPLEVEL_BINDING] * INIT_STACK_TIMES
|
26
|
+
end
|
27
|
+
|
28
|
+
def trace_func(event, file, line, id, binding)
|
29
|
+
case event
|
30
|
+
when 'call', 'class'
|
31
|
+
@frames.push binding
|
32
|
+
when 'return', 'end'
|
33
|
+
@frames.pop
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
def top(n = 0)
|
38
|
+
bind = @frames[-(n + CALL_STACK_OFFSET)]
|
39
|
+
Fail FrameUnderflow unless bind
|
40
|
+
bind
|
41
|
+
end
|
42
|
+
|
43
|
+
def bottom(n = 0)
|
44
|
+
bind = @frames[n]
|
45
|
+
Fail FrameOverflow unless bind
|
46
|
+
bind
|
47
|
+
end
|
48
|
+
|
49
|
+
# singleton functions
|
50
|
+
def Frame.bottom(n = 0)
|
51
|
+
@backtrace.bottom(n)
|
52
|
+
end
|
53
|
+
|
54
|
+
def Frame.top(n = 0)
|
55
|
+
@backtrace.top(n)
|
56
|
+
end
|
57
|
+
|
58
|
+
def Frame.sender
|
59
|
+
eval "self", @backtrace.top
|
60
|
+
end
|
61
|
+
|
62
|
+
@backtrace = Frame.new
|
63
|
+
set_trace_func proc{|event, file, line, id, binding, klass|
|
64
|
+
@backtrace.trace_func(event, file, line, id, binding)
|
65
|
+
}
|
66
|
+
end
|
67
|
+
end
|
data/lib/irb/help.rb
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
#
|
2
|
+
# irb/help.rb - print usage module
|
3
|
+
# $Release Version: 0.9.5$
|
4
|
+
# $Revision: 16857 $
|
5
|
+
# $Date: 2008-06-06 01:05:24 -0700 (Fri, 06 Jun 2008) $
|
6
|
+
# by Keiju ISHITSUKA(keiju@ishitsuka.com)
|
7
|
+
#
|
8
|
+
# --
|
9
|
+
#
|
10
|
+
#
|
11
|
+
#
|
12
|
+
|
13
|
+
module IRB
|
14
|
+
def IRB.print_usage
|
15
|
+
lc = IRB.conf[:LC_MESSAGES]
|
16
|
+
path = lc.find("irb/help-message.rb")
|
17
|
+
space_line = false
|
18
|
+
File.foreach(path) do
|
19
|
+
|l|
|
20
|
+
if /^\s*$/ =~ l
|
21
|
+
lc.puts l unless space_line
|
22
|
+
space_line = true
|
23
|
+
next
|
24
|
+
end
|
25
|
+
space_line = false
|
26
|
+
|
27
|
+
l.sub!(/#.*$/, "")
|
28
|
+
l.sub!(/<<HELP/, "")
|
29
|
+
l.sub!(/HELP/, "")
|
30
|
+
next if /^\s*$/ =~ l
|
31
|
+
lc.puts l
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
data/lib/irb/init.rb
ADDED
@@ -0,0 +1,258 @@
|
|
1
|
+
#
|
2
|
+
# irb/init.rb - irb initialize 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
|
+
|
13
|
+
module IRB
|
14
|
+
|
15
|
+
# initialize config
|
16
|
+
def IRB.setup(ap_path)
|
17
|
+
IRB.init_config(ap_path)
|
18
|
+
IRB.init_error
|
19
|
+
IRB.parse_opts
|
20
|
+
IRB.run_config
|
21
|
+
IRB.load_modules
|
22
|
+
|
23
|
+
unless @CONF[:PROMPT][@CONF[:PROMPT_MODE]]
|
24
|
+
IRB.fail(UndefinedPromptMode, @CONF[:PROMPT_MODE])
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
# @CONF default setting
|
29
|
+
def IRB.init_config(ap_path)
|
30
|
+
# class instance variables
|
31
|
+
@TRACER_INITIALIZED = false
|
32
|
+
|
33
|
+
# default configurations
|
34
|
+
unless ap_path and @CONF[:AP_NAME]
|
35
|
+
ap_path = File.join(File.dirname(File.dirname(__FILE__)), "irb.rb")
|
36
|
+
end
|
37
|
+
|
38
|
+
@CONF[:AP_NAME] = File::basename(ap_path, ".rb")
|
39
|
+
|
40
|
+
@CONF[:IRB_NAME] = "irb"
|
41
|
+
@CONF[:IRB_LIB_PATH] = File.dirname(__FILE__)
|
42
|
+
|
43
|
+
@CONF[:RC] = true
|
44
|
+
@CONF[:LOAD_MODULES] = []
|
45
|
+
@CONF[:IRB_RC] = nil
|
46
|
+
|
47
|
+
@CONF[:MATH_MODE] = false
|
48
|
+
@CONF[:USE_READLINE] = false unless defined?(ReadlineInputMethod)
|
49
|
+
@CONF[:INSPECT_MODE] = nil
|
50
|
+
@CONF[:USE_TRACER] = false
|
51
|
+
@CONF[:USE_LOADER] = false
|
52
|
+
@CONF[:IGNORE_SIGINT] = true
|
53
|
+
@CONF[:IGNORE_EOF] = false
|
54
|
+
@CONF[:ECHO] = nil
|
55
|
+
@CONF[:VERBOSE] = nil
|
56
|
+
|
57
|
+
@CONF[:EVAL_HISTORY] = nil
|
58
|
+
@CONF[:SAVE_HISTORY] = nil
|
59
|
+
|
60
|
+
@CONF[:BACK_TRACE_LIMIT] = 16
|
61
|
+
|
62
|
+
@CONF[:PROMPT] = {
|
63
|
+
:NULL => {
|
64
|
+
:PROMPT_I => nil,
|
65
|
+
:PROMPT_N => nil,
|
66
|
+
:PROMPT_S => nil,
|
67
|
+
:PROMPT_C => nil,
|
68
|
+
:RETURN => "%s\n"
|
69
|
+
},
|
70
|
+
:DEFAULT => {
|
71
|
+
:PROMPT_I => "%N(%m):%03n:%i> ",
|
72
|
+
:PROMPT_N => "%N(%m):%03n:%i> ",
|
73
|
+
:PROMPT_S => "%N(%m):%03n:%i%l ",
|
74
|
+
:PROMPT_C => "%N(%m):%03n:%i* ",
|
75
|
+
:RETURN => "=> %s\n"
|
76
|
+
},
|
77
|
+
:CLASSIC => {
|
78
|
+
:PROMPT_I => "%N(%m):%03n:%i> ",
|
79
|
+
:PROMPT_N => "%N(%m):%03n:%i> ",
|
80
|
+
:PROMPT_S => "%N(%m):%03n:%i%l ",
|
81
|
+
:PROMPT_C => "%N(%m):%03n:%i* ",
|
82
|
+
:RETURN => "%s\n"
|
83
|
+
},
|
84
|
+
:SIMPLE => {
|
85
|
+
:PROMPT_I => ">> ",
|
86
|
+
:PROMPT_N => ">> ",
|
87
|
+
:PROMPT_S => nil,
|
88
|
+
:PROMPT_C => "?> ",
|
89
|
+
:RETURN => "=> %s\n"
|
90
|
+
},
|
91
|
+
:INF_RUBY => {
|
92
|
+
:PROMPT_I => "%N(%m):%03n:%i> ",
|
93
|
+
# :PROMPT_N => "%N(%m):%03n:%i> ",
|
94
|
+
:PROMPT_N => nil,
|
95
|
+
:PROMPT_S => nil,
|
96
|
+
:PROMPT_C => nil,
|
97
|
+
:RETURN => "%s\n",
|
98
|
+
:AUTO_INDENT => true
|
99
|
+
},
|
100
|
+
:XMP => {
|
101
|
+
:PROMPT_I => nil,
|
102
|
+
:PROMPT_N => nil,
|
103
|
+
:PROMPT_S => nil,
|
104
|
+
:PROMPT_C => nil,
|
105
|
+
:RETURN => " ==>%s\n"
|
106
|
+
}
|
107
|
+
}
|
108
|
+
|
109
|
+
@CONF[:PROMPT_MODE] = (STDIN.tty? ? :DEFAULT : :NULL)
|
110
|
+
@CONF[:AUTO_INDENT] = false
|
111
|
+
|
112
|
+
@CONF[:CONTEXT_MODE] = 3 # use binding in function on TOPLEVEL_BINDING
|
113
|
+
@CONF[:SINGLE_IRB] = false
|
114
|
+
|
115
|
+
# @CONF[:LC_MESSAGES] = "en"
|
116
|
+
@CONF[:LC_MESSAGES] = Locale.new
|
117
|
+
|
118
|
+
@CONF[:DEBUG_LEVEL] = 1
|
119
|
+
end
|
120
|
+
|
121
|
+
def IRB.init_error
|
122
|
+
@CONF[:LC_MESSAGES].load("irb/error.rb")
|
123
|
+
end
|
124
|
+
|
125
|
+
FEATURE_IOPT_CHANGE_VERSION = "1.9.0"
|
126
|
+
|
127
|
+
# option analyzing
|
128
|
+
def IRB.parse_opts
|
129
|
+
load_path = []
|
130
|
+
while opt = ARGV.shift
|
131
|
+
case opt
|
132
|
+
when "-f"
|
133
|
+
@CONF[:RC] = false
|
134
|
+
when "-m"
|
135
|
+
@CONF[:MATH_MODE] = true
|
136
|
+
when "-d"
|
137
|
+
$DEBUG = true
|
138
|
+
when /^-r(.+)?/
|
139
|
+
opt = $1 || ARGV.shift
|
140
|
+
@CONF[:LOAD_MODULES].push opt if opt
|
141
|
+
when /^-I(.+)?/
|
142
|
+
opt = $1 || ARGV.shift
|
143
|
+
load_path.concat(opt.split(File::PATH_SEPARATOR)) if opt
|
144
|
+
when /^-K(.)/
|
145
|
+
$KCODE = $1
|
146
|
+
when "--inspect"
|
147
|
+
@CONF[:INSPECT_MODE] = true
|
148
|
+
when "--noinspect"
|
149
|
+
@CONF[:INSPECT_MODE] = false
|
150
|
+
when "--readline"
|
151
|
+
@CONF[:USE_READLINE] = true
|
152
|
+
when "--noreadline"
|
153
|
+
@CONF[:USE_READLINE] = false
|
154
|
+
when "--echo"
|
155
|
+
@CONF[:ECHO] = true
|
156
|
+
when "--noecho"
|
157
|
+
@CONF[:ECHO] = false
|
158
|
+
when "--verbose"
|
159
|
+
@CONF[:VERBOSE] = true
|
160
|
+
when "--noverbose"
|
161
|
+
@CONF[:VERBOSE] = false
|
162
|
+
when "--prompt-mode", "--prompt"
|
163
|
+
prompt_mode = ARGV.shift.upcase.tr("-", "_").intern
|
164
|
+
@CONF[:PROMPT_MODE] = prompt_mode
|
165
|
+
when "--noprompt"
|
166
|
+
@CONF[:PROMPT_MODE] = :NULL
|
167
|
+
when "--inf-ruby-mode"
|
168
|
+
@CONF[:PROMPT_MODE] = :INF_RUBY
|
169
|
+
when "--sample-book-mode", "--simple-prompt"
|
170
|
+
@CONF[:PROMPT_MODE] = :SIMPLE
|
171
|
+
when "--tracer"
|
172
|
+
@CONF[:USE_TRACER] = true
|
173
|
+
when "--back-trace-limit"
|
174
|
+
@CONF[:BACK_TRACE_LIMIT] = ARGV.shift.to_i
|
175
|
+
when "--context-mode"
|
176
|
+
@CONF[:CONTEXT_MODE] = ARGV.shift.to_i
|
177
|
+
when "--single-irb"
|
178
|
+
@CONF[:SINGLE_IRB] = true
|
179
|
+
when "--irb_debug"
|
180
|
+
@CONF[:DEBUG_LEVEL] = ARGV.shift.to_i
|
181
|
+
when "-v", "--version"
|
182
|
+
print IRB.version, "\n"
|
183
|
+
exit 0
|
184
|
+
when "-h", "--help"
|
185
|
+
require "irb/help"
|
186
|
+
IRB.print_usage
|
187
|
+
exit 0
|
188
|
+
when /^-/
|
189
|
+
IRB.fail UnrecognizedSwitch, opt
|
190
|
+
else
|
191
|
+
@CONF[:SCRIPT] = opt
|
192
|
+
$0 = opt
|
193
|
+
break
|
194
|
+
end
|
195
|
+
end
|
196
|
+
|
197
|
+
if RUBY_VERSION >= FEATURE_IOPT_CHANGE_VERSION
|
198
|
+
load_path.collect! do |path|
|
199
|
+
/\A\.\// =~ path ? path : File.expand_path(path)
|
200
|
+
end
|
201
|
+
end
|
202
|
+
$LOAD_PATH.unshift(*load_path)
|
203
|
+
end
|
204
|
+
|
205
|
+
# running config
|
206
|
+
def IRB.run_config
|
207
|
+
if @CONF[:RC]
|
208
|
+
begin
|
209
|
+
load rc_file
|
210
|
+
rescue LoadError, Errno::ENOENT
|
211
|
+
rescue => e
|
212
|
+
print "load error: #{rc_file}\n"
|
213
|
+
raise e
|
214
|
+
end
|
215
|
+
end
|
216
|
+
end
|
217
|
+
|
218
|
+
IRBRC_EXT = "rc"
|
219
|
+
def IRB.rc_file(ext = IRBRC_EXT)
|
220
|
+
if !@CONF[:RC_NAME_GENERATOR]
|
221
|
+
rc_file_generators do |rcgen|
|
222
|
+
@CONF[:RC_NAME_GENERATOR] ||= rcgen
|
223
|
+
if File.exist?(rcgen.call(IRBRC_EXT))
|
224
|
+
@CONF[:RC_NAME_GENERATOR] = rcgen
|
225
|
+
break
|
226
|
+
end
|
227
|
+
end
|
228
|
+
end
|
229
|
+
@CONF[:RC_NAME_GENERATOR].call ext
|
230
|
+
end
|
231
|
+
|
232
|
+
# enumerate possible rc-file base name generators
|
233
|
+
def IRB.rc_file_generators
|
234
|
+
if irbrc = ENV["IRBRC"]
|
235
|
+
yield proc{|rc| rc == "rc" ? irbrc : irbrc+rc}
|
236
|
+
end
|
237
|
+
if home = ENV["HOME"]
|
238
|
+
yield proc{|rc| home+"/.irb#{rc}"}
|
239
|
+
end
|
240
|
+
home = Dir.pwd
|
241
|
+
yield proc{|rc| home+"/.irb#{rc}"}
|
242
|
+
yield proc{|rc| home+"/irb#{rc.sub(/\A_?/, '.')}"}
|
243
|
+
yield proc{|rc| home+"/_irb#{rc}"}
|
244
|
+
yield proc{|rc| home+"/$irb#{rc}"}
|
245
|
+
end
|
246
|
+
|
247
|
+
# loading modules
|
248
|
+
def IRB.load_modules
|
249
|
+
for m in @CONF[:LOAD_MODULES]
|
250
|
+
begin
|
251
|
+
require m
|
252
|
+
rescue
|
253
|
+
print $@[0], ":", $!.class, ": ", $!, "\n"
|
254
|
+
end
|
255
|
+
end
|
256
|
+
end
|
257
|
+
|
258
|
+
end
|