-
Notifications
You must be signed in to change notification settings - Fork 594
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 Family] Full rewrite of C family syntaxes #4147
base: master
Are you sure you want to change the base?
Conversation
C++/C.sublime-syntax
Outdated
- include: expressions | ||
prototype: | ||
- include: preprocessor.comment | ||
- match: \\$ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
heads up, you can test this in a test file for Sublime via:
// SYNTAX TEST "Packages/C/C.sublime-syntax" \
... \
// ^ punctuation.separator.continuation \
...
C++/syntax_test_c.c
Outdated
@@ -1,1555 +1,185 @@ | |||
/* SYNTAX TEST "Packages/C++/C.sublime-syntax" */ | |||
// SYNTAX TEST "Packages/C++/C.sublime-syntax" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
for line-continuation, change header to:
// SYNTAX TEST "Packages/C++/C.sublime-syntax" \
when testing:
... \
// ^ punctuation.separator.continuation \
...
duplicate the line-separator for continuation to the line with the expected scopes as well.
- Add digit separator `'` (C23) - Add scopes for __VA_ARGS__ and __VA_OPT__ - Give defined macro a `suport.macro.c` scope - Add #embed, #elifdef, and #elifndef directives - Add multi-line double-slashed comments via `\` - Fix some bugs
…ht for fn pointer types in a typedef.
Some general advices:
I'd recommend to organize contexts in a logical tree-like top-down structure, grouping related things like preprocessors, declarations, statements, expressions, keywords, identifiers, constants, operators, variables etc. together. Various syntaxes even use All of that will certainly help to keep track of structure as syntax definition grows. Keeping same context order and structure especially is important when extending a syntax, which will be the casse for C++. The more syntaxes in this repo follow a common schema the easier it is to maintain them. Premature ordering can be kill of creativity, so order is not that important for prototyping. Maybe however don't wait too long to add some structure. Please don't just add some code snippets to syntax test files, but also design assertions on the way going. It sometimes takes more time to write tests than syntax, they are however the only way to ensure not to break wanted/designed behavior by automated syntax tests. When writing rules for certain constructs you have in mind what you find important. Tests are just an expression of those thoughts or tools to verify your ideas/expectations against reality and vice versa. Tests can (or even should) also contain incomplete statements/expressions, to ensure code doesn't break too badly. At least it helps to ensure to limit breaking highlighting to small regions or makes you think about how to achieve it. Assertions should also contain some negative tests to ensure meta scope boundaries are maintained correctly or to avoid unwanted overlapping meta scopes. These are the less obvious issues, which may however impact various functionalities such as syntax based folding. |
FWIW, context order and structure of existing C syntaxes may not be ideal nor a good template to rely on. Better look at something more recent, such as Java, PHP or Python. |
I don't think those are the actual tests. 😉 I note the path to the syntax def in May I recommend similar to your PackageDev clone, you look at the suggestions in the ReadMe of this repo? Then you can modify the C syntax directly. If you want to keep the old one for comparison, you can rename it or move that one to
|
C++ is expected to fail at this point. That's step 2. Maybe even disable its tests to be able to focus on C in the meanwhile. |
C++/C.sublime-syntax
Outdated
- match: \" | ||
scope: punctuation.definition.string.begin.c | ||
push: string.double |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Strings are commonly used in various contexts and thus may deserve a dedicated context.
Maybe something like:
- match: \" | |
scope: punctuation.definition.string.begin.c | |
push: string.double | |
- include: string.quoted.double |
And in "literal" or "constants" section:
string.quoted.double:
- match: \"
scope: punctuation.definition.string.begin.c
push: string.quoted.double.body
string.quoted.double.body:
- match: \"
scope: punctuation.definition.string.end.c
pop: 1
|
- match: \bgoto\b | ||
scope: keyword.control.flow.goto.c | ||
keyword.control: | ||
- match: \b(?:if|else|for|while|do|switch|case|default)\b |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some languages have extra subscopes for some of these.
In no particular order, a bunch of this repository's open C Family issues: #409 #888 #1034 #1070 #1082 #1093 #1107 #1138 #1156 #1249 #1333 #1408 #1438 #1749 #1760 #1772 #1774 #1794 #1830 #1901 #1906 #1913 #1914 #1931 #1993 #2047 #2094 #2121 #2221 #2251 #2334 #2352 #2385 #2471 #2762 #2815 #2861 #2883 #2937 #3091 #3113 #3114 #3145 #3224 #3317 #3343 #3487 #3504 #3592 #3714 #3715 #3805 #3901 #3920 #3938 #3956 #3960 #3984 #4058 #4104 Not all of these may be valid, fixable, or even things we want. But it's at least worth looking at them to see if they happen to be fixed. |
I can't tell if these have been fixed yet, but some issues I noticed for C++ files on the latest stable that don't seem to be mentioned above: The names of namespaces being used don't have any specific scopes relating them to namespaces. I would expect the |
- match: \}|\] # Fallback | ||
scope: invalid.illegal.stray-bracket-end.c | ||
pop: 1 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This may easily cause owning contest to also break or not being terminated correctly due to brackets already being consumed here.
I'd recommend to use lookaheads and consume stray brackets only in top-level context.
To auto-close related issues upon merge of this PR, GitHub expects certain keywords: or in other words, you need to change the following in your opening comment (which will be the commit message of the merge commit): ## Issues fixed
- fixes #1070
- fixes #1093
... |
Edited OP to add GitHub's format. |
I am currently working on a full rewrite of the C family using modern Sublime Text syntax highlighting features. I plan to rewrite C, Objective-C, C++, and Objective-C++ in that order. Note that as of right now, only the C syntax has been edited and the syntax test file does not yet have any annotations.
This is currently a draft. Please feel free to let me know if I'm missing anything and I will add it to the roadmap.
C Roadmap
Changes made to C Highlighting
#if 0
and#if 1 #else
creating a commented out blocki
andj
to numerical suffixes (GNU extension)_Alignof
,alignof
, andoffsetof
,_Static_assert
,static_assert
,_Pragma
as word operators__cplusplus
is asupport.constant
nullptr_t
(C23) andmax_align_t
(C11) to list of default types_Thread_local
,thread_local
,_Atomic
,_Alignas
and_Noreturn
as storage modifiers__declspec
properties__attribute__
properties'
(C23)__VA_ARGS__
and__VA_OPT__
(C23)suport.macro.c
scope#embed
,#elifdef
, and#elifndef
directives (C23)\
typedef
support for function ptrstypedef
now share the same scoping as regular function defsIssues
const
as an indexed entity.name.type #3504