[#5563] Non-overridable and non-redefinable methods — Eric Mahurin <eric_mahurin@...>

Lately, I've been thinking about the future of ruby

44 messages 2005/08/19
[#5564] Re: Non-overridable and non-redefinable methods — Austin Ziegler <halostatue@...> 2005/08/19

On 8/19/05, Eric Mahurin <eric_mahurin@yahoo.com> wrote:

[#5571] Re: Non-overridable and non-redefinable methods — Eric Mahurin <eric_mahurin@...> 2005/08/19

--- Austin Ziegler <halostatue@gmail.com> wrote:

[#5574] Re: Non-overridable and non-redefinable methods — TRANS <transfire@...> 2005/08/20

Just wanted to add a few things.

[#5581] Re: Non-overridable and non-redefinable methods — Austin Ziegler <halostatue@...> 2005/08/20

On 8/19/05, TRANS <transfire@gmail.com> wrote:

[#5583] Re: Non-overridable and non-redefinable methods — "David A. Black" <dblack@...> 2005/08/20

Hi --

[#5585] Re: Non-overridable and non-redefinable methods — Eric Mahurin <eric_mahurin@...> 2005/08/20

--- "David A. Black" <dblack@wobblini.net> wrote:

[#5609] Pathname#walk for traversing path nodes (patch) — ES <ruby-ml@...>

Here is a small addition to Pathname against 1.9, probably suited

20 messages 2005/08/22

[PATCH] parsing ->(){} expressions in 1.9

From: Mauricio Fernandez <mfp@...>
Date: 2005-08-15 22:51:53 UTC
List: ruby-core #5551
$ ./ruby -ve "->(){ {} }"
ruby 1.9.0 (2005-08-15) [i686-linux]
-e:1: syntax error
->(){ {} }
       ^

This works for me:


Index: parse.y
===================================================================
RCS file: /src/ruby/parse.y,v
retrieving revision 1.403
diff -p -u -r1.403 parse.y
--- parse.y	12 Aug 2005 08:13:27 -0000	1.403
+++ parse.y	15 Aug 2005 22:40:06 -0000
@@ -95,6 +95,10 @@ union tmpyystype {
     unsigned long id;
     int num;
     struct RVarmap *vars;
+    struct {
+	int num;
+	struct RVarmap *vars;
+    } linfo;
 };
 
 struct local_vars {
@@ -447,6 +451,10 @@ static void ripper_compile_error _((stru
     ID id;
     int num;
     struct RVarmap *vars;
+    struct {
+	int num;
+	struct RVarmap *vars;
+    } linfo;
 }
 
 /*%%%*/
@@ -3178,10 +3186,10 @@ bv_decl		:  tIDENTIFIER
 		;
 
 lambda		: {
-			$<num>$ = lpar_beg;
+			$<linfo>$.num = lpar_beg;
 			lpar_beg = ++paren_nest;
 		    /*%%%*/
-			$<vars>$ = dyna_push();
+			$<linfo>$.vars = dyna_push();
 		    /*%
 		    %*/
 		    }
@@ -3194,7 +3202,8 @@ lambda		: {
 		    /*%%%*/
 			$$ = $2;
                         $$->nd_body = block_append($$->nd_body, $4);
-			dyna_pop($<vars>1);
+			dyna_pop($<linfo>1.vars);
+			lpar_beg = $<linfo>1.num;
 		    /*%
 		    	$$ = dispatch2(lambda, $2, $4);
 		    %*/
@@ -6485,6 +6494,8 @@ parser_yylex(parser)
       case '{':
 	if (lpar_beg && lpar_beg == paren_nest) {
 	    lex_state = EXPR_BEG;
+	    lpar_beg = 0;
+	    --paren_nest;
 	    return tLAMBEG;
 	}
 	if (IS_ARG() || lex_state == EXPR_END || lex_state == EXPR_END2)
@@ -6805,6 +6816,8 @@ parser_yylex(parser)
 		    }
 		    if (kw->id[0] == kDO) {
 			if (lpar_beg && lpar_beg == paren_nest) {
+			    lpar_beg = 0;
+			    --paren_nest;
 			    return kDO_LAMBDA;
 			}
 			if (COND_P()) return kDO_COND;



$ ./ruby -e "->(){ {} }"
$ cat syn.rb
require 'test/unit'

class TestLambdaSyntax < Test::Unit::TestCase
  def test_syntax
      l = ->(a = ->(b = 1){b}){ a.call }
      assert_equal(1, l.call)
      l = ->(a = ->(b = ->(c = ->(){2}){ c.call }){b.call}){ a.call }
      assert_equal(2, l.call)
      l = ->(a = ->(b = ->(c = ->(){3}){ (->(){c}.call.call) }){b.call}){ a.call }
      assert_equal(3, l.call)
      l=->(a=->(b=->(c=->(){3}){(->(){c}.call.call)}){b.call}){a.call}
      assert_equal(3, l.call)
      l = -> a = 1 { a }
      assert_equal(1, l.call)
      l = -> a = 1, b = 2 { [a, b] }
      assert_equal([1,2], l.call)
      l = -> a = -> c = 1 {c}, b = 2 { [a.call, b] }
      assert_equal([1,2], l.call)
  end
end
$ ./ruby syn.rb
Loaded suite syn
Started
.
Finished in 0.001503 seconds.

1 tests, 7 assertions, 0 failures, 0 errors


-- 
Mauricio Fernandez

In This Thread

Prev Next