Skip to content

Commit

Permalink
Merge pull request #1312 from flavorjones/flavorjones-fix-comment-eof
Browse files Browse the repository at this point in the history
fix: newline tracking for a comment at EOF
  • Loading branch information
kddnewton authored Aug 23, 2023
2 parents bc144ad + 62fb0bd commit df807d7
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 2 deletions.
1 change: 1 addition & 0 deletions src/util/yp_newline_list.c
Original file line number Diff line number Diff line change
Expand Up @@ -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]);
Expand Down
2 changes: 1 addition & 1 deletion src/yarp.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
5 changes: 4 additions & 1 deletion test/comments_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit df807d7

Please sign in to comment.