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

ruby-changes:54711

From: nobu <ko1@a...>
Date: Sat, 26 Jan 2019 22:43:38 +0900 (JST)
Subject: [ruby-changes:54711] nobu:r66927 (trunk): parse.y: trim newline in erred code

nobu	2019-01-26 22:43:32 +0900 (Sat, 26 Jan 2019)

  New Revision: 66927

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

  Log:
    parse.y: trim newline in erred code
    
    * parse.y (parser_yyerror): trim a newline at the end of the erred
      code which was replaced with an extra space in the succeeding
      cursor line.

  Modified files:
    trunk/parse.y
    trunk/test/ruby/test_syntax.rb
Index: parse.y
===================================================================
--- parse.y	(revision 66926)
+++ parse.y	(revision 66927)
@@ -4689,6 +4689,7 @@ parser_yyerror(struct parser_params *p, https://github.com/ruby/ruby/blob/trunk/parse.y#L4689
 
     pt = (p->ruby_sourceline == yylloc->end_pos.lineno) ?
 	    p->lex.pbeg + yylloc->end_pos.column : p->lex.pend;
+    if ((p->lex.pbeg < pt) && (*(pt-1) == '\n')) pt--;
     ptr = ptr_end = pt < pend ? pt : pend;
     lim = ptr - p->lex.pbeg > max_line_margin ? ptr - max_line_margin : p->lex.pbeg;
     while ((lim < ptr) && (*(ptr-1) != '\n')) ptr--;
Index: test/ruby/test_syntax.rb
===================================================================
--- test/ruby/test_syntax.rb	(revision 66926)
+++ test/ruby/test_syntax.rb	(revision 66927)
@@ -1142,6 +1142,12 @@ eom https://github.com/ruby/ruby/blob/trunk/test/ruby/test_syntax.rb#L1142
     end;
   end
 
+  def test_syntax_error_at_newline
+    expected = "\n        ^"
+    assert_syntax_error("%[abcdef", expected)
+    assert_syntax_error("%[abcdef\n", expected)
+  end
+
   def test_invalid_jump
     assert_in_out_err(%w[-e redo], "", [], /^-e:1: /)
   end

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

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