irb 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (54) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +9 -0
  3. data/.travis.yml +6 -0
  4. data/Gemfile +5 -0
  5. data/LICENSE.txt +22 -0
  6. data/README.md +55 -0
  7. data/Rakefile +10 -0
  8. data/bin/console +6 -0
  9. data/bin/setup +6 -0
  10. data/exe/irb +11 -0
  11. data/irb.gemspec +26 -0
  12. data/lib/irb.rb +798 -0
  13. data/lib/irb/cmd/chws.rb +34 -0
  14. data/lib/irb/cmd/fork.rb +39 -0
  15. data/lib/irb/cmd/help.rb +42 -0
  16. data/lib/irb/cmd/load.rb +67 -0
  17. data/lib/irb/cmd/nop.rb +39 -0
  18. data/lib/irb/cmd/pushws.rb +41 -0
  19. data/lib/irb/cmd/subirb.rb +43 -0
  20. data/lib/irb/completion.rb +244 -0
  21. data/lib/irb/context.rb +425 -0
  22. data/lib/irb/ext/change-ws.rb +46 -0
  23. data/lib/irb/ext/history.rb +119 -0
  24. data/lib/irb/ext/loader.rb +129 -0
  25. data/lib/irb/ext/multi-irb.rb +265 -0
  26. data/lib/irb/ext/save-history.rb +105 -0
  27. data/lib/irb/ext/tracer.rb +72 -0
  28. data/lib/irb/ext/use-loader.rb +74 -0
  29. data/lib/irb/ext/workspaces.rb +67 -0
  30. data/lib/irb/extend-command.rb +306 -0
  31. data/lib/irb/frame.rb +81 -0
  32. data/lib/irb/help.rb +37 -0
  33. data/lib/irb/init.rb +302 -0
  34. data/lib/irb/input-method.rb +192 -0
  35. data/lib/irb/inspector.rb +132 -0
  36. data/lib/irb/lc/.document +4 -0
  37. data/lib/irb/lc/error.rb +32 -0
  38. data/lib/irb/lc/help-message +49 -0
  39. data/lib/irb/lc/ja/encoding_aliases.rb +11 -0
  40. data/lib/irb/lc/ja/error.rb +31 -0
  41. data/lib/irb/lc/ja/help-message +52 -0
  42. data/lib/irb/locale.rb +182 -0
  43. data/lib/irb/magic-file.rb +38 -0
  44. data/lib/irb/notifier.rb +232 -0
  45. data/lib/irb/output-method.rb +92 -0
  46. data/lib/irb/ruby-lex.rb +1180 -0
  47. data/lib/irb/ruby-token.rb +267 -0
  48. data/lib/irb/slex.rb +282 -0
  49. data/lib/irb/src_encoding.rb +7 -0
  50. data/lib/irb/version.rb +17 -0
  51. data/lib/irb/workspace.rb +143 -0
  52. data/lib/irb/ws-for-case-2.rb +15 -0
  53. data/lib/irb/xmp.rb +170 -0
  54. metadata +125 -0
@@ -0,0 +1,132 @@
1
+ # frozen_string_literal: false
2
+ #
3
+ # irb/inspector.rb - inspect methods
4
+ # $Release Version: 0.9.6$
5
+ # $Revision: 1.19 $
6
+ # $Date: 2002/06/11 07:51:31 $
7
+ # by Keiju ISHITSUKA(keiju@ruby-lang.org)
8
+ #
9
+ # --
10
+ #
11
+ #
12
+ #
13
+
14
+ module IRB # :nodoc:
15
+
16
+
17
+ # Convenience method to create a new Inspector, using the given +inspect+
18
+ # proc, and optional +init+ proc and passes them to Inspector.new
19
+ #
20
+ # irb(main):001:0> ins = IRB::Inspector(proc{ |v| "omg! #{v}" })
21
+ # irb(main):001:0> IRB.CurrentContext.inspect_mode = ins # => omg! #<IRB::Inspector:0x007f46f7ba7d28>
22
+ # irb(main):001:0> "what?" #=> omg! what?
23
+ #
24
+ def IRB::Inspector(inspect, init = nil)
25
+ Inspector.new(inspect, init)
26
+ end
27
+
28
+ # An irb inspector
29
+ #
30
+ # In order to create your own custom inspector there are two things you
31
+ # should be aware of:
32
+ #
33
+ # Inspector uses #inspect_value, or +inspect_proc+, for output of return values.
34
+ #
35
+ # This also allows for an optional #init+, or +init_proc+, which is called
36
+ # when the inspector is activated.
37
+ #
38
+ # Knowing this, you can create a rudimentary inspector as follows:
39
+ #
40
+ # irb(main):001:0> ins = IRB::Inspector.new(proc{ |v| "omg! #{v}" })
41
+ # irb(main):001:0> IRB.CurrentContext.inspect_mode = ins # => omg! #<IRB::Inspector:0x007f46f7ba7d28>
42
+ # irb(main):001:0> "what?" #=> omg! what?
43
+ #
44
+ class Inspector
45
+ # Default inspectors available to irb, this includes:
46
+ #
47
+ # +:pp+:: Using Kernel#pretty_inspect
48
+ # +:yaml+:: Using YAML.dump
49
+ # +:marshal+:: Using Marshal.dump
50
+ INSPECTORS = {}
51
+
52
+ # Determines the inspector to use where +inspector+ is one of the keys passed
53
+ # during inspector definition.
54
+ def self.keys_with_inspector(inspector)
55
+ INSPECTORS.select{|k,v| v == inspector}.collect{|k, v| k}
56
+ end
57
+
58
+ # Example
59
+ #
60
+ # Inspector.def_inspector(key, init_p=nil){|v| v.inspect}
61
+ # Inspector.def_inspector([key1,..], init_p=nil){|v| v.inspect}
62
+ # Inspector.def_inspector(key, inspector)
63
+ # Inspector.def_inspector([key1,...], inspector)
64
+ def self.def_inspector(key, arg=nil, &block)
65
+ if block_given?
66
+ inspector = IRB::Inspector(block, arg)
67
+ else
68
+ inspector = arg
69
+ end
70
+
71
+ case key
72
+ when Array
73
+ for k in key
74
+ def_inspector(k, inspector)
75
+ end
76
+ when Symbol
77
+ INSPECTORS[key] = inspector
78
+ INSPECTORS[key.to_s] = inspector
79
+ when String
80
+ INSPECTORS[key] = inspector
81
+ INSPECTORS[key.intern] = inspector
82
+ else
83
+ INSPECTORS[key] = inspector
84
+ end
85
+ end
86
+
87
+ # Creates a new inspector object, using the given +inspect_proc+ when
88
+ # output return values in irb.
89
+ def initialize(inspect_proc, init_proc = nil)
90
+ @init = init_proc
91
+ @inspect = inspect_proc
92
+ end
93
+
94
+ # Proc to call when the inspector is activated, good for requiring
95
+ # dependent libraries.
96
+ def init
97
+ @init.call if @init
98
+ end
99
+
100
+ # Proc to call when the input is evaluated and output in irb.
101
+ def inspect_value(v)
102
+ @inspect.call(v)
103
+ end
104
+ end
105
+
106
+ Inspector.def_inspector([false, :to_s, :raw]){|v| v.to_s}
107
+ Inspector.def_inspector([true, :p, :inspect]){|v|
108
+ begin
109
+ v.inspect
110
+ rescue NoMethodError
111
+ puts "(Object doesn't support #inspect)"
112
+ end
113
+ }
114
+ Inspector.def_inspector([:pp, :pretty_inspect], proc{require "pp"}){|v| v.pretty_inspect.chomp}
115
+ Inspector.def_inspector([:yaml, :YAML], proc{require "yaml"}){|v|
116
+ begin
117
+ YAML.dump(v)
118
+ rescue
119
+ puts "(can't dump yaml. use inspect)"
120
+ v.inspect
121
+ end
122
+ }
123
+
124
+ Inspector.def_inspector([:marshal, :Marshal, :MARSHAL, Marshal]){|v|
125
+ Marshal.dump(v)
126
+ }
127
+ end
128
+
129
+
130
+
131
+
132
+
@@ -0,0 +1,4 @@
1
+ # hide help-message files which contain usage information
2
+ error.rb
3
+ ja/encoding_aliases.rb
4
+ ja/error.rb
@@ -0,0 +1,32 @@
1
+ # frozen_string_literal: false
2
+ #
3
+ # irb/lc/error.rb -
4
+ # $Release Version: 0.9.6$
5
+ # $Revision$
6
+ # by Keiju ISHITSUKA(keiju@ruby-lang.org)
7
+ #
8
+ # --
9
+ #
10
+ #
11
+ #
12
+ require "e2mmap"
13
+
14
+ # :stopdoc:
15
+ module IRB
16
+
17
+ # exceptions
18
+ extend Exception2MessageMapper
19
+ def_exception :UnrecognizedSwitch, "Unrecognized switch: %s"
20
+ def_exception :NotImplementedError, "Need to define `%s'"
21
+ def_exception :CantReturnToNormalMode, "Can't return to normal mode."
22
+ def_exception :IllegalParameter, "Invalid parameter(%s)."
23
+ def_exception :IrbAlreadyDead, "Irb is already dead."
24
+ def_exception :IrbSwitchedToCurrentThread, "Switched to current thread."
25
+ def_exception :NoSuchJob, "No such job(%s)."
26
+ def_exception :CantShiftToMultiIrbMode, "Can't shift to multi irb mode."
27
+ def_exception :CantChangeBinding, "Can't change binding to (%s)."
28
+ def_exception :UndefinedPromptMode, "Undefined prompt mode(%s)."
29
+ def_exception :IllegalRCGenerator, 'Define illegal RC_NAME_GENERATOR.'
30
+
31
+ end
32
+ # :startdoc:
@@ -0,0 +1,49 @@
1
+ # -*- coding: utf-8 -*-
2
+ #
3
+ # irb/lc/help-message.rb -
4
+ # $Release Version: 0.9.6$
5
+ # $Revision$
6
+ # by Keiju ISHITSUKA(keiju@ruby-lang.org)
7
+ #
8
+ # --
9
+ #
10
+ #
11
+ #
12
+ Usage: irb.rb [options] [programfile] [arguments]
13
+ -f Suppress read of ~/.irbrc
14
+ -d Set $DEBUG to true (same as `ruby -d')
15
+ -r load-module Same as `ruby -r'
16
+ -I path Specify $LOAD_PATH directory
17
+ -U Same as `ruby -U`
18
+ -E enc Same as `ruby -E`
19
+ -w Same as `ruby -w`
20
+ -W[level=2] Same as `ruby -W`
21
+ --context-mode n Set n[0-3] to method to create Binding Object,
22
+ when new workspace was created
23
+ --echo Show result(default)
24
+ --noecho Don't show result
25
+ --inspect Use `inspect' for output (default except for bc mode)
26
+ --noinspect Don't use inspect for output
27
+ --readline Use Readline extension module
28
+ --noreadline Don't use Readline extension module
29
+ --prompt prompt-mode/--prompt-mode prompt-mode
30
+ Switch prompt mode. Pre-defined prompt modes are
31
+ `default', `simple', `xmp' and `inf-ruby'
32
+ --inf-ruby-mode Use prompt appropriate for inf-ruby-mode on emacs.
33
+ Suppresses --readline.
34
+ --sample-book-mode/--simple-prompt
35
+ Simple prompt mode
36
+ --noprompt No prompt mode
37
+ --single-irb Share self with sub-irb.
38
+ --tracer Display trace for each execution of commands.
39
+ --back-trace-limit n
40
+ Display backtrace top n and tail n. The default
41
+ value is 16.
42
+ --irb_debug n Set internal debug level to n (not for popular use)
43
+ --verbose Show details
44
+ --noverbose Don't show details
45
+ -v, --version Print the version of irb
46
+ -h, --help Print help
47
+ -- Separate options of irb from the list of command-line args
48
+
49
+ # vim:fileencoding=utf-8
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: false
2
+ # :stopdoc:
3
+ module IRB
4
+ class Locale
5
+ @@legacy_encoding_alias_map = {
6
+ 'ujis' => Encoding::EUC_JP,
7
+ 'euc' => Encoding::EUC_JP
8
+ }.freeze
9
+ end
10
+ end
11
+ # :startdoc:
@@ -0,0 +1,31 @@
1
+ # -*- coding: utf-8 -*-
2
+ # frozen_string_literal: false
3
+ # irb/lc/ja/error.rb -
4
+ # $Release Version: 0.9.6$
5
+ # $Revision$
6
+ # by Keiju ISHITSUKA(keiju@ruby-lang.org)
7
+ #
8
+ # --
9
+ #
10
+ #
11
+ #
12
+ require "e2mmap"
13
+
14
+ # :stopdoc:
15
+ module IRB
16
+ # exceptions
17
+ extend Exception2MessageMapper
18
+ def_exception :UnrecognizedSwitch, 'スイッチ(%s)が分りません'
19
+ def_exception :NotImplementedError, '`%s\'の定義が必要です'
20
+ def_exception :CantReturnToNormalMode, 'Normalモードに戻れません.'
21
+ def_exception :IllegalParameter, 'パラメータ(%s)が間違っています.'
22
+ def_exception :IrbAlreadyDead, 'Irbは既に死んでいます.'
23
+ def_exception :IrbSwitchedToCurrentThread, 'カレントスレッドに切り替わりました.'
24
+ def_exception :NoSuchJob, 'そのようなジョブ(%s)はありません.'
25
+ def_exception :CantShiftToMultiIrbMode, 'multi-irb modeに移れません.'
26
+ def_exception :CantChangeBinding, 'バインディング(%s)に変更できません.'
27
+ def_exception :UndefinedPromptMode, 'プロンプトモード(%s)は定義されていません.'
28
+ def_exception :IllegalRCNameGenerator, 'RC_NAME_GENERATORが正しく定義されていません.'
29
+ end
30
+ # :startdoc:
31
+ # vim:fileencoding=utf-8
@@ -0,0 +1,52 @@
1
+ # -*- coding: utf-8 -*-
2
+ # irb/lc/ja/help-message.rb -
3
+ # $Release Version: 0.9.6$
4
+ # $Revision$
5
+ # by Keiju ISHITSUKA(keiju@ruby-lang.org)
6
+ #
7
+ # --
8
+ #
9
+ #
10
+ #
11
+ Usage: irb.rb [options] [programfile] [arguments]
12
+ -f ~/.irbrc を読み込まない.
13
+ -d $DEBUG をtrueにする(ruby -d と同じ)
14
+ -r load-module ruby -r と同じ.
15
+ -I path $LOAD_PATH に path を追加する.
16
+ -U ruby -U と同じ.
17
+ -E enc ruby -E と同じ.
18
+ -w ruby -w と同じ.
19
+ -W[level=2] ruby -W と同じ.
20
+ --context-mode n 新しいワークスペースを作成した時に関連する Binding
21
+ オブジェクトの作成方法を 0 から 3 のいずれかに設定する.
22
+ --echo 実行結果を表示する(デフォルト).
23
+ --noecho 実行結果を表示しない.
24
+ --inspect 結果出力にinspectを用いる(bcモード以外はデフォルト).
25
+ --noinspect 結果出力にinspectを用いない.
26
+ --readline readlineライブラリを利用する.
27
+ --noreadline readlineライブラリを利用しない.
28
+ --prompt prompt-mode/--prompt-mode prompt-mode
29
+ プロンプトモードを切替えます. 現在定義されているプ
30
+ ロンプトモードは, default, simple, xmp, inf-rubyが
31
+ 用意されています.
32
+ --inf-ruby-mode emacsのinf-ruby-mode用のプロンプト表示を行なう. 特
33
+ に指定がない限り, readlineライブラリは使わなくなる.
34
+ --sample-book-mode/--simple-prompt
35
+ 非常にシンプルなプロンプトを用いるモードです.
36
+ --noprompt プロンプト表示を行なわない.
37
+ --single-irb irb 中で self を実行して得られるオブジェクトをサ
38
+ ブ irb と共有する.
39
+ --tracer コマンド実行時にトレースを行なう.
40
+ --back-trace-limit n
41
+ バックトレース表示をバックトレースの頭から n, 後ろ
42
+ からnだけ行なう. デフォルトは16
43
+
44
+ --irb_debug n irbのデバッグレベルをnに設定する(非推奨).
45
+
46
+ --verbose 詳細なメッセージを出力する.
47
+ --noverbose 詳細なメッセージを出力しない(デフォルト).
48
+ -v, --version irbのバージョンを表示する.
49
+ -h, --help irb のヘルプを表示する.
50
+ -- 以降のコマンドライン引数をオプションとして扱わない.
51
+
52
+ # vim:fileencoding=utf-8
@@ -0,0 +1,182 @@
1
+ # frozen_string_literal: false
2
+ #
3
+ # irb/locale.rb - internationalization module
4
+ # $Release Version: 0.9.6$
5
+ # $Revision$
6
+ # by Keiju ISHITSUKA(keiju@ruby-lang.org)
7
+ #
8
+ # --
9
+ #
10
+ #
11
+ #
12
+ module IRB # :nodoc:
13
+ class Locale
14
+
15
+ LOCALE_NAME_RE = %r[
16
+ (?<language>[[:alpha:]]{2,3})
17
+ (?:_ (?<territory>[[:alpha:]]{2,3}) )?
18
+ (?:\. (?<codeset>[^@]+) )?
19
+ (?:@ (?<modifier>.*) )?
20
+ ]x
21
+ LOCALE_DIR = "/lc/"
22
+
23
+ @@legacy_encoding_alias_map = {}.freeze
24
+
25
+ def initialize(locale = nil)
26
+ @lang = @territory = @encoding_name = @modifier = nil
27
+ @locale = locale || ENV["IRB_LANG"] || ENV["LC_MESSAGES"] || ENV["LC_ALL"] || ENV["LANG"] || "C"
28
+ if m = LOCALE_NAME_RE.match(@locale)
29
+ @lang, @territory, @encoding_name, @modifier = m[:language], m[:territory], m[:codeset], m[:modifier]
30
+
31
+ if @encoding_name
32
+ begin load 'irb/encoding_aliases.rb'; rescue LoadError; end
33
+ if @encoding = @@legacy_encoding_alias_map[@encoding_name]
34
+ warn(("%s is obsolete. use %s" % ["#{@lang}_#{@territory}.#{@encoding_name}", "#{@lang}_#{@territory}.#{@encoding.name}"]), uplevel: 1)
35
+ end
36
+ @encoding = Encoding.find(@encoding_name) rescue nil
37
+ end
38
+ end
39
+ @encoding ||= (Encoding.find('locale') rescue Encoding::ASCII_8BIT)
40
+ end
41
+
42
+ attr_reader :lang, :territory, :encoding, :modifier
43
+
44
+ def String(mes)
45
+ mes = super(mes)
46
+ if @encoding
47
+ mes.encode(@encoding, undef: :replace)
48
+ else
49
+ mes
50
+ end
51
+ end
52
+
53
+ def format(*opts)
54
+ String(super(*opts))
55
+ end
56
+
57
+ def gets(*rs)
58
+ String(super(*rs))
59
+ end
60
+
61
+ def readline(*rs)
62
+ String(super(*rs))
63
+ end
64
+
65
+ def print(*opts)
66
+ ary = opts.collect{|opt| String(opt)}
67
+ super(*ary)
68
+ end
69
+
70
+ def printf(*opts)
71
+ s = format(*opts)
72
+ print s
73
+ end
74
+
75
+ def puts(*opts)
76
+ ary = opts.collect{|opt| String(opt)}
77
+ super(*ary)
78
+ end
79
+
80
+ def require(file, priv = nil)
81
+ rex = Regexp.new("lc/#{Regexp.quote(file)}\.(so|o|sl|rb)?")
82
+ return false if $".find{|f| f =~ rex}
83
+
84
+ case file
85
+ when /\.rb$/
86
+ begin
87
+ load(file, priv)
88
+ $".push file
89
+ return true
90
+ rescue LoadError
91
+ end
92
+ when /\.(so|o|sl)$/
93
+ return super
94
+ end
95
+
96
+ begin
97
+ load(f = file + ".rb")
98
+ $".push f #"
99
+ return true
100
+ rescue LoadError
101
+ return ruby_require(file)
102
+ end
103
+ end
104
+
105
+ alias toplevel_load load
106
+
107
+ def load(file, priv=nil)
108
+ found = find(file)
109
+ if found
110
+ return real_load(found, priv)
111
+ else
112
+ raise LoadError, "No such file to load -- #{file}"
113
+ end
114
+ end
115
+
116
+ def find(file , paths = $:)
117
+ dir = File.dirname(file)
118
+ dir = "" if dir == "."
119
+ base = File.basename(file)
120
+
121
+ if dir.start_with?('/')
122
+ return each_localized_path(dir, base).find{|full_path| File.readable? full_path}
123
+ else
124
+ return search_file(paths, dir, base)
125
+ end
126
+ end
127
+
128
+ private
129
+ def real_load(path, priv)
130
+ src = MagicFile.open(path){|f| f.read}
131
+ if priv
132
+ eval("self", TOPLEVEL_BINDING).extend(Module.new {eval(src, nil, path)})
133
+ else
134
+ eval(src, TOPLEVEL_BINDING, path)
135
+ end
136
+ end
137
+
138
+ # @param paths load paths in which IRB find a localized file.
139
+ # @param dir directory
140
+ # @param file basename to be localized
141
+ #
142
+ # typically, for the parameters and a <path> in paths, it searches
143
+ # <path>/<dir>/<locale>/<file>
144
+ def search_file(lib_paths, dir, file)
145
+ each_localized_path(dir, file) do |lc_path|
146
+ lib_paths.each do |libpath|
147
+ full_path = File.join(libpath, lc_path)
148
+ return full_path if File.readable?(full_path)
149
+ end
150
+ redo if defined?(Gem) and Gem.try_activate(lc_path)
151
+ end
152
+ nil
153
+ end
154
+
155
+ def each_localized_path(dir, file)
156
+ return enum_for(:each_localized_path) unless block_given?
157
+ each_sublocale do |lc|
158
+ yield lc.nil? ? File.join(dir, LOCALE_DIR, file) : File.join(dir, LOCALE_DIR, lc, file)
159
+ end
160
+ end
161
+
162
+ def each_sublocale
163
+ if @lang
164
+ if @territory
165
+ if @encoding_name
166
+ yield "#{@lang}_#{@territory}.#{@encoding_name}@#{@modifier}" if @modifier
167
+ yield "#{@lang}_#{@territory}.#{@encoding_name}"
168
+ end
169
+ yield "#{@lang}_#{@territory}@#{@modifier}" if @modifier
170
+ yield "#{@lang}_#{@territory}"
171
+ end
172
+ if @encoding_name
173
+ yield "#{@lang}.#{@encoding_name}@#{@modifier}" if @modifier
174
+ yield "#{@lang}.#{@encoding_name}"
175
+ end
176
+ yield "#{@lang}@#{@modifier}" if @modifier
177
+ yield "#{@lang}"
178
+ end
179
+ yield nil
180
+ end
181
+ end
182
+ end