Conversation
Andriamanitra
left a comment
There was a problem hiding this comment.
This is a nice little improvement, works as expected.
You could remove "include" from the preproc rule on line 17 since it's now handled by the region.
|
Done! Dropped |
|
The same is valid for the |
Good point! We have syntaxes for 6 different variants of C:
It would probably make sense to use Grepping for
|
arduino, cpp, cuda, hc and objc had the same issue as c: the header name in an #include line was matched by the type/identifier rules (e.g. float in <float.h>). Each file keeps the group it already used for the directive (statement for arduino, special for objc) so the only visual change is the header name becoming a string. In objc the whole-line special rule for import/include is superseded by the region and has been removed.
| - preproc: "^[[:space:]]*#[[:space:]]*(define|(un|ifn?)def|endif|el(if|se)|if|warning|error|pragma).*$" | ||
| - preproc: "__[A-Z0-9_]*__" | ||
|
|
||
| - special: "^[[:space:]]*[#|@][[:space:]]*(import|include)[[:space:]]*[\"|<].*\\/?[>|\"][[:space:]]*$" |
There was a problem hiding this comment.
You accidentally removed highlighting for @import here.
There was a problem hiding this comment.
Restored it verbatim in 555409f. @import Foundation; was never affected (the @(...) statement rule covers it), but @import <Foundation/Foundation.h> and @import "X.h" lost highlighting since the region only matches #. The region supersedes that rule for # lines, so it still does its job for @.
I also diffed every touched syntax file before/after over a corpus: the only lines that change now are #include/#import directives.
… identifiers Restores the whole-line special rule in objc.yaml verbatim: the region only matches the # form, so removing it dropped highlighting for @import <...> and @import "...". The region supersedes it for # lines. Also adds each file's own identifier rule inside the region, ordered before the string rule, so a macro-form include (#include MY_HEADER) keeps the identifier highlighting it had before while <...> and "..." still win.
|
You're right, thanks for catching it — I reproduced it with your file. The cause turned out not to be this PR though. In if start == endLoc[0] {
searchNesting = false
}When the two happen to be equal, every rule inside the region is skipped. It's pre-existing. On current master, with no changes at all, in a C file: I've opened #4240 with the one-line fix ( So this PR depends on #4240 — happy to reorder them, or to hold this one until that lands. |
|
@JoeKar does this problem remind your of something? |
My bad, I didn't think to test with a file where the |
|
Correction to my comment above: the fix already exists as #4022 (tracked by #4018) — I missed it and opened a duplicate, which I've now closed. #4022 has the same one-line change plus nested-region fixes. So this PR depends on #4022 rather than anything of mine. I've offered my regression test over there since that PR has no tests and the open question was whether it breaks anything else. This one is fine to hold until #4022 lands — no rush from my side. |
At the very least, we should merge #4022 (go from my side) as a temporary solution, and I need to continue working on #3127 to remove this weird (somehow self-inflicted) highlighter loop. Yes, I know...this line was my fault and turned out to be just half of the truth. 😞 |

#include <float.h>highlightedfloatas a type (and<,.,>as operators) because the#includeline was only matched by a pattern rule, so the other top-level patterns still ran over the header name.This makes
#includelines apreprocregion (likescad.yamldoes), which stops the type/identifier patterns from matching inside it. The region's inner rules highlight<...>and"..."asconstant.string— matching how#include "float.h"was already rendered — and keep trailing//and/* */comments as comments. Inner rules are patterns rather than nested regions, since nested regions get top-level patterns leaked into them byhighlightRegion.Checked with
pkg/highlightdirectly:#include <float.h>#include:preproc,<float.h>:constant.string#include "float.h"# include <stdint.h> // TODO: drop<stdint.h>:constant.string,// TODO: drop:comment#include <bool.h> /* int *//* int */:comment (intno longer a type)#include MY_HEADERfloat x = 1.0f;/int y = a < b > c;#include <float.h>followed byfloat z;floatas type (region closes at EOL)Closes #3930