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.
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,120 @@
1
+ #
2
+ # irb/input-method.rb - input methods used irb
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
+ # InputMethod
15
+ # StdioInputMethod
16
+ # FileInputMethod
17
+ # (ReadlineInputMethod)
18
+ #
19
+ STDIN_FILE_NAME = "(line)"
20
+ class InputMethod
21
+ @RCS_ID='-$Id: input-method.rb 11708 2007-02-12 23:01:19Z shyouhei $-'
22
+
23
+ def initialize(file = STDIN_FILE_NAME)
24
+ @file_name = file
25
+ end
26
+ attr_reader :file_name
27
+
28
+ attr_accessor :prompt
29
+
30
+ def gets
31
+ IRB.fail NotImplementedError, "gets"
32
+ end
33
+ public :gets
34
+
35
+ def readable_atfer_eof?
36
+ false
37
+ end
38
+ end
39
+
40
+ class StdioInputMethod < InputMethod
41
+ def initialize
42
+ super
43
+ @line_no = 0
44
+ @line = []
45
+ end
46
+
47
+ def gets
48
+ print @prompt
49
+ @line[@line_no += 1] = $stdin.gets
50
+ end
51
+
52
+ def eof?
53
+ $stdin.eof?
54
+ end
55
+
56
+ def readable_atfer_eof?
57
+ true
58
+ end
59
+
60
+ def line(line_no)
61
+ @line[line_no]
62
+ end
63
+ end
64
+
65
+ class FileInputMethod < InputMethod
66
+ def initialize(file)
67
+ super
68
+ @io = open(file)
69
+ end
70
+ attr_reader :file_name
71
+
72
+ def eof?
73
+ @io.eof?
74
+ end
75
+
76
+ def gets
77
+ print @prompt
78
+ l = @io.gets
79
+ # print @prompt, l
80
+ l
81
+ end
82
+ end
83
+
84
+ begin
85
+ require "readline"
86
+ class ReadlineInputMethod < InputMethod
87
+ include Readline
88
+ def initialize
89
+ super
90
+
91
+ @line_no = 0
92
+ @line = []
93
+ @eof = false
94
+ end
95
+
96
+ def gets
97
+ if l = readline(@prompt, false)
98
+ HISTORY.push(l) if !l.empty?
99
+ @line[@line_no += 1] = l + "\n"
100
+ else
101
+ @eof = true
102
+ l
103
+ end
104
+ end
105
+
106
+ def eof?
107
+ @eof
108
+ end
109
+
110
+ def readable_atfer_eof?
111
+ true
112
+ end
113
+
114
+ def line(line_no)
115
+ @line[line_no]
116
+ end
117
+ end
118
+ rescue LoadError
119
+ end
120
+ end
@@ -0,0 +1,30 @@
1
+ #
2
+ # irb/lc/error.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
+ require "e2mmap"
13
+
14
+ module IRB
15
+
16
+ # exceptions
17
+ extend Exception2MessageMapper
18
+ def_exception :UnrecognizedSwitch, "Unrecognized switch: %s"
19
+ def_exception :NotImplementedError, "Need to define `%s'"
20
+ def_exception :CantReturnToNormalMode, "Can't return to normal mode."
21
+ def_exception :IllegalParameter, "Illegal parameter(%s)."
22
+ def_exception :IrbAlreadyDead, "Irb is already dead."
23
+ def_exception :IrbSwitchedToCurrentThread, "Switched to current thread."
24
+ def_exception :NoSuchJob, "No such job(%s)."
25
+ def_exception :CantShiftToMultiIrbMode, "Can't shift to multi irb mode."
26
+ def_exception :CantChangeBinding, "Can't change binding to (%s)."
27
+ def_exception :UndefinedPromptMode, "Undefined prompt mode(%s)."
28
+
29
+ end
30
+
@@ -0,0 +1,37 @@
1
+ #
2
+ # irb/lc/help-message.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
+ <<HELP
13
+ Usage: irb.rb [options] [programfile] [arguments]
14
+ -f Suppress read of ~/.irbrc
15
+ -m Bc mode (load mathn, fraction or matrix are available)
16
+ -d Set $DEBUG to true (same as `ruby -d')
17
+ -r load-module Same as `ruby -r'
18
+ -I path Specify $LOAD_PATH directory
19
+ --inspect Use `inspect' for output (default except for bc mode)
20
+ --noinspect Don't use inspect for output
21
+ --readline Use Readline extension module
22
+ --noreadline Don't use Readline extension module
23
+ --prompt prompt-mode
24
+ --prompt-mode prompt-mode
25
+ Switch prompt mode. Pre-defined prompt modes are
26
+ `default', `simple', `xmp' and `inf-ruby'
27
+ --inf-ruby-mode Use prompt appropriate for inf-ruby-mode on emacs.
28
+ Suppresses --readline.
29
+ --simple-prompt Simple prompt mode
30
+ --noprompt No prompt mode
31
+ --tracer Display trace for each execution of commands.
32
+ --back-trace-limit n
33
+ Display backtrace top n and tail n. The default
34
+ value is 16.
35
+ --irb_debug n Set internal debug level to n (not for popular use)
36
+ -v, --version Print the version of irb
37
+ HELP
@@ -0,0 +1,27 @@
1
+ #
2
+ # irb/lc/ja/error.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
+ require "e2mmap"
13
+
14
+ module IRB
15
+ # exceptions
16
+ extend Exception2MessageMapper
17
+ def_exception :UnrecognizedSwitch, '$B%9%$%C%A(B(%s)$B$,J,$j$^$;$s(B'
18
+ def_exception :NotImplementedError, '`%s\'$B$NDj5A$,I,MW$G$9(B'
19
+ def_exception :CantReturnToNormalMode, 'Normal$B%b!<%I$KLa$l$^$;$s(B.'
20
+ def_exception :IllegalParameter, '$B%Q%i%a!<%?(B(%s)$B$,4V0c$C$F$$$^$9(B.'
21
+ def_exception :IrbAlreadyDead, 'Irb$B$O4{$K;`$s$G$$$^$9(B.'
22
+ def_exception :IrbSwitchedToCurrentThread, '$B%+%l%s%H%9%l%C%I$K@Z$jBX$o$j$^$7$?(B.'
23
+ def_exception :NoSuchJob, '$B$=$N$h$&$J%8%g%V(B(%s)$B$O$"$j$^$;$s(B.'
24
+ def_exception :CantShiftToMultiIrbMode, 'multi-irb mode$B$K0\$l$^$;$s(B.'
25
+ def_exception :CantChangeBinding, '$B%P%$%s%G%#%s%0(B(%s)$B$KJQ99$G$-$^$;$s(B.'
26
+ def_exception :UndefinedPromptMode, '$B%W%m%s%W%H%b!<%I(B(%s)$B$ODj5A$5$l$F$$$^$;$s(B.'
27
+ end
@@ -0,0 +1,36 @@
1
+ #
2
+ # irb/lc/ja/help-message.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
+ Usage: irb.rb [options] [programfile] [arguments]
13
+ -f ~/.irbrc $B$rFI$_9~$^$J$$(B.
14
+ -m bc$B%b!<%I(B($BJ,?t(B, $B9TNs$N7W;;$,$G$-$k(B)
15
+ -d $DEBUG $B$r(Btrue$B$K$9$k(B(ruby -d $B$HF1$8(B)
16
+ -r load-module ruby -r $B$HF1$8(B.
17
+ -I path $LOAD_PATH $B$K(B path $B$rDI2C$9$k(B.
18
+ --inspect $B7k2L=PNO$K(Binspect$B$rMQ$$$k(B(bc$B%b!<%I0J30$O%G%U%)%k%H(B).
19
+ --noinspect $B7k2L=PNO$K(Binspect$B$rMQ$$$J$$(B.
20
+ --readline readline$B%i%$%V%i%j$rMxMQ$9$k(B.
21
+ --noreadline readline$B%i%$%V%i%j$rMxMQ$7$J$$(B.
22
+ --prompt prompt-mode/--prompt-mode prompt-mode
23
+ $B%W%m%s%W%H%b!<%I$r@ZBX$($^$9(B. $B8=:_Dj5A$5$l$F$$$k%W(B
24
+ $B%m%s%W%H%b!<%I$O(B, default, simple, xmp, inf-ruby$B$,(B
25
+ $BMQ0U$5$l$F$$$^$9(B.
26
+ --inf-ruby-mode emacs$B$N(Binf-ruby-mode$BMQ$N%W%m%s%W%HI=<($r9T$J$&(B. $BFC(B
27
+ $B$K;XDj$,$J$$8B$j(B, readline$B%i%$%V%i%j$O;H$o$J$/$J$k(B.
28
+ --simple-prompt $BHs>o$K%7%s%W%k$J%W%m%s%W%H$rMQ$$$k%b!<%I$G$9(B.
29
+ --noprompt $B%W%m%s%W%HI=<($r9T$J$o$J$$(B.
30
+ --tracer $B%3%^%s%I<B9T;~$K%H%l!<%9$r9T$J$&(B.
31
+ --back-trace-limit n
32
+ $B%P%C%/%H%l!<%9I=<($r%P%C%/%H%l!<%9$NF,$+$i(B n, $B8e$m(B
33
+ $B$+$i(Bn$B$@$19T$J$&(B. $B%G%U%)%k%H$O(B16
34
+ --irb_debug n irb$B$N%G%P%C%0%G%P%C%0%l%Y%k$r(Bn$B$K@_Dj$9$k(B($BMxMQ$7$J(B
35
+ $B$$J}$,L5Fq$G$7$g$&(B).
36
+ -v, --version irb$B$N%P!<%8%g%s$rI=<($9$k(B
data/lib/irb/locale.rb ADDED
@@ -0,0 +1,184 @@
1
+ #
2
+ # irb/locale.rb - internationalization 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
+ autoload :Kconv, "kconv"
14
+
15
+ module IRB
16
+ class Locale
17
+ @RCS_ID='-$Id: locale.rb 11708 2007-02-12 23:01:19Z shyouhei $-'
18
+
19
+ JPDefaultLocale = "ja"
20
+ LOCALE_DIR = "/lc/"
21
+
22
+ def initialize(locale = nil)
23
+ @lang = locale || ENV["IRB_LANG"] || ENV["LC_MESSAGES"] || ENV["LC_ALL"] || ENV["LANG"] || "C"
24
+ end
25
+
26
+ attr_reader :lang
27
+
28
+ def lc2kconv(lang)
29
+ case lang
30
+ when "ja_JP.ujis", "ja_JP.euc", "ja_JP.eucJP"
31
+ Kconv::EUC
32
+ when "ja_JP.sjis", "ja_JP.SJIS"
33
+ Kconv::SJIS
34
+ when /ja_JP.utf-?8/i
35
+ Kconv::UTF8
36
+ end
37
+ end
38
+ private :lc2kconv
39
+
40
+ def String(mes)
41
+ mes = super(mes)
42
+ case @lang
43
+ when /^ja/
44
+ mes = Kconv::kconv(mes, lc2kconv(@lang))
45
+ else
46
+ mes
47
+ end
48
+ mes
49
+ end
50
+
51
+ def format(*opts)
52
+ String(super(*opts))
53
+ end
54
+
55
+ def gets(*rs)
56
+ String(super(*rs))
57
+ end
58
+
59
+ def readline(*rs)
60
+ String(super(*rs))
61
+ end
62
+
63
+ def print(*opts)
64
+ ary = opts.collect{|opt| String(opt)}
65
+ super(*ary)
66
+ end
67
+
68
+ def printf(*opts)
69
+ s = format(*opts)
70
+ print s
71
+ end
72
+
73
+ def puts(*opts)
74
+ ary = opts.collect{|opt| String(opt)}
75
+ super(*ary)
76
+ end
77
+
78
+ def require(file, priv = nil)
79
+ rex = Regexp.new("lc/#{Regexp.quote(file)}\.(so|o|sl|rb)?")
80
+ return false if $".find{|f| f =~ rex}
81
+
82
+ case file
83
+ when /\.rb$/
84
+ begin
85
+ load(file, priv)
86
+ $".push file
87
+ return true
88
+ rescue LoadError
89
+ end
90
+ when /\.(so|o|sl)$/
91
+ return super
92
+ end
93
+
94
+ begin
95
+ load(f = file + ".rb")
96
+ $".push f #"
97
+ return true
98
+ rescue LoadError
99
+ return ruby_require(file)
100
+ end
101
+ end
102
+
103
+ alias toplevel_load load
104
+
105
+ def load(file, priv=nil)
106
+ dir = File.dirname(file)
107
+ dir = "" if dir == "."
108
+ base = File.basename(file)
109
+
110
+ if /^ja(_JP)?$/ =~ @lang
111
+ back, @lang = @lang, "C"
112
+ end
113
+ begin
114
+ if dir[0] == ?/ #/
115
+ lc_path = search_file(dir, base)
116
+ return real_load(lc_path, priv) if lc_path
117
+ end
118
+
119
+ for path in $:
120
+ lc_path = search_file(path + "/" + dir, base)
121
+ return real_load(lc_path, priv) if lc_path
122
+ end
123
+ ensure
124
+ @lang = back if back
125
+ end
126
+ raise LoadError, "No such file to load -- #{file}"
127
+ end
128
+
129
+ def real_load(path, priv)
130
+ src = self.String(File.read(path))
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
+ private :real_load
138
+
139
+ def find(file , paths = $:)
140
+ dir = File.dirname(file)
141
+ dir = "" if dir == "."
142
+ base = File.basename(file)
143
+ if dir[0] == ?/ #/
144
+ return lc_path = search_file(dir, base)
145
+ else
146
+ for path in $:
147
+ if lc_path = search_file(path + "/" + dir, base)
148
+ return lc_path
149
+ end
150
+ end
151
+ end
152
+ nil
153
+ end
154
+
155
+ def search_file(path, file)
156
+ if File.exist?(p1 = path + lc_path(file, "C"))
157
+ if File.exist?(p2 = path + lc_path(file))
158
+ return p2
159
+ else
160
+ end
161
+ return p1
162
+ else
163
+ end
164
+ nil
165
+ end
166
+ private :search_file
167
+
168
+ def lc_path(file = "", lc = @lang)
169
+ case lc
170
+ when "C"
171
+ LOCALE_DIR + file
172
+ when /^ja/
173
+ LOCALE_DIR + "ja/" + file
174
+ else
175
+ LOCALE_DIR + @lang + "/" + file
176
+ end
177
+ end
178
+ private :lc_path
179
+ end
180
+ end
181
+
182
+
183
+
184
+
@@ -0,0 +1,145 @@
1
+ #
2
+ # notifier.rb - optput methods used by irb
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
+ require "e2mmap"
14
+ require "irb/output-method"
15
+
16
+ module IRB
17
+ module Notifier
18
+ extend Exception2MessageMapper
19
+ def_exception :ErrUndefinedNotifier,
20
+ "undefined notifier level: %d is specified"
21
+ def_exception :ErrUnrecognizedLevel,
22
+ "unrecognized notifier level: %s is specified"
23
+
24
+ def def_notifier(prefix = "", output_method = StdioOutputMethod.new)
25
+ CompositeNotifier.new(prefix, output_method)
26
+ end
27
+ module_function :def_notifier
28
+
29
+ class AbstructNotifier
30
+ def initialize(prefix, base_notifier)
31
+ @prefix = prefix
32
+ @base_notifier = base_notifier
33
+ end
34
+
35
+ attr_reader :prefix
36
+
37
+ def notify?
38
+ true
39
+ end
40
+
41
+ def print(*opts)
42
+ @base_notifier.print prefix, *opts if notify?
43
+ end
44
+
45
+ def printn(*opts)
46
+ @base_notifier.printn prefix, *opts if notify?
47
+ end
48
+
49
+ def printf(format, *opts)
50
+ @base_notifier.printf(prefix + format, *opts) if notify?
51
+ end
52
+
53
+ def puts(*objs)
54
+ if notify?
55
+ @base_notifier.puts(*objs.collect{|obj| prefix + obj.to_s})
56
+ end
57
+ end
58
+
59
+ def pp(*objs)
60
+ if notify?
61
+ @base_notifier.ppx @prefix, *objs
62
+ end
63
+ end
64
+
65
+ def ppx(prefix, *objs)
66
+ if notify?
67
+ @base_notifier.ppx @prefix+prefix, *objs
68
+ end
69
+ end
70
+
71
+ def exec_if
72
+ yield(@base_notifier) if notify?
73
+ end
74
+ end
75
+
76
+ class CompositeNotifier<AbstructNotifier
77
+ def initialize(prefix, base_notifier)
78
+ super
79
+
80
+ @notifiers = [D_NOMSG]
81
+ @level_notifier = D_NOMSG
82
+ end
83
+
84
+ attr_reader :notifiers
85
+
86
+ def def_notifier(level, prefix = "")
87
+ notifier = LeveledNotifier.new(self, level, prefix)
88
+ @notifiers[level] = notifier
89
+ notifier
90
+ end
91
+
92
+ attr_reader :level_notifier
93
+ alias level level_notifier
94
+
95
+ def level_notifier=(value)
96
+ case value
97
+ when AbstructNotifier
98
+ @level_notifier = value
99
+ when Integer
100
+ l = @notifiers[value]
101
+ Notifier.Raise ErrUndefinedNotifer, value unless l
102
+ @level_notifier = l
103
+ else
104
+ Notifier.Raise ErrUnrecognizedLevel, value unless l
105
+ end
106
+ end
107
+
108
+ alias level= level_notifier=
109
+ end
110
+
111
+ class LeveledNotifier<AbstructNotifier
112
+ include Comparable
113
+
114
+ def initialize(base, level, prefix)
115
+ super(prefix, base)
116
+
117
+ @level = level
118
+ end
119
+
120
+ attr_reader :level
121
+
122
+ def <=>(other)
123
+ @level <=> other.level
124
+ end
125
+
126
+ def notify?
127
+ @base_notifier.level >= self
128
+ end
129
+ end
130
+
131
+ class NoMsgNotifier<LeveledNotifier
132
+ def initialize
133
+ @base_notifier = nil
134
+ @level = 0
135
+ @prefix = ""
136
+ end
137
+
138
+ def notify?
139
+ false
140
+ end
141
+ end
142
+
143
+ D_NOMSG = NoMsgNotifier.new
144
+ end
145
+ end