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

ruby-changes:56366

From: Nobuyoshi <ko1@a...>
Date: Thu, 4 Jul 2019 16:14:50 +0900 (JST)
Subject: [ruby-changes:56366] Nobuyoshi Nakada: f19e048d24 (master): Do not dispatch a nil token in ripper

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

From f19e048d244c709e2990ddbb0f986e8b51357bd2 Mon Sep 17 00:00:00 2001
From: Nobuyoshi Nakada <nobu@r...>
Date: Thu, 4 Jul 2019 15:43:33 +0900
Subject: Do not dispatch a nil token in ripper

As a comment token includes the newline, so delayed newline token
just follows it should not be dispatched.  [Bug #11485]

Co-Authored-By: Jeremy Evans <code@j...>

diff --git a/parse.y b/parse.y
index e6d1b95..df773ed 100644
--- a/parse.y
+++ b/parse.y
@@ -5340,6 +5340,7 @@ ripper_dispatch_delayed_token(struct parser_params *p, enum yytokentype t) https://github.com/ruby/ruby/blob/trunk/parse.y#L5340
     int saved_line = p->ruby_sourceline;
     const char *saved_tokp = p->lex.ptok;
 
+    if (NIL_P(p->delayed)) return;
     p->ruby_sourceline = p->delayed_line;
     p->lex.ptok = p->lex.pbeg + p->delayed_col;
     add_mark_object(p, yylval_rval = ripper_dispatch1(p, ripper_token2eventid(t), p->delayed));
diff --git a/test/ripper/test_parser_events.rb b/test/ripper/test_parser_events.rb
index 37d7254..2c3b141 100644
--- a/test/ripper/test_parser_events.rb
+++ b/test/ripper/test_parser_events.rb
@@ -751,6 +751,12 @@ class TestRipper::ParserEvents < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ripper/test_parser_events.rb#L751
     assert_equal true, thru_ifop
   end
 
+  def test_ignored_nl
+    ignored_nl = []
+    parse("foo # comment\n...\n", :on_ignored_nl) {|_, a| ignored_nl << a}
+    assert_equal ["\n"], ignored_nl
+  end
+
   def test_lambda
     thru_lambda = false
     parse('->{}', :on_lambda) {thru_lambda = true}
-- 
cgit v0.10.2


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

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