You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
#include <float.h> highlighted float as a type (and <, ., > as operators) because the #include line was only matched by a pattern rule, so the other top-level patterns still ran over the header name.
This makes #include lines a preproc region (like scad.yaml does), which stops the type/identifier patterns from matching inside it. The region's inner rules highlight <...> and "..." as constant.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 by highlightRegion.
Checked with pkg/highlight directly:
input
result
#include <float.h>
#include:preproc, <float.h>:constant.string
#include "float.h"
unchanged from before
# include <stdint.h> // TODO: drop
<stdint.h>:constant.string, // TODO: drop:comment
#include <bool.h> /* int */
/* int */:comment (int no longer a type)
#include MY_HEADER
all preproc
float x = 1.0f; / int y = a < b > c;
unchanged
#include <float.h> followed by float z;
second line still highlights float as type (region closes at EOL)
Done! Dropped include from the pattern. While retesting I noticed that left #include_next unhighlighted (the old pattern was partially matching it), so the region start now also accepts _next.
The same is valid for the cpp.yaml (maybe even more like objc.yaml), right?
Good point! We have syntaxes for 6 different variants of C:
arduino
c
cpp
cuda
hc
objc
It would probably make sense to use include: "c" in at least some of these to inherit from the C syntax, but I'm not sure which ones are true supersets of C. But for this PR simply copying the rule to all of them would be fine too.
Grepping for #.*include also found three others that are not C but I guess can use a similar preprocessor (I don't think we need to touch these):
ats
fortran
zscript
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
#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