[macruby-changes] [562] MacRuby/trunk/bin/rb_nibtool

source_changes at macosforge.org source_changes at macosforge.org
Fri Sep 5 20:05:18 PDT 2008


Revision: 562
          http://trac.macosforge.org/projects/ruby/changeset/562
Author:   lsansonetti at apple.com
Date:     2008-09-05 20:05:17 -0700 (Fri, 05 Sep 2008)
Log Message:
-----------
fix some inevitable bugs

Modified Paths:
--------------
    MacRuby/trunk/bin/rb_nibtool

Modified: MacRuby/trunk/bin/rb_nibtool
===================================================================
--- MacRuby/trunk/bin/rb_nibtool	2008-09-06 01:05:31 UTC (rev 561)
+++ MacRuby/trunk/bin/rb_nibtool	2008-09-06 03:05:17 UTC (rev 562)
@@ -29,14 +29,14 @@
           else _file
         end
       end
-      opts.on('-h', '--help', 'Print this message') { fail opts }
+      opts.on('-h', '--help', 'Print this message') { opt_error opts }
       begin
         opts.parse!(argv)
       rescue OptionParser::InvalidOption => e
         puts e
-        fail opts
+        opt_error opts
       end
-      fail opts if file.nil?
+      opt_error opts if file.nil?
     end
 
     o = super(File.read(file)); o.parse(nil); o
@@ -61,7 +61,7 @@
 
   private
 
-  def fail(opts); puts opts; exit 1; end
+  def self.opt_error(opts); puts opts; exit 1; end
 
   class IBClass
     attr_accessor :name, :super, :outlets, :actions
@@ -83,6 +83,7 @@
     if event == :on_kw
       if token == 'class'
         @def_class = true
+
       elsif token == 'def'
         @def_method = true
       end
@@ -91,7 +92,12 @@
       if @def_class
         @def_class = nil
         @waiting_for_superclass = @token_n
-        (@ib_classes ||= []) << @current_class = IBClass.new(token)
+        @ib_classes ||= []
+        if k = @ib_classes.find { |x| x.name == token }
+          @current_class = k
+        else
+ 	  @ib_classes << @current_class = IBClass.new(token)
+        end
 
       elsif @waiting_for_superclass
         raise "current_class undefined" unless @current_class
@@ -100,14 +106,24 @@
 
     elsif event == :on_ident
       if token == 'attr_accessor' or token == 'attr_writer' \
-      or token == 'ib_outlet' or token == 'ib_outlets'
+      or token == 'ib_outlet' or token == 'ib_outlets' \
+      or token == 'ns_outlet' or token == 'ns_outlets'
         @waiting_for_outlet = @token_n
 
+      elsif token == 'ib_action'
+        @waiting_for_action = @token_n
+
       elsif @waiting_for_outlet
         raise "current_class undefined" unless @current_class
-        @current_class.outlets << token
+        ary = @current_class.outlets
+        ary << token unless ary.include?(token)
         @waiting_for_outlet += 1 # maybe another outlet is coming...
 
+      elsif @waiting_for_action
+        raise "current_class undefined" unless @current_class
+        ary = @current_class.actions
+        ary << token unless ary.include?(token)
+
       elsif @def_method
         @def_method = nil
         @current_method = token
@@ -133,18 +149,36 @@
       end
     end
 
+    if @waiting_for_action and @token_n != @waiting_for_action
+      if (event == :on_symbeg and token == ':')
+        @waiting_for_action += 1
+      else
+        @waiting_for_action = nil
+      end
+    end
+
     if @waiting_for_method_end and @token_n != @waiting_for_method_end
       if event == :on_lparen
         @on_def_method_paren += 1
         @waiting_for_method_end += 1
+
       elsif event == :on_rparen
 	@on_def_method_paren -= 1
         @waiting_for_method_end += 1
+
       elsif event == :on_ident and token == 'sender'
         @waiting_for_method_end += 1
-      elsif event == :on_nl or event == :on_ignored_nl \
-      or event == :on_semicolon or event == :on_comment
-        @current_class.actions << @current_method
+        @has_sender_arg = true
+
+      elsif @on_def_method_paren == 0 \
+      and @has_sender_arg \
+      and (event == :on_nl or event == :on_ignored_nl \
+           or event == :on_semicolon or event == :on_comment)
+        ary = @current_class.actions
+        ary << @current_method unless ary.include?(@current_method)
+        @waiting_for_method_end = nil
+	@has_sender_arg = nil
+
       else
         @waiting_for_method_end = nil
       end
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.macosforge.org/pipermail/macruby-changes/attachments/20080905/41bd5619/attachment.html 


More information about the macruby-changes mailing list