Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
jureslak opened this issue Nov 19, 2023 · 6 comments
Open
Labels
bug good first issue Should be easier for first time contributors help welcome Could use help from community language

Comments

@jureslak
Copy link

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;
}
@jureslak jureslak added bug help welcome Could use help from community language labels Nov 19, 2023
@jureslak jureslak changed the title C++ Integer literals with quote delimiters in #defines break highlighting (C++) Integer literals with quote delimiters in #defines break highlighting Nov 19, 2023
@joshgoebel joshgoebel added the good first issue Should be easier for first time contributors label Nov 19, 2023
@TokenPayId
Copy link

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 null;

}

1 similar comment
@TokenPayId
Copy link

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 null;

}

@joshgoebel
Copy link
Member

Can you confirm a fix: #3930

@jureslak
Copy link
Author

Looks great, thanks!

Before:

image

After:

image

@akhtarmdsaad
Copy link
Contributor

Is this issue resolved?

@joshgoebel
Copy link
Member

Not yet, I think I've started this needs to be contextual, so it's a bit more complicated than what we have so far.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug good first issue Should be easier for first time contributors help welcome Could use help from community language
Projects
None yet
Development

No branches or pull requests

4 participants