[ruby/yarp] fix: newline tracking for a comment at EOF

https://github.com/ruby/yarp/commit/62fb0bddf5
This commit is contained in:
Mike Dalessio 2023-08-23 11:07:52 -04:00 committed by git
parent 8f0a8e579d
commit 9c43ec621d
3 changed files with 6 additions and 2 deletions

View File

@ -6,7 +6,10 @@ class CommentsTest < Test::Unit::TestCase
include ::YARP::DSL
def test_comment_inline
assert_comment "# comment", :inline, 0..9
source = "# comment"
assert_comment source, :inline, 0..9
assert_equal [0], YARP.const_get(:Debug).newlines(source)
end
def test_comment_inline_def

View File

@ -30,6 +30,7 @@ yp_newline_list_append(yp_newline_list_t *list, const char *cursor) {
if (list->offsets == NULL) return false;
}
assert(*cursor == '\n');
assert(cursor >= list->start);
size_t newline_offset = (size_t) (cursor - list->start + 1);
assert(list->size == 0 || newline_offset > list->offsets[list->size - 1]);

View File

@ -5389,7 +5389,7 @@ parser_lex(yp_parser_t *parser) {
/* fallthrough */
case '\n': {
if (parser->heredoc_end == NULL) {
yp_newline_list_append(&parser->newline_list, parser->current.end - 1);
yp_newline_list_check_append(&parser->newline_list, parser->current.end - 1);
} else {
parser_flush_heredoc_end(parser);
}