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

ruby-changes:15512

From: nobu <ko1@a...>
Date: Tue, 20 Apr 2010 12:25:21 +0900 (JST)
Subject: [ruby-changes:15512] Ruby:r27414 (trunk): * parse.y (lex_state_e, IS_END, IS_SPCARG, parser_yylex): separate

nobu	2010-04-20 12:24:59 +0900 (Tue, 20 Apr 2010)

  New Revision: 27414

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

  Log:
    * parse.y (lex_state_e, IS_END, IS_SPCARG, parser_yylex): separate
      the state after vcall.  [ruby-core:29578]

  Modified files:
    trunk/ChangeLog
    trunk/parse.y
    trunk/test/ruby/test_parse.rb

Index: ChangeLog
===================================================================
--- ChangeLog	(revision 27413)
+++ ChangeLog	(revision 27414)
@@ -1,3 +1,8 @@
+Tue Apr 20 12:24:57 2010  Nobuyoshi Nakada  <nobu@r...>
+
+	* parse.y (lex_state_e, IS_END, IS_SPCARG, parser_yylex): separate
+	  the state after vcall.  [ruby-core:29578]
+
 Tue Apr 20 01:03:00 2010  Yusuke Endoh  <mame@t...>
 
 	* bootstraptest/test_fork.rb: add a test for [ruby-core:28924].
Index: parse.y
===================================================================
--- parse.y	(revision 27413)
+++ parse.y	(revision 27414)
@@ -67,7 +67,9 @@
     EXPR_FNAME,			/* ignore newline, no reserved words. */
     EXPR_DOT,			/* right after `.' or `::', no reserved words. */
     EXPR_CLASS,			/* immediate after `class', no here document. */
-    EXPR_VALUE			/* alike EXPR_BEG but label is disallowed. */
+    EXPR_VALUE,			/* alike EXPR_BEG but label is disallowed. */
+    EXPR_VCALL,			/* immediate after vcall */
+    EXPR_MAX_STATE
 };
 
 typedef VALUE stack_type;
@@ -6413,9 +6415,9 @@
 }
 
 #define IS_ARG() (lex_state == EXPR_ARG || lex_state == EXPR_CMDARG)
-#define IS_END() (lex_state == EXPR_END || lex_state == EXPR_ENDARG)
+#define IS_END() (lex_state == EXPR_END || lex_state == EXPR_ENDARG || lex_state == EXPR_VCALL)
 #define IS_BEG() (lex_state == EXPR_BEG || lex_state == EXPR_MID || lex_state == EXPR_VALUE || lex_state == EXPR_CLASS)
-#define IS_SPCARG(c) (IS_ARG() && space_seen && !ISSPACE(c))
+#define IS_SPCARG(c) ((IS_ARG() || lex_state == EXPR_VCALL) && space_seen && !ISSPACE(c))
 
 static int
 parser_yylex(struct parser_params *parser)
@@ -6660,8 +6662,7 @@
 	if (c == '<' &&
 	    lex_state != EXPR_DOT &&
 	    lex_state != EXPR_CLASS &&
-	    !IS_END() &&
-	    (!IS_ARG() || space_seen)) {
+	    (!(IS_ARG() || IS_END()) || space_seen)) {
 	    int token = heredoc_identifier();
 	    if (token) return token;
 	}
@@ -6736,11 +6737,11 @@
 	return tSTRING_BEG;
 
       case '?':
-	if (IS_END()) {
+	c = nextc();
+	if (IS_END() && (!space_seen || ISSPACE(c))) {
 	    lex_state = EXPR_VALUE;
 	    return '?';
 	}
-	c = nextc();
 	if (c == -1) {
 	    compile_error(PARSER_ARG "incomplete character syntax");
 	    return 0;
@@ -7316,7 +7317,7 @@
 	    CMDARG_PUSH(0);
 	    return tLAMBEG;
 	}
-	if (IS_ARG() || lex_state == EXPR_END)
+	if (IS_ARG() || lex_state == EXPR_END || lex_state == EXPR_VCALL)
 	    c = '{';          /* block (primary) */
 	else if (lex_state == EXPR_ENDARG)
 	    c = tLBRACE_ARG;  /* block (expr) */
@@ -7624,7 +7625,7 @@
 	    }
 
 	    if ((lex_state == EXPR_BEG && !cmd_state) ||
-		IS_ARG()) {
+		IS_ARG() || lex_state == EXPR_VCALL) {
 		if (peek(':') && !(lex_p + 1 < lex_pend && lex_p[1] == ':')) {
 		    lex_state = EXPR_BEG;
 		    nextc();
@@ -7687,7 +7688,7 @@
 
             set_yylval_name(ident);
             if (last_state != EXPR_DOT && is_local_id(ident) && lvar_defined(ident)) {
-                lex_state = EXPR_END;
+                lex_state = EXPR_VCALL;
             }
         }
 	return result;
Index: test/ruby/test_parse.rb
===================================================================
--- test/ruby/test_parse.rb	(revision 27413)
+++ test/ruby/test_parse.rb	(revision 27414)
@@ -823,4 +823,28 @@
       c.instance_eval { remove_class_variable(:@var) }
     end
   end
+
+  def result(arg = nil, &pro)
+    pro || arg
+  end
+
+  def test_method_and_lvar
+    result = nil
+    bug3163 = '[ruby-core:29578]'
+    assert_equal(%[bug3163], (result %[bug3163]), bug3163)
+    assert_equal(/bug3163/x, (result /bug3163/x), bug3163)
+    pro = proc {}
+    assert_equal(pro, (result &pro), bug3163)
+    assert_equal(bug3163, (result *bug3163), bug3163)
+    f = g = nil
+    assert_raise(SyntaxError, bug3163) {eval("result ?f : g")}
+    assert_equal("123\n", eval("result <<FOO\n123\nFOO"), bug3163)
+
+    bug3163_2 = '[ruby-core:29594]'
+    one = 1
+    assert_equal(+1, (result +one), bug3163_2)
+    assert_equal(-1, (result -one), bug3163_2)
+
+    assert_equal({:a => 1}, (result a: 1))
+  end
 end

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

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