[macruby-changes] [4651] DietRB/trunk

source_changes at macosforge.org source_changes at macosforge.org
Fri Oct 8 03:54:19 PDT 2010


Revision: 4651
          http://trac.macosforge.org/projects/ruby/changeset/4651
Author:   eloy.de.enige at gmail.com
Date:     2010-10-08 03:54:18 -0700 (Fri, 08 Oct 2010)
Log Message:
-----------
Complete reserved words.

From: Eloy Duran <eloy.de.enige at gmail.com>

Modified Paths:
--------------
    DietRB/trunk/Rakefile
    DietRB/trunk/lib/irb/ext/completion.rb
    DietRB/trunk/spec/completion_spec.rb

Modified: DietRB/trunk/Rakefile
===================================================================
--- DietRB/trunk/Rakefile	2010-10-08 10:54:08 UTC (rev 4650)
+++ DietRB/trunk/Rakefile	2010-10-08 10:54:18 UTC (rev 4651)
@@ -12,7 +12,7 @@
 
 desc "Run dietrb with ruby19"
 task :run do
-  sh "ruby19 -Ilib ./bin/dietrb"
+  sh "ruby19 -Ilib ./bin/dietrb -r irb/ext/completion"
 end
 
 begin

Modified: DietRB/trunk/lib/irb/ext/completion.rb
===================================================================
--- DietRB/trunk/lib/irb/ext/completion.rb	2010-10-08 10:54:08 UTC (rev 4650)
+++ DietRB/trunk/lib/irb/ext/completion.rb	2010-10-08 10:54:18 UTC (rev 4651)
@@ -7,6 +7,29 @@
     VALUE  = 1
     CALLEE = 3
     
+    RESERVED_UPCASE_WORDS = %w{
+      BEGIN  END
+    }
+    
+    RESERVED_DOWNCASE_WORDS = %w{
+      alias  and
+      begin  break
+      case   class
+      def    defined do
+      else   elsif   end   ensure
+      false  for
+      if     in
+      module
+      next   nil     not
+      or
+      redo   rescue  retry return
+      self   super
+      then   true
+      undef  unless  until
+      when   while
+      yield
+    }
+    
     # Returns an array of possible completion results, with the current
     # IRB::Context.
     #
@@ -64,7 +87,7 @@
           format_methods(receiver, methods_of_object(root), filter)
         else
           match_methods_vars_or_consts_in_scope(root)
-        end.sort
+        end.sort.uniq
       end
     end
     
@@ -73,7 +96,7 @@
       filter = var[VALUE]
       case var[TYPE]
       when :@ident
-        local_variables + instance_methods
+        local_variables + instance_methods + RESERVED_DOWNCASE_WORDS
       when :@gvar
         global_variables.map(&:to_s)
       when :@const
@@ -81,7 +104,7 @@
           filter = "::#{filter}"
           Object.constants.map { |c| "::#{c}" }
         else
-          constants
+          constants + RESERVED_UPCASE_WORDS
         end
       end.grep(/^#{Regexp.quote(filter)}/)
     end

Modified: DietRB/trunk/spec/completion_spec.rb
===================================================================
--- DietRB/trunk/spec/completion_spec.rb	2010-10-08 10:54:08 UTC (rev 4650)
+++ DietRB/trunk/spec/completion_spec.rb	2010-10-08 10:54:18 UTC (rev 4651)
@@ -218,4 +218,11 @@
       complete("::CompletionSt").should == %w{ ::CompletionStub }
     end
   end
+  
+  it "completes reserved words as variables or constants" do
+    (IRB::Completion::RESERVED_DOWNCASE_WORDS +
+      IRB::Completion::RESERVED_UPCASE_WORDS).each do |word|
+      complete(word[0..-2]).should.include word
+    end
+  end
 end
\ No newline at end of file
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/macruby-changes/attachments/20101008/e8e739a5/attachment.html>


More information about the macruby-changes mailing list