Variables are highlighted as types in if statement #9

Closed
opened 2025-12-08 19:15:20 +01:00 by shitpoet · 1 comment
shitpoet commented 2025-12-08 19:15:20 +01:00 (Migrated from github.com)

Local variables (parameters) are highlighted as types in an if statement, when using the official Lezer cpp package and classHighlighter.

Example (image):

image link

I understand that it can be complicated to differentiate variable and type names in C++, but still. Maybe it would be better to avoid type tokens at all, if it's too complicated to recognise them correctly.

Code of the example:

int digits_to_number(int a, int b, int c) {
    int mag = abs(a) * 100 + abs(b) * 10 + abs(c);
    if (a < 0 || b < 0 || c < 0) {
        return -mag;
    } else {
        return mag;
    }
}
Local variables (parameters) are highlighted as types in an `if` statement, when using the official Lezer `cpp` package and `classHighlighter`. Example (image): <img src='https://sshots.shitpoet.cc/2025-12-08--220603--2593027907.png'> [image link](https://sshots.shitpoet.cc/2025-12-08--220603--2593027907.png) I understand that it can be complicated to differentiate variable and type names in C++, but still. Maybe it would be better to avoid type tokens at all, if it's too complicated to recognise them correctly. Code of the example: ```cpp int digits_to_number(int a, int b, int c) { int mag = abs(a) * 100 + abs(b) * 10 + abs(c); if (a < 0 || b < 0 || c < 0) { return -mag; } else { return mag; } } ```
marijnh commented 2025-12-09 09:44:43 +01:00 (Migrated from github.com)

Attached patches, released in @lezer/lr 1.4.5 and @lezer/cpp 1.1.4 should improve this.

Attached patches, released in @lezer/lr 1.4.5 and @lezer/cpp 1.1.4 should improve this.
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#9
No description provided.