From 9068219c9fc5c9ea8aa3c1174a6ac441fb324e18 Mon Sep 17 00:00:00 2001 From: Sam McCall Date: Fri, 14 Oct 2022 23:19:20 +0200 Subject: [PATCH 1/2] c/c++ highlights: *& are @type or @operator based on context C gave us the infamous declaration-follows-use syntax for pointers, which can make it hard to tell at a glance whether a `*` is dereferencing a pointer or declaring one. C++ copied the syntax for references, despite the logic not applying. This patch highlights */& as (builtin) types when they're used to declare pointers/refs, and continues to treat them as operators in other contexts. This is more formally correct, but also practically useful (at least for me), particularly with pointer-binds-right code styles. The potential downside is reduced contrast within type declarations. --- runtime/queries/c/highlights.scm | 3 +++ runtime/queries/cpp/highlights.scm | 4 ++++ 2 files changed, 7 insertions(+) diff --git a/runtime/queries/c/highlights.scm b/runtime/queries/c/highlights.scm index c0f5763ac6bb..fe5dacafed53 100644 --- a/runtime/queries/c/highlights.scm +++ b/runtime/queries/c/highlights.scm @@ -51,6 +51,9 @@ (preproc_directive) ] @keyword.directive +(pointer_declarator "*" @type.builtin) +(abstract_pointer_declarator "*" @type.builtin) + [ "+" "-" diff --git a/runtime/queries/cpp/highlights.scm b/runtime/queries/cpp/highlights.scm index 11877a761cc0..70ce69f2c817 100644 --- a/runtime/queries/cpp/highlights.scm +++ b/runtime/queries/cpp/highlights.scm @@ -34,6 +34,10 @@ (auto) @type "decltype" @type +(ref_qualifier (["&" "&&"]) @type.builtin) +(reference_declarator (["&" "&&"]) @type.builtin) +(abstract_reference_declarator (["&" "&&"]) @type.builtin) + ; Constants (this) @variable.builtin From f6d6b75424ce2fa8d90632dbd88ec74de66baae0 Mon Sep 17 00:00:00 2001 From: Sam McCall Date: Sat, 15 Oct 2022 01:27:11 +0200 Subject: [PATCH 2/2] remove redundant parens --- runtime/queries/cpp/highlights.scm | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/runtime/queries/cpp/highlights.scm b/runtime/queries/cpp/highlights.scm index 70ce69f2c817..7bfccf72a263 100644 --- a/runtime/queries/cpp/highlights.scm +++ b/runtime/queries/cpp/highlights.scm @@ -34,9 +34,9 @@ (auto) @type "decltype" @type -(ref_qualifier (["&" "&&"]) @type.builtin) -(reference_declarator (["&" "&&"]) @type.builtin) -(abstract_reference_declarator (["&" "&&"]) @type.builtin) +(ref_qualifier ["&" "&&"] @type.builtin) +(reference_declarator ["&" "&&"] @type.builtin) +(abstract_reference_declarator ["&" "&&"] @type.builtin) ; Constants