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

ruby-changes:55846

From: Nobuyoshi <ko1@a...>
Date: Sun, 26 May 2019 16:25:32 +0900 (JST)
Subject: [ruby-changes:55846] Nobuyoshi Nakada: 02b39daef8 (trunk): Fix scanner event at invalid syntax

https://git.ruby-lang.org/ruby.git/commit/?id=02b39daef8

From 02b39daef834890981689f1f697c7c25cad55dd6 Mon Sep 17 00:00:00 2001
From: Nobuyoshi Nakada <nobu@r...>
Date: Sun, 26 May 2019 11:33:40 +0900
Subject: Fix scanner event at invalid syntax

* parse.y (parser_yyerror, parser_compile_error): revert
  r67224 (e5d10cda07b23682e5e4e64d1324e4d3247d4785) "Flush erred
  token".

diff --git a/parse.y b/parse.y
index 2b34e8a..fcd4959 100644
--- a/parse.y
+++ b/parse.y
@@ -5558,7 +5558,6 @@ parser_yyerror(struct parser_params *p, const YYLTYPE *yylloc, const char *msg) https://github.com/ruby/ruby/blob/trunk/parse.y#L5558
 {
     dispatch1(parse_error, STR_NEW2(msg));
     ripper_error(p);
-    token_flush(p);
     return 0;
 }
 
@@ -12260,7 +12259,6 @@ parser_compile_error(struct parser_params *p, const char *fmt, ...) https://github.com/ruby/ruby/blob/trunk/parse.y#L12259
 			       rb_long2int(p->lex.pcur - p->lex.pbeg),
 			       p->enc, fmt, ap);
     va_end(ap);
-    token_flush(p);
 }
 
 static size_t
diff --git a/test/irb/test_color.rb b/test/irb/test_color.rb
index 3ba0c4c..c25996e 100644
--- a/test/irb/test_color.rb
+++ b/test/irb/test_color.rb
@@ -35,7 +35,7 @@ module TestIRB https://github.com/ruby/ruby/blob/trunk/test/irb/test_color.rb#L35
         '"foo#{a} #{b}"' => "#{RED}\"#{CLEAR}#{RED}foo#{CLEAR}#{RED}\#{#{CLEAR}a#{RED}}#{CLEAR}#{RED} #{CLEAR}#{RED}\#{#{CLEAR}b#{RED}}#{CLEAR}#{RED}\"#{CLEAR}",
         '/r#{e}g/' => "#{RED}#{BOLD}/#{CLEAR}#{RED}r#{CLEAR}#{RED}\#{#{CLEAR}e#{RED}}#{CLEAR}#{RED}g#{CLEAR}#{RED}#{BOLD}/#{CLEAR}",
         "'a\nb'" => "#{RED}'#{CLEAR}#{RED}a#{CLEAR}\n#{RED}b#{CLEAR}#{RED}'#{CLEAR}",
-        "4.5.6" => "4.5.6",
+        "4.5.6" => "#{MAGENTA}#{BOLD}4.5.6#{CLEAR}",
         "[1]]]" => "[1]]]",
         "\e[0m\n" => "^[[#{BLUE}#{BOLD}0#{CLEAR}m\n",
         "%w[a b]" => "#{RED}%w[#{CLEAR}#{RED}a#{CLEAR} #{RED}b#{CLEAR}#{RED}]#{CLEAR}",
diff --git a/test/ripper/test_scanner_events.rb b/test/ripper/test_scanner_events.rb
index bb98e5d..5fab564 100644
--- a/test/ripper/test_scanner_events.rb
+++ b/test/ripper/test_scanner_events.rb
@@ -19,9 +19,16 @@ class TestRipper::ScannerEvents < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ripper/test_scanner_events.rb#L19
     end
   end
 
-  def scan(target, str)
+  def scan(target, str, &error)
     sym = "on_#{target}".intern
-    Ripper.lex(str).select {|_1,type,_2| type == sym }.map {|_1,_2,tok| tok }
+    lexer = Ripper::Lexer.new(str)
+    if error
+      lexer.singleton_class.class_eval do
+        define_method(:compile_error, error)
+        define_method(:on_parse_error, error)
+      end
+    end
+    lexer.lex.select {|_1,type,_2| type == sym }.map {|_1,_2,tok| tok }
   end
 
   def test_tokenize
@@ -927,6 +934,11 @@ class TestRipper::ScannerEvents < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ripper/test_scanner_events.rb#L934
                  scan('CHAR', "?a")
     assert_equal [],
                  scan('CHAR', "@ivar")
+
+    assert_equal ["?\\M-H"], scan('CHAR', '?\\M-H')
+    err = nil
+    assert_equal ["?\\M"], scan('CHAR', '?\\M ') {|e| err = [__callee__, e]}
+    assert_equal([:on_parse_error, "Invalid escape character syntax"], err)
   end
 
   def test_label
diff --git a/test/ruby/test_iseq.rb b/test/ruby/test_iseq.rb
index f2d11cd..dda70ac 100644
--- a/test/ruby/test_iseq.rb
+++ b/test/ruby/test_iseq.rb
@@ -246,9 +246,12 @@ class TestISeq < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_iseq.rb#L246
       end
     end
     assert_equal([m1, e1.message], [m2, e2.message], feature11951)
-    e1, *, e2 = e1.message.lines
-    assert_send([e1, :start_with?, __FILE__])
-    assert_send([e2, :start_with?, __FILE__])
+    message = e1.message.each_line
+    message.with_index(1) do |line, i|
+      next if /^ / =~ line
+      assert_send([line, :start_with?, __FILE__],
+                  proc {message.map {|l, j| (i == j ? ">" : " ") + l}.join("")})
+    end
   end
 
   def test_compile_file_error
-- 
cgit v0.10.2


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

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