Comments must not affect indentation. Block comments have to be lexed here because the internal lexer no longer knows them.
| 595 | // Comments must not affect indentation. Block comments have to be lexed |
| 596 | // here because the internal lexer no longer knows them. |
| 597 | static CommentAtLayout check_comment_at_layout(TSLexer *lexer, |
| 598 | const bool *valid_symbols) { |
| 599 | if (lexer->lookahead != '/') { |
| 600 | return COMMENT_NONE; |
| 601 | } |
| 602 | advance(lexer); |
| 603 | if (lexer->lookahead == '*' && valid_symbols[BLOCK_COMMENT]) { |
| 604 | advance(lexer); |
| 605 | for (;;) { |
| 606 | consume_block_comment_body(lexer); |
| 607 | advance_past_blanks(lexer); |
| 608 | if (lexer->eof(lexer) || lexer->lookahead == '\n' || |
| 609 | lexer->lookahead == '\r') { |
| 610 | finish_block_comment(lexer); |
| 611 | return COMMENT_LEXED; |
| 612 | } |
| 613 | if (lexer->lookahead == '/') { |
| 614 | advance(lexer); |
| 615 | if (lexer->lookahead == '*') { |
| 616 | advance(lexer); |
| 617 | continue; // another block comment on the same line |
| 618 | } |
| 619 | if (lexer->lookahead == '/') { |
| 620 | // The extent cannot be re-marked back, so consume the trailing |
| 621 | // line comment into the comment token. |
| 622 | while (!lexer->eof(lexer) && lexer->lookahead != '\n') { |
| 623 | advance(lexer); |
| 624 | } |
| 625 | finish_block_comment(lexer); |
| 626 | return COMMENT_LEXED; |
| 627 | } |
| 628 | // A lone '/' is code. The off-by-one column is harmless. |
| 629 | return COMMENT_SAME_LINE_CODE; |
| 630 | } |
| 631 | return COMMENT_SAME_LINE_CODE; |
| 632 | } |
| 633 | } |
| 634 | if (lexer->lookahead == '/' || lexer->lookahead == '*') { |
| 635 | return COMMENT_ABORT; |
| 636 | } |
| 637 | // A lone '/' is not a comment. The lexer stays advanced past it. |
| 638 | return COMMENT_NONE; |
| 639 | } |
| 640 | |
| 641 | // Skips a delimited body (a string or a back-ticked identifier) whose opening |
| 642 | // delimiter the caller has consumed. Stops after the closing `close` or at |
no test coverage detected