Subject: Re: bug#63323: c-ts-mode does not know about `restrict'

From: Yuan Fu <[email-masked]>
Date: Sat, 6 May 2023 15:54:32 -0700

> On May 6, 2023, at 5:19 AM, Eli Zaretskii <[email-masked]> wrote:
> 
>> Cc: [email-masked]
>> Date: Sat, 06 May 2023 13:31:03 +0300
>> From: Eli Zaretskii <[email-masked]>
>> 
>> It looks like c-ts-mode thinks type qualifiers are possible only in
>> C++?
>> 
>>   :feature 'type
>>   `((primitive_type) @font-lock-type-face
>>     (type_identifier) @font-lock-type-face
>>     (sized_type_specifier) @font-lock-type-face
>>     ,@(when (eq mode 'cpp) <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
>>         '((type_qualifier) @font-lock-type-face
>> 
>>           (qualified_identifier
>>            scope: (namespace_identifier) @font-lock-type-face)
>> 
>>           (operator_cast) type: (type_identifier) @font-lock-type-face))
>>     [,@c-ts-mode--type-keywords] @font-lock-type-face)
>> 
>> The tree-sitter library returns a type_qualifier node for 'restrict':
>> 
>>       (parameter_declaration type: (type_identifier)
>> declarator: 
>>  (pointer_declarator *
>>   (type_qualifier restrict)
>>   declarator: (identifier)))
>> 
>> Yuan, can you look into fixing this, please?
> 
> Actually, it looks like we recognize the type qualifiers in C as
> keywords, via a separate list.  So I've just added to that list the
> two missing qualifiers: 'restrict' and '_Atomic', and that fixes this
> bug for me.
> 
> Yuan, is that the right fix?  I've installed it on the emacs-29
> branch.

I check tree-sitter-c’s grammar and it defines type_qualifier [1], so if you move (type_qualifier) @font-lock-type-face out of the check for cpp, if would work. Recognizing them as keywords also works. So both are technically correct. C-mode uses keyword face, so I think your fix is a-ok.

[1] you probably know this, but for completeness:

    type_qualifier: $ => choice(
      'const',
      'volatile',
      'restrict',
      '_Atomic'
    ),

Yuan