Partial multi-line comments are not highlighted #11

Closed
opened 2026-01-03 19:34:24 +01:00 by shitpoet · 1 comment
shitpoet commented 2026-01-03 19:34:24 +01:00 (Migrated from github.com)

Multi-line comments are not highlighted until closed. Which is a bit unusual, I'd say, for a code editor.

btw lang-java has the same problem, but not lang-javascript, lang-go, lang-rust. So the behaviour seems a bit inconsistent.

Example (image):

Code:

#include <iostream>
#include <vector>

void partition(std::vector<int> &nums, bool(*pred)(int), size_t l, size_t r) {
    /*if (r - l < 2) {      // here, no comment highliting
        return;
    }

    size_t m = (l + r) / 2;    
    partition(nums, pred, l, m);
    partition(nums, pred, m, r);
}

int main() {
    return 0;
}

Multi-line comments are not highlighted until closed. Which is a bit unusual, I'd say, for a code editor. btw `lang-java` has the same problem, but not `lang-javascript`, `lang-go`, `lang-rust`. So the behaviour seems a bit inconsistent. Example (image): <img src='https://sshots.shitpoet.cc/2026-01-03--222301--2520422019.png'> Code: ```cpp #include <iostream> #include <vector> void partition(std::vector<int> &nums, bool(*pred)(int), size_t l, size_t r) { /*if (r - l < 2) { // here, no comment highliting return; } size_t m = (l + r) / 2; partition(nums, pred, l, m); partition(nums, pred, m, r); } int main() { return 0; } ```
marijnh commented 2026-01-05 09:41:25 +01:00 (Migrated from github.com)

btw lang-java has the same problem, but not lang-javascript, lang-go, lang-rust. So the behaviour seems a bit inconsistent.

Each parser can make its own decisions about how to parse comments. Some treat them as a single token, which will make them not match if the end marker is missing, and others as separate opening tokens, content tokens, and end tokens. The latter is more efficient when re-parsing large comment blocks, so attached patch makes the cpp parser work this way as well.

> btw lang-java has the same problem, but not lang-javascript, lang-go, lang-rust. So the behaviour seems a bit inconsistent. Each parser can make its own decisions about how to parse comments. Some treat them as a single token, which will make them not match if the end marker is missing, and others as separate opening tokens, content tokens, and end tokens. The latter is more efficient when re-parsing large comment blocks, so attached patch makes the cpp parser work this way as well.
Sign in to join this conversation.
No labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
lezer/cpp#11
No description provided.