[macruby-changes] [3999] MacRuby/trunk

source_changes at macosforge.org source_changes at macosforge.org
Sun May 2 04:40:18 PDT 2010


Revision: 3999
          http://trac.macosforge.org/projects/ruby/changeset/3999
Author:   eloy.de.enige at gmail.com
Date:     2010-05-02 04:40:15 -0700 (Sun, 02 May 2010)
Log Message:
-----------
Replaced IRB with DietRB 0.4.2, which is a leightweight rewrite of IRB.

For more info, and to create tickets, see http://github.com/alloy/dietrb

Modified Paths:
--------------
    MacRuby/trunk/bin/irb
    MacRuby/trunk/lib/irb/context.rb
    MacRuby/trunk/lib/irb/ext/history.rb
    MacRuby/trunk/lib/irb/version.rb
    MacRuby/trunk/lib/irb.rb

Added Paths:
-----------
    MacRuby/trunk/lib/irb/ext/colorize.rb
    MacRuby/trunk/lib/irb/ext/completion.rb
    MacRuby/trunk/lib/irb/ext/macruby.rb
    MacRuby/trunk/lib/irb/formatter.rb
    MacRuby/trunk/lib/irb/source.rb

Removed Paths:
-------------
    MacRuby/trunk/lib/irb/cmd/chws.rb
    MacRuby/trunk/lib/irb/cmd/fork.rb
    MacRuby/trunk/lib/irb/cmd/help.rb
    MacRuby/trunk/lib/irb/cmd/load.rb
    MacRuby/trunk/lib/irb/cmd/nop.rb
    MacRuby/trunk/lib/irb/cmd/pushws.rb
    MacRuby/trunk/lib/irb/cmd/subirb.rb
    MacRuby/trunk/lib/irb/completion.rb
    MacRuby/trunk/lib/irb/ext/change-ws.rb
    MacRuby/trunk/lib/irb/ext/loader.rb
    MacRuby/trunk/lib/irb/ext/math-mode.rb
    MacRuby/trunk/lib/irb/ext/multi-irb.rb
    MacRuby/trunk/lib/irb/ext/save-history.rb
    MacRuby/trunk/lib/irb/ext/tracer.rb
    MacRuby/trunk/lib/irb/ext/use-loader.rb
    MacRuby/trunk/lib/irb/ext/workspaces.rb
    MacRuby/trunk/lib/irb/extend-command.rb
    MacRuby/trunk/lib/irb/frame.rb
    MacRuby/trunk/lib/irb/help.rb
    MacRuby/trunk/lib/irb/init.rb
    MacRuby/trunk/lib/irb/input-method.rb
    MacRuby/trunk/lib/irb/lc/error.rb
    MacRuby/trunk/lib/irb/lc/help-message
    MacRuby/trunk/lib/irb/lc/ja/encoding_aliases.rb
    MacRuby/trunk/lib/irb/lc/ja/error.rb
    MacRuby/trunk/lib/irb/lc/ja/help-message
    MacRuby/trunk/lib/irb/locale.rb
    MacRuby/trunk/lib/irb/magic-file.rb
    MacRuby/trunk/lib/irb/notifier.rb
    MacRuby/trunk/lib/irb/output-method.rb
    MacRuby/trunk/lib/irb/ruby-lex.rb
    MacRuby/trunk/lib/irb/ruby-token.rb
    MacRuby/trunk/lib/irb/slex.rb
    MacRuby/trunk/lib/irb/src_encoding.rb
    MacRuby/trunk/lib/irb/workspace.rb
    MacRuby/trunk/lib/irb/ws-for-case-2.rb
    MacRuby/trunk/lib/irb/xmp.rb

Property Changed:
----------------
    MacRuby/trunk/bin/irb

Modified: MacRuby/trunk/bin/irb
===================================================================
--- MacRuby/trunk/bin/irb	2010-05-02 05:58:51 UTC (rev 3998)
+++ MacRuby/trunk/bin/irb	2010-05-02 11:40:15 UTC (rev 3999)
@@ -1,20 +1,36 @@
 #!/usr/bin/env ruby
-#
-#   irb.rb - interactive ruby
-#   	$Release Version: 0.9.5 $
-#   	$Revision: 14912 $
-#   	by Keiju ISHITSUKA(keiju at ruby-lang.org)
-#
 
-require "irb"
+require 'irb'
 
-if __FILE__ == $0
-  IRB.start(__FILE__)
+unless ARGV.empty?
+  require 'optparse'
+  
+  OptionParser.new do |opt|
+    bin = File.basename($0)
+    opt.banner = "Usage:  #{bin} [options] [programfile] [arguments]"
+    opt.on("-r load-lib",     "Loads the given library (same as `ruby -r')") { |lib| require lib }
+    opt.on("-d",              "Set $DEBUG to true (same as `ruby -d')") { $DEBUG = true }
+    opt.on("-I path",         "Add path to $LOAD_PATH") { |path| $LOAD_PATH.unshift(path) }
+    opt.on("--simple-prompt", "Simple prompt mode") { IRB.formatter.prompt = :simple }
+    opt.on("--noprompt",      "No prompt mode") { IRB.formatter.prompt = nil }
+    opt.on("-v", "--version", "Print the version of #{bin}") do
+      puts IRB::VERSION::DESCRIPTION
+      exit
+    end
+  end.parse!(ARGV)
+end
+
+irbrc = File.expand_path("~/.irbrc")
+load(irbrc) if File.exist?(irbrc)
+
+IRB.formatter.filter_from_backtrace << /^#{__FILE__}/
+
+if ARGV.empty?
+  irb(self, TOPLEVEL_BINDING.dup)
 else
-  # check -e option
-  if /^-e$/ =~ $0
-    IRB.start(__FILE__)
-  else
-    IRB.setup(__FILE__)
+  path = ARGV.shift
+  context = IRB::Context.new(self, TOPLEVEL_BINDING.dup)
+  File.open(path, 'r') do |file|
+    file.each_line { |line| context.input_line(line) }
   end
-end
+end
\ No newline at end of file


Property changes on: MacRuby/trunk/bin/irb
___________________________________________________________________
Added: svn:executable
   + *

Deleted: MacRuby/trunk/lib/irb/cmd/chws.rb
===================================================================
--- MacRuby/trunk/lib/irb/cmd/chws.rb	2010-05-02 05:58:51 UTC (rev 3998)
+++ MacRuby/trunk/lib/irb/cmd/chws.rb	2010-05-02 11:40:15 UTC (rev 3999)
@@ -1,32 +0,0 @@
-#
-#   change-ws.rb - 
-#   	$Release Version: 0.9.5$
-#   	$Revision: 14912 $
-#   	by Keiju ISHITSUKA(keiju at ruby-lang.org)
-#
-# --
-#
-#   
-#
-
-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
-

Deleted: MacRuby/trunk/lib/irb/cmd/fork.rb
===================================================================
--- MacRuby/trunk/lib/irb/cmd/fork.rb	2010-05-02 05:58:51 UTC (rev 3998)
+++ MacRuby/trunk/lib/irb/cmd/fork.rb	2010-05-02 11:40:15 UTC (rev 3999)
@@ -1,38 +0,0 @@
-#
-#   fork.rb - 
-#   	$Release Version: 0.9.5 $
-#   	$Revision: 14912 $
-#   	by Keiju ISHITSUKA(keiju at ruby-lang.org)
-#
-# --
-#
-#   
-#
-
- at RCS_ID='-$Id: fork.rb 14912 2008-01-06 15:49:38Z akr $-'
-
-
-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
-
-

Deleted: MacRuby/trunk/lib/irb/cmd/help.rb
===================================================================
--- MacRuby/trunk/lib/irb/cmd/help.rb	2010-05-02 05:58:51 UTC (rev 3998)
+++ MacRuby/trunk/lib/irb/cmd/help.rb	2010-05-02 11:40:15 UTC (rev 3999)
@@ -1,34 +0,0 @@
-#
-#   help.rb - helper using ri
-#   	$Release Version: 0.9.5$
-#   	$Revision: 15761 $
-#
-# --
-#
-#   
-#
-
-require 'rdoc/ri/driver'
-require 'rdoc/ri/util'
-
-module IRB
-  module ExtendCommand
-    module Help
-      begin
-        @ri = RDoc::RI::Driver.new
-      rescue SystemExit
-      else
-        def self.execute(context, *names)
-          names.each do |name|
-            begin
-              @ri.get_info_for(name.to_s)
-            rescue RDoc::RI::Error
-              puts $!.message
-            end
-          end
-          nil
-        end
-      end
-    end
-  end
-end

Deleted: MacRuby/trunk/lib/irb/cmd/load.rb
===================================================================
--- MacRuby/trunk/lib/irb/cmd/load.rb	2010-05-02 05:58:51 UTC (rev 3998)
+++ MacRuby/trunk/lib/irb/cmd/load.rb	2010-05-02 11:40:15 UTC (rev 3999)
@@ -1,66 +0,0 @@
-#
-#   load.rb - 
-#   	$Release Version: 0.9.5$
-#   	$Revision: 14912 $
-#   	by Keiju ISHITSUKA(keiju at ruby-lang.org)
-#
-# --
-#
-#   
-#
-
-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

Deleted: MacRuby/trunk/lib/irb/cmd/nop.rb
===================================================================
--- MacRuby/trunk/lib/irb/cmd/nop.rb	2010-05-02 05:58:51 UTC (rev 3998)
+++ MacRuby/trunk/lib/irb/cmd/nop.rb	2010-05-02 11:40:15 UTC (rev 3999)
@@ -1,38 +0,0 @@
-#
-#   nop.rb - 
-#   	$Release Version: 0.9.5$
-#   	$Revision: 14912 $
-#   	by Keiju ISHITSUKA(keiju at ruby-lang.org)
-#
-# --
-#
-#   
-#
-module IRB
-  module ExtendCommand
-    class Nop
-      
-      @RCS_ID='-$Id: nop.rb 14912 2008-01-06 15:49:38Z akr $-'
-
-      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
-

Deleted: MacRuby/trunk/lib/irb/cmd/pushws.rb
===================================================================
--- MacRuby/trunk/lib/irb/cmd/pushws.rb	2010-05-02 05:58:51 UTC (rev 3998)
+++ MacRuby/trunk/lib/irb/cmd/pushws.rb	2010-05-02 11:40:15 UTC (rev 3999)
@@ -1,38 +0,0 @@
-#
-#   change-ws.rb - 
-#   	$Release Version: 0.9.5$
-#   	$Revision: 14912 $
-#   	by Keiju ISHITSUKA(keiju at ruby-lang.org)
-#
-# --
-#
-#   
-#
-
-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
-

Deleted: MacRuby/trunk/lib/irb/cmd/subirb.rb
===================================================================
--- MacRuby/trunk/lib/irb/cmd/subirb.rb	2010-05-02 05:58:51 UTC (rev 3998)
+++ MacRuby/trunk/lib/irb/cmd/subirb.rb	2010-05-02 11:40:15 UTC (rev 3999)
@@ -1,42 +0,0 @@
-#!/usr/local/bin/ruby
-#
-#   multi.rb - 
-#   	$Release Version: 0.9.5$
-#   	$Revision: 14912 $
-#   	by Keiju ISHITSUKA(keiju at ruby-lang.org)
-#
-# --
-#
-#   
-#
-
-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

Deleted: MacRuby/trunk/lib/irb/completion.rb
===================================================================
--- MacRuby/trunk/lib/irb/completion.rb	2010-05-02 05:58:51 UTC (rev 3998)
+++ MacRuby/trunk/lib/irb/completion.rb	2010-05-02 11:40:15 UTC (rev 3999)
@@ -1,207 +0,0 @@
-#
-#   irb/completor.rb - 
-#   	$Release Version: 0.9$
-#   	$Revision: 20880 $
-#   	by Keiju ISHITSUKA(keiju at ishitsuka.com)
-#       From Original Idea of shugo at ruby-lang.org
-#
-
-require "readline"
-
-module IRB
-  module InputCompletor
-
-    @RCS_ID='-$Id: completion.rb 20880 2008-12-19 11:37:41Z yugui $-'
-
-    ReservedWords = [
-      "BEGIN", "END",
-      "alias", "and", 
-      "begin", "break", 
-      "case", "class",
-      "def", "defined", "do",
-      "else", "elsif", "end", "ensure",
-      "false", "for", 
-      "if", "in", 
-      "module", 
-      "next", "nil", "not",
-      "or", 
-      "redo", "rescue", "retry", "return",
-      "self", "super",
-      "then", "true",
-      "undef", "unless", "until",
-      "when", "while",
-      "yield",
-    ]
-      
-    CompletionProc = proc { |input|
-      bind = IRB.conf[:MAIN_CONTEXT].workspace.binding
-      
-#      puts "input: #{input}"
-
-      case input
-      when /^(\/[^\/]*\/)\.([^.]*)$/
-	# Regexp
-	receiver = $1
-	message = Regexp.quote($2)
-
-	candidates = Regexp.instance_methods.collect{|m| m.to_s}
-	select_message(receiver, message, candidates)
-
-      when /^([^\]]*\])\.([^.]*)$/
-	# Array
-	receiver = $1
-	message = Regexp.quote($2)
-
-	candidates = Array.instance_methods.collect{|m| m.to_s}
-	select_message(receiver, message, candidates)
-
-      when /^([^\}]*\})\.([^.]*)$/
-	# Proc or Hash
-	receiver = $1
-	message = Regexp.quote($2)
-
-	candidates = Proc.instance_methods.collect{|m| m.to_s}
-	candidates |= Hash.instance_methods.collect{|m| m.to_s}
-	select_message(receiver, message, candidates)
-	
-      when /^(:[^:.]*)$/
- 	# Symbol
-	if Symbol.respond_to?(:all_symbols)
-	  sym = $1
-	  candidates = Symbol.all_symbols.collect{|s| ":" + s.id2name}
-	  candidates.grep(/^#{sym}/)
-	else
-	  []
-	end
-
-      when /^::([A-Z][^:\.\(]*)$/
-	# Absolute Constant or class methods
-	receiver = $1
-	candidates = Object.constants.collect{|m| m.to_s}
-	candidates.grep(/^#{receiver}/).collect{|e| "::" + e}
-
-      when /^(((::)?[A-Z][^:.\(]*)+)::?([^:.]*)$/
-	# Constant or class methods
-	receiver = $1
-	message = Regexp.quote($4)
-	begin
-	  candidates = eval("#{receiver}.constants.collect{|m| m.to_s}", bind)
-	  candidates |= eval("#{receiver}.methods.collect{|m| m.to_s}", bind)
-	rescue Exception
-	  candidates = []
-	end
-	candidates.grep(/^#{message}/).collect{|e| receiver + "::" + e}
-
-      when /^(:[^:.]+)\.([^.]*)$/
-	# Symbol
-	receiver = $1
-	message = Regexp.quote($2)
-
-	candidates = Symbol.instance_methods.collect{|m| m.to_s}
-	select_message(receiver, message, candidates)
-
-      when /^(-?(0[dbo])?[0-9_]+(\.[0-9_]+)?([eE]-?[0-9]+)?)\.([^.]*)$/
-	# Numeric
-	receiver = $1
-	message = Regexp.quote($5)
-
-	begin
-	  candidates = eval(receiver, bind).methods.collect{|m| m.to_s}
-	rescue Exception
-	  candidates = []
-	end
-	select_message(receiver, message, candidates)
-
-      when /^(-?0x[0-9a-fA-F_]+)\.([^.]*)$/
-	# Numeric(0xFFFF)
-	receiver = $1
-	message = Regexp.quote($2)
-
-	begin
-	  candidates = eval(receiver, bind).methods.collect{|m| m.to_s}
-	rescue Exception
-	  candidates = []
-	end
-	select_message(receiver, message, candidates)
-
-      when /^(\$[^.]*)$/
-	regmessage = Regexp.new(Regexp.quote($1))
-	candidates = global_variables.collect{|m| m.to_s}.grep(regmessage)
-
-#      when /^(\$?(\.?[^.]+)+)\.([^.]*)$/
-      when /^((\.?[^.]+)+)\.([^.]*)$/
-	# variable
-	receiver = $1
-	message = Regexp.quote($3)
-
-	gv = eval("global_variables", bind).collect{|m| m.to_s}
-	lv = eval("local_variables", bind).collect{|m| m.to_s}
-	cv = eval("self.class.constants", bind).collect{|m| m.to_s}
-	
-	if (gv | lv | cv).include?(receiver)
-	  # foo.func and foo is local var.
-	  candidates = eval("#{receiver}.methods", bind).collect{|m| m.to_s}
-	elsif /^[A-Z]/ =~ receiver and /\./ !~ receiver
-	  # Foo::Bar.func
-	  begin
-	    candidates = eval("#{receiver}.methods", bind).collect{|m| m.to_s}
-	  rescue Exception
-	    candidates = []
-	  end
-	else
-	  # func1.func2
-	  candidates = []
-	  ObjectSpace.each_object(Module){|m|
-	    begin
-	      name = m.name
-	    rescue Exception
-	      name = ""
-	    end
-	    next if name != "IRB::Context" and 
-	      /^(IRB|SLex|RubyLex|RubyToken)/ =~ name
-	    candidates.concat m.instance_methods(false).collect{|x| x.to_s}
-	  }
-	  candidates.sort!
-	  candidates.uniq!
-	end
-	select_message(receiver, message, candidates)
-
-      when /^\.([^.]*)$/
-	# unknown(maybe String)
-
-	receiver = ""
-	message = Regexp.quote($1)
-
-	candidates = String.instance_methods(true).collect{|m| m.to_s}
-	select_message(receiver, message, candidates)
-
-      else
-	candidates = eval("methods | private_methods | local_variables | self.class.constants", bind).collect{|m| m.to_s}
-			  
-	(candidates|ReservedWords).grep(/^#{Regexp.quote(input)}/)
-      end
-    }
-
-    Operators = ["%", "&", "*", "**", "+",  "-",  "/",
-      "<", "<<", "<=", "<=>", "==", "===", "=~", ">", ">=", ">>",
-      "[]", "[]=", "^",]
-
-    def self.select_message(receiver, message, candidates)
-      candidates.grep(/^#{message}/).collect do |e|
-	case e
-	when /^[a-zA-Z_]/
-	  receiver + "." + e
-	when /^[0-9]/
-	when *Operators
-	  #receiver + " " + e
-	end
-      end
-    end
-  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

Modified: MacRuby/trunk/lib/irb/context.rb
===================================================================
--- MacRuby/trunk/lib/irb/context.rb	2010-05-02 05:58:51 UTC (rev 3998)
+++ MacRuby/trunk/lib/irb/context.rb	2010-05-02 11:40:15 UTC (rev 3999)
@@ -1,255 +1,121 @@
+# MacRuby implementation of IRB.
 #
-#   irb/context.rb - irb context
-#   	$Release Version: 0.9.5$
-#   	$Revision: 19670 $
-#   	by Keiju ISHITSUKA(keiju at ruby-lang.org)
-#
-# --
-#
-#   
-#
-require "irb/workspace"
+# This file is covered by the Ruby license. See COPYING for more details.
+# 
+# Copyright (C) 2009-2010, Eloy Duran <eloy.de.enige at gmail.com>
 
+require 'irb/formatter'
+require 'readline'
+
 module IRB
   class Context
-    #
-    # Arguments:
-    #   input_method: nil -- stdin or readline
-    #		      String -- File
-    #		      other -- using this as InputMethod
-    #
-    def initialize(irb, workspace = nil, input_method = nil, output_method = nil)
-      @irb = irb
-      if workspace
-	@workspace = workspace
-      else
-	@workspace = WorkSpace.new
+    class << self
+      attr_accessor :current
+      
+      def make_current(context)
+        # Messing with a current context is gonna bite me in the ass when we
+        # get to multi-threading, but we'll it when we get there.
+        before, @current = @current, context
+        yield
+      ensure
+        @current = before
       end
-      @thread = Thread.current if defined? Thread
-#      @irb_level = 0
-
-      # copy of default configuration
-      @ap_name = IRB.conf[:AP_NAME]
-      @rc = IRB.conf[:RC]
-      @load_modules = IRB.conf[:LOAD_MODULES]
-
-      @use_readline = IRB.conf[:USE_READLINE]
-      @inspect_mode = IRB.conf[:INSPECT_MODE]
-
-      self.math_mode = IRB.conf[:MATH_MODE] if IRB.conf[:MATH_MODE]
-      self.use_tracer = IRB.conf[:USE_TRACER] if IRB.conf[:USE_TRACER]
-      self.use_loader = IRB.conf[:USE_LOADER] if IRB.conf[:USE_LOADER]
-      self.eval_history = IRB.conf[:EVAL_HISTORY] if IRB.conf[:EVAL_HISTORY]
-
-      @ignore_sigint = IRB.conf[:IGNORE_SIGINT]
-      @ignore_eof = IRB.conf[:IGNORE_EOF]
-
-      @back_trace_limit = IRB.conf[:BACK_TRACE_LIMIT]
       
-      self.prompt_mode = IRB.conf[:PROMPT_MODE]
-
-      if IRB.conf[:SINGLE_IRB] or !defined?(JobManager)
-	@irb_name = IRB.conf[:IRB_NAME]
-      else
-	@irb_name = "irb#"+IRB.JobManager.n_jobs.to_s
+      def processors
+        @processors ||= []
       end
-      @irb_path = "(" + @irb_name + ")"
-
-      case input_method
-      when nil
-	case use_readline?
-	when nil
-	  if (defined?(ReadlineInputMethod) && STDIN.tty? &&
-	      IRB.conf[:PROMPT_MODE] != :INF_RUBY)
-	    @io = ReadlineInputMethod.new
-	  else
-	    @io = StdioInputMethod.new
-	  end
-	when false
-	  @io = StdioInputMethod.new
-	when true
-	  if defined?(ReadlineInputMethod)
-	    @io = ReadlineInputMethod.new
-	  else
-	    @io = StdioInputMethod.new
-	  end
-	end
-
-      when String
-	@io = FileInputMethod.new(input_method)
-	@irb_name = File.basename(input_method)
-	@irb_path = input_method
-      else
-	@io = input_method
-      end
-      self.save_history = IRB.conf[:SAVE_HISTORY] if IRB.conf[:SAVE_HISTORY]
-
-      if output_method
-	@output_method = output_method
-      else
-	@output_method = StdioOutputMethod.new
-      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
+    
+    attr_reader :object, :binding, :line, :source, :processors
+    
+    def initialize(object, explicit_binding = nil)
+      @object  = object
+      @binding = explicit_binding || object.instance_eval { binding }
+      @line    = 1
+      clear_buffer
+      
+      @processors = self.class.processors.map { |processor| processor.new(self) }
     end
-
-    attr_reader :workspace_home
-    attr_accessor :workspace
-    attr_reader :thread
-    attr_accessor :io
     
-    attr_accessor :irb
-    attr_accessor :ap_name
-    attr_accessor :rc
-    attr_accessor :load_modules
-    attr_accessor :irb_name
-    attr_accessor :irb_path
-
-    attr_reader :use_readline
-    attr_reader :inspect_mode
-
-    attr_reader :prompt_mode
-    attr_accessor :prompt_i
-    attr_accessor :prompt_s
-    attr_accessor :prompt_c
-    attr_accessor :prompt_n
-    attr_accessor :auto_indent_mode
-    attr_accessor :return_format
-
-    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_readline? use_readline
-    alias rc? rc
-    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
+    def __evaluate__(source, file = __FILE__, line = __LINE__)
+      eval(source, @binding, file, line)
     end
-
-    def prompting?
-      verbose? || (STDIN.tty? && @io.kind_of?(StdioInputMethod) ||
-		(defined?(ReadlineInputMethod) && @io.kind_of?(ReadlineInputMethod)))
+    
+    def evaluate(source)
+      result = __evaluate__("_ = (#{source})", '(irb)', @line - @source.buffer.size + 1)
+      puts formatter.result(result)
+      result
+    rescue Exception => e
+      puts formatter.exception(e)
     end
-
-    attr_reader :last_value
-
-    def set_last_value(value)
-      @last_value = value
-      @workspace.evaluate self, "_ = IRB.CurrentContext.last_value"
+    
+    # Reads input and passes it to all processors.
+    def readline
+      input = Readline.readline(formatter.prompt(self), true)
+      @processors.each { |processor| input = processor.input(input) }
+      input
+    rescue Interrupt
+      clear_buffer
+      ""
     end
-
-    attr_reader :irb_name
-
-    def prompt_mode=(mode)
-      @prompt_mode = mode
-      pconf = IRB.conf[:PROMPT][mode]
-      @prompt_i = pconf[:PROMPT_I]
-      @prompt_s = pconf[:PROMPT_S]
-      @prompt_c = pconf[:PROMPT_C]
-      @prompt_n = pconf[:PROMPT_N]
-      @return_format = pconf[:RETURN]
-      if ai = pconf.include?(:AUTO_INDENT)
-	@auto_indent_mode = ai
-      else
-	@auto_indent_mode = IRB.conf[:AUTO_INDENT]
+    
+    def run
+      self.class.make_current(self) do
+        while line = readline
+          continue = process_line(line)
+          break unless continue
+        end
       end
     end
     
-    def inspect?
-      @inspect_mode.nil? or @inspect_mode
-    end
-
-    def file_input?
-      @io.class == FileInputMethod
-    end
-
-    def inspect_mode=(opt)
-      if opt
-	@inspect_mode = opt
-      else
-	@inspect_mode = !@inspect_mode
+    # Returns whether or not the user wants to continue the current runloop.
+    # This can only be done at a code block indentation level of 0.
+    #
+    # For instance, this will continue:
+    #
+    #   process_line("def foo") # => true
+    #   process_line("quit") # => true
+    #   process_line("end") # => true
+    #
+    # But at code block indentation level 0, `quit' means exit the runloop:
+    #
+    #   process_line("quit") # => false
+    def process_line(line)
+      @source << line
+      return false if @source.to_s == "quit"
+      
+      if @source.syntax_error?
+        puts formatter.syntax_error(@line, @source.syntax_error)
+        @source.pop
+      elsif @source.code_block?
+        evaluate(@source)
+        clear_buffer
       end
-      print "Switch to#{unless @inspect_mode; ' non';end} inspect mode.\n" if verbose?
-      @inspect_mode
+      @line += 1
+      
+      true
     end
-
-    def use_readline=(opt)
-      @use_readline = opt
-      print "use readline module\n" if @use_readline
+    
+    def input_line(line)
+      puts formatter.prompt(self) + line
+      process_line(line)
     end
-
-    def debug_level=(value)
-      @debug_level = value
-      RubyLex.debug_level = value
-      SLex.debug_level = value
+    
+    def formatter
+      IRB.formatter
     end
-
-    def debug?
-      @debug_level > 0
+    
+    def clear_buffer
+      @source = Source.new
     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 __exit__ exit
-    def exit(ret = 0)
-      IRB.irb_exit(@irb, ret)
-    end
-
-    NOPRINTING_IVARS = ["@last_value"]
-    NO_INSPECTING_IVARS = ["@irb", "@io"]
-    IDNAME_IVARS = ["@prompt_mode"]
-
-    alias __inspect__ inspect
-    def inspect
-      array = []
-      for ivar in instance_variables.sort{|e1, e2| e1 <=> e2}
-	ivar = ivar.to_s
-	name = ivar.sub(/^@(.*)$/, '\1')
-	val = instance_eval(ivar)
-	case ivar
-	when *NOPRINTING_IVARS
-	  array.push format("conf.%s=%s", name, "...")
-	when *NO_INSPECTING_IVARS
-	  array.push format("conf.%s=%s", name, val.to_s)
-	when *IDNAME_IVARS
-	  array.push format("conf.%s=:%s", name, val.id2name)
-	else
-	  array.push format("conf.%s=%s", name, val.inspect)
-	end
-      end
-      array.join("\n")
-    end
-    alias __to_s__ to_s
-    alias to_s inspect
   end
 end
+
+module Kernel
+  # Creates a new IRB::Context with the given +object+ and runs it.
+  def irb(object, binding = nil)
+    IRB::Context.new(object, binding).run
+  end
+  
+  private :irb
+end
\ No newline at end of file

Deleted: MacRuby/trunk/lib/irb/ext/change-ws.rb
===================================================================
--- MacRuby/trunk/lib/irb/ext/change-ws.rb	2010-05-02 05:58:51 UTC (rev 3998)
+++ MacRuby/trunk/lib/irb/ext/change-ws.rb	2010-05-02 11:40:15 UTC (rev 3999)
@@ -1,61 +0,0 @@
-#
-#   irb/ext/cb.rb - 
-#   	$Release Version: 0.9.5$
-#   	$Revision: 20880 $
-#   	by Keiju ISHITSUKA(keiju at ruby-lang.org)
-#
-# --
-#
-#   
-#
-
-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
-

Added: MacRuby/trunk/lib/irb/ext/colorize.rb
===================================================================
--- MacRuby/trunk/lib/irb/ext/colorize.rb	                        (rev 0)
+++ MacRuby/trunk/lib/irb/ext/colorize.rb	2010-05-02 11:40:15 UTC (rev 3999)
@@ -0,0 +1,186 @@
+# MacRuby implementation of IRB.
+#
+# This file is covered by the Ruby license. See COPYING for more details.
+# 
+# Copyright (C) 2009-2010, Eloy Duran <eloy.de.enige at gmail.com>
+#
+# Portions Copyright (C) 2006-2010 Paul Duncan <pabs at pablotron.org> (Wirble)
+# Portions Copyright (C) 2009-2010 Jens Wille <jens.wille at gmail.com> (Wirble)
+# Portions Copyright (C) 2006-2010 Giles Bowkett (light background color scheme)
+
+module IRB
+  class ColoredFormatter < Formatter
+    TYPE_ALIASES = {
+      :on_comma           => :comma,
+      :refers             => :operator, # Wirble compat
+      :on_op              => :operator,
+      
+      :on_lbrace          => :open_hash,
+      :on_rbrace          => :close_hash,
+      :on_lbracket        => :open_array,
+      :on_rbracket        => :close_array,
+      
+      :on_ident           => :symbol,
+      :on_symbeg          => :symbol_prefix,
+      
+      :on_tstring_beg     => :open_string,
+      :on_tstring_content => :string,
+      :on_tstring_end     => :close_string,
+      
+      :on_int             => :number,
+      :on_float           => :number,
+      :on_kw              => :keyword,
+      :on_const           => :constant,
+      :class              => :constant # Wirble compat
+    }
+    
+    # # object colors
+    # :open_object        => :dark_gray,
+    # :object_class       => :purple,
+    # :object_addr_prefix => :blue,
+    # :object_line_prefix => :blue,
+    # :close_object       => :dark_gray,
+    
+    COLOR_SCHEMES = {
+      :dark_background => {
+        # :prompt             => :green,
+        # :result_prefix      => :light_purple,
+        
+        :comma              => :blue,
+        :operator           => :blue,
+        
+        :open_hash          => :green,
+        :close_hash         => :green,
+        :open_array         => :green,
+        :close_array        => :green,
+        
+        :symbol_prefix      => :yellow, # hmm ident...
+        :symbol             => :yellow,
+        
+        :open_string        => :red,
+        :string             => :cyan,
+        :close_string       => :red,
+        
+        :number             => :cyan,
+        :keyword            => :yellow,
+        :constant           => :light_green
+      },
+      :light_background => {
+        :comma              => :purple,
+        :operator           => :blue,
+        
+        :open_hash          => :red,
+        :close_hash         => :red,
+        :open_array         => :red,
+        :close_array        => :red,
+        
+        :symbol_prefix      => :black,
+        :symbol             => :light_gray,
+        
+        :open_string        => :blue,
+        :string             => :dark_gray,
+        :close_string       => :blue,
+        
+        :number             => :black,
+        :keyword            => :brown,
+        :constant           => :red
+      },
+      :fresh => {
+        :prompt             => :green,
+        :result_prefix      => :light_purple,
+        
+        :comma              => :red,
+        :operator           => :red,
+        
+        :open_hash          => :blue,
+        :close_hash         => :blue,
+        :open_array         => :green,
+        :close_array        => :green,
+        
+        :symbol_prefix      => :yellow,
+        :symbol             => :yellow,
+        
+        :number             => :cyan,
+        :string             => :cyan,
+        :keyword            => :white
+      }
+    }
+    
+    #
+    # Terminal escape codes for colors.
+    #
+    module Color
+      COLORS = {
+        :nothing      => '0;0',
+        :black        => '0;30',
+        :red          => '0;31',
+        :green        => '0;32',
+        :brown        => '0;33',
+        :blue         => '0;34',
+        :cyan         => '0;36',
+        :purple       => '0;35',
+        :light_gray   => '0;37',
+        :dark_gray    => '1;30',
+        :light_red    => '1;31',
+        :light_green  => '1;32',
+        :yellow       => '1;33',
+        :light_blue   => '1;34',
+        :light_cyan   => '1;36',
+        :light_purple => '1;35',
+        :white        => '1;37',
+      }
+      
+      #
+      # Return the escape code for a given color.
+      #
+      def self.escape(name)
+        COLORS.key?(name) && "\e[#{COLORS[name]}m"
+      end
+      
+      CLEAR = escape(:nothing)
+    end
+    
+    attr_reader :colors, :color_scheme
+    
+    def initialize
+      super
+      self.color_scheme = :dark_background
+    end
+    
+    def color_scheme=(scheme)
+      @colors = COLOR_SCHEMES[scheme].dup
+      @color_scheme = scheme
+    end
+    
+    def color(type)
+      type = TYPE_ALIASES[type] if TYPE_ALIASES.has_key?(type)
+      @colors[type]
+    end
+    
+    def colorize_token(type, token)
+      if color = color(type)
+        "#{Color.escape(color)}#{token}#{Color::CLEAR}"
+      else
+        token
+      end
+    end
+    
+    def colorize(str)
+      Ripper.lex(str).map { |_, type, token| colorize_token(type, token) }.join
+    end
+    
+    def prompt(context)
+      colorize_token(:prompt, super)
+    end
+    
+    def result_prefix
+      colorize_token(:result_prefix, Formatter::RESULT_PREFIX)
+    end
+    
+    def result(object)
+      "#{result_prefix} #{colorize(inspect_object(object))}"
+    end
+  end
+end
+
+IRB.formatter = IRB::ColoredFormatter.new
\ No newline at end of file

Added: MacRuby/trunk/lib/irb/ext/completion.rb
===================================================================
--- MacRuby/trunk/lib/irb/ext/completion.rb	                        (rev 0)
+++ MacRuby/trunk/lib/irb/ext/completion.rb	2010-05-02 11:40:15 UTC (rev 3999)
@@ -0,0 +1,194 @@
+# MacRuby implementation of IRB.
+#
+# This file is covered by the Ruby license. See COPYING for more details.
+# 
+# Copyright (C) 2009-2010, Eloy Duran <eloy.de.enige at gmail.com>
+
+require 'ripper'
+
+module IRB
+  class Completion
+    # Convenience constants for sexp access of Ripper::SexpBuilder.
+    TYPE   = 0
+    VALUE  = 1
+    CALLEE = 3
+    
+    RESERVED_UPCASE_WORDS = %w{
+      BEGIN  END
+    }
+    
+    RESERVED_DOWNCASE_WORDS = %w{
+      alias  and
+      begin  break
+      case   class
+      def    defined do
+      else   elsif   end   ensure
+      false  for
+      if     in
+      module
+      next   nil     not
+      or
+      redo   rescue  retry return
+      self   super
+      then   true
+      undef  unless  until
+      when   while
+      yield
+    }
+    
+    # Returns an array of possible completion results, with the current
+    # IRB::Context.
+    #
+    # This is meant to be used with Readline which takes a completion proc.
+    def self.call(source)
+      new(IRB::Context.current, source).results
+    end
+    
+    attr_reader :context, :source
+    
+    def initialize(context, source)
+      @context, @source = context, source
+    end
+    
+    def evaluate(s)
+      @context.__evaluate__(s)
+    end
+    
+    def local_variables
+      evaluate('local_variables').map(&:to_s)
+    end
+    
+    def instance_methods
+      @context.object.methods.map(&:to_s)
+    end
+    
+    def instance_methods_of(klass)
+      evaluate(klass).instance_methods
+    end
+    
+    # TODO: test and or fix the fact that we need to get constants from the
+    # singleton class.
+    def constants
+      evaluate('Object.constants + self.class.constants + (class << self; constants; end)').map(&:to_s)
+    end
+    
+    def results
+      source = @source
+      filter = nil
+      
+      # if ends with period, remove it to remove the syntax error it causes
+      call = (source[-1,1] == '.')
+      receiver = source = source[0..-2] if call
+      
+      if sexp = Ripper::SexpBuilder.new(source).parse
+        # [:program, [:stmts_add, [:stmts_new], [x, …]]]
+        #                                        ^
+        root = sexp[1][2]
+        
+        # [:call, [:hash, nil], :".", [:@ident, x, …]]
+        if root[TYPE] == :call
+          call  = true
+          stack = unwind_callstack(root)
+          # [[:var_ref, [:@const, "Klass", [1, 0]]], [:call, "new"]]
+          # [[:var_ref, [:@ident, "klass", [1, 0]]], [:call, "new"], [:call, "filter"]]
+          if stack[1][VALUE] == 'new'
+            klass    = stack[0][VALUE][VALUE]
+            filter   = stack[2][VALUE] if stack[2]
+            receiver = "#{klass}.new"
+            methods  = instance_methods_of(klass)
+          else
+            filter   = root[CALLEE][VALUE]
+            filter   = stack[1][VALUE]
+            receiver = source[0..-(filter.length + 2)]
+            root     = root[VALUE]
+          end
+        end
+        
+        if call
+          format_methods(receiver, methods || methods_of_object(root), filter)
+        else
+          match_methods_vars_or_consts_in_scope(root)
+        end.sort.uniq
+      end
+    end
+    
+    def unwind_callstack(root, stack = [])
+      if root[TYPE] == :call
+        stack.unshift [:call, root[CALLEE][VALUE]]
+        unwind_callstack(root[VALUE], stack)
+      else
+        stack.unshift root
+      end
+      stack
+    end
+    
+    def match_methods_vars_or_consts_in_scope(symbol)
+      var    = symbol[VALUE]
+      filter = var[VALUE]
+      case var[TYPE]
+      when :@ident
+        local_variables + instance_methods + RESERVED_DOWNCASE_WORDS
+      when :@gvar
+        global_variables.map(&:to_s)
+      when :@const
+        if symbol[TYPE] == :top_const_ref
+          filter = "::#{filter}"
+          Object.constants.map { |c| "::#{c}" }
+        else
+          constants + RESERVED_UPCASE_WORDS
+        end
+      end.grep(/^#{Regexp.quote(filter)}/)
+    end
+    
+    def format_methods(receiver, methods, filter)
+      (filter ? methods.grep(/^#{filter}/) : methods).map { |m| "#{receiver}.#{m}" }
+    end
+    
+    def methods_of_object(root)
+      result = case root[TYPE]
+      # [:unary, :-@, [x, …]]
+      #               ^
+      when :unary                          then return methods_of_object(root[2]) # TODO: do we really need this?
+      when :var_ref, :top_const_ref        then return methods_of_object_in_variable(root)
+      when :array, :words_add, :qwords_add then Array
+      when :@int                           then Fixnum
+      when :@float                         then Float
+      when :hash                           then Hash
+      when :lambda                         then Proc
+      when :dot2, :dot3                    then Range
+      when :regexp_literal                 then Regexp
+      when :string_literal                 then String
+      when :symbol_literal, :dyna_symbol   then Symbol
+      end.instance_methods
+    end
+    
+    def methods_of_object_in_variable(path)
+      type, name = path[VALUE][0..1]
+      
+      if path[TYPE] == :top_const_ref
+        if type == :@const && Object.constants.include?(name.to_sym)
+          evaluate("::#{name}").methods
+        end
+      else
+        case type
+        when :@ident
+          evaluate(name).methods if local_variables.include?(name)
+        when :@gvar
+          eval(name).methods if global_variables.include?(name.to_sym)
+        when :@const
+          evaluate(name).methods if constants.include?(name)
+        end
+      end
+    end
+  end
+end
+
+if defined?(Readline)
+  if Readline.respond_to?("basic_word_break_characters=")
+    # IRB adds a few breaking chars. that would break literals for us:
+    # * String: " and '
+    # * Hash: = and >
+    Readline.basic_word_break_characters= " \t\n`<;|&("
+  end
+  Readline.completion_proc = IRB::Completion
+end
\ No newline at end of file

Modified: MacRuby/trunk/lib/irb/ext/history.rb
===================================================================
--- MacRuby/trunk/lib/irb/ext/history.rb	2010-05-02 05:58:51 UTC (rev 3998)
+++ MacRuby/trunk/lib/irb/ext/history.rb	2010-05-02 11:40:15 UTC (rev 3999)
@@ -1,109 +1,97 @@
+# MacRuby implementation of IRB.
 #
-#   history.rb - 
-#   	$Release Version: 0.9.5$
-#   	$Revision: 14912 $
-#   	by Keiju ISHITSUKA(keiju at ruby-lang.org)
+# This file is covered by the Ruby license. See COPYING for more details.
+# 
+# Copyright (C) 2009-2010, Eloy Duran <eloy.de.enige at gmail.com>
 #
-# --
-#
-#   
-#
+# Portions Copyright (C) 2006-2010 Ben Bleything <ben at bleything.net> (Kernel#history & Kernel#history!)
 
 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}"
+  class History
+    class << self
+      attr_accessor :file, :max_entries_in_overview
+      
+      def current
+        IRB::Context.current.processors.find do |processor|
+          processor.is_a?(IRB::History)
+        end
       end
-
-      @last_value
     end
-
-    attr_reader :eval_history
-    def eval_history=(no)
-      if no
-	if defined?(@eval_history) && @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
+    
+    def initialize(context)
+      @context = context
+      
+      to_a.each do |source|
+        Readline::HISTORY.push(source)
+      end if Readline::HISTORY.to_a.empty?
     end
-  end
-
-  class History
-    @RCS_ID='-$Id: history.rb 14912 2008-01-06 15:49:38Z akr $-'
-
-    def initialize(size = 16)
-      @size = size
-      @contents = []
+    
+    def input(source)
+      File.open(self.class.file, "a") { |f| f.puts(source) }
+      source
     end
-
-    def size(size)
-      if size != 0 && size < @size 
-	@contents = @contents[@size - size .. @size]
-      end
-      @size = size
+    
+    def to_a
+      file = self.class.file
+      File.exist?(file) ? File.read(file).split("\n") : []
     end
-
-    def [](idx)
-      begin
-	if idx >= 0
-	  @contents.find{|no, val| no == idx}[1]
-	else
-	  @contents[idx][1]
-	end
-      rescue NameError
-	nil
-      end
+    
+    def clear!
+      File.open(self.class.file, "w") { |f| f << "" }
+      Readline::HISTORY.clear
     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
+    def history(number_of_entries = max_entries_in_overview)
+      history_size = Readline::HISTORY.size
+      start_index = 0
+      
+      # always remove one extra, because that's the `history' command itself
+      if history_size <= number_of_entries
+        end_index = history_size - 2
+      else
+        end_index = history_size - 2
+        start_index = history_size - number_of_entries - 1
       end
-
-      unless (last = @contents.pop)[1].equal?(self)
-	@contents.push last
-	last = nil
+      
+      start_index.upto(end_index) do |i|
+        puts "#{i}: #{Readline::HISTORY[i]}"
       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
+    
+    def history!(entry_or_range)
+      # we don't want to execute history! again
+      @context.clear_buffer
+      
+      if entry_or_range.is_a?(Range)
+        entry_or_range.to_a.each do |i|
+          @context.input_line(Readline::HISTORY[i])
+        end
+      else
+        @context.input_line(Readline::HISTORY[entry_or_range])
       end
-      @contents.push last if last
-      str
     end
   end
 end
 
+module Kernel
+  def history(number_of_entries = IRB::History.max_entries_in_overview)
+    IRB::History.current.history(number_of_entries)
+    nil
+  end
+  alias_method :h, :history
+  
+  def history!(entry_or_range)
+    IRB::History.current.history!(entry_or_range)
+    nil
+  end
+  alias_method :h!, :history!
+  
+  def clear_history!
+    IRB::History.current.clear!
+    nil
+  end
+end
 
+IRB::Context.processors << IRB::History
+IRB::History.file = File.expand_path("~/.irb_history")
+IRB::History.max_entries_in_overview = 50
\ No newline at end of file

Deleted: MacRuby/trunk/lib/irb/ext/loader.rb
===================================================================
--- MacRuby/trunk/lib/irb/ext/loader.rb	2010-05-02 05:58:51 UTC (rev 3998)
+++ MacRuby/trunk/lib/irb/ext/loader.rb	2010-05-02 11:40:15 UTC (rev 3999)
@@ -1,119 +0,0 @@
-#
-#   loader.rb - 
-#   	$Release Version: 0.9.5$
-#   	$Revision: 14912 $
-#   	by Keiju ISHITSUKA(keiju at ruby-lang.org)
-#
-# --
-#
-#   
-#
-
-
-module IRB
-  class LoadAbort < Exception;end
-
-  module IrbLoader
-    @RCS_ID='-$Id: loader.rb 14912 2008-01-06 15:49:38Z akr $-'
-
-    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
-

Added: MacRuby/trunk/lib/irb/ext/macruby.rb
===================================================================
--- MacRuby/trunk/lib/irb/ext/macruby.rb	                        (rev 0)
+++ MacRuby/trunk/lib/irb/ext/macruby.rb	2010-05-02 11:40:15 UTC (rev 3999)
@@ -0,0 +1,25 @@
+# MacRuby implementation of IRB.
+#
+# This file is covered by the Ruby license. See COPYING for more details.
+# 
+# Copyright (C) 2009-2010, Eloy Duran <eloy.de.enige at gmail.com>
+
+framework 'AppKit'
+
+module IRB
+  class Context
+    alias_method :_run, :run
+    
+    def run
+      if NSApplication.sharedApplication.running?
+        _run
+      else
+        Thread.new do
+          _run
+          NSApplication.sharedApplication.terminate(self)
+        end
+        NSApplication.sharedApplication.run
+      end
+    end
+  end
+end
\ No newline at end of file

Deleted: MacRuby/trunk/lib/irb/ext/math-mode.rb
===================================================================
--- MacRuby/trunk/lib/irb/ext/math-mode.rb	2010-05-02 05:58:51 UTC (rev 3998)
+++ MacRuby/trunk/lib/irb/ext/math-mode.rb	2010-05-02 11:40:15 UTC (rev 3999)
@@ -1,36 +0,0 @@
-#
-#   math-mode.rb - 
-#   	$Release Version: 0.9.5$
-#   	$Revision: 14912 $
-#   	by Keiju ISHITSUKA(keiju at ruby-lang.org)
-#
-# --
-#
-#   
-#
-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 CantReturnToNormalMode
-	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
-

Deleted: MacRuby/trunk/lib/irb/ext/multi-irb.rb
===================================================================
--- MacRuby/trunk/lib/irb/ext/multi-irb.rb	2010-05-02 05:58:51 UTC (rev 3998)
+++ MacRuby/trunk/lib/irb/ext/multi-irb.rb	2010-05-02 11:40:15 UTC (rev 3999)
@@ -1,240 +0,0 @@
-#
-#   irb/multi-irb.rb - multiple irb module
-#   	$Release Version: 0.9.5$
-#   	$Revision: 18837 $
-#   	by Keiju ISHITSUKA(keiju at ruby-lang.org)
-#
-# --
-#
-#   
-#
-IRB.fail CantShiftToMultiIrbMode unless defined?(Thread)
-require "thread"
-
-module IRB
-  # job management class
-  class JobManager
-    @RCS_ID='-$Id: multi-irb.rb 18837 2008-08-25 13:41:11Z mame $-'
-
-    def initialize
-      # @jobs = [[thread, irb],...]
-      @jobs = []
-      @current_job = nil
-    end
-
-    attr_accessor :current_job
-
-    def n_jobs
-      @jobs.size
-    end
-
-    def thread(key)
-      th, irb = search(key)
-      th
-    end
-
-    def irb(key)
-      th, irb = search(key)
-      irb
-    end
-
-    def main_thread
-      @jobs[0][0]
-    end
-
-    def main_irb
-      @jobs[0][1]
-    end
-
-    def insert(irb)
-      @jobs.push [Thread.current, irb]
-    end
-
-    def switch(key)
-      th, irb = search(key)
-      IRB.fail IrbAlreadyDead unless th.alive?
-      IRB.fail IrbSwitchedToCurrentThread if th == Thread.current
-      @current_job = irb
-      th.run
-      Thread.stop
-      @current_job = irb(Thread.current)
-    end
-
-    def kill(*keys)
-      for key in keys
-	th, irb = search(key)
-	IRB.fail IrbAlreadyDead unless th.alive?
-	th.exit
-      end
-    end    
-
-    def search(key)
-      job = case key
-      when Integer
-	@jobs[key]
-      when Irb
-	@jobs.find{|k, v| v.equal?(key)}
-      when Thread
-	@jobs.assoc(key)
-      else
-	@jobs.find{|k, v| v.context.main.equal?(key)}
-      end
-      IRB.fail NoSuchJob, key if job.nil?
-      job
-    end
-
-    def delete(key)
-      case key
-      when Integer
-	IRB.fail NoSuchJob, key unless @jobs[key]
-	@jobs[key] = nil
-      else
-	catch(:EXISTS) do
-	  @jobs.each_index do
-	    |i|
-	    if @jobs[i] and (@jobs[i][0] == key ||
-			     @jobs[i][1] == key ||
-			     @jobs[i][1].context.main.equal?(key))
-	      @jobs[i] = nil
-	      throw :EXISTS
-	    end
-	  end
-	  IRB.fail NoSuchJob, key
-	end
-      end
-      until assoc = @jobs.pop; end unless @jobs.empty?
-      @jobs.push assoc
-    end
-
-    def inspect
-      ary = []
-      @jobs.each_index do
-	|i|
-	th, irb = @jobs[i]
-	next if th.nil?
-
-	if th.alive?
-	  if th.stop?
-	    t_status = "stop"
-	  else
-	    t_status = "running"
-	  end
-	else
-	  t_status = "exited"
-	end
-	ary.push format("#%d->%s on %s (%s: %s)",
-			i, 
-			irb.context.irb_name, 
-			irb.context.main,
-			th,
-			t_status)
-      end
-      ary.join("\n")
-    end
-  end
-
-  @JobManager = JobManager.new
-
-  def IRB.JobManager
-    @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)
-    parent_thread = Thread.current
-    Thread.start do
-      begin
-	irb = Irb.new(workspace, file)
-      rescue 
-	print "Subirb can't start with context(self): ", workspace.main.inspect, "\n"
-	print "return to main irb\n"
-	Thread.pass
-	Thread.main.wakeup
-	Thread.exit
-      end
-      @CONF[:IRB_RC].call(irb.context) if @CONF[:IRB_RC]
-      @JobManager.insert(irb)
-      @JobManager.current_job = irb
-      begin
-	system_exit = false
-	catch(:IRB_EXIT) do
-	  irb.eval_input
-	end
-      rescue SystemExit
-	system_exit = true
-	raise
-	#fail
-      ensure
-	unless system_exit
-	  @JobManager.delete(irb)
-	  if parent_thread.alive?
-	    @JobManager.current_job = @JobManager.irb(parent_thread)
-	    parent_thread.run
-	  else
-	    @JobManager.current_job = @JobManager.main_irb
-	    @JobManager.main_thread.run
-	  end
-	end
-      end
-    end
-    Thread.stop
-    @JobManager.current_job = @JobManager.irb(Thread.current)
-  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)
-  @JobManager.current_job = @CONF[:MAIN_CONTEXT].irb
-
-  class Irb
-    def signal_handle
-      unless @context.ignore_sigint?
-	print "\nabort!!\n" if @context.verbose?
-	exit
-      end
-
-      case @signal_status
-      when :IN_INPUT
-	print "^C\n"
-	IRB.JobManager.thread(self).raise RubyLex::TerminateLineInput
-      when :IN_EVAL
-	IRB.irb_abort(self)
-      when :IN_LOAD
-	IRB.irb_abort(self, LoadAbort)
-      when :IN_IRB
-	# ignore
-      else
-	# ignore other cases as well
-      end
-    end
-  end
-
-  trap("SIGINT") do
-    @JobManager.current_job.signal_handle
-    Thread.stop
-  end
-
-end

Deleted: MacRuby/trunk/lib/irb/ext/save-history.rb
===================================================================
--- MacRuby/trunk/lib/irb/ext/save-history.rb	2010-05-02 05:58:51 UTC (rev 3998)
+++ MacRuby/trunk/lib/irb/ext/save-history.rb	2010-05-02 11:40:15 UTC (rev 3999)
@@ -1,86 +0,0 @@
-#!/usr/local/bin/ruby
-#
-#   save-history.rb - 
-#   	$Release Version: 0.9.5$
-#   	$Revision: 19671 $
-#   	by Keiju ISHITSUKA(keiju at ruby-lang.org)
-#
-# --
-#
-#   
-#
-
-require "readline"
-
-module IRB
-  module HistorySavingAbility
-    @RCS_ID='-$Id: save-history.rb 19671 2008-10-04 03:28:19Z keiju $-'
-  end
-
-  class Context
-    def init_save_history
-      unless (class<<@io;self;end).include?(HistorySavingAbility)
-	@io.extend(HistorySavingAbility)
-      end
-    end
-
-    def save_history
-      IRB.conf[:SAVE_HISTORY]
-    end
-
-    def save_history=(val)
-      IRB.conf[:SAVE_HISTORY] = val
-      if val
-	main_context = IRB.conf[:MAIN_CONTEXT]
-	main_context = self unless main_context
-	main_context.init_save_history
-      end
-    end
-
-    def history_file
-      IRB.conf[:HISTORY_FILE]
-    end
-
-    def history_file=(hist)
-      IRB.conf[:HISTORY_FILE] = hist
-    end
-  end
-
-  module HistorySavingAbility
-    include Readline
-
-    def HistorySavingAbility.create_finalizer
-      proc do
-	if num = IRB.conf[:SAVE_HISTORY] and (num = num.to_i) > 0
-	  if history_file = IRB.conf[:HISTORY_FILE]
-	    history_file = File.expand_path(history_file)
-	  end
-	  history_file = IRB.rc_file("_history") unless history_file
-	  open(history_file, 'w' ) do |f|
-	    hist = HISTORY.to_a
-	    f.puts(hist[-num..-1] || hist)
-	  end
-	end
-      end
-    end
-
-    def HistorySavingAbility.extended(obj)
-      ObjectSpace.define_finalizer(obj, HistorySavingAbility.create_finalizer)
-      obj.load_history
-      obj
-    end
-
-    def load_history
-      if history_file = IRB.conf[:HISTORY_FILE]
-	history_file = File.expand_path(history_file)
-      end
-      history_file = IRB.rc_file("_history") unless history_file
-      if File.exist?(history_file)
-	open(history_file) do |f|
-	  f.each {|l| HISTORY << l.chomp}
-	end
-      end
-    end
-  end
-end
-

Deleted: MacRuby/trunk/lib/irb/ext/tracer.rb
===================================================================
--- MacRuby/trunk/lib/irb/ext/tracer.rb	2010-05-02 05:58:51 UTC (rev 3998)
+++ MacRuby/trunk/lib/irb/ext/tracer.rb	2010-05-02 11:40:15 UTC (rev 3999)
@@ -1,60 +0,0 @@
-#
-#   irb/lib/tracer.rb - 
-#   	$Release Version: 0.9.5$
-#   	$Revision: 14912 $
-#   	by Keiju ISHITSUKA(keiju at ruby-lang.org)
-#
-# --
-#
-#   
-#
-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
-	

Deleted: MacRuby/trunk/lib/irb/ext/use-loader.rb
===================================================================
--- MacRuby/trunk/lib/irb/ext/use-loader.rb	2010-05-02 05:58:51 UTC (rev 3998)
+++ MacRuby/trunk/lib/irb/ext/use-loader.rb	2010-05-02 11:40:15 UTC (rev 3999)
@@ -1,64 +0,0 @@
-#
-#   use-loader.rb - 
-#   	$Release Version: 0.9.5$
-#   	$Revision: 14912 $
-#   	by Keiju ISHITSUKA(keiju at ruby-lang.org)
-#
-# --
-#
-#   
-#
-
-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
-
-

Deleted: MacRuby/trunk/lib/irb/ext/workspaces.rb
===================================================================
--- MacRuby/trunk/lib/irb/ext/workspaces.rb	2010-05-02 05:58:51 UTC (rev 3998)
+++ MacRuby/trunk/lib/irb/ext/workspaces.rb	2010-05-02 11:40:15 UTC (rev 3999)
@@ -1,55 +0,0 @@
-#
-#   push-ws.rb - 
-#   	$Release Version: 0.9.5$
-#   	$Revision: 14912 $
-#   	by Keiju ISHITSUKA(keiju at ruby-lang.org)
-#
-# --
-#
-#   
-#
-
-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
-

Deleted: MacRuby/trunk/lib/irb/extend-command.rb
===================================================================
--- MacRuby/trunk/lib/irb/extend-command.rb	2010-05-02 05:58:51 UTC (rev 3998)
+++ MacRuby/trunk/lib/irb/extend-command.rb	2010-05-02 11:40:15 UTC (rev 3999)
@@ -1,268 +0,0 @@
-#
-#   irb/extend-command.rb - irb extend command 
-#   	$Release Version: 0.9.5$
-#   	$Revision: 18837 $
-#   	by Keiju ISHITSUKA(keiju at ruby-lang.org)
-#
-# --
-#
-#   
-#
-module IRB
-  #
-  # IRB extended command
-  #
-  module ExtendCommandBundle
-    EXCB = ExtendCommandBundle
-
-    NO_OVERRIDE = 0
-    OVERRIDE_PRIVATE_ONLY = 0x01
-    OVERRIDE_ALL = 0x02
-
-    def irb_exit(ret = 0)
-      irb_context.exit(ret)
-    end
-
-    def irb_context
-      IRB.CurrentContext
-    end
-
-    @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]],
-
-      [:irb_help, :Help, "irb/cmd/help",
-        [:help, NO_OVERRIDE]],
-
-    ]
-
-    def self.install_extend_commands
-      for args in @EXTEND_COMMANDS
-	def_extend_command(*args)
-      end
-    end
-
-    # aliases = [commands_alias, flag], ...
-    def self.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
-
-      if load_file
-	eval %[
-	  def #{cmd_name}(*opts, &b)
-	    require "#{load_file}"
-	    arity = ExtendCommand::#{cmd_class}.instance_method(:execute).arity
-	    args = (1..arity.abs).map {|i| "arg" + i.to_s }
-	    args << "*opts" if arity < 0
-	    args << "&block"
-	    args = args.join(", ")
-	    eval %[
-	      def #{cmd_name}(\#{args})
-		ExtendCommand::#{cmd_class}.execute(irb_context, \#{args})
-	      end
-	    ]
-	    send :#{cmd_name}, *opts, &b
-	  end
-	]
-      else
-	eval %[
-	  def #{cmd_name}(*opts, &b)
-	    ExtendCommand::#{cmd_class}.execute(irb_context, *opts, &b)
-	  end
-	]
-      end
-
-      for ali, flag in aliases
-	@ALIASES.push [ali, cmd_name, flag]
-      end
-    end
-
-    # 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 == NO_OVERRIDE) &&  !respond_to?(to, true)
-	target = self
-	(class<<self;self;end).instance_eval{
-	  if target.respond_to?(to, true) && 
-	      !target.respond_to?(EXCB.irb_original_method_name(to), true)
-	    alias_method(EXCB.irb_original_method_name(to), to) 
-	  end
-	  alias_method to, from
-	}
-      else
-	print "irb: warn: can't alias #{to} from #{from}.\n"
-      end
-    end
-
-    def self.irb_original_method_name(method_name)
-      "irb_" + method_name + "_org"
-    end
-
-    def self.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"],
-      [:save_history=, "irb/ext/save-history.rb"],
-    ]
-
-    def self.install_extend_commands
-      for args in @EXTEND_COMMANDS
-	def_extend_command(*args)
-      end
-    end
-
-    def self.def_extend_command(cmd_name, load_file, *aliases)
-      Context.module_eval %[
-        def #{cmd_name}(*opts, &b)
-	  Context.module_eval {remove_method(:#{cmd_name})}
-	  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
-
-  module MethodExtender
-    def def_pre_proc(base_method, extend_method)
-      base_method = base_method.to_s
-      extend_method = extend_method.to_s
-
-      alias_name = new_alias_name(base_method)
-      module_eval %[
-        alias_method alias_name, base_method
-        def #{base_method}(*opts)
-	  send :#{extend_method}, *opts
-	  send :#{alias_name}, *opts
-	end
-      ]
-    end
-
-    def def_post_proc(base_method, extend_method)
-      base_method = base_method.to_s
-      extend_method = extend_method.to_s
-
-      alias_name = new_alias_name(base_method)
-      module_eval %[
-        alias_method alias_name, base_method
-        def #{base_method}(*opts)
-	  send :#{alias_name}, *opts
-	  send :#{extend_method}, *opts
-	end
-      ]
-    end
-
-    # return #{prefix}#{name}#{postfix}<num>
-    def new_alias_name(name, prefix = "__alias_of__", postfix = "__")
-      base_name = "#{prefix}#{name}#{postfix}"
-      all_methods = instance_methods(true) + private_instance_methods(true)
-      same_methods = all_methods.grep(/^#{Regexp.quote(base_name)}[0-9]*$/)
-      return base_name if same_methods.empty?
-      no = same_methods.size
-      while !same_methods.include?(alias_name = base_name + no)
-	no += 1
-      end
-      alias_name
-    end
-  end
-end
-

Added: MacRuby/trunk/lib/irb/formatter.rb
===================================================================
--- MacRuby/trunk/lib/irb/formatter.rb	                        (rev 0)
+++ MacRuby/trunk/lib/irb/formatter.rb	2010-05-02 11:40:15 UTC (rev 3999)
@@ -0,0 +1,62 @@
+# MacRuby implementation of IRB.
+#
+# This file is covered by the Ruby license. See COPYING for more details.
+# 
+# Copyright (C) 2009-2010, Eloy Duran <eloy.de.enige at gmail.com>
+
+module IRB
+  class << self
+    attr_accessor :formatter
+  end
+  
+  class Formatter
+    DEFAULT_PROMPT = "irb(%s):%03d:%d> "
+    SIMPLE_PROMPT  = ">> "
+    NO_PROMPT      = ""
+    RESULT_PREFIX  = "=>"
+    SYNTAX_ERROR   = "SyntaxError: compile error\n(irb):%d: %s"
+    SOURCE_ROOT    = /^#{File.expand_path('../../../', __FILE__)}/
+    
+    attr_writer :prompt
+    attr_reader :filter_from_backtrace
+    
+    def initialize
+      @prompt = :default
+      @filter_from_backtrace = [SOURCE_ROOT]
+    end
+    
+    def prompt(context)
+      case @prompt
+      when :default then DEFAULT_PROMPT % [context.object.inspect, context.line, context.source.level]
+      when :simple  then SIMPLE_PROMPT
+      else
+        NO_PROMPT
+      end
+    end
+    
+    def inspect_object(object)
+      object.respond_to?(:pretty_inspect) ? object.pretty_inspect : object.inspect
+    end
+    
+    def result(object)
+      "#{RESULT_PREFIX} #{inspect_object(object)}"
+    end
+    
+    def syntax_error(line, message)
+      SYNTAX_ERROR % [line, message]
+    end
+    
+    def exception(exception)
+      backtrace = $DEBUG ? exception.backtrace : filter_backtrace(exception.backtrace)
+      "#{exception.class.name}: #{exception.message}\n\t#{backtrace.join("\n\t")}"
+    end
+    
+    def filter_backtrace(backtrace)
+      backtrace.reject do |line|
+        @filter_from_backtrace.any? { |pattern| pattern.match(line) }
+      end
+    end
+  end
+end
+
+IRB.formatter = IRB::Formatter.new
\ No newline at end of file

Deleted: MacRuby/trunk/lib/irb/frame.rb
===================================================================
--- MacRuby/trunk/lib/irb/frame.rb	2010-05-02 05:58:51 UTC (rev 3998)
+++ MacRuby/trunk/lib/irb/frame.rb	2010-05-02 11:40:15 UTC (rev 3999)
@@ -1,66 +0,0 @@
-#
-#   frame.rb - 
-#   	$Release Version: 0.9$
-#   	$Revision: 14912 $
-#   	by Keiju ISHITSUKA(Nihon Rational Software Co.,Ltd)
-#
-# --
-#
-#   
-#
-
-require "e2mmap"
-
-module IRB
-  class Frame
-    extend Exception2MessageMapper
-    def_exception :FrameOverflow, "frame overflow"
-    def_exception :FrameUnderflow, "frame underflow"
-
-    INIT_STACK_TIMES = 3
-    CALL_STACK_OFFSET = 3
-
-    def initialize
-      @frames = [TOPLEVEL_BINDING] * INIT_STACK_TIMES
-    end
-
-    def trace_func(event, file, line, id, binding)
-      case event
-      when 'call', 'class'
-	@frames.push binding
-      when 'return', 'end'
-	@frames.pop
-      end
-    end
-
-    def top(n = 0)
-      bind = @frames[-(n + CALL_STACK_OFFSET)]
-      Fail FrameUnderflow unless bind
-      bind
-    end
-
-    def bottom(n = 0)
-      bind = @frames[n]
-      Fail FrameOverflow unless bind
-      bind
-    end
-
-    # singleton functions
-    def Frame.bottom(n = 0)
-      @backtrace.bottom(n)
-    end
-
-    def Frame.top(n = 0)
-      @backtrace.top(n)
-    end
-
-    def Frame.sender
-      eval "self", @backtrace.top
-    end
-
-    @backtrace = Frame.new
-    set_trace_func proc{|event, file, line, id, binding, klass|
-      @backtrace.trace_func(event, file, line, id, binding)
-    }
-  end
-end

Deleted: MacRuby/trunk/lib/irb/help.rb
===================================================================
--- MacRuby/trunk/lib/irb/help.rb	2010-05-02 05:58:51 UTC (rev 3998)
+++ MacRuby/trunk/lib/irb/help.rb	2010-05-02 11:40:15 UTC (rev 3999)
@@ -1,35 +0,0 @@
-#
-#   irb/help.rb - print usage module
-#   	$Release Version: 0.9.5$
-#   	$Revision: 20882 $
-#   	by Keiju ISHITSUKA(keiju at ishitsuka.com)
-#
-# --
-#
-#   
-#
-
-require 'irb/magic-file'
-
-module IRB
-  def IRB.print_usage
-    lc = IRB.conf[:LC_MESSAGES]
-    path = lc.find("irb/help-message")
-    space_line = false
-    IRB::MagicFile.open(path){|f|
-      f.each_line do |l|
-	if /^\s*$/ =~ l
-	  lc.puts l unless space_line
-	  space_line = true
-	  next
-	end
-	space_line = false
-
-	l.sub!(/#.*$/, "")
-	  next if /^\s*$/ =~ l
-	lc.puts l
-      end
-    }
-  end
-end
-

Deleted: MacRuby/trunk/lib/irb/init.rb
===================================================================
--- MacRuby/trunk/lib/irb/init.rb	2010-05-02 05:58:51 UTC (rev 3998)
+++ MacRuby/trunk/lib/irb/init.rb	2010-05-02 11:40:15 UTC (rev 3999)
@@ -1,288 +0,0 @@
-#
-#   irb/init.rb - irb initialize module
-#   	$Release Version: 0.9.5$
-#   	$Revision: 20882 $
-#   	by Keiju ISHITSUKA(keiju at ruby-lang.org)
-#
-# --
-#
-#   
-#
-
-module IRB
-
-  # initialize config
-  def IRB.setup(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
-
-    # default configurations
-    unless ap_path and @CONF[:AP_NAME]
-      ap_path = File.join(File.dirname(File.dirname(__FILE__)), "irb.rb")
-    end
-    @CONF[:AP_NAME] = File::basename(ap_path, ".rb")
-
-    @CONF[:IRB_NAME] = "irb"
-    @CONF[:IRB_LIB_PATH] = File.dirname(__FILE__)
-
-    @CONF[:RC] = true
-    @CONF[:LOAD_MODULES] = []
-    @CONF[:IRB_RC] = nil
-
-    @CONF[:MATH_MODE] = false
-    @CONF[:USE_READLINE] = false unless defined?(ReadlineInputMethod)
-    @CONF[:INSPECT_MODE] = nil
-    @CONF[:USE_TRACER] = false
-    @CONF[:USE_LOADER] = false
-    @CONF[:IGNORE_SIGINT] = true
-    @CONF[:IGNORE_EOF] = false
-    @CONF[:ECHO] = nil
-    @CONF[:VERBOSE] = nil
-
-    @CONF[:EVAL_HISTORY] = nil
-    @CONF[:SAVE_HISTORY] = nil
-
-    @CONF[:BACK_TRACE_LIMIT] = 16
-
-    @CONF[:PROMPT] = {
-      :NULL => {
-	:PROMPT_I => nil,
-	:PROMPT_N => nil,
-	:PROMPT_S => nil,
-	:PROMPT_C => nil,
-	:RETURN => "%s\n"
-      },
-      :DEFAULT => {
-	:PROMPT_I => "%N(%m):%03n:%i> ",
-	:PROMPT_N => "%N(%m):%03n:%i> ",
-	:PROMPT_S => "%N(%m):%03n:%i%l ",
-	:PROMPT_C => "%N(%m):%03n:%i* ",
-	:RETURN => "=> %s\n"
-      },
-      :CLASSIC => {
-	:PROMPT_I => "%N(%m):%03n:%i> ",
-	:PROMPT_N => "%N(%m):%03n:%i> ",
-	:PROMPT_S => "%N(%m):%03n:%i%l ",
-	:PROMPT_C => "%N(%m):%03n:%i* ",
-	:RETURN => "%s\n"
-      },
-      :SIMPLE => {
-	:PROMPT_I => ">> ",
-	:PROMPT_N => ">> ",
-	:PROMPT_S => nil,
-	:PROMPT_C => "?> ",
-	:RETURN => "=> %s\n"
-      },
-      :INF_RUBY => {
-	:PROMPT_I => "%N(%m):%03n:%i> ",
-#	:PROMPT_N => "%N(%m):%03n:%i> ",
-	:PROMPT_N => nil,
-	:PROMPT_S => nil,
-	:PROMPT_C => nil,
-	:RETURN => "%s\n",
-	:AUTO_INDENT => true
-      },
-      :XMP => {
-	:PROMPT_I => nil,
-	:PROMPT_N => nil,
-	:PROMPT_S => nil,
-	:PROMPT_C => nil,
-	:RETURN => "    ==>%s\n"
-      }
-    }
-
-    @CONF[:PROMPT_MODE] = (STDIN.tty? ? :DEFAULT : :NULL)
-    @CONF[:AUTO_INDENT] = false
-
-    @CONF[:CONTEXT_MODE] = 3 # use binding in function on TOPLEVEL_BINDING
-    @CONF[:SINGLE_IRB] = false
-
-#    @CONF[:LC_MESSAGES] = "en"
-    @CONF[:LC_MESSAGES] = Locale.new
-    
-    @CONF[:DEBUG_LEVEL] = 1
-  end
-
-  def IRB.init_error
-    @CONF[:LC_MESSAGES].load("irb/error.rb")
-  end
-
-  FEATURE_IOPT_CHANGE_VERSION = "1.9.0"
-
-  # option analyzing
-  def IRB.parse_opts
-    load_path = []
-    while opt = ARGV.shift
-      case opt
-      when "-f"
-	@CONF[:RC] = false
-      when "-m"
-	@CONF[:MATH_MODE] = true
-      when "-d"
-	$DEBUG = true
-      when /^-r(.+)?/
-	opt = $1 || ARGV.shift
-	@CONF[:LOAD_MODULES].push opt if opt
-      when /^-I(.+)?/
-        opt = $1 || ARGV.shift
-	load_path.concat(opt.split(File::PATH_SEPARATOR)) if opt
-      when '-U'
-	set_encoding("UTF-8", "UTF-8")
-      when /^-E(.+)?/, /^--encoding(?:=(.+))?/
-	opt = $1 || ARGV.shift
-	set_encoding(*opt.split(':', 2))
-      when "--inspect"
-	@CONF[:INSPECT_MODE] = true
-      when "--noinspect"
-	@CONF[:INSPECT_MODE] = false
-      when "--readline"
-	@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(?:=(.+))?/
-	opt = $1 || ARGV.shift
-	prompt_mode = opt.upcase.tr("-", "_").intern
-	@CONF[:PROMPT_MODE] = prompt_mode
-      when "--noprompt"
-	@CONF[:PROMPT_MODE] = :NULL
-      when "--inf-ruby-mode"
-	@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(?:=(.+))?/
-	@CONF[:BACK_TRACE_LIMIT] = ($1 || ARGV.shift).to_i
-      when /^--context-mode(?:=(.+))?/
-	@CONF[:CONTEXT_MODE] = ($1 || ARGV.shift).to_i
-      when "--single-irb"
-	@CONF[:SINGLE_IRB] = true
-      when /^--irb_debug=(?:=(.+))?/
-	@CONF[:DEBUG_LEVEL] = ($1 || ARGV.shift).to_i
-      when "-v", "--version"
-	print IRB.version, "\n"
-	exit 0
-      when "-h", "--help"
-	require "irb/help"
-	IRB.print_usage
-	exit 0
-      when "--"
-	if opt = ARGV.shfit
-	  @CONF[:SCRIPT] = opt
-	  $0 = opt
-	end
-        break
-      when /^-/
-	IRB.fail UnrecognizedSwitch, opt
-      else
-	@CONF[:SCRIPT] = opt
-	$0 = opt
-	break
-      end
-    end
-    if RUBY_VERSION >= FEATURE_IOPT_CHANGE_VERSION
-      load_path.collect! do |path|
-	/\A\.\// =~ path ? path : File.expand_path(path)
-      end
-    end
-    $LOAD_PATH.unshift(*load_path)
-
-  end
-
-  # running config
-  def IRB.run_config
-    if @CONF[:RC]
-      begin
-	load rc_file
-      rescue LoadError, Errno::ENOENT
-      rescue # StandardError, ScriptError
-	print "load error: #{rc_file}\n"
-	print $!.class, ": ", $!, "\n"
-	for err in $@[0, $@.size - 2]
-	  print "\t", err, "\n"
-	end
-      end
-    end
-  end
-
-  IRBRC_EXT = "rc"
-  def IRB.rc_file(ext = IRBRC_EXT)
-    if !@CONF[:RC_NAME_GENERATOR]
-      rc_file_generators do |rcgen|
-	@CONF[:RC_NAME_GENERATOR] ||= rcgen
-	if File.exist?(rcgen.call(IRBRC_EXT))
-	  @CONF[:RC_NAME_GENERATOR] = rcgen
-	  break
-	end
-      end
-    end
-    @CONF[:RC_NAME_GENERATOR].call ext
-  end
-
-  # enumerate possible rc-file base name generators
-  def IRB.rc_file_generators
-    if irbrc = ENV["IRBRC"]
-      yield proc{|rc| rc == "rc" ? irbrc : irbrc+rc}
-    end
-    if home = ENV["HOME"]
-      yield proc{|rc| home+"/.irb#{rc}"} 
-    end
-    home = Dir.pwd
-    yield proc{|rc| home+"/.irb#{rc}"}
-    yield proc{|rc| home+"/irb#{rc.sub(/\A_?/, '.')}"}
-    yield proc{|rc| home+"/_irb#{rc}"}
-    yield proc{|rc| home+"/$irb#{rc}"}
-    # MR-hack: let's ignore /etc/irbrc because it brings up RubyGems
-    #yield proc{|rc| "/etc/irb#{rc}"}
-  end
-
-  # loading modules
-  def IRB.load_modules
-    for m in @CONF[:LOAD_MODULES]
-      begin
-	require m
-      rescue LoadError => err
-	warn err.backtrace[0] << ":#{err.class}: #{err}"
-      end
-    end
-  end
-
-
-  DefaultEncodings = Struct.new(:external, :internal)
-  class << IRB
-    private
-    def set_encoding(extern, intern = nil)
-      verbose, $VERBOSE = $VERBOSE, nil
-      Encoding.default_external = extern unless extern.nil? || extern.empty?
-      Encoding.default_internal = intern unless intern.nil? || intern.empty?
-      @CONF[:ENCODINGS] = IRB::DefaultEncodings.new(extern, intern)
-      [$stdin, $stdout, $stderr].each do |io|
-	io.set_encoding(extern, intern)
-      end
-      @CONF[:LC_MESSAGES].instance_variable_set(:@encoding, extern)
-    ensure
-      $VERBOSE = verbose
-    end
-  end
-end

Deleted: MacRuby/trunk/lib/irb/input-method.rb
===================================================================
--- MacRuby/trunk/lib/irb/input-method.rb	2010-05-02 05:58:51 UTC (rev 3998)
+++ MacRuby/trunk/lib/irb/input-method.rb	2010-05-02 11:40:15 UTC (rev 3999)
@@ -1,142 +0,0 @@
-#
-#   irb/input-method.rb - input methods used irb
-#   	$Release Version: 0.9.5$
-#   	$Revision: 21546 $
-#   	by Keiju ISHITSUKA(keiju at ruby-lang.org)
-#
-# --
-#
-#   
-#
-require 'irb/src_encoding'
-require 'irb/magic-file'
-
-module IRB
-  # 
-  # InputMethod
-  #	StdioInputMethod
-  #	FileInputMethod
-  #	(ReadlineInputMethod)
-  #
-  STDIN_FILE_NAME = "(line)"
-  class InputMethod
-    @RCS_ID='-$Id: input-method.rb 21546 2009-01-15 15:36:57Z yugui $-'
-
-    def initialize(file = STDIN_FILE_NAME)
-      @file_name = file
-    end
-    attr_reader :file_name
-
-    attr_accessor :prompt
-    
-    def gets
-      IRB.fail NotImplementedError, "gets"
-    end
-    public :gets
-
-    def readable_atfer_eof?
-      false
-    end
-  end
-  
-  class StdioInputMethod < InputMethod
-    def initialize
-      super
-      @line_no = 0
-      @line = []
-      @stdin = IO.open(STDIN.to_i, :external_encoding => IRB.conf[:LC_MESSAGES].encoding, :internal_encoding => "-")
-      @stdout = IO.open(STDOUT.to_i, 'w', :external_encoding => IRB.conf[:LC_MESSAGES].encoding, :internal_encoding => "-")
-    end
-
-    def gets
-      print @prompt
-      line = @stdin.gets
-      @line[@line_no += 1] = line
-    end
-
-    def eof?
-      @stdin.eof?
-    end
-
-    def readable_atfer_eof?
-      true
-    end
-
-    def line(line_no)
-      @line[line_no]
-    end
-
-    def encoding
-      @stdin.external_encoding
-    end
-  end
-  
-  class FileInputMethod < InputMethod
-    def initialize(file)
-      super
-      @io = IRB::MagicFile.open(file)
-    end
-    attr_reader :file_name
-
-    def eof?
-      @io.eof?
-    end
-
-    def gets
-      print @prompt
-      l = @io.gets
-#      print @prompt, l
-      l
-    end
-
-    def encoding
-      @io.external_encoding
-    end
-  end
-
-  begin
-    require "readline"
-    class ReadlineInputMethod < InputMethod
-      include Readline 
-      def initialize
-	super
-
-	@line_no = 0
-	@line = []
-	@eof = false
-
-	@stdin = IO.open(STDIN.to_i, :external_encoding => IRB.conf[:LC_MESSAGES].encoding, :internal_encoding => "-")
-	@stdout = IO.open(STDOUT.to_i, 'w', :external_encoding => IRB.conf[:LC_MESSAGES].encoding, :internal_encoding => "-")
-      end
-
-      def gets
-        Readline.input = @stdin
-        Readline.output = @stdout
-	if l = readline(@prompt, false)
-	  HISTORY.push(l) if !l.empty?
-	  @line[@line_no += 1] = l + "\n"
-	else
-	  @eof = true
-	  l
-	end
-      end
-
-      def eof?
-	@eof
-      end
-
-      def readable_atfer_eof?
-	true
-      end
-
-      def line(line_no)
-	@line[line_no]
-      end
-
-      def encoding
-	@stdin.external_encoding
-      end
-    end
-  rescue LoadError
-  end
-end

Deleted: MacRuby/trunk/lib/irb/lc/error.rb
===================================================================
--- MacRuby/trunk/lib/irb/lc/error.rb	2010-05-02 05:58:51 UTC (rev 3998)
+++ MacRuby/trunk/lib/irb/lc/error.rb	2010-05-02 11:40:15 UTC (rev 3999)
@@ -1,29 +0,0 @@
-#
-#   irb/lc/error.rb - 
-#   	$Release Version: 0.9.5$
-#   	$Revision: 14912 $
-#   	by Keiju ISHITSUKA(keiju at ruby-lang.org)
-#
-# --
-#
-#   
-#
-require "e2mmap"
-
-module IRB
-
-  # exceptions
-  extend Exception2MessageMapper
-  def_exception :UnrecognizedSwitch, "Unrecognized switch: %s"
-  def_exception :NotImplementedError, "Need to define `%s'"
-  def_exception :CantReturnToNormalMode, "Can't return to normal mode."
-  def_exception :IllegalParameter, "Invalid parameter(%s)."
-  def_exception :IrbAlreadyDead, "Irb is already dead."
-  def_exception :IrbSwitchedToCurrentThread, "Switched to current thread."
-  def_exception :NoSuchJob, "No such job(%s)."
-  def_exception :CantShiftToMultiIrbMode, "Can't shift to multi irb mode."
-  def_exception :CantChangeBinding, "Can't change binding to (%s)."
-  def_exception :UndefinedPromptMode, "Undefined prompt mode(%s)."
-
-end
-

Deleted: MacRuby/trunk/lib/irb/lc/help-message
===================================================================
--- MacRuby/trunk/lib/irb/lc/help-message	2010-05-02 05:58:51 UTC (rev 3998)
+++ MacRuby/trunk/lib/irb/lc/help-message	2010-05-02 11:40:15 UTC (rev 3999)
@@ -1,38 +0,0 @@
-# -*- coding: US-ASCII -*-
-#
-#   irb/lc/help-message.rb - 
-#   	$Release Version: 0.9.5$
-#   	$Revision: 20882 $
-#   	by Keiju ISHITSUKA(keiju at ruby-lang.org)
-#
-# --
-#
-#   
-#
-Usage:  irb.rb [options] [programfile] [arguments]
-  -f		    Suppress read of ~/.irbrc 
-  -m		    Bc mode (load mathn, fraction or matrix are available)
-  -d                Set $DEBUG to true (same as `ruby -d')
-  -r load-module    Same as `ruby -r'
-  -I path           Specify $LOAD_PATH directory
-  -U                Same as `ruby -U`
-  -E enc            Same as `ruby -E`
-  --inspect	    Use `inspect' for output (default except for bc mode)
-  --noinspect	    Don't use inspect for output
-  --readline	    Use Readline extension module
-  --noreadline	    Don't use Readline extension module
-  --prompt prompt-mode
-  --prompt-mode prompt-mode
-		    Switch prompt mode. Pre-defined prompt modes are
-		    `default', `simple', `xmp' and `inf-ruby'
-  --inf-ruby-mode   Use prompt appropriate for inf-ruby-mode on emacs. 
-		    Suppresses --readline. 
-  --simple-prompt   Simple prompt mode
-  --noprompt	    No prompt mode
-  --tracer	    Display trace for each execution of commands.
-  --back-trace-limit n
-		    Display backtrace top n and tail n. The default
-		    value is 16. 
-  --irb_debug n	    Set internal debug level to n (not for popular use)
-  -v, --version	    Print the version of irb
-# vim:fileencoding=us-ascii

Deleted: MacRuby/trunk/lib/irb/lc/ja/encoding_aliases.rb
===================================================================
--- MacRuby/trunk/lib/irb/lc/ja/encoding_aliases.rb	2010-05-02 05:58:51 UTC (rev 3998)
+++ MacRuby/trunk/lib/irb/lc/ja/encoding_aliases.rb	2010-05-02 11:40:15 UTC (rev 3999)
@@ -1,8 +0,0 @@
-module IRB
-  class Locale
-    @@legacy_encoding_alias_map = {
-      'ujis' => Encoding::EUC_JP,
-      'euc' => Encoding::EUC_JP
-    }.freeze
-  end
-end

Deleted: MacRuby/trunk/lib/irb/lc/ja/error.rb
===================================================================
--- MacRuby/trunk/lib/irb/lc/ja/error.rb	2010-05-02 05:58:51 UTC (rev 3998)
+++ MacRuby/trunk/lib/irb/lc/ja/error.rb	2010-05-02 11:40:15 UTC (rev 3999)
@@ -1,27 +0,0 @@
-# -*- coding: utf-8 -*-
-#   irb/lc/ja/error.rb - 
-#   	$Release Version: 0.9.5$
-#   	$Revision: 20882 $
-#   	by Keiju ISHITSUKA(keiju at ruby-lang.org)
-#
-# --
-#
-#   
-#
-require "e2mmap"
-
-module IRB
-  # exceptions
-  extend Exception2MessageMapper
-  def_exception :UnrecognizedSwitch, 'スイッチ(%s)が分りません'
-  def_exception :NotImplementedError, '`%s\'の定義が必要です'
-  def_exception :CantReturnToNormalMode, 'Normalモードに戻れません.'
-  def_exception :IllegalParameter, 'パラメータ(%s)が間違っています.'
-  def_exception :IrbAlreadyDead, 'Irbは既に死んでいます.'
-  def_exception :IrbSwitchedToCurrentThread, 'カレントスレッドに切り替わりました.'
-  def_exception :NoSuchJob, 'そのようなジョブ(%s)はありません.'
-  def_exception :CantShiftToMultiIrbMode, 'multi-irb modeに移れません.'
-  def_exception :CantChangeBinding, 'バインディング(%s)に変更できません.'
-  def_exception :UndefinedPromptMode, 'プロンプトモード(%s)は定義されていません.'
-end
-# vim:fileencoding=utf-8

Deleted: MacRuby/trunk/lib/irb/lc/ja/help-message
===================================================================
--- MacRuby/trunk/lib/irb/lc/ja/help-message	2010-05-02 05:58:51 UTC (rev 3998)
+++ MacRuby/trunk/lib/irb/lc/ja/help-message	2010-05-02 11:40:15 UTC (rev 3999)
@@ -1,39 +0,0 @@
-# -*- coding: utf-8 -*-
-#   irb/lc/ja/help-message.rb - 
-#   	$Release Version: 0.9.5$
-#   	$Revision: 20882 $
-#   	by Keiju ISHITSUKA(keiju at ruby-lang.org)
-#
-# --
-#
-#   
-#
-Usage:  irb.rb [options] [programfile] [arguments]
-  -f		    ~/.irbrc を読み込まない.
-  -m		    bcモード(分数, 行列の計算ができる)
-  -d                $DEBUG をtrueにする(ruby -d と同じ)
-  -r load-module    ruby -r と同じ.
-  -I path           $LOAD_PATH に path を追加する.
-  -U                ruby -U と同じ.
-  -E enc            ruby -E と同じ.
-  --inspect	    結果出力にinspectを用いる(bcモード以外はデフォルト). 
-  --noinspect	    結果出力にinspectを用いない.
-  --readline	    readlineライブラリを利用する.
-  --noreadline	    readlineライブラリを利用しない. 
-  --prompt prompt-mode/--prompt-mode prompt-mode
-		    プロンプトモードを切替えます. 現在定義されているプ
-		    ロンプトモードは, default, simple, xmp, inf-rubyが
-		    用意されています. 
-  --inf-ruby-mode   emacsのinf-ruby-mode用のプロンプト表示を行なう. 特
-		    に指定がない限り, readlineライブラリは使わなくなる.
-  --simple-prompt   非常にシンプルなプロンプトを用いるモードです.
-  --noprompt	    プロンプト表示を行なわない.
-  --tracer	    コマンド実行時にトレースを行なう.
-  --back-trace-limit n
-		    バックトレース表示をバックトレースの頭から n, 後ろ
-		    からnだけ行なう. デフォルトは16 
-  --irb_debug n	    irbのデバッグデバッグレベルをnに設定する(利用しな
-		    い方が無難でしょう).
-  -v, --version	    irbのバージョンを表示する
-
-# vim:fileencoding=utf-8

Deleted: MacRuby/trunk/lib/irb/locale.rb
===================================================================
--- MacRuby/trunk/lib/irb/locale.rb	2010-05-02 05:58:51 UTC (rev 3998)
+++ MacRuby/trunk/lib/irb/locale.rb	2010-05-02 11:40:15 UTC (rev 3999)
@@ -1,201 +0,0 @@
-#
-#   irb/locale.rb - internationalization module
-#   	$Release Version: 0.9.5$
-#   	$Revision: 20889 $
-#   	by Keiju ISHITSUKA(keiju at ruby-lang.org)
-#
-# --
-#
-#   
-#
-module IRB
-  class Locale
-    @RCS_ID='-$Id: locale.rb 20889 2008-12-20 02:02:48Z yugui $-'
-
-    LOCALE_NAME_RE = //
-=begin
-    # This regexp can't compile on MacRuby because of named captures.
-    LOCALE_NAME_RE = %r[
-      (?<language>[[:alpha:]]{2})
-      (?:_
-       (?<territory>[[:alpha:]]{2,3})
-       (?:\.
-	(?<codeset>[^@]+)
-       )?
-      )?
-      (?:@
-       (?<modifier>.*)
-      )?
-    ]x
-=end
-    LOCALE_DIR = "/lc/"
-
-    @@legacy_encoding_alias_map = {}.freeze
-
-    def initialize(locale = nil)
-      @lang = @territory = @encoding_name = @modifier = nil
-      @locale = locale || ENV["IRB_LANG"] || ENV["LC_MESSAGES"] || ENV["LC_ALL"] || ENV["LANG"] || "C" 
-=begin
-      if m = LOCALE_NAME_RE.match(@locale)
-	@lang, @territory, @encoding_name, @modifier = m[:language], m[:territory], m[:codeset], m[:modifier]
-
-	if @encoding_name
-	  begin load 'irb/encoding_aliases.rb'; rescue LoadError; end
-	  if @encoding = @@legacy_encoding_alias_map[@encoding_name]
-	    warn "%s is obsolete. use %s" % ["#{@lang}_#{@territory}.#{@encoding_name}", "#{@lang}_#{@territory}.#{@encoding.name}"]
-	  end
-	  @encoding = Encoding.find(@encoding_name) rescue nil
-	end
-      end
-=end
-      @encoding ||= (Encoding.find('locale') rescue Encoding::ASCII_8BIT)
-    end
-
-    attr_reader :lang, :territory, :encoding, :modifieer
-
-    def String(mes)
-      mes = super(mes)
-      if @encoding
-	mes.encode(@encoding) 
-      else
-	mes
-      end
-    end
-
-    def format(*opts)
-      String(super(*opts))
-    end
-
-    def gets(*rs)
-      String(super(*rs))
-    end
-
-    def readline(*rs)
-      String(super(*rs))
-    end
-
-    def print(*opts)
-      ary = opts.collect{|opt| String(opt)}
-      super(*ary)
-    end
-
-    def printf(*opts)
-      s = format(*opts)
-      print s
-    end
-
-    def puts(*opts)
-      ary = opts.collect{|opt| String(opt)}
-      super(*ary)
-    end
-
-    def require(file, priv = nil)
-      rex = Regexp.new("lc/#{Regexp.quote(file)}\.(so|o|sl|rb)?")
-      return false if $".find{|f| f =~ rex}
-
-      case file
-      when /\.rb$/
-	begin
-	  load(file, priv)
-	  $".push file
-	  return true
-	rescue LoadError
-	end
-      when /\.(so|o|sl)$/
-	return super
-      end
-
-      begin
-	load(f = file + ".rb")
-	$".push f  #"
-	return true
-      rescue LoadError
-	return ruby_require(file)
-      end
-    end
-
-    alias toplevel_load load
-    
-    def load(file, priv=nil)
-      dir = File.dirname(file)
-      dir = "" if dir == "."
-      base = File.basename(file)
-
-      if dir[0] == ?/ #/
-	lc_path = search_file(dir, base)
-	return real_load(lc_path, priv) if lc_path
-      end
-
-      for path in $:
-	lc_path = search_file(path + "/" + dir, base)
-	return real_load(lc_path, priv) if lc_path
-      end
-      raise LoadError, "No such file to load -- #{file}"
-    end 
-
-    def real_load(path, priv)
-      src = MagicFile.open(path){|f| f.read}
-      if priv
-	eval("self", TOPLEVEL_BINDING).extend(Module.new {eval(src, nil, path)})
-      else
-	eval(src, TOPLEVEL_BINDING, path)
-      end
-    end
-    private :real_load
-
-    def find(file , paths = $:)
-      dir = File.dirname(file)
-      dir = "" if dir == "."
-      base = File.basename(file)
-      if dir[0] == ?/ #/
-	  return lc_path = search_file(dir, base)
-      else
-	for path in $:
-	  if lc_path = search_file(path + "/" + dir, base)
-	    return lc_path
-	  end
-	end
-      end
-      nil
-    end
-
-    def search_file(path, file)
-      each_sublocale do |lc|
-	full_path = path + lc_path(file, lc)
-	return full_path if File.exist?(full_path)
-      end
-      nil
-    end
-    private :search_file
-
-    def lc_path(file = "", lc = @locale)
-      if lc.nil?
-	LOCALE_DIR + file
-      else
-	LOCALE_DIR + @lang + "/" + file
-      end
-    end
-    private :lc_path
-
-    def each_sublocale
-      if @lang
-	if @territory
-	  if @encoding_name
-	    yield "#{@lang}_#{@territory}.#{@encoding_name}@#{@modifier}" if @modifier
-	    yield "#{@lang}_#{@territory}.#{@encoding_name}"
-	  end
-	  yield "#{@lang}_#{@territory}@#{@modifier}" if @modifier
-	  yield "#{@lang}_#{@territory}"
-	end
-	yield "#{@lang}@#{@modifier}" if @modifier
-	yield "#{@lang}"
-      end
-      yield nil
-    end
-    private :each_sublocale
-  end
-end
-
-
-
-

Deleted: MacRuby/trunk/lib/irb/magic-file.rb
===================================================================
--- MacRuby/trunk/lib/irb/magic-file.rb	2010-05-02 05:58:51 UTC (rev 3998)
+++ MacRuby/trunk/lib/irb/magic-file.rb	2010-05-02 11:40:15 UTC (rev 3999)
@@ -1,36 +0,0 @@
-module IRB
-  class << (MagicFile = Object.new)
-    # see parser_magic_comment in parse.y
-    ENCODING_SPEC_RE = %r"coding\s*[=:]\s*([[:alnum:]\-_]+)"
-
-    def open(path)
-      io = File.open(path, 'rb')
-      line = io.gets
-      line = io.gets if line[0,2] == "#!"
-      encoding = detect_encoding(line)
-      encoding ||= default_src_encoding
-      io.rewind
-      io.set_encoding(encoding, nil)
-
-      if block_given?
-        begin
-          return (yield io)
-        ensure
-          io.close
-        end
-      else
-        return io
-      end
-    end
-
-    private
-    def detect_encoding(line)
-      return unless line[0] == ?#
-      line = line[1..-1]
-      line = $1 if line[/-\*-\s*(.*?)\s*-*-$/]
-      return nil unless ENCODING_SPEC_RE =~ line
-      encoding = $1
-      return encoding.sub(/-(?:mac|dos|unix)/i, '')
-    end
-  end
-end

Deleted: MacRuby/trunk/lib/irb/notifier.rb
===================================================================
--- MacRuby/trunk/lib/irb/notifier.rb	2010-05-02 05:58:51 UTC (rev 3998)
+++ MacRuby/trunk/lib/irb/notifier.rb	2010-05-02 11:40:15 UTC (rev 3999)
@@ -1,144 +0,0 @@
-#
-#   notifier.rb - output methods used by irb 
-#   	$Release Version: 0.9.5$
-#   	$Revision: 16810 $
-#   	by Keiju ISHITSUKA(keiju at ruby-lang.org)
-#
-# --
-#
-#   
-#
-
-require "e2mmap"
-require "irb/output-method"
-
-module IRB
-  module Notifier
-    extend Exception2MessageMapper
-    def_exception :ErrUndefinedNotifier, 
-      "undefined notifier level: %d is specified"
-    def_exception :ErrUnrecognizedLevel, 
-      "unrecognized notifier level: %s is specified"
-
-    def def_notifier(prefix = "", output_method = StdioOutputMethod.new)
-      CompositeNotifier.new(prefix, output_method)
-    end
-    module_function :def_notifier
-  
-    class AbstructNotifier
-      def initialize(prefix, base_notifier)
-	@prefix = prefix
-	@base_notifier = base_notifier
-      end
-
-      attr_reader :prefix
-
-      def notify?
-	true
-      end
-
-      def print(*opts)
-	@base_notifier.print prefix, *opts if notify?
-      end
-
-      def printn(*opts)
-	@base_notifier.printn prefix, *opts if notify?
-      end
-
-      def printf(format, *opts)
-	@base_notifier.printf(prefix + format, *opts) if notify?
-      end
-
-      def puts(*objs)
-	if notify?
-	  @base_notifier.puts(*objs.collect{|obj| prefix + obj.to_s})
-	end
-      end
-
-      def pp(*objs)
-	if notify?
-	  @base_notifier.ppx @prefix, *objs
-	end
-      end
-
-      def ppx(prefix, *objs)
-	if notify?
-	  @base_notifier.ppx @prefix+prefix, *objs
-	end
-      end
-
-      def exec_if
-	yield(@base_notifier) if notify?
-      end
-    end
-
-    class CompositeNotifier<AbstructNotifier
-      def initialize(prefix, base_notifier)
-	super
-
-	@notifiers = [D_NOMSG]
-	@level_notifier = D_NOMSG
-      end
-
-      attr_reader :notifiers
-
-      def def_notifier(level, prefix = "")
-	notifier = LeveledNotifier.new(self, level, prefix)
-	@notifiers[level] = notifier
-	notifier
-      end
-
-      attr_reader :level_notifier
-      alias level level_notifier
-
-      def level_notifier=(value)
-	case value
-	when AbstructNotifier
-	  @level_notifier = value
-	when Integer
-	  l = @notifiers[value]
-	  Notifier.Raise ErrUndefinedNotifer, value unless l
-	  @level_notifier = l
-	else
-	  Notifier.Raise ErrUnrecognizedLevel, value unless l
-	end
-      end
-
-      alias level= level_notifier=
-    end
-
-    class LeveledNotifier<AbstructNotifier
-      include Comparable
-
-      def initialize(base, level, prefix)
-	super(prefix, base)
-	
-	@level = level
-      end
-
-      attr_reader :level
-
-      def <=>(other)
-	@level <=> other.level
-      end
-      
-      def notify?
-	@base_notifier.level >= self
-      end
-    end
-
-    class NoMsgNotifier<LeveledNotifier
-      def initialize
-	@base_notifier = nil
-	@level = 0
-	@prefix = ""
-      end
-
-      def notify?
-	false
-      end
-    end
-
-    D_NOMSG = NoMsgNotifier.new
-  end
-end

Deleted: MacRuby/trunk/lib/irb/output-method.rb
===================================================================
--- MacRuby/trunk/lib/irb/output-method.rb	2010-05-02 05:58:51 UTC (rev 3998)
+++ MacRuby/trunk/lib/irb/output-method.rb	2010-05-02 11:40:15 UTC (rev 3999)
@@ -1,69 +0,0 @@
-#
-#   output-method.rb - optput methods used by irb 
-#   	$Release Version: 0.9.5$
-#   	$Revision: 14912 $
-#   	by Keiju ISHITSUKA(keiju at ruby-lang.org)
-#
-# --
-#
-#   
-#
-
-require "e2mmap"
-
-module IRB
-  # OutputMethod
-  #   StdioOutputMethod
-
-  class OutputMethod
-    @RCS_ID='-$Id: output-method.rb 14912 2008-01-06 15:49:38Z akr $-'
-
-    def print(*opts)
-      IRB.fail NotImplementError, "print"
-    end
-
-    def printn(*opts)
-      print opts.join(" "), "\n"
-    end
-
-    # extend printf
-    def printf(format, *opts)
-      if /(%*)%I/ =~ format
-	format, opts = parse_printf_format(format, opts)
-      end
-      print sprintf(format, *opts)
-    end
-
-    # %
-    # <flag>  [#0- +]
-    # <minimum field width> (\*|\*[1-9][0-9]*\$|[1-9][0-9]*)
-    # <precision>.(\*|\*[1-9][0-9]*\$|[1-9][0-9]*|)?
-    # #<length modifier>(hh|h|l|ll|L|q|j|z|t)
-    # <conversion specifier>[diouxXeEfgGcsb%] 
-    def parse_printf_format(format, opts)
-      return format, opts if $1.size % 2 == 1
-    end
-
-    def puts(*objs)
-      for obj in objs
-	print(*obj)
-	print "\n"
-      end
-    end
-
-    def pp(*objs)
-      puts(*objs.collect{|obj| obj.inspect})
-    end
-
-    def ppx(prefix, *objs)
-      puts(*objs.collect{|obj| prefix+obj.inspect})
-    end
-
-  end
-
-  class StdioOutputMethod<OutputMethod
-    def print(*opts)
-      STDOUT.print(*opts)
-    end
-  end
-end

Deleted: MacRuby/trunk/lib/irb/ruby-lex.rb
===================================================================
--- MacRuby/trunk/lib/irb/ruby-lex.rb	2010-05-02 05:58:51 UTC (rev 3998)
+++ MacRuby/trunk/lib/irb/ruby-lex.rb	2010-05-02 11:40:15 UTC (rev 3999)
@@ -1,1155 +0,0 @@
-#
-#   irb/ruby-lex.rb - ruby lexcal analyzer
-#   	$Release Version: 0.9.5$
-#   	$Revision: 20882 $
-#   	by Keiju ISHITSUKA(keiju at ruby-lang.org)
-#
-# --
-#
-#   
-#
-
-require "e2mmap"
-require "irb/slex"
-require "irb/ruby-token"
-
-class RubyLex
-  @RCS_ID='-$Id: ruby-lex.rb 20882 2008-12-19 11:37:59Z yugui $-'
-
-  extend Exception2MessageMapper
-  def_exception(:AlreadyDefinedToken, "Already defined token(%s)")
-  def_exception(:TkReading2TokenNoKey, "key nothing(key='%s')")
-  def_exception(:TkSymbol2TokenNoKey, "key nothing(key='%s')")
-  def_exception(:TkReading2TokenDuplicateError, 
-		"key duplicate(token_n='%s', key='%s')")
-  def_exception(:SyntaxError, "%s")
-
-  def_exception(:TerminateLineInput, "Terminate Line Input")
-  
-  include RubyToken
-
-  class << self
-    attr_accessor :debug_level
-    def debug?
-      @debug_level > 0
-    end
-  end
-  @debug_level = 0
-
-  def initialize
-    lex_init
-    set_input(STDIN)
-
-    @seek = 0
-    @exp_line_no = @line_no = 1
-    @base_char_no = 0
-    @char_no = 0
-    @rests = []
-    @readed = []
-    @here_readed = []
-
-    @indent = 0
-    @indent_stack = []
-    @lex_state = EXPR_BEG
-    @space_seen = false
-    @here_header = false
-    
-    @continue = false
-    @line = ""
-
-    @skip_space = false
-    @readed_auto_clean_up = false
-    @exception_on_syntax_error = true
-
-    @prompt = nil
-  end
-
-  attr_accessor :skip_space
-  attr_accessor :readed_auto_clean_up
-  attr_accessor :exception_on_syntax_error
-
-  attr_reader :seek
-  attr_reader :char_no
-  attr_reader :line_no
-  attr_reader :indent
-
-  # io functions
-  def set_input(io, p = nil, &block)
-    @io = io
-    if p.respond_to?(:call)
-      @input = p
-    elsif block_given?
-      @input = block
-    else
-      @input = Proc.new{@io.gets}
-    end
-  end
-
-  def get_readed
-    if idx = @readed.reverse.index("\n")
-      @base_char_no = idx
-    else
-      @base_char_no += @readed.size
-    end
-    
-    readed = @readed.join("")
-    @readed = []
-    readed
-  end
-
-  def getc
-    while @rests.empty?
-#      return nil unless buf_input
-      @rests.push nil unless buf_input
-    end
-    c = @rests.shift
-    return if c == nil
-    if @here_header
-      @here_readed.push c
-    else
-      @readed.push c
-    end
-    @seek += 1
-    if c == "\n"
-      @line_no += 1 
-      @char_no = 0
-    else
-      @char_no += 1
-    end
-    c
-  end
-
-  def gets
-    l = ""
-    while c = getc
-      l.concat(c)
-      break if c == "\n"
-    end
-    return nil if l == "" and c.nil?
-    l
-  end
-
-  def eof?
-    @io.eof?
-  end
-
-  def getc_of_rests
-    if @rests.empty?
-      nil
-    else
-      getc
-    end
-  end
-
-  def ungetc(c = nil)
-    if @here_readed.empty?
-      c2 = @readed.pop
-    else
-      c2 = @here_readed.pop
-    end
-    c = c2 unless c
-    @rests.unshift c #c = 
-      @seek -= 1
-    if c == "\n"
-      @line_no -= 1 
-      if idx = @readed.reverse.index("\n")
-	@char_no = @readed.size - idx
-      else
-	@char_no = @base_char_no + @readed.size
-      end
-    else
-      @char_no -= 1
-    end
-  end
-
-  def peek_equal?(str)
-    chrs = str.split(//)
-    until @rests.size >= chrs.size
-      return false unless buf_input
-    end
-    @rests[0, chrs.size] == chrs
-  end
-
-  def peek_match?(regexp)
-    while @rests.empty?
-      return false unless buf_input
-    end
-    regexp =~ @rests.join("")
-  end
-
-  def peek(i = 0)
-    while @rests.size <= i
-      return nil unless buf_input
-    end
-    @rests[i]
-  end
-
-  def buf_input
-    prompt
-    line = @input.call
-    return nil unless line
-    @rests.concat line.chars.to_a
-    true
-  end
-  private :buf_input
-
-  def set_prompt(p = nil, &block)
-    p = block if block_given?
-    if p.respond_to?(:call)
-      @prompt = p
-    else
-      @prompt = Proc.new{print p}
-    end
-  end
-
-  def prompt
-    if @prompt
-      @prompt.call(@ltype, @indent, @continue, @line_no)
-    end
-  end
-
-  def initialize_input
-    @ltype = nil
-    @quoted = nil
-    @indent = 0
-    @indent_stack = []
-    @lex_state = EXPR_BEG
-    @space_seen = false
-    @here_header = false
-    
-    @continue = false
-    prompt
-
-    @line = ""
-    @exp_line_no = @line_no
-  end
-  
-  def each_top_level_statement
-    initialize_input
-    catch(:TERM_INPUT) do
-      loop do
-	begin
-	  @continue = false
-	  prompt
-	  unless l = lex
-	    throw :TERM_INPUT if @line == ''
-	  else
-	    @line.concat l
-	    if @ltype or @continue or @indent > 0
-	      next
-	    end
-	  end
-	  if @line != "\n"
-      @line.force_encoding(@io.encoding)
-	    yield @line, @exp_line_no
-	  end
-	  break unless l
-	  @line = ''
-	  @exp_line_no = @line_no
-
-	  @indent = 0
-	  @indent_stack = []
-	  prompt
-	rescue TerminateLineInput
-	  initialize_input
-	  prompt
-	  get_readed
-	end
-      end
-    end
-  end
-
-  def lex
-    until (((tk = token).kind_of?(TkNL) || tk.kind_of?(TkEND_OF_SCRIPT)) &&
-	     !@continue or
-	     tk.nil?)
-      #p tk
-      #p @lex_state
-      #p self
-    end
-    line = get_readed
-    #      print self.inspect
-    if line == "" and tk.kind_of?(TkEND_OF_SCRIPT) || tk.nil?
-      nil
-    else
-      line
-    end
-  end
-
-  def token
-    #      require "tracer"
-    #      Tracer.on
-    @prev_seek = @seek
-    @prev_line_no = @line_no
-    @prev_char_no = @char_no
-    begin
-      begin
-	tk = @OP.match(self)
-	@space_seen = tk.kind_of?(TkSPACE)
-      rescue SyntaxError
-	raise if @exception_on_syntax_error
-	tk = TkError.new(@seek, @line_no, @char_no)
-      end
-    end while @skip_space and tk.kind_of?(TkSPACE)
-    if @readed_auto_clean_up
-      get_readed
-    end
-    #      Tracer.off
-    tk
-  end
-  
-  ENINDENT_CLAUSE = [
-    "case", "class", "def", "do", "for", "if",
-    "module", "unless", "until", "while", "begin" #, "when"
-  ]
-  DEINDENT_CLAUSE = ["end" #, "when"
-  ]
-
-  PERCENT_LTYPE = {
-    "q" => "\'",
-    "Q" => "\"",
-    "x" => "\`",
-    "r" => "/",
-    "w" => "]",
-    "W" => "]",
-    "s" => ":"
-  }
-  
-  PERCENT_PAREN = {
-    "{" => "}",
-    "[" => "]",
-    "<" => ">",
-    "(" => ")"
-  }
-
-  Ltype2Token = {
-    "\'" => TkSTRING,
-    "\"" => TkSTRING,
-    "\`" => TkXSTRING,
-    "/" => TkREGEXP,
-    "]" => TkDSTRING,
-    ":" => TkSYMBOL
-  }
-  DLtype2Token = {
-    "\"" => TkDSTRING,
-    "\`" => TkDXSTRING,
-    "/" => TkDREGEXP,
-  }
-
-  def lex_init()
-    @OP = IRB::SLex.new
-    @OP.def_rules("\0", "\004", "\032") do |op, io|
-      Token(TkEND_OF_SCRIPT)
-    end
-
-    @OP.def_rules(" ", "\t", "\f", "\r", "\13") do |op, io|
-      @space_seen = true
-      while getc =~ /[ \t\f\r\13]/; end
-      ungetc
-      Token(TkSPACE)
-    end
-
-    @OP.def_rule("#") do |op, io|
-      identify_comment
-    end
-
-    @OP.def_rule("=begin",
-		 proc{|op, io| @prev_char_no == 0 && peek(0) =~ /\s/}) do 
-      |op, io|
-      @ltype = "="
-      until getc == "\n"; end
-      until peek_equal?("=end") && peek(4) =~ /\s/
-	until getc == "\n"; end
-      end
-      gets
-      @ltype = nil
-      Token(TkRD_COMMENT)
-    end
-
-    @OP.def_rule("\n") do |op, io|
-      print "\\n\n" if RubyLex.debug?
-      case @lex_state
-      when EXPR_BEG, EXPR_FNAME, EXPR_DOT
-	@continue = true
-      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 = []
-      Token(TkNL)
-    end
-
-    @OP.def_rules("*", "**",	
-		  "=", "==", "===", 
-		  "=~", "<=>",	
-		  "<", "<=",
-		  ">", ">=", ">>") do
-      |op, io|
-      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
-      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
-
-    @OP.def_rules("'", '"') do
-      |op, io|
-      identify_string(op)
-    end
-
-    @OP.def_rules("`") do
-      |op, io|
-      if @lex_state == EXPR_FNAME
-	@lex_state = EXPR_END
-	Token(op)
-      else
-	identify_string(op)
-      end
-    end
-
-    @OP.def_rules('?') do
-      |op, io|
-      if @lex_state == EXPR_END
-	@lex_state = EXPR_BEG
-	Token(TkQUESTION)
-      else
-	ch = getc
-	if @lex_state == EXPR_ARG && ch =~ /\s/
-	  ungetc
-	  @lex_state = EXPR_BEG;
-	  Token(TkQUESTION)
-	else
-	  if (ch == '\\') 
-	    read_escape
-	  end
-	  @lex_state = EXPR_END
-	  Token(TkINTEGER)
-	end
-      end
-    end
-
-    @OP.def_rules("&", "&&", "|", "||") do
-      |op, io|
-      @lex_state = EXPR_BEG
-      Token(op)
-    end
-    
-    @OP.def_rules("+=", "-=", "*=", "**=", 
-		  "&=", "|=", "^=", "<<=", ">>=", "||=", "&&=") do
-      |op, io|
-      @lex_state = EXPR_BEG
-      op =~ /^(.*)=$/
-      Token(TkOPASGN, $1)
-    end
-
-    @OP.def_rule("+@", proc{|op, io| @lex_state == EXPR_FNAME}) do
-      |op, io|
-      @lex_state = EXPR_ARG
-      Token(op)
-    end
-
-    @OP.def_rule("-@", proc{|op, io| @lex_state == EXPR_FNAME}) do
-      |op, io|
-      @lex_state = EXPR_ARG
-      Token(op)
-    end
-
-    @OP.def_rules("+", "-") do
-      |op, io|
-      catch(:RET) do
-	if @lex_state == EXPR_ARG
-	  if @space_seen and peek(0) =~ /[0-9]/
-	    throw :RET, identify_number
-	  else
-	    @lex_state = EXPR_BEG
-	  end
-	elsif @lex_state != EXPR_END and peek(0) =~ /[0-9]/
-	  throw :RET, identify_number
-	else
-	  @lex_state = EXPR_BEG
-	end
-	Token(op)
-      end
-    end
-
-    @OP.def_rule(".") do
-      |op, io|
-      @lex_state = EXPR_BEG
-      if peek(0) =~ /[0-9]/
-	ungetc
-	identify_number
-      else
-	# for "obj.if" etc.
-	@lex_state = EXPR_DOT
-	Token(TkDOT)
-      end
-    end
-
-    @OP.def_rules("..", "...") do
-      |op, io|
-      @lex_state = EXPR_BEG
-      Token(op)
-    end
-
-    lex_int2
-  end
-  
-  def lex_int2
-    @OP.def_rules("]", "}", ")") do
-      |op, io|
-      @lex_state = EXPR_END
-      @indent -= 1
-      @indent_stack.pop
-      Token(op)
-    end
-
-    @OP.def_rule(":") do
-      |op, io|
-      if @lex_state == EXPR_END || peek(0) =~ /\s/
-	@lex_state = EXPR_BEG
-	Token(TkCOLON)
-      else
-	@lex_state = EXPR_FNAME;
-	Token(TkSYMBEG)
-      end
-    end
-
-    @OP.def_rule("::") do
-       |op, io|
-#      p @lex_state.id2name, @space_seen
-      if @lex_state == EXPR_BEG or @lex_state == EXPR_ARG && @space_seen
-	@lex_state = EXPR_BEG
-	Token(TkCOLON3)
-      else
-	@lex_state = EXPR_DOT
-	Token(TkCOLON2)
-      end
-    end
-
-    @OP.def_rule("/") do
-      |op, io|
-      if @lex_state == EXPR_BEG || @lex_state == EXPR_MID
-	identify_string(op)
-      elsif peek(0) == '='
-	getc
-	@lex_state = EXPR_BEG
-	Token(TkOPASGN, "/") #/)
-      elsif @lex_state == EXPR_ARG and @space_seen and peek(0) !~ /\s/
-	identify_string(op)
-      else 
-	@lex_state = EXPR_BEG
-	Token("/") #/)
-      end
-    end
-
-    @OP.def_rules("^") do
-      |op, io|
-      @lex_state = EXPR_BEG
-      Token("^")
-    end
-
-    #       @OP.def_rules("^=") do
-    # 	@lex_state = EXPR_BEG
-    # 	Token(OP_ASGN, :^)
-    #       end
-    
-    @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
-      |op, io|
-      @lex_state = EXPR_BEG
-      Token("~")
-    end
-
-    @OP.def_rule("~@", proc{|op, io| @lex_state == EXPR_FNAME}) do
-      |op, io|
-      @lex_state = EXPR_BEG
-      Token("~")
-    end
-    
-    @OP.def_rule("(") do
-      |op, io|
-      @indent += 1
-      if @lex_state == EXPR_BEG || @lex_state == EXPR_MID
-	@lex_state = EXPR_BEG
-	tk_c = TkfLPAREN
-      else
-	@lex_state = EXPR_BEG
-	tk_c = TkLPAREN
-      end
-      @indent_stack.push tk_c
-      tk = Token(tk_c)
-    end
-
-    @OP.def_rule("[]", proc{|op, io| @lex_state == EXPR_FNAME}) do
-      |op, io|
-      @lex_state = EXPR_ARG
-      Token("[]")
-    end
-
-    @OP.def_rule("[]=", proc{|op, io| @lex_state == EXPR_FNAME}) do
-      |op, io|
-      @lex_state = EXPR_ARG
-      Token("[]=")
-    end
-
-    @OP.def_rule("[") do
-      |op, io|
-      @indent += 1
-      if @lex_state == EXPR_FNAME
-	tk_c = TkfLBRACK
-      else
-	if @lex_state == EXPR_BEG || @lex_state == EXPR_MID
-	  tk_c = TkLBRACK
-	elsif @lex_state == EXPR_ARG && @space_seen
-	  tk_c = TkLBRACK
-	else
-	  tk_c = TkfLBRACK
-	end
-	@lex_state = EXPR_BEG
-      end
-      @indent_stack.push tk_c
-      Token(tk_c)
-    end
-
-    @OP.def_rule("{") do
-      |op, io|
-      @indent += 1
-      if @lex_state != EXPR_END && @lex_state != EXPR_ARG
-	tk_c = TkLBRACE
-      else
-	tk_c = TkfLBRACE
-      end
-      @lex_state = EXPR_BEG
-      @indent_stack.push tk_c
-      Token(tk_c)
-    end
-
-    @OP.def_rule('\\') do
-      |op, io|
-      if getc == "\n"
-	@space_seen = true
-	@continue = true
-	Token(TkSPACE)
-      else
-	ungetc
-	Token("\\")
-      end
-    end
-
-    @OP.def_rule('%') do
-      |op, io|
-      if @lex_state == EXPR_BEG || @lex_state == EXPR_MID
-	identify_quotation
-      elsif peek(0) == '='
-	getc
-	Token(TkOPASGN, :%)
-      elsif @lex_state == EXPR_ARG and @space_seen and peek(0) !~ /\s/
-	identify_quotation
-      else
-	@lex_state = EXPR_BEG
-	Token("%") #))
-      end
-    end
-
-    @OP.def_rule('$') do
-      |op, io|
-      identify_gvar
-    end
-
-    @OP.def_rule('@') do
-      |op, io|
-      if peek(0) =~ /[\w_@]/
-	ungetc
-	identify_identifier
-      else
-	Token("@")
-      end
-    end
-
-    #       @OP.def_rule("def", proc{|op, io| /\s/ =~ io.peek(0)}) do 
-    # 	|op, io|
-    # 	@indent += 1
-    # 	@lex_state = EXPR_FNAME
-    # #	@lex_state = EXPR_END
-    # #	until @rests[0] == "\n" or @rests[0] == ";"
-    # #	  rests.shift
-    # #	end
-    #       end
-
-    @OP.def_rule("") do
-      |op, io|
-      printf "MATCH: start %s: %s\n", op, io.inspect if RubyLex.debug?
-      if peek(0) =~ /[0-9]/
-	t = identify_number
-      elsif peek(0) =~ /[\w_]/
-	t = identify_identifier
-      end
-      printf "MATCH: end %s: %s\n", op, io.inspect if RubyLex.debug?
-      t
-    end
-    
-    p @OP if RubyLex.debug?
-  end
-  
-  def identify_gvar
-    @lex_state = EXPR_END
-    
-    case ch = getc
-    when /[~_*$?!@\/\\;,=:<>".]/   #"
-      Token(TkGVAR, "$" + ch)
-    when "-"
-      Token(TkGVAR, "$-" + getc)
-    when "&", "`", "'", "+"
-      Token(TkBACK_REF, "$"+ch)
-    when /[1-9]/
-      while getc =~ /[0-9]/; end
-      ungetc
-      Token(TkNTH_REF)
-    when /\w/
-      ungetc
-      ungetc
-      identify_identifier
-    else 
-      ungetc
-      Token("$")
-    end
-  end
-  
-  def identify_identifier
-    token = ""
-    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 == "!" || 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)
-    end
-    
-    if @lex_state != EXPR_DOT
-      print token, "\n" if RubyLex.debug?
-
-      token_c, *trans = TkReading2Token[token]
-      if token_c
-	# reserved word?
-
-	if (@lex_state != EXPR_BEG &&
-	    @lex_state != EXPR_FNAME &&
-	    trans[1])
-	  # modifiers
-	  token_c = TkSymbol2Token[trans[1]]
-	  @lex_state = trans[0]
-	else
-	  if @lex_state != EXPR_FNAME
-	    if ENINDENT_CLAUSE.include?(token)
-	      # check for ``class = val'' etc.
-	      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
-	    @lex_state = EXPR_END
-	  end
-	end
-	return Token(token_c, token)
-      end
-    end
-
-    if @lex_state == EXPR_FNAME
-      @lex_state = EXPR_END
-      if peek(0) == '='
-	token.concat getc
-      end
-    elsif @lex_state == EXPR_BEG || @lex_state == EXPR_DOT
-      @lex_state = EXPR_ARG
-    else
-      @lex_state = EXPR_END
-    end
-
-    if token[0, 1] =~ /[A-Z]/
-      return Token(TkCONSTANT, token)
-    elsif token[token.size - 1, 1] =~ /[!?]/
-      return Token(TkFID, token)
-    else
-      return Token(TkIDENTIFIER, token)
-    end
-  end
-
-  def identify_here_document
-    ch = getc
-#    if lt = PERCENT_LTYPE[ch]
-    if ch == "-"
-      ch = getc
-      indent = true
-    end
-    if /['"`]/ =~ ch
-      lt = ch
-      quoted = ""
-      while (c = getc) && c != lt
-	quoted.concat c
-      end
-    else
-      lt = '"'
-      quoted = ch.dup
-      while (c = getc) && c =~ /\w/
-	quoted.concat c
-      end
-      ungetc
-    end
-
-    ltback, @ltype = @ltype, lt
-    reserve = []
-    while ch = getc
-      reserve.push ch
-      if ch == "\\"
-	reserve.push ch = getc
-      elsif ch == "\n"
-	break
-      end
-    end
-
-    @here_header = false
-    while l = gets
-      l = l.sub(/(:?\r)?\n\z/, '')
-      if (indent ? l.strip : l) == quoted
- 	break
-      end
-    end
-
-    @here_header = true
-    @here_readed.concat reserve
-    while ch = reserve.pop
-      ungetc ch
-    end
-
-    @ltype = ltback
-    @lex_state = EXPR_END
-    Token(Ltype2Token[lt])
-  end
-  
-  def identify_quotation
-    ch = getc
-    if lt = PERCENT_LTYPE[ch]
-      ch = getc
-    elsif ch =~ /\W/
-      lt = "\""
-    else
-      RubyLex.fail SyntaxError, "unknown type of %string"
-    end
-#     if ch !~ /\W/
-#       ungetc
-#       next
-#     end
-    #@ltype = lt
-    @quoted = ch unless @quoted = PERCENT_PAREN[ch]
-    identify_string(lt, @quoted)
-  end
-
-  def identify_number
-    @lex_state = EXPR_END
-
-    if peek(0) == "0" && peek(1) !~ /[.eE]/
-      getc
-      case peek(0)
-      when /[xX]/
-	ch = getc
-	match = /[0-9a-fA-F_]/
-      when /[bB]/
-	ch = getc
-	match = /[01_]/
-      when /[oO]/
-	ch = getc
-	match = /[0-7_]/
-      when /[dD]/
-	ch = getc
-	match = /[0-9_]/
-      when /[0-7]/
-	match = /[0-7_]/
-      when /[89]/
-	RubyLex.fail SyntaxError, "Invalid octal digit"
-      else 
-	return Token(TkINTEGER)
-      end
-      
-      len0 = true
-      non_digit = false
-      while ch = getc
-	if match =~ ch
-	  if ch == "_"
-	    if non_digit
-	      RubyLex.fail SyntaxError, "trailing `#{ch}' in number"
-	    else
-	      non_digit = ch
-	    end
-	  else
-	    non_digit = false
-	    len0 = false
-	  end
-	else
-	  ungetc
-	  if len0
-	    RubyLex.fail SyntaxError, "numeric literal without digits"
-	  end
-	  if non_digit
-	    RubyLex.fail SyntaxError, "trailing `#{non_digit}' in number"
-	  end
-	  break
-	end
-      end
-      return Token(TkINTEGER)
-    end
-    
-    type = TkINTEGER
-    allow_point = true
-    allow_e = true
-    non_digit = false
-    while ch = getc
-      case ch
-      when /[0-9]/
-	non_digit = false
-      when "_"
-	non_digit = ch
-      when allow_point && "."
-	if non_digit
-	  RubyLex.fail SyntaxError, "trailing `#{non_digit}' in number"
-	end
-	type = TkFLOAT
-	if peek(0) !~ /[0-9]/
-	  type = TkINTEGER
-	  ungetc
-	  break
-	end
-	allow_point = false
-      when allow_e && "e", allow_e && "E"
-	if non_digit
-	  RubyLex.fail SyntaxError, "trailing `#{non_digit}' in number"
-	end
-	type = TkFLOAT
-	if peek(0) =~ /[+-]/
-	  getc
-	end
-	allow_e = false
-	allow_point = false
-	non_digit = ch
-      else
-	if non_digit
-	  RubyLex.fail SyntaxError, "trailing `#{non_digit}' in number"
-	end
-	ungetc
-	break
-      end
-    end
-    Token(type)
-  end
-  
-  def identify_string(ltype, quoted = ltype)
-    @ltype = ltype
-    @quoted = quoted
-    subtype = nil
-    begin
-      nest = 0
-      while ch = getc
-	if @quoted == ch and nest == 0
-	  break
-	elsif @ltype != "'" && @ltype != "]" && @ltype != ":" and ch == "#"
-	  subtype = true
-	elsif ch == '\\' and @ltype == "'" #'
-	  case ch = getc
-	  when "\\", "\n", "'"
-	  else
-	    ungetc
-	  end
-	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|m|x|o|e|s|u|n/
-	  getc
-	end
-      end
-      if subtype
-	Token(DLtype2Token[ltype])
-      else
-	Token(Ltype2Token[ltype])
-      end
-    ensure
-      @ltype = nil
-      @quoted = nil
-      @lex_state = EXPR_END
-    end
-  end
-  
-  def identify_comment
-    @ltype = "#"
-
-    while ch = getc
-#      if ch == "\\" #"
-#	read_escape
-#      end
-      if ch == "\n"
-	@ltype = nil
-	ungetc
-	break
-      end
-    end
-    return Token(TkCOMMENT)
-  end
-  
-  def read_escape
-    case ch = getc
-    when "\n", "\r", "\f"
-    when "\\", "n", "t", "r", "f", "v", "a", "e", "b", "s" #"
-    when /[0-7]/
-      ungetc ch
-      3.times do
-	case ch = getc
-	when /[0-7]/
-	when nil
-	  break
-	else
-	  ungetc
-	  break
-	end
-      end
-      
-    when "x"
-      2.times do
-	case ch = getc
-	when /[0-9a-fA-F]/
-	when nil
-	  break
-	else
-	  ungetc
-	  break
-	end
-      end
-
-    when "M"
-      if (ch = getc) != '-'
-	ungetc
-      else
-	if (ch = getc) == "\\" #"
-	  read_escape
-	end
-      end
-
-    when "C", "c" #, "^"
-      if ch == "C" and (ch = getc) != "-"
-	ungetc
-      elsif (ch = getc) == "\\" #"
-	read_escape
-      end
-    else
-      # other characters 
-    end
-  end
-end

Deleted: MacRuby/trunk/lib/irb/ruby-token.rb
===================================================================
--- MacRuby/trunk/lib/irb/ruby-token.rb	2010-05-02 05:58:51 UTC (rev 3998)
+++ MacRuby/trunk/lib/irb/ruby-token.rb	2010-05-02 11:40:15 UTC (rev 3999)
@@ -1,270 +0,0 @@
-#
-#   irb/ruby-token.rb - ruby tokens 
-#   	$Release Version: 0.9.5$
-#   	$Revision: 14912 $
-#   	by Keiju ISHITSUKA(keiju at ruby-lang.org)
-#
-# --
-#
-#   
-#
-module RubyToken
-  EXPR_BEG = :EXPR_BEG
-  EXPR_MID = :EXPR_MID
-  EXPR_END = :EXPR_END
-  EXPR_ARG = :EXPR_ARG
-  EXPR_FNAME = :EXPR_FNAME
-  EXPR_DOT = :EXPR_DOT
-  EXPR_CLASS = :EXPR_CLASS
-
-  # for ruby 1.4X
-  if !defined?(Symbol)
-    Symbol = Integer
-  end
-  
-  class Token
-    def initialize(seek, line_no, char_no)
-      @seek = seek
-      @line_no = line_no
-      @char_no = char_no
-    end
-    attr :seek, :line_no, :char_no
-  end
-
-  class TkNode < Token
-    def initialize(seek, line_no, char_no)
-      super
-    end
-    attr :node
-  end
-
-  class TkId < Token
-    def initialize(seek, line_no, char_no, name)
-      super(seek, line_no, char_no)
-      @name = name
-    end
-    attr :name
-  end
-
-  class TkVal < Token
-    def initialize(seek, line_no, char_no, value = nil)
-      super(seek, line_no, char_no)
-      @value = value
-    end
-    attr :value
-  end
-
-  class TkOp < Token
-    attr_accessor :name
-  end
-
-  class TkOPASGN < TkOp
-    def initialize(seek, line_no, char_no, op)
-      super(seek, line_no, char_no)
-      op = TkReading2Token[op][0] unless op.kind_of?(Symbol)
-      @op = op
-    end
-    attr :op
-  end
-
-  class TkUnknownChar < Token
-    def initialize(seek, line_no, char_no, id)
-      super(seek, line_no, char_no)
-      @name = name
-    end
-    attr :name
-  end
-
-  class TkError < Token
-  end
-
-  def Token(token, value = nil)
-    case token
-    when String
-      if (tk = TkReading2Token[token]).nil?
-	IRB.fail TkReading2TokenNoKey, token
-      end
-      tk = Token(tk[0], value) 
-      if tk.kind_of?(TkOp)
-	tk.name = token
-      end
-      return tk
-    when Symbol
-      if (tk = TkSymbol2Token[token]).nil?
-	IRB.fail TkSymbol2TokenNoKey, token
-      end
-      return Token(tk[0], value) 
-    else 
-      if (token.ancestors & [TkId, TkVal, TkOPASGN, TkUnknownChar]).empty?
-	token.new(@prev_seek, @prev_line_no, @prev_char_no)
-      else
-	token.new(@prev_seek, @prev_line_no, @prev_char_no, value)
-      end
-    end
-  end
-
-  TokenDefinitions = [
-    [:TkCLASS,      TkId,  "class",  EXPR_CLASS],
-    [:TkMODULE,     TkId,  "module", EXPR_BEG],
-    [:TkDEF,	    TkId,  "def",    EXPR_FNAME],
-    [:TkUNDEF,      TkId,  "undef",  EXPR_FNAME],
-    [:TkBEGIN,      TkId,  "begin",  EXPR_BEG],
-    [:TkRESCUE,     TkId,  "rescue", EXPR_MID],
-    [:TkENSURE,     TkId,  "ensure", EXPR_BEG],
-    [:TkEND,	    TkId,  "end",    EXPR_END],
-    [:TkIF,         TkId,  "if",     EXPR_BEG, :TkIF_MOD],
-    [:TkUNLESS,     TkId,  "unless", EXPR_BEG, :TkUNLESS_MOD],
-    [:TkTHEN,	    TkId,  "then",   EXPR_BEG],
-    [:TkELSIF,      TkId,  "elsif",  EXPR_BEG],
-    [:TkELSE,	    TkId,  "else",   EXPR_BEG],
-    [:TkCASE,	    TkId,  "case",   EXPR_BEG],
-    [:TkWHEN,	    TkId,  "when",   EXPR_BEG],
-    [:TkWHILE,      TkId,  "while",  EXPR_BEG, :TkWHILE_MOD],
-    [:TkUNTIL,      TkId,  "until",  EXPR_BEG, :TkUNTIL_MOD],
-    [:TkFOR,	    TkId,  "for",    EXPR_BEG],
-    [:TkBREAK,      TkId,  "break",  EXPR_END],
-    [:TkNEXT,	    TkId,  "next",   EXPR_END],
-    [:TkREDO,	    TkId,  "redo",   EXPR_END],
-    [:TkRETRY,      TkId,  "retry",  EXPR_END],
-    [:TkIN,	    TkId,  "in",     EXPR_BEG],
-    [:TkDO,	    TkId,  "do",     EXPR_BEG],
-    [:TkRETURN,     TkId,  "return", EXPR_MID],
-    [:TkYIELD,      TkId,  "yield",  EXPR_END],
-    [:TkSUPER,      TkId,  "super",  EXPR_END],
-    [:TkSELF,	    TkId,  "self",   EXPR_END],
-    [:TkNIL, 	    TkId,  "nil",    EXPR_END],
-    [:TkTRUE,	    TkId,  "true",   EXPR_END],
-    [:TkFALSE,      TkId,  "false",  EXPR_END],
-    [:TkAND,	    TkId,  "and",    EXPR_BEG],
-    [:TkOR, 	    TkId,  "or",     EXPR_BEG],
-    [:TkNOT,	    TkId,  "not",    EXPR_BEG],
-    [:TkIF_MOD,     TkId],
-    [:TkUNLESS_MOD, TkId],
-    [:TkWHILE_MOD,  TkId],
-    [:TkUNTIL_MOD,  TkId],
-    [:TkALIAS,      TkId,  "alias",    EXPR_FNAME],
-    [:TkDEFINED,    TkId,  "defined?", EXPR_END],
-    [:TklBEGIN,     TkId,  "BEGIN",    EXPR_END],
-    [:TklEND,	    TkId,  "END",      EXPR_END],
-    [:Tk__LINE__,   TkId,  "__LINE__", EXPR_END],
-    [:Tk__FILE__,   TkId,  "__FILE__", EXPR_END],
-
-    [:TkIDENTIFIER, TkId],
-    [:TkFID,	    TkId],
-    [:TkGVAR,	    TkId],
-    [:TkCVAR,	    TkId],
-    [:TkIVAR,	    TkId],
-    [:TkCONSTANT,   TkId],
-
-    [:TkINTEGER,    TkVal],
-    [:TkFLOAT,      TkVal],
-    [:TkSTRING,     TkVal],
-    [:TkXSTRING,    TkVal],
-    [:TkREGEXP,     TkVal],
-    [:TkSYMBOL,     TkVal],
-
-    [:TkDSTRING,    TkNode],
-    [:TkDXSTRING,   TkNode],
-    [:TkDREGEXP,    TkNode],
-    [:TkNTH_REF,    TkNode],
-    [:TkBACK_REF,   TkNode],
-
-    [:TkUPLUS,      TkOp,   "+@"],
-    [:TkUMINUS,     TkOp,   "-@"],
-    [:TkPOW,	    TkOp,   "**"],
-    [:TkCMP,	    TkOp,   "<=>"],
-    [:TkEQ,	    TkOp,   "=="],
-    [:TkEQQ,	    TkOp,   "==="],
-    [:TkNEQ,	    TkOp,   "!="],
-    [:TkGEQ,	    TkOp,   ">="],
-    [:TkLEQ,	    TkOp,   "<="],
-    [:TkANDOP,      TkOp,   "&&"],
-    [:TkOROP,	    TkOp,   "||"],
-    [:TkMATCH,      TkOp,   "=~"],
-    [:TkNMATCH,     TkOp,   "!~"],
-    [:TkDOT2,	    TkOp,   ".."],
-    [:TkDOT3,	    TkOp,   "..."],
-    [:TkAREF,	    TkOp,   "[]"],
-    [:TkASET,	    TkOp,   "[]="],
-    [:TkLSHFT,      TkOp,   "<<"],
-    [:TkRSHFT,      TkOp,   ">>"],
-    [:TkCOLON2,     TkOp],
-    [:TkCOLON3,     TkOp],
-#   [:OPASGN,	    TkOp],               # +=, -=  etc. #
-    [:TkASSOC,      TkOp,   "=>"],
-    [:TkQUESTION,   TkOp,   "?"],	 #?
-    [:TkCOLON,      TkOp,   ":"],        #:
-    
-    [:TkfLPAREN],         # func( #
-    [:TkfLBRACK],         # func[ #
-    [:TkfLBRACE],         # func{ #
-    [:TkSTAR],            # *arg
-    [:TkAMPER],           # &arg #
-    [:TkSYMBEG],          # :SYMBOL
-
-    [:TkGT,	    TkOp,   ">"],
-    [:TkLT,	    TkOp,   "<"],
-    [:TkPLUS,	    TkOp,   "+"],
-    [:TkMINUS,      TkOp,   "-"],
-    [:TkMULT,	    TkOp,   "*"],
-    [:TkDIV,	    TkOp,   "/"],
-    [:TkMOD,	    TkOp,   "%"],
-    [:TkBITOR,      TkOp,   "|"],
-    [:TkBITXOR,     TkOp,   "^"],
-    [:TkBITAND,     TkOp,   "&"],
-    [:TkBITNOT,     TkOp,   "~"],
-    [:TkNOTOP,      TkOp,   "!"],
-
-    [:TkBACKQUOTE,  TkOp,   "`"],
-
-    [:TkASSIGN,     Token,  "="],
-    [:TkDOT,	    Token,  "."],
-    [:TkLPAREN,     Token,  "("],  #(exp)
-    [:TkLBRACK,     Token,  "["],  #[arry]
-    [:TkLBRACE,     Token,  "{"],  #{hash}
-    [:TkRPAREN,     Token,  ")"],
-    [:TkRBRACK,     Token,  "]"],
-    [:TkRBRACE,     Token,  "}"],
-    [:TkCOMMA,      Token,  ","],
-    [:TkSEMICOLON,  Token,  ";"],
-
-    [:TkCOMMENT],
-    [:TkRD_COMMENT],
-    [:TkSPACE],
-    [:TkNL],
-    [:TkEND_OF_SCRIPT],
-
-    [:TkBACKSLASH,  TkUnknownChar,  "\\"],
-    [:TkAT,	    TkUnknownChar,  "@"],
-    [:TkDOLLAR,     TkUnknownChar,  "$"],
-  ]
-
-  # {reading => token_class}
-  # {reading => [token_class, *opt]}
-  TkReading2Token = {}
-  TkSymbol2Token = {}
-
-  def RubyToken.def_token(token_n, super_token = Token, reading = nil, *opts)
-    token_n = token_n.id2name if token_n.kind_of?(Symbol)
-    if RubyToken.const_defined?(token_n)
-      IRB.fail AlreadyDefinedToken, token_n
-    end
-    token_c = eval("class #{token_n} < #{super_token}; end; #{token_n}")
-    
-    if reading
-      if TkReading2Token[reading]
-	IRB.fail TkReading2TokenDuplicateError, token_n, reading
-      end
-      if opts.empty?
-	TkReading2Token[reading] = [token_c]
-      else
-	TkReading2Token[reading] = [token_c].concat(opts)
-      end
-    end
-    TkSymbol2Token[token_n.intern] = token_c
-  end
-
-  for defs in TokenDefinitions
-    def_token(*defs)
-  end
-end

Deleted: MacRuby/trunk/lib/irb/slex.rb
===================================================================
--- MacRuby/trunk/lib/irb/slex.rb	2010-05-02 05:58:51 UTC (rev 3998)
+++ MacRuby/trunk/lib/irb/slex.rb	2010-05-02 11:40:15 UTC (rev 3999)
@@ -1,282 +0,0 @@
-#
-#   irb/slex.rb - simple lex analyzer
-#   	$Release Version: 0.9.5$
-#   	$Revision: 16810 $
-#   	by Keiju ISHITSUKA(keiju at ruby-lang.org)
-#
-# --
-#
-#   
-#
-
-require "e2mmap"
-require "irb/notifier"
-
-module IRB
-  class SLex
-    @RCS_ID='-$Id: slex.rb 16810 2008-06-04 09:37:38Z matz $-'
-
-    extend Exception2MessageMapper
-    def_exception :ErrNodeNothing, "node nothing"
-    def_exception :ErrNodeAlreadyExists, "node already exists"
-
-    DOUT = Notifier::def_notifier("SLex::")
-    D_WARN = DOUT::def_notifier(1, "Warn: ")
-    D_DEBUG = DOUT::def_notifier(2, "Debug: ")
-    D_DETAIL = DOUT::def_notifier(4, "Detail: ")
-    
-    DOUT.level = Notifier::D_NOMSG
-
-    def initialize
-      @head = Node.new("")
-    end
-    
-    def def_rule(token, preproc = nil, postproc = nil, &block)
-      D_DETAIL.pp token
-
-      postproc = block if block_given?
-      node = create(token, preproc, postproc)
-    end
-    
-    def def_rules(*tokens, &block)
-      if block_given?
-	p = block
-      end
-      for token in tokens
-	def_rule(token, nil, p)
-      end
-    end
-    
-    def preproc(token, proc)
-      node = search(token)
-      node.preproc=proc
-    end
-    
-    #要チェック? 
-    def postproc(token)
-      node = search(token, proc)
-      node.postproc=proc
-    end
-    
-    def search(token)
-      @head.search(token.split(//))
-    end
-
-    def create(token, preproc = nil, postproc = nil)
-      @head.create_subnode(token.split(//), preproc, postproc)
-    end
-    
-    def match(token)
-      case token
-      when Array
-      when String
-	return match(token.split(//))
-      else
-	return @head.match_io(token)
-      end
-      ret = @head.match(token)
-      D_DETAIL.exec_if{D_DEATIL.printf "match end: %s:%s\n", ret, token.inspect}
-      ret
-    end
-    
-    def inspect
-      format("<SLex: @head = %s>", @head.inspect)
-    end
-
-    #----------------------------------------------------------------------
-    #
-    #   class Node - 
-    #
-    #----------------------------------------------------------------------
-    class Node
-      # if postproc is nil, this node is an abstract node.
-      # if postproc is non-nil, this node is a real node.
-      def initialize(preproc = nil, postproc = nil)
-	@Tree = {}
-	@preproc = preproc
-	@postproc = postproc
-      end
-
-      attr_accessor :preproc
-      attr_accessor :postproc
-      
-      def search(chrs, opt = nil)
-	return self if chrs.empty?
-	ch = chrs.shift
-	if node = @Tree[ch]
-	  node.search(chrs, opt)
-	else
-	  if opt
-	    chrs.unshift ch
-	    self.create_subnode(chrs)
-	  else
-	    SLex.fail ErrNodeNothing
-	  end
-	end
-      end
-      
-      def create_subnode(chrs, preproc = nil, postproc = nil)
-	if chrs.empty?
-	  if @postproc
-	    D_DETAIL.pp node
-	    SLex.fail ErrNodeAlreadyExists
-	  else
-	    D_DEBUG.puts "change abstract node to real node."
-	    @preproc = preproc
-	    @postproc = postproc
-	  end
-	  return self
-	end
-	
-	ch = chrs.shift
-	if node = @Tree[ch]
-	  if chrs.empty?
-	    if node.postproc
-	      DebugLogger.pp node
-	      DebugLogger.pp self
-	      DebugLogger.pp ch
-	      DebugLogger.pp chrs
-	      SLex.fail ErrNodeAlreadyExists
-	    else
-	      D_WARN.puts "change abstract node to real node"
-	      node.preproc = preproc
-	      node.postproc = postproc
-	    end
-	  else
-	    node.create_subnode(chrs, preproc, postproc)
-	  end
-	else
-	  if chrs.empty?
-	    node = Node.new(preproc, postproc)
-	  else
-	    node = Node.new
-	    node.create_subnode(chrs, preproc, postproc)
-	  end
-	  @Tree[ch] = node
-	end
-	node
-      end
-
-      #
-      # chrs: String
-      #       character array
-      #       io must have getc()/ungetc(); and ungetc() must be
-      #       able to be called arbitrary number of times. 
-      #
-      def match(chrs, op = "")
-	D_DETAIL.print "match>: ", chrs, "op:", op, "\n"
-	if chrs.empty?
-	  if @preproc.nil? || @preproc.call(op, chrs)
-	    DOUT.printf(D_DETAIL, "op1: %s\n", op)
-	    @postproc.call(op, chrs)
-	  else
-	    nil
-	  end
-	else
-	  ch = chrs.shift
-	  if node = @Tree[ch]
-	    if ret = node.match(chrs, op+ch)
-	      return ret
-	    else
-	      chrs.unshift ch
-	      if @postproc and @preproc.nil? || @preproc.call(op, chrs)
-		DOUT.printf(D_DETAIL, "op2: %s\n", op.inspect)
-		ret = @postproc.call(op, chrs)
-		return ret
-	      else
-		return nil
-	      end
-	    end
-	  else
-	    chrs.unshift ch
-	    if @postproc and @preproc.nil? || @preproc.call(op, chrs)
-	      DOUT.printf(D_DETAIL, "op3: %s\n", op)
-	      @postproc.call(op, chrs)
-	      return ""
-	    else
-	      return nil
-	    end
-	  end
-	end
-      end
-
-      def match_io(io, op = "")
-	if op == ""
-	  ch = io.getc
-	  if ch == nil
-	    return nil
-	  end
-	else
-	  ch = io.getc_of_rests
-	end
-	if ch.nil?
-	  if @preproc.nil? || @preproc.call(op, io)
-	    D_DETAIL.printf("op1: %s\n", op)
-	    @postproc.call(op, io)
-	  else
-	    nil
-	  end
-	else
-	  if node = @Tree[ch]
-	    if ret = node.match_io(io, op+ch)
-	      ret
-	    else
-	      io.ungetc ch
-	      if @postproc and @preproc.nil? || @preproc.call(op, io)
-		DOUT.exec_if{D_DETAIL.printf "op2: %s\n", op.inspect}
-		@postproc.call(op, io)
-	      else
-		nil
-	      end
-	    end
-	  else
-	    io.ungetc ch
-	    if @postproc and @preproc.nil? || @preproc.call(op, io)
-	      D_DETAIL.printf("op3: %s\n", op)
-	      @postproc.call(op, io)
-	    else
-	      nil
-	    end
-	  end
-	end
-      end
-    end
-  end
-end
-
-if $0 == __FILE__
-  #    Tracer.on
-  case $1
-  when "1"
-    tr = SLex.new
-    print "0: ", tr.inspect, "\n"
-    tr.def_rule("=") {print "=\n"}
-    print "1: ", tr.inspect, "\n"
-    tr.def_rule("==") {print "==\n"}
-    print "2: ", tr.inspect, "\n"
-    
-    print "case 1:\n"
-    print tr.match("="), "\n"
-    print "case 2:\n"
-    print tr.match("=="), "\n"
-    print "case 3:\n"
-    print tr.match("=>"), "\n"
-    
-  when "2"
-    tr = SLex.new
-    print "0: ", tr.inspect, "\n"
-    tr.def_rule("=") {print "=\n"}
-    print "1: ", tr.inspect, "\n"
-    tr.def_rule("==", proc{false}) {print "==\n"}
-    print "2: ", tr.inspect, "\n"
-    
-    print "case 1:\n"
-    print tr.match("="), "\n"
-    print "case 2:\n"
-    print tr.match("=="), "\n"
-    print "case 3:\n"
-    print tr.match("=>"), "\n"
-  end
-  exit
-end
-

Added: MacRuby/trunk/lib/irb/source.rb
===================================================================
--- MacRuby/trunk/lib/irb/source.rb	                        (rev 0)
+++ MacRuby/trunk/lib/irb/source.rb	2010-05-02 11:40:15 UTC (rev 3999)
@@ -0,0 +1,160 @@
+# MacRuby implementation of IRB.
+#
+# This file is covered by the Ruby license. See COPYING for more details.
+# 
+# Copyright (C) 2009-2010, Eloy Duran <eloy.de.enige at gmail.com>
+
+require 'ripper'
+
+module IRB
+  class Source
+    attr_reader :buffer
+    
+    def initialize(buffer = [])
+      @buffer = buffer
+    end
+    
+    # Adds a source line to the buffer and flushes the cached reflection.
+    def <<(source)
+      source = source.strip
+      unless source.empty?
+        @reflection = nil
+        @buffer << source
+      end
+    end
+    
+    # Removes the last line from the buffer and flushes the cached reflection.
+    def pop
+      @reflection = nil
+      @buffer.pop
+    end
+    
+    # Returns the accumulated source as a string, joined by newlines.
+    def source
+      @buffer.join("\n")
+    end
+    
+    alias_method :to_s, :source
+    
+    # Reflects on the accumulated source and returns the current code block
+    # indentation level.
+    def level
+      reflect.level
+    end
+    
+    # Reflects on the accumulated source to see if it's a valid code block.
+    def code_block?
+      reflect.code_block?
+    end
+    
+    # Reflects on the accumulated source to see if it contains a syntax error.
+    def syntax_error?
+      reflect.syntax_error?
+    end
+    
+    # Reflects on the accumulated source and returns the actual syntax error
+    # message if one occurs.
+    def syntax_error
+      reflect.syntax_error
+    end
+    
+    # Returns a Reflector for the accumulated source and caches it.
+    def reflect
+      @reflection ||= Reflector.new(source)
+    end
+    
+    class Reflector < Ripper::SexpBuilder
+      def initialize(source)
+        super
+        @level = 0
+        @code_block = !parse.nil?
+      end
+      
+      # Returns the code block indentation level.
+      #
+      #   Reflector.new("").level # => 0
+      #   Reflector.new("class Foo").level # => 1
+      #   Reflector.new("class Foo; def foo").level # => 2
+      #   Reflector.new("class Foo; def foo; end").level # => 1
+      #   Reflector.new("class Foo; def foo; end; end").level # => 0
+      attr_reader :level
+      
+      # Returns the actual syntax error message if one occurs.
+      attr_reader :syntax_error
+      
+      # Returns whether or not the source is a valid code block, but does not
+      # take syntax errors into account. In short, it's a valid code block if
+      # after parsing the level is at zero.
+      #
+      # For example, this is not a valid full code block:
+      #
+      #   def foo; p :ok
+      #
+      # This however is:
+      #
+      #   def foo; p :ok; end
+      def code_block?
+        @code_block
+      end
+      
+      # Returns whether or not the source contains a syntax error. However, it
+      # ignores a syntax error resulting in a code block not ending yet.
+      #
+      # For example, this contains a syntax error:
+      #
+      #   def; foo
+      #
+      # This does not:
+      #
+      #   def foo
+      def syntax_error?
+        !@syntax_error.nil?
+      end
+      
+      UNEXPECTED_END = "syntax error, unexpected $end"
+      
+      def on_parse_error(error) #:nodoc:
+        if code_block? || !error.start_with?(UNEXPECTED_END)
+          @syntax_error = error
+        end
+      end
+      
+      INCREASE_LEVEL_KEYWORDS = %w{ class module def begin if unless case while for do }
+      
+      def on_kw(token) #:nodoc:
+        case token
+        when *INCREASE_LEVEL_KEYWORDS
+          @level += 1
+        when "end"
+          @level -= 1
+        end
+        super
+      end
+      
+      def on_lbracket(token) #:nodoc:
+        @level += 1
+        super
+      end
+      
+      def on_rbracket(token) #:nodoc:
+        @level -= 1
+        super
+      end
+      
+      def on_embexpr_beg(token) #:nodoc:
+        @level += 1
+        super
+      end
+      
+      def on_lbrace(token) #:nodoc:
+        @level += 1
+        super
+      end
+      
+      def on_rbrace(token) #:nodoc:
+        @level -= 1
+        super
+      end
+    end
+  end
+end
\ No newline at end of file

Deleted: MacRuby/trunk/lib/irb/src_encoding.rb
===================================================================
--- MacRuby/trunk/lib/irb/src_encoding.rb	2010-05-02 05:58:51 UTC (rev 3998)
+++ MacRuby/trunk/lib/irb/src_encoding.rb	2010-05-02 11:40:15 UTC (rev 3999)
@@ -1,4 +0,0 @@
-# DO NOT WRITE ANY MAGIC COMMENT HERE.
-def default_src_encoding
-  return __ENCODING__
-end

Modified: MacRuby/trunk/lib/irb/version.rb
===================================================================
--- MacRuby/trunk/lib/irb/version.rb	2010-05-02 05:58:51 UTC (rev 3998)
+++ MacRuby/trunk/lib/irb/version.rb	2010-05-02 11:40:15 UTC (rev 3999)
@@ -1,15 +1,16 @@
+# MacRuby implementation of IRB.
 #
-#   irb/version.rb - irb version definition file
-#   	$Release Version: 0.9.5$
-#   	$Revision: 14912 $
-#   	by Keiju ISHITSUKA(keiju at ishitsuka.com)
-#
-# --
-#
-#   
-#
+# This file is covered by the Ruby license. See COPYING for more details.
+# 
+# Copyright (C) 2009-2010, Eloy Duran <eloy.de.enige at gmail.com>
 
 module IRB
-  @RELEASE_VERSION = "0.9.5"
-  @LAST_UPDATE_DATE = "05/04/13"
-end
+  module VERSION #:nodoc:
+    MAJOR = 0
+    MINOR = 4
+    TINY  = 2
+    
+    STRING = [MAJOR, MINOR, TINY].join('.')
+    DESCRIPTION = "#{STRING} (DietRB)"
+  end
+end
\ No newline at end of file

Deleted: MacRuby/trunk/lib/irb/workspace.rb
===================================================================
--- MacRuby/trunk/lib/irb/workspace.rb	2010-05-02 05:58:51 UTC (rev 3998)
+++ MacRuby/trunk/lib/irb/workspace.rb	2010-05-02 11:40:15 UTC (rev 3999)
@@ -1,108 +0,0 @@
-#
-#   irb/workspace-binding.rb - 
-#   	$Release Version: 0.9.5$
-#   	$Revision: 15689 $
-#   	by Keiju ISHITSUKA(keiju at ruby-lang.org)
-#
-# --
-#
-#   
-#
-module IRB
-  class WorkSpace
-    # create new workspace. set self to main if specified, otherwise
-    # inherit main from TOPLEVEL_BINDING.
-    def initialize(*main)
-      if main[0].kind_of?(Binding)
-	@binding = main.shift
-      elsif IRB.conf[:SINGLE_IRB]
-	@binding = TOPLEVEL_BINDING
-      else
-	case IRB.conf[:CONTEXT_MODE]
-	when 0	# binding in proc on TOPLEVEL_BINDING
-	  @binding = eval("proc{binding}.call",
-		      TOPLEVEL_BINDING, 
-		      __FILE__,
-		      __LINE__)
-	when 1	# binding in loaded file
-	  require "tempfile"
-	  f = Tempfile.open("irb-binding")
-	  f.print <<EOF
-	  $binding = binding
-EOF
-	  f.close
-	  load f.path
-	  @binding = $binding
-
-	when 2	# binding in loaded file(thread use)
-	  unless defined? BINDING_QUEUE
-	    require "thread"
-	    
-	    IRB.const_set("BINDING_QUEUE", SizedQueue.new(1))
-	    Thread.abort_on_exception = true
-	    Thread.start do
-	      eval "require \"irb/ws-for-case-2\"", TOPLEVEL_BINDING, __FILE__, __LINE__
-	    end
-	    Thread.pass
-	  end
-	  @binding = BINDING_QUEUE.pop
-
-	when 3	# binging in function on TOPLEVEL_BINDING(default)
-	  @binding = eval("def irb_binding; binding; end; irb_binding",
-		      TOPLEVEL_BINDING, 
-		      __FILE__,
-		      __LINE__ - 3)
-	end
-      end
-      if main.empty?
-	@main = eval("self", @binding)
-      else
-	@main = main[0]
-	IRB.conf[:__MAIN__] = @main
-	case @main
-	when Module
-	  @binding = eval("IRB.conf[:__MAIN__].module_eval('binding', __FILE__, __LINE__)", @binding, __FILE__, __LINE__)
-	else
-	  begin 
-	    @binding = eval("IRB.conf[:__MAIN__].instance_eval('binding', __FILE__, __LINE__)", @binding, __FILE__, __LINE__)
-	  rescue TypeError
-	    IRB.fail CantChangeBinding, @main.inspect
-	  end
-	end
-      end
-      eval("_=nil", @binding)
-    end
-
-    attr_reader :binding
-    attr_reader :main
-
-    def evaluate(context, statements, file = __FILE__, line = __LINE__)
-      eval(statements, @binding, file, line)
-    end
-  
-    # error message manipulator
-    def filter_backtrace(bt)
-      case IRB.conf[:CONTEXT_MODE]
-      when 0
-	return nil if bt =~ /\(irb_local_binding\)/
-      when 1
-	if(bt =~ %r!/tmp/irb-binding! or
-	   bt =~ %r!irb/.*\.rb! or
-	   bt =~ /irb\.rb/)
-	  return nil
-	end
-      when 2
-	return nil if bt =~ /irb\/.*\.rb/
-	return nil if bt =~ /irb\.rb/
-      when 3
-	return nil if bt =~ /irb\/.*\.rb/
-	return nil if bt =~ /irb\.rb/
-	bt.sub!(/:\s*in `irb_binding'/, '')
-      end
-      bt
-    end
-
-    def IRB.delete_caller
-    end
-  end
-end

Deleted: MacRuby/trunk/lib/irb/ws-for-case-2.rb
===================================================================
--- MacRuby/trunk/lib/irb/ws-for-case-2.rb	2010-05-02 05:58:51 UTC (rev 3998)
+++ MacRuby/trunk/lib/irb/ws-for-case-2.rb	2010-05-02 11:40:15 UTC (rev 3999)
@@ -1,14 +0,0 @@
-#
-#   irb/ws-for-case-2.rb - 
-#   	$Release Version: 0.9.5$
-#   	$Revision: 14912 $
-#   	by Keiju ISHITSUKA(keiju at ruby-lang.org)
-#
-# --
-#
-#   
-#
-
-while true
-  IRB::BINDING_QUEUE.push b = binding
-end

Deleted: MacRuby/trunk/lib/irb/xmp.rb
===================================================================
--- MacRuby/trunk/lib/irb/xmp.rb	2010-05-02 05:58:51 UTC (rev 3998)
+++ MacRuby/trunk/lib/irb/xmp.rb	2010-05-02 11:40:15 UTC (rev 3999)
@@ -1,97 +0,0 @@
-#
-#   xmp.rb - irb version of gotoken xmp
-#   	$Release Version: 0.9$
-#   	$Revision: 21633 $
-#   	by Keiju ISHITSUKA(Nippon Rational Inc.)
-#
-# --
-#
-#   
-#
-
-require "irb"
-require "irb/frame"
-
-class XMP
-  @RCS_ID='-$Id: xmp.rb 21633 2009-01-17 12:19:53Z yugui $-'
-
-  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
-    ws = IRB::WorkSpace.new(bind)
-    @io = StringInputMethod.new
-    @irb = IRB::Irb.new(ws, @io)
-    @irb.context.ignore_sigint = false
-
-#    IRB.conf[:IRB_RC].call(@irb.context) if IRB.conf[:IRB_RC]
-    IRB.conf[:MAIN_CONTEXT] = @irb.context
-  end
-
-  def puts(exps)
-    @io.puts exps
-
-    if @irb.context.ignore_sigint
-      begin
-	trap_proc_b = trap("SIGINT"){@irb.signal_handle}
-	catch(:IRB_EXIT) do
-	  @irb.eval_input
-	end
-      ensure
-	trap("SIGINT", trap_proc_b)
-      end
-    else
-      catch(:IRB_EXIT) do
-	@irb.eval_input
-      end
-    end
-  end
-
-  class StringInputMethod < IRB::InputMethod
-    def initialize
-      super
-      @exps = []
-    end
-
-    def eof?
-      @exps.empty?
-    end
-
-    def gets
-      while l = @exps.shift
-	next if /^\s+$/ =~ l
-	l.concat "\n"
-	print @prompt, l
-	break
-      end
-      l
-    end
-
-    def puts(exps)
-      if @encoding and exps.encoding != @encoding
-	enc = Encoding.compatible?(@exps.join("\n"), exps)
-	if enc.nil?
-	  raise Encoding::CompatibilityError, "Encoding in which the passed exression is encoded is not compatible to the preceding's one"
-	else
-	  @encoding = enc
-	end
-      else
-	@encoding = exps.encoding
-      end
-      @exps.concat exps.split(/\n/)
-    end
-
-    attr_reader :encoding
-  end
-end
-
-def xmp(exps, bind = nil)
-  bind = IRB::Frame.top(1) unless bind
-  xmp = XMP.new(bind)
-  xmp.puts exps
-  xmp
-end

Modified: MacRuby/trunk/lib/irb.rb
===================================================================
--- MacRuby/trunk/lib/irb.rb	2010-05-02 05:58:51 UTC (rev 3998)
+++ MacRuby/trunk/lib/irb.rb	2010-05-02 11:40:15 UTC (rev 3999)
@@ -1,347 +1,15 @@
+# MacRuby implementation of IRB.
 #
-#   irb.rb - irb main module
-#   	$Release Version: 0.9.5 $
-#   	$Revision: 20186 $
-#   	by Keiju ISHITSUKA(keiju at ruby-lang.org)
-#
-# --
-#
-#
-#
-require "e2mmap"
+# This file is covered by the Ruby license. See COPYING for more details.
+# 
+# Copyright (C) 2009-2010, Eloy Duran <eloy.de.enige at gmail.com>
 
-require "irb/init"
-require "irb/context"
-require "irb/extend-command"
-#require "irb/workspace"
+require 'irb/context'
+require 'irb/source'
+require 'irb/version'
 
-require "irb/ruby-lex"
-require "irb/input-method"
-require "irb/locale"
+require 'irb/ext/history'
 
-STDOUT.sync = true
-
-module IRB
-  @RCS_ID='-$Id: irb.rb 20186 2008-11-11 08:41:29Z yugui $-'
-
-  class Abort < Exception;end
-
-  #
-  @CONF = {}
-
-  def IRB.conf
-    @CONF
-  end
-
-  # IRB version method
-  def IRB.version
-    if v = @CONF[:VERSION] then return v end
-
-    require "irb/version"
-    rv = @RELEASE_VERSION.sub(/\.0/, "")
-    @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.setup(ap_path)
-
-    if @CONF[:SCRIPT]
-      irb = Irb.new(nil, @CONF[:SCRIPT])
-    else
-      irb = Irb.new
-    end
-
-    @CONF[:IRB_RC].call(irb.context) if @CONF[:IRB_RC]
-    @CONF[:MAIN_CONTEXT] = irb.context
-
-    trap("SIGINT") do
-      irb.signal_handle
-    end
-    
-    catch(:IRB_EXIT) do
-      irb.eval_input
-    end
-#    print "\n"
-  end
-
-  def IRB.irb_exit(irb, ret)
-    throw :IRB_EXIT, ret
-  end
-
-  def IRB.irb_abort(irb, exception = Abort)
-    if defined? Thread
-      irb.context.thread.raise exception, "abort then interrupt!!"
-    else
-      raise exception, "abort then interrupt!!"
-    end
-  end
-
-  #
-  # irb interpreter main routine 
-  #
-  class Irb
-    def initialize(workspace = nil, input_method = nil, output_method = nil)
-      @context = Context.new(self, workspace, input_method, output_method)
-      @context.main.extend ExtendCommandBundle
-      @signal_status = :IN_IRB
-
-      @scanner = RubyLex.new
-      @scanner.exception_on_syntax_error = false
-    end
-    attr_reader :context
-    attr_accessor :scanner
-
-    def eval_input
-      @scanner.set_prompt do
-	|ltype, indent, continue, line_no|
-	if ltype
-	  f = @context.prompt_s
-	elsif continue
-	  f = @context.prompt_c
-	elsif indent > 0
-	  f = @context.prompt_n
-	else
-	  f = @context.prompt_i
-	end
-	f = "" unless f
-	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)[/.*\z/].size +
-	      indent * 2 - p.size
-	    ind += 2 if continue
-	    @context.io.prompt = p + " " * ind if ind > 0
-	  end
-	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
-            line.untaint
-	    @context.evaluate(line, line_no)
-	    output_value if @context.echo?
-	    exc = nil
-	  rescue Interrupt => exc
-	  rescue SystemExit, SignalException
-	    raise
-	  rescue Exception => exc
-	  end
-	  if exc
-	    print exc.class, ": ", exc, "\n"
-	    exc.set_backtrace([]) if exc.backtrace.nil?
-	    if exc.backtrace[0] =~ /irb(2)?(\/.*|-.*|\.rb)?:/ && exc.class.to_s !~ /^IRB/ &&
-                !(SyntaxError === exc)
-	      irb_bug = true 
-	    else
-	      irb_bug = false
-	    end
-
-	    messages = []
-	    lasts = []
-	    levels = 0
-	    for m in exc.backtrace
-	      m = @context.workspace.filter_backtrace(m) unless irb_bug
-	      if m
-		if messages.size < @context.back_trace_limit
-		  messages.push "\tfrom "+m
-		else
-		  lasts.push "\tfrom "+m
-		  if lasts.size > @context.back_trace_limit
-		    lasts.shift 
-		    levels += 1
-		  end
-		end
-	      end
-	    end
-	    print messages.join("\n"), "\n"
-	    unless lasts.empty?
-	      printf "... %d levels...\n", levels if levels > 0
-	      print lasts.join("\n")
-	    end
-	    print "Maybe IRB bug!!\n" if irb_bug
-	  end
-          if $SAFE > 2
-            abort "Error: irb does not work for $SAFE level higher than 2"
-          end
-	end
-      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?
-	print "\nabort!!\n" if @context.verbose?
-	exit
-      end
-
-      case @signal_status
-      when :IN_INPUT
-	print "^C\n"
-	raise RubyLex::TerminateLineInput
-      when :IN_EVAL
-	IRB.irb_abort(self)
-      when :IN_LOAD
-	IRB.irb_abort(self, LoadAbort)
-      when :IN_IRB
-	# ignore
-      else
-	# ignore other cases as well
-      end
-    end
-
-    def signal_status(status)
-      return yield if @signal_status == :IN_LOAD
-
-      signal_status_back = @signal_status
-      @signal_status = status
-      begin
-	yield
-      ensure
-	@signal_status = signal_status_back
-      end
-    end
-
-    def prompt(prompt, ltype, indent, line_no)
-      p = prompt.dup
-      p.gsub!(/%([0-9]+)?([a-zA-Z])/) do
-	case $2
-	when "N"
-	  @context.irb_name
-	when "m"
-	  @context.main.to_s
-	when "M"
-	  @context.main.inspect
-	when "l"
-	  ltype
-	when "i"
-	  if $1 
-	    format("%" + $1 + "d", indent)
-	  else
-	    indent.to_s
-	  end
-	when "n"
-	  if $1 
-	    format("%" + $1 + "d", line_no)
-	  else
-	    line_no.to_s
-	  end
-	when "%"
-	  "%"
-	end
-      end
-      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
-	case (iv = iv.to_s)
-	when "@signal_status"
-	  ary.push format("%s=:%s", iv, @signal_status.id2name)
-	when "@context"
-	  ary.push format("%s=%s", iv, eval(iv).__to_s__)
-	else
-	  ary.push format("%s=%s", iv, eval(iv))
-	end
-      end
-      format("#<%s: %s>", self.class, ary.join(", "))
-    end
-  end
-
-  # Singleton method
-  def @CONF.inspect
-    IRB.version unless self[:VERSION]
-
-    array = []
-    for k, v in sort{|a1, a2| a1[0].id2name <=> a2[0].id2name}
-      case k
-      when :MAIN_CONTEXT, :__TMP__EHV__
-	array.push format("CONF[:%s]=...myself...", k.id2name)
-      when :PROMPT
-	s = v.collect{
-	  |kk, vv|
-	  ss = vv.collect{|kkk, vvv| ":#{kkk.id2name}=>#{vvv.inspect}"}
-	  format(":%s=>{%s}", kk.id2name, ss.join(", "))
-	}
-	array.push format("CONF[:%s]={%s}", k.id2name, s.join(", "))
-      else
-	array.push format("CONF[:%s]=%s", k.id2name, v.inspect)
-      end
-    end
-    array.join("\n")
-  end
+if !ENV['SPECCING'] && defined?(RUBY_ENGINE) && RUBY_ENGINE == "macruby"
+  require 'irb/ext/macruby'
 end
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/macruby-changes/attachments/20100502/07192eaa/attachment-0001.html>


More information about the macruby-changes mailing list