~ubuntu-branches/ubuntu/quantal/ruby1.9.1/quantal

« back to all changes in this revision

Viewing changes to lib/irb/completion.rb

  • Committer: Bazaar Package Importer
  • Author(s): Lucas Nussbaum
  • Date: 2010-07-31 17:08:39 UTC
  • mfrom: (1.1.4 upstream) (8.1.2 sid)
  • Revision ID: james.westby@ubuntu.com-20100731170839-j034dmpdqt1cc4p6
Tags: 1.9.2~svn28788-1
* New release based on upstream snapshot from the 1.9.2 branch,
  after 1.9.2 RC2. That branch is (supposed to be) binary-compatible
  with the 1.9.1 branch.
  + Builds fine on i386. Closes: #580852.
* Upgrade to Standards-Version: 3.9.1. No changes needed.
* Updated generated incs.
* Patches that still need work:
  + Unclear status, need more investigation:
   090729_fix_Makefile_deps.dpatch
   090803_exclude_rdoc.dpatch
   203_adjust_base_of_search_path.dpatch
   902_define_YAML_in_yaml_stringio.rb.dpatch
   919_common.mk_tweaks.dpatch
   931_libruby_suffix.dpatch
   940_test_thread_mutex_sync_shorter.dpatch
  + Maybe not needed anymore, keeping but not applying.
   102_skip_test_copy_stream.dpatch (test doesn't block anymore?)
   104_skip_btest_io.dpatch (test doesn't block anymore?)
   201_gem_prelude.dpatch (we don't use that rubygems anyway?)
   202_gem_default_dir.dpatch (we don't use that rubygems anyway?)
   940_test_file_exhaustive_fails_as_root.dpatch
   940_test_priority_fails.dpatch
   100518_load_libc_libm.dpatch
* Add disable-tests.diff: disable some tests that cause failures on FreeBSD.
  Closes: #590002, #543805, #542927.
* However, many new failures on FreeBSD. Since that version is still an
  improvement, add the check that makes test suite failures non-fatal on
  FreeBSD again. That still needs to be investigated.
* Re-add 903_skip_base_ruby_check.dpatch
* Add build-dependency on ruby1.8 and drop all pre-generated files.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
#
2
 
#   irb/completor.rb - 
 
2
#   irb/completor.rb -
3
3
#       $Release Version: 0.9$
4
 
#       $Revision: 23233 $
 
4
#       $Revision: 27327 $
5
5
#       by Keiju ISHITSUKA(keiju@ishitsuka.com)
6
6
#       From Original Idea of shugo@ruby-lang.org
7
7
#
11
11
module IRB
12
12
  module InputCompletor
13
13
 
14
 
    @RCS_ID='-$Id: completion.rb 23233 2009-04-19 13:35:47Z yugui $-'
 
14
    @RCS_ID='-$Id: completion.rb 27327 2010-04-13 05:01:10Z keiju $-'
15
15
 
16
16
    ReservedWords = [
17
17
      "BEGIN", "END",
18
 
      "alias", "and", 
19
 
      "begin", "break", 
 
18
      "alias", "and",
 
19
      "begin", "break",
20
20
      "case", "class",
21
21
      "def", "defined", "do",
22
22
      "else", "elsif", "end", "ensure",
23
 
      "false", "for", 
24
 
      "if", "in", 
25
 
      "module", 
 
23
      "false", "for",
 
24
      "if", "in",
 
25
      "module",
26
26
      "next", "nil", "not",
27
 
      "or", 
 
27
      "or",
28
28
      "redo", "rescue", "retry", "return",
29
29
      "self", "super",
30
30
      "then", "true",
32
32
      "when", "while",
33
33
      "yield",
34
34
    ]
35
 
      
 
35
 
36
36
    CompletionProc = proc { |input|
37
37
      bind = IRB.conf[:MAIN_CONTEXT].workspace.binding
38
 
      
 
38
 
39
39
#      puts "input: #{input}"
40
40
 
41
41
      case input
63
63
        candidates = Proc.instance_methods.collect{|m| m.to_s}
64
64
        candidates |= Hash.instance_methods.collect{|m| m.to_s}
65
65
        select_message(receiver, message, candidates)
66
 
        
 
66
 
67
67
      when /^(:[^:.]*)$/
68
68
        # Symbol
69
69
        if Symbol.respond_to?(:all_symbols)
80
80
        candidates = Object.constants.collect{|m| m.to_s}
81
81
        candidates.grep(/^#{receiver}/).collect{|e| "::" + e}
82
82
 
83
 
      when /^(((::)?[A-Z][^:.\(]*)+)::?([^:.]*)$/
 
83
#      when /^(((::)?[A-Z][^:.\(]*)+)::?([^:.]*)$/
 
84
      when /^([A-Z].*)::([^:.]*)$/
84
85
        # Constant or class methods
85
86
        receiver = $1
86
 
        message = Regexp.quote($4)
 
87
        message = Regexp.quote($2)
87
88
        begin
88
89
          candidates = eval("#{receiver}.constants.collect{|m| m.to_s}", bind)
89
90
          candidates |= eval("#{receiver}.methods.collect{|m| m.to_s}", bind)
129
130
        candidates = global_variables.collect{|m| m.to_s}.grep(regmessage)
130
131
 
131
132
#      when /^(\$?(\.?[^.]+)+)\.([^.]*)$/
132
 
      when /^((\.?[^.]+)+)\.([^.]*)$/
 
133
#      when /^((\.?[^.]+)+)\.([^.]*)$/
 
134
      when /^([^."].*)\.([^.]*)$/
133
135
        # variable
134
136
        receiver = $1
135
 
        message = Regexp.quote($3)
 
137
        message = Regexp.quote($2)
136
138
 
137
139
        gv = eval("global_variables", bind).collect{|m| m.to_s}
138
140
        lv = eval("local_variables", bind).collect{|m| m.to_s}
139
141
        cv = eval("self.class.constants", bind).collect{|m| m.to_s}
140
 
        
141
 
        if (gv | lv | cv).include?(receiver)
142
 
          # foo.func and foo is local var.
143
 
          candidates = eval("#{receiver}.methods", bind).collect{|m| m.to_s}
144
 
        elsif /^[A-Z]/ =~ receiver and /\./ !~ receiver
 
142
 
 
143
        if (gv | lv | cv).include?(receiver) or /^[A-Z]/ =~ receiver && /\./ !~ receiver
 
144
          # foo.func and foo is local var. OR
145
145
          # Foo::Bar.func
146
146
          begin
147
147
            candidates = eval("#{receiver}.methods", bind).collect{|m| m.to_s}
157
157
            rescue Exception
158
158
              name = ""
159
159
            end
160
 
            next if name != "IRB::Context" and 
 
160
            next if name != "IRB::Context" and
161
161
              /^(IRB|SLex|RubyLex|RubyToken)/ =~ name
162
162
            candidates.concat m.instance_methods(false).collect{|x| x.to_s}
163
163
          }
177
177
 
178
178
      else
179
179
        candidates = eval("methods | private_methods | local_variables | self.class.constants", bind).collect{|m| m.to_s}
180
 
                          
 
180
 
181
181
        (candidates|ReservedWords).grep(/^#{Regexp.quote(input)}/)
182
182
      end
183
183
    }