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

ruby-changes:49422

From: nobu <ko1@a...>
Date: Tue, 2 Jan 2018 12:00:19 +0900 (JST)
Subject: [ruby-changes:49422] nobu:r61538 (trunk): parse.y: code end position

nobu	2018-01-02 12:00:13 +0900 (Tue, 02 Jan 2018)

  New Revision: 61538

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

  Log:
    parse.y: code end position
    
    * parse.y (parser_yyerror): use the given location as the end of
      erred code, instead of the current position.

  Modified files:
    trunk/parse.y
    trunk/test/ruby/test_parse.rb
Index: parse.y
===================================================================
--- parse.y	(revision 61537)
+++ parse.y	(revision 61538)
@@ -5378,7 +5378,7 @@ parser_yyerror(struct parser_params *par https://github.com/ruby/ruby/blob/trunk/parse.y#L5378
     }
 
     pt = (ruby_sourceline == yylloc->last_loc.lineno) ?
-	    lex_p : lex_pend;
+	    lex_pbeg + yylloc->last_loc.column : lex_pend;
     p = pe = pt < pend ? pt : pend;
     lim = p - lex_pbeg > max_line_margin ? p - max_line_margin : lex_pbeg;
     while ((lim < p) && (*(p-1) != '\n')) p--;
Index: test/ruby/test_parse.rb
===================================================================
--- test/ruby/test_parse.rb	(revision 61537)
+++ test/ruby/test_parse.rb	(revision 61538)
@@ -1099,6 +1099,12 @@ x = __ENCODING__ https://github.com/ruby/ruby/blob/trunk/test/ruby/test_parse.rb#L1099
     assert_raise(SyntaxError) { eval("def m\n\C-z""end") }
   end
 
+  def test_location_of_invalid_token
+    assert_raise_with_message(SyntaxError, /^      \^~~\z/) do
+      eval('class xxx end')
+    end
+  end
+
 =begin
   def test_past_scope_variable
     assert_warning(/past scope/) {catch {|tag| eval("BEGIN{throw tag}; tap {a = 1}; a")}}

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

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