1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

* bin/irb lib/irb.rb lib/irb/...: IRB 0.9.5.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@8322 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
keiju 2005-04-13 15:27:09 +00:00
parent c56355fbdc
commit 622b522047
33 changed files with 464 additions and 337 deletions

View file

@ -1,3 +1,6 @@
Thu Apr 14 00:20:31 2005 Keiju Ishitsuka <keiju@ruby-lang.org>
* bin/irb lib/irb.rb lib/irb/...: IRB 0.9.5.
Wed Apr 13 23:40:21 2005 Kouhei Sutou <kou@cozmixng.org> Wed Apr 13 23:40:21 2005 Kouhei Sutou <kou@cozmixng.org>
* lib/rss/rss.rb (RSS::VERSION): 0.1.3 -> 0.1.4. * lib/rss/rss.rb (RSS::VERSION): 0.1.3 -> 0.1.4.

View file

@ -1,10 +1,10 @@
#!/usr/bin/env ruby #!/usr/bin/env ruby
# #
# irb.rb - intaractive ruby # irb.rb - intaractive ruby
# $Release Version: 0.7.3 $ # $Release Version: 0.9.5 $
# $Revision$ # $Revision$
# $Date$ # $Date$
# by Keiju ISHITSUKA(keiju@ishitsuka.com) # by Keiju ISHITSUKA(keiju@ruby-lang.org)
# #
require "irb" require "irb"

View file

@ -1,9 +1,9 @@
# #
# irb.rb - irb main module # irb.rb - irb main module
# $Release Version: 0.9 $ # $Release Version: 0.9.5 $
# $Revision$ # $Revision$
# $Date$ # $Date$
# by Keiju ISHITSUKA(keiju@ishitsuka.com) # by Keiju ISHITSUKA(keiju@ruby-lang.org)
# #
# -- # --
# #
@ -88,8 +88,8 @@ module IRB
# irb interpriter main routine # irb interpriter main routine
# #
class Irb class Irb
def initialize(workspace = nil, input_method = nil) def initialize(workspace = nil, input_method = nil, output_method = nil)
@context = Context.new(self, workspace, input_method) @context = Context.new(self, workspace, input_method, output_method)
@context.main.extend ExtendCommandBundle @context.main.extend ExtendCommandBundle
@signal_status = :IN_IRB @signal_status = :IN_IRB
@ -106,6 +106,8 @@ module IRB
f = @context.prompt_s f = @context.prompt_s
elsif continue elsif continue
f = @context.prompt_c f = @context.prompt_c
elsif indent > 0
f = @context.prompt_n
else @context.prompt_i else @context.prompt_i
f = @context.prompt_i f = @context.prompt_i
end end

View file

@ -1,9 +1,9 @@
# #
# change-ws.rb - # change-ws.rb -
# $Release Version: 0.9$ # $Release Version: 0.9.5$
# $Revision$ # $Revision$
# $Date$ # $Date$
# by Keiju ISHITSUKA(Nihon Rational Software Co.,Ltd) # by Keiju ISHITSUKA(keiju@ruby-lang.org)
# #
# -- # --
# #

View file

@ -1,9 +1,23 @@
#
# fork.rb -
# $Release Version: 0.9.5 $
# $Revision$
# $Date$
# by Keiju ISHITSUKA(keiju@ruby-lang.org)
#
# --
#
#
#
@RCS_ID='-$Id$-'
module IRB module IRB
module ExtendCommand module ExtendCommand
class Fork<Nop class Fork<Nop
def execute(&block) def execute(&block)
pid = send(ExtendCommand.irb_original_method_name("fork")) pid = send ExtendCommand.irb_original_method_name("fork")
unless pid unless pid
class<<self class<<self
alias_method :exit, ExtendCommand.irb_original_method_name('exit') alias_method :exit, ExtendCommand.irb_original_method_name('exit')

View file

@ -1,9 +1,9 @@
# #
# load.rb - # load.rb -
# $Release Version: 0.9$ # $Release Version: 0.9.5$
# $Revision$ # $Revision$
# $Date$ # $Date$
# by Keiju ISHITSUKA(Nihon Rational Software Co.,Ltd) # by Keiju ISHITSUKA(keiju@ruby-lang.org)
# #
# -- # --
# #

View file

@ -1,9 +1,9 @@
# #
# nop.rb - # nop.rb -
# $Release Version: 0.9$ # $Release Version: 0.9.5$
# $Revision$ # $Revision$
# $Date$ # $Date$
# by Keiju ISHITSUKA(Nihon Rational Software Co.,Ltd) # by Keiju ISHITSUKA(keiju@ruby-lang.org)
# #
# -- # --
# #

View file

@ -1,9 +1,9 @@
# #
# change-ws.rb - # change-ws.rb -
# $Release Version: 0.9$ # $Release Version: 0.9.5$
# $Revision$ # $Revision$
# $Date$ # $Date$
# by Keiju ISHITSUKA(Nihon Rational Software Co.,Ltd) # by Keiju ISHITSUKA(keiju@ruby-lang.org)
# #
# -- # --
# #

View file

@ -1,10 +1,10 @@
#!/usr/local/bin/ruby #!/usr/local/bin/ruby
# #
# multi.rb - # multi.rb -
# $Release Version: 0.9$ # $Release Version: 0.9.5$
# $Revision$ # $Revision$
# $Date$ # $Date$
# by Keiju ISHITSUKA(Nihon Rational Software Co.,Ltd) # by Keiju ISHITSUKA(keiju@ruby-lang.org)
# #
# -- # --
# #

View file

@ -1,9 +1,9 @@
# #
# irb/context.rb - irb context # irb/context.rb - irb context
# $Release Version: 0.9$ # $Release Version: 0.9.5$
# $Revision$ # $Revision$
# $Date$ # $Date$
# by Keiju ISHITSUKA(keiju@ishitsuka.com) # by Keiju ISHITSUKA(keiju@ruby-lang.org)
# #
# -- # --
# #
@ -19,7 +19,7 @@ module IRB
# String -- File # String -- File
# other -- using this as InputMethod # other -- using this as InputMethod
# #
def initialize(irb, workspace = nil, input_method = nil) def initialize(irb, workspace = nil, input_method = nil, output_method = nil)
@irb = irb @irb = irb
if workspace if workspace
@workspace = workspace @workspace = workspace
@ -71,6 +71,13 @@ module IRB
else else
@io = input_method @io = input_method
end 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] @verbose = IRB.conf[:VERBOSE]
@echo = IRB.conf[:ECHO] @echo = IRB.conf[:ECHO]
@ -96,13 +103,14 @@ module IRB
attr_accessor :irb_name attr_accessor :irb_name
attr_accessor :irb_path attr_accessor :irb_path
attr_accessor :use_readline attr_reader :use_readline
attr_reader :inspect_mode attr_reader :inspect_mode
attr_reader :prompt_mode attr_reader :prompt_mode
attr_accessor :prompt_i attr_accessor :prompt_i
attr_accessor :prompt_s attr_accessor :prompt_s
attr_accessor :prompt_c attr_accessor :prompt_c
attr_accessor :prompt_n
attr_accessor :auto_indent_mode attr_accessor :auto_indent_mode
attr_accessor :return_format attr_accessor :return_format
@ -141,6 +149,7 @@ module IRB
def set_last_value(value) def set_last_value(value)
@last_value = value @last_value = value
@workspace.evaluate self, "_ = IRB.CurrentContext.last_value"
end end
attr_reader :irb_name attr_reader :irb_name
@ -151,6 +160,7 @@ module IRB
@prompt_i = pconf[:PROMPT_I] @prompt_i = pconf[:PROMPT_I]
@prompt_s = pconf[:PROMPT_S] @prompt_s = pconf[:PROMPT_S]
@prompt_c = pconf[:PROMPT_C] @prompt_c = pconf[:PROMPT_C]
@prompt_n = pconf[:PROMPT_N]
@return_format = pconf[:RETURN] @return_format = pconf[:RETURN]
if ai = pconf.include?(:AUTO_INDENT) if ai = pconf.include?(:AUTO_INDENT)
@auto_indent_mode = ai @auto_indent_mode = ai
@ -177,7 +187,6 @@ module IRB
@inspect_mode @inspect_mode
end end
undef use_readline=
def use_readline=(opt) def use_readline=(opt)
@use_readline = opt @use_readline = opt
print "use readline module\n" if @use_readline print "use readline module\n" if @use_readline

View file

@ -1,9 +1,9 @@
# #
# irb/ext/cb.rb - # irb/ext/cb.rb -
# $Release Version: 0.9$ # $Release Version: 0.9.5$
# $Revision$ # $Revision$
# $Date$ # $Date$
# by Keiju ISHITSUKA(Nihon Rational Software Co.,Ltd) # by Keiju ISHITSUKA(keiju@ruby-lang.org)
# #
# -- # --
# #

View file

@ -1,9 +1,9 @@
# #
# history.rb - # history.rb -
# $Release Version: 0.9$ # $Release Version: 0.9.5$
# $Revision$ # $Revision$
# $Date$ # $Date$
# by Keiju ISHITSUKA(Nihon Rational Software Co.,Ltd) # by Keiju ISHITSUKA(keiju@ruby-lang.org)
# #
# -- # --
# #
@ -21,8 +21,8 @@ module IRB
def set_last_value(value) def set_last_value(value)
_set_last_value(value) _set_last_value(value)
@workspace.evaluate self, "_ = IRB.CurrentContext.last_value" # @workspace.evaluate self, "_ = IRB.CurrentContext.last_value"
if (@eval_history ||= nil) #and !@eval_history_values.equal?(llv) if @eval_history #and !@eval_history_values.equal?(llv)
@eval_history_values.push @line_no, @last_value @eval_history_values.push @line_no, @last_value
@workspace.evaluate self, "__ = IRB.CurrentContext.instance_eval{@eval_history_values}" @workspace.evaluate self, "__ = IRB.CurrentContext.instance_eval{@eval_history_values}"
end end
@ -33,7 +33,7 @@ module IRB
attr_reader :eval_history attr_reader :eval_history
def eval_history=(no) def eval_history=(no)
if no if no
if (@eval_history ||= nil) if @eval_history
@eval_history_values.size(no) @eval_history_values.size(no)
else else
@eval_history_values = History.new(no) @eval_history_values = History.new(no)

View file

@ -1,3 +1,18 @@
#
# loader.rb -
# $Release Version: 0.9.5$
# $Revision$
# $Date$
# by Keiju ISHITSUKA(keiju@ruby-lang.org)
#
# --
#
#
#
@RCS_ID='-$Id$-'
module IRB module IRB
class LoadAbort < Exception;end class LoadAbort < Exception;end

View file

@ -1,9 +1,9 @@
# #
# math-mode.rb - # math-mode.rb -
# $Release Version: 0.9$ # $Release Version: 0.9.5$
# $Revision$ # $Revision$
# $Date$ # $Date$
# by Keiju ISHITSUKA(Nihon Rational Software Co.,Ltd) # by Keiju ISHITSUKA(keiju@ruby-lang.org)
# #
# -- # --
# #

View file

@ -1,9 +1,9 @@
# #
# irb/multi-irb.rb - multiple irb module # irb/multi-irb.rb - multiple irb module
# $Release Version: 0.9$ # $Release Version: 0.9.5$
# $Revision$ # $Revision$
# $Date$ # $Date$
# by Keiju ISHITSUKA(keiju@ishitsuka.com) # by Keiju ISHITSUKA(keiju@ruby-lang.org)
# #
# -- # --
# #

View file

@ -1,9 +1,9 @@
# #
# irb/lib/tracer.rb - # irb/lib/tracer.rb -
# $Release Version: 0.9$ # $Release Version: 0.9.5$
# $Revision$ # $Revision$
# $Date$ # $Date$
# by Keiju ISHITSUKA(Nihon Rational Software Co.,Ltd) # by Keiju ISHITSUKA(keiju@ruby-lang.org)
# #
# -- # --
# #

View file

@ -1,9 +1,9 @@
# #
# use-loader.rb - # use-loader.rb -
# $Release Version: 0.9$ # $Release Version: 0.9.5$
# $Revision$ # $Revision$
# $Date$ # $Date$
# by Keiju ISHITSUKA(Nihon Rational Software Co.,Ltd) # by Keiju ISHITSUKA(keiju@ruby-lang.org)
# #
# -- # --
# #

View file

@ -1,9 +1,9 @@
# #
# push-ws.rb - # push-ws.rb -
# $Release Version: 0.9$ # $Release Version: 0.9.5$
# $Revision$ # $Revision$
# $Date$ # $Date$
# by Keiju ISHITSUKA(Nihon Rational Software Co.,Ltd) # by Keiju ISHITSUKA(keiju@ruby-lang.org)
# #
# -- # --
# #

View file

@ -1,9 +1,9 @@
# #
# irb/extend-command.rb - irb command extend # irb/extend-command.rb - irb extend command
# $Release Version: 0.9$ # $Release Version: 0.9.5$
# $Revision$ # $Revision$
# $Date$ # $Date$
# by Keiju ISHITSUKA(keiju@ishitsuka.com) # by Keiju ISHITSUKA(keiju@ruby-lang.org)
# #
# -- # --
# #
@ -103,6 +103,7 @@ module IRB
[:irb_help, :Help, "irb/cmd/help", [:irb_help, :Help, "irb/cmd/help",
[:help, NO_OVERRIDE]], [:help, NO_OVERRIDE]],
] ]
def EXCB.install_extend_commands def EXCB.install_extend_commands
@ -192,6 +193,7 @@ module IRB
[:use_tracer=, "irb/ext/tracer.rb"], [:use_tracer=, "irb/ext/tracer.rb"],
[:math_mode=, "irb/ext/math-mode.rb"], [:math_mode=, "irb/ext/math-mode.rb"],
[:use_loader=, "irb/ext/use-loader.rb"], [:use_loader=, "irb/ext/use-loader.rb"],
[:save_history=, "irb/ext/save-history.rb"],
] ]
def CE.install_extend_commands def CE.install_extend_commands
@ -215,5 +217,48 @@ module IRB
CE.install_extend_commands CE.install_extend_commands
end 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 end

View file

@ -1,6 +1,6 @@
# #
# irb/help.rb - print usase module # irb/help.rb - print usase module
# $Release Version: 0.9$ # $Release Version: 0.9.5$
# $Revision$ # $Revision$
# $Date$ # $Date$
# by Keiju ISHITSUKA(keiju@ishitsuka.com) # by Keiju ISHITSUKA(keiju@ishitsuka.com)

View file

@ -1,9 +1,9 @@
# #
# irb/init.rb - irb initialize module # irb/init.rb - irb initialize module
# $Release Version: 0.9$ # $Release Version: 0.9.5$
# $Revision$ # $Revision$
# $Date$ # $Date$
# by Keiju ISHITSUKA(keiju@ishitsuka.com) # by Keiju ISHITSUKA(keiju@ruby-lang.org)
# #
# -- # --
# #
@ -54,36 +54,43 @@ module IRB
@CONF[:VERBOSE] = nil @CONF[:VERBOSE] = nil
@CONF[:EVAL_HISTORY] = nil @CONF[:EVAL_HISTORY] = nil
@CONF[:SAVE_HISTORY] = nil
@CONF[:BACK_TRACE_LIMIT] = 16 @CONF[:BACK_TRACE_LIMIT] = 16
@CONF[:PROMPT] = { @CONF[:PROMPT] = {
:NULL => { :NULL => {
:PROMPT_I => nil, :PROMPT_I => nil,
:PROMPT_N => nil,
:PROMPT_S => nil, :PROMPT_S => nil,
:PROMPT_C => nil, :PROMPT_C => nil,
:RETURN => "%s\n" :RETURN => "%s\n"
}, },
:DEFAULT => { :DEFAULT => {
:PROMPT_I => "%N(%m):%03n:%i> ", :PROMPT_I => "%N(%m):%03n:%i> ",
:PROMPT_N => "%N(%m):%03n:%i> ",
:PROMPT_S => "%N(%m):%03n:%i%l ", :PROMPT_S => "%N(%m):%03n:%i%l ",
:PROMPT_C => "%N(%m):%03n:%i* ", :PROMPT_C => "%N(%m):%03n:%i* ",
:RETURN => "=> %s\n" :RETURN => "=> %s\n"
}, },
:CLASSIC => { :CLASSIC => {
:PROMPT_I => "%N(%m):%03n:%i> ", :PROMPT_I => "%N(%m):%03n:%i> ",
:PROMPT_N => "%N(%m):%03n:%i> ",
:PROMPT_S => "%N(%m):%03n:%i%l ", :PROMPT_S => "%N(%m):%03n:%i%l ",
:PROMPT_C => "%N(%m):%03n:%i* ", :PROMPT_C => "%N(%m):%03n:%i* ",
:RETURN => "%s\n" :RETURN => "%s\n"
}, },
:SIMPLE => { :SIMPLE => {
:PROMPT_I => ">> ", :PROMPT_I => ">> ",
:PROMPT_N => ">> ",
:PROMPT_S => nil, :PROMPT_S => nil,
:PROMPT_C => "?> ", :PROMPT_C => "?> ",
:RETURN => "=> %s\n" :RETURN => "=> %s\n"
}, },
:INF_RUBY => { :INF_RUBY => {
:PROMPT_I => "%N(%m):%03n:%i> ", :PROMPT_I => "%N(%m):%03n:%i> ",
# :PROMPT_N => "%N(%m):%03n:%i> ",
:PROMPT_N => nil,
:PROMPT_S => nil, :PROMPT_S => nil,
:PROMPT_C => nil, :PROMPT_C => nil,
:RETURN => "%s\n", :RETURN => "%s\n",
@ -91,6 +98,7 @@ module IRB
}, },
:XMP => { :XMP => {
:PROMPT_I => nil, :PROMPT_I => nil,
:PROMPT_N => nil,
:PROMPT_S => nil, :PROMPT_S => nil,
:PROMPT_C => nil, :PROMPT_C => nil,
:RETURN => " ==>%s\n" :RETURN => " ==>%s\n"
@ -183,36 +191,47 @@ module IRB
end end
end end
# enumerate possible rc files
def IRB.rc_files(rc)
yield File.expand_path("~/.irb#{rc}") if ENV.key?("HOME")
yield ".irb#{rc}"
yield "irb#{rc.sub(/\A_?/, '.')}"
yield "_irb#{rc}"
yield "$irb#{rc}"
end
# running config # running config
def IRB.run_config def IRB.run_config
if @CONF[:RC] if @CONF[:RC]
catch(:EXIT) do
rc_files("rc") do |rc|
begin begin
load rc load rc_file
throw :EXIT
rescue LoadError, Errno::ENOENT rescue LoadError, Errno::ENOENT
rescue rescue
print "load error: #{rc}\n" print "load error: #{rc_file}\n"
print $!.class, ": ", $!, "\n" print $!.class, ": ", $!, "\n"
for err in $@[0, $@.size - 2] for err in $@[0, $@.size - 2]
print "\t", err, "\n" print "\t", err, "\n"
end end
throw :EXIT
end end
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 end
end
@CONF[:RC_NAME_GENERATOR].call ext
end
# enumerate possible rc-file base name generators
def IRB.rc_file_generators
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}"}
end
# loading modules # loading modules
def IRB.load_modules def IRB.load_modules

View file

@ -1,9 +1,9 @@
# #
# irb/input-method.rb - input methods using irb # irb/input-method.rb - input methods used irb
# $Release Version: 0.9$ # $Release Version: 0.9.5$
# $Revision$ # $Revision$
# $Date$ # $Date$
# by Keiju ISHITSUKA(keiju@ishitsuka.com) # by Keiju ISHITSUKA(keiju@ruby-lang.org)
# #
# -- # --
# #
@ -85,49 +85,12 @@ module IRB
require "readline" require "readline"
class ReadlineInputMethod < InputMethod class ReadlineInputMethod < InputMethod
include Readline include Readline
def ReadlineInputMethod.create_finalizer(hist, file)
proc do
if num = IRB.conf[:SAVE_HISTORY] and (num = num.to_i) > 0
if hf = IRB.conf[:HISTORY_FILE]
file = File.expand_path(hf)
end
if file
open(file, 'w' ) do |f|
hist = hist.to_a
f.puts(hist[-num..-1] || hist)
end
end
end
end
end
def initialize def initialize
super super
@line_no = 0 @line_no = 0
@line = [] @line = []
@eof = false @eof = false
loader = proc {|f| f.each {|l| HISTORY << l.chomp}}
if hist = IRB.conf[:HISTORY_FILE]
hist = File.expand_path(hist)
begin
open(hist, &loader)
rescue
end
else
IRB.rc_files("_history") do |hist|
begin
open(hist, &loader)
rescue
hist = nil
else
break
end
end
end
ObjectSpace.define_finalizer(self, ReadlineInputMethod.create_finalizer(HISTORY, hist))
end end
def gets def gets

View file

@ -1,9 +1,9 @@
# #
# irb/lc/error.rb - # irb/lc/error.rb -
# $Release Version: 0.9$ # $Release Version: 0.9.5$
# $Revision$ # $Revision$
# $Date$ # $Date$
# by Keiju ISHITSUKA(keiju@ishitsuka.com) # by Keiju ISHITSUKA(keiju@ruby-lang.org)
# #
# -- # --
# #

View file

@ -1,9 +1,9 @@
# #
# irb/lc/help-message.rb - # irb/lc/help-message.rb -
# $Release Version: 0.9$ # $Release Version: 0.9.5$
# $Revision$ # $Revision$
# $Date$ # $Date$
# by Keiju ISHITSUKA(keiju@ishitsuka.com) # by Keiju ISHITSUKA(keiju@ruby-lang.org)
# #
# -- # --
# #

View file

@ -1,9 +1,9 @@
# #
# irb/lc/ja/error.rb - # irb/lc/ja/error.rb -
# $Release Version: 0.9$ # $Release Version: 0.9.5$
# $Revision$ # $Revision$
# $Date$ # $Date$
# by Keiju ISHITSUKA(keiju@ishitsuka.com) # by Keiju ISHITSUKA(keiju@ruby-lang.org)
# #
# -- # --
# #
@ -25,5 +25,3 @@ module IRB
def_exception :CantChangeBinding, '$B%P%$%s%G%#%s%0(B(%s)$B$KJQ99$G$-$^$;$s(B.' def_exception :CantChangeBinding, '$B%P%$%s%G%#%s%0(B(%s)$B$KJQ99$G$-$^$;$s(B.'
def_exception :UndefinedPromptMode, '$B%W%m%s%W%H%b!<%I(B(%s)$B$ODj5A$5$l$F$$$^$;$s(B.' def_exception :UndefinedPromptMode, '$B%W%m%s%W%H%b!<%I(B(%s)$B$ODj5A$5$l$F$$$^$;$s(B.'
end end

View file

@ -1,9 +1,9 @@
# #
# irb/lc/ja/help-message.rb - # irb/lc/ja/help-message.rb -
# $Release Version: 0.9$ # $Release Version: 0.9.5$
# $Revision$ # $Revision$
# $Date$ # $Date$
# by Keiju ISHITSUKA(keiju@ishitsuka.com) # by Keiju ISHITSUKA(keiju@ruby-lang.org)
# #
# -- # --
# #

View file

@ -1,9 +1,9 @@
# #
# irb/locale.rb - internationalization module # irb/locale.rb - internationalization module
# $Release Version: 0.9$ # $Release Version: 0.9.5$
# $Revision$ # $Revision$
# $Date$ # $Date$
# by Keiju ISHITSUKA(keiju@ishitsuka.com) # by Keiju ISHITSUKA(keiju@ruby-lang.org)
# #
# -- # --
# #

View file

@ -1,9 +1,9 @@
# #
# irb/ruby-lex.rb - ruby lexcal analizer # irb/ruby-lex.rb - ruby lexcal analizer
# $Release Version: 0.9$ # $Release Version: 0.9.5$
# $Revision$ # $Revision$
# $Date$ # $Date$
# by Keiju ISHITSUKA(keiju@ishitsuka.com) # by Keiju ISHITSUKA(keiju@ruby-lang.org)
# #
# -- # --
# #
@ -51,13 +51,18 @@ class RubyLex
@indent = 0 @indent = 0
@indent_stack = [] @indent_stack = []
@lex_state = EXPR_BEG
@space_seen = false
@here_header = false
@continue = false
@line = ""
@skip_space = false @skip_space = false
@readed_auto_clean_up = false @readed_auto_clean_up = false
@exception_on_syntax_error = true @exception_on_syntax_error = true
@prompt = nil @prompt = nil
@here_header = nil
@lex_state = nil
end end
attr_accessor :skip_space attr_accessor :skip_space
@ -119,6 +124,7 @@ class RubyLex
l.concat c l.concat c
break if c == "\n" break if c == "\n"
end end
return nil if l == "" and c.nil?
l l
end end
@ -280,7 +286,7 @@ class RubyLex
tk = @OP.match(self) tk = @OP.match(self)
@space_seen = tk.kind_of?(TkSPACE) @space_seen = tk.kind_of?(TkSPACE)
rescue SyntaxError rescue SyntaxError
abort if @exception_on_syntax_error raise if @exception_on_syntax_error
tk = TkError.new(@seek, @line_no, @char_no) tk = TkError.new(@seek, @line_no, @char_no)
end end
end while @skip_space and tk.kind_of?(TkSPACE) end while @skip_space and tk.kind_of?(TkSPACE)
@ -330,7 +336,7 @@ class RubyLex
} }
def lex_init() def lex_init()
@OP = SLex.new @OP = IRB::SLex.new
@OP.def_rules("\0", "\004", "\032") do @OP.def_rules("\0", "\004", "\032") do
Token(TkEND_OF_SCRIPT) Token(TkEND_OF_SCRIPT)
end end
@ -429,6 +435,7 @@ class RubyLex
@OP.def_rules("`") do @OP.def_rules("`") do
|op, io| |op, io|
if @lex_state == EXPR_FNAME if @lex_state == EXPR_FNAME
@lex_state = EXPR_END
Token(op) Token(op)
else else
identify_string(op) identify_string(op)
@ -472,11 +479,13 @@ class RubyLex
@OP.def_rule("+@", proc{@lex_state == EXPR_FNAME}) do @OP.def_rule("+@", proc{@lex_state == EXPR_FNAME}) do
|op, io| |op, io|
@lex_state = EXPR_ARG
Token(op) Token(op)
end end
@OP.def_rule("-@", proc{@lex_state == EXPR_FNAME}) do @OP.def_rule("-@", proc{@lex_state == EXPR_FNAME}) do
|op, io| |op, io|
@lex_state = EXPR_ARG
Token(op) Token(op)
end end
@ -616,10 +625,12 @@ class RubyLex
end end
@OP.def_rule("[]", proc{@lex_state == EXPR_FNAME}) do @OP.def_rule("[]", proc{@lex_state == EXPR_FNAME}) do
@lex_state = EXPR_ARG
Token("[]") Token("[]")
end end
@OP.def_rule("[]=", proc{@lex_state == EXPR_FNAME}) do @OP.def_rule("[]=", proc{@lex_state == EXPR_FNAME}) do
@lex_state = EXPR_ARG
Token("[]=") Token("[]=")
end end
@ -790,14 +801,13 @@ class RubyLex
else else
if @lex_state != EXPR_FNAME if @lex_state != EXPR_FNAME
if ENINDENT_CLAUSE.include?(token) if ENINDENT_CLAUSE.include?(token)
# check for ``class = val''. # check for ``class = val'' etc.
valid = true valid = true
case token case token
when "class" when "class"
valid = false unless peek_match?(/^\s*(<<|\w|::)/) valid = false unless peek_match?(/^\s*(<<|\w|::)/)
when "def" when "def"
valid = false if peek_match?(/^\s*(([+-\/*&\|^]|<<|>>|\|\||\&\&)=|\&\&|\|\|)/) valid = false if peek_match?(/^\s*(([+-\/*&\|^]|<<|>>|\|\||\&\&)=|\&\&|\|\|)/)
# valid = false if peek_match?(/^\s*(([+-\/*&\|^]|<<|>>|\|\||\&\&)?=|\&\&|\|\|)/)
when "do" when "do"
valid = false if peek_match?(/^\s*([+-\/*]?=|\*|<|>|\&)/) valid = false if peek_match?(/^\s*([+-\/*]?=|\*|<|>|\&)/)
when *ENINDENT_CLAUSE when *ENINDENT_CLAUSE
@ -885,7 +895,11 @@ class RubyLex
end end
@here_header = false @here_header = false
while (l = gets.chomp) && (indent ? l.strip : l) != quoted while l = gets
l = l.sub(/(:?\r)?\n\z/, '')
if (indent ? l.strip : l) == quoted
break
end
end end
@here_header = true @here_header = true
@ -920,19 +934,43 @@ class RubyLex
def identify_number def identify_number
@lex_state = EXPR_END @lex_state = EXPR_END
if ch = getc if peek(0) == "0" && peek(1) !~ /[.eE]/
getc
if /[xX]/ =~ peek(0) if /[xX]/ =~ peek(0)
ch = getc ch = getc
match = /[0-9a-fA-F_]/ match = /[0-9a-fA-F_]/
elsif /[bB]/ =~ peek(0) elsif /[bB]/ =~ peek(0)
ch = getc ch = getc
match = /[01_]/ match = /[01_]/
elsif /[oO]/ =~ peek(0)
ch = getc
match = /[0-7_]/
else else
match = /[0-7_]/ match = /[0-7_]/
end end
len0 = true
non_digit = false
while ch = getc while ch = getc
if ch !~ match 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 ungetc
if len0
RubyLex.fail SyntaxError, "numeric literal without digits"
end
if non_digit
RubyLex.fail SyntaxError, "trailing `#{non_digit}' in number"
end
break break
end end
end end
@ -942,24 +980,39 @@ class RubyLex
type = TkINTEGER type = TkINTEGER
allow_point = true allow_point = true
allow_e = true allow_e = true
non_digit = false
while ch = getc while ch = getc
case ch case ch
when /[0-9_]/ when /[0-9]/
non_digit = false
when "_"
non_digit = ch
when allow_point && "." when allow_point && "."
if non_digit
RubyLex.fail SyntaxError, "trailing `#{non_digit}' in number"
end
type = TkFLOAT type = TkFLOAT
if peek(0) !~ /[0-9]/ if peek(0) !~ /[0-9]/
type = TkINTEGER
ungetc ungetc
break break
end end
allow_point = false allow_point = false
when allow_e && "e", allow_e && "E" when allow_e && "e", allow_e && "E"
if non_digit
RubyLex.fail SyntaxError, "trailing `#{non_digit}' in number"
end
type = TkFLOAT type = TkFLOAT
if peek(0) =~ /[+-]/ if peek(0) =~ /[+-]/
getc getc
end end
allow_e = false allow_e = false
allow_point = false allow_point = false
non_digit = ch
else else
if non_digit
RubyLex.fail SyntaxError, "trailing `#{non_digit}' in number"
end
ungetc ungetc
break break
end end

View file

@ -1,9 +1,9 @@
# #
# irb/ruby-token.rb - ruby tokens # irb/ruby-token.rb - ruby tokens
# $Release Version: 0.9$ # $Release Version: 0.9.5$
# $Revision$ # $Revision$
# $Date$ # $Date$
# by Keiju ISHITSUKA(keiju@ishitsuka.com) # by Keiju ISHITSUKA(keiju@ruby-lang.org)
# #
# -- # --
# #
@ -64,7 +64,7 @@ module RubyToken
class TkOPASGN < TkOp class TkOPASGN < TkOp
def initialize(seek, line_no, char_no, op) def initialize(seek, line_no, char_no, op)
super(seek, line_no, char_no) super(seek, line_no, char_no)
op = TkReading2Token[op] unless op.kind_of?(Symbol) op = TkReading2Token[op][0] unless op.kind_of?(Symbol)
@op = op @op = op
end end
attr :op attr :op

View file

@ -1,9 +1,9 @@
# #
# irb/slex.rb - symple lex analizer # irb/slex.rb - symple lex analizer
# $Release Version: 0.9$ # $Release Version: 0.9.5$
# $Revision$ # $Revision$
# $Date$ # $Date$
# by Keiju ISHITSUKA(keiju@ishituska.com) # by Keiju ISHITSUKA(keiju@ruby-lang.org)
# #
# -- # --
# #
@ -11,7 +11,9 @@
# #
require "e2mmap" require "e2mmap"
require "irb/notifier"
module IRB
class SLex class SLex
@RCS_ID='-$Id$-' @RCS_ID='-$Id$-'
@ -19,20 +21,20 @@ class SLex
def_exception :ErrNodeNothing, "node nothing" def_exception :ErrNodeNothing, "node nothing"
def_exception :ErrNodeAlreadyExists, "node already exists" def_exception :ErrNodeAlreadyExists, "node already exists"
class << self DOUT = Notifier::def_notifier("SLex::")
attr_accessor :debug_level D_WARN = DOUT::def_notifier(1, "Warn: ")
def debug? D_DEBUG = DOUT::def_notifier(2, "Debug: ")
debug_level > 0 D_DETAIL = DOUT::def_notifier(4, "Detail: ")
end
end DOUT.level = Notifier::D_NOMSG
@debug_level = 0
def initialize def initialize
@head = Node.new("") @head = Node.new("")
end end
def def_rule(token, preproc = nil, postproc = nil, &block) def def_rule(token, preproc = nil, postproc = nil, &block)
# print node.inspect, "\n" if SLex.debug? D_DETAIL.pp token
postproc = block if block_given? postproc = block if block_given?
node = create(token, preproc, postproc) node = create(token, preproc, postproc)
end end
@ -51,6 +53,7 @@ class SLex
node.preproc=proc node.preproc=proc
end end
#$BMW%A%'%C%/(B?
def postproc(token) def postproc(token)
node = search(token, proc) node = search(token, proc)
node.postproc=proc node.postproc=proc
@ -73,7 +76,7 @@ class SLex
return @head.match_io(token) return @head.match_io(token)
end end
ret = @head.match(token) ret = @head.match(token)
printf "match end: %s:%s", ret, token.inspect if SLex.debug? D_DETAIL.exec_if{D_DEATIL.printf "match end: %s:%s\n", ret, token.inspect}
ret ret
end end
@ -116,9 +119,10 @@ class SLex
def create_subnode(chrs, preproc = nil, postproc = nil) def create_subnode(chrs, preproc = nil, postproc = nil)
if chrs.empty? if chrs.empty?
if @postproc if @postproc
D_DETAIL.pp node
SLex.fail ErrNodeAlreadyExists SLex.fail ErrNodeAlreadyExists
else else
print "Warn: change abstract node to real node\n" if SLex.debug? D_DEBUG.puts "change abstract node to real node."
@preproc = preproc @preproc = preproc
@postproc = postproc @postproc = postproc
end end
@ -129,13 +133,13 @@ class SLex
if node = @Tree[ch] if node = @Tree[ch]
if chrs.empty? if chrs.empty?
if node.postproc if node.postproc
p node DebugLogger.pp node
p self DebugLogger.pp self
p ch DebugLogger.pp ch
p chrs DebugLogger.pp chrs
SLex.fail ErrNodeAlreadyExists SLex.fail ErrNodeAlreadyExists
else else
print "Warn: change abstract node to real node\n" if SLex.debug? D_WARN.puts "change abstract node to real node"
node.preproc = preproc node.preproc = preproc
node.postproc = postproc node.postproc = postproc
end end
@ -161,10 +165,10 @@ class SLex
# able to be called arbitrary number of times. # able to be called arbitrary number of times.
# #
def match(chrs, op = "") def match(chrs, op = "")
print "match>: ", chrs, "op:", op, "\n" if SLex.debug? D_DETAIL.print "match>: ", chrs, "op:", op, "\n"
if chrs.empty? if chrs.empty?
if @preproc.nil? || @preproc.call(op, chrs) if @preproc.nil? || @preproc.call(op, chrs)
printf "op1: %s\n", op if SLex.debug? DOUT.printf(D_DETAIL, "op1: %s\n", op)
@postproc.call(op, chrs) @postproc.call(op, chrs)
else else
nil nil
@ -177,7 +181,7 @@ class SLex
else else
chrs.unshift ch chrs.unshift ch
if @postproc and @preproc.nil? || @preproc.call(op, chrs) if @postproc and @preproc.nil? || @preproc.call(op, chrs)
printf "op2: %s\n", op.inspect if SLex.debug? DOUT.printf(D_DETAIL, "op2: %s\n", op.inspect)
ret = @postproc.call(op, chrs) ret = @postproc.call(op, chrs)
return ret return ret
else else
@ -187,7 +191,7 @@ class SLex
else else
chrs.unshift ch chrs.unshift ch
if @postproc and @preproc.nil? || @preproc.call(op, chrs) if @postproc and @preproc.nil? || @preproc.call(op, chrs)
printf "op3: %s\n", op if SLex.debug? DOUT.printf(D_DETAIL, "op3: %s\n", op)
@postproc.call(op, chrs) @postproc.call(op, chrs)
return "" return ""
else else
@ -208,7 +212,7 @@ class SLex
end end
if ch.nil? if ch.nil?
if @preproc.nil? || @preproc.call(op, io) if @preproc.nil? || @preproc.call(op, io)
printf "op1: %s\n", op if SLex.debug? D_DETAIL.printf("op1: %s\n", op)
@postproc.call(op, io) @postproc.call(op, io)
else else
nil nil
@ -220,7 +224,7 @@ class SLex
else else
io.ungetc ch io.ungetc ch
if @postproc and @preproc.nil? || @preproc.call(op, io) if @postproc and @preproc.nil? || @preproc.call(op, io)
printf "op2: %s\n", op.inspect if SLex.debug? DOUT.exec_if(D_DETAIL) {printf "op2: %s\n", op.inspect}
@postproc.call(op, io) @postproc.call(op, io)
else else
nil nil
@ -229,7 +233,7 @@ class SLex
else else
io.ungetc ch io.ungetc ch
if @postproc and @preproc.nil? || @preproc.call(op, io) if @postproc and @preproc.nil? || @preproc.call(op, io)
printf "op3: %s\n", op if SLex.debug? D_DETAIL.printf("op3: %s\n", op)
@postproc.call(op, io) @postproc.call(op, io)
else else
nil nil
@ -239,6 +243,7 @@ class SLex
end end
end end
end end
end
if $0 == __FILE__ if $0 == __FILE__
# Tracer.on # Tracer.on
@ -275,3 +280,4 @@ if $0 == __FILE__
end end
exit exit
end end

View file

@ -1,6 +1,6 @@
# #
# irb/version.rb - irb version definition file # irb/version.rb - irb version definition file
# $Release Version: 0.9$ # $Release Version: 0.9.5$
# $Revision$ # $Revision$
# $Date$ # $Date$
# by Keiju ISHITSUKA(keiju@ishitsuka.com) # by Keiju ISHITSUKA(keiju@ishitsuka.com)
@ -11,6 +11,6 @@
# #
module IRB module IRB
@RELEASE_VERSION = "0.9" @RELEASE_VERSION = "0.9.5"
@LAST_UPDATE_DATE = "02/07/03" @LAST_UPDATE_DATE = "05/04/13"
end end

View file

@ -1,9 +1,9 @@
# #
# irb/workspace-binding.rb - # irb/workspace-binding.rb -
# $Release Version: 0.9$ # $Release Version: 0.9.5$
# $Revision$ # $Revision$
# $Date$ # $Date$
# by Keiju ISHITSUKA(keiju@ishitsuka.com) # by Keiju ISHITSUKA(keiju@ruby-lang.org)
# #
# -- # --
# #

View file

@ -1,9 +1,9 @@
# #
# irb/ws-for-case-2.rb - # irb/ws-for-case-2.rb -
# $Release Version: 0.9$ # $Release Version: 0.9.5$
# $Revision$ # $Revision$
# $Date$ # $Date$
# by Keiju ISHITSUKA(keiju@ishitsuka.com) # by Keiju ISHITSUKA(keiju@ruby-lang.org)
# #
# -- # --
# #