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

ruby-changes:45644

From: nobu <ko1@a...>
Date: Sun, 26 Feb 2017 09:33:11 +0900 (JST)
Subject: [ruby-changes:45644] nobu:r57717 (trunk): parse.y: indent at invalid identifier

nobu	2017-02-26 09:33:06 +0900 (Sun, 26 Feb 2017)

  New Revision: 57717

  https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=57717

  Log:
    parse.y: indent at invalid identifier
    
    * parse.y (parser_heredoc_identifier): set indent only when valid
      identifier, not to dedent non-existent contents later.
      [ruby-core:79772] [Bug #13253]

  Modified files:
    trunk/parse.y
    trunk/test/ruby/test_syntax.rb
Index: test/ruby/test_syntax.rb
===================================================================
--- test/ruby/test_syntax.rb	(revision 57716)
+++ test/ruby/test_syntax.rb	(revision 57717)
@@ -656,6 +656,10 @@ eom https://github.com/ruby/ruby/blob/trunk/test/ruby/test_syntax.rb#L656
     assert_equal(expected, actual, bug7559)
   end
 
+  def test_dedented_heredoc_invalid_identifer
+    assert_syntax_error('<<~ "#{}"', /unexpected <</)
+  end
+
   def test_lineno_operation_brace_block
     expected = __LINE__ + 1
     actual = caller_lineno\
Index: parse.y
===================================================================
--- parse.y	(revision 57716)
+++ parse.y	(revision 57717)
@@ -6234,6 +6234,7 @@ parser_heredoc_identifier(struct parser_ https://github.com/ruby/ruby/blob/trunk/parse.y#L6234
     int token = tSTRING_BEG;
     long len;
     int newline = 0;
+    int indent = 0;
 
     if (c == '-') {
 	c = nextc();
@@ -6242,8 +6243,7 @@ parser_heredoc_identifier(struct parser_ https://github.com/ruby/ruby/blob/trunk/parse.y#L6243
     else if (c == '~') {
 	c = nextc();
 	func = STR_FUNC_INDENT;
-	heredoc_indent = INT_MAX;
-	heredoc_line_indent = 0;
+	indent = INT_MAX;
     }
     switch (c) {
       case '\'':
@@ -6282,7 +6282,7 @@ parser_heredoc_identifier(struct parser_ https://github.com/ruby/ruby/blob/trunk/parse.y#L6282
 	if (!parser_is_identchar()) {
 	    pushback(c);
 	    if (func & STR_FUNC_INDENT) {
-		pushback(heredoc_indent > 0 ? '~' : '-');
+		pushback(indent > 0 ? '~' : '-');
 	    }
 	    return 0;
 	}
@@ -6305,6 +6305,8 @@ parser_heredoc_identifier(struct parser_ https://github.com/ruby/ruby/blob/trunk/parse.y#L6305
 				  lex_lastline);		/* nd_orig */
     parser_set_line(lex_strterm, ruby_sourceline);
     ripper_flush(parser);
+    heredoc_indent = indent;
+    heredoc_line_indent = 0;
     return token;
 }
 

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

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