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

Merge from irb-tools 0.7.1.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@1349 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
knu 2001-04-30 18:25:04 +00:00
parent 8752585250
commit 30a7496b22
4 changed files with 148 additions and 13 deletions

View file

@ -1,3 +1,8 @@
Tue May 1 03:24:05 2001 Akinori MUSHA <knu@iDaemons.org>
* lib/irb/completion.rb, lib/irb/frame.rb, lib/irb/xmp.rb,
doc/irb/irb-tools.rd.jp: Merge from irb-tools 0.7.1.
Tue May 1 03:07:17 2001 Akinori MUSHA <knu@iDaemons.org> Tue May 1 03:07:17 2001 Akinori MUSHA <knu@iDaemons.org>
* sample/irb.rb, lib/irb.rb, lib/irb/*, doc/irb/*: Merge from irb * sample/irb.rb, lib/irb.rb, lib/irb/*, doc/irb/*: Merge from irb

View file

@ -1,8 +1,19 @@
#
# irb/completor.rb -
# $Release Version: 0.7.1$
# $Revision$
# $Date$
# by Keiju ISHITSUKA(keiju@ishitsuka.com)
# From Original Idea of shugo@ruby-lang.org
#
require "readline" require "readline"
module IRB module IRB
module InputCompletion module InputCompletor
@RCS_ID='-$Id$-'
ReservedWords = [ ReservedWords = [
"BEGIN", "END", "BEGIN", "END",
"alias", "and", "alias", "and",
@ -20,28 +31,147 @@ module IRB
"then", "true", "then", "true",
"undef", "unless", "until", "undef", "unless", "until",
"when", "while", "when", "while",
"yield" "yield",
] ]
CompletionProc = proc { |input| CompletionProc = proc { |input|
bind = IRB.conf[:MAIN_CONTEXT].workspace.binding
case input case input
when /^([^.]+)\.([^.]*)$/ when /^(\/[^\/]*\/)\.([^.]*)$/
# Regexp
receiver = $1 receiver = $1
message = $2 message = Regexp.quote($2)
if eval("(local_variables|#{receiver}.type.constants).include?('#{receiver}')",
IRB.conf[:MAIN_CONTEXT].bind) candidates = Regexp.instance_methods(true)
candidates = eval("#{receiver}.methods", IRB.conf[:MAIN_CONTEXT].bind) select_message(receiver, message, candidates)
when /^([^\]]*\])\.([^.]*)$/
# Array
receiver = $1
message = Regexp.quote($2)
candidates = Array.instance_methods(true)
select_message(receiver, message, candidates)
when /^([^\}]*\})\.([^.]*)$/
# Proc or Hash
receiver = $1
message = Regexp.quote($2)
candidates = Proc.instance_methods(true) | Hash.instance_methods(true)
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(/^#{sym}/)
else else
[]
end
when /^::([A-Z][^:\.\(]*)$/
# Absolute Constant or class methods
receiver = $1
candidates = Object.constants
candidates.grep(/^#{receiver}/).collect{|e| "::" + e}
when /^(((::)?[A-Z][^:.\(]*)+)::?([^:.]*)$/
# Constant or class methods
receiver = $1
message = Regexp.quote($4)
begin
candidates = eval("#{receiver}.constants | #{receiver}.methods", bind)
rescue Exception
candidates = []
end
candidates.grep(/^#{message}/).collect{|e| receiver + "::" + e}
when /^(:[^.]+)\.([^.]*)$/
# Symbol
receiver = $1
message = Regexp.quote($2)
candidates = Symbol.instance_methods(true)
select_message(receiver, message, candidates)
when /^([0-9_]+(\.[0-9_]+)?(e[0-9]+)?)\.([^.]*)$/
# Numeric
receiver = $1
message = Regexp.quote($4)
begin
candidates = eval(receiver, bind).methods
rescue Exception
candidates
end
select_message(receiver, message, candidates)
# when /^(\$?(\.?[^.]+)+)\.([^.]*)$/
when /^((\.?[^.]+)+)\.([^.]*)$/
# variable
receiver = $1
message = Regexp.quote($3)
gv = eval "global_variables", bind
lv = eval "local_variables", bind
cv = eval "type.constants", bind
if (gv | lv | cv).include?(receiver)
# foo.func and foo is local var.
candidates = eval("#{receiver}.methods", bind)
elsif /^[A-Z]/ =~ receiver and /\./ !~ receiver
# Foo::Bar.func
begin
candidates = eval("#{receiver}.methods", bind)
rescue Exception
candidates = [] candidates = []
end end
candidates.grep(/^#{Regexp.quote(message)}/).collect{|e| receiver + "." + e}
else else
candidates = eval("methods | private_methods | local_variables | type.constants", # func1.func2
IRB.conf[:MAIN_CONTEXT].bind) candidates = []
ObjectSpace.each_object(Module){|m|
next if /^(IRB|SLex|RubyLex|RubyToken)/ =~ m.name
candidates.concat m.instance_methods
}
candidates.sort!
candidates.uniq!
end
select_message(receiver, message, candidates)
when /^\.([^.]*)$/
# unknown(maybe String)
receiver = ""
message = Regexp.quote($1)
candidates = String.instance_methods(true)
select_message(receiver, message, candidates)
else
candidates = eval("methods | private_methods | local_variables | type.constants", bind)
(candidates|ReservedWords).grep(/^#{Regexp.quote(input)}/) (candidates|ReservedWords).grep(/^#{Regexp.quote(input)}/)
end end
} }
Operators = ["%", "&", "*", "**", "+", "-", "/",
"<", "<<", "<=", "<=>", "==", "===", "=~", ">", ">=", ">>",
"[]", "[]=", "^",]
def self.select_message(receiver, message, candidates)
candidates.grep(/^#{message}/).collect do |e|
case e
when /^[a-zA-Z_]/
receiver + "." + e
when /^[0-9]/
when *Operators
#receiver + " " + e
end
end
end
end end
end end
Readline.completion_proc = IRB::InputCompletion::CompletionProc Readline.completion_proc = IRB::InputCompletor::CompletionProc

View file

@ -1,6 +1,6 @@
# #
# frame.rb - # frame.rb -
# $Release Version: 0.6$ # $Release Version: 0.7.1$
# $Revision$ # $Revision$
# $Date$ # $Date$
# by Keiju ISHITSUKA(Nihon Rational Software Co.,Ltd) # by Keiju ISHITSUKA(Nihon Rational Software Co.,Ltd)

View file

@ -1,6 +1,6 @@
# #
# xmp.rb - irb version of gotoken xmp # xmp.rb - irb version of gotoken xmp
# $Release Version: 0.6$ # $Release Version: 0.7.1$
# $Revision$ # $Revision$
# $Date$ # $Date$
# by Keiju ISHITSUKA(Nippon Rational Inc.) # by Keiju ISHITSUKA(Nippon Rational Inc.)