irb 0.9.6

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,7 @@
1
+ # frozen_string_literal: false
2
+ # DO NOT WRITE ANY MAGIC COMMENT HERE.
3
+ module IRB
4
+ def self.default_src_encoding
5
+ return __ENCODING__
6
+ end
7
+ end
@@ -0,0 +1,17 @@
1
+ # frozen_string_literal: false
2
+ #
3
+ # irb/version.rb - irb version definition file
4
+ # $Release Version: 0.9.6$
5
+ # $Revision$
6
+ # by Keiju ISHITSUKA(keiju@ishitsuka.com)
7
+ #
8
+ # --
9
+ #
10
+ #
11
+ #
12
+
13
+ module IRB # :nodoc:
14
+ VERSION = "0.9.6"
15
+ @RELEASE_VERSION = VERSION
16
+ @LAST_UPDATE_DATE = "2009-06-30"
17
+ end
@@ -0,0 +1,143 @@
1
+ # frozen_string_literal: false
2
+ #
3
+ # irb/workspace-binding.rb -
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 WorkSpace
14
+ # Creates a new workspace.
15
+ #
16
+ # set self to main if specified, otherwise
17
+ # inherit main from TOPLEVEL_BINDING.
18
+ def initialize(*main)
19
+ if main[0].kind_of?(Binding)
20
+ @binding = main.shift
21
+ elsif IRB.conf[:SINGLE_IRB]
22
+ @binding = TOPLEVEL_BINDING
23
+ else
24
+ case IRB.conf[:CONTEXT_MODE]
25
+ when 0 # binding in proc on TOPLEVEL_BINDING
26
+ @binding = eval("proc{binding}.call",
27
+ TOPLEVEL_BINDING,
28
+ __FILE__,
29
+ __LINE__)
30
+ when 1 # binding in loaded file
31
+ require "tempfile"
32
+ f = Tempfile.open("irb-binding")
33
+ f.print <<EOF
34
+ $binding = binding
35
+ EOF
36
+ f.close
37
+ load f.path
38
+ @binding = $binding
39
+
40
+ when 2 # binding in loaded file(thread use)
41
+ unless defined? BINDING_QUEUE
42
+ IRB.const_set(:BINDING_QUEUE, Thread::SizedQueue.new(1))
43
+ Thread.abort_on_exception = true
44
+ Thread.start do
45
+ eval "require \"irb/ws-for-case-2\"", TOPLEVEL_BINDING, __FILE__, __LINE__
46
+ end
47
+ Thread.pass
48
+ end
49
+ @binding = BINDING_QUEUE.pop
50
+
51
+ when 3 # binding in function on TOPLEVEL_BINDING(default)
52
+ @binding = eval("def irb_binding; private; binding; end; irb_binding",
53
+ TOPLEVEL_BINDING,
54
+ __FILE__,
55
+ __LINE__ - 3)
56
+ end
57
+ end
58
+ if main.empty?
59
+ @main = eval("self", @binding)
60
+ else
61
+ @main = main[0]
62
+ IRB.conf[:__MAIN__] = @main
63
+ case @main
64
+ when Module
65
+ @binding = eval("IRB.conf[:__MAIN__].module_eval('binding', __FILE__, __LINE__)", @binding, __FILE__, __LINE__)
66
+ else
67
+ begin
68
+ @binding = eval("IRB.conf[:__MAIN__].instance_eval('binding', __FILE__, __LINE__)", @binding, __FILE__, __LINE__)
69
+ rescue TypeError
70
+ IRB.fail CantChangeBinding, @main.inspect
71
+ end
72
+ end
73
+ end
74
+ @binding.local_variable_set(:_, nil)
75
+ end
76
+
77
+ # The Binding of this workspace
78
+ attr_reader :binding
79
+ # The top-level workspace of this context, also available as
80
+ # <code>IRB.conf[:__MAIN__]</code>
81
+ attr_reader :main
82
+
83
+ # Evaluate the given +statements+ within the context of this workspace.
84
+ def evaluate(context, statements, file = __FILE__, line = __LINE__)
85
+ eval(statements, @binding, file, line)
86
+ end
87
+
88
+ def local_variable_set(name, value)
89
+ @binding.local_variable_set(name, value)
90
+ end
91
+
92
+ def local_variable_get(name)
93
+ @binding.local_variable_get(name)
94
+ end
95
+
96
+ # error message manipulator
97
+ def filter_backtrace(bt)
98
+ case IRB.conf[:CONTEXT_MODE]
99
+ when 0
100
+ return nil if bt =~ /\(irb_local_binding\)/
101
+ when 1
102
+ if(bt =~ %r!/tmp/irb-binding! or
103
+ bt =~ %r!irb/.*\.rb! or
104
+ bt =~ /irb\.rb/)
105
+ return nil
106
+ end
107
+ when 2
108
+ return nil if bt =~ /irb\/.*\.rb/
109
+ return nil if bt =~ /irb\.rb/
110
+ when 3
111
+ return nil if bt =~ /irb\/.*\.rb/
112
+ return nil if bt =~ /irb\.rb/
113
+ bt = bt.sub(/:\s*in `irb_binding'/, '')
114
+ end
115
+ bt
116
+ end
117
+
118
+ def code_around_binding
119
+ file, pos = @binding.source_location
120
+
121
+ unless defined?(::SCRIPT_LINES__[file]) && lines = ::SCRIPT_LINES__[file]
122
+ begin
123
+ lines = File.readlines(file)
124
+ rescue SystemCallError
125
+ return
126
+ end
127
+ end
128
+ pos -= 1
129
+
130
+ start_pos = [pos - 5, 0].max
131
+ end_pos = [pos + 5, lines.size - 1].min
132
+
133
+ fmt = " %2s %#{end_pos.to_s.length}d: %s"
134
+ body = (start_pos..end_pos).map do |current_pos|
135
+ sprintf(fmt, pos == current_pos ? '=>' : '', current_pos + 1, lines[current_pos])
136
+ end.join("")
137
+ "\nFrom: #{file} @ line #{pos + 1} :\n\n#{body}\n"
138
+ end
139
+
140
+ def IRB.delete_caller
141
+ end
142
+ end
143
+ end
@@ -0,0 +1,15 @@
1
+ # frozen_string_literal: false
2
+ #
3
+ # irb/ws-for-case-2.rb -
4
+ # $Release Version: 0.9.6$
5
+ # $Revision$
6
+ # by Keiju ISHITSUKA(keiju@ruby-lang.org)
7
+ #
8
+ # --
9
+ #
10
+ #
11
+ #
12
+
13
+ while true
14
+ IRB::BINDING_QUEUE.push _ = binding
15
+ end
@@ -0,0 +1,170 @@
1
+ # frozen_string_literal: false
2
+ #
3
+ # xmp.rb - irb version of gotoken xmp
4
+ # $Release Version: 0.9$
5
+ # $Revision$
6
+ # by Keiju ISHITSUKA(Nippon Rational Inc.)
7
+ #
8
+ # --
9
+ #
10
+ #
11
+ #
12
+
13
+ require "irb"
14
+ require_relative "frame"
15
+
16
+ # An example printer for irb.
17
+ #
18
+ # It's much like the standard library PrettyPrint, that shows the value of each
19
+ # expression as it runs.
20
+ #
21
+ # In order to use this library, you must first require it:
22
+ #
23
+ # require 'irb/xmp'
24
+ #
25
+ # Now, you can take advantage of the Object#xmp convenience method.
26
+ #
27
+ # xmp <<END
28
+ # foo = "bar"
29
+ # baz = 42
30
+ # END
31
+ # #=> foo = "bar"
32
+ # #==>"bar"
33
+ # #=> baz = 42
34
+ # #==>42
35
+ #
36
+ # You can also create an XMP object, with an optional binding to print
37
+ # expressions in the given binding:
38
+ #
39
+ # ctx = binding
40
+ # x = XMP.new ctx
41
+ # x.puts
42
+ # #=> today = "a good day"
43
+ # #==>"a good day"
44
+ # ctx.eval 'today # is what?'
45
+ # #=> "a good day"
46
+ class XMP
47
+
48
+ # Creates a new XMP object.
49
+ #
50
+ # The top-level binding or, optional +bind+ parameter will be used when
51
+ # creating the workspace. See WorkSpace.new for more information.
52
+ #
53
+ # This uses the +:XMP+ prompt mode, see IRB@Customizing+the+IRB+Prompt for
54
+ # full detail.
55
+ def initialize(bind = nil)
56
+ IRB.init_config(nil)
57
+
58
+ IRB.conf[:PROMPT_MODE] = :XMP
59
+
60
+ bind = IRB::Frame.top(1) unless bind
61
+ ws = IRB::WorkSpace.new(bind)
62
+ @io = StringInputMethod.new
63
+ @irb = IRB::Irb.new(ws, @io)
64
+ @irb.context.ignore_sigint = false
65
+
66
+ IRB.conf[:MAIN_CONTEXT] = @irb.context
67
+ end
68
+
69
+ # Evaluates the given +exps+, for example:
70
+ #
71
+ # require 'irb/xmp'
72
+ # x = XMP.new
73
+ #
74
+ # x.puts '{:a => 1, :b => 2, :c => 3}'
75
+ # #=> {:a => 1, :b => 2, :c => 3}
76
+ # # ==>{:a=>1, :b=>2, :c=>3}
77
+ # x.puts 'foo = "bar"'
78
+ # # => foo = "bar"
79
+ # # ==>"bar"
80
+ def puts(exps)
81
+ @io.puts exps
82
+
83
+ if @irb.context.ignore_sigint
84
+ begin
85
+ trap_proc_b = trap("SIGINT"){@irb.signal_handle}
86
+ catch(:IRB_EXIT) do
87
+ @irb.eval_input
88
+ end
89
+ ensure
90
+ trap("SIGINT", trap_proc_b)
91
+ end
92
+ else
93
+ catch(:IRB_EXIT) do
94
+ @irb.eval_input
95
+ end
96
+ end
97
+ end
98
+
99
+ # A custom InputMethod class used by XMP for evaluating string io.
100
+ class StringInputMethod < IRB::InputMethod
101
+ # Creates a new StringInputMethod object
102
+ def initialize
103
+ super
104
+ @exps = []
105
+ end
106
+
107
+ # Whether there are any expressions left in this printer.
108
+ def eof?
109
+ @exps.empty?
110
+ end
111
+
112
+ # Reads the next expression from this printer.
113
+ #
114
+ # See IO#gets for more information.
115
+ def gets
116
+ while l = @exps.shift
117
+ next if /^\s+$/ =~ l
118
+ l.concat "\n"
119
+ print @prompt, l
120
+ break
121
+ end
122
+ l
123
+ end
124
+
125
+ # Concatenates all expressions in this printer, separated by newlines.
126
+ #
127
+ # An Encoding::CompatibilityError is raised of the given +exps+'s encoding
128
+ # doesn't match the previous expression evaluated.
129
+ def puts(exps)
130
+ if @encoding and exps.encoding != @encoding
131
+ enc = Encoding.compatible?(@exps.join("\n"), exps)
132
+ if enc.nil?
133
+ raise Encoding::CompatibilityError, "Encoding in which the passed expression is encoded is not compatible to the preceding's one"
134
+ else
135
+ @encoding = enc
136
+ end
137
+ else
138
+ @encoding = exps.encoding
139
+ end
140
+ @exps.concat exps.split(/\n/)
141
+ end
142
+
143
+ # Returns the encoding of last expression printed by #puts.
144
+ attr_reader :encoding
145
+ end
146
+ end
147
+
148
+ # A convenience method that's only available when the you require the IRB::XMP standard library.
149
+ #
150
+ # Creates a new XMP object, using the given expressions as the +exps+
151
+ # parameter, and optional binding as +bind+ or uses the top-level binding. Then
152
+ # evaluates the given expressions using the +:XMP+ prompt mode.
153
+ #
154
+ # For example:
155
+ #
156
+ # require 'irb/xmp'
157
+ # ctx = binding
158
+ # xmp 'foo = "bar"', ctx
159
+ # #=> foo = "bar"
160
+ # #==>"bar"
161
+ # ctx.eval 'foo'
162
+ # #=> "bar"
163
+ #
164
+ # See XMP.new for more information.
165
+ def xmp(exps, bind = nil)
166
+ bind = IRB::Frame.top(1) unless bind
167
+ xmp = XMP.new(bind)
168
+ xmp.puts exps
169
+ xmp
170
+ end
metadata ADDED
@@ -0,0 +1,125 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: irb
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.9.6
5
+ platform: ruby
6
+ authors:
7
+ - Keiju ISHITSUKA
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2018-12-04 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ description: Interactive Ruby command-line tool for REPL (Read Eval Print Loop).
42
+ email:
43
+ - keiju@ruby-lang.org
44
+ executables:
45
+ - irb
46
+ extensions: []
47
+ extra_rdoc_files: []
48
+ files:
49
+ - ".gitignore"
50
+ - ".travis.yml"
51
+ - Gemfile
52
+ - LICENSE.txt
53
+ - README.md
54
+ - Rakefile
55
+ - bin/console
56
+ - bin/setup
57
+ - exe/irb
58
+ - irb.gemspec
59
+ - lib/irb.rb
60
+ - lib/irb/cmd/chws.rb
61
+ - lib/irb/cmd/fork.rb
62
+ - lib/irb/cmd/help.rb
63
+ - lib/irb/cmd/load.rb
64
+ - lib/irb/cmd/nop.rb
65
+ - lib/irb/cmd/pushws.rb
66
+ - lib/irb/cmd/subirb.rb
67
+ - lib/irb/completion.rb
68
+ - lib/irb/context.rb
69
+ - lib/irb/ext/change-ws.rb
70
+ - lib/irb/ext/history.rb
71
+ - lib/irb/ext/loader.rb
72
+ - lib/irb/ext/multi-irb.rb
73
+ - lib/irb/ext/save-history.rb
74
+ - lib/irb/ext/tracer.rb
75
+ - lib/irb/ext/use-loader.rb
76
+ - lib/irb/ext/workspaces.rb
77
+ - lib/irb/extend-command.rb
78
+ - lib/irb/frame.rb
79
+ - lib/irb/help.rb
80
+ - lib/irb/init.rb
81
+ - lib/irb/input-method.rb
82
+ - lib/irb/inspector.rb
83
+ - lib/irb/lc/.document
84
+ - lib/irb/lc/error.rb
85
+ - lib/irb/lc/help-message
86
+ - lib/irb/lc/ja/encoding_aliases.rb
87
+ - lib/irb/lc/ja/error.rb
88
+ - lib/irb/lc/ja/help-message
89
+ - lib/irb/locale.rb
90
+ - lib/irb/magic-file.rb
91
+ - lib/irb/notifier.rb
92
+ - lib/irb/output-method.rb
93
+ - lib/irb/ruby-lex.rb
94
+ - lib/irb/ruby-token.rb
95
+ - lib/irb/slex.rb
96
+ - lib/irb/src_encoding.rb
97
+ - lib/irb/version.rb
98
+ - lib/irb/workspace.rb
99
+ - lib/irb/ws-for-case-2.rb
100
+ - lib/irb/xmp.rb
101
+ homepage: https://github.com/ruby/irb
102
+ licenses:
103
+ - BSD-2-Clause
104
+ metadata: {}
105
+ post_install_message:
106
+ rdoc_options: []
107
+ require_paths:
108
+ - lib
109
+ required_ruby_version: !ruby/object:Gem::Requirement
110
+ requirements:
111
+ - - ">="
112
+ - !ruby/object:Gem::Version
113
+ version: '0'
114
+ required_rubygems_version: !ruby/object:Gem::Requirement
115
+ requirements:
116
+ - - ">="
117
+ - !ruby/object:Gem::Version
118
+ version: '0'
119
+ requirements: []
120
+ rubyforge_project:
121
+ rubygems_version: 2.7.6
122
+ signing_key:
123
+ specification_version: 4
124
+ summary: Interactive Ruby command-line tool for REPL (Read Eval Print Loop).
125
+ test_files: []