irb 1.1.1 → 1.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile +5 -0
- data/README.md +3 -3
- data/doc/irb/irb-tools.rd.ja +184 -0
- data/doc/irb/irb.rd.ja +411 -0
- data/irb.gemspec +58 -1
- data/lib/irb.rb +106 -35
- data/lib/irb/cmd/fork.rb +1 -1
- data/lib/irb/cmd/help.rb +9 -5
- data/lib/irb/color.rb +233 -0
- data/lib/irb/completion.rb +126 -33
- data/lib/irb/context.rb +105 -65
- data/lib/irb/ext/history.rb +47 -9
- data/lib/irb/ext/multi-irb.rb +7 -7
- data/lib/irb/ext/save-history.rb +17 -5
- data/lib/irb/ext/tracer.rb +14 -1
- data/lib/irb/ext/use-loader.rb +3 -0
- data/lib/irb/extend-command.rb +70 -48
- data/lib/irb/frame.rb +12 -7
- data/lib/irb/init.rb +30 -20
- data/lib/irb/input-method.rb +108 -3
- data/lib/irb/inspector.rb +12 -2
- data/lib/irb/lc/error.rb +55 -16
- data/lib/irb/lc/help-message +9 -6
- data/lib/irb/lc/ja/error.rb +55 -14
- data/lib/irb/lc/ja/help-message +9 -6
- data/lib/irb/locale.rb +5 -1
- data/lib/irb/notifier.rb +12 -8
- data/lib/irb/output-method.rb +6 -6
- data/lib/irb/ruby-lex.rb +345 -1039
- data/lib/irb/ruby_logo.aa +38 -0
- data/lib/irb/version.rb +2 -2
- data/lib/irb/workspace.rb +58 -20
- data/man/irb.1 +207 -0
- metadata +21 -6
- data/.gitignore +0 -9
- data/.travis.yml +0 -6
- data/lib/irb/ruby-token.rb +0 -267
- data/lib/irb/slex.rb +0 -282
data/lib/irb/input-method.rb
CHANGED
@@ -11,6 +11,8 @@
|
|
11
11
|
#
|
12
12
|
require_relative 'src_encoding'
|
13
13
|
require_relative 'magic-file'
|
14
|
+
require_relative 'completion'
|
15
|
+
require 'reline'
|
14
16
|
|
15
17
|
module IRB
|
16
18
|
STDIN_FILE_NAME = "(line)" # :nodoc:
|
@@ -30,7 +32,7 @@ module IRB
|
|
30
32
|
#
|
31
33
|
# See IO#gets for more information.
|
32
34
|
def gets
|
33
|
-
|
35
|
+
fail NotImplementedError, "gets"
|
34
36
|
end
|
35
37
|
public :gets
|
36
38
|
|
@@ -116,8 +118,7 @@ module IRB
|
|
116
118
|
# See IO#gets for more information.
|
117
119
|
def gets
|
118
120
|
print @prompt
|
119
|
-
|
120
|
-
l
|
121
|
+
@io.gets
|
121
122
|
end
|
122
123
|
|
123
124
|
# The external encoding for standard input.
|
@@ -140,6 +141,12 @@ module IRB
|
|
140
141
|
|
141
142
|
@stdin = IO.open(STDIN.to_i, :external_encoding => IRB.conf[:LC_MESSAGES].encoding, :internal_encoding => "-")
|
142
143
|
@stdout = IO.open(STDOUT.to_i, 'w', :external_encoding => IRB.conf[:LC_MESSAGES].encoding, :internal_encoding => "-")
|
144
|
+
|
145
|
+
if Readline.respond_to?("basic_word_break_characters=")
|
146
|
+
Readline.basic_word_break_characters = IRB::InputCompletor::BASIC_WORD_BREAK_CHARACTERS
|
147
|
+
end
|
148
|
+
Readline.completion_append_character = nil
|
149
|
+
Readline.completion_proc = IRB::InputCompletor::CompletionProc
|
143
150
|
end
|
144
151
|
|
145
152
|
# Reads the next line from this input method.
|
@@ -186,7 +193,105 @@ module IRB
|
|
186
193
|
def encoding
|
187
194
|
@stdin.external_encoding
|
188
195
|
end
|
196
|
+
|
197
|
+
if Readline.respond_to?("basic_word_break_characters=")
|
198
|
+
Readline.basic_word_break_characters = IRB::InputCompletor::BASIC_WORD_BREAK_CHARACTERS
|
199
|
+
end
|
200
|
+
Readline.completion_append_character = nil
|
201
|
+
Readline.completion_proc = IRB::InputCompletor::CompletionProc
|
189
202
|
end
|
190
203
|
rescue LoadError
|
191
204
|
end
|
205
|
+
|
206
|
+
class ReidlineInputMethod < InputMethod
|
207
|
+
include Reline
|
208
|
+
# Creates a new input method object using Readline
|
209
|
+
def initialize
|
210
|
+
super
|
211
|
+
|
212
|
+
@line_no = 0
|
213
|
+
@line = []
|
214
|
+
@eof = false
|
215
|
+
|
216
|
+
@stdin = ::IO.open(STDIN.to_i, :external_encoding => IRB.conf[:LC_MESSAGES].encoding, :internal_encoding => "-")
|
217
|
+
@stdout = ::IO.open(STDOUT.to_i, 'w', :external_encoding => IRB.conf[:LC_MESSAGES].encoding, :internal_encoding => "-")
|
218
|
+
|
219
|
+
if Reline.respond_to?("basic_word_break_characters=")
|
220
|
+
Reline.basic_word_break_characters = IRB::InputCompletor::BASIC_WORD_BREAK_CHARACTERS
|
221
|
+
end
|
222
|
+
Reline.completion_append_character = nil
|
223
|
+
Reline.completion_proc = IRB::InputCompletor::CompletionProc
|
224
|
+
Reline.output_modifier_proc =
|
225
|
+
if IRB.conf[:USE_COLORIZE]
|
226
|
+
proc do |output, complete:|
|
227
|
+
next unless IRB::Color.colorable?
|
228
|
+
IRB::Color.colorize_code(output, complete: complete)
|
229
|
+
end
|
230
|
+
else
|
231
|
+
proc do |output|
|
232
|
+
Reline::Unicode.escape_for_print(output)
|
233
|
+
end
|
234
|
+
end
|
235
|
+
Reline.dig_perfect_match_proc = IRB::InputCompletor::PerfectMatchedProc
|
236
|
+
end
|
237
|
+
|
238
|
+
def check_termination(&block)
|
239
|
+
@check_termination_proc = block
|
240
|
+
end
|
241
|
+
|
242
|
+
def dynamic_prompt(&block)
|
243
|
+
@prompt_proc = block
|
244
|
+
end
|
245
|
+
|
246
|
+
def auto_indent(&block)
|
247
|
+
@auto_indent_proc = block
|
248
|
+
end
|
249
|
+
|
250
|
+
# Reads the next line from this input method.
|
251
|
+
#
|
252
|
+
# See IO#gets for more information.
|
253
|
+
def gets
|
254
|
+
Reline.input = @stdin
|
255
|
+
Reline.output = @stdout
|
256
|
+
Reline.prompt_proc = @prompt_proc
|
257
|
+
Reline.auto_indent_proc = @auto_indent_proc if @auto_indent_proc
|
258
|
+
if l = readmultiline(@prompt, false, &@check_termination_proc)
|
259
|
+
HISTORY.push(l) if !l.empty?
|
260
|
+
@line[@line_no += 1] = l + "\n"
|
261
|
+
else
|
262
|
+
@eof = true
|
263
|
+
l
|
264
|
+
end
|
265
|
+
end
|
266
|
+
|
267
|
+
# Whether the end of this input method has been reached, returns +true+
|
268
|
+
# if there is no more data to read.
|
269
|
+
#
|
270
|
+
# See IO#eof? for more information.
|
271
|
+
def eof?
|
272
|
+
@eof
|
273
|
+
end
|
274
|
+
|
275
|
+
# Whether this input method is still readable when there is no more data to
|
276
|
+
# read.
|
277
|
+
#
|
278
|
+
# See IO#eof for more information.
|
279
|
+
def readable_after_eof?
|
280
|
+
true
|
281
|
+
end
|
282
|
+
|
283
|
+
# Returns the current line number for #io.
|
284
|
+
#
|
285
|
+
# #line counts the number of times #gets is called.
|
286
|
+
#
|
287
|
+
# See IO#lineno for more information.
|
288
|
+
def line(line_no)
|
289
|
+
@line[line_no]
|
290
|
+
end
|
291
|
+
|
292
|
+
# The external encoding for standard input.
|
293
|
+
def encoding
|
294
|
+
@stdin.external_encoding
|
295
|
+
end
|
296
|
+
end
|
192
297
|
end
|
data/lib/irb/inspector.rb
CHANGED
@@ -106,12 +106,22 @@ module IRB # :nodoc:
|
|
106
106
|
Inspector.def_inspector([false, :to_s, :raw]){|v| v.to_s}
|
107
107
|
Inspector.def_inspector([true, :p, :inspect]){|v|
|
108
108
|
begin
|
109
|
-
v.inspect
|
109
|
+
result = v.inspect
|
110
|
+
if IRB.conf[:MAIN_CONTEXT]&.use_colorize? && Color.inspect_colorable?(v)
|
111
|
+
result = Color.colorize_code(result)
|
112
|
+
end
|
113
|
+
result
|
110
114
|
rescue NoMethodError
|
111
115
|
puts "(Object doesn't support #inspect)"
|
112
116
|
end
|
113
117
|
}
|
114
|
-
Inspector.def_inspector([:pp, :pretty_inspect], proc{require "pp"}){|v|
|
118
|
+
Inspector.def_inspector([:pp, :pretty_inspect], proc{require "pp"}){|v|
|
119
|
+
result = v.pretty_inspect.chomp
|
120
|
+
if IRB.conf[:MAIN_CONTEXT]&.use_colorize? && Color.inspect_colorable?(v)
|
121
|
+
result = Color.colorize_code(result)
|
122
|
+
end
|
123
|
+
result
|
124
|
+
}
|
115
125
|
Inspector.def_inspector([:yaml, :YAML], proc{require "yaml"}){|v|
|
116
126
|
begin
|
117
127
|
YAML.dump(v)
|
data/lib/irb/lc/error.rb
CHANGED
@@ -9,24 +9,63 @@
|
|
9
9
|
#
|
10
10
|
#
|
11
11
|
#
|
12
|
-
require "e2mmap"
|
13
12
|
|
14
13
|
# :stopdoc:
|
15
14
|
module IRB
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
15
|
+
class UnrecognizedSwitch < StandardError
|
16
|
+
def initialize(val)
|
17
|
+
super("Unrecognized switch: #{val}")
|
18
|
+
end
|
19
|
+
end
|
20
|
+
class NotImplementedError < StandardError
|
21
|
+
def initialize(val)
|
22
|
+
super("Need to define `#{val}'")
|
23
|
+
end
|
24
|
+
end
|
25
|
+
class CantReturnToNormalMode < StandardError
|
26
|
+
def initialize
|
27
|
+
super("Can't return to normal mode.")
|
28
|
+
end
|
29
|
+
end
|
30
|
+
class IllegalParameter < StandardError
|
31
|
+
def initialize(val)
|
32
|
+
super("Invalid parameter(#{val}).")
|
33
|
+
end
|
34
|
+
end
|
35
|
+
class IrbAlreadyDead < StandardError
|
36
|
+
def initialize
|
37
|
+
super("Irb is already dead.")
|
38
|
+
end
|
39
|
+
end
|
40
|
+
class IrbSwitchedToCurrentThread < StandardError
|
41
|
+
def initialize
|
42
|
+
super("Switched to current thread.")
|
43
|
+
end
|
44
|
+
end
|
45
|
+
class NoSuchJob < StandardError
|
46
|
+
def initialize(val)
|
47
|
+
super("No such job(#{val}).")
|
48
|
+
end
|
49
|
+
end
|
50
|
+
class CantShiftToMultiIrbMode < StandardError
|
51
|
+
def initialize
|
52
|
+
super("Can't shift to multi irb mode.")
|
53
|
+
end
|
54
|
+
end
|
55
|
+
class CantChangeBinding < StandardError
|
56
|
+
def initialize(val)
|
57
|
+
super("Can't change binding to (#{val}).")
|
58
|
+
end
|
59
|
+
end
|
60
|
+
class UndefinedPromptMode < StandardError
|
61
|
+
def initialize(val)
|
62
|
+
super("Undefined prompt mode(#{val}).")
|
63
|
+
end
|
64
|
+
end
|
65
|
+
class IllegalRCGenerator < StandardError
|
66
|
+
def initialize
|
67
|
+
super("Define illegal RC_NAME_GENERATOR.")
|
68
|
+
end
|
69
|
+
end
|
31
70
|
end
|
32
71
|
# :startdoc:
|
data/lib/irb/lc/help-message
CHANGED
@@ -22,15 +22,19 @@ Usage: irb.rb [options] [programfile] [arguments]
|
|
22
22
|
when new workspace was created
|
23
23
|
--echo Show result(default)
|
24
24
|
--noecho Don't show result
|
25
|
-
--inspect
|
26
|
-
--noinspect
|
27
|
-
--
|
28
|
-
--
|
25
|
+
--inspect Use `inspect' for output
|
26
|
+
--noinspect Don't use inspect for output
|
27
|
+
--multiline Use multiline editor module
|
28
|
+
--nomultiline Don't use multiline editor module
|
29
|
+
--singleline Use singleline editor module
|
30
|
+
--nosingleline Don't use singleline editor module
|
31
|
+
--colorize Use colorization
|
32
|
+
--nocolorize Don't use colorization
|
29
33
|
--prompt prompt-mode/--prompt-mode prompt-mode
|
30
34
|
Switch prompt mode. Pre-defined prompt modes are
|
31
35
|
`default', `simple', `xmp' and `inf-ruby'
|
32
36
|
--inf-ruby-mode Use prompt appropriate for inf-ruby-mode on emacs.
|
33
|
-
|
37
|
+
Suppresses --multiline and --singleline.
|
34
38
|
--sample-book-mode/--simple-prompt
|
35
39
|
Simple prompt mode
|
36
40
|
--noprompt No prompt mode
|
@@ -39,7 +43,6 @@ Usage: irb.rb [options] [programfile] [arguments]
|
|
39
43
|
--back-trace-limit n
|
40
44
|
Display backtrace top n and tail n. The default
|
41
45
|
value is 16.
|
42
|
-
--irb_debug n Set internal debug level to n (not for popular use)
|
43
46
|
--verbose Show details
|
44
47
|
--noverbose Don't show details
|
45
48
|
-v, --version Print the version of irb
|
data/lib/irb/lc/ja/error.rb
CHANGED
@@ -9,23 +9,64 @@
|
|
9
9
|
#
|
10
10
|
#
|
11
11
|
#
|
12
|
-
require "e2mmap"
|
13
12
|
|
14
13
|
# :stopdoc:
|
15
14
|
module IRB
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
15
|
+
class UnrecognizedSwitch < StandardError
|
16
|
+
def initialize(val)
|
17
|
+
super("スイッチ(#{val})が分りません")
|
18
|
+
end
|
19
|
+
end
|
20
|
+
class NotImplementedError < StandardError
|
21
|
+
def initialize(val)
|
22
|
+
super("`#{val}'の定義が必要です")
|
23
|
+
end
|
24
|
+
end
|
25
|
+
class CantReturnToNormalMode < StandardError
|
26
|
+
def initialize
|
27
|
+
super("Normalモードに戻れません.")
|
28
|
+
end
|
29
|
+
end
|
30
|
+
class IllegalParameter < StandardError
|
31
|
+
def initialize(val)
|
32
|
+
super("パラメータ(#{val})が間違っています.")
|
33
|
+
end
|
34
|
+
end
|
35
|
+
class IrbAlreadyDead < StandardError
|
36
|
+
def initialize
|
37
|
+
super("Irbは既に死んでいます.")
|
38
|
+
end
|
39
|
+
end
|
40
|
+
class IrbSwitchedToCurrentThread < StandardError
|
41
|
+
def initialize
|
42
|
+
super("カレントスレッドに切り替わりました.")
|
43
|
+
end
|
44
|
+
end
|
45
|
+
class NoSuchJob < StandardError
|
46
|
+
def initialize(val)
|
47
|
+
super("そのようなジョブ(#{val})はありません.")
|
48
|
+
end
|
49
|
+
end
|
50
|
+
class CantShiftToMultiIrbMode < StandardError
|
51
|
+
def initialize
|
52
|
+
super("multi-irb modeに移れません.")
|
53
|
+
end
|
54
|
+
end
|
55
|
+
class CantChangeBinding < StandardError
|
56
|
+
def initialize(val)
|
57
|
+
super("バインディング(#{val})に変更できません.")
|
58
|
+
end
|
59
|
+
end
|
60
|
+
class UndefinedPromptMode < StandardError
|
61
|
+
def initialize(val)
|
62
|
+
super("プロンプトモード(#{val})は定義されていません.")
|
63
|
+
end
|
64
|
+
end
|
65
|
+
class IllegalRCGenerator < StandardError
|
66
|
+
def initialize
|
67
|
+
super("RC_NAME_GENERATORが正しく定義されていません.")
|
68
|
+
end
|
69
|
+
end
|
29
70
|
end
|
30
71
|
# :startdoc:
|
31
72
|
# vim:fileencoding=utf-8
|
data/lib/irb/lc/ja/help-message
CHANGED
@@ -21,16 +21,21 @@ Usage: irb.rb [options] [programfile] [arguments]
|
|
21
21
|
オブジェクトの作成方法を 0 から 3 のいずれかに設定する.
|
22
22
|
--echo 実行結果を表示する(デフォルト).
|
23
23
|
--noecho 実行結果を表示しない.
|
24
|
-
--inspect 結果出力にinspect
|
24
|
+
--inspect 結果出力にinspectを用いる.
|
25
25
|
--noinspect 結果出力にinspectを用いない.
|
26
|
-
--
|
27
|
-
--
|
26
|
+
--multiline マルチラインエディタを利用する.
|
27
|
+
--nomultiline マルチラインエディタを利用しない.
|
28
|
+
--singleline シングルラインエディタを利用する.
|
29
|
+
--nosingleline シングルラインエディタを利用しない.
|
30
|
+
--colorize 色付けを利用する.
|
31
|
+
--nocolorize 色付けを利用しない.
|
28
32
|
--prompt prompt-mode/--prompt-mode prompt-mode
|
29
33
|
プロンプトモードを切替えます. 現在定義されているプ
|
30
34
|
ロンプトモードは, default, simple, xmp, inf-rubyが
|
31
35
|
用意されています.
|
32
36
|
--inf-ruby-mode emacsのinf-ruby-mode用のプロンプト表示を行なう. 特
|
33
|
-
|
37
|
+
に指定がない限り, シングルラインエディタとマルチラ
|
38
|
+
インエディタは使わなくなる.
|
34
39
|
--sample-book-mode/--simple-prompt
|
35
40
|
非常にシンプルなプロンプトを用いるモードです.
|
36
41
|
--noprompt プロンプト表示を行なわない.
|
@@ -41,8 +46,6 @@ Usage: irb.rb [options] [programfile] [arguments]
|
|
41
46
|
バックトレース表示をバックトレースの頭から n, 後ろ
|
42
47
|
からnだけ行なう. デフォルトは16
|
43
48
|
|
44
|
-
--irb_debug n irbのデバッグレベルをnに設定する(非推奨).
|
45
|
-
|
46
49
|
--verbose 詳細なメッセージを出力する.
|
47
50
|
--noverbose 詳細なメッセージを出力しない(デフォルト).
|
48
51
|
-v, --version irbのバージョンを表示する.
|
data/lib/irb/locale.rb
CHANGED
@@ -21,6 +21,7 @@ module IRB # :nodoc:
|
|
21
21
|
LOCALE_DIR = "/lc/"
|
22
22
|
|
23
23
|
@@legacy_encoding_alias_map = {}.freeze
|
24
|
+
@@loaded = []
|
24
25
|
|
25
26
|
def initialize(locale = nil)
|
26
27
|
@lang = @territory = @encoding_name = @modifier = nil
|
@@ -107,7 +108,10 @@ module IRB # :nodoc:
|
|
107
108
|
def load(file, priv=nil)
|
108
109
|
found = find(file)
|
109
110
|
if found
|
110
|
-
|
111
|
+
unless @@loaded.include?(found)
|
112
|
+
@@loaded << found # cache
|
113
|
+
return real_load(found, priv)
|
114
|
+
end
|
111
115
|
else
|
112
116
|
raise LoadError, "No such file to load -- #{file}"
|
113
117
|
end
|
data/lib/irb/notifier.rb
CHANGED
@@ -10,17 +10,21 @@
|
|
10
10
|
#
|
11
11
|
#
|
12
12
|
|
13
|
-
require "e2mmap"
|
14
13
|
require_relative "output-method"
|
15
14
|
|
16
15
|
module IRB
|
17
16
|
# An output formatter used internally by the lexer.
|
18
17
|
module Notifier
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
18
|
+
class ErrUndefinedNotifier < StandardError
|
19
|
+
def initialize(val)
|
20
|
+
super("undefined notifier level: #{val} is specified")
|
21
|
+
end
|
22
|
+
end
|
23
|
+
class ErrUnrecognizedLevel < StandardError
|
24
|
+
def initialize(val)
|
25
|
+
super("unrecognized notifier level: #{val} is specified")
|
26
|
+
end
|
27
|
+
end
|
24
28
|
|
25
29
|
# Define a new Notifier output source, returning a new CompositeNotifier
|
26
30
|
# with the given +prefix+ and +output_method+.
|
@@ -162,10 +166,10 @@ module IRB
|
|
162
166
|
@level_notifier = value
|
163
167
|
when Integer
|
164
168
|
l = @notifiers[value]
|
165
|
-
|
169
|
+
raise ErrUndefinedNotifier, value unless l
|
166
170
|
@level_notifier = l
|
167
171
|
else
|
168
|
-
|
172
|
+
raise ErrUnrecognizedLevel, value unless l
|
169
173
|
end
|
170
174
|
end
|
171
175
|
|