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