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 lines are a region so that the header name (e.g. <float.h>) | ||
| # is not matched by the type rules above | ||
| - special: | ||
| start: "^[[:space:]]*#[[:space:]]*(include(_next)?|import)\\b" | ||
| end: "$" | ||
| rules: | ||
| - constant.string: "<[^>]*>|\"[^\"]*\"" | ||
| - comment: "//.*|/\\*.*?\\*/" |
There was a problem hiding this comment.
What's the difference between this and line 25? Other than line 25 covering @Import .... Maybe we can merge/remove one?..
There was a problem hiding this comment.
Good question. With the region in place, line 25 no longer applies to any #import/#include line, since regions are matched before patterns. The only thing it still affects is @import followed by a header in angle brackets, like @import <Foundation/Foundation.h>, which isn't valid Objective-C: @import takes a module name (@import Foundation;, @import std.io;), and those are highlighted by the @(...) statement rule either way.
I diffed objc.yaml with and without line 25 over 22 valid and invalid lines. Only three change: @import <Foundation/Foundation.h>, @ import <UIKit/UIKit.h> and |import <x.h> (the [#|@] class also matches a literal |).
Merging it into the region would be worse: the region would then also take @import Foundation; and color the whole line as special.
So I think it can simply go. I restored it after the earlier review to keep the output identical for every input. @Andriamanitra, are you OK with removing it?
There was a problem hiding this comment.
You're right, the @import <...> pattern matched by line 25 was never actually valid Objective-C, and @import on its own is already highlighted on line 20. It can be removed.
There was a problem hiding this comment.
How about the text after @import?
Maybe change line 25 to just be matching @import ...?
There was a problem hiding this comment.
Removed line 25 in 32044ff, as Andriamanitra suggested. With that, the only lines this PR changes in objc are #import/#include directives, plus the invalid @import <...> forms above.
On matching @import ... instead: the text after @import is a module name, and micro's Swift and Java syntaxes also color only the keyword there (import UIKit, import java.util.List;). That's already how @import Foundation; looks here, via line 20. (@import UIKit; does get UIKit colored, but that's the two-capitals type rule on line 10, not line 25.)
Coloring the text after @import would change how valid @import lines look, which is outside this PR's #include fix, so I'd leave that for a separate PR if it's wanted.

#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