highlightjs/highlight.js

(C++) Integer literals with quote delimiters in #defines break highlighting

開放

#3,928 建立於 2023年11月19日

 (11 則留言) (0 個反應) (0 位負責人)JavaScript (3,497 個分叉)batch import
buggood first issuehelp welcomelanguage

倉庫指標

星標
 (22,960 顆星)
PR 合併指標
 (平均合併 6分鐘) (30 天內合併 2 個 PR)

描述

Describe the issue Integer literals in C++ may be written as 1'000'000'000 instead of 1000000000 for greater readability. When this is used inside a #define, if breaks highlighting which treats the rest of the code as being inside a string.

Which language seems to have the issue? cpp

Are you using highlight or highlightAuto? highlight

Sample Code to Reproduce

#include <iostream>
#define INF 1'000'000'000

int main() {
	int a = INF;
    return 0;
}

image

Expected behavior The token 1'000'000'000 should be highlighted as a number, and the following code should also be highlighted normally, instead of as if it is inside a string:

image

Additional context

The snippet below seems to be highlighted fine, so the issue is likely the interplay between quote-separated literals and defines.

#include <iostream>

int f(int x) { return f(2'000); }

int main() {
	int a = 1'000'000'000;
    int b = f(1'000);
    return 0;
}

貢獻者指南