aboutsummaryrefslogtreecommitdiffstats
path: root/lib/irb.rb
diff options
context:
space:
mode:
authorkeiju <keiju@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2002-07-09 11:17:17 +0000
committerkeiju <keiju@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2002-07-09 11:17:17 +0000
commitaf064b04b1622897995fe1177aabfb60db90e6f7 (patch)
tree326cb343c08c55d2d93fa5223c01f940d3591f8b /lib/irb.rb
parent93602810e93b5da1c7161fb4b5c1a4025434a9ce (diff)
downloadruby-af064b04b1622897995fe1177aabfb60db90e6f7.tar.gz
* irb 0.9
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@2627 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'lib/irb.rb')
-rw-r--r--lib/irb.rb136
1 files changed, 79 insertions, 57 deletions
diff --git a/lib/irb.rb b/lib/irb.rb
index 1b8444b5b3..b5f12a66f8 100644
--- a/lib/irb.rb
+++ b/lib/irb.rb
@@ -1,6 +1,6 @@
#
# irb.rb - irb main module
-# $Release Version: 0.7.4 $
+# $Release Version: 0.9 $
# $Revision$
# $Date$
# by Keiju ISHITSUKA(keiju@ishitsuka.com)
@@ -14,7 +14,7 @@ require "e2mmap"
require "irb/init"
require "irb/context"
require "irb/extend-command"
-require "irb/workspace"
+#require "irb/workspace"
require "irb/ruby-lex"
require "irb/input-method"
@@ -43,13 +43,15 @@ module IRB
@CONF[:VERSION] = format("irb %s(%s)", rv, @LAST_UPDATE_DATE)
end
+ def IRB.CurrentContext
+ IRB.conf[:MAIN_CONTEXT]
+ end
+
# initialize IRB and start TOP_LEVEL irb
def IRB.start(ap_path = nil)
$0 = File::basename(ap_path, ".rb") if ap_path
IRB.initialize(ap_path)
- IRB.parse_opts
- IRB.load_modules
if @CONF[:SCRIPT]
irb = Irb.new(nil, @CONF[:SCRIPT])
@@ -67,7 +69,7 @@ module IRB
catch(:IRB_EXIT) do
irb.eval_input
end
- print "\n"
+# print "\n"
end
def IRB.irb_exit(irb, ret)
@@ -88,7 +90,7 @@ module IRB
class Irb
def initialize(workspace = nil, input_method = nil)
@context = Context.new(self, workspace, input_method)
- @context.main.extend ExtendCommand
+ @context.main.extend ExtendCommandBundle
@signal_status = :IN_IRB
@scanner = RubyLex.new
@@ -98,20 +100,6 @@ module IRB
attr_accessor :scanner
def eval_input
- @scanner.set_input(@context.io) do
- signal_status(:IN_INPUT) do
- unless l = @context.io.gets
- if @context.ignore_eof? and @context.io.readable_atfer_eof?
- l = "\n"
- if @context.verbose?
- printf "Use \"exit\" to leave %s\n", @context.ap_name
- end
- end
- end
- l
- end
- end
-
@scanner.set_prompt do
|ltype, indent, continue, line_no|
if ltype
@@ -122,7 +110,11 @@ module IRB
f = @context.prompt_i
end
f = "" unless f
- @context.io.prompt = p = prompt(f, ltype, indent, line_no)
+ if @context.prompting?
+ @context.io.prompt = p = prompt(f, ltype, indent, line_no)
+ else
+ @context.io.prompt = p = ""
+ end
if @context.auto_indent_mode
unless ltype
ind = prompt(@context.prompt_i, ltype, indent, line_no).size +
@@ -133,22 +125,28 @@ module IRB
end
end
+ @scanner.set_input(@context.io) do
+ signal_status(:IN_INPUT) do
+ if l = @context.io.gets
+ print l if @context.verbose?
+ else
+ if @context.ignore_eof? and @context.io.readable_atfer_eof?
+ l = "\n"
+ if @context.verbose?
+ printf "Use \"exit\" to leave %s\n", @context.ap_name
+ end
+ end
+ end
+ l
+ end
+ end
+
@scanner.each_top_level_statement do
|line, line_no|
signal_status(:IN_EVAL) do
begin
- trace_in do
- @context._ = @context.workspace.evaluate(line,
- @context.irb_path,
- line_no)
-# @context._ = irb_eval(line, @context.bind, @context.irb_path, line_no)
- end
-
- if @context.inspect?
- printf @context.return_format, @context._.inspect
- else
- printf @context.return_format, @context._
- end
+ @context.evaluate(line, line_no)
+ output_value if @context.echo?
rescue StandardError, ScriptError, Abort
$! = RuntimeError.new("unknown exception raised") unless $!
print $!.type, ": ", $!, "\n"
@@ -186,19 +184,44 @@ module IRB
end
end
-# def irb_eval(line, bind, path, line_no)
-# id, str = catch(:IRB_TOPLEVEL_EVAL){
-# return eval(line, bind, path, line_no)
-# }
-# case id
-# when :EVAL_TOPLEVEL
-# eval(str, bind, "(irb_internal)", 1)
-# when :EVAL_CONTEXT
-# @context.instance_eval(str)
-# else
-# IRB.fail IllegalParameter
-# end
-# end
+ def suspend_name(path = nil, name = nil)
+ @context.irb_path, back_path = path, @context.irb_path if path
+ @context.irb_name, back_name = name, @context.irb_name if name
+ begin
+ yield back_path, back_name
+ ensure
+ @context.irb_path = back_path if path
+ @context.irb_name = back_name if name
+ end
+ end
+
+ def suspend_workspace(workspace)
+ @context.workspace, back_workspace = workspace, @context.workspace
+ begin
+ yield back_workspace
+ ensure
+ @context.workspace = back_workspace
+ end
+ end
+
+ def suspend_input_method(input_method)
+ back_io = @context.io
+ @context.instance_eval{@io = input_method}
+ begin
+ yield back_io
+ ensure
+ @context.instance_eval{@io = back_io}
+ end
+ end
+
+ def suspend_context(context)
+ @context, back_context = context, @context
+ begin
+ yield back_context
+ ensure
+ @context = back_context
+ end
+ end
def signal_handle
unless @context.ignore_sigint?
@@ -233,15 +256,6 @@ module IRB
end
end
- def trace_in
- Tracer.on if @context.use_tracer?
- begin
- yield
- ensure
- Tracer.off if @context.use_tracer?
- end
- end
-
def prompt(prompt, ltype, indent, line_no)
p = prompt.dup
p.gsub!(/%([0-9]+)?([a-zA-Z])/) do
@@ -273,6 +287,14 @@ module IRB
p
end
+ def output_value
+ if @context.inspect?
+ printf @context.return_format, @context.last_value.inspect
+ else
+ printf @context.return_format, @context.last_value
+ end
+ end
+
def inspect
ary = []
for iv in instance_variables
@@ -296,8 +318,8 @@ module IRB
array = []
for k, v in sort{|a1, a2| a1[0].id2name <=> a2[0].id2name}
case k
- when :MAIN_CONTEXT
- next
+ when :MAIN_CONTEXT, :__TMP__EHV__
+ array.push format("CONF[:%s]=...myself...", k.id2name)
when :PROMPT
s = v.collect{
|kk, vv|