-
Notifications
You must be signed in to change notification settings - Fork 3.6k
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
(cpp) syntax should be split into C and C++ syntaxes #2146
Comments
hhmm... yeah, might be worth splitting into two. |
It's also possible we should start with a "C-like" like Prism does. My recent work on CPP/Arduino might make sense to look at as a potential pattern. |
But those things wouldn't really be using in a C context either, would they? |
@yyyc514 In a language where the words "vector" and "string" have no special meaning, they're pretty reasonable variable names. The context I encountered this in was with tagged unions; something like struct whatever {
enum {
WHATEVER_NUMBER,
WHATEVER_STRING
} tag;
union {
double number;
char *string;
} val;
}; |
Now just having separate keyword lists would be pretty easy. |
@egor-rogov How would you feel if we prepared for this by simply making C a requirement of C++ but for v10 effectively they were still the exact same thing? Ie a patch would only:
This would get the "breaking" part of the change out of the way and avoid us having to release v11 just to do this later... Thoughts? |
In my perfect world v10 would break a lot of things, then we'd go back to stable releases for a year or so... I don't want to get into the habit of breaking something with every release. So I think that requires a little planning ahead. |
I'm okay with it. Having separated keywords for these two languages sounds like a good idea. |
- chore(parser): effectively rename `cpp.js` to `c-like.js` [Josh Goebel][] - chore(parser): create new `c.js` (C), depends on `c-like` now [Josh Goebel][] - chore(parser): create new `cpp.js` (C), depends on `c-like` now [Josh Goebel][] - This will allow us to clean up C/C++ in the future without another breaking change by getting this require change out of the way early. (#2146)
- chore(parser): effectively rename `cpp.js` to `c-like.js` [Josh Goebel][] - chore(parser): create new `c.js` (C), depends on `c-like` now [Josh Goebel][] - chore(parser): create new `cpp.js` (C), depends on `c-like` now [Josh Goebel][] - This will allow us to clean up C/C++ in the future without another breaking change by getting this require change out of the way early. (#2146)
- chore(parser): effectively rename `cpp.js` to `c-like.js` [Josh Goebel][] - chore(parser): create new `c.js` (C), depends on `c-like` now [Josh Goebel][] - chore(parser): create new `cpp.js` (C), depends on `c-like` now [Josh Goebel][] - This will allow us to clean up C/C++ in the future without another breaking change by getting this require change out of the way early. (#2146)
- chore(parser): effectively rename `cpp.js` to `c-like.js` [Josh Goebel][] - chore(parser): create new `c.js` (C), depends on `c-like` now [Josh Goebel][] - chore(parser): create new `cpp.js` (C), depends on `c-like` now [Josh Goebel][] - This will allow us to clean up C/C++ in the future without another breaking change by getting this require change out of the way early. (#2146)
- chore(parser): effectively rename `cpp.js` to `c-like.js` [Josh Goebel][] - chore(parser): create new `c.js` (C), depends on `c-like` now [Josh Goebel][] - chore(parser): create new `cpp.js` (C), depends on `c-like` now [Josh Goebel][] - This will allow us to clean up C/C++ in the future without another breaking change by getting this require change out of the way early. (#2146)
- chore(parser): effectively rename `cpp.js` to `c-like.js` [Josh Goebel][] - chore(parser): create new `c.js` (C), depends on `c-like` now [Josh Goebel][] - chore(parser): create new `cpp.js` (C), depends on `c-like` now [Josh Goebel][] - This will allow us to clean up C/C++ in the future without another breaking change by getting this require change out of the way early. (#2146)
- chore(parser): effectively rename `cpp.js` to `c-like.js` [Josh Goebel][] - chore(parser): create new `c.js` (C), depends on `c-like` now [Josh Goebel][] - chore(parser): create new `cpp.js` (C), depends on `c-like` now [Josh Goebel][] - This will allow us to clean up C/C++ in the future without another breaking change by getting this require change out of the way early. (#2146)
- chore(parser): effectively rename `cpp.js` to `c-like.js` [Josh Goebel][] - chore(parser): create new `c.js` (C), depends on `c-like` now [Josh Goebel][] - chore(parser): create new `cpp.js` (C), depends on `c-like` now [Josh Goebel][] - This will allow us to clean up C/C++ in the future without another breaking change by getting this require change out of the way early. (#2146)
It doesn't really make sense to have C and C++ share the same code - there are almost more differences than there are similarities, it is not just about keywords. The preprocessor and the basic literal tokens and comments could use the same structure but that's about it. For example C does not have templates, so there is no point in trying to figure out if |
The name |
Yep that's definitely C++ only... and if we had a common foundation that wouldn't go in the foundation... ie it really doesn't belong in But I could be persuaded that the grammars should be entirely separate if the C stand-alone grammar is simple enough... If someone knowledgable in C wants to take the Any takers? Also: Is the C language still evolving these days or is it pretty much static? |
For the most part, the C language is static, but not wholly static. The C2x proposal includes new syntax for attributes such as |
@klmr Not sure if you might have any interest in helping out here... I can't imagine this would be super hard to accomplish for someone who knows C well. (although perhaps you're only a C++ guru) :-) |
I've not studied the documentation (so I may just need pointing at the right bit), but what's the attitude of highlight.js to code that is not precisely syntactically correct, but that is mostly correct? The reason for asking is that in the c-like code, there are expressions for C++ numbers. These can use single quotes between digits (e.g. On a related point, some C compilers allow the binary constant notation, but standard C does not (they're a part of C++). And I'm not sure whether those C compilers allow the single quotes feature — again, that's primarily C++. Should the (currently hypothetical) C scanner handle such extensions? |
This is probably fine (ie, it doesn't necessarily need to be fixed)... this should never exist in the wild (since it's invalid) so it doesn't matter if we'd highlight it wrong.
Depends. Often it can be better to leave them more readable UNLESS it's super easy (and not too complex) to be more precise... if it's just expanding the regex slightly, OK. If it adds 20 lines of code or a whole bunch of impossible to read regex, then we'd really want to consider the value. Precision can improve our auto-detection abilities.
I really don't know, but I'd say we could go minimal for starters and then add things back later if it proves to be an issue? Although if we think it's common AND it's not really going to "break" anything I also don't see the harm in including say single quotes for C... |
I'm fully splitting the grammars and killing |
Closing this issue after the split. I assume the two will diverge over time, not see a single larger rework (although that's also welcome). |
@klmr C is ripe for simplification now if you're still interested. :-) |
Currently, C and C++ are both highlighted the same way, but that's not ideal. For example, the words
string
andvector
are highlighted as built-ins, which makes no sense in a C context.The text was updated successfully, but these errors were encountered: