diff options
author | Nobuyoshi Nakada <nobu@ruby-lang.org> | 2019-07-04 15:43:33 +0900 |
---|---|---|
committer | Nobuyoshi Nakada <nobu@ruby-lang.org> | 2019-07-04 15:58:47 +0900 |
commit | f19e048d244c709e2990ddbb0f986e8b51357bd2 (patch) | |
tree | 8c733ee5c0d475a7c6d72230498a0d9fa35a8fa3 | |
parent | 23c92b6f820f670994026423d4c7b5abcf51eafa (diff) | |
download | ruby-f19e048d244c709e2990ddbb0f986e8b51357bd2.tar.gz |
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@jeremyevans.net>
-rw-r--r-- | parse.y | 1 | ||||
-rw-r--r-- | test/ripper/test_parser_events.rb | 6 |
2 files changed, 7 insertions, 0 deletions
@@ -5340,6 +5340,7 @@ ripper_dispatch_delayed_token(struct parser_params *p, enum yytokentype t) 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 37d72542a7..2c3b141904 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 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} |