#2078: parse every file as if its last line were terminated. * * Many grammars treat the line terminator as part of the construct it ends -- * a markdown fence, heading or list marker, a Makefile recipe, a Dockerfile * instruction. A file whose last byte is not "\n" leaves that construct * unterminated: at best a zero-width MISSING token (#1610/#1746 excuse those at * EOF), at worst a WIDTH-
| 532 | * |
| 533 | * A file that is empty or already ends in "\n" is parsed exactly as before. */ |
| 534 | TSTree *cbm_parse_source(TSParser *parser, const char *source, uint32_t source_len, |
| 535 | TSParseOptions opts) { |
| 536 | CBMStringInput input = {source, source_len, source_len > 0 && source[source_len - 1] != '\n'}; |
| 537 | TSInput ts_input = {&input, cbm_string_read, TSInputEncodingUTF8, NULL}; |
| 538 | TSTree *tree = ts_parser_parse_with_options(parser, NULL, ts_input, opts); |
| 539 | if (tree && input.virtual_newline) { |
| 540 | TSPoint end = cbm_source_end_point(source, source_len); |
| 541 | TSInputEdit drop_virtual_newline = { |
| 542 | .start_byte = source_len, |
| 543 | .old_end_byte = source_len + 1, |
| 544 | .new_end_byte = source_len, |
| 545 | .start_point = end, |
| 546 | .old_end_point = {end.row + 1, 0}, |
| 547 | .new_end_point = end, |
| 548 | }; |
| 549 | ts_tree_edit(tree, &drop_virtual_newline); |
| 550 | } |
| 551 | return tree; |
| 552 | } |
| 553 | |
| 554 | // --- Parse timeout callback --- |
| 555 |
no test coverage detected