From 8e5af8b628b2a52d203e43ad5a8b18375f801cde Mon Sep 17 00:00:00 2001 From: hsbt Date: Sat, 9 Aug 2014 01:36:49 +0000 Subject: [PATCH] * lib/cmath.rb: fixed indent. * lib/drb/ssl.rb: ditto. * lib/irb/**/*.rb: ditto. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@47112 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ChangeLog | 6 + lib/cmath.rb | 112 +++---- lib/drb/ssl.rb | 2 +- lib/irb/cmd/chws.rb | 6 +- lib/irb/cmd/fork.rb | 28 +- lib/irb/cmd/load.rb | 50 +-- lib/irb/cmd/nop.rb | 10 +- lib/irb/cmd/pushws.rb | 10 +- lib/irb/cmd/subirb.rb | 8 +- lib/irb/completion.rb | 260 +++++++------- lib/irb/context.rb | 178 +++++----- lib/irb/ext/change-ws.rb | 10 +- lib/irb/ext/history.rb | 56 ++-- lib/irb/ext/loader.rb | 118 +++---- lib/irb/ext/math-mode.rb | 8 +- lib/irb/ext/multi-irb.rb | 16 +- lib/irb/ext/save-history.rb | 50 +-- lib/irb/ext/tracer.rb | 26 +- lib/irb/ext/use-loader.rb | 28 +- lib/irb/ext/workspaces.rb | 26 +- lib/irb/extend-command.rb | 232 ++++++------- lib/irb/frame.rb | 4 +- lib/irb/help.rb | 18 +- lib/irb/init.rb | 204 +++++------ lib/irb/input-method.rb | 34 +- lib/irb/locale.rb | 66 ++-- lib/irb/notifier.rb | 80 ++--- lib/irb/ruby-lex.rb | 652 ++++++++++++++++++------------------ lib/irb/ruby-token.rb | 16 +- lib/irb/slex.rb | 258 +++++++------- lib/irb/workspace.rb | 114 +++---- lib/irb/xmp.rb | 34 +- 32 files changed, 1363 insertions(+), 1357 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 + + * lib/cmath.rb: fixed indent. + * lib/drb/ssl.rb: ditto. + * lib/irb/**/*.rb: ditto. + Sat Aug 9 10:28:03 2014 SHIBATA Hiroshi * 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<=;|&{(" + # 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<= 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< { - :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] + @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 + 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 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 + 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 + @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? + # 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 + 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) + 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 <