[macruby-changes] [4415] MacRuby/trunk

source_changes at macosforge.org source_changes at macosforge.org
Fri Aug 6 16:48:45 PDT 2010


Revision: 4415
          http://trac.macosforge.org/projects/ruby/changeset/4415
Author:   eloy.de.enige at gmail.com
Date:     2010-08-06 16:48:44 -0700 (Fri, 06 Aug 2010)
Log Message:
-----------
Update DietRB to HEAD 7366450743a2a7b482b576c88dafa96d069b7941

Modified Paths:
--------------
    MacRuby/trunk/lib/irb/ext/completion.rb
    MacRuby/trunk/lib/irb/source.rb
    MacRuby/trunk/spec/dietrb/ext/completion_spec.rb
    MacRuby/trunk/spec/dietrb/source_spec.rb

Modified: MacRuby/trunk/lib/irb/ext/completion.rb
===================================================================
--- MacRuby/trunk/lib/irb/ext/completion.rb	2010-08-06 20:57:20 UTC (rev 4414)
+++ MacRuby/trunk/lib/irb/ext/completion.rb	2010-08-06 23:48:44 UTC (rev 4415)
@@ -59,6 +59,14 @@
       evaluate('local_variables').map(&:to_s)
     end
     
+    def instance_variables
+      context.object.instance_variables.map(&:to_s)
+    end
+    
+    def global_variables
+      super.map(&:to_s)
+    end
+    
     def instance_methods
       context.object.methods.map(&:to_s)
     end
@@ -106,7 +114,13 @@
         end
         
         if call
-          format_methods(receiver, methods || methods_of_object(root), filter)
+          if results = (methods || methods_of_object(root))
+            format_methods(receiver, results, filter)
+          else
+            # this is mainly because MacRuby currently has a problem with local_variables,
+            # normally I'd prefer to let the program die so the user might report it
+            []
+          end
         else
           match_methods_vars_or_consts_in_scope(root)
         end.sort.uniq
@@ -129,8 +143,10 @@
       case var[TYPE]
       when :@ident
         local_variables + instance_methods + RESERVED_DOWNCASE_WORDS
+      when :@ivar
+        instance_variables
       when :@gvar
-        global_variables.map(&:to_s)
+        global_variables
       when :@const
         if symbol[TYPE] == :top_const_ref
           filter = "::#{filter}"
@@ -174,8 +190,10 @@
         case type
         when :@ident
           evaluate(name).methods if local_variables.include?(name)
+        when :@ivar
+          evaluate(name).methods if instance_variables.include?(name)
         when :@gvar
-          eval(name).methods if global_variables.include?(name.to_sym)
+          eval(name).methods if global_variables.include?(name)
         when :@const
           evaluate(name).methods if constants.include?(name)
         end

Modified: MacRuby/trunk/lib/irb/source.rb
===================================================================
--- MacRuby/trunk/lib/irb/source.rb	2010-08-06 20:57:20 UTC (rev 4414)
+++ MacRuby/trunk/lib/irb/source.rb	2010-08-06 23:48:44 UTC (rev 4415)
@@ -72,7 +72,7 @@
       def initialize(source)
         super
         @level = 0
-        @code_block = !parse.nil?
+        @code_block = !parse.nil? && !@in_string && !@in_regexp && !@in_array
       end
       
       # Returns the code block indentation level.
@@ -183,6 +183,65 @@
         @level -= 1
         super
       end
+
+      def on_tstring_beg(token)
+        @in_string = token
+        @level += 1
+        super
+      end
+
+      def on_tstring_end(token)
+        if @in_string && tokens_match?(@in_string, token)
+          @in_string = nil
+          @level -= 1
+        end
+        super
+      end
+
+      def on_qwords_beg(token)
+        @in_array = token.strip
+        @level += 1
+        super
+      end
+      alias_method :on_words_beg, :on_qwords_beg
+
+      def on_words_sep(token)
+        if tokens_match?(@in_array, token)
+          @in_array = false
+          @level -= 1
+        end
+        super
+      end
+
+      def on_regexp_beg(token)
+        @in_regexp = token
+        @level += 1
+        super
+      end
+
+      def on_regexp_end(token)
+        if tokens_match?(@in_regexp, token)
+          @in_regexp = false
+          @level -= 1
+        end
+        super
+      end
+
+      def tokens_match?(open_token, close_token)
+        last_char_open_token = open_token[-1, 1]
+        last_char_close_token = close_token[-1, 1]
+        if last_char_open_token == last_char_close_token
+          true
+        else
+          case last_char_open_token
+          when '{' then last_char_close_token == '}'
+          when '(' then last_char_close_token == ')'
+          when '[' then last_char_close_token == ']'
+          else
+            false
+          end
+        end
+      end
     end
   end
 end

Modified: MacRuby/trunk/spec/dietrb/ext/completion_spec.rb
===================================================================
--- MacRuby/trunk/spec/dietrb/ext/completion_spec.rb	2010-08-06 20:57:20 UTC (rev 4414)
+++ MacRuby/trunk/spec/dietrb/ext/completion_spec.rb	2010-08-06 23:48:44 UTC (rev 4415)
@@ -58,6 +58,11 @@
           complete('foo.').should include('foo.singleton_method')
         end
         
+        it "matches as an instance variable" do
+          @context.__evaluate__('@an_instance_variable = ::CompletionStub.new')
+          complete('@an_instance_variable.').should == imethods(::CompletionStub, '@an_instance_variable')
+        end
+        
         it "matches as a global variable" do
           complete('$a_completion_stub.').should == imethods(::CompletionStub, '$a_completion_stub')
         end
@@ -193,9 +198,10 @@
       end
       
       it "filters the methods, of the variable receiver, by the given method name" do
-        @context.__evaluate__('foo = ::CompletionStub.new')
+        @context.__evaluate__('foo = @an_instance_variable = ::CompletionStub.new')
         complete('foo.an_im').should == %w{ foo.an_imethod }
         complete('$a_completion_stub.an_im').should == %w{ $a_completion_stub.an_imethod }
+        complete('@an_instance_variable.an_im').should == %w{ @an_instance_variable.an_imethod }
         # TODO: fix
         # complete('CompletionStub.a_sing').should == %w{ CompletionStub.a_singleton_method }
       end
@@ -204,7 +210,7 @@
   
   describe "when *not* doing a method call on an explicit receiver" do
     before do
-      @context.__evaluate__("a_local_variable = :ok")
+      @context.__evaluate__("a_local_variable = @an_instance_variable = :ok")
     end
     
     it "matches local variables" do
@@ -219,6 +225,10 @@
       complete("a_loc").should == %w{ a_local_method a_local_variable }
     end
     
+    it "matches instance variables" do
+      complete("@an_inst").should == %w{ @an_instance_variable }
+    end
+    
     it "matches global variables" do
       complete("$a_completion_s").should == %w{ $a_completion_stub }
     end

Modified: MacRuby/trunk/spec/dietrb/source_spec.rb
===================================================================
--- MacRuby/trunk/spec/dietrb/source_spec.rb	2010-08-06 20:57:20 UTC (rev 4414)
+++ MacRuby/trunk/spec/dietrb/source_spec.rb	2010-08-06 23:48:44 UTC (rev 4415)
@@ -140,11 +140,14 @@
   it "returns whether or not the source contains a syntax error, except a code block not ending" do
     reflect("def;").syntax_error?.should == true
     reflect("def;").syntax_error?.should == true
+    reflect("{ [ } ]").syntax_error?.should == true
     reflect("def foo").syntax_error?.should == false
     reflect("class A; }").syntax_error?.should == true
     reflect("class A; {" ).syntax_error?.should == false
+    reflect("class A; def {").syntax_error?.should == true
     reflect("class A def foo").syntax_error?.should == true
     reflect("class A; def foo" ).syntax_error?.should == false
+    reflect("def foo; {; end; }").syntax_error?.should == true
   end
   
   it "returns the actual syntax error message if one occurs" do
@@ -185,12 +188,68 @@
   it "correctly increases and decreases the code block indentation level for literals" do
     [
       ["lambda { |x|", "}"],
-      ["{", "}"],
-      ['"#{', '}"'],
-      ["[", "]"]
+      ["{ :foo => ", " :bar }"],
+      ["[ 1", ", 2 ]"],
+
+      ["'", "'"],
+      ["' ", " '"],
+      ["'foo ", " bar'"],
+      ["' foo ", " bar '"],
+
+      ['"', '"'],
+      ['" ', ' "'],
+      ['"foo ', ' bar"'],
+      ['" foo ', ' bar "'],
+
+      ["%{", "}"],
+      ["%{ ", " }"],
+      ["%{foo ", " bar}"],
+      ["%{ foo ", " bar }"],
+      ["%(foo ", " bar)"],
+      ["%( foo ", " bar )"],
+      ["%[ foo ", " bar ]"],
+      ["%[foo ", " bar]"],
+
+      ["%w{ ", " }"],
+      ["%w{foo ", " bar}"],
+      ["%w{ foo ", " bar }"],
+      ["%w(foo ", " bar)"],
+      ["%w( foo ", " bar )"],
+      ["%w[foo ", " bar]"],
+      ["%w[ foo ", " bar ]"],
+
+      ["%W{foo ", " bar}"],
+      ["%W{ foo ", " bar }"],
+      ["%W(foo ", " bar)"],
+      ["%W( foo ", " bar )"],
+      ["%W[foo ", " bar]"],
+      ["%W[ foo ", " bar ]"],
+
+      ["%r{foo ", " bar}"],
+      ["%r{ foo ", " bar }"],
+      ["%r(foo ", " bar)"],
+      ["%r( foo ", " bar )"],
+      ["%r[foo ", " bar]"],
+      ["%r[ foo ", " bar ]"],
+
+      ["/foo ", " bar/"],
+      ["/ foo ", " bar /"],
     ].each do |open, close|
       reflect(open).level.should == 1
+      reflect(open).code_block?.should == false
       reflect("#{open}\n#{close}").level.should == 0
+      reflect("#{open}\n#{close}").code_block?.should == true
     end
   end
+
+  it "handles cases that contain backspaces" do
+    [
+      ["%{", "\b"],
+      ["%w{", "\b"],
+      ["%r{", "\b"],
+    ].each do |open, close|
+      reflect("#{open}\n#{close}").level.should == 1
+      reflect("#{open}\n#{close}").code_block?.should == false
+    end
+  end
 end
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/macruby-changes/attachments/20100806/c2b30393/attachment-0001.html>


More information about the macruby-changes mailing list