-
Notifications
You must be signed in to change notification settings - Fork 3.6k
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
enh(cpp) recognize primitive types (int
, char
, etc.) as keywords
#3313
enh(cpp) recognize primitive types (int
, char
, etc.) as keywords
#3313
Conversation
This isn't highly relevant though (for us), as often we make decisions that improve the consistency of highlighting (across languages) without overly weighting any particular language. The idea being that highlighting snippets somewhat consistently across languages is a higher (and more achievable) goal than absolutely correctness with accordance to one particular language. IE: It doesn't matter if type is literally a type in C while literally a keyword in CPP, etc... C and C++ code (two different grammar types for us) should highlight similarly - with things that appear to be primitive types highlighted at I think if anything we should perhaps add the type modifiers so that they also highlight as At the very least...
...do seem broken the way we're doing it now, as my understanding is the type name includes the signed/unsigned prefix. Also worth pointing out this is entirely within the users control via CSS: .language-cpp .hljs-type {
color: /* whatever */
} ... if they want to erase the type/keyword distinction for |
@joshgoebel, thanks for the detailed reply!
I get the point. I just wanted to point out that the current highlighting looks
Okey.
The CSS rule also affects type names with the Highlightjs (jsfiddle): The separation of primitive types and types that have definitions can be |
I'm not sure we care about this distinction (a type is a type contextually, IMHO), and if we did perhaps a better way to handle it (if it was shown that more people actually care about this) would be to simply expand our scopes... so we have You can also do this at the grammar level (vs CSS) by patching a grammars Closing this in favor of #3316 to make the full type declaration consistent as |
I would like to discuss the change made in hljs 11.0.0:
As part of the above pull request, primitive types and keywords were split to
be highlighted separately (commit 1be7a28). It seems to me that after the
change, the highlighting of some C++ code looks unnatural and confusing. For
example, take a look at the variable declarations before and after the change:
Before (jsfiddle):
After (jsfiddle):
How would you feel about returning to the previous behaviour?
Technically, as far as the C++ standard is concerned, primitive types are
keywords. Plus, many popular C++ IDEs and text editors highlight primitive
types as keywords:
Changes
RESERVED_TYPES
toRESERVED_KEYWORDS
.keyword
for Arduino specific data types as Arduino is a superset of C++.Checklist
CHANGES.md