[macruby-changes] [4217] MacRuby/trunk

source_changes at macosforge.org source_changes at macosforge.org
Thu Jun 10 19:31:14 PDT 2010


Revision: 4217
          http://trac.macosforge.org/projects/ruby/changeset/4217
Author:   martinlagardette at apple.com
Date:     2010-06-10 19:31:10 -0700 (Thu, 10 Jun 2010)
Log Message:
-----------
Allow reserved keywords to be used as function keyword arguments

Modified Paths:
--------------
    MacRuby/trunk/parse.y
    MacRuby/trunk/spec/macruby/language/method_spec.rb

Modified: MacRuby/trunk/parse.y
===================================================================
--- MacRuby/trunk/parse.y	2010-06-10 01:03:00 UTC (rev 4216)
+++ MacRuby/trunk/parse.y	2010-06-11 02:31:10 UTC (rev 4217)
@@ -7587,6 +7587,16 @@
 		}
 	    }
 
+	    if ((lex_state == EXPR_BEG && !cmd_state) ||
+		lex_state == EXPR_ARG ||
+		lex_state == EXPR_CMDARG) {
+		if (peek(':') && !(lex_p + 1 < lex_pend && lex_p[1] == ':')) {
+		    lex_state = EXPR_BEG;
+		    nextc();
+		    set_yylval_id(TOK_INTERN(!ENC_SINGLE(mb)));
+		    return tLABEL;
+		}
+	    }
 #if WITH_OBJC
 	    if (lex_state != EXPR_DOT) {
 #else
@@ -7627,16 +7637,6 @@
 		}
 	    }
 
-	    if ((lex_state == EXPR_BEG && !cmd_state) ||
-		lex_state == EXPR_ARG ||
-		lex_state == EXPR_CMDARG) {
-		if (peek(':') && !(lex_p + 1 < lex_pend && lex_p[1] == ':')) {
-		    lex_state = EXPR_BEG;
-		    nextc();
-		    set_yylval_id(TOK_INTERN(!ENC_SINGLE(mb)));
-		    return tLABEL;
-		}
-	    }
 	    if (IS_BEG() ||
 		lex_state == EXPR_DOT ||
 		IS_ARG()) {

Modified: MacRuby/trunk/spec/macruby/language/method_spec.rb
===================================================================
--- MacRuby/trunk/spec/macruby/language/method_spec.rb	2010-06-10 01:03:00 UTC (rev 4216)
+++ MacRuby/trunk/spec/macruby/language/method_spec.rb	2010-06-11 02:31:10 UTC (rev 4217)
@@ -35,6 +35,13 @@
     lambda { eval("def foo(x, with:y, z); end") }.should raise_error(SyntaxError)
   end
 
+  it "can be called with reserved words as keyword arguments" do
+    def @o.doSomething(x, in: y); x + y; end
+    @o.doSomething(40, in: 2).should == 42
+    @o.performSelector(:'doSomething:in:', withObject: 40, withObject: 2).should == 42
+    @o.send(:'doSomething:in:', 40, 2).should == 42
+  end
+
   it "can be called using argument-names + colon + variable syntax" do
     def @o.doSomething(x, withObject:y, withObject:z); x + y + z; end
     @o.doSomething(30, withObject:10, withObject:2).should == 42
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/macruby-changes/attachments/20100610/13a5b3c0/attachment.html>


More information about the macruby-changes mailing list