1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

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>
This commit is contained in:
Nobuyoshi Nakada 2019-07-04 15:43:33 +09:00
parent 23c92b6f82
commit f19e048d24
No known key found for this signature in database
GPG key ID: 4BC7D6DF58D8DF60
2 changed files with 7 additions and 0 deletions

View file

@ -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));

View file

@ -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}