зеркало из https://github.com/github/ruby.git
* lib/cmath.rb: fixed indent.
* lib/drb/ssl.rb: ditto. * lib/irb/**/*.rb: ditto. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@47112 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
Родитель
45592f4b4c
Коммит
8e5af8b628
|
@ -1,3 +1,9 @@
|
||||||
|
Sat Aug 9 10:35:30 2014 Laurent Arnoud <laurent@spkdev.net>
|
||||||
|
|
||||||
|
* lib/cmath.rb: fixed indent.
|
||||||
|
* lib/drb/ssl.rb: ditto.
|
||||||
|
* lib/irb/**/*.rb: ditto.
|
||||||
|
|
||||||
Sat Aug 9 10:28:03 2014 SHIBATA Hiroshi <shibata.hiroshi@gmail.com>
|
Sat Aug 9 10:28:03 2014 SHIBATA Hiroshi <shibata.hiroshi@gmail.com>
|
||||||
|
|
||||||
* test/minitest/test_minitest_unit.rb: removed obsoleted condition
|
* test/minitest/test_minitest_unit.rb: removed obsoleted condition
|
||||||
|
|
112
lib/cmath.rb
112
lib/cmath.rb
|
@ -50,11 +50,11 @@ module CMath
|
||||||
def exp(z)
|
def exp(z)
|
||||||
begin
|
begin
|
||||||
if z.real?
|
if z.real?
|
||||||
exp!(z)
|
exp!(z)
|
||||||
else
|
else
|
||||||
ere = exp!(z.real)
|
ere = exp!(z.real)
|
||||||
Complex(ere * cos!(z.imag),
|
Complex(ere * cos!(z.imag),
|
||||||
ere * sin!(z.imag))
|
ere * sin!(z.imag))
|
||||||
end
|
end
|
||||||
rescue NoMethodError
|
rescue NoMethodError
|
||||||
handle_no_method_error
|
handle_no_method_error
|
||||||
|
@ -70,14 +70,14 @@ module CMath
|
||||||
begin
|
begin
|
||||||
z, b = args
|
z, b = args
|
||||||
unless b.nil? || b.kind_of?(Numeric)
|
unless b.nil? || b.kind_of?(Numeric)
|
||||||
raise TypeError, "Numeric Number required"
|
raise TypeError, "Numeric Number required"
|
||||||
end
|
end
|
||||||
if z.real? and z >= 0 and (b.nil? or b >= 0)
|
if z.real? and z >= 0 and (b.nil? or b >= 0)
|
||||||
log!(*args)
|
log!(*args)
|
||||||
else
|
else
|
||||||
a = Complex(log!(z.abs), z.arg)
|
a = Complex(log!(z.abs), z.arg)
|
||||||
if b
|
if b
|
||||||
a /= log(b)
|
a /= log(b)
|
||||||
end
|
end
|
||||||
a
|
a
|
||||||
end
|
end
|
||||||
|
@ -91,9 +91,9 @@ module CMath
|
||||||
def log2(z)
|
def log2(z)
|
||||||
begin
|
begin
|
||||||
if z.real? and z >= 0
|
if z.real? and z >= 0
|
||||||
log2!(z)
|
log2!(z)
|
||||||
else
|
else
|
||||||
log(z) / log!(2)
|
log(z) / log!(2)
|
||||||
end
|
end
|
||||||
rescue NoMethodError
|
rescue NoMethodError
|
||||||
handle_no_method_error
|
handle_no_method_error
|
||||||
|
@ -105,9 +105,9 @@ module CMath
|
||||||
def log10(z)
|
def log10(z)
|
||||||
begin
|
begin
|
||||||
if z.real? and z >= 0
|
if z.real? and z >= 0
|
||||||
log10!(z)
|
log10!(z)
|
||||||
else
|
else
|
||||||
log(z) / log!(10)
|
log(z) / log!(10)
|
||||||
end
|
end
|
||||||
rescue NoMethodError
|
rescue NoMethodError
|
||||||
handle_no_method_error
|
handle_no_method_error
|
||||||
|
@ -122,20 +122,20 @@ module CMath
|
||||||
def sqrt(z)
|
def sqrt(z)
|
||||||
begin
|
begin
|
||||||
if z.real?
|
if z.real?
|
||||||
if z < 0
|
if z < 0
|
||||||
Complex(0, sqrt!(-z))
|
Complex(0, sqrt!(-z))
|
||||||
else
|
else
|
||||||
sqrt!(z)
|
sqrt!(z)
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
if z.imag < 0 ||
|
if z.imag < 0 ||
|
||||||
(z.imag == 0 && z.imag.to_s[0] == '-')
|
(z.imag == 0 && z.imag.to_s[0] == '-')
|
||||||
sqrt(z.conjugate).conjugate
|
sqrt(z.conjugate).conjugate
|
||||||
else
|
else
|
||||||
r = z.abs
|
r = z.abs
|
||||||
x = z.real
|
x = z.real
|
||||||
Complex(sqrt!((r + x) / 2.0), sqrt!((r - x) / 2.0))
|
Complex(sqrt!((r + x) / 2.0), sqrt!((r - x) / 2.0))
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
rescue NoMethodError
|
rescue NoMethodError
|
||||||
handle_no_method_error
|
handle_no_method_error
|
||||||
|
@ -153,10 +153,10 @@ module CMath
|
||||||
def sin(z)
|
def sin(z)
|
||||||
begin
|
begin
|
||||||
if z.real?
|
if z.real?
|
||||||
sin!(z)
|
sin!(z)
|
||||||
else
|
else
|
||||||
Complex(sin!(z.real) * cosh!(z.imag),
|
Complex(sin!(z.real) * cosh!(z.imag),
|
||||||
cos!(z.real) * sinh!(z.imag))
|
cos!(z.real) * sinh!(z.imag))
|
||||||
end
|
end
|
||||||
rescue NoMethodError
|
rescue NoMethodError
|
||||||
handle_no_method_error
|
handle_no_method_error
|
||||||
|
@ -168,10 +168,10 @@ module CMath
|
||||||
def cos(z)
|
def cos(z)
|
||||||
begin
|
begin
|
||||||
if z.real?
|
if z.real?
|
||||||
cos!(z)
|
cos!(z)
|
||||||
else
|
else
|
||||||
Complex(cos!(z.real) * cosh!(z.imag),
|
Complex(cos!(z.real) * cosh!(z.imag),
|
||||||
-sin!(z.real) * sinh!(z.imag))
|
-sin!(z.real) * sinh!(z.imag))
|
||||||
end
|
end
|
||||||
rescue NoMethodError
|
rescue NoMethodError
|
||||||
handle_no_method_error
|
handle_no_method_error
|
||||||
|
@ -183,9 +183,9 @@ module CMath
|
||||||
def tan(z)
|
def tan(z)
|
||||||
begin
|
begin
|
||||||
if z.real?
|
if z.real?
|
||||||
tan!(z)
|
tan!(z)
|
||||||
else
|
else
|
||||||
sin(z) / cos(z)
|
sin(z) / cos(z)
|
||||||
end
|
end
|
||||||
rescue NoMethodError
|
rescue NoMethodError
|
||||||
handle_no_method_error
|
handle_no_method_error
|
||||||
|
@ -197,10 +197,10 @@ module CMath
|
||||||
def sinh(z)
|
def sinh(z)
|
||||||
begin
|
begin
|
||||||
if z.real?
|
if z.real?
|
||||||
sinh!(z)
|
sinh!(z)
|
||||||
else
|
else
|
||||||
Complex(sinh!(z.real) * cos!(z.imag),
|
Complex(sinh!(z.real) * cos!(z.imag),
|
||||||
cosh!(z.real) * sin!(z.imag))
|
cosh!(z.real) * sin!(z.imag))
|
||||||
end
|
end
|
||||||
rescue NoMethodError
|
rescue NoMethodError
|
||||||
handle_no_method_error
|
handle_no_method_error
|
||||||
|
@ -212,10 +212,10 @@ module CMath
|
||||||
def cosh(z)
|
def cosh(z)
|
||||||
begin
|
begin
|
||||||
if z.real?
|
if z.real?
|
||||||
cosh!(z)
|
cosh!(z)
|
||||||
else
|
else
|
||||||
Complex(cosh!(z.real) * cos!(z.imag),
|
Complex(cosh!(z.real) * cos!(z.imag),
|
||||||
sinh!(z.real) * sin!(z.imag))
|
sinh!(z.real) * sin!(z.imag))
|
||||||
end
|
end
|
||||||
rescue NoMethodError
|
rescue NoMethodError
|
||||||
handle_no_method_error
|
handle_no_method_error
|
||||||
|
@ -227,9 +227,9 @@ module CMath
|
||||||
def tanh(z)
|
def tanh(z)
|
||||||
begin
|
begin
|
||||||
if z.real?
|
if z.real?
|
||||||
tanh!(z)
|
tanh!(z)
|
||||||
else
|
else
|
||||||
sinh(z) / cosh(z)
|
sinh(z) / cosh(z)
|
||||||
end
|
end
|
||||||
rescue NoMethodError
|
rescue NoMethodError
|
||||||
handle_no_method_error
|
handle_no_method_error
|
||||||
|
@ -241,9 +241,9 @@ module CMath
|
||||||
def asin(z)
|
def asin(z)
|
||||||
begin
|
begin
|
||||||
if z.real? and z >= -1 and z <= 1
|
if z.real? and z >= -1 and z <= 1
|
||||||
asin!(z)
|
asin!(z)
|
||||||
else
|
else
|
||||||
(-1.0).i * log(1.0.i * z + sqrt(1.0 - z * z))
|
(-1.0).i * log(1.0.i * z + sqrt(1.0 - z * z))
|
||||||
end
|
end
|
||||||
rescue NoMethodError
|
rescue NoMethodError
|
||||||
handle_no_method_error
|
handle_no_method_error
|
||||||
|
@ -255,9 +255,9 @@ module CMath
|
||||||
def acos(z)
|
def acos(z)
|
||||||
begin
|
begin
|
||||||
if z.real? and z >= -1 and z <= 1
|
if z.real? and z >= -1 and z <= 1
|
||||||
acos!(z)
|
acos!(z)
|
||||||
else
|
else
|
||||||
(-1.0).i * log(z + 1.0.i * sqrt(1.0 - z * z))
|
(-1.0).i * log(z + 1.0.i * sqrt(1.0 - z * z))
|
||||||
end
|
end
|
||||||
rescue NoMethodError
|
rescue NoMethodError
|
||||||
handle_no_method_error
|
handle_no_method_error
|
||||||
|
@ -269,9 +269,9 @@ module CMath
|
||||||
def atan(z)
|
def atan(z)
|
||||||
begin
|
begin
|
||||||
if z.real?
|
if z.real?
|
||||||
atan!(z)
|
atan!(z)
|
||||||
else
|
else
|
||||||
1.0.i * log((1.0.i + z) / (1.0.i - z)) / 2.0
|
1.0.i * log((1.0.i + z) / (1.0.i - z)) / 2.0
|
||||||
end
|
end
|
||||||
rescue NoMethodError
|
rescue NoMethodError
|
||||||
handle_no_method_error
|
handle_no_method_error
|
||||||
|
@ -284,9 +284,9 @@ module CMath
|
||||||
def atan2(y,x)
|
def atan2(y,x)
|
||||||
begin
|
begin
|
||||||
if y.real? and x.real?
|
if y.real? and x.real?
|
||||||
atan2!(y,x)
|
atan2!(y,x)
|
||||||
else
|
else
|
||||||
(-1.0).i * log((x + 1.0.i * y) / sqrt(x * x + y * y))
|
(-1.0).i * log((x + 1.0.i * y) / sqrt(x * x + y * y))
|
||||||
end
|
end
|
||||||
rescue NoMethodError
|
rescue NoMethodError
|
||||||
handle_no_method_error
|
handle_no_method_error
|
||||||
|
@ -298,9 +298,9 @@ module CMath
|
||||||
def asinh(z)
|
def asinh(z)
|
||||||
begin
|
begin
|
||||||
if z.real?
|
if z.real?
|
||||||
asinh!(z)
|
asinh!(z)
|
||||||
else
|
else
|
||||||
log(z + sqrt(1.0 + z * z))
|
log(z + sqrt(1.0 + z * z))
|
||||||
end
|
end
|
||||||
rescue NoMethodError
|
rescue NoMethodError
|
||||||
handle_no_method_error
|
handle_no_method_error
|
||||||
|
@ -312,9 +312,9 @@ module CMath
|
||||||
def acosh(z)
|
def acosh(z)
|
||||||
begin
|
begin
|
||||||
if z.real? and z >= 1
|
if z.real? and z >= 1
|
||||||
acosh!(z)
|
acosh!(z)
|
||||||
else
|
else
|
||||||
log(z + sqrt(z * z - 1.0))
|
log(z + sqrt(z * z - 1.0))
|
||||||
end
|
end
|
||||||
rescue NoMethodError
|
rescue NoMethodError
|
||||||
handle_no_method_error
|
handle_no_method_error
|
||||||
|
@ -326,9 +326,9 @@ module CMath
|
||||||
def atanh(z)
|
def atanh(z)
|
||||||
begin
|
begin
|
||||||
if z.real? and z >= -1 and z <= 1
|
if z.real? and z >= -1 and z <= 1
|
||||||
atanh!(z)
|
atanh!(z)
|
||||||
else
|
else
|
||||||
log((1.0 + z) / (1.0 - z)) / 2.0
|
log((1.0 + z) / (1.0 - z)) / 2.0
|
||||||
end
|
end
|
||||||
rescue NoMethodError
|
rescue NoMethodError
|
||||||
handle_no_method_error
|
handle_no_method_error
|
||||||
|
|
|
@ -327,7 +327,7 @@ module DRb
|
||||||
soc.close
|
soc.close
|
||||||
end
|
end
|
||||||
begin
|
begin
|
||||||
ssl = @config.accept(soc)
|
ssl = @config.accept(soc)
|
||||||
rescue Exception
|
rescue Exception
|
||||||
soc.close
|
soc.close
|
||||||
raise
|
raise
|
||||||
|
|
|
@ -18,14 +18,14 @@ module IRB
|
||||||
|
|
||||||
class CurrentWorkingWorkspace<Nop
|
class CurrentWorkingWorkspace<Nop
|
||||||
def execute(*obj)
|
def execute(*obj)
|
||||||
irb_context.main
|
irb_context.main
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
class ChangeWorkspace<Nop
|
class ChangeWorkspace<Nop
|
||||||
def execute(*obj)
|
def execute(*obj)
|
||||||
irb_context.change_workspace(*obj)
|
irb_context.change_workspace(*obj)
|
||||||
irb_context.main
|
irb_context.main
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -16,20 +16,20 @@ module IRB
|
||||||
module ExtendCommand
|
module ExtendCommand
|
||||||
class Fork<Nop
|
class Fork<Nop
|
||||||
def execute
|
def execute
|
||||||
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')
|
||||||
end
|
end
|
||||||
if iterator?
|
if iterator?
|
||||||
begin
|
begin
|
||||||
yield
|
yield
|
||||||
ensure
|
ensure
|
||||||
exit
|
exit
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
pid
|
pid
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -19,8 +19,8 @@ module IRB
|
||||||
include IrbLoader
|
include IrbLoader
|
||||||
|
|
||||||
def execute(file_name, priv = nil)
|
def execute(file_name, priv = nil)
|
||||||
# return ruby_load(file_name) unless IRB.conf[:USE_LOADER]
|
# return ruby_load(file_name) unless IRB.conf[:USE_LOADER]
|
||||||
return irb_load(file_name, priv)
|
return irb_load(file_name, priv)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -28,38 +28,38 @@ module IRB
|
||||||
include IrbLoader
|
include IrbLoader
|
||||||
|
|
||||||
def execute(file_name)
|
def execute(file_name)
|
||||||
# return ruby_require(file_name) unless IRB.conf[:USE_LOADER]
|
# return ruby_require(file_name) unless IRB.conf[:USE_LOADER]
|
||||||
|
|
||||||
rex = Regexp.new("#{Regexp.quote(file_name)}(\.o|\.rb)?")
|
rex = Regexp.new("#{Regexp.quote(file_name)}(\.o|\.rb)?")
|
||||||
return false if $".find{|f| f =~ rex}
|
return false if $".find{|f| f =~ rex}
|
||||||
|
|
||||||
case file_name
|
case file_name
|
||||||
when /\.rb$/
|
when /\.rb$/
|
||||||
begin
|
begin
|
||||||
if irb_load(file_name)
|
if irb_load(file_name)
|
||||||
$".push file_name
|
$".push file_name
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
rescue LoadError
|
rescue LoadError
|
||||||
end
|
end
|
||||||
when /\.(so|o|sl)$/
|
when /\.(so|o|sl)$/
|
||||||
return ruby_require(file_name)
|
return ruby_require(file_name)
|
||||||
end
|
end
|
||||||
|
|
||||||
begin
|
begin
|
||||||
irb_load(f = file_name + ".rb")
|
irb_load(f = file_name + ".rb")
|
||||||
$".push f
|
$".push f
|
||||||
return true
|
return true
|
||||||
rescue LoadError
|
rescue LoadError
|
||||||
return ruby_require(file_name)
|
return ruby_require(file_name)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
class Source<Nop
|
class Source<Nop
|
||||||
include IrbLoader
|
include IrbLoader
|
||||||
def execute(file_name)
|
def execute(file_name)
|
||||||
source_file(file_name)
|
source_file(file_name)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -16,22 +16,22 @@ module IRB
|
||||||
@RCS_ID='-$Id$-'
|
@RCS_ID='-$Id$-'
|
||||||
|
|
||||||
def self.execute(conf, *opts)
|
def self.execute(conf, *opts)
|
||||||
command = new(conf)
|
command = new(conf)
|
||||||
command.execute(*opts)
|
command.execute(*opts)
|
||||||
end
|
end
|
||||||
|
|
||||||
def initialize(conf)
|
def initialize(conf)
|
||||||
@irb_context = conf
|
@irb_context = conf
|
||||||
end
|
end
|
||||||
|
|
||||||
attr_reader :irb_context
|
attr_reader :irb_context
|
||||||
|
|
||||||
def irb
|
def irb
|
||||||
@irb_context.irb
|
@irb_context.irb
|
||||||
end
|
end
|
||||||
|
|
||||||
def execute(*opts)
|
def execute(*opts)
|
||||||
#nop
|
#nop
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -17,21 +17,21 @@ module IRB
|
||||||
module ExtendCommand
|
module ExtendCommand
|
||||||
class Workspaces<Nop
|
class Workspaces<Nop
|
||||||
def execute(*obj)
|
def execute(*obj)
|
||||||
irb_context.workspaces.collect{|ws| ws.main}
|
irb_context.workspaces.collect{|ws| ws.main}
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
class PushWorkspace<Workspaces
|
class PushWorkspace<Workspaces
|
||||||
def execute(*obj)
|
def execute(*obj)
|
||||||
irb_context.push_workspace(*obj)
|
irb_context.push_workspace(*obj)
|
||||||
super
|
super
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
class PopWorkspace<Workspaces
|
class PopWorkspace<Workspaces
|
||||||
def execute(*obj)
|
def execute(*obj)
|
||||||
irb_context.pop_workspace(*obj)
|
irb_context.pop_workspace(*obj)
|
||||||
super
|
super
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -16,25 +16,25 @@ module IRB
|
||||||
module ExtendCommand
|
module ExtendCommand
|
||||||
class IrbCommand<Nop
|
class IrbCommand<Nop
|
||||||
def execute(*obj)
|
def execute(*obj)
|
||||||
IRB.irb(nil, *obj)
|
IRB.irb(nil, *obj)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
class Jobs<Nop
|
class Jobs<Nop
|
||||||
def execute
|
def execute
|
||||||
IRB.JobManager
|
IRB.JobManager
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
class Foreground<Nop
|
class Foreground<Nop
|
||||||
def execute(key)
|
def execute(key)
|
||||||
IRB.JobManager.switch(key)
|
IRB.JobManager.switch(key)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
class Kill<Nop
|
class Kill<Nop
|
||||||
def execute(*keys)
|
def execute(*keys)
|
||||||
IRB.JobManager.kill(*keys)
|
IRB.JobManager.kill(*keys)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -38,175 +38,175 @@ module IRB
|
||||||
CompletionProc = proc { |input|
|
CompletionProc = proc { |input|
|
||||||
bind = IRB.conf[:MAIN_CONTEXT].workspace.binding
|
bind = IRB.conf[:MAIN_CONTEXT].workspace.binding
|
||||||
|
|
||||||
# puts "input: #{input}"
|
# puts "input: #{input}"
|
||||||
|
|
||||||
case input
|
case input
|
||||||
when /^((["'`]).*\2)\.([^.]*)$/
|
when /^((["'`]).*\2)\.([^.]*)$/
|
||||||
# String
|
# String
|
||||||
receiver = $1
|
receiver = $1
|
||||||
message = Regexp.quote($3)
|
message = Regexp.quote($3)
|
||||||
|
|
||||||
candidates = String.instance_methods.collect{|m| m.to_s}
|
candidates = String.instance_methods.collect{|m| m.to_s}
|
||||||
select_message(receiver, message, candidates)
|
select_message(receiver, message, candidates)
|
||||||
|
|
||||||
when /^(\/[^\/]*\/)\.([^.]*)$/
|
when /^(\/[^\/]*\/)\.([^.]*)$/
|
||||||
# Regexp
|
# Regexp
|
||||||
receiver = $1
|
receiver = $1
|
||||||
message = Regexp.quote($2)
|
message = Regexp.quote($2)
|
||||||
|
|
||||||
candidates = Regexp.instance_methods.collect{|m| m.to_s}
|
candidates = Regexp.instance_methods.collect{|m| m.to_s}
|
||||||
select_message(receiver, message, candidates)
|
select_message(receiver, message, candidates)
|
||||||
|
|
||||||
when /^([^\]]*\])\.([^.]*)$/
|
when /^([^\]]*\])\.([^.]*)$/
|
||||||
# Array
|
# Array
|
||||||
receiver = $1
|
receiver = $1
|
||||||
message = Regexp.quote($2)
|
message = Regexp.quote($2)
|
||||||
|
|
||||||
candidates = Array.instance_methods.collect{|m| m.to_s}
|
candidates = Array.instance_methods.collect{|m| m.to_s}
|
||||||
select_message(receiver, message, candidates)
|
select_message(receiver, message, candidates)
|
||||||
|
|
||||||
when /^([^\}]*\})\.([^.]*)$/
|
when /^([^\}]*\})\.([^.]*)$/
|
||||||
# Proc or Hash
|
# Proc or Hash
|
||||||
receiver = $1
|
receiver = $1
|
||||||
message = Regexp.quote($2)
|
message = Regexp.quote($2)
|
||||||
|
|
||||||
candidates = Proc.instance_methods.collect{|m| m.to_s}
|
candidates = Proc.instance_methods.collect{|m| m.to_s}
|
||||||
candidates |= Hash.instance_methods.collect{|m| m.to_s}
|
candidates |= Hash.instance_methods.collect{|m| m.to_s}
|
||||||
select_message(receiver, message, candidates)
|
select_message(receiver, message, candidates)
|
||||||
|
|
||||||
when /^(:[^:.]*)$/
|
when /^(:[^:.]*)$/
|
||||||
# Symbol
|
# Symbol
|
||||||
if Symbol.respond_to?(:all_symbols)
|
if Symbol.respond_to?(:all_symbols)
|
||||||
sym = $1
|
sym = $1
|
||||||
candidates = Symbol.all_symbols.collect{|s| ":" + s.id2name}
|
candidates = Symbol.all_symbols.collect{|s| ":" + s.id2name}
|
||||||
candidates.grep(/^#{Regexp.quote(sym)}/)
|
candidates.grep(/^#{Regexp.quote(sym)}/)
|
||||||
else
|
else
|
||||||
[]
|
[]
|
||||||
end
|
end
|
||||||
|
|
||||||
when /^::([A-Z][^:\.\(]*)$/
|
when /^::([A-Z][^:\.\(]*)$/
|
||||||
# Absolute Constant or class methods
|
# Absolute Constant or class methods
|
||||||
receiver = $1
|
receiver = $1
|
||||||
candidates = Object.constants.collect{|m| m.to_s}
|
candidates = Object.constants.collect{|m| m.to_s}
|
||||||
candidates.grep(/^#{receiver}/).collect{|e| "::" + e}
|
candidates.grep(/^#{receiver}/).collect{|e| "::" + e}
|
||||||
|
|
||||||
# when /^(((::)?[A-Z][^:.\(]*)+)::?([^:.]*)$/
|
# when /^(((::)?[A-Z][^:.\(]*)+)::?([^:.]*)$/
|
||||||
when /^([A-Z].*)::([^:.]*)$/
|
when /^([A-Z].*)::([^:.]*)$/
|
||||||
# Constant or class methods
|
# Constant or class methods
|
||||||
receiver = $1
|
receiver = $1
|
||||||
message = Regexp.quote($2)
|
message = Regexp.quote($2)
|
||||||
begin
|
begin
|
||||||
candidates = eval("#{receiver}.constants.collect{|m| m.to_s}", bind)
|
candidates = eval("#{receiver}.constants.collect{|m| m.to_s}", bind)
|
||||||
candidates |= eval("#{receiver}.methods.collect{|m| m.to_s}", bind)
|
candidates |= eval("#{receiver}.methods.collect{|m| m.to_s}", bind)
|
||||||
rescue Exception
|
rescue Exception
|
||||||
candidates = []
|
candidates = []
|
||||||
end
|
end
|
||||||
select_message(receiver, message, candidates, "::")
|
select_message(receiver, message, candidates, "::")
|
||||||
|
|
||||||
when /^(:[^:.]+)(\.|::)([^.]*)$/
|
when /^(:[^:.]+)(\.|::)([^.]*)$/
|
||||||
# Symbol
|
# Symbol
|
||||||
receiver = $1
|
receiver = $1
|
||||||
sep = $2
|
sep = $2
|
||||||
message = Regexp.quote($3)
|
message = Regexp.quote($3)
|
||||||
|
|
||||||
candidates = Symbol.instance_methods.collect{|m| m.to_s}
|
candidates = Symbol.instance_methods.collect{|m| m.to_s}
|
||||||
select_message(receiver, message, candidates, sep)
|
select_message(receiver, message, candidates, sep)
|
||||||
|
|
||||||
when /^(-?(0[dbo])?[0-9_]+(\.[0-9_]+)?([eE]-?[0-9]+)?)(\.|::)([^.]*)$/
|
when /^(-?(0[dbo])?[0-9_]+(\.[0-9_]+)?([eE]-?[0-9]+)?)(\.|::)([^.]*)$/
|
||||||
# Numeric
|
# Numeric
|
||||||
receiver = $1
|
receiver = $1
|
||||||
sep = $5
|
sep = $5
|
||||||
message = Regexp.quote($6)
|
message = Regexp.quote($6)
|
||||||
|
|
||||||
begin
|
begin
|
||||||
candidates = eval(receiver, bind).methods.collect{|m| m.to_s}
|
candidates = eval(receiver, bind).methods.collect{|m| m.to_s}
|
||||||
rescue Exception
|
rescue Exception
|
||||||
candidates = []
|
candidates = []
|
||||||
end
|
end
|
||||||
select_message(receiver, message, candidates, sep)
|
select_message(receiver, message, candidates, sep)
|
||||||
|
|
||||||
when /^(-?0x[0-9a-fA-F_]+)(\.|::)([^.]*)$/
|
when /^(-?0x[0-9a-fA-F_]+)(\.|::)([^.]*)$/
|
||||||
# Numeric(0xFFFF)
|
# Numeric(0xFFFF)
|
||||||
receiver = $1
|
receiver = $1
|
||||||
sep = $2
|
sep = $2
|
||||||
message = Regexp.quote($3)
|
message = Regexp.quote($3)
|
||||||
|
|
||||||
begin
|
begin
|
||||||
candidates = eval(receiver, bind).methods.collect{|m| m.to_s}
|
candidates = eval(receiver, bind).methods.collect{|m| m.to_s}
|
||||||
rescue Exception
|
rescue Exception
|
||||||
candidates = []
|
candidates = []
|
||||||
end
|
end
|
||||||
select_message(receiver, message, candidates, sep)
|
select_message(receiver, message, candidates, sep)
|
||||||
|
|
||||||
when /^(\$[^.]*)$/
|
when /^(\$[^.]*)$/
|
||||||
# global var
|
# global var
|
||||||
regmessage = Regexp.new(Regexp.quote($1))
|
regmessage = Regexp.new(Regexp.quote($1))
|
||||||
candidates = global_variables.collect{|m| m.to_s}.grep(regmessage)
|
candidates = global_variables.collect{|m| m.to_s}.grep(regmessage)
|
||||||
|
|
||||||
# when /^(\$?(\.?[^.]+)+)\.([^.]*)$/
|
# when /^(\$?(\.?[^.]+)+)\.([^.]*)$/
|
||||||
# when /^((\.?[^.]+)+)\.([^.]*)$/
|
# when /^((\.?[^.]+)+)\.([^.]*)$/
|
||||||
# when /^([^."].*)\.([^.]*)$/
|
# when /^([^."].*)\.([^.]*)$/
|
||||||
when /^([^."].*)(\.|::)([^.]*)$/
|
when /^([^."].*)(\.|::)([^.]*)$/
|
||||||
# variable.func or func.func
|
# variable.func or func.func
|
||||||
receiver = $1
|
receiver = $1
|
||||||
sep = $2
|
sep = $2
|
||||||
message = Regexp.quote($3)
|
message = Regexp.quote($3)
|
||||||
|
|
||||||
gv = eval("global_variables", bind).collect{|m| m.to_s}
|
gv = eval("global_variables", bind).collect{|m| m.to_s}
|
||||||
lv = eval("local_variables", bind).collect{|m| m.to_s}
|
lv = eval("local_variables", bind).collect{|m| m.to_s}
|
||||||
iv = eval("instance_variables", bind).collect{|m| m.to_s}
|
iv = eval("instance_variables", bind).collect{|m| m.to_s}
|
||||||
cv = eval("self.class.constants", bind).collect{|m| m.to_s}
|
cv = eval("self.class.constants", bind).collect{|m| m.to_s}
|
||||||
|
|
||||||
if (gv | lv | iv | cv).include?(receiver) or /^[A-Z]/ =~ receiver && /\./ !~ receiver
|
if (gv | lv | iv | cv).include?(receiver) or /^[A-Z]/ =~ receiver && /\./ !~ receiver
|
||||||
# foo.func and foo is var. OR
|
# foo.func and foo is var. OR
|
||||||
# foo::func and foo is var. OR
|
# foo::func and foo is var. OR
|
||||||
# foo::Const and foo is var. OR
|
# foo::Const and foo is var. OR
|
||||||
# Foo::Bar.func
|
# Foo::Bar.func
|
||||||
begin
|
begin
|
||||||
candidates = []
|
candidates = []
|
||||||
rec = eval(receiver, bind)
|
rec = eval(receiver, bind)
|
||||||
if sep == "::" and rec.kind_of?(Module)
|
if sep == "::" and rec.kind_of?(Module)
|
||||||
candidates = rec.constants.collect{|m| m.to_s}
|
candidates = rec.constants.collect{|m| m.to_s}
|
||||||
end
|
end
|
||||||
candidates |= rec.methods.collect{|m| m.to_s}
|
candidates |= rec.methods.collect{|m| m.to_s}
|
||||||
rescue Exception
|
rescue Exception
|
||||||
candidates = []
|
candidates = []
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
# func1.func2
|
# func1.func2
|
||||||
candidates = []
|
candidates = []
|
||||||
ObjectSpace.each_object(Module){|m|
|
ObjectSpace.each_object(Module){|m|
|
||||||
begin
|
begin
|
||||||
name = m.name
|
name = m.name
|
||||||
rescue Exception
|
rescue Exception
|
||||||
name = ""
|
name = ""
|
||||||
end
|
end
|
||||||
begin
|
begin
|
||||||
next if name != "IRB::Context" and
|
next if name != "IRB::Context" and
|
||||||
/^(IRB|SLex|RubyLex|RubyToken)/ =~ name
|
/^(IRB|SLex|RubyLex|RubyToken)/ =~ name
|
||||||
rescue Exception
|
rescue Exception
|
||||||
next
|
next
|
||||||
end
|
end
|
||||||
candidates.concat m.instance_methods(false).collect{|x| x.to_s}
|
candidates.concat m.instance_methods(false).collect{|x| x.to_s}
|
||||||
}
|
}
|
||||||
candidates.sort!
|
candidates.sort!
|
||||||
candidates.uniq!
|
candidates.uniq!
|
||||||
end
|
end
|
||||||
select_message(receiver, message, candidates, sep)
|
select_message(receiver, message, candidates, sep)
|
||||||
|
|
||||||
when /^\.([^.]*)$/
|
when /^\.([^.]*)$/
|
||||||
# unknown(maybe String)
|
# unknown(maybe String)
|
||||||
|
|
||||||
receiver = ""
|
receiver = ""
|
||||||
message = Regexp.quote($1)
|
message = Regexp.quote($1)
|
||||||
|
|
||||||
candidates = String.instance_methods(true).collect{|m| m.to_s}
|
candidates = String.instance_methods(true).collect{|m| m.to_s}
|
||||||
select_message(receiver, message, candidates)
|
select_message(receiver, message, candidates)
|
||||||
|
|
||||||
else
|
else
|
||||||
candidates = eval("methods | private_methods | local_variables | instance_variables | self.class.constants", bind).collect{|m| m.to_s}
|
candidates = eval("methods | private_methods | local_variables | instance_variables | self.class.constants", bind).collect{|m| m.to_s}
|
||||||
|
|
||||||
(candidates|ReservedWords).grep(/^#{Regexp.quote(input)}/)
|
(candidates|ReservedWords).grep(/^#{Regexp.quote(input)}/)
|
||||||
end
|
end
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -215,20 +215,20 @@ module IRB
|
||||||
|
|
||||||
def self.select_message(receiver, message, candidates, sep = ".")
|
def self.select_message(receiver, message, candidates, sep = ".")
|
||||||
candidates.grep(/^#{message}/).collect do |e|
|
candidates.grep(/^#{message}/).collect do |e|
|
||||||
case e
|
case e
|
||||||
when /^[a-zA-Z_]/
|
when /^[a-zA-Z_]/
|
||||||
receiver + sep + e
|
receiver + sep + e
|
||||||
when /^[0-9]/
|
when /^[0-9]/
|
||||||
when *Operators
|
when *Operators
|
||||||
#receiver + " " + e
|
#receiver + " " + e
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
if Readline.respond_to?("basic_word_break_characters=")
|
if Readline.respond_to?("basic_word_break_characters=")
|
||||||
# Readline.basic_word_break_characters= " \t\n\"\\'`><=;|&{("
|
# Readline.basic_word_break_characters= " \t\n\"\\'`><=;|&{("
|
||||||
Readline.basic_word_break_characters= " \t\n`><=;|&{("
|
Readline.basic_word_break_characters= " \t\n`><=;|&{("
|
||||||
end
|
end
|
||||||
Readline.completion_append_character = nil
|
Readline.completion_append_character = nil
|
||||||
|
|
|
@ -25,12 +25,12 @@ module IRB
|
||||||
def initialize(irb, workspace = nil, input_method = nil, output_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
|
||||||
else
|
else
|
||||||
@workspace = WorkSpace.new
|
@workspace = WorkSpace.new
|
||||||
end
|
end
|
||||||
@thread = Thread.current if defined? Thread
|
@thread = Thread.current if defined? Thread
|
||||||
# @irb_level = 0
|
# @irb_level = 0
|
||||||
|
|
||||||
# copy of default configuration
|
# copy of default configuration
|
||||||
@ap_name = IRB.conf[:AP_NAME]
|
@ap_name = IRB.conf[:AP_NAME]
|
||||||
|
@ -55,50 +55,50 @@ module IRB
|
||||||
self.prompt_mode = IRB.conf[:PROMPT_MODE]
|
self.prompt_mode = IRB.conf[:PROMPT_MODE]
|
||||||
|
|
||||||
if IRB.conf[:SINGLE_IRB] or !defined?(IRB::JobManager)
|
if IRB.conf[:SINGLE_IRB] or !defined?(IRB::JobManager)
|
||||||
@irb_name = IRB.conf[:IRB_NAME]
|
@irb_name = IRB.conf[:IRB_NAME]
|
||||||
else
|
else
|
||||||
@irb_name = IRB.conf[:IRB_NAME]+"#"+IRB.JobManager.n_jobs.to_s
|
@irb_name = IRB.conf[:IRB_NAME]+"#"+IRB.JobManager.n_jobs.to_s
|
||||||
end
|
end
|
||||||
@irb_path = "(" + @irb_name + ")"
|
@irb_path = "(" + @irb_name + ")"
|
||||||
|
|
||||||
case input_method
|
case input_method
|
||||||
when nil
|
when nil
|
||||||
case use_readline?
|
case use_readline?
|
||||||
when nil
|
when nil
|
||||||
if (defined?(ReadlineInputMethod) && STDIN.tty? &&
|
if (defined?(ReadlineInputMethod) && STDIN.tty? &&
|
||||||
IRB.conf[:PROMPT_MODE] != :INF_RUBY)
|
IRB.conf[:PROMPT_MODE] != :INF_RUBY)
|
||||||
@io = ReadlineInputMethod.new
|
@io = ReadlineInputMethod.new
|
||||||
else
|
else
|
||||||
@io = StdioInputMethod.new
|
@io = StdioInputMethod.new
|
||||||
end
|
end
|
||||||
when false
|
when false
|
||||||
@io = StdioInputMethod.new
|
@io = StdioInputMethod.new
|
||||||
when true
|
when true
|
||||||
if defined?(ReadlineInputMethod)
|
if defined?(ReadlineInputMethod)
|
||||||
@io = ReadlineInputMethod.new
|
@io = ReadlineInputMethod.new
|
||||||
else
|
else
|
||||||
@io = StdioInputMethod.new
|
@io = StdioInputMethod.new
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
when String
|
when String
|
||||||
@io = FileInputMethod.new(input_method)
|
@io = FileInputMethod.new(input_method)
|
||||||
@irb_name = File.basename(input_method)
|
@irb_name = File.basename(input_method)
|
||||||
@irb_path = input_method
|
@irb_path = input_method
|
||||||
else
|
else
|
||||||
@io = input_method
|
@io = input_method
|
||||||
end
|
end
|
||||||
self.save_history = IRB.conf[:SAVE_HISTORY] if IRB.conf[:SAVE_HISTORY]
|
self.save_history = IRB.conf[:SAVE_HISTORY] if IRB.conf[:SAVE_HISTORY]
|
||||||
|
|
||||||
if output_method
|
if output_method
|
||||||
@output_method = output_method
|
@output_method = output_method
|
||||||
else
|
else
|
||||||
@output_method = StdioOutputMethod.new
|
@output_method = StdioOutputMethod.new
|
||||||
end
|
end
|
||||||
|
|
||||||
@echo = IRB.conf[:ECHO]
|
@echo = IRB.conf[:ECHO]
|
||||||
if @echo.nil?
|
if @echo.nil?
|
||||||
@echo = true
|
@echo = true
|
||||||
end
|
end
|
||||||
self.debug_level = IRB.conf[:DEBUG_LEVEL]
|
self.debug_level = IRB.conf[:DEBUG_LEVEL]
|
||||||
end
|
end
|
||||||
|
@ -235,15 +235,15 @@ module IRB
|
||||||
# Returns whether messages are displayed or not.
|
# Returns whether messages are displayed or not.
|
||||||
def verbose?
|
def verbose?
|
||||||
if @verbose.nil?
|
if @verbose.nil?
|
||||||
if defined?(ReadlineInputMethod) && @io.kind_of?(ReadlineInputMethod)
|
if defined?(ReadlineInputMethod) && @io.kind_of?(ReadlineInputMethod)
|
||||||
false
|
false
|
||||||
elsif !STDIN.tty? or @io.kind_of?(FileInputMethod)
|
elsif !STDIN.tty? or @io.kind_of?(FileInputMethod)
|
||||||
true
|
true
|
||||||
else
|
else
|
||||||
false
|
false
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
@verbose
|
@verbose
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -251,7 +251,7 @@ module IRB
|
||||||
# StdioInputMethod or ReadlineInputMethod, see #io for more information.
|
# StdioInputMethod or ReadlineInputMethod, see #io for more information.
|
||||||
def prompting?
|
def prompting?
|
||||||
verbose? || (STDIN.tty? && @io.kind_of?(StdioInputMethod) ||
|
verbose? || (STDIN.tty? && @io.kind_of?(StdioInputMethod) ||
|
||||||
(defined?(ReadlineInputMethod) && @io.kind_of?(ReadlineInputMethod)))
|
(defined?(ReadlineInputMethod) && @io.kind_of?(ReadlineInputMethod)))
|
||||||
end
|
end
|
||||||
|
|
||||||
# The return value of the last statement evaluated.
|
# The return value of the last statement evaluated.
|
||||||
|
@ -276,9 +276,9 @@ module IRB
|
||||||
@prompt_n = pconf[:PROMPT_N]
|
@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
|
||||||
else
|
else
|
||||||
@auto_indent_mode = IRB.conf[:AUTO_INDENT]
|
@auto_indent_mode = IRB.conf[:AUTO_INDENT]
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -309,41 +309,41 @@ module IRB
|
||||||
def inspect_mode=(opt)
|
def inspect_mode=(opt)
|
||||||
|
|
||||||
if i = Inspector::INSPECTORS[opt]
|
if i = Inspector::INSPECTORS[opt]
|
||||||
@inspect_mode = opt
|
@inspect_mode = opt
|
||||||
@inspect_method = i
|
@inspect_method = i
|
||||||
i.init
|
i.init
|
||||||
else
|
else
|
||||||
case opt
|
case opt
|
||||||
when nil
|
when nil
|
||||||
if Inspector.keys_with_inspector(Inspector::INSPECTORS[true]).include?(@inspect_mode)
|
if Inspector.keys_with_inspector(Inspector::INSPECTORS[true]).include?(@inspect_mode)
|
||||||
self.inspect_mode = false
|
self.inspect_mode = false
|
||||||
elsif Inspector.keys_with_inspector(Inspector::INSPECTORS[false]).include?(@inspect_mode)
|
elsif Inspector.keys_with_inspector(Inspector::INSPECTORS[false]).include?(@inspect_mode)
|
||||||
self.inspect_mode = true
|
self.inspect_mode = true
|
||||||
else
|
else
|
||||||
puts "Can't switch inspect mode."
|
puts "Can't switch inspect mode."
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
when /^\s*\{.*\}\s*$/
|
when /^\s*\{.*\}\s*$/
|
||||||
begin
|
begin
|
||||||
inspector = eval "proc#{opt}"
|
inspector = eval "proc#{opt}"
|
||||||
rescue Exception
|
rescue Exception
|
||||||
puts "Can't switch inspect mode(#{opt})."
|
puts "Can't switch inspect mode(#{opt})."
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
self.inspect_mode = inspector
|
self.inspect_mode = inspector
|
||||||
when Proc
|
when Proc
|
||||||
self.inspect_mode = IRB::Inspector(opt)
|
self.inspect_mode = IRB::Inspector(opt)
|
||||||
when Inspector
|
when Inspector
|
||||||
prefix = "usr%d"
|
prefix = "usr%d"
|
||||||
i = 1
|
i = 1
|
||||||
while Inspector::INSPECTORS[format(prefix, i)]; i += 1; end
|
while Inspector::INSPECTORS[format(prefix, i)]; i += 1; end
|
||||||
@inspect_mode = format(prefix, i)
|
@inspect_mode = format(prefix, i)
|
||||||
@inspect_method = opt
|
@inspect_method = opt
|
||||||
Inspector.def_inspector(format(prefix, i), @inspect_method)
|
Inspector.def_inspector(format(prefix, i), @inspect_method)
|
||||||
else
|
else
|
||||||
puts "Can't switch inspect mode(#{opt})."
|
puts "Can't switch inspect mode(#{opt})."
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
print "Switch to#{unless @inspect_mode; ' non';end} inspect mode.\n" if verbose?
|
print "Switch to#{unless @inspect_mode; ' non';end} inspect mode.\n" if verbose?
|
||||||
@inspect_mode
|
@inspect_mode
|
||||||
|
@ -378,8 +378,8 @@ module IRB
|
||||||
def evaluate(line, line_no) # :nodoc:
|
def evaluate(line, line_no) # :nodoc:
|
||||||
@line_no = line_no
|
@line_no = line_no
|
||||||
set_last_value(@workspace.evaluate(self, line, irb_path, line_no))
|
set_last_value(@workspace.evaluate(self, line, irb_path, line_no))
|
||||||
# @workspace.evaluate("_ = IRB.conf[:MAIN_CONTEXT]._")
|
# @workspace.evaluate("_ = IRB.conf[:MAIN_CONTEXT]._")
|
||||||
# @_ = @workspace.evaluate(line, irb_path, line_no)
|
# @_ = @workspace.evaluate(line, irb_path, line_no)
|
||||||
end
|
end
|
||||||
|
|
||||||
def inspect_last_value # :nodoc:
|
def inspect_last_value # :nodoc:
|
||||||
|
@ -400,19 +400,19 @@ module IRB
|
||||||
def inspect # :nodoc:
|
def inspect # :nodoc:
|
||||||
array = []
|
array = []
|
||||||
for ivar in instance_variables.sort{|e1, e2| e1 <=> e2}
|
for ivar in instance_variables.sort{|e1, e2| e1 <=> e2}
|
||||||
ivar = ivar.to_s
|
ivar = ivar.to_s
|
||||||
name = ivar.sub(/^@(.*)$/, '\1')
|
name = ivar.sub(/^@(.*)$/, '\1')
|
||||||
val = instance_eval(ivar)
|
val = instance_eval(ivar)
|
||||||
case ivar
|
case ivar
|
||||||
when *NOPRINTING_IVARS
|
when *NOPRINTING_IVARS
|
||||||
array.push format("conf.%s=%s", name, "...")
|
array.push format("conf.%s=%s", name, "...")
|
||||||
when *NO_INSPECTING_IVARS
|
when *NO_INSPECTING_IVARS
|
||||||
array.push format("conf.%s=%s", name, val.to_s)
|
array.push format("conf.%s=%s", name, val.to_s)
|
||||||
when *IDNAME_IVARS
|
when *IDNAME_IVARS
|
||||||
array.push format("conf.%s=:%s", name, val.id2name)
|
array.push format("conf.%s=:%s", name, val.id2name)
|
||||||
else
|
else
|
||||||
array.push format("conf.%s=%s", name, val.inspect)
|
array.push format("conf.%s=%s", name, val.inspect)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
array.join("\n")
|
array.join("\n")
|
||||||
end
|
end
|
||||||
|
|
|
@ -15,9 +15,9 @@ module IRB # :nodoc:
|
||||||
# Inherited from +TOPLEVEL_BINDING+.
|
# Inherited from +TOPLEVEL_BINDING+.
|
||||||
def home_workspace
|
def home_workspace
|
||||||
if defined? @home_workspace
|
if defined? @home_workspace
|
||||||
@home_workspace
|
@home_workspace
|
||||||
else
|
else
|
||||||
@home_workspace = @workspace
|
@home_workspace = @workspace
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -30,14 +30,14 @@ module IRB # :nodoc:
|
||||||
# See IRB::WorkSpace.new for more information.
|
# See IRB::WorkSpace.new for more information.
|
||||||
def change_workspace(*_main)
|
def change_workspace(*_main)
|
||||||
if _main.empty?
|
if _main.empty?
|
||||||
@workspace = home_workspace
|
@workspace = home_workspace
|
||||||
return main
|
return main
|
||||||
end
|
end
|
||||||
|
|
||||||
@workspace = WorkSpace.new(_main[0])
|
@workspace = WorkSpace.new(_main[0])
|
||||||
|
|
||||||
if !(class<<main;ancestors;end).include?(ExtendCommandBundle)
|
if !(class<<main;ancestors;end).include?(ExtendCommandBundle)
|
||||||
main.extend ExtendCommandBundle
|
main.extend ExtendCommandBundle
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -21,10 +21,10 @@ module IRB # :nodoc:
|
||||||
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 #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
|
||||||
|
|
||||||
@last_value
|
@last_value
|
||||||
|
@ -43,16 +43,16 @@ module IRB # :nodoc:
|
||||||
# If +no+ is +nil+, execution result history isn't used (default).
|
# If +no+ is +nil+, execution result history isn't used (default).
|
||||||
def eval_history=(no)
|
def eval_history=(no)
|
||||||
if no
|
if no
|
||||||
if defined?(@eval_history) && @eval_history
|
if defined?(@eval_history) && @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)
|
||||||
IRB.conf[:__TMP__EHV__] = @eval_history_values
|
IRB.conf[:__TMP__EHV__] = @eval_history_values
|
||||||
@workspace.evaluate(self, "__ = IRB.conf[:__TMP__EHV__]")
|
@workspace.evaluate(self, "__ = IRB.conf[:__TMP__EHV__]")
|
||||||
IRB.conf.delete(:__TMP_EHV__)
|
IRB.conf.delete(:__TMP_EHV__)
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
@eval_history_values = nil
|
@eval_history_values = nil
|
||||||
end
|
end
|
||||||
@eval_history = no
|
@eval_history = no
|
||||||
end
|
end
|
||||||
|
@ -68,20 +68,20 @@ module IRB # :nodoc:
|
||||||
|
|
||||||
def size(size)
|
def size(size)
|
||||||
if size != 0 && size < @size
|
if size != 0 && size < @size
|
||||||
@contents = @contents[@size - size .. @size]
|
@contents = @contents[@size - size .. @size]
|
||||||
end
|
end
|
||||||
@size = size
|
@size = size
|
||||||
end
|
end
|
||||||
|
|
||||||
def [](idx)
|
def [](idx)
|
||||||
begin
|
begin
|
||||||
if idx >= 0
|
if idx >= 0
|
||||||
@contents.find{|no, val| no == idx}[1]
|
@contents.find{|no, val| no == idx}[1]
|
||||||
else
|
else
|
||||||
@contents[idx][1]
|
@contents[idx][1]
|
||||||
end
|
end
|
||||||
rescue NameError
|
rescue NameError
|
||||||
nil
|
nil
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -94,22 +94,22 @@ module IRB # :nodoc:
|
||||||
|
|
||||||
def inspect
|
def inspect
|
||||||
if @contents.empty?
|
if @contents.empty?
|
||||||
return real_inspect
|
return real_inspect
|
||||||
end
|
end
|
||||||
|
|
||||||
unless (last = @contents.pop)[1].equal?(self)
|
unless (last = @contents.pop)[1].equal?(self)
|
||||||
@contents.push last
|
@contents.push last
|
||||||
last = nil
|
last = nil
|
||||||
end
|
end
|
||||||
str = @contents.collect{|no, val|
|
str = @contents.collect{|no, val|
|
||||||
if val.equal?(self)
|
if val.equal?(self)
|
||||||
"#{no} ...self-history..."
|
"#{no} ...self-history..."
|
||||||
else
|
else
|
||||||
"#{no} #{val.inspect}"
|
"#{no} #{val.inspect}"
|
||||||
end
|
end
|
||||||
}.join("\n")
|
}.join("\n")
|
||||||
if str == ""
|
if str == ""
|
||||||
str = "Empty."
|
str = "Empty."
|
||||||
end
|
end
|
||||||
@contents.push last if last
|
@contents.push last if last
|
||||||
str
|
str
|
||||||
|
|
|
@ -33,14 +33,14 @@ module IRB # :nodoc:
|
||||||
|
|
||||||
def search_file_from_ruby_path(fn) # :nodoc:
|
def search_file_from_ruby_path(fn) # :nodoc:
|
||||||
if /^#{Regexp.quote(File::Separator)}/ =~ fn
|
if /^#{Regexp.quote(File::Separator)}/ =~ fn
|
||||||
return fn if File.exist?(fn)
|
return fn if File.exist?(fn)
|
||||||
return nil
|
return nil
|
||||||
end
|
end
|
||||||
|
|
||||||
for path in $:
|
for path in $:
|
||||||
if File.exist?(f = File.join(path, fn))
|
if File.exist?(f = File.join(path, fn))
|
||||||
return f
|
return f
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
return nil
|
return nil
|
||||||
end
|
end
|
||||||
|
@ -50,20 +50,20 @@ module IRB # :nodoc:
|
||||||
# See Irb#suspend_input_method for more information.
|
# See Irb#suspend_input_method for more information.
|
||||||
def source_file(path)
|
def source_file(path)
|
||||||
irb.suspend_name(path, File.basename(path)) do
|
irb.suspend_name(path, File.basename(path)) do
|
||||||
irb.suspend_input_method(FileInputMethod.new(path)) do
|
irb.suspend_input_method(FileInputMethod.new(path)) do
|
||||||
|back_io|
|
|back_io|
|
||||||
irb.signal_status(:IN_LOAD) do
|
irb.signal_status(:IN_LOAD) do
|
||||||
if back_io.kind_of?(FileInputMethod)
|
if back_io.kind_of?(FileInputMethod)
|
||||||
irb.eval_input
|
irb.eval_input
|
||||||
else
|
else
|
||||||
begin
|
begin
|
||||||
irb.eval_input
|
irb.eval_input
|
||||||
rescue LoadAbort
|
rescue LoadAbort
|
||||||
print "load abort!!\n"
|
print "load abort!!\n"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -73,28 +73,28 @@ module IRB # :nodoc:
|
||||||
def load_file(path, priv = nil)
|
def load_file(path, priv = nil)
|
||||||
irb.suspend_name(path, File.basename(path)) do
|
irb.suspend_name(path, File.basename(path)) do
|
||||||
|
|
||||||
if priv
|
if priv
|
||||||
ws = WorkSpace.new(Module.new)
|
ws = WorkSpace.new(Module.new)
|
||||||
else
|
else
|
||||||
ws = WorkSpace.new
|
ws = WorkSpace.new
|
||||||
end
|
end
|
||||||
irb.suspend_workspace(ws) do
|
irb.suspend_workspace(ws) do
|
||||||
irb.suspend_input_method(FileInputMethod.new(path)) do
|
irb.suspend_input_method(FileInputMethod.new(path)) do
|
||||||
|back_io|
|
|back_io|
|
||||||
irb.signal_status(:IN_LOAD) do
|
irb.signal_status(:IN_LOAD) do
|
||||||
# p irb.conf
|
# p irb.conf
|
||||||
if back_io.kind_of?(FileInputMethod)
|
if back_io.kind_of?(FileInputMethod)
|
||||||
irb.eval_input
|
irb.eval_input
|
||||||
else
|
else
|
||||||
begin
|
begin
|
||||||
irb.eval_input
|
irb.eval_input
|
||||||
rescue LoadAbort
|
rescue LoadAbort
|
||||||
print "load abort!!\n"
|
print "load abort!!\n"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -104,25 +104,25 @@ module IRB # :nodoc:
|
||||||
back_name = @irb_name
|
back_name = @irb_name
|
||||||
back_scanner = @irb.scanner
|
back_scanner = @irb.scanner
|
||||||
begin
|
begin
|
||||||
@io = FileInputMethod.new(path)
|
@io = FileInputMethod.new(path)
|
||||||
@irb_name = File.basename(path)
|
@irb_name = File.basename(path)
|
||||||
@irb_path = path
|
@irb_path = path
|
||||||
@irb.signal_status(:IN_LOAD) do
|
@irb.signal_status(:IN_LOAD) do
|
||||||
if back_io.kind_of?(FileInputMethod)
|
if back_io.kind_of?(FileInputMethod)
|
||||||
@irb.eval_input
|
@irb.eval_input
|
||||||
else
|
else
|
||||||
begin
|
begin
|
||||||
@irb.eval_input
|
@irb.eval_input
|
||||||
rescue LoadAbort
|
rescue LoadAbort
|
||||||
print "load abort!!\n"
|
print "load abort!!\n"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
ensure
|
ensure
|
||||||
@io = back_io
|
@io = back_io
|
||||||
@irb_name = back_name
|
@irb_name = back_name
|
||||||
@irb_path = back_path
|
@irb_path = back_path
|
||||||
@irb.scanner = back_scanner
|
@irb.scanner = back_scanner
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -28,14 +28,14 @@ module IRB
|
||||||
# more information.
|
# more information.
|
||||||
def math_mode=(opt)
|
def math_mode=(opt)
|
||||||
if @math_mode == true && !opt
|
if @math_mode == true && !opt
|
||||||
IRB.fail CantReturnToNormalMode
|
IRB.fail CantReturnToNormalMode
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
@math_mode = opt
|
@math_mode = opt
|
||||||
if math_mode
|
if math_mode
|
||||||
main.extend Math
|
main.extend Math
|
||||||
print "start math mode\n" if verbose?
|
print "start math mode\n" if verbose?
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -258,22 +258,22 @@ module IRB
|
||||||
class Irb
|
class Irb
|
||||||
def signal_handle
|
def signal_handle
|
||||||
unless @context.ignore_sigint?
|
unless @context.ignore_sigint?
|
||||||
print "\nabort!!\n" if @context.verbose?
|
print "\nabort!!\n" if @context.verbose?
|
||||||
exit
|
exit
|
||||||
end
|
end
|
||||||
|
|
||||||
case @signal_status
|
case @signal_status
|
||||||
when :IN_INPUT
|
when :IN_INPUT
|
||||||
print "^C\n"
|
print "^C\n"
|
||||||
IRB.JobManager.thread(self).raise RubyLex::TerminateLineInput
|
IRB.JobManager.thread(self).raise RubyLex::TerminateLineInput
|
||||||
when :IN_EVAL
|
when :IN_EVAL
|
||||||
IRB.irb_abort(self)
|
IRB.irb_abort(self)
|
||||||
when :IN_LOAD
|
when :IN_LOAD
|
||||||
IRB.irb_abort(self, LoadAbort)
|
IRB.irb_abort(self, LoadAbort)
|
||||||
when :IN_IRB
|
when :IN_IRB
|
||||||
# ignore
|
# ignore
|
||||||
else
|
else
|
||||||
# ignore other cases as well
|
# ignore other cases as well
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -18,7 +18,7 @@ module IRB
|
||||||
class Context
|
class Context
|
||||||
def init_save_history# :nodoc:
|
def init_save_history# :nodoc:
|
||||||
unless (class<<@io;self;end).include?(HistorySavingAbility)
|
unless (class<<@io;self;end).include?(HistorySavingAbility)
|
||||||
@io.extend(HistorySavingAbility)
|
@io.extend(HistorySavingAbility)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -39,9 +39,9 @@ module IRB
|
||||||
def save_history=(val)
|
def save_history=(val)
|
||||||
IRB.conf[:SAVE_HISTORY] = val
|
IRB.conf[:SAVE_HISTORY] = val
|
||||||
if val
|
if val
|
||||||
main_context = IRB.conf[:MAIN_CONTEXT]
|
main_context = IRB.conf[:MAIN_CONTEXT]
|
||||||
main_context = self unless main_context
|
main_context = self unless main_context
|
||||||
main_context.init_save_history
|
main_context.init_save_history
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -83,37 +83,37 @@ module IRB
|
||||||
|
|
||||||
def load_history
|
def load_history
|
||||||
if history_file = IRB.conf[:HISTORY_FILE]
|
if history_file = IRB.conf[:HISTORY_FILE]
|
||||||
history_file = File.expand_path(history_file)
|
history_file = File.expand_path(history_file)
|
||||||
end
|
end
|
||||||
history_file = IRB.rc_file("_history") unless history_file
|
history_file = IRB.rc_file("_history") unless history_file
|
||||||
if File.exist?(history_file)
|
if File.exist?(history_file)
|
||||||
open(history_file) do |f|
|
open(history_file) do |f|
|
||||||
f.each {|l| HISTORY << l.chomp}
|
f.each {|l| HISTORY << l.chomp}
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def save_history
|
def save_history
|
||||||
if num = IRB.conf[:SAVE_HISTORY] and (num = num.to_i) > 0
|
if num = IRB.conf[:SAVE_HISTORY] and (num = num.to_i) > 0
|
||||||
if history_file = IRB.conf[:HISTORY_FILE]
|
if history_file = IRB.conf[:HISTORY_FILE]
|
||||||
history_file = File.expand_path(history_file)
|
history_file = File.expand_path(history_file)
|
||||||
end
|
end
|
||||||
history_file = IRB.rc_file("_history") unless history_file
|
history_file = IRB.rc_file("_history") unless history_file
|
||||||
|
|
||||||
# Change the permission of a file that already exists[BUG #7694]
|
# Change the permission of a file that already exists[BUG #7694]
|
||||||
begin
|
begin
|
||||||
if File.stat(history_file).mode & 066 != 0
|
if File.stat(history_file).mode & 066 != 0
|
||||||
File.chmod(0600, history_file)
|
File.chmod(0600, history_file)
|
||||||
end
|
end
|
||||||
rescue Errno::ENOENT
|
rescue Errno::ENOENT
|
||||||
rescue
|
rescue
|
||||||
raise
|
raise
|
||||||
end
|
end
|
||||||
|
|
||||||
open(history_file, 'w', 0600 ) do |f|
|
open(history_file, 'w', 0600 ) do |f|
|
||||||
hist = HISTORY.to_a
|
hist = HISTORY.to_a
|
||||||
f.puts(hist[-num..-1] || hist)
|
f.puts(hist[-num..-1] || hist)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -18,7 +18,7 @@ module IRB
|
||||||
Tracer.add_filter {
|
Tracer.add_filter {
|
||||||
|event, file, line, id, binding, *rests|
|
|event, file, line, id, binding, *rests|
|
||||||
/^#{Regexp.quote(@CONF[:IRB_LIB_PATH])}/ !~ file and
|
/^#{Regexp.quote(@CONF[:IRB_LIB_PATH])}/ !~ file and
|
||||||
File::basename(file) != "irb.rb"
|
File::basename(file) != "irb.rb"
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -35,12 +35,12 @@ module IRB
|
||||||
# See +lib/tracer.rb+ for more information.
|
# See +lib/tracer.rb+ for more information.
|
||||||
def use_tracer=(opt)
|
def use_tracer=(opt)
|
||||||
if opt
|
if opt
|
||||||
Tracer.set_get_line_procs(@irb_path) {
|
Tracer.set_get_line_procs(@irb_path) {
|
||||||
|line_no, *rests|
|
|line_no, *rests|
|
||||||
@io.line(line_no)
|
@io.line(line_no)
|
||||||
}
|
}
|
||||||
elsif !opt && @use_tracer
|
elsif !opt && @use_tracer
|
||||||
Tracer.off
|
Tracer.off
|
||||||
end
|
end
|
||||||
@use_tracer=opt
|
@use_tracer=opt
|
||||||
end
|
end
|
||||||
|
@ -54,14 +54,14 @@ module IRB
|
||||||
# See +lib/tracer.rb+ for more information.
|
# See +lib/tracer.rb+ for more information.
|
||||||
def evaluate(context, statements, file = nil, line = nil)
|
def evaluate(context, statements, file = nil, line = nil)
|
||||||
if context.use_tracer? && file != nil && line != nil
|
if context.use_tracer? && file != nil && line != nil
|
||||||
Tracer.on
|
Tracer.on
|
||||||
begin
|
begin
|
||||||
__evaluate__(context, statements, file, line)
|
__evaluate__(context, statements, file, line)
|
||||||
ensure
|
ensure
|
||||||
Tracer.off
|
Tracer.off
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
__evaluate__(context, statements, file || __FILE__, line || __LINE__)
|
__evaluate__(context, statements, file || __FILE__, line || __LINE__)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -49,20 +49,20 @@ module IRB
|
||||||
def use_loader=(opt)
|
def use_loader=(opt)
|
||||||
|
|
||||||
if IRB.conf[:USE_LOADER] != opt
|
if IRB.conf[:USE_LOADER] != opt
|
||||||
IRB.conf[:USE_LOADER] = opt
|
IRB.conf[:USE_LOADER] = opt
|
||||||
if opt
|
if opt
|
||||||
if !$".include?("irb/cmd/load")
|
if !$".include?("irb/cmd/load")
|
||||||
end
|
end
|
||||||
(class<<@workspace.main;self;end).instance_eval {
|
(class<<@workspace.main;self;end).instance_eval {
|
||||||
alias_method :load, :irb_load
|
alias_method :load, :irb_load
|
||||||
alias_method :require, :irb_require
|
alias_method :require, :irb_require
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
(class<<@workspace.main;self;end).instance_eval {
|
(class<<@workspace.main;self;end).instance_eval {
|
||||||
alias_method :load, :__original__load__IRB_use_loader__
|
alias_method :load, :__original__load__IRB_use_loader__
|
||||||
alias_method :require, :__original__require__IRB_use_loader__
|
alias_method :require, :__original__require__IRB_use_loader__
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
print "Switch to load/require#{unless use_loader; ' non';end} trace mode.\n" if verbose?
|
print "Switch to load/require#{unless use_loader; ' non';end} trace mode.\n" if verbose?
|
||||||
opt
|
opt
|
||||||
|
|
|
@ -20,9 +20,9 @@ module IRB # :nodoc:
|
||||||
# WorkSpaces in the current stack
|
# WorkSpaces in the current stack
|
||||||
def workspaces
|
def workspaces
|
||||||
if defined? @workspaces
|
if defined? @workspaces
|
||||||
@workspaces
|
@workspaces
|
||||||
else
|
else
|
||||||
@workspaces = []
|
@workspaces = []
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -33,20 +33,20 @@ module IRB # :nodoc:
|
||||||
# information.
|
# information.
|
||||||
def push_workspace(*_main)
|
def push_workspace(*_main)
|
||||||
if _main.empty?
|
if _main.empty?
|
||||||
if workspaces.empty?
|
if workspaces.empty?
|
||||||
print "No other workspace\n"
|
print "No other workspace\n"
|
||||||
return nil
|
return nil
|
||||||
end
|
end
|
||||||
ws = workspaces.pop
|
ws = workspaces.pop
|
||||||
workspaces.push @workspace
|
workspaces.push @workspace
|
||||||
@workspace = ws
|
@workspace = ws
|
||||||
return workspaces
|
return workspaces
|
||||||
end
|
end
|
||||||
|
|
||||||
workspaces.push @workspace
|
workspaces.push @workspace
|
||||||
@workspace = WorkSpace.new(@workspace.binding, _main[0])
|
@workspace = WorkSpace.new(@workspace.binding, _main[0])
|
||||||
if !(class<<main;ancestors;end).include?(ExtendCommandBundle)
|
if !(class<<main;ancestors;end).include?(ExtendCommandBundle)
|
||||||
main.extend ExtendCommandBundle
|
main.extend ExtendCommandBundle
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -56,8 +56,8 @@ module IRB # :nodoc:
|
||||||
# Also, see #push_workspace.
|
# Also, see #push_workspace.
|
||||||
def pop_workspace
|
def pop_workspace
|
||||||
if workspaces.empty?
|
if workspaces.empty?
|
||||||
print "workspace stack empty\n"
|
print "workspace stack empty\n"
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
@workspace = workspaces.pop
|
@workspace = workspaces.pop
|
||||||
end
|
end
|
||||||
|
|
|
@ -46,71 +46,71 @@ module IRB # :nodoc:
|
||||||
|
|
||||||
@EXTEND_COMMANDS = [
|
@EXTEND_COMMANDS = [
|
||||||
[:irb_current_working_workspace, :CurrentWorkingWorkspace, "irb/cmd/chws",
|
[:irb_current_working_workspace, :CurrentWorkingWorkspace, "irb/cmd/chws",
|
||||||
[:irb_print_working_workspace, OVERRIDE_ALL],
|
[:irb_print_working_workspace, OVERRIDE_ALL],
|
||||||
[:irb_cwws, OVERRIDE_ALL],
|
[:irb_cwws, OVERRIDE_ALL],
|
||||||
[:irb_pwws, OVERRIDE_ALL],
|
[:irb_pwws, OVERRIDE_ALL],
|
||||||
# [:irb_cww, OVERRIDE_ALL],
|
# [:irb_cww, OVERRIDE_ALL],
|
||||||
# [:irb_pww, OVERRIDE_ALL],
|
# [:irb_pww, OVERRIDE_ALL],
|
||||||
[:cwws, NO_OVERRIDE],
|
[:cwws, NO_OVERRIDE],
|
||||||
[:pwws, NO_OVERRIDE],
|
[:pwws, NO_OVERRIDE],
|
||||||
# [:cww, NO_OVERRIDE],
|
# [:cww, NO_OVERRIDE],
|
||||||
# [:pww, NO_OVERRIDE],
|
# [:pww, NO_OVERRIDE],
|
||||||
[:irb_current_working_binding, OVERRIDE_ALL],
|
[:irb_current_working_binding, OVERRIDE_ALL],
|
||||||
[:irb_print_working_binding, OVERRIDE_ALL],
|
[:irb_print_working_binding, OVERRIDE_ALL],
|
||||||
[:irb_cwb, OVERRIDE_ALL],
|
[:irb_cwb, OVERRIDE_ALL],
|
||||||
[:irb_pwb, OVERRIDE_ALL],
|
[:irb_pwb, OVERRIDE_ALL],
|
||||||
# [:cwb, NO_OVERRIDE],
|
# [:cwb, NO_OVERRIDE],
|
||||||
# [:pwb, NO_OVERRIDE]
|
# [:pwb, NO_OVERRIDE]
|
||||||
],
|
],
|
||||||
[:irb_change_workspace, :ChangeWorkspace, "irb/cmd/chws",
|
[:irb_change_workspace, :ChangeWorkspace, "irb/cmd/chws",
|
||||||
[:irb_chws, OVERRIDE_ALL],
|
[:irb_chws, OVERRIDE_ALL],
|
||||||
# [:irb_chw, OVERRIDE_ALL],
|
# [:irb_chw, OVERRIDE_ALL],
|
||||||
[:irb_cws, OVERRIDE_ALL],
|
[:irb_cws, OVERRIDE_ALL],
|
||||||
# [:irb_cw, OVERRIDE_ALL],
|
# [:irb_cw, OVERRIDE_ALL],
|
||||||
[:chws, NO_OVERRIDE],
|
[:chws, NO_OVERRIDE],
|
||||||
# [:chw, NO_OVERRIDE],
|
# [:chw, NO_OVERRIDE],
|
||||||
[:cws, NO_OVERRIDE],
|
[:cws, NO_OVERRIDE],
|
||||||
# [:cw, NO_OVERRIDE],
|
# [:cw, NO_OVERRIDE],
|
||||||
[:irb_change_binding, OVERRIDE_ALL],
|
[:irb_change_binding, OVERRIDE_ALL],
|
||||||
[:irb_cb, OVERRIDE_ALL],
|
[:irb_cb, OVERRIDE_ALL],
|
||||||
[:cb, NO_OVERRIDE]],
|
[:cb, NO_OVERRIDE]],
|
||||||
|
|
||||||
[:irb_workspaces, :Workspaces, "irb/cmd/pushws",
|
[:irb_workspaces, :Workspaces, "irb/cmd/pushws",
|
||||||
[:workspaces, NO_OVERRIDE],
|
[:workspaces, NO_OVERRIDE],
|
||||||
[:irb_bindings, OVERRIDE_ALL],
|
[:irb_bindings, OVERRIDE_ALL],
|
||||||
[:bindings, NO_OVERRIDE]],
|
[:bindings, NO_OVERRIDE]],
|
||||||
[:irb_push_workspace, :PushWorkspace, "irb/cmd/pushws",
|
[:irb_push_workspace, :PushWorkspace, "irb/cmd/pushws",
|
||||||
[:irb_pushws, OVERRIDE_ALL],
|
[:irb_pushws, OVERRIDE_ALL],
|
||||||
# [:irb_pushw, OVERRIDE_ALL],
|
# [:irb_pushw, OVERRIDE_ALL],
|
||||||
[:pushws, NO_OVERRIDE],
|
[:pushws, NO_OVERRIDE],
|
||||||
# [:pushw, NO_OVERRIDE],
|
# [:pushw, NO_OVERRIDE],
|
||||||
[:irb_push_binding, OVERRIDE_ALL],
|
[:irb_push_binding, OVERRIDE_ALL],
|
||||||
[:irb_pushb, OVERRIDE_ALL],
|
[:irb_pushb, OVERRIDE_ALL],
|
||||||
[:pushb, NO_OVERRIDE]],
|
[:pushb, NO_OVERRIDE]],
|
||||||
[:irb_pop_workspace, :PopWorkspace, "irb/cmd/pushws",
|
[:irb_pop_workspace, :PopWorkspace, "irb/cmd/pushws",
|
||||||
[:irb_popws, OVERRIDE_ALL],
|
[:irb_popws, OVERRIDE_ALL],
|
||||||
# [:irb_popw, OVERRIDE_ALL],
|
# [:irb_popw, OVERRIDE_ALL],
|
||||||
[:popws, NO_OVERRIDE],
|
[:popws, NO_OVERRIDE],
|
||||||
# [:popw, NO_OVERRIDE],
|
# [:popw, NO_OVERRIDE],
|
||||||
[:irb_pop_binding, OVERRIDE_ALL],
|
[:irb_pop_binding, OVERRIDE_ALL],
|
||||||
[:irb_popb, OVERRIDE_ALL],
|
[:irb_popb, OVERRIDE_ALL],
|
||||||
[:popb, NO_OVERRIDE]],
|
[:popb, NO_OVERRIDE]],
|
||||||
|
|
||||||
[:irb_load, :Load, "irb/cmd/load"],
|
[:irb_load, :Load, "irb/cmd/load"],
|
||||||
[:irb_require, :Require, "irb/cmd/load"],
|
[:irb_require, :Require, "irb/cmd/load"],
|
||||||
[:irb_source, :Source, "irb/cmd/load",
|
[:irb_source, :Source, "irb/cmd/load",
|
||||||
[:source, NO_OVERRIDE]],
|
[:source, NO_OVERRIDE]],
|
||||||
|
|
||||||
[:irb, :IrbCommand, "irb/cmd/subirb"],
|
[:irb, :IrbCommand, "irb/cmd/subirb"],
|
||||||
[:irb_jobs, :Jobs, "irb/cmd/subirb",
|
[:irb_jobs, :Jobs, "irb/cmd/subirb",
|
||||||
[:jobs, NO_OVERRIDE]],
|
[:jobs, NO_OVERRIDE]],
|
||||||
[:irb_fg, :Foreground, "irb/cmd/subirb",
|
[:irb_fg, :Foreground, "irb/cmd/subirb",
|
||||||
[:fg, NO_OVERRIDE]],
|
[:fg, NO_OVERRIDE]],
|
||||||
[:irb_kill, :Kill, "irb/cmd/subirb",
|
[:irb_kill, :Kill, "irb/cmd/subirb",
|
||||||
[:kill, OVERRIDE_PRIVATE_ONLY]],
|
[:kill, OVERRIDE_PRIVATE_ONLY]],
|
||||||
|
|
||||||
[:irb_help, :Help, "irb/cmd/help",
|
[:irb_help, :Help, "irb/cmd/help",
|
||||||
[:help, NO_OVERRIDE]],
|
[:help, NO_OVERRIDE]],
|
||||||
|
|
||||||
]
|
]
|
||||||
|
|
||||||
|
@ -131,7 +131,7 @@ module IRB # :nodoc:
|
||||||
# +irb_help+:: IRB@Command+line+options
|
# +irb_help+:: IRB@Command+line+options
|
||||||
def self.install_extend_commands
|
def self.install_extend_commands
|
||||||
for args in @EXTEND_COMMANDS
|
for args in @EXTEND_COMMANDS
|
||||||
def_extend_command(*args)
|
def_extend_command(*args)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -144,39 +144,39 @@ module IRB # :nodoc:
|
||||||
def self.def_extend_command(cmd_name, cmd_class, load_file = nil, *aliases)
|
def self.def_extend_command(cmd_name, cmd_class, load_file = nil, *aliases)
|
||||||
case cmd_class
|
case cmd_class
|
||||||
when Symbol
|
when Symbol
|
||||||
cmd_class = cmd_class.id2name
|
cmd_class = cmd_class.id2name
|
||||||
when String
|
when String
|
||||||
when Class
|
when Class
|
||||||
cmd_class = cmd_class.name
|
cmd_class = cmd_class.name
|
||||||
end
|
end
|
||||||
|
|
||||||
if load_file
|
if load_file
|
||||||
line = __LINE__; eval %[
|
line = __LINE__; eval %[
|
||||||
def #{cmd_name}(*opts, &b)
|
def #{cmd_name}(*opts, &b)
|
||||||
require "#{load_file}"
|
require "#{load_file}"
|
||||||
arity = ExtendCommand::#{cmd_class}.instance_method(:execute).arity
|
arity = ExtendCommand::#{cmd_class}.instance_method(:execute).arity
|
||||||
args = (1..(arity < 0 ? ~arity : arity)).map {|i| "arg" + i.to_s }
|
args = (1..(arity < 0 ? ~arity : arity)).map {|i| "arg" + i.to_s }
|
||||||
args << "*opts" if arity < 0
|
args << "*opts" if arity < 0
|
||||||
args << "&block"
|
args << "&block"
|
||||||
args = args.join(", ")
|
args = args.join(", ")
|
||||||
line = __LINE__; eval %[
|
line = __LINE__; eval %[
|
||||||
def #{cmd_name}(\#{args})
|
def #{cmd_name}(\#{args})
|
||||||
ExtendCommand::#{cmd_class}.execute(irb_context, \#{args})
|
ExtendCommand::#{cmd_class}.execute(irb_context, \#{args})
|
||||||
end
|
end
|
||||||
], nil, __FILE__, line
|
], nil, __FILE__, line
|
||||||
send :#{cmd_name}, *opts, &b
|
send :#{cmd_name}, *opts, &b
|
||||||
end
|
end
|
||||||
], nil, __FILE__, line
|
], nil, __FILE__, line
|
||||||
else
|
else
|
||||||
line = __LINE__; eval %[
|
line = __LINE__; eval %[
|
||||||
def #{cmd_name}(*opts, &b)
|
def #{cmd_name}(*opts, &b)
|
||||||
ExtendCommand::#{cmd_class}.execute(irb_context, *opts, &b)
|
ExtendCommand::#{cmd_class}.execute(irb_context, *opts, &b)
|
||||||
end
|
end
|
||||||
], nil, __FILE__, line
|
], nil, __FILE__, line
|
||||||
end
|
end
|
||||||
|
|
||||||
for ali, flag in aliases
|
for ali, flag in aliases
|
||||||
@ALIASES.push [ali, cmd_name, flag]
|
@ALIASES.push [ali, cmd_name, flag]
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -187,18 +187,18 @@ module IRB # :nodoc:
|
||||||
from = from.id2name unless from.kind_of?(String)
|
from = from.id2name unless from.kind_of?(String)
|
||||||
|
|
||||||
if override == OVERRIDE_ALL or
|
if override == OVERRIDE_ALL or
|
||||||
(override == OVERRIDE_PRIVATE_ONLY) && !respond_to?(to) or
|
(override == OVERRIDE_PRIVATE_ONLY) && !respond_to?(to) or
|
||||||
(override == NO_OVERRIDE) && !respond_to?(to, true)
|
(override == NO_OVERRIDE) && !respond_to?(to, true)
|
||||||
target = self
|
target = self
|
||||||
(class << self; self; end).instance_eval{
|
(class << self; self; end).instance_eval{
|
||||||
if target.respond_to?(to, true) &&
|
if target.respond_to?(to, true) &&
|
||||||
!target.respond_to?(EXCB.irb_original_method_name(to), true)
|
!target.respond_to?(EXCB.irb_original_method_name(to), true)
|
||||||
alias_method(EXCB.irb_original_method_name(to), to)
|
alias_method(EXCB.irb_original_method_name(to), to)
|
||||||
end
|
end
|
||||||
alias_method to, from
|
alias_method to, from
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
print "irb: warn: can't alias #{to} from #{from}.\n"
|
print "irb: warn: can't alias #{to} from #{from}.\n"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -210,10 +210,10 @@ module IRB # :nodoc:
|
||||||
# using #install_alias_method.
|
# using #install_alias_method.
|
||||||
def self.extend_object(obj)
|
def self.extend_object(obj)
|
||||||
unless (class << obj; ancestors; end).include?(EXCB)
|
unless (class << obj; ancestors; end).include?(EXCB)
|
||||||
super
|
super
|
||||||
for ali, com, flg in @ALIASES
|
for ali, com, flg in @ALIASES
|
||||||
obj.install_alias_method(ali, com, flg)
|
obj.install_alias_method(ali, com, flg)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -241,7 +241,7 @@ module IRB # :nodoc:
|
||||||
# Context#save_history=:: +irb/ext/save-history.rb+
|
# Context#save_history=:: +irb/ext/save-history.rb+
|
||||||
def self.install_extend_commands
|
def self.install_extend_commands
|
||||||
for args in @EXTEND_COMMANDS
|
for args in @EXTEND_COMMANDS
|
||||||
def_extend_command(*args)
|
def_extend_command(*args)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -252,13 +252,13 @@ module IRB # :nodoc:
|
||||||
def self.def_extend_command(cmd_name, load_file, *aliases)
|
def self.def_extend_command(cmd_name, load_file, *aliases)
|
||||||
line = __LINE__; Context.module_eval %[
|
line = __LINE__; Context.module_eval %[
|
||||||
def #{cmd_name}(*opts, &b)
|
def #{cmd_name}(*opts, &b)
|
||||||
Context.module_eval {remove_method(:#{cmd_name})}
|
Context.module_eval {remove_method(:#{cmd_name})}
|
||||||
require "#{load_file}"
|
require "#{load_file}"
|
||||||
send :#{cmd_name}, *opts, &b
|
send :#{cmd_name}, *opts, &b
|
||||||
end
|
end
|
||||||
for ali in aliases
|
for ali in aliases
|
||||||
alias_method ali, cmd_name
|
alias_method ali, cmd_name
|
||||||
end
|
end
|
||||||
], __FILE__, line
|
], __FILE__, line
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -277,9 +277,9 @@ module IRB # :nodoc:
|
||||||
module_eval %[
|
module_eval %[
|
||||||
alias_method alias_name, base_method
|
alias_method alias_name, base_method
|
||||||
def #{base_method}(*opts)
|
def #{base_method}(*opts)
|
||||||
send :#{extend_method}, *opts
|
send :#{extend_method}, *opts
|
||||||
send :#{alias_name}, *opts
|
send :#{alias_name}, *opts
|
||||||
end
|
end
|
||||||
]
|
]
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -293,9 +293,9 @@ module IRB # :nodoc:
|
||||||
module_eval %[
|
module_eval %[
|
||||||
alias_method alias_name, base_method
|
alias_method alias_name, base_method
|
||||||
def #{base_method}(*opts)
|
def #{base_method}(*opts)
|
||||||
send :#{alias_name}, *opts
|
send :#{alias_name}, *opts
|
||||||
send :#{extend_method}, *opts
|
send :#{extend_method}, *opts
|
||||||
end
|
end
|
||||||
]
|
]
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -313,7 +313,7 @@ module IRB # :nodoc:
|
||||||
return base_name if same_methods.empty?
|
return base_name if same_methods.empty?
|
||||||
no = same_methods.size
|
no = same_methods.size
|
||||||
while !same_methods.include?(alias_name = base_name + no)
|
while !same_methods.include?(alias_name = base_name + no)
|
||||||
no += 1
|
no += 1
|
||||||
end
|
end
|
||||||
alias_name
|
alias_name
|
||||||
end
|
end
|
||||||
|
|
|
@ -31,9 +31,9 @@ module IRB
|
||||||
def trace_func(event, file, line, id, binding)
|
def trace_func(event, file, line, id, binding)
|
||||||
case event
|
case event
|
||||||
when 'call', 'class'
|
when 'call', 'class'
|
||||||
@frames.push binding
|
@frames.push binding
|
||||||
when 'return', 'end'
|
when 'return', 'end'
|
||||||
@frames.pop
|
@frames.pop
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -19,16 +19,16 @@ module IRB
|
||||||
space_line = false
|
space_line = false
|
||||||
IRB::MagicFile.open(path){|f|
|
IRB::MagicFile.open(path){|f|
|
||||||
f.each_line do |l|
|
f.each_line do |l|
|
||||||
if /^\s*$/ =~ l
|
if /^\s*$/ =~ l
|
||||||
lc.puts l unless space_line
|
lc.puts l unless space_line
|
||||||
space_line = true
|
space_line = true
|
||||||
next
|
next
|
||||||
end
|
end
|
||||||
space_line = false
|
space_line = false
|
||||||
|
|
||||||
l.sub!(/#.*$/, "")
|
l.sub!(/#.*$/, "")
|
||||||
next if /^\s*$/ =~ l
|
next if /^\s*$/ =~ l
|
||||||
lc.puts l
|
lc.puts l
|
||||||
end
|
end
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
204
lib/irb/init.rb
204
lib/irb/init.rb
|
@ -59,48 +59,48 @@ module IRB # :nodoc:
|
||||||
|
|
||||||
@CONF[:PROMPT] = {
|
@CONF[:PROMPT] = {
|
||||||
:NULL => {
|
:NULL => {
|
||||||
:PROMPT_I => nil,
|
:PROMPT_I => nil,
|
||||||
:PROMPT_N => 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_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_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_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 => "%N(%m):%03n:%i> ",
|
||||||
:PROMPT_N => nil,
|
:PROMPT_N => nil,
|
||||||
:PROMPT_S => nil,
|
:PROMPT_S => nil,
|
||||||
:PROMPT_C => nil,
|
:PROMPT_C => nil,
|
||||||
:RETURN => "%s\n",
|
:RETURN => "%s\n",
|
||||||
:AUTO_INDENT => true
|
:AUTO_INDENT => true
|
||||||
},
|
},
|
||||||
:XMP => {
|
:XMP => {
|
||||||
:PROMPT_I => nil,
|
:PROMPT_I => nil,
|
||||||
:PROMPT_N => nil,
|
:PROMPT_N => nil,
|
||||||
:PROMPT_S => nil,
|
:PROMPT_S => nil,
|
||||||
:PROMPT_C => nil,
|
:PROMPT_C => nil,
|
||||||
:RETURN => " ==>%s\n"
|
:RETURN => " ==>%s\n"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -128,94 +128,94 @@ module IRB # :nodoc:
|
||||||
while opt = ARGV.shift
|
while opt = ARGV.shift
|
||||||
case opt
|
case opt
|
||||||
when "-f"
|
when "-f"
|
||||||
@CONF[:RC] = false
|
@CONF[:RC] = false
|
||||||
when "-m"
|
when "-m"
|
||||||
@CONF[:MATH_MODE] = true
|
@CONF[:MATH_MODE] = true
|
||||||
when "-d"
|
when "-d"
|
||||||
$DEBUG = true
|
$DEBUG = true
|
||||||
$VERBOSE = true
|
$VERBOSE = true
|
||||||
when "-w"
|
when "-w"
|
||||||
$VERBOSE = true
|
$VERBOSE = true
|
||||||
when /^-W(.+)?/
|
when /^-W(.+)?/
|
||||||
opt = $1 || ARGV.shift
|
opt = $1 || ARGV.shift
|
||||||
case opt
|
case opt
|
||||||
when "0"
|
when "0"
|
||||||
$VERBOSE = nil
|
$VERBOSE = nil
|
||||||
when "1"
|
when "1"
|
||||||
$VERBOSE = false
|
$VERBOSE = false
|
||||||
else
|
else
|
||||||
$VERBOSE = true
|
$VERBOSE = true
|
||||||
end
|
end
|
||||||
when /^-r(.+)?/
|
when /^-r(.+)?/
|
||||||
opt = $1 || ARGV.shift
|
opt = $1 || ARGV.shift
|
||||||
@CONF[:LOAD_MODULES].push opt if opt
|
@CONF[:LOAD_MODULES].push opt if opt
|
||||||
when /^-I(.+)?/
|
when /^-I(.+)?/
|
||||||
opt = $1 || ARGV.shift
|
opt = $1 || ARGV.shift
|
||||||
load_path.concat(opt.split(File::PATH_SEPARATOR)) if opt
|
load_path.concat(opt.split(File::PATH_SEPARATOR)) if opt
|
||||||
when '-U'
|
when '-U'
|
||||||
set_encoding("UTF-8", "UTF-8")
|
set_encoding("UTF-8", "UTF-8")
|
||||||
when /^-E(.+)?/, /^--encoding(?:=(.+))?/
|
when /^-E(.+)?/, /^--encoding(?:=(.+))?/
|
||||||
opt = $1 || ARGV.shift
|
opt = $1 || ARGV.shift
|
||||||
set_encoding(*opt.split(':', 2))
|
set_encoding(*opt.split(':', 2))
|
||||||
when "--inspect"
|
when "--inspect"
|
||||||
if /^-/ !~ ARGV.first
|
if /^-/ !~ ARGV.first
|
||||||
@CONF[:INSPECT_MODE] = ARGV.shift
|
@CONF[:INSPECT_MODE] = ARGV.shift
|
||||||
else
|
else
|
||||||
@CONF[:INSPECT_MODE] = true
|
@CONF[:INSPECT_MODE] = true
|
||||||
end
|
end
|
||||||
when "--noinspect"
|
when "--noinspect"
|
||||||
@CONF[:INSPECT_MODE] = false
|
@CONF[:INSPECT_MODE] = false
|
||||||
when "--readline"
|
when "--readline"
|
||||||
@CONF[:USE_READLINE] = true
|
@CONF[:USE_READLINE] = true
|
||||||
when "--noreadline"
|
when "--noreadline"
|
||||||
@CONF[:USE_READLINE] = false
|
@CONF[:USE_READLINE] = false
|
||||||
when "--echo"
|
when "--echo"
|
||||||
@CONF[:ECHO] = true
|
@CONF[:ECHO] = true
|
||||||
when "--noecho"
|
when "--noecho"
|
||||||
@CONF[:ECHO] = false
|
@CONF[:ECHO] = false
|
||||||
when "--verbose"
|
when "--verbose"
|
||||||
@CONF[:VERBOSE] = true
|
@CONF[:VERBOSE] = true
|
||||||
when "--noverbose"
|
when "--noverbose"
|
||||||
@CONF[:VERBOSE] = false
|
@CONF[:VERBOSE] = false
|
||||||
when /^--prompt-mode(?:=(.+))?/, /^--prompt(?:=(.+))?/
|
when /^--prompt-mode(?:=(.+))?/, /^--prompt(?:=(.+))?/
|
||||||
opt = $1 || ARGV.shift
|
opt = $1 || ARGV.shift
|
||||||
prompt_mode = opt.upcase.tr("-", "_").intern
|
prompt_mode = opt.upcase.tr("-", "_").intern
|
||||||
@CONF[:PROMPT_MODE] = prompt_mode
|
@CONF[:PROMPT_MODE] = prompt_mode
|
||||||
when "--noprompt"
|
when "--noprompt"
|
||||||
@CONF[:PROMPT_MODE] = :NULL
|
@CONF[:PROMPT_MODE] = :NULL
|
||||||
when "--inf-ruby-mode"
|
when "--inf-ruby-mode"
|
||||||
@CONF[:PROMPT_MODE] = :INF_RUBY
|
@CONF[:PROMPT_MODE] = :INF_RUBY
|
||||||
when "--sample-book-mode", "--simple-prompt"
|
when "--sample-book-mode", "--simple-prompt"
|
||||||
@CONF[:PROMPT_MODE] = :SIMPLE
|
@CONF[:PROMPT_MODE] = :SIMPLE
|
||||||
when "--tracer"
|
when "--tracer"
|
||||||
@CONF[:USE_TRACER] = true
|
@CONF[:USE_TRACER] = true
|
||||||
when /^--back-trace-limit(?:=(.+))?/
|
when /^--back-trace-limit(?:=(.+))?/
|
||||||
@CONF[:BACK_TRACE_LIMIT] = ($1 || ARGV.shift).to_i
|
@CONF[:BACK_TRACE_LIMIT] = ($1 || ARGV.shift).to_i
|
||||||
when /^--context-mode(?:=(.+))?/
|
when /^--context-mode(?:=(.+))?/
|
||||||
@CONF[:CONTEXT_MODE] = ($1 || ARGV.shift).to_i
|
@CONF[:CONTEXT_MODE] = ($1 || ARGV.shift).to_i
|
||||||
when "--single-irb"
|
when "--single-irb"
|
||||||
@CONF[:SINGLE_IRB] = true
|
@CONF[:SINGLE_IRB] = true
|
||||||
when /^--irb_debug(?:=(.+))?/
|
when /^--irb_debug(?:=(.+))?/
|
||||||
@CONF[:DEBUG_LEVEL] = ($1 || ARGV.shift).to_i
|
@CONF[:DEBUG_LEVEL] = ($1 || ARGV.shift).to_i
|
||||||
when "-v", "--version"
|
when "-v", "--version"
|
||||||
print IRB.version, "\n"
|
print IRB.version, "\n"
|
||||||
exit 0
|
exit 0
|
||||||
when "-h", "--help"
|
when "-h", "--help"
|
||||||
require "irb/help"
|
require "irb/help"
|
||||||
IRB.print_usage
|
IRB.print_usage
|
||||||
exit 0
|
exit 0
|
||||||
when "--"
|
when "--"
|
||||||
if opt = ARGV.shift
|
if opt = ARGV.shift
|
||||||
@CONF[:SCRIPT] = opt
|
@CONF[:SCRIPT] = opt
|
||||||
$0 = opt
|
$0 = opt
|
||||||
end
|
end
|
||||||
break
|
break
|
||||||
when /^-/
|
when /^-/
|
||||||
IRB.fail UnrecognizedSwitch, opt
|
IRB.fail UnrecognizedSwitch, opt
|
||||||
else
|
else
|
||||||
@CONF[:SCRIPT] = opt
|
@CONF[:SCRIPT] = opt
|
||||||
$0 = opt
|
$0 = opt
|
||||||
break
|
break
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
load_path.collect! do |path|
|
load_path.collect! do |path|
|
||||||
|
@ -229,14 +229,14 @@ module IRB # :nodoc:
|
||||||
def IRB.run_config
|
def IRB.run_config
|
||||||
if @CONF[:RC]
|
if @CONF[:RC]
|
||||||
begin
|
begin
|
||||||
load rc_file
|
load rc_file
|
||||||
rescue LoadError, Errno::ENOENT
|
rescue LoadError, Errno::ENOENT
|
||||||
rescue # StandardError, ScriptError
|
rescue # StandardError, ScriptError
|
||||||
print "load error: #{rc_file}\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
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -245,11 +245,11 @@ module IRB # :nodoc:
|
||||||
def IRB.rc_file(ext = IRBRC_EXT)
|
def IRB.rc_file(ext = IRBRC_EXT)
|
||||||
if !@CONF[:RC_NAME_GENERATOR]
|
if !@CONF[:RC_NAME_GENERATOR]
|
||||||
rc_file_generators do |rcgen|
|
rc_file_generators do |rcgen|
|
||||||
@CONF[:RC_NAME_GENERATOR] ||= rcgen
|
@CONF[:RC_NAME_GENERATOR] ||= rcgen
|
||||||
if File.exist?(rcgen.call(IRBRC_EXT))
|
if File.exist?(rcgen.call(IRBRC_EXT))
|
||||||
@CONF[:RC_NAME_GENERATOR] = rcgen
|
@CONF[:RC_NAME_GENERATOR] = rcgen
|
||||||
break
|
break
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
case rc_file = @CONF[:RC_NAME_GENERATOR].call(ext)
|
case rc_file = @CONF[:RC_NAME_GENERATOR].call(ext)
|
||||||
|
@ -279,9 +279,9 @@ module IRB # :nodoc:
|
||||||
def IRB.load_modules
|
def IRB.load_modules
|
||||||
for m in @CONF[:LOAD_MODULES]
|
for m in @CONF[:LOAD_MODULES]
|
||||||
begin
|
begin
|
||||||
require m
|
require m
|
||||||
rescue LoadError => err
|
rescue LoadError => err
|
||||||
warn err.backtrace[0] << ":#{err.class}: #{err}"
|
warn err.backtrace[0] << ":#{err.class}: #{err}"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -296,7 +296,7 @@ module IRB # :nodoc:
|
||||||
Encoding.default_internal = intern unless intern.nil? || intern.empty?
|
Encoding.default_internal = intern unless intern.nil? || intern.empty?
|
||||||
@CONF[:ENCODINGS] = IRB::DefaultEncodings.new(extern, intern)
|
@CONF[:ENCODINGS] = IRB::DefaultEncodings.new(extern, intern)
|
||||||
[$stdin, $stdout, $stderr].each do |io|
|
[$stdin, $stdout, $stderr].each do |io|
|
||||||
io.set_encoding(extern, intern)
|
io.set_encoding(extern, intern)
|
||||||
end
|
end
|
||||||
@CONF[:LC_MESSAGES].instance_variable_set(:@encoding, extern)
|
@CONF[:LC_MESSAGES].instance_variable_set(:@encoding, extern)
|
||||||
ensure
|
ensure
|
||||||
|
|
|
@ -133,14 +133,14 @@ module IRB
|
||||||
include Readline
|
include Readline
|
||||||
# Creates a new input method object using Readline
|
# Creates a new input method object using Readline
|
||||||
def initialize
|
def initialize
|
||||||
super
|
super
|
||||||
|
|
||||||
@line_no = 0
|
@line_no = 0
|
||||||
@line = []
|
@line = []
|
||||||
@eof = false
|
@eof = false
|
||||||
|
|
||||||
@stdin = IO.open(STDIN.to_i, :external_encoding => IRB.conf[:LC_MESSAGES].encoding, :internal_encoding => "-")
|
@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 => "-")
|
@stdout = IO.open(STDOUT.to_i, 'w', :external_encoding => IRB.conf[:LC_MESSAGES].encoding, :internal_encoding => "-")
|
||||||
end
|
end
|
||||||
|
|
||||||
# Reads the next line from this input method.
|
# Reads the next line from this input method.
|
||||||
|
@ -149,13 +149,13 @@ module IRB
|
||||||
def gets
|
def gets
|
||||||
Readline.input = @stdin
|
Readline.input = @stdin
|
||||||
Readline.output = @stdout
|
Readline.output = @stdout
|
||||||
if l = readline(@prompt, false)
|
if l = readline(@prompt, false)
|
||||||
HISTORY.push(l) if !l.empty?
|
HISTORY.push(l) if !l.empty?
|
||||||
@line[@line_no += 1] = l + "\n"
|
@line[@line_no += 1] = l + "\n"
|
||||||
else
|
else
|
||||||
@eof = true
|
@eof = true
|
||||||
l
|
l
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
# Whether the end of this input method has been reached, returns +true+
|
# Whether the end of this input method has been reached, returns +true+
|
||||||
|
@ -163,7 +163,7 @@ module IRB
|
||||||
#
|
#
|
||||||
# See IO#eof? for more information.
|
# See IO#eof? for more information.
|
||||||
def eof?
|
def eof?
|
||||||
@eof
|
@eof
|
||||||
end
|
end
|
||||||
|
|
||||||
# Whether this input method is still readable when there is no more data to
|
# Whether this input method is still readable when there is no more data to
|
||||||
|
@ -171,7 +171,7 @@ module IRB
|
||||||
#
|
#
|
||||||
# See IO#eof for more information.
|
# See IO#eof for more information.
|
||||||
def readable_after_eof?
|
def readable_after_eof?
|
||||||
true
|
true
|
||||||
end
|
end
|
||||||
|
|
||||||
# Returns the current line number for #io.
|
# Returns the current line number for #io.
|
||||||
|
@ -180,12 +180,12 @@ module IRB
|
||||||
#
|
#
|
||||||
# See IO#lineno for more information.
|
# See IO#lineno for more information.
|
||||||
def line(line_no)
|
def line(line_no)
|
||||||
@line[line_no]
|
@line[line_no]
|
||||||
end
|
end
|
||||||
|
|
||||||
# The external encoding for standard input.
|
# The external encoding for standard input.
|
||||||
def encoding
|
def encoding
|
||||||
@stdin.external_encoding
|
@stdin.external_encoding
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
rescue LoadError
|
rescue LoadError
|
||||||
|
|
|
@ -26,15 +26,15 @@ module IRB # :nodoc:
|
||||||
@lang = @territory = @encoding_name = @modifier = nil
|
@lang = @territory = @encoding_name = @modifier = nil
|
||||||
@locale = locale || ENV["IRB_LANG"] || ENV["LC_MESSAGES"] || ENV["LC_ALL"] || ENV["LANG"] || "C"
|
@locale = locale || ENV["IRB_LANG"] || ENV["LC_MESSAGES"] || ENV["LC_ALL"] || ENV["LANG"] || "C"
|
||||||
if m = LOCALE_NAME_RE.match(@locale)
|
if m = LOCALE_NAME_RE.match(@locale)
|
||||||
@lang, @territory, @encoding_name, @modifier = m[:language], m[:territory], m[:codeset], m[:modifier]
|
@lang, @territory, @encoding_name, @modifier = m[:language], m[:territory], m[:codeset], m[:modifier]
|
||||||
|
|
||||||
if @encoding_name
|
if @encoding_name
|
||||||
begin load 'irb/encoding_aliases.rb'; rescue LoadError; end
|
begin load 'irb/encoding_aliases.rb'; rescue LoadError; end
|
||||||
if @encoding = @@legacy_encoding_alias_map[@encoding_name]
|
if @encoding = @@legacy_encoding_alias_map[@encoding_name]
|
||||||
warn "%s is obsolete. use %s" % ["#{@lang}_#{@territory}.#{@encoding_name}", "#{@lang}_#{@territory}.#{@encoding.name}"]
|
warn "%s is obsolete. use %s" % ["#{@lang}_#{@territory}.#{@encoding_name}", "#{@lang}_#{@territory}.#{@encoding.name}"]
|
||||||
end
|
end
|
||||||
@encoding = Encoding.find(@encoding_name) rescue nil
|
@encoding = Encoding.find(@encoding_name) rescue nil
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@encoding ||= (Encoding.find('locale') rescue Encoding::ASCII_8BIT)
|
@encoding ||= (Encoding.find('locale') rescue Encoding::ASCII_8BIT)
|
||||||
end
|
end
|
||||||
|
@ -44,9 +44,9 @@ module IRB # :nodoc:
|
||||||
def String(mes)
|
def String(mes)
|
||||||
mes = super(mes)
|
mes = super(mes)
|
||||||
if @encoding
|
if @encoding
|
||||||
mes.encode(@encoding, undef: :replace)
|
mes.encode(@encoding, undef: :replace)
|
||||||
else
|
else
|
||||||
mes
|
mes
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -83,22 +83,22 @@ module IRB # :nodoc:
|
||||||
|
|
||||||
case file
|
case file
|
||||||
when /\.rb$/
|
when /\.rb$/
|
||||||
begin
|
begin
|
||||||
load(file, priv)
|
load(file, priv)
|
||||||
$".push file
|
$".push file
|
||||||
return true
|
return true
|
||||||
rescue LoadError
|
rescue LoadError
|
||||||
end
|
end
|
||||||
when /\.(so|o|sl)$/
|
when /\.(so|o|sl)$/
|
||||||
return super
|
return super
|
||||||
end
|
end
|
||||||
|
|
||||||
begin
|
begin
|
||||||
load(f = file + ".rb")
|
load(f = file + ".rb")
|
||||||
$".push f #"
|
$".push f #"
|
||||||
return true
|
return true
|
||||||
rescue LoadError
|
rescue LoadError
|
||||||
return ruby_require(file)
|
return ruby_require(file)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -129,9 +129,9 @@ module IRB # :nodoc:
|
||||||
def real_load(path, priv)
|
def real_load(path, priv)
|
||||||
src = MagicFile.open(path){|f| f.read}
|
src = MagicFile.open(path){|f| f.read}
|
||||||
if priv
|
if priv
|
||||||
eval("self", TOPLEVEL_BINDING).extend(Module.new {eval(src, nil, path)})
|
eval("self", TOPLEVEL_BINDING).extend(Module.new {eval(src, nil, path)})
|
||||||
else
|
else
|
||||||
eval(src, TOPLEVEL_BINDING, path)
|
eval(src, TOPLEVEL_BINDING, path)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -161,20 +161,20 @@ module IRB # :nodoc:
|
||||||
|
|
||||||
def each_sublocale
|
def each_sublocale
|
||||||
if @lang
|
if @lang
|
||||||
if @territory
|
if @territory
|
||||||
if @encoding_name
|
if @encoding_name
|
||||||
yield "#{@lang}_#{@territory}.#{@encoding_name}@#{@modifier}" if @modifier
|
yield "#{@lang}_#{@territory}.#{@encoding_name}@#{@modifier}" if @modifier
|
||||||
yield "#{@lang}_#{@territory}.#{@encoding_name}"
|
yield "#{@lang}_#{@territory}.#{@encoding_name}"
|
||||||
end
|
end
|
||||||
yield "#{@lang}_#{@territory}@#{@modifier}" if @modifier
|
yield "#{@lang}_#{@territory}@#{@modifier}" if @modifier
|
||||||
yield "#{@lang}_#{@territory}"
|
yield "#{@lang}_#{@territory}"
|
||||||
end
|
end
|
||||||
if @encoding_name
|
if @encoding_name
|
||||||
yield "#{@lang}.#{@encoding_name}@#{@modifier}" if @modifier
|
yield "#{@lang}.#{@encoding_name}@#{@modifier}" if @modifier
|
||||||
yield "#{@lang}.#{@encoding_name}"
|
yield "#{@lang}.#{@encoding_name}"
|
||||||
end
|
end
|
||||||
yield "#{@lang}@#{@modifier}" if @modifier
|
yield "#{@lang}@#{@modifier}" if @modifier
|
||||||
yield "#{@lang}"
|
yield "#{@lang}"
|
||||||
end
|
end
|
||||||
yield nil
|
yield nil
|
||||||
end
|
end
|
||||||
|
|
|
@ -40,8 +40,8 @@ module IRB
|
||||||
class AbstractNotifier
|
class AbstractNotifier
|
||||||
# Creates a new Notifier object
|
# Creates a new Notifier object
|
||||||
def initialize(prefix, base_notifier)
|
def initialize(prefix, base_notifier)
|
||||||
@prefix = prefix
|
@prefix = prefix
|
||||||
@base_notifier = base_notifier
|
@base_notifier = base_notifier
|
||||||
end
|
end
|
||||||
|
|
||||||
# The +prefix+ for this Notifier, which is appended to all objects being
|
# The +prefix+ for this Notifier, which is appended to all objects being
|
||||||
|
@ -52,38 +52,38 @@ module IRB
|
||||||
#
|
#
|
||||||
# Defaults to +true+.
|
# Defaults to +true+.
|
||||||
def notify?
|
def notify?
|
||||||
true
|
true
|
||||||
end
|
end
|
||||||
|
|
||||||
# See OutputMethod#print for more detail.
|
# See OutputMethod#print for more detail.
|
||||||
def print(*opts)
|
def print(*opts)
|
||||||
@base_notifier.print prefix, *opts if notify?
|
@base_notifier.print prefix, *opts if notify?
|
||||||
end
|
end
|
||||||
|
|
||||||
# See OutputMethod#printn for more detail.
|
# See OutputMethod#printn for more detail.
|
||||||
def printn(*opts)
|
def printn(*opts)
|
||||||
@base_notifier.printn prefix, *opts if notify?
|
@base_notifier.printn prefix, *opts if notify?
|
||||||
end
|
end
|
||||||
|
|
||||||
# See OutputMethod#printf for more detail.
|
# See OutputMethod#printf for more detail.
|
||||||
def printf(format, *opts)
|
def printf(format, *opts)
|
||||||
@base_notifier.printf(prefix + format, *opts) if notify?
|
@base_notifier.printf(prefix + format, *opts) if notify?
|
||||||
end
|
end
|
||||||
|
|
||||||
# See OutputMethod#puts for more detail.
|
# See OutputMethod#puts for more detail.
|
||||||
def puts(*objs)
|
def puts(*objs)
|
||||||
if notify?
|
if notify?
|
||||||
@base_notifier.puts(*objs.collect{|obj| prefix + obj.to_s})
|
@base_notifier.puts(*objs.collect{|obj| prefix + obj.to_s})
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
# Same as #ppx, except it uses the #prefix given during object
|
# Same as #ppx, except it uses the #prefix given during object
|
||||||
# initialization.
|
# initialization.
|
||||||
# See OutputMethod#ppx for more detail.
|
# See OutputMethod#ppx for more detail.
|
||||||
def pp(*objs)
|
def pp(*objs)
|
||||||
if notify?
|
if notify?
|
||||||
@base_notifier.ppx @prefix, *objs
|
@base_notifier.ppx @prefix, *objs
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
# Same as #pp, except it concatenates the given +prefix+ with the #prefix
|
# Same as #pp, except it concatenates the given +prefix+ with the #prefix
|
||||||
|
@ -91,14 +91,14 @@ module IRB
|
||||||
#
|
#
|
||||||
# See OutputMethod#ppx for more detail.
|
# See OutputMethod#ppx for more detail.
|
||||||
def ppx(prefix, *objs)
|
def ppx(prefix, *objs)
|
||||||
if notify?
|
if notify?
|
||||||
@base_notifier.ppx @prefix+prefix, *objs
|
@base_notifier.ppx @prefix+prefix, *objs
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
# Execute the given block if notifications are enabled.
|
# Execute the given block if notifications are enabled.
|
||||||
def exec_if
|
def exec_if
|
||||||
yield(@base_notifier) if notify?
|
yield(@base_notifier) if notify?
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -116,10 +116,10 @@ module IRB
|
||||||
# Create a new composite notifier object with the given +prefix+, and
|
# Create a new composite notifier object with the given +prefix+, and
|
||||||
# +base_notifier+ to use for output.
|
# +base_notifier+ to use for output.
|
||||||
def initialize(prefix, base_notifier)
|
def initialize(prefix, base_notifier)
|
||||||
super
|
super
|
||||||
|
|
||||||
@notifiers = [D_NOMSG]
|
@notifiers = [D_NOMSG]
|
||||||
@level_notifier = D_NOMSG
|
@level_notifier = D_NOMSG
|
||||||
end
|
end
|
||||||
|
|
||||||
# List of notifiers in the group
|
# List of notifiers in the group
|
||||||
|
@ -132,9 +132,9 @@ module IRB
|
||||||
#
|
#
|
||||||
# This method returns the newly created instance.
|
# This method returns the newly created instance.
|
||||||
def def_notifier(level, prefix = "")
|
def def_notifier(level, prefix = "")
|
||||||
notifier = LeveledNotifier.new(self, level, prefix)
|
notifier = LeveledNotifier.new(self, level, prefix)
|
||||||
@notifiers[level] = notifier
|
@notifiers[level] = notifier
|
||||||
notifier
|
notifier
|
||||||
end
|
end
|
||||||
|
|
||||||
# Returns the leveled notifier for this object
|
# Returns the leveled notifier for this object
|
||||||
|
@ -156,16 +156,16 @@ module IRB
|
||||||
# found in the existing #notifiers Array, or an instance of
|
# found in the existing #notifiers Array, or an instance of
|
||||||
# AbstractNotifier
|
# AbstractNotifier
|
||||||
def level_notifier=(value)
|
def level_notifier=(value)
|
||||||
case value
|
case value
|
||||||
when AbstractNotifier
|
when AbstractNotifier
|
||||||
@level_notifier = value
|
@level_notifier = value
|
||||||
when Integer
|
when Integer
|
||||||
l = @notifiers[value]
|
l = @notifiers[value]
|
||||||
Notifier.Raise ErrUndefinedNotifier, value unless l
|
Notifier.Raise ErrUndefinedNotifier, value unless l
|
||||||
@level_notifier = l
|
@level_notifier = l
|
||||||
else
|
else
|
||||||
Notifier.Raise ErrUnrecognizedLevel, value unless l
|
Notifier.Raise ErrUnrecognizedLevel, value unless l
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
alias level= level_notifier=
|
alias level= level_notifier=
|
||||||
|
@ -183,9 +183,9 @@ module IRB
|
||||||
# CompositeNotifier group to determine whether or not to output
|
# CompositeNotifier group to determine whether or not to output
|
||||||
# notifications.
|
# notifications.
|
||||||
def initialize(base, level, prefix)
|
def initialize(base, level, prefix)
|
||||||
super(prefix, base)
|
super(prefix, base)
|
||||||
|
|
||||||
@level = level
|
@level = level
|
||||||
end
|
end
|
||||||
|
|
||||||
# The current level of this notifier object
|
# The current level of this notifier object
|
||||||
|
@ -196,13 +196,13 @@ module IRB
|
||||||
#
|
#
|
||||||
# See the Comparable module for more information.
|
# See the Comparable module for more information.
|
||||||
def <=>(other)
|
def <=>(other)
|
||||||
@level <=> other.level
|
@level <=> other.level
|
||||||
end
|
end
|
||||||
|
|
||||||
# Whether to output messages to the output method, depending on the level
|
# Whether to output messages to the output method, depending on the level
|
||||||
# of this notifier object.
|
# of this notifier object.
|
||||||
def notify?
|
def notify?
|
||||||
@base_notifier.level >= self
|
@base_notifier.level >= self
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -214,15 +214,15 @@ module IRB
|
||||||
class NoMsgNotifier<LeveledNotifier
|
class NoMsgNotifier<LeveledNotifier
|
||||||
# Creates a new notifier that should not be used to output messages.
|
# Creates a new notifier that should not be used to output messages.
|
||||||
def initialize
|
def initialize
|
||||||
@base_notifier = nil
|
@base_notifier = nil
|
||||||
@level = 0
|
@level = 0
|
||||||
@prefix = ""
|
@prefix = ""
|
||||||
end
|
end
|
||||||
|
|
||||||
# Ensures notifications are ignored, see AbstractNotifier#notify? for
|
# Ensures notifications are ignored, see AbstractNotifier#notify? for
|
||||||
# more information.
|
# more information.
|
||||||
def notify?
|
def notify?
|
||||||
false
|
false
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -22,7 +22,7 @@ class RubyLex
|
||||||
def_exception(:TkReading2TokenNoKey, "key nothing(key='%s')")
|
def_exception(:TkReading2TokenNoKey, "key nothing(key='%s')")
|
||||||
def_exception(:TkSymbol2TokenNoKey, "key nothing(key='%s')")
|
def_exception(:TkSymbol2TokenNoKey, "key nothing(key='%s')")
|
||||||
def_exception(:TkReading2TokenDuplicateError,
|
def_exception(:TkReading2TokenDuplicateError,
|
||||||
"key duplicate(token_n='%s', key='%s')")
|
"key duplicate(token_n='%s', key='%s')")
|
||||||
def_exception(:SyntaxError, "%s")
|
def_exception(:SyntaxError, "%s")
|
||||||
|
|
||||||
def_exception(:TerminateLineInput, "Terminate Line Input")
|
def_exception(:TerminateLineInput, "Terminate Line Input")
|
||||||
|
@ -154,9 +154,9 @@ class RubyLex
|
||||||
if c == "\n"
|
if c == "\n"
|
||||||
@line_no -= 1
|
@line_no -= 1
|
||||||
if idx = @readed.rindex("\n")
|
if idx = @readed.rindex("\n")
|
||||||
@char_no = idx + 1
|
@char_no = idx + 1
|
||||||
else
|
else
|
||||||
@char_no = @base_char_no + @readed.size
|
@char_no = @base_char_no + @readed.size
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
@char_no -= 1
|
@char_no -= 1
|
||||||
|
@ -231,41 +231,41 @@ class RubyLex
|
||||||
initialize_input
|
initialize_input
|
||||||
catch(:TERM_INPUT) do
|
catch(:TERM_INPUT) do
|
||||||
loop do
|
loop do
|
||||||
begin
|
begin
|
||||||
@continue = false
|
@continue = false
|
||||||
prompt
|
prompt
|
||||||
unless l = lex
|
unless l = lex
|
||||||
throw :TERM_INPUT if @line == ''
|
throw :TERM_INPUT if @line == ''
|
||||||
else
|
else
|
||||||
@line.concat l
|
@line.concat l
|
||||||
if @ltype or @continue or @indent > 0
|
if @ltype or @continue or @indent > 0
|
||||||
next
|
next
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
if @line != "\n"
|
if @line != "\n"
|
||||||
@line.force_encoding(@io.encoding)
|
@line.force_encoding(@io.encoding)
|
||||||
yield @line, @exp_line_no
|
yield @line, @exp_line_no
|
||||||
end
|
end
|
||||||
break unless l
|
break unless l
|
||||||
@line = ''
|
@line = ''
|
||||||
@exp_line_no = @line_no
|
@exp_line_no = @line_no
|
||||||
|
|
||||||
@indent = 0
|
@indent = 0
|
||||||
@indent_stack = []
|
@indent_stack = []
|
||||||
prompt
|
prompt
|
||||||
rescue TerminateLineInput
|
rescue TerminateLineInput
|
||||||
initialize_input
|
initialize_input
|
||||||
prompt
|
prompt
|
||||||
get_readed
|
get_readed
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def lex
|
def lex
|
||||||
until (((tk = token).kind_of?(TkNL) || tk.kind_of?(TkEND_OF_SCRIPT)) &&
|
until (((tk = token).kind_of?(TkNL) || tk.kind_of?(TkEND_OF_SCRIPT)) &&
|
||||||
!@continue or
|
!@continue or
|
||||||
tk.nil?)
|
tk.nil?)
|
||||||
#p tk
|
#p tk
|
||||||
#p @lex_state
|
#p @lex_state
|
||||||
#p self
|
#p self
|
||||||
|
@ -287,13 +287,13 @@ class RubyLex
|
||||||
@prev_char_no = @char_no
|
@prev_char_no = @char_no
|
||||||
begin
|
begin
|
||||||
begin
|
begin
|
||||||
tk = @OP.match(self)
|
tk = @OP.match(self)
|
||||||
@space_seen = tk.kind_of?(TkSPACE)
|
@space_seen = tk.kind_of?(TkSPACE)
|
||||||
@lex_state = EXPR_END if @post_symbeg && tk.kind_of?(TkOp)
|
@lex_state = EXPR_END if @post_symbeg && tk.kind_of?(TkOp)
|
||||||
@post_symbeg = tk.kind_of?(TkSYMBEG)
|
@post_symbeg = tk.kind_of?(TkSYMBEG)
|
||||||
rescue SyntaxError
|
rescue SyntaxError
|
||||||
raise 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)
|
||||||
if @readed_auto_clean_up
|
if @readed_auto_clean_up
|
||||||
|
@ -361,12 +361,12 @@ class RubyLex
|
||||||
end
|
end
|
||||||
|
|
||||||
@OP.def_rule("=begin",
|
@OP.def_rule("=begin",
|
||||||
proc{|op, io| @prev_char_no == 0 && peek(0) =~ /\s/}) do
|
proc{|op, io| @prev_char_no == 0 && peek(0) =~ /\s/}) do
|
||||||
|op, io|
|
|op, io|
|
||||||
@ltype = "="
|
@ltype = "="
|
||||||
until getc == "\n"; end
|
until getc == "\n"; end
|
||||||
until peek_equal?("=end") && peek(4) =~ /\s/
|
until peek_equal?("=end") && peek(4) =~ /\s/
|
||||||
until getc == "\n"; end
|
until getc == "\n"; end
|
||||||
end
|
end
|
||||||
gets
|
gets
|
||||||
@ltype = nil
|
@ltype = nil
|
||||||
|
@ -377,15 +377,15 @@ class RubyLex
|
||||||
print "\\n\n" if RubyLex.debug?
|
print "\\n\n" if RubyLex.debug?
|
||||||
case @lex_state
|
case @lex_state
|
||||||
when EXPR_BEG, EXPR_FNAME, EXPR_DOT
|
when EXPR_BEG, EXPR_FNAME, EXPR_DOT
|
||||||
@continue = true
|
@continue = true
|
||||||
else
|
else
|
||||||
@continue = false
|
@continue = false
|
||||||
@lex_state = EXPR_BEG
|
@lex_state = EXPR_BEG
|
||||||
until (@indent_stack.empty? ||
|
until (@indent_stack.empty? ||
|
||||||
[TkLPAREN, TkLBRACK, TkLBRACE,
|
[TkLPAREN, TkLBRACK, TkLBRACE,
|
||||||
TkfLPAREN, TkfLBRACK, TkfLBRACE].include?(@indent_stack.last))
|
TkfLPAREN, TkfLBRACK, TkfLBRACE].include?(@indent_stack.last))
|
||||||
@indent_stack.pop
|
@indent_stack.pop
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@here_header = false
|
@here_header = false
|
||||||
@here_readed = []
|
@here_readed = []
|
||||||
|
@ -393,17 +393,17 @@ class RubyLex
|
||||||
end
|
end
|
||||||
|
|
||||||
@OP.def_rules("*", "**",
|
@OP.def_rules("*", "**",
|
||||||
"=", "==", "===",
|
"=", "==", "===",
|
||||||
"=~", "<=>",
|
"=~", "<=>",
|
||||||
"<", "<=",
|
"<", "<=",
|
||||||
">", ">=", ">>",
|
">", ">=", ">>",
|
||||||
"!", "!=", "!~") do
|
"!", "!=", "!~") do
|
||||||
|op, io|
|
|op, io|
|
||||||
case @lex_state
|
case @lex_state
|
||||||
when EXPR_FNAME, EXPR_DOT
|
when EXPR_FNAME, EXPR_DOT
|
||||||
@lex_state = EXPR_ARG
|
@lex_state = EXPR_ARG
|
||||||
else
|
else
|
||||||
@lex_state = EXPR_BEG
|
@lex_state = EXPR_BEG
|
||||||
end
|
end
|
||||||
Token(op)
|
Token(op)
|
||||||
end
|
end
|
||||||
|
@ -412,20 +412,20 @@ class RubyLex
|
||||||
|op, io|
|
|op, io|
|
||||||
tk = nil
|
tk = nil
|
||||||
if @lex_state != EXPR_END && @lex_state != EXPR_CLASS &&
|
if @lex_state != EXPR_END && @lex_state != EXPR_CLASS &&
|
||||||
(@lex_state != EXPR_ARG || @space_seen)
|
(@lex_state != EXPR_ARG || @space_seen)
|
||||||
c = peek(0)
|
c = peek(0)
|
||||||
if /\S/ =~ c && (/["'`]/ =~ c || /\w/ =~ c || c == "-")
|
if /\S/ =~ c && (/["'`]/ =~ c || /\w/ =~ c || c == "-")
|
||||||
tk = identify_here_document
|
tk = identify_here_document
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
unless tk
|
unless tk
|
||||||
tk = Token(op)
|
tk = Token(op)
|
||||||
case @lex_state
|
case @lex_state
|
||||||
when EXPR_FNAME, EXPR_DOT
|
when EXPR_FNAME, EXPR_DOT
|
||||||
@lex_state = EXPR_ARG
|
@lex_state = EXPR_ARG
|
||||||
else
|
else
|
||||||
@lex_state = EXPR_BEG
|
@lex_state = EXPR_BEG
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
tk
|
tk
|
||||||
end
|
end
|
||||||
|
@ -438,31 +438,31 @@ 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
|
@lex_state = EXPR_END
|
||||||
Token(op)
|
Token(op)
|
||||||
else
|
else
|
||||||
identify_string(op)
|
identify_string(op)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@OP.def_rules('?') do
|
@OP.def_rules('?') do
|
||||||
|op, io|
|
|op, io|
|
||||||
if @lex_state == EXPR_END
|
if @lex_state == EXPR_END
|
||||||
@lex_state = EXPR_BEG
|
@lex_state = EXPR_BEG
|
||||||
Token(TkQUESTION)
|
Token(TkQUESTION)
|
||||||
else
|
else
|
||||||
ch = getc
|
ch = getc
|
||||||
if @lex_state == EXPR_ARG && ch =~ /\s/
|
if @lex_state == EXPR_ARG && ch =~ /\s/
|
||||||
ungetc
|
ungetc
|
||||||
@lex_state = EXPR_BEG;
|
@lex_state = EXPR_BEG;
|
||||||
Token(TkQUESTION)
|
Token(TkQUESTION)
|
||||||
else
|
else
|
||||||
if (ch == '\\')
|
if (ch == '\\')
|
||||||
read_escape
|
read_escape
|
||||||
end
|
end
|
||||||
@lex_state = EXPR_END
|
@lex_state = EXPR_END
|
||||||
Token(TkINTEGER)
|
Token(TkINTEGER)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -473,7 +473,7 @@ class RubyLex
|
||||||
end
|
end
|
||||||
|
|
||||||
@OP.def_rules("+=", "-=", "*=", "**=",
|
@OP.def_rules("+=", "-=", "*=", "**=",
|
||||||
"&=", "|=", "^=", "<<=", ">>=", "||=", "&&=") do
|
"&=", "|=", "^=", "<<=", ">>=", "||=", "&&=") do
|
||||||
|op, io|
|
|op, io|
|
||||||
@lex_state = EXPR_BEG
|
@lex_state = EXPR_BEG
|
||||||
op =~ /^(.*)=$/
|
op =~ /^(.*)=$/
|
||||||
|
@ -495,18 +495,18 @@ class RubyLex
|
||||||
@OP.def_rules("+", "-") do
|
@OP.def_rules("+", "-") do
|
||||||
|op, io|
|
|op, io|
|
||||||
catch(:RET) do
|
catch(:RET) do
|
||||||
if @lex_state == EXPR_ARG
|
if @lex_state == EXPR_ARG
|
||||||
if @space_seen and peek(0) =~ /[0-9]/
|
if @space_seen and peek(0) =~ /[0-9]/
|
||||||
throw :RET, identify_number
|
throw :RET, identify_number
|
||||||
else
|
else
|
||||||
@lex_state = EXPR_BEG
|
@lex_state = EXPR_BEG
|
||||||
end
|
end
|
||||||
elsif @lex_state != EXPR_END and peek(0) =~ /[0-9]/
|
elsif @lex_state != EXPR_END and peek(0) =~ /[0-9]/
|
||||||
throw :RET, identify_number
|
throw :RET, identify_number
|
||||||
else
|
else
|
||||||
@lex_state = EXPR_BEG
|
@lex_state = EXPR_BEG
|
||||||
end
|
end
|
||||||
Token(op)
|
Token(op)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -514,12 +514,12 @@ class RubyLex
|
||||||
|op, io|
|
|op, io|
|
||||||
@lex_state = EXPR_BEG
|
@lex_state = EXPR_BEG
|
||||||
if peek(0) =~ /[0-9]/
|
if peek(0) =~ /[0-9]/
|
||||||
ungetc
|
ungetc
|
||||||
identify_number
|
identify_number
|
||||||
else
|
else
|
||||||
# for "obj.if" etc.
|
# for "obj.if" etc.
|
||||||
@lex_state = EXPR_DOT
|
@lex_state = EXPR_DOT
|
||||||
Token(TkDOT)
|
Token(TkDOT)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -544,11 +544,11 @@ class RubyLex
|
||||||
@OP.def_rule(":") do
|
@OP.def_rule(":") do
|
||||||
|op, io|
|
|op, io|
|
||||||
if @lex_state == EXPR_END || peek(0) =~ /\s/
|
if @lex_state == EXPR_END || peek(0) =~ /\s/
|
||||||
@lex_state = EXPR_BEG
|
@lex_state = EXPR_BEG
|
||||||
Token(TkCOLON)
|
Token(TkCOLON)
|
||||||
else
|
else
|
||||||
@lex_state = EXPR_FNAME
|
@lex_state = EXPR_FNAME
|
||||||
Token(TkSYMBEG)
|
Token(TkSYMBEG)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -556,27 +556,27 @@ class RubyLex
|
||||||
|op, io|
|
|op, io|
|
||||||
# p @lex_state.id2name, @space_seen
|
# p @lex_state.id2name, @space_seen
|
||||||
if @lex_state == EXPR_BEG or @lex_state == EXPR_ARG && @space_seen
|
if @lex_state == EXPR_BEG or @lex_state == EXPR_ARG && @space_seen
|
||||||
@lex_state = EXPR_BEG
|
@lex_state = EXPR_BEG
|
||||||
Token(TkCOLON3)
|
Token(TkCOLON3)
|
||||||
else
|
else
|
||||||
@lex_state = EXPR_DOT
|
@lex_state = EXPR_DOT
|
||||||
Token(TkCOLON2)
|
Token(TkCOLON2)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@OP.def_rule("/") do
|
@OP.def_rule("/") do
|
||||||
|op, io|
|
|op, io|
|
||||||
if @lex_state == EXPR_BEG || @lex_state == EXPR_MID
|
if @lex_state == EXPR_BEG || @lex_state == EXPR_MID
|
||||||
identify_string(op)
|
identify_string(op)
|
||||||
elsif peek(0) == '='
|
elsif peek(0) == '='
|
||||||
getc
|
getc
|
||||||
@lex_state = EXPR_BEG
|
@lex_state = EXPR_BEG
|
||||||
Token(TkOPASGN, "/") #/)
|
Token(TkOPASGN, "/") #/)
|
||||||
elsif @lex_state == EXPR_ARG and @space_seen and peek(0) !~ /\s/
|
elsif @lex_state == EXPR_ARG and @space_seen and peek(0) !~ /\s/
|
||||||
identify_string(op)
|
identify_string(op)
|
||||||
else
|
else
|
||||||
@lex_state = EXPR_BEG
|
@lex_state = EXPR_BEG
|
||||||
Token("/") #/)
|
Token("/") #/)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -601,9 +601,9 @@ class RubyLex
|
||||||
|op, io|
|
|op, io|
|
||||||
@lex_state = EXPR_BEG
|
@lex_state = EXPR_BEG
|
||||||
until (@indent_stack.empty? ||
|
until (@indent_stack.empty? ||
|
||||||
[TkLPAREN, TkLBRACK, TkLBRACE,
|
[TkLPAREN, TkLBRACK, TkLBRACE,
|
||||||
TkfLPAREN, TkfLBRACK, TkfLBRACE].include?(@indent_stack.last))
|
TkfLPAREN, TkfLBRACK, TkfLBRACE].include?(@indent_stack.last))
|
||||||
@indent_stack.pop
|
@indent_stack.pop
|
||||||
end
|
end
|
||||||
Token(op)
|
Token(op)
|
||||||
end
|
end
|
||||||
|
@ -624,11 +624,11 @@ class RubyLex
|
||||||
|op, io|
|
|op, io|
|
||||||
@indent += 1
|
@indent += 1
|
||||||
if @lex_state == EXPR_BEG || @lex_state == EXPR_MID
|
if @lex_state == EXPR_BEG || @lex_state == EXPR_MID
|
||||||
@lex_state = EXPR_BEG
|
@lex_state = EXPR_BEG
|
||||||
tk_c = TkfLPAREN
|
tk_c = TkfLPAREN
|
||||||
else
|
else
|
||||||
@lex_state = EXPR_BEG
|
@lex_state = EXPR_BEG
|
||||||
tk_c = TkLPAREN
|
tk_c = TkLPAREN
|
||||||
end
|
end
|
||||||
@indent_stack.push tk_c
|
@indent_stack.push tk_c
|
||||||
Token(tk_c)
|
Token(tk_c)
|
||||||
|
@ -650,16 +650,16 @@ class RubyLex
|
||||||
|op, io|
|
|op, io|
|
||||||
@indent += 1
|
@indent += 1
|
||||||
if @lex_state == EXPR_FNAME
|
if @lex_state == EXPR_FNAME
|
||||||
tk_c = TkfLBRACK
|
tk_c = TkfLBRACK
|
||||||
else
|
else
|
||||||
if @lex_state == EXPR_BEG || @lex_state == EXPR_MID
|
if @lex_state == EXPR_BEG || @lex_state == EXPR_MID
|
||||||
tk_c = TkLBRACK
|
tk_c = TkLBRACK
|
||||||
elsif @lex_state == EXPR_ARG && @space_seen
|
elsif @lex_state == EXPR_ARG && @space_seen
|
||||||
tk_c = TkLBRACK
|
tk_c = TkLBRACK
|
||||||
else
|
else
|
||||||
tk_c = TkfLBRACK
|
tk_c = TkfLBRACK
|
||||||
end
|
end
|
||||||
@lex_state = EXPR_BEG
|
@lex_state = EXPR_BEG
|
||||||
end
|
end
|
||||||
@indent_stack.push tk_c
|
@indent_stack.push tk_c
|
||||||
Token(tk_c)
|
Token(tk_c)
|
||||||
|
@ -669,9 +669,9 @@ class RubyLex
|
||||||
|op, io|
|
|op, io|
|
||||||
@indent += 1
|
@indent += 1
|
||||||
if @lex_state != EXPR_END && @lex_state != EXPR_ARG
|
if @lex_state != EXPR_END && @lex_state != EXPR_ARG
|
||||||
tk_c = TkLBRACE
|
tk_c = TkLBRACE
|
||||||
else
|
else
|
||||||
tk_c = TkfLBRACE
|
tk_c = TkfLBRACE
|
||||||
end
|
end
|
||||||
@lex_state = EXPR_BEG
|
@lex_state = EXPR_BEG
|
||||||
@indent_stack.push tk_c
|
@indent_stack.push tk_c
|
||||||
|
@ -681,27 +681,27 @@ class RubyLex
|
||||||
@OP.def_rule('\\') do
|
@OP.def_rule('\\') do
|
||||||
|op, io|
|
|op, io|
|
||||||
if getc == "\n"
|
if getc == "\n"
|
||||||
@space_seen = true
|
@space_seen = true
|
||||||
@continue = true
|
@continue = true
|
||||||
Token(TkSPACE)
|
Token(TkSPACE)
|
||||||
else
|
else
|
||||||
read_escape
|
read_escape
|
||||||
Token("\\")
|
Token("\\")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@OP.def_rule('%') do
|
@OP.def_rule('%') do
|
||||||
|op, io|
|
|op, io|
|
||||||
if @lex_state == EXPR_BEG || @lex_state == EXPR_MID
|
if @lex_state == EXPR_BEG || @lex_state == EXPR_MID
|
||||||
identify_quotation
|
identify_quotation
|
||||||
elsif peek(0) == '='
|
elsif peek(0) == '='
|
||||||
getc
|
getc
|
||||||
Token(TkOPASGN, :%)
|
Token(TkOPASGN, :%)
|
||||||
elsif @lex_state == EXPR_ARG and @space_seen and peek(0) !~ /\s/
|
elsif @lex_state == EXPR_ARG and @space_seen and peek(0) !~ /\s/
|
||||||
identify_quotation
|
identify_quotation
|
||||||
else
|
else
|
||||||
@lex_state = EXPR_BEG
|
@lex_state = EXPR_BEG
|
||||||
Token("%") #))
|
Token("%") #))
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -713,10 +713,10 @@ class RubyLex
|
||||||
@OP.def_rule('@') do
|
@OP.def_rule('@') do
|
||||||
|op, io|
|
|op, io|
|
||||||
if peek(0) =~ /[\w@]/
|
if peek(0) =~ /[\w@]/
|
||||||
ungetc
|
ungetc
|
||||||
identify_identifier
|
identify_identifier
|
||||||
else
|
else
|
||||||
Token("@")
|
Token("@")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -734,9 +734,9 @@ class RubyLex
|
||||||
|op, io|
|
|op, io|
|
||||||
printf "MATCH: start %s: %s\n", op, io.inspect if RubyLex.debug?
|
printf "MATCH: start %s: %s\n", op, io.inspect if RubyLex.debug?
|
||||||
if peek(0) =~ /[0-9]/
|
if peek(0) =~ /[0-9]/
|
||||||
t = identify_number
|
t = identify_number
|
||||||
elsif peek(0) =~ /[^\x00-\/:-@\[-^`{-\x7F]/
|
elsif peek(0) =~ /[^\x00-\/:-@\[-^`{-\x7F]/
|
||||||
t = identify_identifier
|
t = identify_identifier
|
||||||
end
|
end
|
||||||
printf "MATCH: end %s: %s\n", op, io.inspect if RubyLex.debug?
|
printf "MATCH: end %s: %s\n", op, io.inspect if RubyLex.debug?
|
||||||
t
|
t
|
||||||
|
@ -774,7 +774,7 @@ class RubyLex
|
||||||
if peek(0) =~ /[$@]/
|
if peek(0) =~ /[$@]/
|
||||||
token.concat(c = getc)
|
token.concat(c = getc)
|
||||||
if c == "@" and peek(0) == "@"
|
if c == "@" and peek(0) == "@"
|
||||||
token.concat getc
|
token.concat getc
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -807,61 +807,61 @@ class RubyLex
|
||||||
|
|
||||||
token_c, *trans = TkReading2Token[token]
|
token_c, *trans = TkReading2Token[token]
|
||||||
if token_c
|
if token_c
|
||||||
# reserved word?
|
# reserved word?
|
||||||
|
|
||||||
if (@lex_state != EXPR_BEG &&
|
if (@lex_state != EXPR_BEG &&
|
||||||
@lex_state != EXPR_FNAME &&
|
@lex_state != EXPR_FNAME &&
|
||||||
trans[1])
|
trans[1])
|
||||||
# modifiers
|
# modifiers
|
||||||
token_c = TkSymbol2Token[trans[1]]
|
token_c = TkSymbol2Token[trans[1]]
|
||||||
@lex_state = trans[0]
|
@lex_state = trans[0]
|
||||||
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'' etc.
|
# 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*(([+\-\/*&\|^]|<<|>>|\|\||\&\&)=|\&\&|\|\|)/)
|
||||||
when "do"
|
when "do"
|
||||||
valid = false if peek_match?(/^\s*([+\-\/*]?=|\*|<|>|\&)/)
|
valid = false if peek_match?(/^\s*([+\-\/*]?=|\*|<|>|\&)/)
|
||||||
when *ENINDENT_CLAUSE
|
when *ENINDENT_CLAUSE
|
||||||
valid = false if peek_match?(/^\s*([+\-\/*]?=|\*|<|>|\&|\|)/)
|
valid = false if peek_match?(/^\s*([+\-\/*]?=|\*|<|>|\&|\|)/)
|
||||||
else
|
else
|
||||||
# no nothing
|
# no nothing
|
||||||
end
|
end
|
||||||
if valid
|
if valid
|
||||||
if token == "do"
|
if token == "do"
|
||||||
if ![TkFOR, TkWHILE, TkUNTIL].include?(@indent_stack.last)
|
if ![TkFOR, TkWHILE, TkUNTIL].include?(@indent_stack.last)
|
||||||
@indent += 1
|
@indent += 1
|
||||||
@indent_stack.push token_c
|
@indent_stack.push token_c
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
@indent += 1
|
@indent += 1
|
||||||
@indent_stack.push token_c
|
@indent_stack.push token_c
|
||||||
end
|
end
|
||||||
# p @indent_stack
|
# p @indent_stack
|
||||||
end
|
end
|
||||||
|
|
||||||
elsif DEINDENT_CLAUSE.include?(token)
|
elsif DEINDENT_CLAUSE.include?(token)
|
||||||
@indent -= 1
|
@indent -= 1
|
||||||
@indent_stack.pop
|
@indent_stack.pop
|
||||||
end
|
end
|
||||||
@lex_state = trans[0]
|
@lex_state = trans[0]
|
||||||
else
|
else
|
||||||
@lex_state = EXPR_END
|
@lex_state = EXPR_END
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
return Token(token_c, token)
|
return Token(token_c, token)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
if @lex_state == EXPR_FNAME
|
if @lex_state == EXPR_FNAME
|
||||||
@lex_state = EXPR_END
|
@lex_state = EXPR_END
|
||||||
if peek(0) == '='
|
if peek(0) == '='
|
||||||
token.concat getc
|
token.concat getc
|
||||||
end
|
end
|
||||||
elsif @lex_state == EXPR_BEG || @lex_state == EXPR_DOT
|
elsif @lex_state == EXPR_BEG || @lex_state == EXPR_DOT
|
||||||
@lex_state = EXPR_ARG
|
@lex_state = EXPR_ARG
|
||||||
|
@ -889,13 +889,13 @@ class RubyLex
|
||||||
lt = ch
|
lt = ch
|
||||||
quoted = ""
|
quoted = ""
|
||||||
while (c = getc) && c != lt
|
while (c = getc) && c != lt
|
||||||
quoted.concat c
|
quoted.concat c
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
lt = '"'
|
lt = '"'
|
||||||
quoted = ch.dup
|
quoted = ch.dup
|
||||||
while (c = getc) && c =~ /\w/
|
while (c = getc) && c =~ /\w/
|
||||||
quoted.concat c
|
quoted.concat c
|
||||||
end
|
end
|
||||||
ungetc
|
ungetc
|
||||||
end
|
end
|
||||||
|
@ -905,9 +905,9 @@ class RubyLex
|
||||||
while ch = getc
|
while ch = getc
|
||||||
reserve.push ch
|
reserve.push ch
|
||||||
if ch == "\\"
|
if ch == "\\"
|
||||||
reserve.push ch = getc
|
reserve.push ch = getc
|
||||||
elsif ch == "\n"
|
elsif ch == "\n"
|
||||||
break
|
break
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -922,15 +922,15 @@ class RubyLex
|
||||||
line = ""
|
line = ""
|
||||||
while ch = getc
|
while ch = getc
|
||||||
if ch == "\n"
|
if ch == "\n"
|
||||||
if line == quoted
|
if line == quoted
|
||||||
break
|
break
|
||||||
end
|
end
|
||||||
line = ""
|
line = ""
|
||||||
else
|
else
|
||||||
line.concat ch unless indent && line == "" && /\s/ =~ ch
|
line.concat ch unless indent && line == "" && /\s/ =~ ch
|
||||||
if @ltype != "'" && ch == "#" && peek(0) == "{"
|
if @ltype != "'" && ch == "#" && peek(0) == "{"
|
||||||
identify_string_dvar
|
identify_string_dvar
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -970,49 +970,49 @@ class RubyLex
|
||||||
getc
|
getc
|
||||||
case peek(0)
|
case peek(0)
|
||||||
when /[xX]/
|
when /[xX]/
|
||||||
ch = getc
|
ch = getc
|
||||||
match = /[0-9a-fA-F_]/
|
match = /[0-9a-fA-F_]/
|
||||||
when /[bB]/
|
when /[bB]/
|
||||||
ch = getc
|
ch = getc
|
||||||
match = /[01_]/
|
match = /[01_]/
|
||||||
when /[oO]/
|
when /[oO]/
|
||||||
ch = getc
|
ch = getc
|
||||||
match = /[0-7_]/
|
match = /[0-7_]/
|
||||||
when /[dD]/
|
when /[dD]/
|
||||||
ch = getc
|
ch = getc
|
||||||
match = /[0-9_]/
|
match = /[0-9_]/
|
||||||
when /[0-7]/
|
when /[0-7]/
|
||||||
match = /[0-7_]/
|
match = /[0-7_]/
|
||||||
when /[89]/
|
when /[89]/
|
||||||
RubyLex.fail SyntaxError, "Invalid octal digit"
|
RubyLex.fail SyntaxError, "Invalid octal digit"
|
||||||
else
|
else
|
||||||
return Token(TkINTEGER)
|
return Token(TkINTEGER)
|
||||||
end
|
end
|
||||||
|
|
||||||
len0 = true
|
len0 = true
|
||||||
non_digit = false
|
non_digit = false
|
||||||
while ch = getc
|
while ch = getc
|
||||||
if match =~ ch
|
if match =~ ch
|
||||||
if ch == "_"
|
if ch == "_"
|
||||||
if non_digit
|
if non_digit
|
||||||
RubyLex.fail SyntaxError, "trailing `#{ch}' in number"
|
RubyLex.fail SyntaxError, "trailing `#{ch}' in number"
|
||||||
else
|
else
|
||||||
non_digit = ch
|
non_digit = ch
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
non_digit = false
|
non_digit = false
|
||||||
len0 = false
|
len0 = false
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
ungetc
|
ungetc
|
||||||
if len0
|
if len0
|
||||||
RubyLex.fail SyntaxError, "numeric literal without digits"
|
RubyLex.fail SyntaxError, "numeric literal without digits"
|
||||||
end
|
end
|
||||||
if non_digit
|
if non_digit
|
||||||
RubyLex.fail SyntaxError, "trailing `#{non_digit}' in number"
|
RubyLex.fail SyntaxError, "trailing `#{non_digit}' in number"
|
||||||
end
|
end
|
||||||
break
|
break
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
return Token(TkINTEGER)
|
return Token(TkINTEGER)
|
||||||
end
|
end
|
||||||
|
@ -1024,37 +1024,37 @@ class RubyLex
|
||||||
while ch = getc
|
while ch = getc
|
||||||
case ch
|
case ch
|
||||||
when /[0-9]/
|
when /[0-9]/
|
||||||
non_digit = false
|
non_digit = false
|
||||||
when "_"
|
when "_"
|
||||||
non_digit = ch
|
non_digit = ch
|
||||||
when allow_point && "."
|
when allow_point && "."
|
||||||
if non_digit
|
if non_digit
|
||||||
RubyLex.fail SyntaxError, "trailing `#{non_digit}' in number"
|
RubyLex.fail SyntaxError, "trailing `#{non_digit}' in number"
|
||||||
end
|
end
|
||||||
type = TkFLOAT
|
type = TkFLOAT
|
||||||
if peek(0) !~ /[0-9]/
|
if peek(0) !~ /[0-9]/
|
||||||
type = TkINTEGER
|
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
|
if non_digit
|
||||||
RubyLex.fail SyntaxError, "trailing `#{non_digit}' in number"
|
RubyLex.fail SyntaxError, "trailing `#{non_digit}' in number"
|
||||||
end
|
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
|
non_digit = ch
|
||||||
else
|
else
|
||||||
if non_digit
|
if non_digit
|
||||||
RubyLex.fail SyntaxError, "trailing `#{non_digit}' in number"
|
RubyLex.fail SyntaxError, "trailing `#{non_digit}' in number"
|
||||||
end
|
end
|
||||||
ungetc
|
ungetc
|
||||||
break
|
break
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
Token(type)
|
Token(type)
|
||||||
|
@ -1067,38 +1067,38 @@ class RubyLex
|
||||||
begin
|
begin
|
||||||
nest = 0
|
nest = 0
|
||||||
while ch = getc
|
while ch = getc
|
||||||
if @quoted == ch and nest == 0
|
if @quoted == ch and nest == 0
|
||||||
break
|
break
|
||||||
elsif @ltype != "'" && ch == "#" && peek(0) == "{"
|
elsif @ltype != "'" && ch == "#" && peek(0) == "{"
|
||||||
identify_string_dvar
|
identify_string_dvar
|
||||||
elsif @ltype != "'" && @ltype != "]" && @ltype != ":" and ch == "#"
|
elsif @ltype != "'" && @ltype != "]" && @ltype != ":" and ch == "#"
|
||||||
subtype = true
|
subtype = true
|
||||||
elsif ch == '\\' and @ltype == "'" #'
|
elsif ch == '\\' and @ltype == "'" #'
|
||||||
case ch = getc
|
case ch = getc
|
||||||
when "\\", "\n", "'"
|
when "\\", "\n", "'"
|
||||||
else
|
else
|
||||||
ungetc
|
ungetc
|
||||||
end
|
end
|
||||||
elsif ch == '\\' #'
|
elsif ch == '\\' #'
|
||||||
read_escape
|
read_escape
|
||||||
end
|
end
|
||||||
if PERCENT_PAREN.values.include?(@quoted)
|
if PERCENT_PAREN.values.include?(@quoted)
|
||||||
if PERCENT_PAREN[ch] == @quoted
|
if PERCENT_PAREN[ch] == @quoted
|
||||||
nest += 1
|
nest += 1
|
||||||
elsif ch == @quoted
|
elsif ch == @quoted
|
||||||
nest -= 1
|
nest -= 1
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
if @ltype == "/"
|
if @ltype == "/"
|
||||||
while /[imxoesun]/ =~ peek(0)
|
while /[imxoesun]/ =~ peek(0)
|
||||||
getc
|
getc
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
if subtype
|
if subtype
|
||||||
Token(DLtype2Token[ltype])
|
Token(DLtype2Token[ltype])
|
||||||
else
|
else
|
||||||
Token(Ltype2Token[ltype])
|
Token(Ltype2Token[ltype])
|
||||||
end
|
end
|
||||||
ensure
|
ensure
|
||||||
@ltype = nil
|
@ltype = nil
|
||||||
|
@ -1125,13 +1125,13 @@ class RubyLex
|
||||||
@lex_state = EXPR_BEG
|
@lex_state = EXPR_BEG
|
||||||
|
|
||||||
loop do
|
loop do
|
||||||
@continue = false
|
@continue = false
|
||||||
prompt
|
prompt
|
||||||
tk = token
|
tk = token
|
||||||
if @ltype or @continue or @indent >= 0
|
if @ltype or @continue or @indent >= 0
|
||||||
next
|
next
|
||||||
end
|
end
|
||||||
break if tk.kind_of?(TkRBRACE)
|
break if tk.kind_of?(TkRBRACE)
|
||||||
end
|
end
|
||||||
ensure
|
ensure
|
||||||
@continue = reserve_continue
|
@continue = reserve_continue
|
||||||
|
@ -1151,9 +1151,9 @@ class RubyLex
|
||||||
# read_escape
|
# read_escape
|
||||||
# end
|
# end
|
||||||
if ch == "\n"
|
if ch == "\n"
|
||||||
@ltype = nil
|
@ltype = nil
|
||||||
ungetc
|
ungetc
|
||||||
break
|
break
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
return Token(TkCOMMENT)
|
return Token(TkCOMMENT)
|
||||||
|
@ -1166,42 +1166,42 @@ class RubyLex
|
||||||
when /[0-7]/
|
when /[0-7]/
|
||||||
ungetc ch
|
ungetc ch
|
||||||
3.times do
|
3.times do
|
||||||
case ch = getc
|
case ch = getc
|
||||||
when /[0-7]/
|
when /[0-7]/
|
||||||
when nil
|
when nil
|
||||||
break
|
break
|
||||||
else
|
else
|
||||||
ungetc
|
ungetc
|
||||||
break
|
break
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
when "x"
|
when "x"
|
||||||
2.times do
|
2.times do
|
||||||
case ch = getc
|
case ch = getc
|
||||||
when /[0-9a-fA-F]/
|
when /[0-9a-fA-F]/
|
||||||
when nil
|
when nil
|
||||||
break
|
break
|
||||||
else
|
else
|
||||||
ungetc
|
ungetc
|
||||||
break
|
break
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
when "M"
|
when "M"
|
||||||
if (ch = getc) != '-'
|
if (ch = getc) != '-'
|
||||||
ungetc
|
ungetc
|
||||||
else
|
else
|
||||||
if (ch = getc) == "\\" #"
|
if (ch = getc) == "\\" #"
|
||||||
read_escape
|
read_escape
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
when "C", "c" #, "^"
|
when "C", "c" #, "^"
|
||||||
if ch == "C" and (ch = getc) != "-"
|
if ch == "C" and (ch = getc) != "-"
|
||||||
ungetc
|
ungetc
|
||||||
elsif (ch = getc) == "\\" #"
|
elsif (ch = getc) == "\\" #"
|
||||||
read_escape
|
read_escape
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
# other characters
|
# other characters
|
||||||
|
|
|
@ -78,23 +78,23 @@ module RubyToken
|
||||||
case token
|
case token
|
||||||
when String
|
when String
|
||||||
if (tk = TkReading2Token[token]).nil?
|
if (tk = TkReading2Token[token]).nil?
|
||||||
IRB.fail TkReading2TokenNoKey, token
|
IRB.fail TkReading2TokenNoKey, token
|
||||||
end
|
end
|
||||||
tk = Token(tk[0], value)
|
tk = Token(tk[0], value)
|
||||||
if tk.kind_of?(TkOp)
|
if tk.kind_of?(TkOp)
|
||||||
tk.name = token
|
tk.name = token
|
||||||
end
|
end
|
||||||
return tk
|
return tk
|
||||||
when Symbol
|
when Symbol
|
||||||
if (tk = TkSymbol2Token[token]).nil?
|
if (tk = TkSymbol2Token[token]).nil?
|
||||||
IRB.fail TkSymbol2TokenNoKey, token
|
IRB.fail TkSymbol2TokenNoKey, token
|
||||||
end
|
end
|
||||||
return Token(tk[0], value)
|
return Token(tk[0], value)
|
||||||
else
|
else
|
||||||
if (token.ancestors & [TkId, TkVal, TkOPASGN, TkUnknownChar]).empty?
|
if (token.ancestors & [TkId, TkVal, TkOPASGN, TkUnknownChar]).empty?
|
||||||
token.new(@prev_seek, @prev_line_no, @prev_char_no)
|
token.new(@prev_seek, @prev_line_no, @prev_char_no)
|
||||||
else
|
else
|
||||||
token.new(@prev_seek, @prev_line_no, @prev_char_no, value)
|
token.new(@prev_seek, @prev_line_no, @prev_char_no, value)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -249,12 +249,12 @@ module RubyToken
|
||||||
|
|
||||||
if reading
|
if reading
|
||||||
if TkReading2Token[reading]
|
if TkReading2Token[reading]
|
||||||
IRB.fail TkReading2TokenDuplicateError, token_n, reading
|
IRB.fail TkReading2TokenDuplicateError, token_n, reading
|
||||||
end
|
end
|
||||||
if opts.empty?
|
if opts.empty?
|
||||||
TkReading2Token[reading] = [token_c]
|
TkReading2Token[reading] = [token_c]
|
||||||
else
|
else
|
||||||
TkReading2Token[reading] = [token_c].concat(opts)
|
TkReading2Token[reading] = [token_c].concat(opts)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
TkSymbol2Token[token_n.intern] = token_c
|
TkSymbol2Token[token_n.intern] = token_c
|
||||||
|
|
258
lib/irb/slex.rb
258
lib/irb/slex.rb
|
@ -41,10 +41,10 @@ module IRB
|
||||||
|
|
||||||
def def_rules(*tokens, &block)
|
def def_rules(*tokens, &block)
|
||||||
if block_given?
|
if block_given?
|
||||||
p = block
|
p = block
|
||||||
end
|
end
|
||||||
for token in tokens
|
for token in tokens
|
||||||
def_rule(token, nil, p)
|
def_rule(token, nil, p)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -71,9 +71,9 @@ module IRB
|
||||||
case token
|
case token
|
||||||
when Array
|
when Array
|
||||||
when String
|
when String
|
||||||
return match(token.split(//))
|
return match(token.split(//))
|
||||||
else
|
else
|
||||||
return @head.match_io(token)
|
return @head.match_io(token)
|
||||||
end
|
end
|
||||||
ret = @head.match(token)
|
ret = @head.match(token)
|
||||||
D_DETAIL.exec_if{D_DETAIL.printf "match end: %s:%s\n", ret, token.inspect}
|
D_DETAIL.exec_if{D_DETAIL.printf "match end: %s:%s\n", ret, token.inspect}
|
||||||
|
@ -93,69 +93,69 @@ module IRB
|
||||||
# if postproc is nil, this node is an abstract node.
|
# if postproc is nil, this node is an abstract node.
|
||||||
# if postproc is non-nil, this node is a real node.
|
# if postproc is non-nil, this node is a real node.
|
||||||
def initialize(preproc = nil, postproc = nil)
|
def initialize(preproc = nil, postproc = nil)
|
||||||
@Tree = {}
|
@Tree = {}
|
||||||
@preproc = preproc
|
@preproc = preproc
|
||||||
@postproc = postproc
|
@postproc = postproc
|
||||||
end
|
end
|
||||||
|
|
||||||
attr_accessor :preproc
|
attr_accessor :preproc
|
||||||
attr_accessor :postproc
|
attr_accessor :postproc
|
||||||
|
|
||||||
def search(chrs, opt = nil)
|
def search(chrs, opt = nil)
|
||||||
return self if chrs.empty?
|
return self if chrs.empty?
|
||||||
ch = chrs.shift
|
ch = chrs.shift
|
||||||
if node = @Tree[ch]
|
if node = @Tree[ch]
|
||||||
node.search(chrs, opt)
|
node.search(chrs, opt)
|
||||||
else
|
else
|
||||||
if opt
|
if opt
|
||||||
chrs.unshift ch
|
chrs.unshift ch
|
||||||
self.create_subnode(chrs)
|
self.create_subnode(chrs)
|
||||||
else
|
else
|
||||||
SLex.fail ErrNodeNothing
|
SLex.fail ErrNodeNothing
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
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
|
D_DETAIL.pp node
|
||||||
SLex.fail ErrNodeAlreadyExists
|
SLex.fail ErrNodeAlreadyExists
|
||||||
else
|
else
|
||||||
D_DEBUG.puts "change abstract node to real node."
|
D_DEBUG.puts "change abstract node to real node."
|
||||||
@preproc = preproc
|
@preproc = preproc
|
||||||
@postproc = postproc
|
@postproc = postproc
|
||||||
end
|
end
|
||||||
return self
|
return self
|
||||||
end
|
end
|
||||||
|
|
||||||
ch = chrs.shift
|
ch = chrs.shift
|
||||||
if node = @Tree[ch]
|
if node = @Tree[ch]
|
||||||
if chrs.empty?
|
if chrs.empty?
|
||||||
if node.postproc
|
if node.postproc
|
||||||
DebugLogger.pp node
|
DebugLogger.pp node
|
||||||
DebugLogger.pp self
|
DebugLogger.pp self
|
||||||
DebugLogger.pp ch
|
DebugLogger.pp ch
|
||||||
DebugLogger.pp chrs
|
DebugLogger.pp chrs
|
||||||
SLex.fail ErrNodeAlreadyExists
|
SLex.fail ErrNodeAlreadyExists
|
||||||
else
|
else
|
||||||
D_WARN.puts "change abstract node to real node"
|
D_WARN.puts "change abstract node to real node"
|
||||||
node.preproc = preproc
|
node.preproc = preproc
|
||||||
node.postproc = postproc
|
node.postproc = postproc
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
node.create_subnode(chrs, preproc, postproc)
|
node.create_subnode(chrs, preproc, postproc)
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
if chrs.empty?
|
if chrs.empty?
|
||||||
node = Node.new(preproc, postproc)
|
node = Node.new(preproc, postproc)
|
||||||
else
|
else
|
||||||
node = Node.new
|
node = Node.new
|
||||||
node.create_subnode(chrs, preproc, postproc)
|
node.create_subnode(chrs, preproc, postproc)
|
||||||
end
|
end
|
||||||
@Tree[ch] = node
|
@Tree[ch] = node
|
||||||
end
|
end
|
||||||
node
|
node
|
||||||
end
|
end
|
||||||
|
|
||||||
#
|
#
|
||||||
|
@ -165,81 +165,81 @@ module IRB
|
||||||
# able to be called arbitrary number of times.
|
# able to be called arbitrary number of times.
|
||||||
#
|
#
|
||||||
def match(chrs, op = "")
|
def match(chrs, op = "")
|
||||||
D_DETAIL.print "match>: ", chrs, "op:", op, "\n"
|
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)
|
||||||
DOUT.printf(D_DETAIL, "op1: %s\n", op)
|
DOUT.printf(D_DETAIL, "op1: %s\n", op)
|
||||||
@postproc.call(op, chrs)
|
@postproc.call(op, chrs)
|
||||||
else
|
else
|
||||||
nil
|
nil
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
ch = chrs.shift
|
ch = chrs.shift
|
||||||
if node = @Tree[ch]
|
if node = @Tree[ch]
|
||||||
if ret = node.match(chrs, op+ch)
|
if ret = node.match(chrs, op+ch)
|
||||||
return ret
|
return ret
|
||||||
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)
|
||||||
DOUT.printf(D_DETAIL, "op2: %s\n", op.inspect)
|
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
|
||||||
return nil
|
return nil
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
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)
|
||||||
DOUT.printf(D_DETAIL, "op3: %s\n", op)
|
DOUT.printf(D_DETAIL, "op3: %s\n", op)
|
||||||
@postproc.call(op, chrs)
|
@postproc.call(op, chrs)
|
||||||
return ""
|
return ""
|
||||||
else
|
else
|
||||||
return nil
|
return nil
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def match_io(io, op = "")
|
def match_io(io, op = "")
|
||||||
if op == ""
|
if op == ""
|
||||||
ch = io.getc
|
ch = io.getc
|
||||||
if ch == nil
|
if ch == nil
|
||||||
return nil
|
return nil
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
ch = io.getc_of_rests
|
ch = io.getc_of_rests
|
||||||
end
|
end
|
||||||
if ch.nil?
|
if ch.nil?
|
||||||
if @preproc.nil? || @preproc.call(op, io)
|
if @preproc.nil? || @preproc.call(op, io)
|
||||||
D_DETAIL.printf("op1: %s\n", op)
|
D_DETAIL.printf("op1: %s\n", op)
|
||||||
@postproc.call(op, io)
|
@postproc.call(op, io)
|
||||||
else
|
else
|
||||||
nil
|
nil
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
if node = @Tree[ch]
|
if node = @Tree[ch]
|
||||||
if ret = node.match_io(io, op+ch)
|
if ret = node.match_io(io, op+ch)
|
||||||
ret
|
ret
|
||||||
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)
|
||||||
DOUT.exec_if{D_DETAIL.printf "op2: %s\n", op.inspect}
|
DOUT.exec_if{D_DETAIL.printf "op2: %s\n", op.inspect}
|
||||||
@postproc.call(op, io)
|
@postproc.call(op, io)
|
||||||
else
|
else
|
||||||
nil
|
nil
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
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)
|
||||||
D_DETAIL.printf("op3: %s\n", op)
|
D_DETAIL.printf("op3: %s\n", op)
|
||||||
@postproc.call(op, io)
|
@postproc.call(op, io)
|
||||||
else
|
else
|
||||||
nil
|
nil
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -16,61 +16,61 @@ module IRB # :nodoc:
|
||||||
# inherit main from TOPLEVEL_BINDING.
|
# inherit main from TOPLEVEL_BINDING.
|
||||||
def initialize(*main)
|
def initialize(*main)
|
||||||
if main[0].kind_of?(Binding)
|
if main[0].kind_of?(Binding)
|
||||||
@binding = main.shift
|
@binding = main.shift
|
||||||
elsif IRB.conf[:SINGLE_IRB]
|
elsif IRB.conf[:SINGLE_IRB]
|
||||||
@binding = TOPLEVEL_BINDING
|
@binding = TOPLEVEL_BINDING
|
||||||
else
|
else
|
||||||
case IRB.conf[:CONTEXT_MODE]
|
case IRB.conf[:CONTEXT_MODE]
|
||||||
when 0 # binding in proc on TOPLEVEL_BINDING
|
when 0 # binding in proc on TOPLEVEL_BINDING
|
||||||
@binding = eval("proc{binding}.call",
|
@binding = eval("proc{binding}.call",
|
||||||
TOPLEVEL_BINDING,
|
TOPLEVEL_BINDING,
|
||||||
__FILE__,
|
__FILE__,
|
||||||
__LINE__)
|
__LINE__)
|
||||||
when 1 # binding in loaded file
|
when 1 # binding in loaded file
|
||||||
require "tempfile"
|
require "tempfile"
|
||||||
f = Tempfile.open("irb-binding")
|
f = Tempfile.open("irb-binding")
|
||||||
f.print <<EOF
|
f.print <<EOF
|
||||||
$binding = binding
|
$binding = binding
|
||||||
EOF
|
EOF
|
||||||
f.close
|
f.close
|
||||||
load f.path
|
load f.path
|
||||||
@binding = $binding
|
@binding = $binding
|
||||||
|
|
||||||
when 2 # binding in loaded file(thread use)
|
when 2 # binding in loaded file(thread use)
|
||||||
unless defined? BINDING_QUEUE
|
unless defined? BINDING_QUEUE
|
||||||
require "thread"
|
require "thread"
|
||||||
|
|
||||||
IRB.const_set(:BINDING_QUEUE, SizedQueue.new(1))
|
IRB.const_set(:BINDING_QUEUE, SizedQueue.new(1))
|
||||||
Thread.abort_on_exception = true
|
Thread.abort_on_exception = true
|
||||||
Thread.start do
|
Thread.start do
|
||||||
eval "require \"irb/ws-for-case-2\"", TOPLEVEL_BINDING, __FILE__, __LINE__
|
eval "require \"irb/ws-for-case-2\"", TOPLEVEL_BINDING, __FILE__, __LINE__
|
||||||
end
|
end
|
||||||
Thread.pass
|
Thread.pass
|
||||||
end
|
end
|
||||||
@binding = BINDING_QUEUE.pop
|
@binding = BINDING_QUEUE.pop
|
||||||
|
|
||||||
when 3 # binding in function on TOPLEVEL_BINDING(default)
|
when 3 # binding in function on TOPLEVEL_BINDING(default)
|
||||||
@binding = eval("def irb_binding; private; binding; end; irb_binding",
|
@binding = eval("def irb_binding; private; binding; end; irb_binding",
|
||||||
TOPLEVEL_BINDING,
|
TOPLEVEL_BINDING,
|
||||||
__FILE__,
|
__FILE__,
|
||||||
__LINE__ - 3)
|
__LINE__ - 3)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
if main.empty?
|
if main.empty?
|
||||||
@main = eval("self", @binding)
|
@main = eval("self", @binding)
|
||||||
else
|
else
|
||||||
@main = main[0]
|
@main = main[0]
|
||||||
IRB.conf[:__MAIN__] = @main
|
IRB.conf[:__MAIN__] = @main
|
||||||
case @main
|
case @main
|
||||||
when Module
|
when Module
|
||||||
@binding = eval("IRB.conf[:__MAIN__].module_eval('binding', __FILE__, __LINE__)", @binding, __FILE__, __LINE__)
|
@binding = eval("IRB.conf[:__MAIN__].module_eval('binding', __FILE__, __LINE__)", @binding, __FILE__, __LINE__)
|
||||||
else
|
else
|
||||||
begin
|
begin
|
||||||
@binding = eval("IRB.conf[:__MAIN__].instance_eval('binding', __FILE__, __LINE__)", @binding, __FILE__, __LINE__)
|
@binding = eval("IRB.conf[:__MAIN__].instance_eval('binding', __FILE__, __LINE__)", @binding, __FILE__, __LINE__)
|
||||||
rescue TypeError
|
rescue TypeError
|
||||||
IRB.fail CantChangeBinding, @main.inspect
|
IRB.fail CantChangeBinding, @main.inspect
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
eval("_=nil", @binding)
|
eval("_=nil", @binding)
|
||||||
end
|
end
|
||||||
|
@ -90,20 +90,20 @@ EOF
|
||||||
def filter_backtrace(bt)
|
def filter_backtrace(bt)
|
||||||
case IRB.conf[:CONTEXT_MODE]
|
case IRB.conf[:CONTEXT_MODE]
|
||||||
when 0
|
when 0
|
||||||
return nil if bt =~ /\(irb_local_binding\)/
|
return nil if bt =~ /\(irb_local_binding\)/
|
||||||
when 1
|
when 1
|
||||||
if(bt =~ %r!/tmp/irb-binding! or
|
if(bt =~ %r!/tmp/irb-binding! or
|
||||||
bt =~ %r!irb/.*\.rb! or
|
bt =~ %r!irb/.*\.rb! or
|
||||||
bt =~ /irb\.rb/)
|
bt =~ /irb\.rb/)
|
||||||
return nil
|
return nil
|
||||||
end
|
end
|
||||||
when 2
|
when 2
|
||||||
return nil if bt =~ /irb\/.*\.rb/
|
return nil if bt =~ /irb\/.*\.rb/
|
||||||
return nil if bt =~ /irb\.rb/
|
return nil if bt =~ /irb\.rb/
|
||||||
when 3
|
when 3
|
||||||
return nil if bt =~ /irb\/.*\.rb/
|
return nil if bt =~ /irb\/.*\.rb/
|
||||||
return nil if bt =~ /irb\.rb/
|
return nil if bt =~ /irb\.rb/
|
||||||
bt = bt.sub(/:\s*in `irb_binding'/, '')
|
bt = bt.sub(/:\s*in `irb_binding'/, '')
|
||||||
end
|
end
|
||||||
bt
|
bt
|
||||||
end
|
end
|
||||||
|
|
|
@ -85,16 +85,16 @@ class XMP
|
||||||
|
|
||||||
if @irb.context.ignore_sigint
|
if @irb.context.ignore_sigint
|
||||||
begin
|
begin
|
||||||
trap_proc_b = trap("SIGINT"){@irb.signal_handle}
|
trap_proc_b = trap("SIGINT"){@irb.signal_handle}
|
||||||
catch(:IRB_EXIT) do
|
catch(:IRB_EXIT) do
|
||||||
@irb.eval_input
|
@irb.eval_input
|
||||||
end
|
end
|
||||||
ensure
|
ensure
|
||||||
trap("SIGINT", trap_proc_b)
|
trap("SIGINT", trap_proc_b)
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
catch(:IRB_EXIT) do
|
catch(:IRB_EXIT) do
|
||||||
@irb.eval_input
|
@irb.eval_input
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -117,10 +117,10 @@ class XMP
|
||||||
# See IO#gets for more information.
|
# See IO#gets for more information.
|
||||||
def gets
|
def gets
|
||||||
while l = @exps.shift
|
while l = @exps.shift
|
||||||
next if /^\s+$/ =~ l
|
next if /^\s+$/ =~ l
|
||||||
l.concat "\n"
|
l.concat "\n"
|
||||||
print @prompt, l
|
print @prompt, l
|
||||||
break
|
break
|
||||||
end
|
end
|
||||||
l
|
l
|
||||||
end
|
end
|
||||||
|
@ -131,14 +131,14 @@ class XMP
|
||||||
# doesn't match the previous expression evaluated.
|
# doesn't match the previous expression evaluated.
|
||||||
def puts(exps)
|
def puts(exps)
|
||||||
if @encoding and exps.encoding != @encoding
|
if @encoding and exps.encoding != @encoding
|
||||||
enc = Encoding.compatible?(@exps.join("\n"), exps)
|
enc = Encoding.compatible?(@exps.join("\n"), exps)
|
||||||
if enc.nil?
|
if enc.nil?
|
||||||
raise Encoding::CompatibilityError, "Encoding in which the passed expression is encoded is not compatible to the preceding's one"
|
raise Encoding::CompatibilityError, "Encoding in which the passed expression is encoded is not compatible to the preceding's one"
|
||||||
else
|
else
|
||||||
@encoding = enc
|
@encoding = enc
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
@encoding = exps.encoding
|
@encoding = exps.encoding
|
||||||
end
|
end
|
||||||
@exps.concat exps.split(/\n/)
|
@exps.concat exps.split(/\n/)
|
||||||
end
|
end
|
||||||
|
|
Загрузка…
Ссылка в новой задаче