irb 0.9.6 → 1.4.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (57) hide show
  1. checksums.yaml +4 -4
  2. data/.document +4 -0
  3. data/Gemfile +10 -2
  4. data/LICENSE.txt +3 -3
  5. data/README.md +3 -3
  6. data/Rakefile +17 -1
  7. data/doc/irb/irb-tools.rd.ja +184 -0
  8. data/doc/irb/irb.rd.ja +427 -0
  9. data/irb.gemspec +18 -4
  10. data/lib/irb/cmd/fork.rb +2 -4
  11. data/lib/irb/cmd/help.rb +10 -5
  12. data/lib/irb/cmd/info.rb +32 -0
  13. data/lib/irb/cmd/ls.rb +101 -0
  14. data/lib/irb/cmd/measure.rb +43 -0
  15. data/lib/irb/cmd/nop.rb +10 -4
  16. data/lib/irb/cmd/pushws.rb +0 -1
  17. data/lib/irb/cmd/show_source.rb +93 -0
  18. data/lib/irb/cmd/whereami.rb +20 -0
  19. data/lib/irb/color.rb +246 -0
  20. data/lib/irb/color_printer.rb +47 -0
  21. data/lib/irb/completion.rb +254 -55
  22. data/lib/irb/context.rb +165 -72
  23. data/lib/irb/easter-egg.rb +138 -0
  24. data/lib/irb/ext/change-ws.rb +0 -1
  25. data/lib/irb/ext/history.rb +47 -11
  26. data/lib/irb/ext/loader.rb +46 -20
  27. data/lib/irb/ext/multi-irb.rb +7 -7
  28. data/lib/irb/ext/save-history.rb +36 -11
  29. data/lib/irb/ext/tracer.rb +14 -2
  30. data/lib/irb/ext/use-loader.rb +4 -3
  31. data/lib/irb/ext/workspaces.rb +0 -1
  32. data/lib/irb/extend-command.rb +113 -63
  33. data/lib/irb/frame.rb +12 -7
  34. data/lib/irb/help.rb +0 -1
  35. data/lib/irb/init.rb +146 -26
  36. data/lib/irb/input-method.rb +287 -9
  37. data/lib/irb/inspector.rb +15 -11
  38. data/lib/irb/lc/error.rb +55 -16
  39. data/lib/irb/lc/help-message +25 -13
  40. data/lib/irb/lc/ja/error.rb +55 -14
  41. data/lib/irb/lc/ja/help-message +11 -6
  42. data/lib/irb/locale.rb +13 -4
  43. data/lib/irb/notifier.rb +12 -8
  44. data/lib/irb/output-method.rb +6 -6
  45. data/lib/irb/ruby-lex.rb +673 -992
  46. data/lib/irb/ruby_logo.aa +37 -0
  47. data/lib/irb/version.rb +2 -2
  48. data/lib/irb/workspace.rb +65 -21
  49. data/lib/irb/xmp.rb +1 -1
  50. data/lib/irb.rb +276 -96
  51. data/man/irb.1 +229 -0
  52. metadata +25 -31
  53. data/.gitignore +0 -9
  54. data/.travis.yml +0 -6
  55. data/lib/irb/lc/.document +0 -4
  56. data/lib/irb/ruby-token.rb +0 -267
  57. data/lib/irb/slex.rb +0 -282
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
- # 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
-
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:
@@ -10,7 +10,7 @@
10
10
  #
11
11
  #
12
12
  Usage: irb.rb [options] [programfile] [arguments]
13
- -f Suppress read of ~/.irbrc
13
+ -f Suppress read of ~/.irbrc
14
14
  -d Set $DEBUG to true (same as `ruby -d')
15
15
  -r load-module Same as `ruby -r'
16
16
  -I path Specify $LOAD_PATH directory
@@ -18,28 +18,40 @@ Usage: irb.rb [options] [programfile] [arguments]
18
18
  -E enc Same as `ruby -E`
19
19
  -w Same as `ruby -w`
20
20
  -W[level=2] Same as `ruby -W`
21
- --context-mode n Set n[0-3] to method to create Binding Object,
21
+ --context-mode n Set n[0-4] to method to create Binding Object,
22
22
  when new workspace was created
23
- --echo Show result(default)
23
+ --extra-doc-dir Add an extra doc dir for the doc dialog
24
+ --echo Show result (default)
24
25
  --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
26
+ --echo-on-assignment
27
+ Show result on assignment
28
+ --noecho-on-assignment
29
+ Don't show result on assignment
30
+ --truncate-echo-on-assignment
31
+ Show truncated result on assignment (default)
32
+ --inspect Use `inspect' for output
33
+ --noinspect Don't use inspect for output
34
+ --multiline Use multiline editor module
35
+ --nomultiline Don't use multiline editor module
36
+ --singleline Use singleline editor module
37
+ --nosingleline Don't use singleline editor module
38
+ --colorize Use colorization
39
+ --nocolorize Don't use colorization
40
+ --autocomplete Use autocompletion
41
+ --noautocomplete Don't use autocompletion
29
42
  --prompt prompt-mode/--prompt-mode prompt-mode
30
- Switch prompt mode. Pre-defined prompt modes are
31
- `default', `simple', `xmp' and `inf-ruby'
43
+ Switch prompt mode. Pre-defined prompt modes are
44
+ `default', `simple', `xmp' and `inf-ruby'
32
45
  --inf-ruby-mode Use prompt appropriate for inf-ruby-mode on emacs.
33
- Suppresses --readline.
46
+ Suppresses --multiline and --singleline.
34
47
  --sample-book-mode/--simple-prompt
35
48
  Simple prompt mode
36
49
  --noprompt No prompt mode
37
50
  --single-irb Share self with sub-irb.
38
51
  --tracer Display trace for each execution of commands.
39
52
  --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)
53
+ Display backtrace top n and tail n. The default
54
+ value is 16.
43
55
  --verbose Show details
44
56
  --noverbose Don't show details
45
57
  -v, --version Print the version of irb
@@ -9,23 +9,64 @@
9
9
  #
10
10
  #
11
11
  #
12
- require "e2mmap"
13
12
 
14
13
  # :stopdoc:
15
14
  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が正しく定義されていません.'
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
@@ -21,16 +21,23 @@ Usage: irb.rb [options] [programfile] [arguments]
21
21
  オブジェクトの作成方法を 0 から 3 のいずれかに設定する.
22
22
  --echo 実行結果を表示する(デフォルト).
23
23
  --noecho 実行結果を表示しない.
24
- --inspect 結果出力にinspectを用いる(bcモード以外はデフォルト).
24
+ --inspect 結果出力にinspectを用いる.
25
25
  --noinspect 結果出力にinspectを用いない.
26
- --readline readlineライブラリを利用する.
27
- --noreadline readlineライブラリを利用しない.
26
+ --multiline マルチラインエディタを利用する.
27
+ --nomultiline マルチラインエディタを利用しない.
28
+ --singleline シングルラインエディタを利用する.
29
+ --nosingleline シングルラインエディタを利用しない.
30
+ --colorize 色付けを利用する.
31
+ --nocolorize 色付けを利用しない.
32
+ --autocomplete オートコンプリートを利用する.
33
+ --noautocomplete オートコンプリートを利用しない.
28
34
  --prompt prompt-mode/--prompt-mode prompt-mode
29
35
  プロンプトモードを切替えます. 現在定義されているプ
30
36
  ロンプトモードは, default, simple, xmp, inf-rubyが
31
37
  用意されています.
32
38
  --inf-ruby-mode emacsのinf-ruby-mode用のプロンプト表示を行なう. 特
33
- に指定がない限り, readlineライブラリは使わなくなる.
39
+ に指定がない限り, シングルラインエディタとマルチラ
40
+ インエディタは使わなくなる.
34
41
  --sample-book-mode/--simple-prompt
35
42
  非常にシンプルなプロンプトを用いるモードです.
36
43
  --noprompt プロンプト表示を行なわない.
@@ -41,8 +48,6 @@ Usage: irb.rb [options] [programfile] [arguments]
41
48
  バックトレース表示をバックトレースの頭から n, 後ろ
42
49
  からnだけ行なう. デフォルトは16
43
50
 
44
- --irb_debug n irbのデバッグレベルをnに設定する(非推奨).
45
-
46
51
  --verbose 詳細なメッセージを出力する.
47
52
  --noverbose 詳細なメッセージを出力しない(デフォルト).
48
53
  -v, --version irbのバージョンを表示する.
data/lib/irb/locale.rb CHANGED
@@ -21,8 +21,10 @@ 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)
27
+ @override_encoding = nil
26
28
  @lang = @territory = @encoding_name = @modifier = nil
27
29
  @locale = locale || ENV["IRB_LANG"] || ENV["LC_MESSAGES"] || ENV["LC_ALL"] || ENV["LANG"] || "C"
28
30
  if m = LOCALE_NAME_RE.match(@locale)
@@ -39,12 +41,16 @@ module IRB # :nodoc:
39
41
  @encoding ||= (Encoding.find('locale') rescue Encoding::ASCII_8BIT)
40
42
  end
41
43
 
42
- attr_reader :lang, :territory, :encoding, :modifier
44
+ attr_reader :lang, :territory, :modifier
45
+
46
+ def encoding
47
+ @override_encoding || @encoding
48
+ end
43
49
 
44
50
  def String(mes)
45
51
  mes = super(mes)
46
- if @encoding
47
- mes.encode(@encoding, undef: :replace)
52
+ if encoding
53
+ mes.encode(encoding, undef: :replace)
48
54
  else
49
55
  mes
50
56
  end
@@ -107,7 +113,10 @@ module IRB # :nodoc:
107
113
  def load(file, priv=nil)
108
114
  found = find(file)
109
115
  if found
110
- return real_load(found, priv)
116
+ unless @@loaded.include?(found)
117
+ @@loaded << found # cache
118
+ return real_load(found, priv)
119
+ end
111
120
  else
112
121
  raise LoadError, "No such file to load -- #{file}"
113
122
  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
- extend Exception2MessageMapper
20
- def_exception :ErrUndefinedNotifier,
21
- "undefined notifier level: %d is specified"
22
- def_exception :ErrUnrecognizedLevel,
23
- "unrecognized notifier level: %s is specified"
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
- Notifier.Raise ErrUndefinedNotifier, value unless l
169
+ raise ErrUndefinedNotifier, value unless l
166
170
  @level_notifier = l
167
171
  else
168
- Notifier.Raise ErrUnrecognizedLevel, value unless l
172
+ raise ErrUnrecognizedLevel, value unless l
169
173
  end
170
174
  end
171
175
 
@@ -10,21 +10,21 @@
10
10
  #
11
11
  #
12
12
 
13
- require "e2mmap"
14
-
15
13
  module IRB
16
14
  # An abstract output class for IO in irb. This is mainly used internally by
17
15
  # IRB::Notifier. You can define your own output method to use with Irb.new,
18
16
  # or Context.new
19
17
  class OutputMethod
20
- extend Exception2MessageMapper
21
- def_exception :NotImplementedError, "Need to define `%s'"
22
-
18
+ class NotImplementedError < StandardError
19
+ def initialize(val)
20
+ super("Need to define `#{val}'")
21
+ end
22
+ end
23
23
 
24
24
  # Open this method to implement your own output method, raises a
25
25
  # NotImplementedError if you don't define #print in your own class.
26
26
  def print(*opts)
27
- OutputMethod.Raise NotImplementedError, "print"
27
+ raise NotImplementedError, "print"
28
28
  end
29
29
 
30
30
  # Prints the given +opts+, with a newline delimiter.