summaryrefslogtreecommitdiff
path: root/lib/irb
diff options
context:
space:
mode:
authoraycabta <aycabta@gmail.com>2019-11-25 05:38:09 +0900
committeraycabta <aycabta@gmail.com>2019-11-25 05:38:09 +0900
commit51ea1abb5f2ed70387dda28a5d0d9ee817367d61 (patch)
treef7eb2f57a21436682212399ecc34dcacbb5b91c2 /lib/irb
parentefbca15116d4aea1588c6ba4ef0eb72c3c55c1db (diff)
Remove e2mmap dependency
Diffstat (limited to 'lib/irb')
-rw-r--r--lib/irb/ext/multi-irb.rb14
-rw-r--r--lib/irb/frame.rb19
-rw-r--r--lib/irb/init.rb6
-rw-r--r--lib/irb/input-method.rb2
-rw-r--r--lib/irb/lc/error.rb71
-rw-r--r--lib/irb/lc/ja/error.rb69
-rw-r--r--lib/irb/notifier.rb20
-rw-r--r--lib/irb/output-method.rb12
-rw-r--r--lib/irb/ruby-lex.rb8
-rw-r--r--lib/irb/workspace.rb2
10 files changed, 157 insertions, 66 deletions
diff --git a/lib/irb/ext/multi-irb.rb b/lib/irb/ext/multi-irb.rb
index 28d6fba832..74de1ecde5 100644
--- a/lib/irb/ext/multi-irb.rb
+++ b/lib/irb/ext/multi-irb.rb
@@ -9,7 +9,7 @@
#
#
#
-IRB.fail CantShiftToMultiIrbMode unless defined?(Thread)
+fail CantShiftToMultiIrbMode unless defined?(Thread)
module IRB
class JobManager
@@ -67,8 +67,8 @@ module IRB
# exception is raised.
def switch(key)
th, irb = search(key)
- IRB.fail IrbAlreadyDead unless th.alive?
- IRB.fail IrbSwitchedToCurrentThread if th == Thread.current
+ fail IrbAlreadyDead unless th.alive?
+ fail IrbSwitchedToCurrentThread if th == Thread.current
@current_job = irb
th.run
Thread.stop
@@ -84,7 +84,7 @@ module IRB
def kill(*keys)
for key in keys
th, _ = search(key)
- IRB.fail IrbAlreadyDead unless th.alive?
+ fail IrbAlreadyDead unless th.alive?
th.exit
end
end
@@ -114,7 +114,7 @@ module IRB
else
@jobs.find{|k, v| v.context.main.equal?(key)}
end
- IRB.fail NoSuchJob, key if job.nil?
+ fail NoSuchJob, key if job.nil?
job
end
@@ -122,7 +122,7 @@ module IRB
def delete(key)
case key
when Integer
- IRB.fail NoSuchJob, key unless @jobs[key]
+ fail NoSuchJob, key unless @jobs[key]
@jobs[key] = nil
else
catch(:EXISTS) do
@@ -135,7 +135,7 @@ module IRB
throw :EXISTS
end
end
- IRB.fail NoSuchJob, key
+ fail NoSuchJob, key
end
end
until assoc = @jobs.pop; end unless @jobs.empty?
diff --git a/lib/irb/frame.rb b/lib/irb/frame.rb
index 6073809249..de54a98f1b 100644
--- a/lib/irb/frame.rb
+++ b/lib/irb/frame.rb
@@ -10,13 +10,18 @@
#
#
-require "e2mmap"
-
module IRB
class Frame
- extend Exception2MessageMapper
- def_exception :FrameOverflow, "frame overflow"
- def_exception :FrameUnderflow, "frame underflow"
+ class FrameOverflow < StandardError
+ def initialize
+ super("frame overflow")
+ end
+ end
+ class FrameUnderflow < StandardError
+ def initialize
+ super("frame underflow")
+ end
+ end
# Default number of stack frames
INIT_STACK_TIMES = 3
@@ -44,7 +49,7 @@ module IRB
# Raises FrameUnderflow if there are no frames in the given stack range.
def top(n = 0)
bind = @frames[-(n + CALL_STACK_OFFSET)]
- Fail FrameUnderflow unless bind
+ fail FrameUnderflow unless bind
bind
end
@@ -54,7 +59,7 @@ module IRB
# Raises FrameOverflow if there are no frames in the given stack range.
def bottom(n = 0)
bind = @frames[n]
- Fail FrameOverflow unless bind
+ fail FrameOverflow unless bind
bind
end
diff --git a/lib/irb/init.rb b/lib/irb/init.rb
index ebae37146f..2af872fd03 100644
--- a/lib/irb/init.rb
+++ b/lib/irb/init.rb
@@ -21,7 +21,7 @@ module IRB # :nodoc:
IRB.load_modules
unless @CONF[:PROMPT][@CONF[:PROMPT_MODE]]
- IRB.fail(UndefinedPromptMode, @CONF[:PROMPT_MODE])
+ fail UndefinedPromptMode, @CONF[:PROMPT_MODE]
end
end
@@ -217,7 +217,7 @@ module IRB # :nodoc:
end
break
when /^-/
- IRB.fail UnrecognizedSwitch, opt
+ fail UnrecognizedSwitch, opt
else
@CONF[:SCRIPT] = opt
$0 = opt
@@ -262,7 +262,7 @@ module IRB # :nodoc:
when String
return rc_file
else
- IRB.fail IllegalRCNameGenerator
+ fail IllegalRCNameGenerator
end
end
diff --git a/lib/irb/input-method.rb b/lib/irb/input-method.rb
index bde6ccdc69..6f064885bc 100644
--- a/lib/irb/input-method.rb
+++ b/lib/irb/input-method.rb
@@ -32,7 +32,7 @@ module IRB
#
# See IO#gets for more information.
def gets
- IRB.fail NotImplementedError, "gets"
+ fail NotImplementedError, "gets"
end
public :gets
diff --git a/lib/irb/lc/error.rb b/lib/irb/lc/error.rb
index 6623f82d84..798994e92c 100644
--- a/lib/irb/lc/error.rb
+++ b/lib/irb/lc/error.rb
@@ -9,24 +9,63 @@
#
#
#
-require "e2mmap"
# :stopdoc:
module IRB
-
- # exceptions
- extend Exception2MessageMapper
- def_exception :UnrecognizedSwitch, "Unrecognized switch: %s"
- def_exception :NotImplementedError, "Need to define `%s'"
- def_exception :CantReturnToNormalMode, "Can't return to normal mode."
- def_exception :IllegalParameter, "Invalid parameter(%s)."
- def_exception :IrbAlreadyDead, "Irb is already dead."
- def_exception :IrbSwitchedToCurrentThread, "Switched to current thread."
- def_exception :NoSuchJob, "No such job(%s)."
- def_exception :CantShiftToMultiIrbMode, "Can't shift to multi irb mode."
- def_exception :CantChangeBinding, "Can't change binding to (%s)."
- def_exception :UndefinedPromptMode, "Undefined prompt mode(%s)."
- def_exception :IllegalRCGenerator, 'Define illegal RC_NAME_GENERATOR.'
-
+ class UnrecognizedSwitch < StandardError
+ def initialize(val)
+ super("Unrecognized switch: #{val}")
+ end
+ end
+ class NotImplementedError < StandardError
+ def initialize(val)
+ super("Need to define `#{val}'")
+ end
+ end
+ class CantReturnToNormalMode < StandardError
+ def initialize
+ super("Can't return to normal mode.")
+ end
+ end
+ class IllegalParameter < StandardError
+ def initialize(val)
+ super("Invalid parameter(#{val}).")
+ end
+ end
+ class IrbAlreadyDead < StandardError
+ def initialize
+ super("Irb is already dead.")
+ end
+ end
+ class IrbSwitchedToCurrentThread < StandardError
+ def initialize
+ super("Switched to current thread.")
+ end
+ end
+ class NoSuchJob < StandardError
+ def initialize(val)
+ super("No such job(#{val}).")
+ end
+ end
+ class CantShiftToMultiIrbMode < StandardError
+ def initialize
+ super("Can't shift to multi irb mode.")
+ end
+ end
+ class CantChangeBinding < StandardError
+ def initialize(val)
+ super("Can't change binding to (#{val}).")
+ end
+ end
+ class UndefinedPromptMode < StandardError
+ def initialize(val)
+ super("Undefined prompt mode(#{val}).")
+ end
+ end
+ class IllegalRCGenerator < StandardError
+ def initialize
+ super("Define illegal RC_NAME_GENERATOR.")
+ end
+ end
end
# :startdoc:
diff --git a/lib/irb/lc/ja/error.rb b/lib/irb/lc/ja/error.rb
index 919363154c..31ebb3b5f0 100644
--- a/lib/irb/lc/ja/error.rb
+++ b/lib/irb/lc/ja/error.rb
@@ -9,23 +9,64 @@
#
#
#
-require "e2mmap"
# :stopdoc:
module IRB
- # exceptions
- extend Exception2MessageMapper
- def_exception :UnrecognizedSwitch, 'スイッチ(%s)が分りません'
- def_exception :NotImplementedError, '`%s\'の定義が必要です'
- def_exception :CantReturnToNormalMode, 'Normalモードに戻れません.'
- def_exception :IllegalParameter, 'パラメータ(%s)が間違っています.'
- def_exception :IrbAlreadyDead, 'Irbは既に死んでいます.'
- def_exception :IrbSwitchedToCurrentThread, 'カレントスレッドに切り替わりました.'
- def_exception :NoSuchJob, 'そのようなジョブ(%s)はありません.'
- def_exception :CantShiftToMultiIrbMode, 'multi-irb modeに移れません.'
- def_exception :CantChangeBinding, 'バインディング(%s)に変更できません.'
- def_exception :UndefinedPromptMode, 'プロンプトモード(%s)は定義されていません.'
- def_exception :IllegalRCNameGenerator, 'RC_NAME_GENERATORが正しく定義されていません.'
+ class UnrecognizedSwitch < StandardError
+ def initialize(val)
+ super("スイッチ(#{val})が分りません")
+ end
+ end
+ class NotImplementedError < StandardError
+ def initialize(val)
+ super("`#{val}'の定義が必要です")
+ end
+ end
+ class CantReturnToNormalMode < StandardError
+ def initialize
+ super("Normalモードに戻れません.")
+ end
+ end
+ class IllegalParameter < StandardError
+ def initialize(val)
+ super("パラメータ(#{val})が間違っています.")
+ end
+ end
+ class IrbAlreadyDead < StandardError
+ def initialize
+ super("Irbは既に死んでいます.")
+ end
+ end
+ class IrbSwitchedToCurrentThread < StandardError
+ def initialize
+ super("カレントスレッドに切り替わりました.")
+ end
+ end
+ class NoSuchJob < StandardError
+ def initialize(val)
+ super("そのようなジョブ(#{val})はありません.")
+ end
+ end
+ class CantShiftToMultiIrbMode < StandardError
+ def initialize
+ super("multi-irb modeに移れません.")
+ end
+ end
+ class CantChangeBinding < StandardError
+ def initialize(val)
+ super("バインディング(#{val})に変更できません.")
+ end
+ end
+ class UndefinedPromptMode < StandardError
+ def initialize(val)
+ super("プロンプトモード(#{val})は定義されていません.")
+ end
+ end
+ class IllegalRCGenerator < StandardError
+ def initialize
+ super("RC_NAME_GENERATORが正しく定義されていません.")
+ end
+ end
end
# :startdoc:
# vim:fileencoding=utf-8
diff --git a/lib/irb/notifier.rb b/lib/irb/notifier.rb
index 5a68b0e8c8..d0e413dd68 100644
--- a/lib/irb/notifier.rb
+++ b/lib/irb/notifier.rb
@@ -10,17 +10,21 @@
#
#
-require "e2mmap"
require_relative "output-method"
module IRB
# An output formatter used internally by the lexer.
module Notifier
- extend Exception2MessageMapper
- def_exception :ErrUndefinedNotifier,
- "undefined notifier level: %d is specified"
- def_exception :ErrUnrecognizedLevel,
- "unrecognized notifier level: %s is specified"
+ class ErrUndefinedNotifier < StandardError
+ def initialize(val)
+ super("undefined notifier level: #{val} is specified")
+ end
+ end
+ class ErrUnrecognizedLevel < StandardError
+ def initialize(val)
+ super("unrecognized notifier level: #{val} is specified")
+ end
+ end
# Define a new Notifier output source, returning a new CompositeNotifier
# with the given +prefix+ and +output_method+.
@@ -162,10 +166,10 @@ module IRB
@level_notifier = value
when Integer
l = @notifiers[value]
- Notifier.Raise ErrUndefinedNotifier, value unless l
+ raise ErrUndefinedNotifier, value unless l
@level_notifier = l
else
- Notifier.Raise ErrUnrecognizedLevel, value unless l
+ raise ErrUnrecognizedLevel, value unless l
end
end
diff --git a/lib/irb/output-method.rb b/lib/irb/output-method.rb
index 935a127d0a..3fda708cb0 100644
--- a/lib/irb/output-method.rb
+++ b/lib/irb/output-method.rb
@@ -10,21 +10,21 @@
#
#
-require "e2mmap"
-
module IRB
# An abstract output class for IO in irb. This is mainly used internally by
# IRB::Notifier. You can define your own output method to use with Irb.new,
# or Context.new
class OutputMethod
- extend Exception2MessageMapper
- def_exception :NotImplementedError, "Need to define `%s'"
-
+ class NotImplementedError < StandardError
+ def initialize(val)
+ super("Need to define `#{val}'")
+ end
+ end
# Open this method to implement your own output method, raises a
# NotImplementedError if you don't define #print in your own class.
def print(*opts)
- OutputMethod.Raise NotImplementedError, "print"
+ raise NotImplementedError, "print"
end
# Prints the given +opts+, with a newline delimiter.
diff --git a/lib/irb/ruby-lex.rb b/lib/irb/ruby-lex.rb
index b6db384568..ad6cb93309 100644
--- a/lib/irb/ruby-lex.rb
+++ b/lib/irb/ruby-lex.rb
@@ -10,14 +10,16 @@
#
#
-require "e2mmap"
require "ripper"
# :stopdoc:
class RubyLex
- extend Exception2MessageMapper
- def_exception(:TerminateLineInput, "Terminate Line Input")
+ class TerminateLineInput < StandardError
+ def initialize
+ super("Terminate Line Input")
+ end
+ end
def initialize
@exp_line_no = @line_no = 1
diff --git a/lib/irb/workspace.rb b/lib/irb/workspace.rb
index 878bba9e95..794a511521 100644
--- a/lib/irb/workspace.rb
+++ b/lib/irb/workspace.rb
@@ -74,7 +74,7 @@ EOF
begin
@binding = eval("IRB.conf[:__MAIN__].instance_eval('binding', __FILE__, __LINE__)", @binding, __FILE__, __LINE__)
rescue TypeError
- IRB.fail CantChangeBinding, @main.inspect
+ fail CantChangeBinding, @main.inspect
end
end
end