Closed jeff-hykin closed 2 years ago
What is your opinion on temporarily using the C++ syntax as the C syntax since C++ is almost a perfect superset of C @matter123 ? We might want to consider this since changes to the theme (for C++) might break the colors in C since their tags have not been updated. (ex: keyword.control
for memory)
Or maybe having it be a superset with the exception of replacing cpp_tokens
with c_tokens
There is also the option of creating a shared C and C++
file that is imported into both, but that will take time to setup properly.
I have a very experimental way to "diff" grammars, let me compare the C and C++ on the linux kernel. Give me about 10 minutes to set that up. Sharing common patterns is probably the best though.
Edit: There are far more files than I thought. The relatively small file size is promising, however.
Only a small fraction of the files as the diff tool crashed. However, most changes from the C++ grammar look harmless. Have a better source of C files?
Gettext: gettext.log
built-in
from storage.type.built-in.primitive
-c
to punctuation.section.parens-c
punctuation.section.parens.block
and instead has meta.block.parens
variable.object
to variable.other.object
punctuation.section.block.begin.bracket.curly
from union YYSTYPE {
While its not impossiable to do there are several issues.
Sadly I don't but I might know some people that do. I'll check in with them. This is a good idea for testing.
Yeah, it can catch some slightly hard to find bugs like anonymous struct https://github.com/jeff-hykin/cpp-textmate-grammar/pull/57#issuecomment-481502001, but it is currently pretty rough.
So long as themers don't have an issue, it might be best to fully clean up the C++ code first and then once it is, we work on back-porting everything to C.
If themers do have an issue, then I think the best solution will be to use the C++ highlighting for both until it is cleaned up. I looked up the differences in the C syntax that were not in C++ and there are only a handful of cases.
C supports some pretty fancy designated initalizers int a[10] = { [5] =5,0}
and {.a.v[0].c = {.a ={[1]='q'}}
are both valid.
I guess we will have to see how the C++ syntax handles that. So long as it doesn't break the syntax it will probably still be an improvement over what it currently is highlighted with.
That is interesting though, I didn't see anything about that so I probably didn't dig deep enough.
C | C++ |
---|---|
So currently C and C++ offer similar coloring of the provided designated initializer example. C++ does forget about the character literal, however.
I have a C repo located at https://git.sr.ht/~tristan957/tllt-cp that might be able to serve as a good test for diffing the C/C++ grammars. About 3000 lines of C code that uses many parts of the language.
So the first item I noticed if we are to share generators, the existing pattern tags that manually add, .cpp
have to go.
meta.function
, but being a meta scope is probably not all that important.err->message
message is tagged as variable.other.member
in C but variable.other.property
in C++punctuation.section.parameters.end.bracket.round
from []
variable.object
to variable.other.object
punctuation.section.parens.block
to meta.block.parens
Thanks @tristan957
Cool glad I could be of assistance
I just realized #107 blocks copying the C++ syntax to C. It would completely wreck any language that is inheriting from the C language.
I am going to use this comment to list patterns that can be shared between C and C++
EXAMPLE 1 The program fragment 1Ex is parsed as a preprocessing number token (one that is not a valid floating or integer constant token), even though a parse as the pair of preprocessing tokens 1 and Ex might produce a valid expression (for example, if Ex were a macro defined as +1). Similarly, the program fragment 1E1 is parsed as a preprocessing number (one that is a valid floating constant token), whether or not E is a macro name.
tokenization treats any sequence of characters starting with a number as a number
(std::)?malloc
shoulden't over match in the C grammar, but maybe with Obj-Cand
, or
, etc are only defined in C upon inclusion of iso646.h
bool
and stdbool.h
noreturn
and stdnoreturn.h
static_assert
and assert.h
enum struct foo
has no valid meaning.Are you guys noticing that true, false, and NULL in C++ are not highlighted the same as in C?
Yeah that's a regressions
@jeff-hykin Is there a preferred way for shared patterns to add to the current grammars repository?
Ah this is really old, I was thinking the file that imports the shared thing would add it to it's grammar.
In general though, I think most of the sharing is going to happen once C++ has it's type system figured out. Then the common stuff will be extracted and a good sharing system will be implemented.
C syntax has finally been separated/moved to https://github.com/jeff-hykin/better-c-syntax !
Right now the C++ and C syntax are being generated completely separately. I am familiar with C++ and most of my fixes have been exclusively for C++ even if they should be applicable to C.
There have already been issues posted about this difference.
46
47
This issue is a log and general discussion about how to keep the C syntax in sync with the C++ Syntax without breaking compatibility on either side.
update:
I've decided to fix all of C++ first and then fix C. If there's a major issue with the C syntax, then it will get fixed separately.
I'm going to use this post as a log to keep track of all the non-major issues with the C syntax.
sscanf(user_input, "%c %[^\n]", &arg0, arg_str); // reads char into arg0, the remainder until \n to arg_str
atom/language-c#222 atom/language-c#70struct f foo
is missing highlighting46
/ Function Declaration / void a(struct A b); void b(enum B c); void c(union C d); void d(A b);
/ Definition / struct A { enum B c; union C d; }; enum B { struct A d; union C d; }; union C { struct A b; enum B c; };