From 72caeb574d7e82780e134a69be82890d1a47fcd6 Mon Sep 17 00:00:00 2001 From: Londopy Date: Sun, 20 Sep 2026 13:25:15 -0700 Subject: [PATCH 1/4] syntax/c: highlight the header name in #include as a string, not a type --- runtime/syntax/c.yaml | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/runtime/syntax/c.yaml b/runtime/syntax/c.yaml index c6a46741ea..26955d0394 100644 --- a/runtime/syntax/c.yaml +++ b/runtime/syntax/c.yaml @@ -30,6 +30,15 @@ rules: - constant.number: "(\\b0[Xx]([0-9A-Za-z]*[.][0-9A-Za-z]+|[0-9A-Za-z]+[.][0-9A-Za-z]*)[Pp][+-]?[0-9]+[FfLl]?\\b)" - constant.bool: "(\\b(true|false|NULL|nullptr|TRUE|FALSE)\\b)" + # #include lines are a region so that the header name (e.g. ) + # is not matched by the type/identifier rules above + - preproc: + start: "^[[:space:]]*#[[:space:]]*include\\b" + end: "$" + rules: + - constant.string: "<[^>]*>|\"[^\"]*\"" + - comment: "//.*|/\\*.*?\\*/" + - constant.string: start: "\"" end: "\"" From da80c699882d6f088eb90d8a00f4949041bd285a Mon Sep 17 00:00:00 2001 From: Londopy Date: Sun, 20 Sep 2026 16:12:58 -0700 Subject: [PATCH 2/4] syntax/c: drop include from the preproc pattern now that the region handles it --- runtime/syntax/c.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/runtime/syntax/c.yaml b/runtime/syntax/c.yaml index 26955d0394..b1efbcfccd 100644 --- a/runtime/syntax/c.yaml +++ b/runtime/syntax/c.yaml @@ -14,7 +14,7 @@ rules: - statement: "\\b(for|if|while|do|else|case|default|switch|_Generic|_Static_assert|static_assert)\\b" - statement: "\\b(goto|continue|break|return)\\b" - statement: "\\b(asm|fortran)\\b" - - preproc: "^[[:space:]]*#[[:space:]]*(define|embed|pragma|include|(un|ifn?)def|endif|el(if|ifdef|ifndef|se)|if|line|warning|error|__has_include|__has_embed|__has_c_attribute)" + - preproc: "^[[:space:]]*#[[:space:]]*(define|embed|pragma|(un|ifn?)def|endif|el(if|ifdef|ifndef|se)|if|line|warning|error|__has_include|__has_embed|__has_c_attribute)" - preproc: "^[[:space:]]*_Pragma\\b" # GCC builtins - statement: "__attribute__[[:space:]]*\\(\\([^)]*\\)\\)" @@ -33,7 +33,7 @@ rules: # #include lines are a region so that the header name (e.g. ) # is not matched by the type/identifier rules above - preproc: - start: "^[[:space:]]*#[[:space:]]*include\\b" + start: "^[[:space:]]*#[[:space:]]*include(_next)?\\b" end: "$" rules: - constant.string: "<[^>]*>|\"[^\"]*\"" From 8ae90fe6712e279055bcc6ffb4a6670488fdc20b Mon Sep 17 00:00:00 2001 From: Londopy Date: Mon, 21 Sep 2026 15:08:15 -0700 Subject: [PATCH 3/4] syntax: apply the #include region to the other C variants 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 ). 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. --- runtime/syntax/arduino.yaml | 11 ++++++++++- runtime/syntax/cpp.yaml | 11 ++++++++++- runtime/syntax/cuda.yaml | 11 ++++++++++- runtime/syntax/hc.yaml | 11 ++++++++++- runtime/syntax/objc.yaml | 13 ++++++++++--- 5 files changed, 50 insertions(+), 7 deletions(-) diff --git a/runtime/syntax/arduino.yaml b/runtime/syntax/arduino.yaml index 35a0480f5f..37ccfa6932 100644 --- a/runtime/syntax/arduino.yaml +++ b/runtime/syntax/arduino.yaml @@ -67,11 +67,20 @@ rules: - identifier: "\\b(setup|loop)\\b" ## - - statement: "^[[:space:]]*#[[:space:]]*(define|include(_next)?|(un|ifn?)def|endif|el(if|se)|if|warning|error|pragma)" + - statement: "^[[:space:]]*#[[:space:]]*(define|(un|ifn?)def|endif|el(if|se)|if|warning|error|pragma)" ## GCC builtins - constant: "(__attribute__[[:space:]]*\\(\\([^)]*\\)\\)|__(aligned|asm|builtin|hidden|inline|packed|restrict|section|typeof|weak)__)" + # #include lines are a region so that the header name (e.g. ) + # is not matched by the type/identifier rules above + - statement: + start: "^[[:space:]]*#[[:space:]]*include(_next)?\\b" + end: "$" + rules: + - constant.string: "<[^>]*>|\"[^\"]*\"" + - comment: "//.*|/\\*.*?\\*/" + - constant.string: start: "\"" end: "\"" diff --git a/runtime/syntax/cpp.yaml b/runtime/syntax/cpp.yaml index edd09c6087..54e89631fd 100644 --- a/runtime/syntax/cpp.yaml +++ b/runtime/syntax/cpp.yaml @@ -17,7 +17,7 @@ rules: - statement: "\\b(for|if|while|do|else|case|default|switch)\\b" - statement: "\\b(try|throw|catch|operator|new|delete|static_assert)\\b" - statement: "\\b(goto|continue|break|return)\\b" - - preproc: "^[[:space:]]*#[[:space:]]*(define|pragma|include|(un|ifn?)def|endif|el(if|se)|if|warning|error)|_Pragma" + - preproc: "^[[:space:]]*#[[:space:]]*(define|pragma|(un|ifn?)def|endif|el(if|se)|if|warning|error)|_Pragma" # Conditionally-supported/extension keywords - statement: "\\b(asm|fortran)\\b" @@ -61,6 +61,15 @@ rules: - constant.bool: "(\\b(true|false|NULL|nullptr|TRUE|FALSE)\\b)" + # #include lines are a region so that the header name (e.g. ) + # is not matched by the type/identifier rules above + - preproc: + start: "^[[:space:]]*#[[:space:]]*include(_next)?\\b" + end: "$" + rules: + - constant.string: "<[^>]*>|\"[^\"]*\"" + - comment: "//.*|/\\*.*?\\*/" + - constant.string: start: "\"" end: "\"" diff --git a/runtime/syntax/cuda.yaml b/runtime/syntax/cuda.yaml index 6875b1ef5a..f87c66c14e 100644 --- a/runtime/syntax/cuda.yaml +++ b/runtime/syntax/cuda.yaml @@ -16,7 +16,7 @@ rules: - statement: "\\b(for|if|while|do|else|case|default|switch)\\b" - statement: "\\b(try|throw|catch|operator|new|delete|static_assert)\\b" - statement: "\\b(goto|continue|break|return)\\b" - - preproc: "^[[:space:]]*#[[:space:]]*(define|pragma|include|(un|ifn?)def|endif|el(if|se)|if|warning|error)|_Pragma" + - preproc: "^[[:space:]]*#[[:space:]]*(define|pragma|(un|ifn?)def|endif|el(if|se)|if|warning|error)|_Pragma" # Conditionally-supported/extension keywords - statement: "\\b(asm|fortran)\\b" @@ -39,6 +39,15 @@ rules: - constant.number: "(\\b0[Xx]([0-9a-zA-Z']*[.][0-9a-zA-Z']+|[0-9a-zA-Z']+[.][0-9a-zA-Z']*)[Pp][+-]?[0-9']+[FfLl]?\\b)" - constant.bool: "(\\b(true|false|NULL|nullptr)\\b)" + # #include lines are a region so that the header name (e.g. ) + # is not matched by the type/identifier rules above + - preproc: + start: "^[[:space:]]*#[[:space:]]*include(_next)?\\b" + end: "$" + rules: + - constant.string: "<[^>]*>|\"[^\"]*\"" + - comment: "//.*|/\\*.*?\\*/" + - constant.string: start: "\"" end: "\"" diff --git a/runtime/syntax/hc.yaml b/runtime/syntax/hc.yaml index 9b94b0cd25..2a65433fc4 100644 --- a/runtime/syntax/hc.yaml +++ b/runtime/syntax/hc.yaml @@ -9,7 +9,7 @@ rules: - statement: "\\b(for|if|while|do|else|case|default|switch)\\b" - statement: "\\b(try|catch|throw|goto|continue|break|return)\\b" - - preproc: "^[[:space:]]*#[[:space:]]*(define|pragma|include|(un|ifn?)def|endif|el(if|se)|if|help_index|ifjit|ifaot|exe)" + - preproc: "^[[:space:]]*#[[:space:]]*(define|pragma|(un|ifn?)def|endif|el(if|se)|if|help_index|ifjit|ifaot|exe)" # Operator Color - symbol.operator: "([.:;,+*|=!\\%]|<|>|/|-|&)" @@ -24,6 +24,15 @@ rules: - constant.number: "TRUE" - constant.number: "FALSE" + # #include lines are a region so that the header name (e.g. ) + # is not matched by the type/identifier rules above + - preproc: + start: "^[[:space:]]*#[[:space:]]*include(_next)?\\b" + end: "$" + rules: + - constant.string: "<[^>]*>|\"[^\"]*\"" + - comment: "//.*|/\\*.*?\\*/" + - constant.string: start: "\"" end: "\"" diff --git a/runtime/syntax/objc.yaml b/runtime/syntax/objc.yaml index d4cccac317..0754b29f88 100644 --- a/runtime/syntax/objc.yaml +++ b/runtime/syntax/objc.yaml @@ -19,11 +19,9 @@ rules: - statement: "\\b(nonatomic|atomic|readonly|readwrite|strong|weak|assign)\\b" - statement: "@(encode|end|interface|implementation|class|selector|protocol|synchronized|try|catch|finally|property|optional|required|import|autoreleasepool)" - - preproc: "^[[:space:]]*#[[:space:]]*(define|include|import|(un|ifn?)def|endif|el(if|se)|if|warning|error|pragma).*$" + - 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:]]*$" - - statement: "([.:;,+*|=!\\%\\[\\]]|<|>|/|-|&)" - constant.number: "(\\b(-?)?[0-9]+\\b|\\b\\[0-9]+\\.[0-9]+\\b|\\b0x[0-9a-fA-F]+\\b)" @@ -33,6 +31,15 @@ rules: - constant: "\\bk[[:alnum]]*\\b" - constant.string: "'.'" + # #include lines are a region so that the header name (e.g. ) + # is not matched by the type/identifier rules above + - special: + start: "^[[:space:]]*#[[:space:]]*(include(_next)?|import)\\b" + end: "$" + rules: + - constant.string: "<[^>]*>|\"[^\"]*\"" + - comment: "//.*|/\\*.*?\\*/" + - constant.string: start: "@\"" end: "\"" From 555409f6bd79f1432d98705e921277afc357ab06 Mon Sep 17 00:00:00 2001 From: Londopy Date: Mon, 21 Sep 2026 15:26:04 -0700 Subject: [PATCH 4/4] syntax: restore the objc @import rule and keep macro-form includes as 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. --- runtime/syntax/arduino.yaml | 3 ++- runtime/syntax/c.yaml | 3 ++- runtime/syntax/cpp.yaml | 3 ++- runtime/syntax/cuda.yaml | 3 ++- runtime/syntax/hc.yaml | 3 ++- runtime/syntax/objc.yaml | 4 +++- 6 files changed, 13 insertions(+), 6 deletions(-) diff --git a/runtime/syntax/arduino.yaml b/runtime/syntax/arduino.yaml index 37ccfa6932..47c97efb16 100644 --- a/runtime/syntax/arduino.yaml +++ b/runtime/syntax/arduino.yaml @@ -73,11 +73,12 @@ rules: - constant: "(__attribute__[[:space:]]*\\(\\([^)]*\\)\\)|__(aligned|asm|builtin|hidden|inline|packed|restrict|section|typeof|weak)__)" # #include lines are a region so that the header name (e.g. ) - # is not matched by the type/identifier rules above + # is not matched by the type rules above - statement: start: "^[[:space:]]*#[[:space:]]*include(_next)?\\b" end: "$" rules: + - identifier: "\\b[A-Z_][0-9A-Z_]+\\b" - constant.string: "<[^>]*>|\"[^\"]*\"" - comment: "//.*|/\\*.*?\\*/" diff --git a/runtime/syntax/c.yaml b/runtime/syntax/c.yaml index b1efbcfccd..b816eac8a7 100644 --- a/runtime/syntax/c.yaml +++ b/runtime/syntax/c.yaml @@ -31,11 +31,12 @@ rules: - constant.bool: "(\\b(true|false|NULL|nullptr|TRUE|FALSE)\\b)" # #include lines are a region so that the header name (e.g. ) - # is not matched by the type/identifier rules above + # is not matched by the type rules above - preproc: start: "^[[:space:]]*#[[:space:]]*include(_next)?\\b" end: "$" rules: + - identifier: "\\b[A-Z_][0-9A-Z_]+\\b" - constant.string: "<[^>]*>|\"[^\"]*\"" - comment: "//.*|/\\*.*?\\*/" diff --git a/runtime/syntax/cpp.yaml b/runtime/syntax/cpp.yaml index 54e89631fd..d11de21f05 100644 --- a/runtime/syntax/cpp.yaml +++ b/runtime/syntax/cpp.yaml @@ -62,11 +62,12 @@ rules: - constant.bool: "(\\b(true|false|NULL|nullptr|TRUE|FALSE)\\b)" # #include lines are a region so that the header name (e.g. ) - # is not matched by the type/identifier rules above + # is not matched by the type rules above - preproc: start: "^[[:space:]]*#[[:space:]]*include(_next)?\\b" end: "$" rules: + - identifier: "\\b[A-Z_][0-9A-Z_]*\\b" - constant.string: "<[^>]*>|\"[^\"]*\"" - comment: "//.*|/\\*.*?\\*/" diff --git a/runtime/syntax/cuda.yaml b/runtime/syntax/cuda.yaml index f87c66c14e..b86e6e6de0 100644 --- a/runtime/syntax/cuda.yaml +++ b/runtime/syntax/cuda.yaml @@ -40,11 +40,12 @@ rules: - constant.bool: "(\\b(true|false|NULL|nullptr)\\b)" # #include lines are a region so that the header name (e.g. ) - # is not matched by the type/identifier rules above + # is not matched by the type rules above - preproc: start: "^[[:space:]]*#[[:space:]]*include(_next)?\\b" end: "$" rules: + - identifier: "\\b[A-Z_][0-9A-Z_]*\\b" - constant.string: "<[^>]*>|\"[^\"]*\"" - comment: "//.*|/\\*.*?\\*/" diff --git a/runtime/syntax/hc.yaml b/runtime/syntax/hc.yaml index 2a65433fc4..6a91b3b17c 100644 --- a/runtime/syntax/hc.yaml +++ b/runtime/syntax/hc.yaml @@ -25,11 +25,12 @@ rules: - constant.number: "FALSE" # #include lines are a region so that the header name (e.g. ) - # is not matched by the type/identifier rules above + # is not matched by the type rules above - preproc: start: "^[[:space:]]*#[[:space:]]*include(_next)?\\b" end: "$" rules: + - identifier: "\\b[A-Z_][0-9A-Z_]+\\b" - constant.string: "<[^>]*>|\"[^\"]*\"" - comment: "//.*|/\\*.*?\\*/" diff --git a/runtime/syntax/objc.yaml b/runtime/syntax/objc.yaml index 0754b29f88..7f8ce71df4 100644 --- a/runtime/syntax/objc.yaml +++ b/runtime/syntax/objc.yaml @@ -22,6 +22,8 @@ rules: - 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:]]*$" + - statement: "([.:;,+*|=!\\%\\[\\]]|<|>|/|-|&)" - constant.number: "(\\b(-?)?[0-9]+\\b|\\b\\[0-9]+\\.[0-9]+\\b|\\b0x[0-9a-fA-F]+\\b)" @@ -32,7 +34,7 @@ rules: - constant.string: "'.'" # #include lines are a region so that the header name (e.g. ) - # is not matched by the type/identifier rules above + # is not matched by the type rules above - special: start: "^[[:space:]]*#[[:space:]]*(include(_next)?|import)\\b" end: "$"