[前][次][番号順一覧][スレッド一覧]

ruby-changes:30901

From: nobu <ko1@a...>
Date: Thu, 19 Sep 2013 16:59:16 +0900 (JST)
Subject: [ruby-changes:30901] nobu:r42980 (trunk): parse.y: adjust position of lambda

nobu	2013-09-19 16:59:07 +0900 (Thu, 19 Sep 2013)

  New Revision: 42980

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=42980

  Log:
    parse.y: adjust position of lambda
    
    * parse.y (lambda): adjust position to the beginning of the block.

  Modified files:
    trunk/ChangeLog
    trunk/parse.y
    trunk/test/ruby/test_lambda.rb
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 42979)
+++ ChangeLog	(revision 42980)
@@ -1,3 +1,7 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Thu Sep 19 16:59:02 2013  Nobuyoshi Nakada  <nobu@r...>
+
+	* parse.y (lambda): adjust position to the beginning of the block.
+
 Thu Sep 19 16:25:06 2013  Nobuyoshi Nakada  <nobu@r...>
 
 	* vsnprintf.c (BSD_vfprintf): initialize cp so that size is 0 in the
Index: parse.y
===================================================================
--- parse.y	(revision 42979)
+++ parse.y	(revision 42980)
@@ -3460,13 +3460,17 @@ lambda		:   { https://github.com/ruby/ruby/blob/trunk/parse.y#L3460
 			lpar_beg = ++paren_nest;
 		    }
 		  f_larglist
+		    {
+			$<num>$ = ruby_sourceline;
+		    }
 		  lambda_body
 		    {
 			lpar_beg = $<num>2;
 		    /*%%%*/
-			$$ = NEW_LAMBDA($3, $4);
+			$$ = NEW_LAMBDA($3, $5);
+			nd_set_line($$, $<num>4);
 		    /*%
-			$$ = dispatch2(lambda, $3, $4);
+			$$ = dispatch2(lambda, $3, $5);
 		    %*/
 			dyna_pop($<vars>1);
 		    }
Index: test/ruby/test_lambda.rb
===================================================================
--- test/ruby/test_lambda.rb	(revision 42979)
+++ test/ruby/test_lambda.rb	(revision 42980)
@@ -109,4 +109,28 @@ class TestLambdaParameters < Test::Unit: https://github.com/ruby/ruby/blob/trunk/test/ruby/test_lambda.rb#L109
     assert_equal(42, return_in_current(42), feature8693)
     assert_equal(42, return_in_callee(42), feature8693)
   end
+
+  def test_do_lambda_source_location
+    exp_lineno = __LINE__ + 3
+    lmd = ->(x,
+             y,
+             z) do
+      #
+    end
+    file, lineno = lmd.source_location
+    assert_match(/^#{ Regexp.quote(__FILE__) }$/, file)
+    assert_equal(exp_lineno, lineno, "must be ")
+  end
+
+  def test_brace_lambda_source_location
+    exp_lineno = __LINE__ + 3
+    lmd = ->(x,
+             y,
+             z) {
+      #
+    }
+    file, lineno = lmd.source_location
+    assert_match(/^#{ Regexp.quote(__FILE__) }$/, file)
+    assert_equal(exp_lineno, lineno, "must be ")
+  end
 end

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]