summaryrefslogtreecommitdiff
path: root/lib
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
parent93602810e93b5da1c7161fb4b5c1a4025434a9ce (diff)
* irb 0.9
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@2627 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'lib')
-rw-r--r--lib/irb.rb136
-rw-r--r--lib/irb/cmd/chws.rb33
-rw-r--r--lib/irb/cmd/fork.rb25
-rw-r--r--lib/irb/cmd/load.rb67
-rw-r--r--lib/irb/cmd/nop.rb39
-rw-r--r--lib/irb/cmd/pushws.rb39
-rw-r--r--lib/irb/cmd/subirb.rb43
-rw-r--r--lib/irb/completion.rb21
-rw-r--r--lib/irb/context.rb164
-rw-r--r--lib/irb/ext/change-ws.rb62
-rw-r--r--lib/irb/ext/history.rb110
-rw-r--r--lib/irb/ext/loader.rb106
-rw-r--r--lib/irb/ext/math-mode.rb37
-rw-r--r--lib/irb/ext/multi-irb.rb (renamed from lib/irb/multi-irb.rb)39
-rw-r--r--lib/irb/ext/tracer.rb61
-rw-r--r--lib/irb/ext/use-loader.rb65
-rw-r--r--lib/irb/ext/workspaces.rb56
-rw-r--r--lib/irb/extend-command.rb243
-rw-r--r--lib/irb/frame.rb2
-rw-r--r--lib/irb/help.rb2
-rw-r--r--lib/irb/init.rb58
-rw-r--r--lib/irb/input-method.rb6
-rw-r--r--lib/irb/lc/error.rb2
-rw-r--r--lib/irb/lc/help-message2
-rw-r--r--lib/irb/lc/ja/error.rb2
-rw-r--r--lib/irb/lc/ja/help-message2
-rw-r--r--lib/irb/loader.rb118
-rw-r--r--lib/irb/locale.rb3
-rw-r--r--lib/irb/ruby-lex.rb161
-rw-r--r--lib/irb/ruby-token.rb3
-rw-r--r--lib/irb/slex.rb5
-rw-r--r--lib/irb/version.rb6
-rw-r--r--lib/irb/workspace.rb17
-rw-r--r--lib/irb/ws-for-case-2.rb2
-rw-r--r--lib/irb/xmp.rb12
35 files changed, 1267 insertions, 482 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|
diff --git a/lib/irb/cmd/chws.rb b/lib/irb/cmd/chws.rb
new file mode 100644
index 0000000000..84f06014ba
--- /dev/null
+++ b/lib/irb/cmd/chws.rb
@@ -0,0 +1,33 @@
+#
+# change-ws.rb -
+# $Release Version: 0.9$
+# $Revision$
+# $Date$
+# by Keiju ISHITSUKA(Nihon Rational Software Co.,Ltd)
+#
+# --
+#
+#
+#
+
+require "irb/cmd/nop.rb"
+require "irb/ext/change-ws.rb"
+
+module IRB
+ module ExtendCommand
+
+ class CurrentWorkingWorkspace<Nop
+ def execute(*obj)
+ irb_context.main
+ end
+ end
+
+ class ChangeWorkspace<Nop
+ def execute(*obj)
+ irb_context.change_workspace(*obj)
+ irb_context.main
+ end
+ end
+ end
+end
+
diff --git a/lib/irb/cmd/fork.rb b/lib/irb/cmd/fork.rb
new file mode 100644
index 0000000000..1cc4458b13
--- /dev/null
+++ b/lib/irb/cmd/fork.rb
@@ -0,0 +1,25 @@
+
+module IRB
+ module ExtendCommand
+ class Fork<Nop
+ def execute(&block)
+ pid = send ExtendCommand.irb_original_method_name("fork")
+ unless pid
+ class<<self
+ alias_method :exit, ExtendCommand.irb_original_method_name('exit')
+ end
+ if iterator?
+ begin
+ yield
+ ensure
+ exit
+ end
+ end
+ end
+ pid
+ end
+ end
+ end
+end
+
+
diff --git a/lib/irb/cmd/load.rb b/lib/irb/cmd/load.rb
new file mode 100644
index 0000000000..99d20f500c
--- /dev/null
+++ b/lib/irb/cmd/load.rb
@@ -0,0 +1,67 @@
+#
+# load.rb -
+# $Release Version: 0.9$
+# $Revision$
+# $Date$
+# by Keiju ISHITSUKA(Nihon Rational Software Co.,Ltd)
+#
+# --
+#
+#
+#
+
+require "irb/cmd/nop.rb"
+require "irb/ext/loader"
+
+module IRB
+ module ExtendCommand
+ class Load<Nop
+ include IrbLoader
+
+ def execute(file_name, priv = nil)
+# return ruby_load(file_name) unless IRB.conf[:USE_LOADER]
+ return irb_load(file_name, priv)
+ end
+ end
+
+ class Require<Nop
+ include IrbLoader
+
+ def execute(file_name)
+# return ruby_require(file_name) unless IRB.conf[:USE_LOADER]
+
+ rex = Regexp.new("#{Regexp.quote(file_name)}(\.o|\.rb)?")
+ return false if $".find{|f| f =~ rex}
+
+ case file_name
+ when /\.rb$/
+ begin
+ if irb_load(file_name)
+ $".push file_name
+ return true
+ end
+ rescue LoadError
+ end
+ when /\.(so|o|sl)$/
+ return ruby_require(file_name)
+ end
+
+ begin
+ irb_load(f = file_name + ".rb")
+ $".push f
+ return true
+ rescue LoadError
+ return ruby_require(file_name)
+ end
+ end
+ end
+
+ class Source<Nop
+ include IrbLoader
+ def execute(file_name)
+ source_file(file_name)
+ end
+ end
+ end
+
+end
diff --git a/lib/irb/cmd/nop.rb b/lib/irb/cmd/nop.rb
new file mode 100644
index 0000000000..73c52b1aa3
--- /dev/null
+++ b/lib/irb/cmd/nop.rb
@@ -0,0 +1,39 @@
+#
+# nop.rb -
+# $Release Version: 0.9$
+# $Revision$
+# $Date$
+# by Keiju ISHITSUKA(Nihon Rational Software Co.,Ltd)
+#
+# --
+#
+#
+#
+module IRB
+ module ExtendCommand
+ class Nop
+
+ @RCS_ID='-$Id$-'
+
+ def self.execute(conf, *opts)
+ command = new(conf)
+ command.execute(*opts)
+ end
+
+ def initialize(conf)
+ @irb_context = conf
+ end
+
+ attr_reader :irb_context
+
+ def irb
+ @irb_context.irb
+ end
+
+ def execute(*opts)
+ #nop
+ end
+ end
+ end
+end
+
diff --git a/lib/irb/cmd/pushws.rb b/lib/irb/cmd/pushws.rb
new file mode 100644
index 0000000000..0d8130d5c6
--- /dev/null
+++ b/lib/irb/cmd/pushws.rb
@@ -0,0 +1,39 @@
+#
+# change-ws.rb -
+# $Release Version: 0.9$
+# $Revision$
+# $Date$
+# by Keiju ISHITSUKA(Nihon Rational Software Co.,Ltd)
+#
+# --
+#
+#
+#
+
+require "irb/cmd/nop.rb"
+require "irb/ext/workspaces.rb"
+
+module IRB
+ module ExtendCommand
+ class Workspaces<Nop
+ def execute(*obj)
+ irb_context.workspaces.collect{|ws| ws.main}
+ end
+ end
+
+ class PushWorkspace<Workspaces
+ def execute(*obj)
+ irb_context.push_workspace(*obj)
+ super
+ end
+ end
+
+ class PopWorkspace<Workspaces
+ def execute(*obj)
+ irb_context.pop_workspace(*obj)
+ super
+ end
+ end
+ end
+end
+
diff --git a/lib/irb/cmd/subirb.rb b/lib/irb/cmd/subirb.rb
new file mode 100644
index 0000000000..7899f1bb43
--- /dev/null
+++ b/lib/irb/cmd/subirb.rb
@@ -0,0 +1,43 @@
+#!/usr/local/bin/ruby
+#
+# multi.rb -
+# $Release Version: 0.9$
+# $Revision$
+# $Date$
+# by Keiju ISHITSUKA(Nihon Rational Software Co.,Ltd)
+#
+# --
+#
+#
+#
+
+require "irb/cmd/nop.rb"
+require "irb/ext/multi-irb"
+
+module IRB
+ module ExtendCommand
+ class IrbCommand<Nop
+ def execute(*obj)
+ IRB.irb(nil, *obj)
+ end
+ end
+
+ class Jobs<Nop
+ def execute
+ IRB.JobManager
+ end
+ end
+
+ class Foreground<Nop
+ def execute(key)
+ IRB.JobManager.switch(key)
+ end
+ end
+
+ class Kill<Nop
+ def execute(*keys)
+ IRB.JobManager.kill(*keys)
+ end
+ end
+ end
+end
diff --git a/lib/irb/completion.rb b/lib/irb/completion.rb
index 01dcbd2219..a350013e8e 100644
--- a/lib/irb/completion.rb
+++ b/lib/irb/completion.rb
@@ -1,6 +1,6 @@
#
# irb/completor.rb -
-# $Release Version: 0.7.1$
+# $Release Version: 0.9$
# $Revision$
# $Date$
# by Keiju ISHITSUKA(keiju@ishitsuka.com)
@@ -36,6 +36,9 @@ module IRB
CompletionProc = proc { |input|
bind = IRB.conf[:MAIN_CONTEXT].workspace.binding
+
+# puts "input: #{input}"
+
case input
when /^(\/[^\/]*\/)\.([^.]*)$/
# Regexp
@@ -61,11 +64,11 @@ module IRB
candidates = Proc.instance_methods(true) | Hash.instance_methods(true)
select_message(receiver, message, candidates)
- when /^(:[^:]*)$/
+ when /^(:[^:.]*)$/
# Symbol
if Symbol.respond_to?(:all_symbols)
sym = $1
- candidates = Symbol.all_symbols.collect{|s| s.id2name}
+ candidates = Symbol.all_symbols.collect{|s| ":" + s.id2name}
candidates.grep(/^#{sym}/)
else
[]
@@ -88,7 +91,7 @@ module IRB
end
candidates.grep(/^#{message}/).collect{|e| receiver + "::" + e}
- when /^(:[^.]+)\.([^.]*)$/
+ when /^(:[^:.]+)\.([^.]*)$/
# Symbol
receiver = $1
message = Regexp.quote($2)
@@ -108,6 +111,9 @@ module IRB
end
select_message(receiver, message, candidates)
+ when /^(\$[^.]*)$/
+ candidates = global_variables.grep Regexp.new(Regexp.quote($1))
+
# when /^(\$?(\.?[^.]+)+)\.([^.]*)$/
when /^((\.?[^.]+)+)\.([^.]*)$/
# variable
@@ -132,7 +138,8 @@ module IRB
# func1.func2
candidates = []
ObjectSpace.each_object(Module){|m|
- next if /^(IRB|SLex|RubyLex|RubyToken)/ =~ m.name
+ next if m.name != "IRB::Context" and
+ /^(IRB|SLex|RubyLex|RubyToken)/ =~ m.name
candidates.concat m.instance_methods
}
candidates.sort!
@@ -174,4 +181,8 @@ module IRB
end
end
+if Readline.respond_to?("basic_word_break_characters=")
+ Readline.basic_word_break_characters= "\t\n\"\\'`><=;|&{("
+end
+Readline.completion_append_character = nil
Readline.completion_proc = IRB::InputCompletor::CompletionProc
diff --git a/lib/irb/context.rb b/lib/irb/context.rb
index ffc77de875..1c504451cb 100644
--- a/lib/irb/context.rb
+++ b/lib/irb/context.rb
@@ -1,6 +1,6 @@
#
# irb/context.rb - irb context
-# $Release Version: 0.7.3$
+# $Release Version: 0.9$
# $Revision$
# $Date$
# by Keiju ISHITSUKA(keiju@ishitsuka.com)
@@ -9,6 +9,8 @@
#
#
#
+require "irb/workspace"
+
module IRB
class Context
#
@@ -22,33 +24,30 @@ module IRB
if workspace
@workspace = workspace
else
- @workspace = WorkSpace.new unless workspace
+ @workspace = WorkSpace.new
end
@thread = Thread.current if defined? Thread
- @irb_level = 0
+# @irb_level = 0
# copy of default configuration
@ap_name = IRB.conf[:AP_NAME]
@rc = IRB.conf[:RC]
@load_modules = IRB.conf[:LOAD_MODULES]
- self.math_mode = IRB.conf[:MATH_MODE]
@use_readline = IRB.conf[:USE_READLINE]
@inspect_mode = IRB.conf[:INSPECT_MODE]
- self.use_tracer = IRB.conf[:USE_TRACER]
-# @use_loader = IRB.conf[:USE_LOADER]
- self.prompt_mode = IRB.conf[:PROMPT_MODE]
-
+ self.math_mode = IRB.conf[:MATH_MODE] if IRB.conf[:MATH_MODE]
+ self.use_tracer = IRB.conf[:USE_TRACER] if IRB.conf[:USE_TRASER]
+ self.use_loader = IRB.conf[:USE_LOADER] if IRB.conf[:USE_LOADER]
+ self.eval_history = IRB.conf[:EVAL_HISTORY] if IRB.conf[:EVEL_HISTORY]
+
@ignore_sigint = IRB.conf[:IGNORE_SIGINT]
@ignore_eof = IRB.conf[:IGNORE_EOF]
@back_trace_limit = IRB.conf[:BACK_TRACE_LIMIT]
- debug_level = IRB.conf[:DEBUG_LEVEL]
- @verbose = IRB.conf[:VERBOSE]
-
- @tracer_initialized = false
+ self.prompt_mode = IRB.conf[:PROMPT_MODE]
if IRB.conf[:SINGLE_IRB] or !defined?(JobManager)
@irb_name = IRB.conf[:IRB_NAME]
@@ -59,7 +58,7 @@ module IRB
case input_method
when nil
- if (use_readline.nil? && IRB.conf[:PROMPT_MODE] != :INF_RUBY ||
+ if (use_readline.nil? && IRB.conf[:PROMPT_MODE] != :INF_RUBY && STDIN.tty? ||
use_readline?)
@io = ReadlineInputMethod.new
else
@@ -72,18 +71,24 @@ module IRB
else
@io = input_method
end
+
+ @verbose = IRB.conf[:VERBOSE]
+ @echo = IRB.conf[:ECHO]
+ if @echo.nil?
+ @echo = true
+ end
+ @debug_level = IRB.conf[:DEBUG_LEVEL]
end
def main
@workspace.main
end
+ attr_reader :workspace_home
attr_accessor :workspace
attr_reader :thread
attr_accessor :io
- attr_reader :_
-
attr_accessor :irb
attr_accessor :ap_name
attr_accessor :rc
@@ -91,14 +96,8 @@ module IRB
attr_accessor :irb_name
attr_accessor :irb_path
- attr_accessor :math_mode
attr_accessor :use_readline
attr_reader :inspect_mode
- attr_reader :use_tracer
-# attr :use_loader
-
- attr_reader :debug_level
- attr_accessor :verbose
attr_reader :prompt_mode
attr_accessor :prompt_i
@@ -109,33 +108,43 @@ module IRB
attr_accessor :ignore_sigint
attr_accessor :ignore_eof
+ attr_accessor :echo
+ attr_accessor :verbose
+ attr_reader :debug_level
attr_accessor :back_trace_limit
-# alias use_loader? use_loader
- alias use_tracer? use_tracer
alias use_readline? use_readline
alias rc? rc
- alias math? math_mode
- alias verbose? verbose
alias ignore_sigint? ignore_sigint
alias ignore_eof? ignore_eof
+ alias echo? echo
+
+ def verbose?
+ if @verbose.nil?
+ if defined?(ReadlineInputMethod) && @io.kind_of?(ReadlineInputMethod)
+ false
+ elsif !STDIN.tty? or @io.kind_of?(FileInputMethod)
+ true
+ else
+ false
+ end
+ end
+ end
- def _=(value)
- @_ = value
- @workspace.evaluate "_ = IRB.conf[:MAIN_CONTEXT]._"
+ def prompting?
+ verbose? || (STDIN.tty? && @io.kind_of?(StdioInputMethod) ||
+ (defined?(ReadlineInputMethod) && @io.kind_of?(ReadlineInputMethod)))
end
- def irb_name
- if @irb_level == 0
- @irb_name
- elsif @irb_name =~ /#[0-9]*$/
- @irb_name + "." + @irb_level.to_s
- else
- @irb_name + "#0." + @irb_level.to_s
- end
+ attr_reader :last_value
+
+ def set_last_value(value)
+ @last_value = value
end
+ attr_reader :irb_name
+
def prompt_mode=(mode)
@prompt_mode = mode
pconf = IRB.conf[:PROMPT][mode]
@@ -151,42 +160,13 @@ module IRB
end
def inspect?
- @inspect_mode.nil? && !@math_mode or @inspect_mode
+ @inspect_mode.nil? or @inspect_mode
end
def file_input?
@io.type == FileInputMethod
end
- def use_tracer=(opt)
- if opt
- IRB.initialize_tracer
- unless @tracer_initialized
- Tracer.set_get_line_procs(@irb_path) {
- |line_no|
- @io.line(line_no)
- }
- @tracer_initialized = true
- end
- elsif !opt && @use_tracer
- Tracer.off
- end
- @use_tracer=opt
- end
-
- def use_loader
- IRB.conf[:USE_LOADER]
- end
-
- def use_loader=(opt)
- IRB.conf[:USE_LOADER] = opt
- if opt
- IRB.initialize_loader
- end
- print "Switch to load/require#{unless use_loader; ' non';end} trace mode.\n" if verbose?
- opt
- end
-
def inspect_mode=(opt)
if opt
@inspect_mode = opt
@@ -197,20 +177,6 @@ module IRB
@inspect_mode
end
- def math_mode=(opt)
- if @math_mode == true && opt == false
- IRB.fail CantRetuenNormalMode
- return
- end
-
- @math_mode = opt
- if math_mode
- IRB.initialize_mathn
- main.instance_eval("include Math")
- print "start math mode\n" if verbose?
- end
- end
-
def use_readline=(opt)
@use_readline = opt
print "use readline module\n" if @use_readline
@@ -226,41 +192,19 @@ module IRB
@debug_level > 0
end
- def change_binding(*_main)
- back = @workspace
- @workspace = WorkSpace.new(*_main)
- unless _main.empty?
- begin
- main.extend ExtendCommand
- rescue
- print "can't change binding to: ", main.inspect, "\n"
- @workspace = back
- return nil
- end
- end
- @irb_level += 1
- begin
- catch(:SU_EXIT) do
- @irb.eval_input
- end
- ensure
- @irb_level -= 1
- @workspace = back
- end
+ def evaluate(line, line_no)
+ @line_no = line_no
+ set_last_value(@workspace.evaluate(self, line, irb_path, line_no))
+# @workspace.evaluate("_ = IRB.conf[:MAIN_CONTEXT]._")
+# @_ = @workspace.evaluate(line, irb_path, line_no)
end
- alias change_workspace change_binding
-
alias __exit__ exit
def exit(ret = 0)
- if @irb_level == 0
- IRB.irb_exit(@irb, ret)
- else
- throw :SU_EXIT, ret
- end
+ IRB.irb_exit(@irb, ret)
end
- NOPRINTING_IVARS = ["@_"]
+ NOPRINTING_IVARS = ["@last_value"]
NO_INSPECTING_IVARS = ["@irb", "@io"]
IDNAME_IVARS = ["@prompt_mode"]
@@ -272,7 +216,7 @@ module IRB
val = instance_eval(ivar)
case ivar
when *NOPRINTING_IVARS
- next
+ array.push format("conf.%s=%s", name, "...")
when *NO_INSPECTING_IVARS
array.push format("conf.%s=%s", name, val.to_s)
when *IDNAME_IVARS
diff --git a/lib/irb/ext/change-ws.rb b/lib/irb/ext/change-ws.rb
new file mode 100644
index 0000000000..f15391e202
--- /dev/null
+++ b/lib/irb/ext/change-ws.rb
@@ -0,0 +1,62 @@
+#
+# irb/ext/cb.rb -
+# $Release Version: 0.9$
+# $Revision$
+# $Date$
+# by Keiju ISHITSUKA(Nihon Rational Software Co.,Ltd)
+#
+# --
+#
+#
+#
+
+module IRB
+ class Context
+
+ def home_workspace
+ if defined? @home_workspace
+ @home_workspace
+ else
+ @home_workspace = @workspace
+ end
+ end
+
+ def change_workspace(*_main)
+ if _main.empty?
+ @workspace = home_workspace
+ return main
+ end
+
+ @workspace = WorkSpace.new(_main[0])
+
+ if !(class<<main;ancestors;end).include?(ExtendCommandBundle)
+ main.extend ExtendCommandBundle
+ end
+ end
+
+# def change_binding(*_main)
+# back = @workspace
+# @workspace = WorkSpace.new(*_main)
+# unless _main.empty?
+# begin
+# main.extend ExtendCommandBundle
+# rescue
+# print "can't change binding to: ", main.inspect, "\n"
+# @workspace = back
+# return nil
+# end
+# end
+# @irb_level += 1
+# begin
+# catch(:SU_EXIT) do
+# @irb.eval_input
+# end
+# ensure
+# @irb_level -= 1
+# @workspace = back
+# end
+# end
+# alias change_workspace change_binding
+ end
+end
+
diff --git a/lib/irb/ext/history.rb b/lib/irb/ext/history.rb
new file mode 100644
index 0000000000..d40a62e959
--- /dev/null
+++ b/lib/irb/ext/history.rb
@@ -0,0 +1,110 @@
+#
+# history.rb -
+# $Release Version: 0.9$
+# $Revision$
+# $Date$
+# by Keiju ISHITSUKA(Nihon Rational Software Co.,Ltd)
+#
+# --
+#
+#
+#
+
+module IRB
+
+ class Context
+
+ NOPRINTING_IVARS.push "@eval_history_values"
+
+ alias _set_last_value set_last_value
+
+ def set_last_value(value)
+ _set_last_value(value)
+
+ @workspace.evaluate self, "_ = IRB.CurrentContext.last_value"
+ if @eval_history #and !@eval_history_values.equal?(llv)
+ @eval_history_values.push @line_no, @last_value
+ @workspace.evaluate self, "__ = IRB.CurrentContext.instance_eval{@eval_history_values}"
+ end
+
+ @last_value
+ end
+
+ attr_reader :eval_history
+ def eval_history=(no)
+ if no
+ if @eval_history
+ @eval_history_values.size(no)
+ else
+ @eval_history_values = History.new(no)
+ IRB.conf[:__TMP__EHV__] = @eval_history_values
+ @workspace.evaluate(self, "__ = IRB.conf[:__TMP__EHV__]")
+ IRB.conf.delete(:__TMP_EHV__)
+ end
+ else
+ @eval_history_values = nil
+ end
+ @eval_history = no
+ end
+ end
+
+ class History
+ @RCS_ID='-$Id$-'
+
+ def initialize(size = 16)
+ @size = size
+ @contents = []
+ end
+
+ def size(size)
+ if size != 0 && size < @size
+ @contents = @contents[@size - size .. @size]
+ end
+ @size = size
+ end
+
+ def [](idx)
+ begin
+ if idx >= 0
+ @contents.find{|no, val| no == idx}[1]
+ else
+ @contents[idx][1]
+ end
+ rescue NameError
+ nil
+ end
+ end
+
+ def push(no, val)
+ @contents.push [no, val]
+ @contents.shift if @size != 0 && @contents.size > @size
+ end
+
+ alias real_inspect inspect
+
+ def inspect
+ if @contents.empty?
+ return real_inspect
+ end
+
+ unless (last = @contents.pop)[1].equal?(self)
+ @contents.push last
+ last = nil
+ end
+ str = @contents.collect{|no, val|
+ if val.equal?(self)
+ "#{no} ...self-history..."
+ else
+ "#{no} #{val.inspect}"
+ end
+ }.join("\n")
+ if str == ""
+ str = "Empty."
+ end
+ @contents.push last if last
+ str
+ end
+ end
+end
+
+
diff --git a/lib/irb/ext/loader.rb b/lib/irb/ext/loader.rb
new file mode 100644
index 0000000000..26e36e1209
--- /dev/null
+++ b/lib/irb/ext/loader.rb
@@ -0,0 +1,106 @@
+module IRB
+ class LoadAbort < Exception;end
+
+ module IrbLoader
+ @RCS_ID='-$Id$-'
+ alias ruby_load load
+ alias ruby_require require
+
+ def irb_load(fn, priv = nil)
+ path = search_file_from_ruby_path(fn)
+ raise LoadError, "No such file to load -- #{fn}" unless path
+
+ load_file(path, priv)
+ end
+
+ def search_file_from_ruby_path(fn)
+ if /^#{Regexp.quote(File::Separator)}/ =~ fn
+ return fn if File.exist?(fn)
+ return nil
+ end
+
+ for path in $:
+ if File.exist?(f = File.join(path, fn))
+ return f
+ end
+ end
+ return nil
+ end
+
+ def source_file(path)
+ irb.suspend_name(path, File.basename(path)) do
+ irb.suspend_input_method(FileInputMethod.new(path)) do
+ |back_io|
+ irb.signal_status(:IN_LOAD) do
+ if back_io.kind_of?(FileInputMethod)
+ irb.eval_input
+ else
+ begin
+ irb.eval_input
+ rescue LoadAbort
+ print "load abort!!\n"
+ end
+ end
+ end
+ end
+ end
+ end
+
+ def load_file(path, priv = nil)
+ irb.suspend_name(path, File.basename(path)) do
+
+ if priv
+ ws = WorkSpace.new(Module.new)
+ else
+ ws = WorkSpace.new
+ end
+ irb.suspend_workspace(ws) do
+ irb.suspend_input_method(FileInputMethod.new(path)) do
+ |back_io|
+ irb.signal_status(:IN_LOAD) do
+# p irb.conf
+ if back_io.kind_of?(FileInputMethod)
+ irb.eval_input
+ else
+ begin
+ irb.eval_input
+ rescue LoadAbort
+ print "load abort!!\n"
+ end
+ end
+ end
+ end
+ end
+ end
+ end
+
+ def old
+ back_io = @io
+ back_path = @irb_path
+ back_name = @irb_name
+ back_scanner = @irb.scanner
+ begin
+ @io = FileInputMethod.new(path)
+ @irb_name = File.basename(path)
+ @irb_path = path
+ @irb.signal_status(:IN_LOAD) do
+ if back_io.kind_of?(FileInputMethod)
+ @irb.eval_input
+ else
+ begin
+ @irb.eval_input
+ rescue LoadAbort
+ print "load abort!!\n"
+ end
+ end
+ end
+ ensure
+ @io = back_io
+ @irb_name = back_name
+ @irb_path = back_path
+ @irb.scanner = back_scanner
+ end
+ end
+ end
+end
+
diff --git a/lib/irb/ext/math-mode.rb b/lib/irb/ext/math-mode.rb
new file mode 100644
index 0000000000..a98664448e
--- /dev/null
+++ b/lib/irb/ext/math-mode.rb
@@ -0,0 +1,37 @@
+#
+# math-mode.rb -
+# $Release Version: 0.9$
+# $Revision$
+# $Date$
+# by Keiju ISHITSUKA(Nihon Rational Software Co.,Ltd)
+#
+# --
+#
+#
+#
+require "mathn"
+
+module IRB
+ class Context
+ attr_reader :math_mode
+ alias math? math_mode
+
+ def math_mode=(opt)
+ if @math_mode == true && opt == false
+ IRB.fail CantRetuenNormalMode
+ return
+ end
+
+ @math_mode = opt
+ if math_mode
+ main.extend Math
+ print "start math mode\n" if verbose?
+ end
+ end
+
+ def inspect?
+ @inspect_mode.nil? && !@math_mode or @inspect_mode
+ end
+ end
+end
+
diff --git a/lib/irb/multi-irb.rb b/lib/irb/ext/multi-irb.rb
index 77d9921ea8..86569ae333 100644
--- a/lib/irb/multi-irb.rb
+++ b/lib/irb/ext/multi-irb.rb
@@ -1,6 +1,6 @@
#
# irb/multi-irb.rb - multiple irb module
-# $Release Version: 0.7.3$
+# $Release Version: 0.9$
# $Revision$
# $Date$
# by Keiju ISHITSUKA(keiju@ishitsuka.com)
@@ -140,6 +140,10 @@ module IRB
@JobManager
end
+ def IRB.CurrentContext
+ IRB.JobManager.irb(Thread.current).context
+ end
+
# invoke multi-irb
def IRB.irb(file = nil, *main)
workspace = WorkSpace.new(*main)
@@ -183,19 +187,24 @@ module IRB
@JobManager.current_job = @JobManager.irb(Thread.current)
end
- class Context
- def _=(value)
- @_ = value
- @workspace.evaluate "_ = IRB.JobManager.irb(Thread.current).context._"
- end
- end
-
- module ExtendCommand
- def irb_context
- IRB.JobManager.irb(Thread.current).context
- end
-# alias conf irb_context
- end
+# class Context
+# def set_last_value(value)
+# @last_value = value
+# @workspace.evaluate "_ = IRB.JobManager.irb(Thread.current).context.last_value"
+# if @eval_history #and !@__.equal?(@last_value)
+# @eval_history_values.push @line_no, @last_value
+# @workspace.evaluate "__ = IRB.JobManager.irb(Thread.current).context.instance_eval{@eval_history_values}"
+# end
+# @last_value
+# end
+# end
+
+# module ExtendCommand
+# def irb_context
+# IRB.JobManager.irb(Thread.current).context
+# end
+# # alias conf irb_context
+# end
@CONF[:SINGLE_IRB_MODE] = false
@JobManager.insert(@CONF[:MAIN_CONTEXT].irb)
@@ -219,7 +228,7 @@ module IRB
when :IN_IRB
# ignore
else
- # ignore
+ # ignore other cases as well
end
end
end
diff --git a/lib/irb/ext/tracer.rb b/lib/irb/ext/tracer.rb
new file mode 100644
index 0000000000..b2528f74b2
--- /dev/null
+++ b/lib/irb/ext/tracer.rb
@@ -0,0 +1,61 @@
+#
+# irb/lib/tracer.rb -
+# $Release Version: 0.9$
+# $Revision$
+# $Date$
+# by Keiju ISHITSUKA(Nihon Rational Software Co.,Ltd)
+#
+# --
+#
+#
+#
+require "tracer"
+
+module IRB
+
+ # initialize tracing function
+ def IRB.initialize_tracer
+ Tracer.verbose = false
+ Tracer.add_filter {
+ |event, file, line, id, binding, *rests|
+ /^#{Regexp.quote(@CONF[:IRB_LIB_PATH])}/ !~ file and
+ File::basename(file) != "irb.rb"
+ }
+ end
+
+ class Context
+ attr_reader :use_tracer
+ alias use_tracer? use_tracer
+
+ def use_tracer=(opt)
+ if opt
+ Tracer.set_get_line_procs(@irb_path) {
+ |line_no, *rests|
+ @io.line(line_no)
+ }
+ elsif !opt && @use_tracer
+ Tracer.off
+ end
+ @use_tracer=opt
+ end
+ end
+
+ class WorkSpace
+ alias __evaluate__ evaluate
+ def evaluate(context, statements, file = nil, line = nil)
+ if context.use_tracer? && file != nil && line != nil
+ Tracer.on
+ begin
+ __evaluate__(context, statements, file, line)
+ ensure
+ Tracer.off
+ end
+ else
+ __evaluate__(context, statements, file || __FILE__, line || __LINE__)
+ end
+ end
+ end
+
+ IRB.initialize_tracer
+end
+
diff --git a/lib/irb/ext/use-loader.rb b/lib/irb/ext/use-loader.rb
new file mode 100644
index 0000000000..a81b3aca7b
--- /dev/null
+++ b/lib/irb/ext/use-loader.rb
@@ -0,0 +1,65 @@
+#
+# use-loader.rb -
+# $Release Version: 0.9$
+# $Revision$
+# $Date$
+# by Keiju ISHITSUKA(Nihon Rational Software Co.,Ltd)
+#
+# --
+#
+#
+#
+
+require "irb/cmd/load"
+require "irb/ext/loader"
+
+class Object
+ alias __original__load__IRB_use_loader__ load
+ alias __original__require__IRB_use_loader__ require
+end
+
+module IRB
+ module ExtendCommandBundle
+ def irb_load(*opts, &b)
+ ExtendCommand::Load.execute(irb_context, *opts, &b)
+ end
+ def irb_require(*opts, &b)
+ ExtendCommand::Require.execute(irb_context, *opts, &b)
+ end
+ end
+
+ class Context
+
+ IRB.conf[:USE_LOADER] = false
+
+ def use_loader
+ IRB.conf[:USE_LOADER]
+ end
+
+ alias use_loader? use_loader
+
+ def use_loader=(opt)
+
+ if IRB.conf[:USE_LOADER] != opt
+ IRB.conf[:USE_LOADER] = opt
+ if opt
+ if !$".include?("irb/cmd/load")
+ end
+ (class<<@workspace.main;self;end).instance_eval {
+ alias_method :load, :irb_load
+ alias_method :require, :irb_require
+ }
+ else
+ (class<<@workspace.main;self;end).instance_eval {
+ alias_method :load, :__original__load__IRB_use_loader__
+ alias_method :require, :__original__require__IRB_use_loader__
+ }
+ end
+ end
+ print "Switch to load/require#{unless use_loader; ' non';end} trace mode.\n" if verbose?
+ opt
+ end
+ end
+end
+
+
diff --git a/lib/irb/ext/workspaces.rb b/lib/irb/ext/workspaces.rb
new file mode 100644
index 0000000000..2fe8f8a87b
--- /dev/null
+++ b/lib/irb/ext/workspaces.rb
@@ -0,0 +1,56 @@
+#
+# push-ws.rb -
+# $Release Version: 0.9$
+# $Revision$
+# $Date$
+# by Keiju ISHITSUKA(Nihon Rational Software Co.,Ltd)
+#
+# --
+#
+#
+#
+
+module IRB
+ class Context
+
+ def irb_level
+ workspace_stack.size
+ end
+
+ def workspaces
+ if defined? @workspaces
+ @workspaces
+ else
+ @workspaces = []
+ end
+ end
+
+ def push_workspace(*_main)
+ if _main.empty?
+ if workspaces.empty?
+ print "No other workspace\n"
+ return nil
+ end
+ ws = workspaces.pop
+ workspaces.push @workspace
+ @workspace = ws
+ return workspaces
+ end
+
+ workspaces.push @workspace
+ @workspace = WorkSpace.new(@workspace.binding, _main[0])
+ if !(class<<main;ancestors;end).include?(ExtendCommandBundle)
+ main.extend ExtendCommandBundle
+ end
+ end
+
+ def pop_workspace
+ if workspaces.empty?
+ print "workspace stack empty\n"
+ return
+ end
+ @workspace = workspaces.pop
+ end
+ end
+end
+
diff --git a/lib/irb/extend-command.rb b/lib/irb/extend-command.rb
index 3f92707d01..fd71968c1f 100644
--- a/lib/irb/extend-command.rb
+++ b/lib/irb/extend-command.rb
@@ -1,6 +1,6 @@
#
# irb/extend-command.rb - irb command extend
-# $Release Version: 0.7.3$
+# $Release Version: 0.9$
# $Revision$
# $Date$
# by Keiju ISHITSUKA(keiju@ishitsuka.com)
@@ -13,104 +13,149 @@ module IRB
#
# IRB extended command
#
- module ExtendCommand
-# include Loader
-
- def irb_exit(ret = 0)
- irb_context.exit(ret)
- end
- alias irb_quit irb_exit
-
- def irb_fork(&block)
- pid = send ExtendCommand.irb_original_method_name("fork")
- unless pid
- class<<self
- alias_method :exit, ExtendCommand.irb_original_method_name('exit')
- end
- if iterator?
- begin
- yield
- ensure
- exit
- end
- end
- end
- pid
- end
+ module ExtendCommandBundle
+ EXCB = ExtendCommandBundle
- def irb_change_binding(*main)
- irb_context.change_binding(*main)
- end
- alias irb_change_workspace irb_change_binding
-
- def irb_source(file)
- irb_context.source(file)
- end
+ NO_OVERRIDE = 0
+ OVERRIDE_PRIVATE_ONLY = 0x01
+ OVERRIDE_ALL = 0x02
- def irb(*obj)
- require "irb/multi-irb"
- IRB.irb(nil, *obj)
+ def irb_exit(ret = 0)
+ irb_context.exit(ret)
end
def irb_context
- IRB.conf[:MAIN_CONTEXT]
- end
-
- def irb_jobs
- require "irb/multi-irb"
- IRB.JobManager
+ IRB.CurrentContext
end
- def irb_fg(key)
- require "irb/multi-irb"
- IRB.JobManager.switch(key)
- end
-
- def irb_kill(*keys)
- require "irb/multi-irb"
- IRB.JobManager.kill(*keys)
- end
-
- # extend command functions
- def ExtendCommand.extend_object(obj)
- super
- unless (class<<obj;ancestors;end).include?(ExtendCommand)
- obj.install_aliases
+ @ALIASES = [
+ [:context, :irb_context, NO_OVERRIDE],
+ [:conf, :irb_context, NO_OVERRIDE],
+ [:irb_quit, :irb_exit, OVERRIDE_PRIVATE_ONLY],
+ [:exit, :irb_exit, OVERRIDE_PRIVATE_ONLY],
+ [:quit, :irb_exit, OVERRIDE_PRIVATE_ONLY],
+ ]
+
+ @EXTEND_COMMANDS = [
+ [:irb_current_working_workspace, :CurrentWorkingWorkspace, "irb/cmd/chws",
+ [:irb_print_working_workspace, OVERRIDE_ALL],
+ [:irb_cwws, OVERRIDE_ALL],
+ [:irb_pwws, OVERRIDE_ALL],
+# [:irb_cww, OVERRIDE_ALL],
+# [:irb_pww, OVERRIDE_ALL],
+ [:cwws, NO_OVERRIDE],
+ [:pwws, NO_OVERRIDE],
+# [:cww, NO_OVERRIDE],
+# [:pww, NO_OVERRIDE],
+ [:irb_current_working_binding, OVERRIDE_ALL],
+ [:irb_print_working_binding, OVERRIDE_ALL],
+ [:irb_cwb, OVERRIDE_ALL],
+ [:irb_pwb, OVERRIDE_ALL],
+# [:cwb, NO_OVERRIDE],
+# [:pwb, NO_OVERRIDE]
+ ],
+ [:irb_change_workspace, :ChangeWorkspace, "irb/cmd/chws",
+ [:irb_chws, OVERRIDE_ALL],
+# [:irb_chw, OVERRIDE_ALL],
+ [:irb_cws, OVERRIDE_ALL],
+# [:irb_cw, OVERRIDE_ALL],
+ [:chws, NO_OVERRIDE],
+# [:chw, NO_OVERRIDE],
+ [:cws, NO_OVERRIDE],
+# [:cw, NO_OVERRIDE],
+ [:irb_change_binding, OVERRIDE_ALL],
+ [:irb_cb, OVERRIDE_ALL],
+ [:cb, NO_OVERRIDE]],
+
+ [:irb_workspaces, :Workspaces, "irb/cmd/pushws",
+ [:workspaces, NO_OVERRIDE],
+ [:irb_bindings, OVERRIDE_ALL],
+ [:bindings, NO_OVERRIDE]],
+ [:irb_push_workspace, :PushWorkspace, "irb/cmd/pushws",
+ [:irb_pushws, OVERRIDE_ALL],
+# [:irb_pushw, OVERRIDE_ALL],
+ [:pushws, NO_OVERRIDE],
+# [:pushw, NO_OVERRIDE],
+ [:irb_push_binding, OVERRIDE_ALL],
+ [:irb_pushb, OVERRIDE_ALL],
+ [:pushb, NO_OVERRIDE]],
+ [:irb_pop_workspace, :PopWorkspace, "irb/cmd/pushws",
+ [:irb_popws, OVERRIDE_ALL],
+# [:irb_popw, OVERRIDE_ALL],
+ [:popws, NO_OVERRIDE],
+# [:popw, NO_OVERRIDE],
+ [:irb_pop_binding, OVERRIDE_ALL],
+ [:irb_popb, OVERRIDE_ALL],
+ [:popb, NO_OVERRIDE]],
+
+ [:irb_load, :Load, "irb/cmd/load"],
+ [:irb_require, :Require, "irb/cmd/load"],
+ [:irb_source, :Source, "irb/cmd/load",
+ [:source, NO_OVERRIDE]],
+
+ [:irb, :IrbCommand, "irb/cmd/subirb"],
+ [:irb_jobs, :Jobs, "irb/cmd/subirb",
+ [:jobs, NO_OVERRIDE]],
+ [:irb_fg, :Foreground, "irb/cmd/subirb",
+ [:fg, NO_OVERRIDE]],
+ [:irb_kill, :Kill, "irb/cmd/subirb",
+ [:kill, OVERRIDE_PRIVATE_ONLY]],
+ ]
+
+ def EXCB.install_extend_commands
+ for args in @EXTEND_COMMANDS
+ def_extend_command *args
end
end
- OVERRIDE_NOTHING = 0
- OVERRIDE_PRIVATE_ONLY = 0x01
- OVERRIDE_ALL = 0x02
-
- def install_aliases(override = OVERRIDE_NOTHING)
+ # aliases = [commans_alias, flag], ...
+ def EXCB.def_extend_command(cmd_name, cmd_class, load_file = nil, *aliases)
+ case cmd_class
+ when Symbol
+ cmd_class = cmd_class.id2name
+ when String
+ when Class
+ cmd_class = cmd_class.name
+ end
- install_alias_method(:exit, :irb_exit, override | OVERRIDE_PRIVATE_ONLY)
- install_alias_method(:quit, :irb_quit, override | OVERRIDE_PRIVATE_ONLY)
- install_alias_method(:fork, :irb_fork, override | OVERRIDE_PRIVATE_ONLY)
- install_alias_method(:kill, :irb_kill, override | OVERRIDE_PRIVATE_ONLY)
+ if load_file
+ eval %[
+ def #{cmd_name}(*opts, &b)
+ require "#{load_file}"
+ eval %[
+ def #{cmd_name}(*opts, &b)
+ ExtendCommand::#{cmd_class}.execute(irb_context, *opts, &b)
+ end
+ ]
+ send :#{cmd_name}, *opts, &b
+ end
+ ]
+ else
+ eval %[
+ def #{cmd_name}(*opts, &b)
+ ExtendCommand::#{cmd_class}.execute(irb_context, *opts, &b)
+ end
+ ]
+ end
- install_alias_method(:irb_cb, :irb_change_binding, override)
- install_alias_method(:irb_ws, :irb_change_workspace, override)
- install_alias_method(:source, :irb_source, override)
- install_alias_method(:conf, :irb_context, override)
- install_alias_method(:jobs, :irb_jobs, override)
- install_alias_method(:fg, :irb_fg, override)
+ for ali, flag in aliases
+ @ALIASES.push [ali, cmd_name, flag]
+ end
end
- # override = {OVERRIDE_NOTHING, OVERRIDE_PRIVATE_ONLY, OVERRIDE_ALL}
- def install_alias_method(to, from, override = OVERRIDE_NOTHING)
+ # override = {NO_OVERRIDE, OVERRIDE_PRIVATE_ONLY, OVERRIDE_ALL}
+ def install_alias_method(to, from, override = NO_OVERRIDE)
to = to.id2name unless to.kind_of?(String)
from = from.id2name unless from.kind_of?(String)
if override == OVERRIDE_ALL or
(override == OVERRIDE_PRIVATE_ONLY) && !respond_to?(to) or
- (override == OVERRIDE_NOTHING) && !respond_to?(to, true)
+ (override == NO_OVERRIDE) && !respond_to?(to, true)
target = self
(class<<self;self;end).instance_eval{
if target.respond_to?(to, true) &&
- !target.respond_to?(ExtendCommand.irb_original_method_name(to), true)
- alias_method(ExtendCommand.irb_original_method_name(to), to)
+ !target.respond_to?(EXCB.irb_original_method_name(to), true)
+ alias_method(EXCB.irb_original_method_name(to), to)
end
alias_method to, from
}
@@ -122,5 +167,49 @@ module IRB
def self.irb_original_method_name(method_name)
"irb_" + method_name + "_org"
end
+
+ def EXCB.extend_object(obj)
+ unless (class<<obj;ancestors;end).include?(EXCB)
+ super
+ for ali, com, flg in @ALIASES
+ obj.install_alias_method(ali, com, flg)
+ end
+ end
+ end
+
+ install_extend_commands
+ end
+
+ # extension support for Context
+ module ContextExtender
+ CE = ContextExtender
+
+ @EXTEND_COMMANDS = [
+ [:eval_history=, "irb/ext/history.rb"],
+ [:use_tracer=, "irb/ext/tracer.rb"],
+ [:math_mode=, "irb/ext/math-mode.rb"],
+ [:use_loader=, "irb/ext/use-loader.rb"],
+ ]
+
+ def CE.install_extend_commands
+ for args in @EXTEND_COMMANDS
+ def_extend_command *args
+ end
+ end
+
+ def CE.def_extend_command(cmd_name, load_file, *aliases)
+ Context.module_eval %[
+ def #{cmd_name}(*opts, &b)
+ require "#{load_file}"
+ send :#{cmd_name}, *opts, &b
+ end
+ for ali in aliases
+ alias_method ali, cmd_name
+ end
+ ]
+ end
+
+ CE.install_extend_commands
end
end
+
diff --git a/lib/irb/frame.rb b/lib/irb/frame.rb
index 1090cd9684..f0b0a9abf3 100644
--- a/lib/irb/frame.rb
+++ b/lib/irb/frame.rb
@@ -1,6 +1,6 @@
#
# frame.rb -
-# $Release Version: 0.7.1$
+# $Release Version: 0.9$
# $Revision$
# $Date$
# by Keiju ISHITSUKA(Nihon Rational Software Co.,Ltd)
diff --git a/lib/irb/help.rb b/lib/irb/help.rb
index 0821f68d13..eb876a6dbe 100644
--- a/lib/irb/help.rb
+++ b/lib/irb/help.rb
@@ -1,6 +1,6 @@
#
# irb/help.rb - print usase module
-# $Release Version: 0.7.3$
+# $Release Version: 0.9$
# $Revision$
# $Date$
# by Keiju ISHITSUKA(keiju@ishitsuka.com)
diff --git a/lib/irb/init.rb b/lib/irb/init.rb
index f34a51b345..f238153164 100644
--- a/lib/irb/init.rb
+++ b/lib/irb/init.rb
@@ -1,6 +1,6 @@
#
# irb/init.rb - irb initialize module
-# $Release Version: 0.7.3$
+# $Release Version: 0.9$
# $Revision$
# $Date$
# by Keiju ISHITSUKA(keiju@ishitsuka.com)
@@ -16,14 +16,19 @@ module IRB
def IRB.initialize(ap_path)
IRB.init_config(ap_path)
IRB.init_error
+ IRB.parse_opts
IRB.run_config
+ IRB.load_modules
+
+ unless @CONF[:PROMPT][@CONF[:PROMPT_MODE]]
+ IRB.fail(UndefinedPromptMode, @CONF[:PROMPT_MODE])
+ end
end
# @CONF default setting
def IRB.init_config(ap_path)
# class instance variables
@TRACER_INITIALIZED = false
- @MATHN_INITIALIZED = false
# default configurations
unless ap_path and @CONF[:AP_NAME]
@@ -45,6 +50,10 @@ module IRB
@CONF[:USE_LOADER] = false
@CONF[:IGNORE_SIGINT] = true
@CONF[:IGNORE_EOF] = false
+ @CONF[:ECHO] = nil
+ @CONF[:VERBOSE] = nil
+
+ @CONF[:EVAL_HISTORY] = nil
@CONF[:BACK_TRACE_LIMIT] = 16
@@ -92,7 +101,6 @@ module IRB
@CONF[:LC_MESSAGES] = Locale.new
@CONF[:DEBUG_LEVEL] = 1
- @CONF[:VERBOSE] = true
end
def IRB.init_error
@@ -104,7 +112,6 @@ module IRB
while opt = ARGV.shift
case opt
when "-f"
- opt = ARGV.shift
@CONF[:RC] = false
when "-m"
@CONF[:MATH_MODE] = true
@@ -113,6 +120,8 @@ module IRB
when "-r"
opt = ARGV.shift
@CONF[:LOAD_MODULES].push opt if opt
+ when /^-K(.)/
+ $KCODE = $1
when "--inspect"
@CONF[:INSPECT_MODE] = true
when "--noinspect"
@@ -121,11 +130,16 @@ module IRB
@CONF[:USE_READLINE] = true
when "--noreadline"
@CONF[:USE_READLINE] = false
-
+ when "--echo"
+ @CONF[:ECHO] = true
+ when "--noecho"
+ @CONF[:ECHO] = false
+ when "--verbose"
+ @CONF[:VERBOSE] = true
+ when "--noverbose"
+ @CONF[:VERBOSE] = false
when "--prompt-mode", "--prompt"
prompt_mode = ARGV.shift.upcase.tr("-", "_").intern
- IRB.fail(UndefinedPromptMode,
- prompt_mode.id2name) unless @CONF[:PROMPT][prompt_mode]
@CONF[:PROMPT_MODE] = prompt_mode
when "--noprompt"
@CONF[:PROMPT_MODE] = :NULL
@@ -133,7 +147,6 @@ module IRB
@CONF[:PROMPT_MODE] = :INF_RUBY
when "--sample-book-mode", "--simple-prompt"
@CONF[:PROMPT_MODE] = :SIMPLE
-
when "--tracer"
@CONF[:USE_TRACER] = true
when "--back-trace-limit"
@@ -154,7 +167,6 @@ module IRB
when /^-/
IRB.fail UnrecognizedSwitch, opt
else
- @CONF[:USE_READLINE] = false
@CONF[:SCRIPT] = opt
$0 = opt
break
@@ -201,32 +213,4 @@ module IRB
end
end
- # initialize tracing function
- def IRB.initialize_tracer
- unless @TRACER_INITIALIZED
- require("tracer")
- Tracer.verbose = false
- Tracer.add_filter {
- |event, file, line, id, binding|
- File::dirname(file) != @CONF[:IRB_LIB_PATH]
- }
- @TRACER_INITIALIZED = true
- end
- end
-
- # initialize mathn function
- def IRB.initialize_mathn
- unless @MATHN_INITIALIZED
- require "mathn"
- @MATHN_INITIALIZED = true
- end
- end
-
- # initialize loader function
- def IRB.initialize_loader
- unless @LOADER_INITIALIZED
- require "irb/loader"
- @LOADER_INITIALIZED = true
- end
- end
end
diff --git a/lib/irb/input-method.rb b/lib/irb/input-method.rb
index ffbc6d9edc..65a016fd07 100644
--- a/lib/irb/input-method.rb
+++ b/lib/irb/input-method.rb
@@ -1,6 +1,6 @@
#
# irb/input-method.rb - input methods using irb
-# $Release Version: 0.7.3$
+# $Release Version: 0.9$
# $Revision$
# $Date$
# by Keiju ISHITSUKA(keiju@ishitsuka.com)
@@ -74,8 +74,9 @@ module IRB
end
def gets
+ print @prompt
l = @io.gets
- print @prompt, l
+# print @prompt, l
l
end
end
@@ -94,6 +95,7 @@ module IRB
def gets
if l = readline(@prompt, true)
+ HISTORY.pop if l.empty?
@line[@line_no += 1] = l + "\n"
else
@eof = true
diff --git a/lib/irb/lc/error.rb b/lib/irb/lc/error.rb
index de38f29978..a80da7567f 100644
--- a/lib/irb/lc/error.rb
+++ b/lib/irb/lc/error.rb
@@ -1,6 +1,6 @@
#
# irb/lc/error.rb -
-# $Release Version: 0.7.3$
+# $Release Version: 0.9$
# $Revision$
# $Date$
# by Keiju ISHITSUKA(keiju@ishitsuka.com)
diff --git a/lib/irb/lc/help-message b/lib/irb/lc/help-message
index daede5ec21..29c7c0fe4a 100644
--- a/lib/irb/lc/help-message
+++ b/lib/irb/lc/help-message
@@ -1,6 +1,6 @@
#
# irb/lc/help-message.rb -
-# $Release Version: 0.7.3$
+# $Release Version: 0.9$
# $Revision$
# $Date$
# by Keiju ISHITSUKA(keiju@ishitsuka.com)
diff --git a/lib/irb/lc/ja/error.rb b/lib/irb/lc/ja/error.rb
index d5aef0a7c8..19585467a0 100644
--- a/lib/irb/lc/ja/error.rb
+++ b/lib/irb/lc/ja/error.rb
@@ -1,6 +1,6 @@
#
# irb/lc/ja/error.rb -
-# $Release Version: 0.7.3$
+# $Release Version: 0.9$
# $Revision$
# $Date$
# by Keiju ISHITSUKA(keiju@ishitsuka.com)
diff --git a/lib/irb/lc/ja/help-message b/lib/irb/lc/ja/help-message
index 9fa3952a0b..1cf980f6ba 100644
--- a/lib/irb/lc/ja/help-message
+++ b/lib/irb/lc/ja/help-message
@@ -1,6 +1,6 @@
#
# irb/lc/ja/help-message.rb -
-# $Release Version: 0.7.3$
+# $Release Version: 0.9$
# $Revision$
# $Date$
# by Keiju ISHITSUKA(keiju@ishitsuka.com)
diff --git a/lib/irb/loader.rb b/lib/irb/loader.rb
deleted file mode 100644
index 6e7a89e454..0000000000
--- a/lib/irb/loader.rb
+++ /dev/null
@@ -1,118 +0,0 @@
-#
-# irb/loader.rb - irb loader
-# $Release Version: 0.7.3$
-# $Revision$
-# $Date$
-# by Keiju ISHITSUKA(keiju@ishitsuka.com)
-#
-# --
-#
-#
-#
-
-module IRB
- class LoadAbort < GlobalExit;end
-
- module Loader
- @RCS_ID='-$Id$-'
-
- alias ruby_load load
- alias ruby_require require
-
- def irb_load(file_name)
- return ruby_load(file_name) unless IRB.conf[:USE_LOADER]
-
- load_sub(file_name)
- return true
- end
-
- def irb_require(file_name)
- return ruby_require(file_name) unless IRB.conf[:USE_LOADER]
-
- rex = Regexp.new("#{Regexp.quote(file_name)}(\.o|\.rb)?")
- return false if $".find{|f| f =~ rex}
-
- case file_name
- when /\.rb$/
- begin
- load_sub(file_name)
- $".push file_name
- return true
- rescue LoadError
- end
- when /\.(so|o|sl)$/
- return ruby_require(file_name)
- end
-
- begin
- load_sub(f = file_name + ".rb")
- $".push f
- return true
- rescue LoadError
- return ruby_require(file_name)
- end
- end
-
- def load_sub(fn)
- if fn =~ /^#{Regexp.quote(File::Separator)}/
- return false unless File.exist?(fn)
- return irb_context.load_file(fn)
- end
-
- for path in $:
- if File.exist?(f = File.join(path, fn))
- return irb_context.load_file(f)
- end
- end
- raise LoadError, "No such file to load -- #{file_name}"
- end
-
- alias load irb_load
- alias require irb_require
- end
-
-# class Context
-# def load_from(file_name)
-# io = FileInputMethod.new(file_name)
-# @irb.signal_status(:IN_LOAD) do
-# switch_io(io, file_name) do
-# eval_input
-# end
-# end
-# end
-# end
-
- class Context
- def load_file(path)
- back_io = @io
- back_path = @irb_path
- back_name = @irb_name
- back_scanner = @irb.scanner
- begin
- @io = FileInputMethod.new(path)
- @irb_name = File.basename(path)
- @irb_path = path
- @irb.signal_status(:IN_LOAD) do
- if back_io.kind_of?(FileInputMethod)
- @irb.eval_input
- else
- begin
- @irb.eval_input
- rescue LoadAbort
- print "load abort!!\n"
- end
- end
- end
- ensure
- @io = back_io
- @irb_name = back_name
- @irb_path = back_path
- @irb.scanner = back_scanner
- end
- end
- end
-
- module ExtendCommand
- include Loader
- end
-end
diff --git a/lib/irb/locale.rb b/lib/irb/locale.rb
index e0a44f3421..0e36359f5b 100644
--- a/lib/irb/locale.rb
+++ b/lib/irb/locale.rb
@@ -1,6 +1,6 @@
#
# irb/locale.rb - internationalization module
-# $Release Version: 0.7.4$
+# $Release Version: 0.9$
# $Revision$
# $Date$
# by Keiju ISHITSUKA(keiju@ishitsuka.com)
@@ -135,6 +135,7 @@ module IRB
end
lc_file.close
toplevel_load lc_file.path, priv
+ lc_file.close(true)
end
private :real_load
diff --git a/lib/irb/ruby-lex.rb b/lib/irb/ruby-lex.rb
index 3647617849..e96edef30b 100644
--- a/lib/irb/ruby-lex.rb
+++ b/lib/irb/ruby-lex.rb
@@ -1,6 +1,6 @@
#
# irb/ruby-lex.rb - ruby lexcal analizer
-# $Release Version: 0.7.3$
+# $Release Version: 0.9$
# $Revision$
# $Date$
# by Keiju ISHITSUKA(keiju@ishitsuka.com)
@@ -50,6 +50,7 @@ class RubyLex
@here_readed = []
@indent = 0
+ @indent_stack = []
@skip_space = false
@readed_auto_clean_up = false
@@ -200,6 +201,7 @@ class RubyLex
@ltype = nil
@quoted = nil
@indent = 0
+ @indent_stack = []
@lex_state = EXPR_BEG
@space_seen = false
@here_header = false
@@ -235,6 +237,7 @@ class RubyLex
@exp_line_no = @line_no
@indent = 0
+ @indent_stack = []
prompt
rescue TerminateLineInput
initialize_input
@@ -250,6 +253,7 @@ class RubyLex
!@continue or
tk.nil?)
#p tk
+ #p @lex_state
#p self
end
line = get_readed
@@ -356,6 +360,11 @@ class RubyLex
else
@continue = false
@lex_state = EXPR_BEG
+ until (@indent_stack.empty? ||
+ [TkLPAREN, TkLBRACK, TkLBRACE,
+ TkfLPAREN, TkfLBRACK, TkfLBRACE].include?(@indent_stack.last))
+ @indent_stack.pop
+ end
end
@here_header = false
@here_readed = []
@@ -363,26 +372,44 @@ class RubyLex
end
@OP.def_rules("*", "**",
- "!", "!=", "!~",
"=", "==", "===",
"=~", "<=>",
"<", "<=",
">", ">=", ">>") do
|op, io|
- @lex_state = EXPR_BEG
+ case @lex_state
+ when EXPR_FNAME, EXPR_DOT
+ @lex_state = EXPR_ARG
+ else
+ @lex_state = EXPR_BEG
+ end
+ Token(op)
+ end
+
+ @OP.def_rules("!", "!=", "!~") do
+ |op, io|
+ #@lex_state = EXPR_BEG
Token(op)
end
@OP.def_rules("<<") do
|op, io|
+ tk = nil
if @lex_state != EXPR_END && @lex_state != EXPR_CLASS &&
(@lex_state != EXPR_ARG || @space_seen)
c = peek(0)
if /\S/ =~ c && (/["'`]/ =~ c || /[\w_]/ =~ c || c == "-")
tk = identify_here_document
end
- else
- tk = Token(op)
+ end
+ unless tk
+ tk = Token(op)
+ case @lex_state
+ when EXPR_FNAME, EXPR_DOT
+ @lex_state = EXPR_ARG
+ else
+ @lex_state = EXPR_BEG
+ end
end
tk
end
@@ -408,7 +435,7 @@ class RubyLex
Token(TkQUESTION)
else
ch = getc
- if @lex_state == EXPR_ARG && ch !~ /\s/
+ if @lex_state == EXPR_ARG && ch =~ /\s/
ungetc
@lex_state = EXPR_BEG;
Token(TkQUESTION)
@@ -437,11 +464,13 @@ class RubyLex
end
@OP.def_rule("+@", proc{@lex_state == EXPR_FNAME}) do
- Token(TkUPLUS)
+ |op, io|
+ Token(op)
end
@OP.def_rule("-@", proc{@lex_state == EXPR_FNAME}) do
- Token(TkUMINUS)
+ |op, io|
+ Token(op)
end
@OP.def_rules("+", "-") do
@@ -488,6 +517,7 @@ class RubyLex
|op, io|
@lex_state = EXPR_END
@indent -= 1
+ @indent_stack.pop
Token(op)
end
@@ -519,7 +549,7 @@ class RubyLex
elsif peek(0) == '='
getc
@lex_state = EXPR_BEG
- Token(TkOPASGN, :/) #/)
+ Token(TkOPASGN, "/") #/)
elsif @lex_state == EXPR_ARG and @space_seen and peek(0) !~ /\s/
identify_string(op)
else
@@ -538,18 +568,29 @@ class RubyLex
# Token(OP_ASGN, :^)
# end
- @OP.def_rules(",", ";") do
+ @OP.def_rules(",") do
|op, io|
@lex_state = EXPR_BEG
Token(op)
end
+ @OP.def_rules(";") do
+ |op, io|
+ @lex_state = EXPR_BEG
+ until (@indent_stack.empty? ||
+ [TkLPAREN, TkLBRACK, TkLBRACE,
+ TkfLPAREN, TkfLBRACK, TkfLBRACE].include?(@indent_stack.last))
+ @indent_stack.pop
+ end
+ Token(op)
+ end
+
@OP.def_rule("~") do
@lex_state = EXPR_BEG
Token("~")
end
- @OP.def_rule("~@", proc{@lex_state = EXPR_FNAME}) do
+ @OP.def_rule("~@", proc{@lex_state == EXPR_FNAME}) do
@lex_state = EXPR_BEG
Token("~")
end
@@ -558,11 +599,13 @@ class RubyLex
@indent += 1
if @lex_state == EXPR_BEG || @lex_state == EXPR_MID
@lex_state = EXPR_BEG
- Token(TkfLPAREN)
+ tk_c = TkfLPAREN
else
@lex_state = EXPR_BEG
- Token(TkLPAREN)
+ tk_c = TkLPAREN
end
+ @indent_stack.push tk_c
+ tk = Token(tk_c)
end
@OP.def_rule("[]", proc{@lex_state == EXPR_FNAME}) do
@@ -576,29 +619,31 @@ class RubyLex
@OP.def_rule("[") do
@indent += 1
if @lex_state == EXPR_FNAME
- Token(TkfLBRACK)
+ tk_c = TkfLBRACK
else
if @lex_state == EXPR_BEG || @lex_state == EXPR_MID
- t = Token(TkLBRACK)
+ tk_c = TkLBRACK
elsif @lex_state == EXPR_ARG && @space_seen
- t = Token(TkLBRACK)
+ tk_c = TkLBRACK
else
- t = Token(TkfLBRACK)
+ tk_c = TkfLBRACK
end
@lex_state = EXPR_BEG
- t
end
+ @indent_stack.push tk_c
+ Token(tk_c)
end
@OP.def_rule("{") do
@indent += 1
if @lex_state != EXPR_END && @lex_state != EXPR_ARG
- t = Token(TkLBRACE)
+ tk_c = TkLBRACE
else
- t = Token(TkfLBRACE)
+ tk_c = TkfLBRACE
end
@lex_state = EXPR_BEG
- t
+ @indent_stack.push tk_c
+ Token(tk_c)
end
@OP.def_rule('\\') do
@@ -632,7 +677,7 @@ class RubyLex
end
@OP.def_rule('@') do
- if peek(0) =~ /[\w_]/
+ if peek(0) =~ /[\w_@]/
ungetc
identify_identifier
else
@@ -691,21 +736,32 @@ class RubyLex
def identify_identifier
token = ""
- token.concat getc if peek(0) =~ /[$@]/
+ if peek(0) =~ /[$@]/
+ token.concat (c = getc)
+ if c == "@" and peek(0) == "@"
+ token.concat getc
+ end
+ end
+
while (ch = getc) =~ /\w|_/
print ":", ch, ":" if RubyLex.debug?
token.concat ch
end
ungetc
- if ch == "!" or ch == "?"
+ if (ch == "!" || ch == "?") && token[0,1] =~ /\w/ && peek(0) != "="
token.concat getc
end
+
# almost fix token
case token
when /^\$/
return Token(TkGVAR, token)
+ when /^\@\@/
+ @lex_state = EXPR_END
+ # p Token(TkCVAR, token)
+ return Token(TkCVAR, token)
when /^\@/
@lex_state = EXPR_END
return Token(TkIVAR, token)
@@ -727,9 +783,37 @@ class RubyLex
else
if @lex_state != EXPR_FNAME
if ENINDENT_CLAUSE.include?(token)
- @indent += 1
+ # check for ``class = val''.
+ valid = true
+ case token
+ when "class"
+ valid = false unless peek_match?(/^\s*(<<|\w)/)
+
+ when "def"
+ valid = false if peek_match?(/^\s*(([+-\/*&\|^]|<<|>>|\|\||\&\&)?=|\&\&|\|\|)/)
+ when "do"
+ valid = false if peek_match?(/^\s*([+-\/*]?=|\*|<|>|\&)/)
+ when *ENINDENT_CLAUSE
+ valid = false if peek_match?(/^\s*([+-\/*]?=|\*|<|>|\&|\|)/)
+ else
+ # no nothing
+ end
+ if valid
+ if token == "do"
+ if ![TkFOR, TkWHILE, TkUNTIL].include?(@indent_stack.last)
+ @indent += 1
+ @indent_stack.push token_c
+ end
+ else
+ @indent += 1
+ @indent_stack.push token_c
+ end
+# p @indent_stack
+ end
+
elsif DEINDENT_CLAUSE.include?(token)
@indent -= 1
+ @indent_stack.pop
end
@lex_state = trans[0]
else
@@ -830,9 +914,12 @@ class RubyLex
@lex_state = EXPR_END
if ch = getc
- if peek(0) == "x"
+ if /[xX]/ =~ peek(0)
ch = getc
- match = /[0-9a-f_]/
+ match = /[0-9a-fA-F_]/
+ elsif /[bB]/ =~ peek(0)
+ ch = getc
+ match = /[01_]/
else
match = /[0-7_]/
end
@@ -878,17 +965,25 @@ class RubyLex
@quoted = quoted
subtype = nil
begin
- while ch = getc
- if @quoted == ch
+ nest = 0
+ while ch = getc
+ if @quoted == ch and nest == 0
break
elsif @ltype != "'" && @ltype != "]" and ch == "#"
subtype = true
elsif ch == '\\' #'
read_escape
end
+ if PERCENT_PAREN.values.include?(@quoted)
+ if PERCENT_PAREN[ch] == @quoted
+ nest += 1
+ elsif ch == @quoted
+ nest -= 1
+ end
+ end
end
if @ltype == "/"
- if peek(0) =~ /i|o|n|e|s/
+ if peek(0) =~ /i|m|x|o|e|s|u|n/
getc
end
end
@@ -908,9 +1003,9 @@ class RubyLex
@ltype = "#"
while ch = getc
- if ch == "\\" #"
- read_escape
- end
+# if ch == "\\" #"
+# read_escape
+# end
if ch == "\n"
@ltype = nil
ungetc
diff --git a/lib/irb/ruby-token.rb b/lib/irb/ruby-token.rb
index 373c8defea..55c1bd11f3 100644
--- a/lib/irb/ruby-token.rb
+++ b/lib/irb/ruby-token.rb
@@ -1,6 +1,6 @@
#
# irb/ruby-token.rb - ruby tokens
-# $Release Version: 0.7.3$
+# $Release Version: 0.9$
# $Revision$
# $Date$
# by Keiju ISHITSUKA(keiju@ishitsuka.com)
@@ -155,6 +155,7 @@ module RubyToken
[:TkIDENTIFIER, TkId],
[:TkFID, TkId],
[:TkGVAR, TkId],
+ [:TkCVAR, TkId],
[:TkIVAR, TkId],
[:TkCONSTANT, TkId],
diff --git a/lib/irb/slex.rb b/lib/irb/slex.rb
index 26008906e5..1cf23255ad 100644
--- a/lib/irb/slex.rb
+++ b/lib/irb/slex.rb
@@ -1,6 +1,6 @@
#
# irb/slex.rb - symple lex analizer
-# $Release Version: 0.7.3$
+# $Release Version: 0.9$
# $Revision$
# $Date$
# by Keiju ISHITSUKA(keiju@ishituska.com)
@@ -68,8 +68,7 @@ class SLex
case token
when Array
when String
- token = token.split(//)
- match(token.split(//))
+ return match(token.split(//))
else
return @head.match_io(token)
end
diff --git a/lib/irb/version.rb b/lib/irb/version.rb
index 367cc21046..a9e37f7e7b 100644
--- a/lib/irb/version.rb
+++ b/lib/irb/version.rb
@@ -1,6 +1,6 @@
#
# irb/version.rb - irb version definition file
-# $Release Version: 0.7.4$
+# $Release Version: 0.9$
# $Revision$
# $Date$
# by Keiju ISHITSUKA(keiju@ishitsuka.com)
@@ -11,6 +11,6 @@
#
module IRB
- @RELEASE_VERSION = "0.7.4"
- @LAST_UPDATE_DATE = "01/05/08"
+ @RELEASE_VERSION = "0.9"
+ @LAST_UPDATE_DATE = "02/07/03"
end
diff --git a/lib/irb/workspace.rb b/lib/irb/workspace.rb
index 68559a1173..6dcb450fd7 100644
--- a/lib/irb/workspace.rb
+++ b/lib/irb/workspace.rb
@@ -1,6 +1,6 @@
#
# irb/workspace-binding.rb -
-# $Release Version: 0.7.3$
+# $Release Version: 0.9$
# $Revision$
# $Date$
# by Keiju ISHITSUKA(keiju@ishitsuka.com)
@@ -11,11 +11,12 @@
#
module IRB
class WorkSpace
- # create new workspace.
- # set self to main if specified, otherwise inherit main
- # from TOPLEVEL_BINDING.
+ # create new workspace. set self to main if specified, otherwise
+ # inherit main from TOPLEVEL_BINDING.
def initialize(*main)
- if IRB.conf[:SINGLE_IRB]
+ if main[0].kind_of?(Binding)
+ @binding = main.shift
+ elsif IRB.conf[:SINGLE_IRB]
@binding = TOPLEVEL_BINDING
else
case IRB.conf[:CONTEXT_MODE]
@@ -76,10 +77,10 @@ EOF
attr_reader :binding
attr_reader :main
- def evaluate(statements, file = __FILE__, line = __LINE__)
- eval statements, @binding, file, line
+ def evaluate(context, statements, file = __FILE__, line = __LINE__)
+ eval(statements, @binding, file, line)
end
-
+
# error message manupilator
def filter_backtrace(bt)
case IRB.conf[:CONTEXT_MODE]
diff --git a/lib/irb/ws-for-case-2.rb b/lib/irb/ws-for-case-2.rb
index 8cfa87ae3d..1c58fb7dda 100644
--- a/lib/irb/ws-for-case-2.rb
+++ b/lib/irb/ws-for-case-2.rb
@@ -1,6 +1,6 @@
#
# irb/ws-for-case-2.rb -
-# $Release Version: 0.7.3$
+# $Release Version: 0.9$
# $Revision$
# $Date$
# by Keiju ISHITSUKA(keiju@ishitsuka.com)
diff --git a/lib/irb/xmp.rb b/lib/irb/xmp.rb
index e0bcee4bdb..4bcc2ca22f 100644
--- a/lib/irb/xmp.rb
+++ b/lib/irb/xmp.rb
@@ -1,6 +1,6 @@
#
# xmp.rb - irb version of gotoken xmp
-# $Release Version: 0.7.1$
+# $Release Version: 0.9$
# $Revision$
# $Date$
# by Keiju ISHITSUKA(Nippon Rational Inc.)
@@ -10,21 +10,23 @@
#
#
-require "irb/irb"
+require "irb"
require "irb/frame"
class XMP
@RCS_ID='-$Id$-'
def initialize(bind = nil)
+ IRB.init_config(nil)
#IRB.parse_opts
#IRB.load_modules
+ IRB.conf[:PROMPT_MODE] = :XMP
+
bind = IRB::Frame.top(1) unless bind
- main = eval("self", bind)
+ ws = IRB::WorkSpace.new(bind)
@io = StringInputMethod.new
- @irb = IRB::Irb.new(main, bind, @io)
- @irb.context.prompt_mode = :XMP
+ @irb = IRB::Irb.new(ws, @io)
@irb.context.ignore_sigint = false
# IRB.conf[:IRB_RC].call(@irb.context) if IRB.conf[:IRB_RC]